コード例 #1
0
ファイル: update.class.php プロジェクト: noikiy/owaspbwa
 /**
  * Deletes the Patch Package File and its extracted contents
  *
  * @param array $d
  * @return boolean
  */
 function removePackageFile(&$d)
 {
     global $vm_mainframe, $vmLogger;
     $packageFile = vmGet($_SESSION, 'vm_updatepackage');
     if (empty($packageFile) || !file_exists($packageFile)) {
         return true;
     }
     $packageDir = vmUpdate::getPackageDir($packageFile);
     if (!empty($packageDir)) {
         $result = vmRemoveDirectoryR($packageDir);
         if (!$result) {
             $vmLogger->err('Failed to remove the Directory of the Patch Package');
         }
         $result = @unlink($packageFile);
         if (!$result) {
             $vmLogger->err('Failed to remove the Patch Package File');
             return false;
         }
         unset($_SESSION['vm_updatepackage']);
         unset($_SESSION['vmLatestVersion']);
     }
     if (vmIsXHR()) {
         $vm_mainframe->addResponseScript('parent.loadPage("' . $GLOBALS['sess']->url($_SERVER['PHP_SELF'] . '?page=admin.update_check', false, false) . '");');
     }
     return true;
 }
コード例 #2
0
ファイル: ps_cart.php プロジェクト: rafarubert/megafiltros
 /**
  * adds an item to the shopping cart
  * @author pablo
  * @param array $d
  */
 function add(&$d)
 {
     global $sess, $VM_LANG, $cart, $vmLogger, $func;
     $d = $GLOBALS['vmInputFilter']->process($d);
     include_class("product");
     $db = new ps_DB();
     $ci = 0;
     $request_stock = "";
     $total_quantity = 0;
     $total_updated = 0;
     $total_deleted = 0;
     $_SESSION['last_page'] = "shop.product_details";
     if (!empty($d['product_id']) && !isset($d["prod_id"])) {
         if (empty($d['prod_id'])) {
             $d['prod_id'] = array();
         }
         if (is_array($d['product_id'])) {
             $d['prod_id'] = array_merge($d['prod_id'], $d['product_id']);
         } else {
             $d['prod_id'] = array_merge($d['prod_id'], array($d['product_id']));
         }
     }
     //Check to see if a prod_id has been set
     if (!isset($d["prod_id"])) {
         return true;
     }
     $multiple_products = sizeof($d["prod_id"]);
     //Iterate through the prod_id's and perform an add to cart for each one
     for ($ikey = 0; $ikey < $multiple_products; $ikey++) {
         // Create single array from multi array
         $key_fields = array_keys($d);
         foreach ($key_fields as $key) {
             if (is_array($d[$key])) {
                 $e[$key] = @$d[$key][$ikey];
             } else {
                 $e[$key] = $d[$key];
             }
         }
         if ($multiple_products > 1) {
             $func = "cartUpdate";
         }
         $e['product_id'] = $d['product_id'];
         $e['Itemid'] = $d['Itemid'];
         if (is_array($d["prod_id"])) {
             $product_id = $d["prod_id"][$ikey];
         } else {
             $product_id = $e["prod_id"];
         }
         if (is_array($d["quantity"])) {
             $quantity = @$d['quantity'][$ikey];
         } else {
             $quantity = @$e['quantity'];
         }
         // Check for negative quantity
         if ($quantity < 0) {
             vmRequest::setVar('product_id', $product_id);
             $vmLogger->warning($VM_LANG->_('PHPSHOP_CART_ERROR_NO_NEGATIVE', false));
             return False;
         }
         if (!is_numeric($quantity)) {
             vmRequest::setVar('product_id', $product_id);
             $vmLogger->warning($VM_LANG->_('PHPSHOP_CART_ERROR_NO_VALID_QUANTITY', false));
             return False;
         }
         $quantity = intval($quantity);
         // Check to see if checking stock quantity
         if (CHECK_STOCK) {
             $product_in_stock = ps_product::get_field($product_id, 'product_in_stock');
             if (empty($product_in_stock)) {
                 $product_in_stock = 0;
             }
             if ($quantity > $product_in_stock) {
                 //Create an array for out of stock items and continue to next item
                 $request_stock[$ci]['product_id'] = $product_id;
                 $request_stock[$ci]['quantity'] = $quantity;
                 $ci++;
                 continue;
             }
         }
         // Check if product exists and is published
         if (!ps_product::product_exists($product_id)) {
             $vmLogger->tip($VM_LANG->_('VM_CART_PRODUCT_NOTEXIST', false));
             return false;
         }
         // Quick add of item
         $q = "SELECT product_id FROM #__{vm}_product WHERE ";
         $q .= "product_parent_id = " . (int) $product_id;
         $db->query($q);
         if ($db->num_rows()) {
             vmRequest::setVar('product_id', $e["product_id"]);
             $vmLogger->tip($VM_LANG->_('PHPSHOP_CART_SELECT_ITEM', false));
             $_REQUEST['flypage'] = ps_product::get_flypage($e["product_id"]);
             $GLOBALS['page'] = 'shop.product_details';
             return true;
         }
         // Check to see if we already have it
         $updated = 0;
         $result = ps_product_attribute::cartGetAttributes($e);
         if ($result["attribute_given"] == false && !empty($result["advanced_attribute_list"]) || $multiple_products == 1 && ($result["custom_attribute_given"] == false && !empty($result["custom_attribute_list"]))) {
             $_REQUEST['flypage'] = ps_product::get_flypage($product_id);
             $GLOBALS['page'] = 'shop.product_details';
             $vmLogger->tip($VM_LANG->_('PHPSHOP_CART_SELECT_ITEM', false));
             return true;
         }
         //Check for empty custom field and quantity>0 for multiple addto
         //Normally means no info added to a custom field, but once added to a cart the quantity is automatically placed
         //If another item is added and the custom field is left blank for another product already added this will just ignore that item
         if ($multiple_products != 1 && $quantity != 0 && ($result["custom_attribute_given"] == false && !empty($result["custom_attribute_list"]))) {
             $vmLogger->tip($VM_LANG->_('PHPSHOP_CART_SELECT_ITEM', false));
             continue;
         }
         // Check for duplicate and do not add to current quantity
         for ($i = 0; $i < $_SESSION["cart"]["idx"]; $i++) {
             // modified for advanced attributes
             if ($_SESSION['cart'][$i]["product_id"] == $product_id && $_SESSION['cart'][$i]["description"] == $e["description"]) {
                 $updated = 1;
             }
         }
         list($min, $max) = ps_product::product_order_levels($product_id);
         if ($min != 0 && $quantity != 0 && $quantity < $min) {
             eval("\$msg = \"" . $VM_LANG->_('VM_CART_MIN_ORDER', false) . "\";");
             $vmLogger->warning($msg);
             continue;
         }
         if ($max != 0 && $quantity != 0 && $quantity > $max) {
             eval("\$msg = \"" . $VM_LANG->_('VM_CART_MAX_ORDER', false) . "\";");
             $vmLogger->warning($msg);
             continue;
         }
         // If we did not update then add the item
         if (!$updated && $quantity) {
             $k = $_SESSION['cart']["idx"];
             $_SESSION['cart'][$k]["quantity"] = $quantity;
             $_SESSION['cart'][$k]["product_id"] = $product_id;
             $_SESSION['cart'][$k]["parent_id"] = $e["product_id"];
             $_SESSION['cart'][$k]["category_id"] = vmGet($e, 'category_id', 0);
             // added for the advanced attribute modification
             $_SESSION['cart'][$k]["description"] = $e["description"];
             $_SESSION['cart']["idx"]++;
             $total_quantity += $quantity;
         } else {
             list($updated_prod, $deleted_prod) = $this->update($e);
             $total_updated += $updated_prod;
             $total_deleted += $deleted_prod;
         }
         /* next 3 lines added by Erich for coupon code */
         /* if the cart was updated we gotta update any coupon discounts to avoid ppl getting free stuff */
         if (!empty($_SESSION['coupon_discount'])) {
             // Update the Coupon Discount !!
             require_once CLASSPATH . 'ps_coupon.php';
             ps_coupon::process_coupon_code($d);
         }
     }
     // End Iteration through Prod id's
     $cart = $_SESSION['cart'];
     ps_cart::saveCart();
     // Ouput info message with cart update details /*
     if ($total_quantity != 0 || $total_updated != 0 || $total_deleted != 0) {
         if ($total_quantity > 0 && $total_updated == 0) {
             $msg = $VM_LANG->_('VM_CART_PRODUCT_ADDED', false);
         } else {
             $msg = $VM_LANG->_('VM_CART_PRODUCT_UPDATED', false);
         }
         // Comment out the following line to turn off msg i.e. //$vmLogger->tip( $msg );
         $vmLogger->info($msg);
     } else {
         if (@$request_stock) {
             $vmLogger->tip($VM_LANG->_('PHPSHOP_CART_GOTO_WAITING_LIST', false));
         } elseif ($total_quantity == 0) {
             vmRequest::setVar('product_id', $product_id);
             $GLOBALS['last_page'] = 'shop.product_details';
             $vmLogger->warning($VM_LANG->_('PHPSHOP_CART_ERROR_NO_VALID_QUANTITY', false));
             return false;
         } else {
             $vmLogger->tip($VM_LANG->_('PHPSHOP_CART_QUANTITY_EXCEEDED', false));
         }
     }
     // end cart update message */
     // Perform notification of out of stock items
     if (@$request_stock) {
         global $notify;
         $_SESSION['notify'] = array();
         $_SESSION['notify']['idx'] = 0;
         $k = 0;
         $notify = $_SESSION['notify'];
         foreach ($request_stock as $request) {
             $_SESSION['notify'][$k]["prod_id"] = $request['product_id'];
             $_SESSION['notify'][$k]["quantity"] = $request['quantity'];
             $_SESSION['notify']['idx']++;
             $k++;
         }
         if (vmIsXHR()) {
             $GLOBALS['vm_mainframe']->scriptRedirect($sess->url('index.php?page=shop.waiting_list&product_id=' . $product_id, true, false));
         } else {
             vmRedirect($sess->url('index.php?page=shop.waiting_list&product_id=' . $product_id, true, false));
         }
     }
     return True;
 }