[ PHPXref.com ] [ Generated: Sun Jul 20 19:13:40 2008 ] [ osCommRes 1.2.0 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/includes/functions/ -> affiliate_functions.php (source)

   1  <?php
   2  /*

   3  

   4    osCommerce, Open Source E-Commerce Solutions

   5    http://www.oscommerce.com

   6  

   7    Copyright (c) 2003 osCommerce

   8    

   9    osCommRes, Services Online

  10    http://www.oscommres.com

  11  

  12    Copyright (c) 2005 osCommRes

  13  

  14    Released under the GNU General Public License

  15  */
  16    function affiliate_check_url($url) {
  17      return eregi("^https?://[a-z0-9]([-_.]?[a-z0-9])+[.][a-z0-9][a-z0-9/=?.&\~_-]+$",$url);
  18    }
  19  
  20    function affiliate_insert ($sql_data_array, $affiliate_parent = 0) {
  21      // LOCK TABLES

  22      tep_db_query("LOCK TABLES " . TABLE_AFFILIATE . " WRITE");
  23      if ($affiliate_parent > 0) {
  24        $affiliate_root_query = tep_db_query("select affiliate_root, affiliate_rgt, affiliate_lft from  " . TABLE_AFFILIATE . " where affiliate_id = '" . $affiliate_parent . "' ");
  25        // Check if we have a parent affiliate

  26        if ($affiliate_root_array = tep_db_fetch_array($affiliate_root_query)) {
  27          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'] . " ");
  28          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'] . "  ");
  29        
  30  
  31          $sql_data_array['affiliate_root'] = $affiliate_root_array['affiliate_root'];
  32          $sql_data_array['affiliate_lft'] = $affiliate_root_array['affiliate_rgt'];
  33          $sql_data_array['affiliate_rgt'] = ($affiliate_root_array['affiliate_rgt'] + 1);
  34          tep_db_perform(TABLE_AFFILIATE, $sql_data_array);
  35          $affiliate_id = tep_db_insert_id();
  36        }
  37      // no parent -> new root

  38      } else {
  39        $sql_data_array['affiliate_lft'] = '1';
  40        $sql_data_array['affiliate_rgt'] = '2';
  41        tep_db_perform(TABLE_AFFILIATE, $sql_data_array);
  42        $affiliate_id = tep_db_insert_id();
  43        tep_db_query ("update " . TABLE_AFFILIATE . " set affiliate_root = '" . $affiliate_id . "' where affiliate_id = '" . $affiliate_id . "' ");
  44      }
  45      // UNLOCK TABLES

  46      tep_db_query("UNLOCK TABLES");
  47      return $affiliate_id;
  48  
  49    }
  50  
  51  
  52  
  53  ////

  54  // Compatibility to older Snapshots

  55    if (!function_exists('tep_round')) {
  56      function tep_round($value, $precision) {
  57        if (PHP_VERSION < 4) {
  58          $exp = pow(10, $precision);
  59          return round($value * $exp) / $exp;
  60        } else {
  61          return round($value, $precision);
  62        }
  63      }
  64    }
  65  
  66  ////

  67  // Output a form

  68    if (!function_exists('tep_draw_form')) {
  69      function tep_draw_form($name, $action, $method = 'post', $parameters = '') {
  70        $form = '<form name="' . tep_parse_input_field_data($name, array('"' => '&quot;')) . '" action="' . tep_parse_input_field_data($action, array('"' => '&quot;')) . '" method="' . tep_parse_input_field_data($method, array('"' => '&quot;')) . '"';
  71  
  72        if (tep_not_null($parameters)) $form .= ' ' . $parameters;
  73  
  74        $form .= '>';
  75  
  76        return $form;
  77      }
  78    }
  79  
  80  ////

  81  // This funstion validates a plain text password with an encrpyted password

  82    if (!function_exists('tep_validate_password')) {
  83      function tep_validate_password($plain, $encrypted) {
  84        if (tep_not_null($plain) && tep_not_null($encrypted)) {
  85  // split apart the hash / salt

  86          $stack = explode(':', $encrypted);
  87  
  88          if (sizeof($stack) != 2) return false;
  89  
  90          if (md5($stack[1] . $plain) == $stack[0]) {
  91            return true;
  92          }
  93        }
  94  
  95        return false;
  96      }
  97    }
  98  
  99  ////

 100  // This function makes a new password from a plaintext password. 

 101    if (!function_exists('tep_encrypt_password')) {
 102      function tep_encrypt_password($plain) {
 103        $password = '';
 104  
 105        for ($i=0; $i<10; $i++) {
 106          $password .= tep_rand();
 107        }
 108  
 109        $salt = substr(md5($password), 0, 2);
 110  
 111        $password = md5($salt . $plain) . ':' . $salt;
 112  
 113        return $password;
 114      }
 115    }
 116  
 117  ////

 118  // Return a random value

 119    if (!function_exists('tep_rand')) {
 120      function tep_rand($min = null, $max = null) {
 121        static $seeded;
 122  
 123        if (!isset($seeded)) {
 124          mt_srand((double)microtime()*1000000);
 125          $seeded = true;
 126        }
 127  
 128        if (isset($min) && isset($max)) {
 129          if ($min >= $max) {
 130            return $min;
 131          } else {
 132            return mt_rand($min, $max);
 133          }
 134        } else {
 135          return mt_rand();
 136        }
 137      }
 138    }
 139  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]