[ Index ]
 

Code source de Zen Cart E-Commerce Shopping Cart 1.3.7.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

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

   1  <?php
   2  /**

   3   * functions_gvcoupons.php

   4   * Functions related to processing Gift Vouchers/Certificates and coupons

   5   *

   6   * @package functions

   7   * @copyright Copyright 2003-2006 Zen Cart Development Team

   8   * @copyright Portions Copyright 2003 osCommerce

   9   * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0

  10   * @version $Id: functions_gvcoupons.php 4135 2006-08-14 04:25:02Z drbyte $

  11   */
  12  
  13  ////

  14  // Update the Customers GV account

  15    function zen_gv_account_update($c_id, $gv_id) {
  16      global $db;
  17      $customer_gv_query = "select amount
  18                            from " . TABLE_COUPON_GV_CUSTOMER . "
  19                            where customer_id = '" . (int)$c_id . "'";
  20  
  21      $customer_gv = $db->Execute($customer_gv_query);
  22      $coupon_gv_query = "select coupon_amount
  23                          from " . TABLE_COUPONS . "
  24                          where coupon_id = '" . (int)$gv_id . "'";
  25  
  26      $coupon_gv = $db->Execute($coupon_gv_query);
  27  
  28      if ($customer_gv->RecordCount() > 0) {
  29  
  30        $new_gv_amount = $customer_gv->fields['amount'] + $coupon_gv->fields['coupon_amount'];
  31        $gv_query = "update " . TABLE_COUPON_GV_CUSTOMER . "
  32                     set amount = '" . $new_gv_amount . "' where customer_id = '" . (int)$c_id . "'";
  33  
  34        $db->Execute($gv_query);
  35  
  36      } else {
  37  
  38        $gv_query = "insert into " . TABLE_COUPON_GV_CUSTOMER . "
  39                                     (customer_id, amount)
  40                            values ('" . (int)$c_id . "', '" . $coupon_gv->fields['coupon_amount'] . "')";
  41  
  42        $db->Execute($gv_query);
  43      }
  44    }
  45  
  46      function zen_user_has_gv_account($c_id) {
  47        global $db;
  48        if ($_SESSION['customer_id']) {
  49          $gv_result = $db->Execute("select amount from " . TABLE_COUPON_GV_CUSTOMER . " where customer_id = '" . (int)$c_id . "'");
  50          if ($gv_result->RecordCount() > 0) {
  51            if ($gv_result->fields['amount'] > 0) {
  52              return $gv_result->fields['amount'];
  53            }
  54          }
  55          return '0.00';
  56        } else {
  57          return '0.00';
  58        }
  59      }
  60  
  61  ////

  62  // Create a Coupon Code. length may be between 1 and 16 Characters

  63  // $salt needs some thought.

  64  
  65    function zen_create_coupon_code($salt="secret", $length = SECURITY_CODE_LENGTH) {
  66      global $db;
  67      $ccid = md5(uniqid("","salt"));
  68      $ccid .= md5(uniqid("","salt"));
  69      $ccid .= md5(uniqid("","salt"));
  70      $ccid .= md5(uniqid("","salt"));
  71      srand((double)microtime()*1000000); // seed the random number generator

  72      $random_start = @rand(0, (128-$length));
  73      $good_result = 0;
  74      while ($good_result == 0) {
  75        $id1=substr($ccid, $random_start,$length);
  76        $query = "select coupon_code
  77                  from " . TABLE_COUPONS . "
  78                  where coupon_code = '" . $id1 . "'";
  79  
  80        $rs = $db->Execute($query);
  81  
  82        if ($rs->RecordCount() == 0) $good_result = 1;
  83      }
  84      return $id1;
  85    }
  86  ?>


Généré le : Mon Nov 26 16:45:43 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics