[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/admin/includes/ -> add_ccgvdc_application_top.php (source)

   1  <?php
   2    define('FILENAME_GV_QUEUE', 'gv_queue.php');
   3    define('FILENAME_GV_MAIL', 'gv_mail.php');
   4    define('FILENAME_GV_SENT', 'gv_sent.php');
   5    define('FILENAME_COUPON_ADMIN', 'coupon_admin.php');
   6  
   7    define('TABLE_COUPON_GV_QUEUE', 'coupon_gv_queue');
   8    define('TABLE_COUPON_GV_CUSTOMER', 'coupon_gv_customer');
   9    define('TABLE_COUPON_EMAIL_TRACK', 'coupon_email_track');
  10    define('TABLE_COUPON_REDEEM_TRACK', 'coupon_redeem_track');
  11    define('TABLE_COUPONS', 'coupons');
  12    define('TABLE_COUPONS_DESCRIPTION', 'coupons_description');
  13  
  14  // Below are some defines which affect the way the discount coupon/gift voucher system work
  15  // Be careful when editing them.
  16  //
  17  // Set the length of the redeem code, the longer the more secure
  18  
  19    define('SECURITY_CODE_LENGTH', '6');
  20  
  21  ////
  22  // Create a Coupon Code. length may be between 1 and 16 Characters
  23  // $salt needs some thought.
  24  
  25    function create_coupon_code($salt="secret", $length=SECURITY_CODE_LENGTH) {
  26      $ccid = md5(uniqid("","salt"));
  27      $ccid .= md5(uniqid("","salt"));
  28      $ccid .= md5(uniqid("","salt"));
  29      $ccid .= md5(uniqid("","salt"));
  30      srand((double)microtime()*1000000); // seed the random number generator
  31      $random_start = @rand(0, (128-$length));
  32      $good_result = 0;
  33      while ($good_result == 0) {
  34        $id1=substr($ccid, $random_start,$length);        
  35        $query = tep_db_query("select coupon_code from " . TABLE_COUPONS . " where coupon_code = '" . $id1 . "'");    
  36        if (tep_db_num_rows($query) == 0) $good_result = 1;
  37      }
  38      return $id1;
  39    }
  40  ////
  41  // Update the Customers GV account
  42    function tep_gv_account_update($customer_id, $gv_id) {
  43      $customer_gv_query = tep_db_query("select amount from " . TABLE_COUPON_GV_CUSTOMER . " where customer_id = '" . $customer_id . "'");
  44      $coupon_gv_query = tep_db_query("select coupon_amount from " . TABLE_COUPONS . " where coupon_id = '" . $gv_id . "'");
  45      $coupon_gv = tep_db_fetch_array($coupon_gv_query);
  46      if (tep_db_num_rows($customer_gv_query) > 0) {
  47        $customer_gv = tep_db_fetch_array($customer_gv_query);
  48        $new_gv_amount = $customer_gv['amount'] + $coupon_gv['coupon_amount'];
  49        $gv_query = tep_db_query("update " . TABLE_COUPON_GV_CUSTOMER . " set amount = '" . $new_gv_amount . "' where customer_id = '" . $customer_id . "'");
  50      } else {
  51        $gv_query = tep_db_query("insert into " . TABLE_COUPON_GV_CUSTOMER . " (customer_id, amount) values ('" . $customer_id . "', '" . $coupon_gv['coupon_amount'] . "')");
  52      }
  53    }
  54  ////
  55  // Output a day/month/year dropdown selector
  56    function tep_draw_date_selector($prefix, $date='') {
  57      $month_array = array();
  58      $month_array[1] =_JANUARY;
  59      $month_array[2] =_FEBRUARY;
  60      $month_array[3] =_MARCH;
  61      $month_array[4] =_APRIL;
  62      $month_array[5] =_MAY;
  63      $month_array[6] =_JUNE;
  64      $month_array[7] =_JULY;
  65      $month_array[8] =_AUGUST;
  66      $month_array[9] =_SEPTEMBER;
  67      $month_array[10] =_OCTOBER;
  68      $month_array[11] =_NOVEMBER;
  69      $month_array[12] =_DECEMBER;
  70      $usedate = getdate($date);
  71      $day = $usedate['mday'];
  72      $month = $usedate['mon'];
  73      $year = $usedate['year'];        
  74      $date_selector = '<select name="'. $prefix .'_day">';
  75      for ($i=1;$i<32;$i++){
  76        $date_selector .= '<option value="' . $i . '"';
  77        if ($i==$day) $date_selector .= 'selected';
  78        $date_selector .= '>' . $i . '</option>';
  79      }
  80      $date_selector .= '</select>';
  81      $date_selector .= '<select name="'. $prefix .'_month">';
  82      for ($i=1;$i<13;$i++){
  83        $date_selector .= '<option value="' . $i . '"';
  84        if ($i==$month) $date_selector .= 'selected';      
  85        $date_selector .= '>' . $month_array[$i] . '</option>';
  86      }
  87      $date_selector .= '</select>';
  88      $date_selector .= '<select name="'. $prefix .'_year">';
  89      for ($i=2001;$i<2019;$i++){
  90        $date_selector .= '<option value="' . $i . '"';
  91        if ($i==$year) $date_selector .= 'selected';
  92        $date_selector .= '>' . $i . '</option>';
  93      }
  94      $date_selector .= '</select>';
  95      return $date_selector;
  96    }
  97  ?>


Generated: Fri Jan 1 13:43:16 2010 Cross-referenced by PHPXref 0.7