Esempio n. 1
0
 /**
  * Validates product fields and uploaded image files.
  *
  * @param array $d The input vars
  * @return boolean True when validation successful, false when not
  */
 function validate(&$d)
 {
     global $vmLogger, $database, $perm, $VM_LANG;
     require_once CLASSPATH . 'imageTools.class.php';
     $valid = true;
     $db = new ps_DB();
     $q = "SELECT product_id,product_thumb_image,product_full_image FROM #__{vm}_product WHERE product_sku='";
     $q .= $d["product_sku"] . "'";
     $db->setQuery($q);
     $db->query();
     if ($db->next_record() && $db->f("product_id") != $d["product_id"]) {
         $vmLogger->err("A Product with the SKU " . $d['product_sku'] . " already exists.");
         $valid = false;
     }
     if (!empty($d['product_discount_id'])) {
         if ($d['product_discount_id'] == "override") {
             $d['is_percent'] = "0";
             // If discount are applied before tax then base the discount on the untaxed price
             if (PAYMENT_DISCOUNT_BEFORE == '1') {
                 $d['amount'] = (double) $d['product_price'] - (double) $d['discounted_price_override'];
             } else {
                 $d['amount'] = (double) $d['product_price_incl_tax'] - (double) $d['discounted_price_override'];
             }
             // Set the discount start date as today
             $d['start_date'] = date('Y-m-d');
             require_once CLASSPATH . 'ps_product_discount.php';
             $ps_product_discount = new ps_product_discount();
             $ps_product_discount->add($d);
             $d['product_discount_id'] = $database->insertid();
             vmRequest::setVar('product_discount_id', $d['product_discount_id']);
         }
     }
     if (empty($d['manufacturer_id'])) {
         $d['manufacturer_id'] = "1";
     }
     if (empty($d["product_sku"])) {
         $vmLogger->err($VM_LANG->_('VM_PRODUCT_MISSING_SKU', false));
         $valid = false;
     }
     if (!$d["product_name"]) {
         $vmLogger->err($VM_LANG->_('VM_PRODUCT_MISSING_NAME', false));
         $valid = false;
     }
     if (empty($d["product_available_date"])) {
         $vmLogger->err($VM_LANG->_('VM_PRODUCT_MISSING_AVAILDATE', false));
         $valid = false;
     } else {
         $day = (int) substr($d["product_available_date"], 8, 2);
         $month = (int) substr($d["product_available_date"], 5, 2);
         $year = (int) substr($d["product_available_date"], 0, 4);
         $d["product_available_date_timestamp"] = mktime(0, 0, 0, $month, $day, $year);
     }
     /** Validate Product Specific Fields **/
     if (!$d["product_parent_id"]) {
         if (empty($d['product_categories']) || !is_array(@$d['product_categories'])) {
             $d['product_categories'] = explode('|', $d['category_ids']);
         }
         if (sizeof(@$d["product_categories"]) < 1) {
             $vmLogger->err($VM_LANG->_('VM_PRODUCT_MISSING_CATEGORY'));
             $valid = false;
         }
     }
     /** Image Upload Validation **/
     // do we have an image URL or an image File Upload?
     if (!empty($d['product_thumb_image_url'])) {
         // Image URL
         if (substr($d['product_thumb_image_url'], 0, 4) != "http") {
             $vmLogger->err($VM_LANG->_('VM_PRODUCT_IMAGEURL_MUSTBEGIN', false));
             $valid = false;
         }
         // if we have an uploaded image file, prepare this one for deleting.
         if ($db->f("product_thumb_image") && substr($db->f("product_thumb_image"), 0, 4) != "http") {
             $_REQUEST["product_thumb_image_curr"] = $db->f("product_thumb_image");
             $d["product_thumb_image_action"] = "delete";
             if (!vmImageTools::validate_image($d, "product_thumb_image", "product")) {
                 return false;
             }
         }
         $d["product_thumb_image"] = $d['product_thumb_image_url'];
     } else {
         // File Upload
         if (!vmImageTools::validate_image($d, "product_thumb_image", "product")) {
             $valid = false;
         }
     }
     if (!empty($d['product_full_image_url'])) {
         // Image URL
         if (substr($d['product_full_image_url'], 0, 4) != "http") {
             $vmLogger->err($VM_LANG->_('VM_PRODUCT_IMAGEURL_MUSTBEGIN', false));
             return false;
         }
         // if we have an uploaded image file, prepare this one for deleting.
         if ($db->f("product_full_image") && substr($db->f("product_full_image"), 0, 4) != "http") {
             $_REQUEST["product_full_image_curr"] = $db->f("product_full_image");
             $d["product_full_image_action"] = "delete";
             if (!vmImageTools::validate_image($d, "product_full_image", "product")) {
                 return false;
             }
         }
         $d["product_full_image"] = $d['product_full_image_url'];
     } else {
         // File Upload
         if (!vmImageTools::validate_image($d, "product_full_image", "product")) {
             $valid = false;
         }
     }
     // validate attribute names
     foreach ($d["attributeX"] as $attributeX) {
         // if we only have one attribute it can be left empty
         if ($attributeX["name"] == "" and count($d["attributeX"]) > 1) {
             $vmLogger->err($VM_LANG->_('VM_PRODUCT_MISSING_ATTRIBUTE_NAME', false));
             $valid = false;
         }
         if (strpos($attributeX["name"], ":") or strpos($attributeX["name"], ".") or strpos($attributeX["name"], "&") or strpos($attributeX["name"], "'")) {
             $vmLogger->err($VM_LANG->_('VM_PRODUCT_INVALID_ATTRIBUTE_NAME', false));
             $valid = false;
         }
     }
     // added for advanced attribute modification
     // strips the trailing semi-colon from an attribute
     if (isset($d["product_advanced_attribute"])) {
         if (';' == substr($d["product_advanced_attribute"], strlen($d["product_advanced_attribute"]) - 1, 1)) {
             $d["product_advanced_attribute"] = substr($d["product_advanced_attribute"], 0, strlen($d["product_advanced_attribute"]) - 1);
         }
     }
     // added for custom attribute modification
     // strips the trailing semi-colon from an attribute
     if (isset($d["product_custom_attribute"])) {
         if (';' == substr($d["product_custom_attribute"], strlen($d["product_custom_attribute"]) - 1, 1)) {
             $d["product_custom_attribute"] = substr($d["product_custom_attribute"], 0, strlen($d["product_custom_attribute"]) - 1);
         }
     }
     $d["clone_product"] = empty($d["clone_product"]) ? "N" : "Y";
     $d["product_publish"] = empty($d["product_publish"]) ? "N" : "Y";
     $d["product_special"] = empty($d["product_special"]) ? "N" : "Y";
     //parse quantity and child options
     $d['display_headers'] = vmGet($d, 'display_headers', 'Y') == 'Y' ? 'Y' : 'N';
     $d['product_list_child'] = vmGet($d, 'product_list_child', 'Y') == 'Y' ? 'Y' : 'N';
     $d['display_use_parent'] = vmGet($d, 'display_use_parent', 'Y') == 'Y' ? 'Y' : 'N';
     $d['product_list_type'] = vmGet($d, 'product_list_type', 'Y') == 'Y' ? 'Y' : 'N';
     $d['display_desc'] = vmGet($d, 'display_desc', 'Y') == 'Y' ? 'Y' : 'N';
     if (@$d['product_list'] == "Y") {
         if ($d['list_style'] == "one") {
             $d['product_list'] = "Y";
         } else {
             $d['product_list'] = "YM";
         }
     } else {
         $d['product_list'] = "N";
     }
     $d['quantity_options'] = ps_product::set_quantity_options($d);
     $d['child_options'] = ps_product::set_child_options($d);
     $d['order_levels'] = vmRequest::getInt('min_order_level') . "," . vmRequest::getInt('max_order_level');
     return $valid;
 }
