[ Index ] |
PHP Cross Reference of osCMax 2.0.4 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 $Id: affiliate_functions.php 14 2006-07-28 17:42:07Z user $ 4 5 OSC-Affiliate 6 7 Contribution based on: 8 9 osCMax Power E-Commerce 10 http://oscdox.com 11 12 Copyright 2006 osCMax 13 14 Released under the GNU General Public License 15 */ 16 17 function affiliate_check_url($url) { 18 return eregi("^https?://[a-z0-9]([-_.]?[a-z0-9])+[.][a-z0-9][a-z0-9/=?.&\~_-]+$",$url); 19 } 20 21 function affiliate_insert ($sql_data_array, $affiliate_parent = 0) { 22 // LOCK TABLES 23 tep_db_query("LOCK TABLES " . TABLE_AFFILIATE . " WRITE"); 24 if ($affiliate_parent > 0) { 25 $affiliate_root_query = tep_db_query("select affiliate_root, affiliate_rgt, affiliate_lft from " . TABLE_AFFILIATE . " where affiliate_id = '" . $affiliate_parent . "' "); 26 // Check if we have a parent affiliate 27 if ($affiliate_root_array = tep_db_fetch_array($affiliate_root_query)) { 28 tep_db_query("update " . TABLE_AFFILIATE . " SET affiliate_lft = affiliate_lft + 2 WHERE affiliate_root = '" . $affiliate_root_array['affiliate_root'] . "' and affiliate_lft > " . $affiliate_root_array['affiliate_rgt'] . " AND affiliate_rgt >= " . $affiliate_root_array['affiliate_rgt'] . " "); 29 tep_db_query("update " . TABLE_AFFILIATE . " SET affiliate_rgt = affiliate_rgt + 2 WHERE affiliate_root = '" . $affiliate_root_array['affiliate_root'] . "' and affiliate_rgt >= " . $affiliate_root_array['affiliate_rgt'] . " "); 30 31 32 $sql_data_array['affiliate_root'] = $affiliate_root_array['affiliate_root']; 33 $sql_data_array['affiliate_lft'] = $affiliate_root_array['affiliate_rgt']; 34 $sql_data_array['affiliate_rgt'] = ($affiliate_root_array['affiliate_rgt'] + 1); 35 tep_db_perform(TABLE_AFFILIATE, $sql_data_array); 36 $affiliate_id = tep_db_insert_id(); 37 } 38 // no parent -> new root 39 } else { 40 $sql_data_array['affiliate_lft'] = '1'; 41 $sql_data_array['affiliate_rgt'] = '2'; 42 tep_db_perform(TABLE_AFFILIATE, $sql_data_array); 43 $affiliate_id = tep_db_insert_id(); 44 tep_db_query ("update " . TABLE_AFFILIATE . " set affiliate_root = '" . $affiliate_id . "' where affiliate_id = '" . $affiliate_id . "' "); 45 } 46 // UNLOCK TABLES 47 tep_db_query("UNLOCK TABLES"); 48 return $affiliate_id; 49 50 } 51 52 53 54 //// 55 // Compatibility to older Snapshots 56 if (!function_exists('tep_round')) { 57 function tep_round($value, $precision) { 58 if (PHP_VERSION < 4) { 59 $exp = pow(10, $precision); 60 return round($value * $exp) / $exp; 61 } else { 62 return round($value, $precision); 63 } 64 } 65 } 66 67 //// 68 // Output a form 69 if (!function_exists('tep_draw_form')) { 70 function tep_draw_form($name, $action, $method = 'post', $parameters = '') { 71 $form = '<form name="' . tep_parse_input_field_data($name, array('"' => '"')) . '" action="' . tep_parse_input_field_data($action, array('"' => '"')) . '" method="' . tep_parse_input_field_data($method, array('"' => '"')) . '"'; 72 73 if (tep_not_null($parameters)) $form .= ' ' . $parameters; 74 75 $form .= '>'; 76 77 return $form; 78 } 79 } 80 81 //// 82 // This funstion validates a plain text password with an encrpyted password 83 if (!function_exists('tep_validate_password')) { 84 function tep_validate_password($plain, $encrypted) { 85 if (tep_not_null($plain) && tep_not_null($encrypted)) { 86 // split apart the hash / salt 87 $stack = explode(':', $encrypted); 88 89 if (sizeof($stack) != 2) return false; 90 91 if (md5($stack[1] . $plain) == $stack[0]) { 92 return true; 93 } 94 } 95 96 return false; 97 } 98 } 99 100 //// 101 // This function makes a new password from a plaintext password. 102 if (!function_exists('tep_encrypt_password')) { 103 function tep_encrypt_password($plain) { 104 $password = ''; 105 106 for ($i=0; $i<10; $i++) { 107 $password .= tep_rand(); 108 } 109 110 $salt = substr(md5($password), 0, 2); 111 112 $password = md5($salt . $plain) . ':' . $salt; 113 114 return $password; 115 } 116 } 117 118 //// 119 // Return a random value 120 if (!function_exists('tep_rand')) { 121 function tep_rand($min = null, $max = null) { 122 static $seeded; 123 124 if (!isset($seeded)) { 125 mt_srand((double)microtime()*1000000); 126 $seeded = true; 127 } 128 129 if (isset($min) && isset($max)) { 130 if ($min >= $max) { 131 return $min; 132 } else { 133 return mt_rand($min, $max); 134 } 135 } else { 136 return mt_rand(); 137 } 138 } 139 } 140 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Jan 1 13:43:16 2010 | Cross-referenced by PHPXref 0.7 |