Esempio n. 2
0
      				<td width="71%" >
	        			<?php 
require_once CLASSPATH . 'ps_tax.php';
$tax_rates = ps_tax::list_tax_value("product_tax_id", $db->sf("product_tax_id"), "updateGross();");
?>
      				</td>
    			</tr>
    			<tr class="row1"> 
      				<td width="21%" ><div style="text-align:right;font-weight:bold;">
        				<?php 
echo $VM_LANG->_('PHPSHOP_PRODUCT_FORM_DISCOUNT_TYPE');
?>
:</div>
      				</td>
      				<td width="79%" ><?php 
echo ps_product_discount::discount_list($db->sf("product_discount_id"));
?>
      				</td>
    			</tr>
    			<tr class="row0"> 
      				<td width="21%" ><div style="text-align:right;font-weight:bold;">
        			<?php 
echo $VM_LANG->_('PHPSHOP_PRODUCT_FORM_DISCOUNTED_PRICE');
?>
:</div>
      				</td>
      				<td width="79%" >
                		<input type="text" size="10" name="discounted_price_override" onchange="try { document.adminForm.product_discount_id[document.adminForm.product_discount_id.length-1].selected=true; } catch( e ) {}" />&nbsp;&nbsp;
                		<?php 
echo vmToolTip($VM_LANG->_('PHPSHOP_PRODUCT_FORM_DISCOUNTED_PRICE_TIP'));
?>