Esempio n. 1
0
 /**
  * Adds a new Vendor Category
  *
  * @param array $d
  * @return boolean
  */
 function add(&$d)
 {
     $db = new ps_DB();
     if (!$this->validate_add($d)) {
         return False;
     }
     $fields = array('vendor_category_name' => $d["vendor_category_name"], 'vendor_category_desc' => $d["vendor_category_desc"]);
     $db->buildQuery('INSERT', '#__{vm}_vendor_category', $fields);
     $res = $db->query();
     if ($res !== false) {
         $_REQUEST['vendor_category_id'] = $db->last_insert_id();
         $GLOBALS['vmLogger']->info('The Vendor Category has been added.');
         return true;
     }
     $GLOBALS['vmLogger']->err('Failed to add the Vendor Category.');
     return false;
 }
Esempio n. 2
0
 function add(&$d)
 {
     $db = new ps_DB();
     $ps_vendor_id = $_SESSION["ps_vendor_id"];
     $timestamp = time();
     if (!$this->validate_add($d)) {
         return False;
     }
     foreach ($d as $key => $value) {
         $d[$key] = addslashes($value);
     }
     $q = "INSERT INTO #__{vm}_zone_shipping (zone_name, zone_cost, ";
     $q .= "zone_limit, zone_description, zone_tax_rate) VALUES ('";
     $q .= $d["zone_name"] . "','";
     $q .= $d["zone_cost"] . "','";
     $q .= $d["zone_limit"] . "','";
     $q .= $d["zone_description"] . "','";
     $q .= $d["zone_tax_rate"] . "')";
     $db->query($q);
     $db->next_record();
     $_REQUEST['zone_id'] = $db->last_insert_id();
     return True;
 }
Esempio n. 3
0
 /**
  * creates a new discount record
  *
  * @param array $d
  * @return boolean
  */
 function add(&$d)
 {
     global $VM_LANG;
     $db = new ps_DB();
     if (!empty($d["start_date"])) {
         $day = substr($d["start_date"], 8, 2);
         $month = substr($d["start_date"], 5, 2);
         $year = substr($d["start_date"], 0, 4);
         $d["start_date"] = mktime(0, 0, 0, $month, $day, $year);
     } else {
         $d["start_date"] = 0;
     }
     if (!empty($d["end_date"])) {
         $day = substr($d["end_date"], 8, 2);
         $month = substr($d["end_date"], 5, 2);
         $year = substr($d["end_date"], 0, 4);
         $d["end_date"] = mktime(0, 0, 0, $month, $day, $year);
     } else {
         $d["end_date"] = 0;
     }
     if (!$this->validate_add($d)) {
         return False;
     }
     $fields = array('amount' => (double) vmGet($d, 'amount'), 'is_percent' => (int) vmGet($d, 'is_percent'), 'start_date' => $d["start_date"], 'end_date' => $d["end_date"]);
     $db->buildQuery('INSERT', '#__{vm}_product_discount', $fields);
     $db->query();
     $GLOBALS['vmLogger']->info($VM_LANG->_('VM_PRODUCT_DISCOUNT_ADDED'));
     $_REQUEST['discount_id'] = $db->last_insert_id();
     return True;
 }
Esempio n. 4
0
 /**
  * Creates a new tax record
  * @author pablo
  *
  * @param arry $d The _REQUEST array
  * @return boolean True on success, false on failure
  */
 function add(&$d)
 {
     global $VM_LANG;
     $db = new ps_DB();
     $ps_vendor_id = $_SESSION["ps_vendor_id"];
     $timestamp = time();
     if (!$this->validate_add($d)) {
         return False;
     }
     $fields = array('vendor_id' => $ps_vendor_id, 'tax_state' => vmget($d, 'tax_state'), 'tax_country' => vmget($d, 'tax_country'), 'tax_rate' => $d["tax_rate"], 'mdate' => $timestamp);
     $db->buildQuery('INSERT', $this->getTable(), $fields);
     if ($db->query() !== false) {
         $_REQUEST['tax_rate_id'] = $db->last_insert_id();
         $GLOBALS['vmLogger']->info($VM_LANG->_('VM_TAX_ADDED'));
         return True;
     }
     $GLOBALS['vmLogger']->err($VM_LANG->_('VM_TAX_ADD_FAILED'));
     return false;
 }
Esempio n. 5
0
 /**
  * Creates a new function record
  * @author pablo, soeren
  *
  * @param array $d
  * @return boolean
  */
 function add(&$d)
 {
     $db = new ps_DB();
     $timestamp = time();
     if (!$this->validate_add($d)) {
         return False;
     }
     if (is_array($d['function_perms'])) {
         $d['function_perms'] = implode(',', $d['function_perms']);
     }
     $fields = array('function_name' => vmGet($d, 'function_name'), 'function_class' => vmGet($d, 'function_class'), 'function_method' => vmGet($d, 'function_method'), 'function_perms' => vmGet($d, 'function_perms'), 'module_id' => vmRequest::getInt('module_id'), 'function_description' => vmGet($d, 'function_description'));
     $db->buildQuery('INSERT', '#__{vm}_function', $fields);
     $db->query();
     $_REQUEST['function_id'] = $db->last_insert_id();
     return True;
 }
Esempio n. 6
0
 /**
  * Adds a Vendor Record
  *
  * @param array $d
  * @return boolean
  */
 function add(&$d)
 {
     global $vendor_currency;
     $db = new ps_DB();
     $timestamp = time();
     if (!$this->validate_add($d)) {
         return False;
     }
     if (!vmImageTools::process_images($d)) {
         return false;
     }
     $d['display_style'][1] = ps_vendor::checkCurrencySymbol($d['display_style'][1]);
     $d['display_style'] = implode("|", $d['display_style']);
     if (empty($d['vendor_accepted_currencies'])) {
         $d['vendor_accepted_currencies'] = array($vendor_currency);
     }
     $fields = array('vendor_name' => $d["vendor_name"], 'contact_last_name' => $d["contact_last_name"], 'contact_first_name' => $d["contact_first_name"], 'contact_middle_name' => $d["contact_middle_name"], 'contact_title' => $d["contact_title"], 'contact_phone_1' => $d["contact_phone_1"], 'contact_phone_2' => $d["contact_phone_2"], 'contact_fax' => $d["contact_fax"], 'contact_email' => $d["contact_email"], 'vendor_phone' => $d["vendor_phone"], 'vendor_address_1' => $d["vendor_address_1"], 'vendor_address_2' => $d["vendor_address_2"], 'vendor_city' => $d["vendor_city"], 'vendor_state' => $d["vendor_state"], 'vendor_country' => $d["vendor_country"], 'vendor_zip' => $d["vendor_zip"], 'vendor_store_name' => $d["vendor_store_name"], 'vendor_store_desc' => $d["vendor_store_desc"], 'vendor_category_id' => $d["vendor_category_id"], 'vendor_image_path' => $d["vendor_image_path"], 'vendor_thumb_image' => $d["vendor_thumb_image"], 'vendor_full_image' => $d["vendor_full_image"], 'vendor_currency' => $d["vendor_currency"], 'vendor_url' => $d["vendor_url"], 'cdate' => $timestamp, 'mdate' => $timestamp, 'vendor_terms_of_service' => $d["vendor_terms_of_service"], 'vendor_min_pov' => $d["vendor_min_pov"], 'vendor_currency_display_style' => $d["display_style"], 'vendor_freeshipping' => $d['vendor_freeshipping'], 'vendor_accepted_currencies' => implode(',', $d['vendor_accepted_currencies']), 'vendor_address_format' => $d['vendor_address_format'], 'vendor_date_format' => $d['vendor_date_format']);
     $db->buildQuery('INSERT', '#__{vm}_vendor', $fields);
     $db->query();
     // Get the assigned vendor_id //
     $_REQUEST['vendor_id'] = $db->last_insert_id();
     $GLOBALS['vmLogger']->info('The Vendor has been added.');
     /* Insert default- shopper group */
     $q = "INSERT INTO #__{vm}_shopper_group (";
     $q .= "`vendor_id`,";
     $q .= "`shopper_group_name`,";
     $q .= "`shopper_group_desc`,`default`) VALUES ('";
     $q .= $d["vendor_id"] . "',";
     $q .= "'-default-',";
     $q .= "'Default shopper group for " . $d["vendor_name"] . "','1')";
     $db->query($q);
     return True;
 }
Esempio n. 7
0
 /**
  * Function to add a new product into the product table
  *
  * @param array $d The input vars
  * @return boolean True, when the product was added, false when not
  */
 function add(&$d)
 {
     global $perm, $vmLogger, $VM_LANG;
     $database = new ps_DB();
     if (!$this->validate($d)) {
         return false;
     }
     if (!vmImageTools::process_images($d)) {
         return false;
     }
     $timestamp = time();
     $db = new ps_DB();
     $ps_vendor_id = $_SESSION["ps_vendor_id"];
     if ($perm->check('admin')) {
         $vendor_id = $d['vendor_id'];
     } else {
         $vendor_id = $ps_vendor_id;
     }
     // Insert into DB
     $fields = array('vendor_id' => $vendor_id, 'product_parent_id' => vmRequest::getInt('product_parent_id'), 'product_sku' => vmGet($d, 'product_sku'), 'product_name' => vmGet($d, 'product_name'), 'product_desc' => vmRequest::getVar('product_desc', '', 'default', '', VMREQUEST_ALLOWHTML), 'product_s_desc' => vmRequest::getVar('product_s_desc', '', 'default', '', VMREQUEST_ALLOWHTML), 'product_thumb_image' => vmGet($d, 'product_thumb_image'), 'product_full_image' => vmGet($d, 'product_full_image'), 'product_publish' => $d['product_publish'], 'product_weight' => vmRequest::getFloat('product_weight'), 'product_weight_uom' => vmGet($d, 'product_weight_uom'), 'product_length' => vmRequest::getFloat('product_length'), 'product_width' => vmRequest::getFloat('product_width'), 'product_height' => vmRequest::getFloat('product_height'), 'product_lwh_uom' => vmGet($d, 'product_lwh_uom'), 'product_unit' => vmGet($d, 'product_unit'), 'product_packaging' => $d["product_box"] << 16 | $d["product_packaging"] & 0xffff, 'product_url' => vmGet($d, 'product_url'), 'product_in_stock' => vmRequest::getInt('product_in_stock'), 'attribute' => ps_product_attribute::formatAttributeX(), 'custom_attribute' => vmGet($d, 'product_custom_attribute'), 'product_available_date' => $d['product_available_date_timestamp'], 'product_availability' => vmGet($d, 'product_availability'), 'product_special' => $d['product_special'], 'child_options' => $d['child_options'], 'quantity_options' => $d['quantity_options'], 'product_discount_id' => vmRequest::getInt('product_discount_id'), 'cdate' => $timestamp, 'mdate' => $timestamp, 'product_tax_id' => vmRequest::getInt('product_tax_id'), 'child_option_ids' => vmGet($d, 'included_product_id'), 'product_order_levels' => $d['order_levels']);
     $db->buildQuery('INSERT', '#__{vm}_product', $fields);
     if ($db->query() === false) {
         $vmLogger->err($VM_LANG->_('VM_PRODUCT_ADDING_FAILED', false));
         return false;
     }
     $d["product_id"] = $_REQUEST['product_id'] = $db->last_insert_id();
     // If is Item, add attributes from parent //
     if ($d["product_parent_id"]) {
         $q = "SELECT attribute_name FROM #__{vm}_product_attribute_sku ";
         $q .= "WHERE product_id='" . vmRequest::getInt('product_parent_id') . "' ";
         $q .= "ORDER BY attribute_list,attribute_name";
         $db->query($q);
         $db2 = new ps_DB();
         $i = 0;
         while ($db->next_record()) {
             $i++;
             $q = "INSERT INTO #__{vm}_product_attribute (`product_id`,`attribute_name`,`attribute_value`) VALUES ";
             $q .= "('" . $d["product_id"] . "', '" . $db->f("attribute_name", false) . "', '" . vmGet($d, 'attribute_' . $i) . "')";
             $db2->query($q);
         }
     } else {
         // If is Product, Insert category ids
         if (empty($d['product_categories']) || !is_array(@$d['product_categories'])) {
             $d['product_categories'] = explode('|', $d['category_ids']);
         }
         foreach ($d["product_categories"] as $category_id) {
             $db->query('SELECT MAX(`product_list`) as list_order FROM `#__{vm}_product_category_xref` WHERE `category_id`=' . $category_id);
             $db->next_record();
             $q = "INSERT INTO #__{vm}_product_category_xref ";
             $q .= "(category_id,product_id,product_list) ";
             $q .= "VALUES ('{$category_id}','" . $d["product_id"] . "', " . intval($db->f('max') + 1) . ")";
             $db->setQuery($q);
             $db->query();
         }
     }
     $q = "INSERT INTO #__{vm}_product_mf_xref VALUES (";
     $q .= "'" . $d['product_id'] . "', '" . vmRequest::getInt('manufacturer_id') . "')";
     $db->setQuery($q);
     $db->query();
     if (!empty($d["related_products"])) {
         /* Insert Pipe separated Related Product IDs */
         $related_products = vmGet($d, "related_products");
         $q = "INSERT INTO #__{vm}_product_relations ";
         $q .= "(product_id, related_products) ";
         $q .= "VALUES ('" . $d["product_id"] . "','" . $db->getEscaped($related_products) . "')";
         $db->setQuery($q);
         $db->query();
     }
     // ADD A PRICE, IF NOT EMPTY ADD 0
     if (!empty($d['product_price'])) {
         if (empty($d['product_currency'])) {
             $d['product_currency'] = $_SESSION['vendor_currency'];
         }
         $d["price_quantity_start"] = 0;
         $d["price_quantity_end"] = "";
         require_once CLASSPATH . 'ps_product_price.php';
         $my_price = new ps_product_price();
         $my_price->add($d);
     }
     if (!empty($d['product_type_id'])) {
         require_once CLASSPATH . 'ps_product_product_type.php';
         $ps_product_product_type = new ps_product_product_type();
         $ps_product_product_type->add($d);
         // Product Type Parameters!
         $this->handleParameters($d);
     }
     // CLONE PRODUCT additional code
     if ($d["clone_product"] == "Y") {
         // Clone Parent Product's Attributes
         $q = "INSERT INTO #__{vm}_product_attribute_sku\n              SELECT '" . $d["product_id"] . "', attribute_name, attribute_list \n              FROM #__{vm}_product_attribute_sku WHERE product_id='" . (int) $d["old_product_id"] . "' ";
         $db->query($q);
         if (!empty($d["child_items"])) {
             $database->query("SHOW COLUMNS FROM #__{vm}_product");
             $rows = $database->record;
             while (list(, $Field) = each($rows)) {
                 $product_fields[$Field->Field] = $Field->Field;
             }
             // Change the Field Names
             // leave empty for auto_increment
             $product_fields["product_id"] = "''";
             // Update Product Parent ID to the new one
             $product_fields["product_parent_id"] = "'" . $d["product_id"] . "'";
             // Rename the SKU
             $product_fields["product_sku"] = "CONCAT(product_sku,'_" . $d["product_id"] . "')";
             $rows = array();
             $database->query("SHOW COLUMNS FROM #__{vm}_product_price");
             $rows = $database->record;
             while (list(, $Field) = each($rows)) {
                 $price_fields[$Field->Field] = $Field->Field;
             }
             foreach ($d["child_items"] as $child_id) {
                 $q = "INSERT INTO #__{vm}_product ";
                 $q .= "SELECT " . implode(",", $product_fields) . " FROM #__{vm}_product WHERE product_id='{$child_id}'";
                 $db->query($q);
                 $new_product_id = $db->last_insert_id();
                 $q = "INSERT INTO #__{vm}_product_attribute\n\t\t\t                  SELECT NULL, '{$new_product_id}', attribute_name, attribute_value\n\t\t\t                  FROM #__{vm}_product_attribute WHERE product_id='{$child_id}'";
                 $db->query($q);
                 $price_fields["product_price_id"] = "''";
                 $price_fields["product_id"] = "'{$new_product_id}'";
                 $q = "INSERT INTO #__{vm}_product_price ";
                 $q .= "SELECT " . implode(",", $price_fields) . " FROM #__{vm}_product_price WHERE product_id='{$child_id}'";
                 $db->query($q);
             }
         }
         // End Cloning
     }
     if ($d['clone_product'] == 'Y') {
         $vmLogger->info($VM_LANG->_('VM_PRODUCT_CLONED', false));
     } else {
         $vmLogger->info($VM_LANG->_('VM_PRODUCT_ADDED', false));
     }
     return true;
 }
 /**
  * Adds a new Shopper Group
  *
  * @param array $d
  * @return boolean
  */
 function add(&$d)
 {
     global $perm, $vmLogger, $VM_LANG;
     $hash_secret = "virtuemart";
     if ($perm->check("admin")) {
         $vendor_id = $d["vendor_id"];
     } else {
         $vendor_id = $_SESSION["ps_vendor_id"];
     }
     $db = new ps_DB();
     $timestamp = time();
     $default = @$d["default"] == "1" ? "1" : "0";
     if (!$this->validate_add($d)) {
         return False;
     }
     $user_id = md5(uniqid($hash_secret));
     $fields = array('vendor_id' => $vendor_id, 'shopper_group_name' => $d["shopper_group_name"], 'shopper_group_desc' => $d["shopper_group_desc"], 'shopper_group_discount' => $d["shopper_group_discount"], 'show_price_including_tax' => $d["show_price_including_tax"], 'default' => $default);
     $db->buildQuery('INSERT', '#__{vm}_shopper_group', $fields);
     if ($db->query() !== false) {
         $shopper_group_id = $db->last_insert_id();
         vmRequest::setVar('shopper_group_id', $shopper_group_id);
         $vmLogger->info($VM_LANG->_('SHOPPER_GROUP_ADDED'));
         // Set all other shopper groups to be non-default, if this new shopper group shall be "default"
         if ($default == "1") {
             $q = "UPDATE #__{vm}_shopper_group ";
             $q .= "SET `default`=0 ";
             $q .= "WHERE shopper_group_id !=" . $shopper_group_id;
             $q .= " AND vendor_id ={$vendor_id}";
             $db->query($q);
             $db->next_record();
         }
         return $_REQUEST['shopper_group_id'];
     }
     $vmLogger->err($VM_LANG->_('SHOPPER_GROUP_ADD_FAILED'));
     return false;
 }
Esempio n. 9
0
 /**
  * creates a new manufacturer record
  *
  * @param array $d
  * @return boolean
  */
 function add(&$d)
 {
     global $VM_LANG;
     $db = new ps_DB();
     if (!$this->validate_add($d)) {
         return false;
     }
     $fields = array('mf_name' => vmGet($d, 'mf_name'), 'mf_email' => vmGet($d, 'mf_email'), 'mf_desc' => vmGet($d, 'mf_desc', '', VMREQUEST_ALLOWHTML), 'mf_category_id' => vmRequest::getInt('mf_category_id'), 'mf_url' => vmGet($d, 'mf_url'));
     $db->buildQuery('INSERT', '#__{vm}_manufacturer', $fields);
     if ($db->query() !== false) {
         $GLOBALS['vmLogger']->info($VM_LANG->_('VM_MANUF_ADDED'));
         $_REQUEST['manufacturer_id'] = $db->last_insert_id();
         return true;
     }
     return false;
 }
 /**
  * Adds a new price record for a given product
  *
  * @param array $d
  * @return boolean
  */
 function add(&$d)
 {
     global $vmLogger, $VM_LANG;
     if (!$this->validate($d)) {
         return false;
     }
     if ($d["product_price"] === '') {
         $vmLogger->err($VM_LANG->_('VM_PRODUCT_PRICE_NOTENTERED', false));
         return false;
     }
     $timestamp = time();
     if (empty($d["product_price_vdate"])) {
         $d["product_price_vdate"] = '';
     }
     if (empty($d["product_price_edate"])) {
         $d["product_price_edate"] = '';
     }
     $fields = array('product_id' => $d["product_id"], 'shopper_group_id' => vmRequest::getInt('shopper_group_id'), 'product_price' => vmRequest::getFloat('product_price'), 'product_currency' => vmGet($d, 'product_currency'), 'product_price_vdate' => vmGet($d, 'product_price_vdate'), 'product_price_edate' => vmGet($d, 'product_price_edate'), 'cdate' => $timestamp, 'mdate' => $timestamp, 'price_quantity_start' => vmRequest::getInt('price_quantity_start'), 'price_quantity_end' => vmRequest::getInt('price_quantity_end'));
     $db = new ps_DB();
     $db->buildQuery('INSERT', '#__{vm}_product_price', $fields);
     if ($db->query() !== false) {
         $_REQUEST['product_price_id'] = $db->last_insert_id();
         $vmLogger->info($VM_LANG->_('VM_PRODUCT_PRICE_ADDED', false));
         return true;
     }
     $vmLogger->err($VM_LANG->_('VM_PRODUCT_PRICE_ADDING_FAILED', false));
     return false;
 }
Esempio n. 11
0
 function saveField(&$d)
 {
     global $my, $mosConfig_live_site, $VM_LANG;
     $db = new ps_DB();
     if ($d['type'] == 'webaddress') {
         $d['rows'] = $d['webaddresstypes'];
         if (!($d['rows'] == 0 || $d['rows'] == 2)) {
             $d['rows'] = 0;
         }
     }
     $d['name'] = str_replace(" ", "", strtolower($d['name']));
     if (!$this->validateOnSave($d)) {
         return false;
     }
     // Prevent unpublishing and renaming of IMPORTANT Fields like "email", "username", "password",...
     $fieldObj = $this->get($d['fieldid']);
     if ($fieldObj !== false) {
         if (in_array($fieldObj->f('name'), $this->getSkipFields())) {
             $d['name'] = $fieldObj->f('name');
             $d['required'] = $fieldObj->f('required');
             $d['published'] = $fieldObj->f('published');
         }
     }
     $fields = array('name' => vmGet($d, 'name'), 'title' => vmGet($d, 'title'), 'description' => vmGet($d, 'description'), 'type' => vmGet($d, 'type'), 'maxlength' => vmGet($d, 'maxlength'), 'size' => vmGet($d, 'size'), 'required' => vmGet($d, 'required'), 'ordering' => vmGet($d, 'ordering'), 'cols' => vmGet($d, 'cols'), 'rows' => vmGet($d, 'rows'), 'value' => vmGet($d, 'value'), 'default' => vmGet($d, 'default'), 'published' => vmGet($d, 'published'), 'registration' => vmGet($d, 'registration'), 'shipping' => vmGet($d, 'shipping'), 'account' => vmGet($d, 'account'), 'readonly' => vmGet($d, 'readonly'), 'calculated' => vmGet($d, 'calculated'), 'params' => vmGet($d, 'params'), 'vendor_id' => vmGet($_SESSION, 'ps_vendor_id', 1));
     if (!empty($d['fieldid'])) {
         // existing record
         $db->buildQuery('UPDATE', '#__{vm}_userfield', $fields, 'WHERE `fieldid` =' . intval($d['fieldid']));
         $db->query();
         if ($d['type'] != 'delimiter') {
             $this->changeColumn($d['name'], $d['cType'], 'update');
         }
     } else {
         // add a new record
         $sql = "SELECT MAX(ordering) as max FROM #__{vm}_userfield";
         $db->query($sql);
         $db->next_record();
         $d['ordering'] = $db->f('max') + 1;
         $db->buildQuery('INSERT', '#__{vm}_userfield', $fields);
         $db->query();
         $_REQUEST['fieldid'] = $db->last_insert_id();
         if ($d['type'] != 'delimiter') {
             $this->changeColumn($d['name'], $d['cType'], 'add');
         }
     }
     $fieldNames = vmGet($d, 'vNames', array());
     $fieldValues = vmGet($d, 'vValues', array());
     $j = 1;
     if (!empty($d['fieldid'])) {
         $db->query("DELETE FROM #__{vm}_userfield_values" . " WHERE fieldid=" . (int) $d['fieldid'] . ' LIMIT 1');
     } else {
         $db->query("SELECT MAX(fieldid) as max FROM `#__{vm}_userfield`");
         $maxID = $db->loadResult();
         $d['fieldid'] = $maxID;
     }
     $n = count($fieldNames);
     for ($i = 0; $i < $n; $i++) {
         if (trim($fieldNames[$i]) != null || trim($fieldNames[$i]) != '') {
             $fields = array('fieldid' => (int) $d['fieldid'], 'fieldtitle' => htmlspecialchars($fieldNames[$i]), 'fieldvalue' => htmlspecialchars($fieldValues[$i]), 'ordering' => $j);
             $db->buildQuery('INSERT', '#__{vm}_userfield_values', $fields);
             $db->query();
             $j++;
         }
     }
     $GLOBALS['vmLogger']->info($VM_LANG->_('VM_USERFIELD_SAVED'));
     return true;
 }
Esempio n. 12
0
 function rate_add(&$d)
 {
     $db = new ps_DB();
     $timestamp = time();
     if (!$this->validate_rate_add($d)) {
         return False;
     }
     $country_str = "";
     if (!empty($d["shipping_rate_country"])) {
         for ($i = 0; $i < count($d["shipping_rate_country"]); $i++) {
             if ($d["shipping_rate_country"][$i] != "") {
                 $country_str .= $d["shipping_rate_country"][$i] . ";";
             }
         }
         chop($country_str, ";");
     }
     $fields = array('shipping_rate_name' => vmGet($d, 'shipping_rate_name'), 'shipping_rate_carrier_id' => (int) vmGet($d, 'shipping_rate_carrier_id'), 'shipping_rate_country' => $country_str, 'shipping_rate_zip_start' => vmGet($d, 'shipping_rate_zip_start'), 'shipping_rate_zip_end' => vmGet($d, 'shipping_rate_zip_end'), 'shipping_rate_weight_start' => vmGet($d, 'shipping_rate_weight_start'), 'shipping_rate_weight_end' => vmGet($d, 'shipping_rate_weight_end'), 'shipping_rate_value' => vmGet($d, 'shipping_rate_value'), 'shipping_rate_package_fee' => vmGet($d, 'shipping_rate_package_fee'), 'shipping_rate_currency_id' => vmGet($d, 'shipping_rate_currency_id'), 'shipping_rate_vat_id' => vmGet($d, 'shipping_rate_vat_id'), 'shipping_rate_list_order' => (int) vmGet($d, 'shipping_rate_list_order'));
     $db->buildQuery('INSERT', '#__{vm}_shipping_rate', $fields);
     $db->query();
     $_REQUEST['shipping_rate_id'] = $db->last_insert_id();
     return True;
 }
Esempio n. 13
0
 function update_coupon(&$d)
 {
     global $vmLogger, $VM_LANG;
     if (!$this->validate_update($d)) {
         return false;
     }
     /* init the database */
     $coupon_db = new ps_DB();
     $fields = array('coupon_code' => vmGet($d, 'coupon_code'), 'percent_or_total' => strtolower($d['percent_or_total']) == 'percent' ? 'percent' : 'total', 'coupon_type' => strtolower($d['coupon_type']) == 'gift' ? 'gift' : 'permanent', 'coupon_value' => (double) $d['coupon_value']);
     $coupon_db->buildQuery('UPDATE', '#__{vm}_coupons', $fields, 'WHERE coupon_id = ' . (int) $d['coupon_id']);
     if ($coupon_db->query()) {
         $_REQUEST['coupon_id'] = $coupon_db->last_insert_id();
         $vmLogger->info($VM_LANG->_('VM_COUPON_UPDATED'));
         return true;
     }
     return false;
 }
Esempio n. 14
0
 /**
  * Adds a new state entry for a country specified by country_id
  *
  * @param array $d
  * @return boolean
  */
 function addState(&$d)
 {
     $db = new ps_DB();
     if (empty($d['country_id'])) {
         $GLOBALS['vmLogger']->err('No country was selected for this State');
         return False;
     }
     $fields = array('state_name' => vmGet($d, 'state_name'), 'country_id' => vmRequest::getInt('country_id'), 'state_2_code' => vmGet($d, 'state_2_code'), 'state_3_code' => vmGet($d, 'state_3_code'));
     $db->buildQuery('INSERT', '#__{vm}_state', $fields);
     if ($db->query()) {
         $GLOBALS['vmLogger']->info('The state has been added.');
         $_REQUEST['state_id'] = $db->last_insert_id();
         return True;
     }
     return false;
 }
Esempio n. 15
0
 /**
  * Creates a new category record and a category_xref record
  * with the appropriate parent and child ids
  * @author pablo
  * @author soeren
  * 
  * @param array $d
  * @return mixed - int category_id on success, false on error
  */
 function add(&$d)
 {
     global $vmLogger, $VM_LANG;
     $ps_vendor_id = $_SESSION["ps_vendor_id"];
     $db = new ps_DB();
     $timestamp = time();
     if ($this->validate_add($d)) {
         if (!vmImageTools::process_images($d)) {
             return false;
         }
         while (list($key, $value) = each($d)) {
             if (!is_array($value)) {
                 $d[$key] = addslashes($value);
             }
         }
         // Let's find out the last category in
         // the level of the new category
         $q = 'SELECT MAX(list_order) AS list_order FROM #__{vm}_category_xref,#__{vm}_category ';
         $q .= 'WHERE category_parent_id=' . vmRequest::getInt('parent_category_id');
         $q .= ' AND category_child_id=category_id';
         $db->query($q);
         $db->next_record();
         $list_order = intval($db->f("list_order")) + 1;
         if (empty($d["category_publish"])) {
             $d["category_publish"] = "N";
         }
         $fields = array('vendor_id' => $ps_vendor_id, 'category_name' => vmGet($d, 'category_name'), 'category_publish' => vmGet($d, 'category_publish'), 'category_description' => vmGet($d, 'category_description', '', VMREQUEST_ALLOWHTML), 'category_browsepage' => vmGet($d, 'category_browsepage'), 'products_per_row' => vmRequest::getInt('products_per_row'), 'category_flypage' => vmGet($d, 'category_flypage'), 'category_thumb_image' => vmGet($d, 'category_thumb_image'), 'category_full_image' => vmGet($d, 'category_full_image'), 'cdate' => $timestamp, 'mdate' => $timestamp, 'list_order' => $list_order);
         $db->buildQuery('INSERT', '#__{vm}_category', $fields);
         $db->query();
         $category_id = $_REQUEST['category_id'] = $db->last_insert_id();
         $fields = array('category_parent_id' => (int) $d["parent_category_id"], 'category_child_id' => $category_id);
         $db->buildQuery('INSERT', '#__{vm}_category_xref', $fields);
         $db->query();
         $vmLogger->info($VM_LANG->_('VM_PRODUCT_CATEGORY_ADDED') . ': "' . vmGet($d, 'category_name') . '"');
         return true;
     } else {
         return False;
     }
 }
Esempio n. 16
0
 /**
  * Updates a given Credit Card Record
  *
  * @param array $d
  * @return boolean
  */
 function update(&$d)
 {
     global $VM_LANG;
     $db = new ps_DB();
     $timestamp = time();
     if (!$this->validate_update($d)) {
         $d["error"] = $this->error;
         return False;
     }
     $fields = array('vendor_id' => $_SESSION["ps_vendor_id"], 'creditcard_name' => vmGet($d, 'creditcard_name'), 'creditcard_code' => vmGet($d, 'creditcard_code'));
     $db->buildQuery('UPDATE', '#__{vm}_creditcard', $fields, 'WHERE creditcard_id=' . (int) $d["creditcard_id"]);
     if ($db->query()) {
         $GLOBALS['vmLogger']->info($VM_LANG->_('VM_CREDITCARD_UPDATED'));
         $_REQUEST['creditcard_id'] = $db->last_insert_id();
         return true;
     }
     return false;
 }
Esempio n. 17
0
 /**
  * creates a new currency record
  *
  * @param array $d
  * @return boolean
  */
 function add(&$d)
 {
     global $VM_LANG;
     $db = new ps_DB();
     if (!$this->validate_add($d)) {
         return False;
     }
     $fields = array('currency_name' => vmGet($d, 'currency_name'), 'currency_code' => vmGet($d, 'currency_code'));
     $db->buildQuery('INSERT', '#__{vm}_currency', $fields);
     if ($db->query()) {
         $GLOBALS['vmLogger']->info($VM_LANG->_('VM_CURRENCY_ADDED'));
         $_REQUEST['currency_id'] = $db->last_insert_id();
         return true;
     }
     return false;
 }
Esempio n. 18
0
 /**
  * creates a new Order Status
  * @author soeren, pablo
  * @param array $d
  * @return boolean
  */
 function add(&$d)
 {
     global $VM_LANG;
     $db = new ps_DB();
     $ps_vendor_id = $_SESSION["ps_vendor_id"];
     if (!$this->validate_add($d)) {
         return False;
     }
     $fields = array('vendor_id' => $ps_vendor_id, 'order_status_code' => vmGet($d, 'order_status_code'), 'order_status_name' => vmGet($d, 'order_status_name'), 'order_status_description' => vmGet($d, 'order_status_description'), 'list_order' => vmRequest::getInt('list_order'));
     $db->buildQuery('INSERT', $this->_table_name, $fields);
     $result = $db->query();
     if ($result) {
         $GLOBALS['vmLogger']->info($VM_LANG->_('VM_ORDERSTATUS_ADDED'));
         $d["order_status_id"] = $_REQUEST['order_status_id'] = $db->last_insert_id();
     } else {
         $GLOBALS['vmLogger']->err($VM_LANG->_('VM_ORDERSTATUS_ADD_FAILED'));
     }
     return $result;
 }
 /**
  * updates manufacturer information
  *
  * @param array $d
  * @return boolean
  */
 function update(&$d)
 {
     global $VM_LANG;
     $db = new ps_DB();
     $GLOBALS['vmInputFilter']->safeSQL($d);
     if (!$this->validate_update($d)) {
         return False;
     }
     $fields = array('mf_category_name' => vmGet($d, 'mf_category_name'), 'mf_category_desc' => vmGet($d, 'mf_category_desc'));
     $db->buildQuery('UPDATE', '#__{vm}_manufacturer_category', $fields, "WHERE mf_category_id=" . (int) $d["mf_category_id"]);
     if ($db->query() !== false) {
         $_REQUEST['mf_category_id'] = $db->last_insert_id();
         $GLOBALS['vmLogger']->info($VM_LANG->_('VM_MANUF_CAT_UPDATED'));
         return True;
     }
     return false;
 }
    /**
     * This is the main function which stores the order information in the database
     * 
     * @author Ashish Solanki!
     * @return boolean
     */
    function updateRecords($order_number, $order_total, &$d)
    {
        require_once CLASSPATH . 'ps_checkout.php';
        $ps_chkout = new ps_checkout();
        global $order_tax_details, $afid, $VM_LANG, $auth, $my, $mosConfig_offset, $vmLogger, $vmInputFilter, $discount_factor;
        $ps_vendor_id = $_SESSION["ps_vendor_id"];
        $cart = $_SESSION['cart'];
        require_once CLASSPATH . 'ps_payment_method.php';
        $ps_payment_method = new ps_payment_method();
        require_once CLASSPATH . 'ps_product.php';
        $ps_product = new ps_product();
        require_once CLASSPATH . 'ps_cart.php';
        $ps_cart = new ps_cart();
        $db = new ps_DB();
        $totals = $ps_chkout->calc_order_totals($d);
        extract($totals);
        $timestamp = time();
        //Custom
        $vmLogger->debug('-- Checkout Debug--
							Subtotal: ' . $order_subtotal . '
							Taxable: ' . $order_taxable . '
							Payment Discount: ' . $payment_discount . '
							Coupon Discount: ' . $coupon_discount . '
							Shipping: ' . $order_shipping . '
							Shipping Tax : ' . $order_shipping_tax . '
							Tax : ' . $order_tax . '
							------------------------
							Order Total: ' . $order_total . '
							----------------------------');
        // Check to see if Payment Class File exists
        $payment_class = $ps_payment_method->get_field($d["payment_method_id"], "payment_class");
        $d['new_order_status'] = 'P';
        // This is meant to be updated by a payment modules' process_payment method
        if (!class_exists($payment_class)) {
            include CLASSPATH . "payment/{$payment_class}.php";
        }
        $_PAYMENT = new $payment_class();
        // Remove the Coupon, because it is a Gift Coupon and now is used!!
        if (@$_SESSION['coupon_type'] == "gift") {
            $d['coupon_id'] = $_SESSION['coupon_id'];
            include_once CLASSPATH . 'ps_coupon.php';
            ps_coupon::remove_coupon_code($d);
        }
        // Get the IP Address
        if (!empty($_SERVER['REMOTE_ADDR'])) {
            $ip = $_SERVER['REMOTE_ADDR'];
        } else {
            $ip = 'unknown';
        }
        // Collect all fields and values to store them!
        $fields = array('user_id' => $auth["user_id"], 'vendor_id' => $ps_vendor_id, 'order_number' => $order_number, 'user_info_id' => $d["ship_to_info_id"], 'ship_method_id' => @urldecode($d["shipping_rate_id"]), 'order_total' => $order_total, 'order_subtotal' => $order_subtotal, 'order_tax' => $order_tax, 'order_tax_details' => serialize($order_tax_details), 'order_shipping' => $order_shipping, 'order_shipping_tax' => $order_shipping_tax, 'order_discount' => $payment_discount, 'coupon_discount' => $coupon_discount, 'coupon_code' => @$_SESSION['coupon_code'], 'order_currency' => $GLOBALS['product_currency'], 'order_status' => 'P', 'cdate' => $timestamp, 'mdate' => $timestamp, 'customer_note' => htmlspecialchars(vmRequest::getString('customer_note', '', 'POST', 'none'), ENT_QUOTES), 'ip_address' => $ip);
        // Insert the main order information
        $db->buildQuery('INSERT', '#__{vm}_orders', $fields);
        $result = $db->query();
        $d["order_id"] = $order_id = $db->last_insert_id();
        if ($result === false || empty($order_id)) {
            $vmLogger->crit('Adding the Order into the Database failed! User ID: ' . $auth["user_id"]);
            return false;
        }
        // Insert the initial Order History.
        $mysqlDatetime = date("Y-m-d G:i:s", $timestamp);
        $fields = array('order_id' => $order_id, 'order_status_code' => 'P', 'date_added' => $mysqlDatetime, 'customer_notified' => 1, 'comments' => '');
        $db->buildQuery('INSERT', '#__{vm}_order_history', $fields);
        $db->query();
        /**
         * Insert the Order payment info 
         */
        $payment_number = str_replace(array(' ', '|', '-'), '', @$_SESSION['ccdata']['order_payment_number']);
        $d["order_payment_code"] = @$_SESSION['ccdata']['credit_card_code'];
        // Payment number is encrypted using mySQL encryption functions.
        $fields = array('order_id' => $order_id, 'payment_method_id' => $d["payment_method_id"], 'order_payment_log' => @$d["order_payment_log"], 'order_payment_trans_id' => $vmInputFilter->safeSQL(@$d["order_payment_trans_id"]));
        if (!empty($payment_number) && VM_STORE_CREDITCARD_DATA == '1') {
            // Store Credit Card Information only if the Store Owner has decided to do so
            $fields['order_payment_code'] = $d["order_payment_code"];
            $fields['order_payment_expire'] = @$_SESSION["ccdata"]["order_payment_expire"];
            $fields['order_payment_name'] = @$_SESSION["ccdata"]["order_payment_name"];
            $fields['order_payment_number'] = VM_ENCRYPT_FUNCTION . "( '{$payment_number}','" . ENCODE_KEY . "')";
            $specialfield = array('order_payment_number');
        } else {
            $specialfield = array();
        }
        $db->buildQuery('INSERT', '#__{vm}_order_payment', $fields, '', $specialfield);
        $db->query();
        /**
         * Insert the User Billto & Shipto Info
         */
        // First: get all the fields from the user field list to copy them from user_info into the order_user_info
        $fields = array();
        require_once CLASSPATH . 'ps_userfield.php';
        $userfields = ps_userfield::getUserFields('', false, '', true, true);
        foreach ($userfields as $field) {
            if ($field->name == 'email') {
                $fields[] = 'user_email';
            } else {
                $fields[] = $field->name;
            }
        }
        $fieldstr = implode(',', $fields);
        // Save current Bill To Address
        $q = "INSERT INTO `#__{vm}_order_user_info` \n\t\t\t(`order_info_id`,`order_id`,`user_id`,address_type, " . $fieldstr . ") ";
        $q .= "SELECT NULL, '{$order_id}', '" . $auth['user_id'] . "', address_type, " . $fieldstr . " FROM #__{vm}_user_info WHERE user_id='" . $auth['user_id'] . "' AND address_type='BT'";
        $db->query($q);
        // Save current Ship to Address if applicable
        $q = "INSERT INTO `#__{vm}_order_user_info` \n\t\t\t(`order_info_id`,`order_id`,`user_id`,address_type, " . $fieldstr . ") ";
        $q .= "SELECT NULL, '{$order_id}', '" . $auth['user_id'] . "', address_type, " . $fieldstr . " FROM #__{vm}_user_info WHERE user_id='" . $auth['user_id'] . "' AND user_info_id='" . $d['ship_to_info_id'] . "' AND address_type='ST'";
        $db->query($q);
        /**
         * Insert all Products from the Cart into order line items; 
         * one row per product in the cart 
         */
        $dboi = new ps_DB();
        for ($i = 0; $i < $cart["idx"]; $i++) {
            $r = "SELECT product_id,product_in_stock,product_sales,product_parent_id,product_sku,product_name ";
            $r .= "FROM #__{vm}_product WHERE product_id='" . $cart[$i]["product_id"] . "'";
            $dboi->query($r);
            $dboi->next_record();
            $product_price_arr = $ps_product->get_adjusted_attribute_price($cart[$i]["product_id"], $cart[$i]["description"]);
            $product_price = $GLOBALS['CURRENCY']->convert($product_price_arr["product_price"], $product_price_arr["product_currency"]);
            if (empty($_SESSION['product_sess'][$cart[$i]["product_id"]]['tax_rate'])) {
                $my_taxrate = $ps_product->get_product_taxrate($cart[$i]["product_id"]);
            } else {
                $my_taxrate = $_SESSION['product_sess'][$cart[$i]["product_id"]]['tax_rate'];
            }
            // Attribute handling
            $product_parent_id = $dboi->f('product_parent_id');
            $description = '';
            if ($product_parent_id > 0) {
                $db_atts = $ps_product->attribute_sql($dboi->f('product_id'), $product_parent_id);
                while ($db_atts->next_record()) {
                    $description .= $db_atts->f('attribute_name') . ': ' . $db_atts->f('attribute_value') . '; ';
                }
            }
            $description .= $ps_product->getDescriptionWithTax($_SESSION['cart'][$i]["description"], $dboi->f('product_id'));
            $product_final_price = round($product_price * ($my_taxrate + 1), 2);
            $vendor_id = $ps_vendor_id;
            $fields = array('order_id' => $order_id, 'user_info_id' => $d["ship_to_info_id"], 'vendor_id' => $vendor_id, 'product_id' => $cart[$i]["product_id"], 'order_item_sku' => $dboi->f("product_sku"), 'order_item_name' => $dboi->f("product_name"), 'product_quantity' => $cart[$i]["quantity"], 'product_item_price' => $product_price, 'product_final_price' => $product_final_price, 'order_item_currency' => $GLOBALS['product_currency'], 'order_status' => 'P', 'product_attribute' => $description, 'cdate' => $timestamp, 'mdate' => $timestamp);
            $db->buildQuery('INSERT', '#__{vm}_order_item', $fields);
            $db->query();
            // Update Stock Level and Product Sales, decrease - no matter if in stock or not!
            $q = "UPDATE #__{vm}_product ";
            $q .= "SET product_in_stock = product_in_stock - " . (int) $cart[$i]["quantity"];
            $q .= " WHERE product_id = '" . $cart[$i]["product_id"] . "'";
            $db->query($q);
            $q = "UPDATE #__{vm}_product ";
            $q .= "SET product_sales= product_sales + " . (int) $cart[$i]["quantity"];
            $q .= " WHERE product_id='" . $cart[$i]["product_id"] . "'";
            $db->query($q);
            // Update stock of parent product, if all child products are sold, thanks Ragnar Brynjulfsson
            if ($dboi->f("product_parent_id") != 0) {
                $q = "SELECT COUNT(product_id) ";
                $q .= "FROM #__{vm}_product ";
                $q .= "WHERE product_parent_id = " . $dboi->f("product_parent_id");
                $q .= " AND product_in_stock > 0";
                $db->query($q);
                $db->next_record();
                if (!$db->f("COUNT(product_id)")) {
                    $q = "UPDATE #__{vm}_product ";
                    $q .= "SET product_in_stock = 0 ";
                    $q .= "WHERE product_id = " . $dboi->f("product_parent_id") . " LIMIT 1";
                    $db->query($q);
                }
            }
        }
        ######## BEGIN DOWNLOAD MOD ###############
        if (ENABLE_DOWNLOADS == "1") {
            require_once CLASSPATH . 'ps_order.php';
            for ($i = 0; $i < $cart["idx"]; $i++) {
                // only handle downloadable products here
                if (ps_product::is_downloadable($cart[$i]["product_id"])) {
                    $params = array('product_id' => $cart[$i]["product_id"], 'order_id' => $order_id, 'user_id' => $auth["user_id"]);
                    ps_order::insert_downloads_for_product($params);
                    if (@VM_DOWNLOADABLE_PRODUCTS_KEEP_STOCKLEVEL == '1') {
                        // Update the product stock level back to where it was.
                        $q = "UPDATE #__{vm}_product ";
                        $q .= "SET product_in_stock = product_in_stock + " . (int) $cart[$i]["quantity"];
                        $q .= " WHERE product_id = '" . (int) $cart[$i]["product_id"] . "'";
                        $db->query($q);
                    }
                }
            }
        }
        ################## END DOWNLOAD MOD ###########
        // Export the order_id so the checkout complete page can get it
        $d["order_id"] = $order_id;
        /*
         * Let the shipping module know which shipping method
         * was selected.  This way it can save any information
         * it might need later to print a shipping label.
         */
        if (is_callable(array($this->_SHIPPING, 'save_rate_info'))) {
            $this->_SHIPPING->save_rate_info($d);
        }
        // Now as everything else has been done, we can update the Order Status
        $update_order = false;
        if ($order_total == 0.0) {
            // code moved out of $_PAYMENT check as no payment will be needed when $order_total=0.0
            // If the Order Total is zero, we can confirm the order to automatically enable the download
            $d['order_status'] = ENABLE_DOWNLOAD_STATUS;
            $update_order = true;
        } elseif (isset($_PAYMENT)) {
            if ($d['new_order_status'] != 'P') {
                $d['order_status'] = $d['new_order_status'];
                $update_order = true;
            }
        }
        if ($update_order) {
            require_once CLASSPATH . "ps_order.php";
            $ps_order = new ps_order();
            $ps_order->order_status_update($d);
        }
        // Send the e-mail confirmation messages
        $ps_chkout->email_receipt($order_id);
        // Reset the cart (=empty it)
        $ps_cart->reset();
        $_SESSION['savedcart']['idx'] = 0;
        $ps_cart->saveCart();
        // Unset the payment_method variables
        $d["payment_method_id"] = "";
        $d["order_payment_number"] = "";
        $d["order_payment_expire"] = "";
        $d["order_payment_name"] = "";
        $d["credit_card_code"] = "";
        // Clear the sensitive Session data
        $_SESSION['ccdata']['order_payment_name'] = "";
        $_SESSION['ccdata']['order_payment_number'] = "";
        $_SESSION['ccdata']['order_payment_expire_month'] = "";
        $_SESSION['ccdata']['order_payment_expire_year'] = "";
        $_SESSION['ccdata']['credit_card_code'] = "";
        $_SESSION['coupon_discount'] = "";
        $_SESSION['coupon_id'] = "";
        $_SESSION['coupon_redeemed'] = false;
        $_POST["payment_method_id"] = "";
        $_POST["order_payment_number"] = "";
        $_POST["order_payment_expire"] = "";
        $_POST["order_payment_name"] = "";
        $_SESSION['order_id'] = $order_id;
    }
Esempio n. 21
0
 /**
  * Adds a new payment method
  *
  * @param array $d
  * @return boolean
  */
 function add(&$d)
 {
     global $VM_LANG;
     $ps_vendor_id = $_SESSION["ps_vendor_id"];
     $db = new ps_DB();
     if (!$this->validate_add($d)) {
         return False;
     }
     if (!empty($d["payment_class"])) {
         // Here we have a custom payment class
         $payment_class = basename($d["payment_class"]);
         if (file_exists(CLASSPATH . "payment/" . $payment_class . ".php")) {
             // Include the class code and create an instance of this class
             include CLASSPATH . "payment/" . $payment_class . ".php";
             if (class_exists($payment_class)) {
                 $_PAYMENT = new $payment_class();
             } else {
                 $GLOBALS['vmLogger']->err($VM_LANG->_('VM_PAYMENTMETHOD_CLASS_NOT_EXIST'));
                 return false;
             }
         }
     } else {
         // ps_payment is the default payment method handler
         include CLASSPATH . "payment/ps_payment.php";
         $_PAYMENT = new ps_payment();
     }
     if (is_callable(array($_PAYMENT, 'write_configuration'))) {
         $_PAYMENT->write_configuration($d);
     }
     if (!$d["shopper_group_id"]) {
         $q = "SELECT shopper_group_id FROM #__{vm}_shopper_group WHERE ";
         $q .= "`default`='1' ";
         $q .= "AND vendor_id='{$ps_vendor_id}'";
         $db->query($q);
         $db->next_record();
         $d["shopper_group_id"] = $db->f("shopper_group_id");
     }
     $fields = array('vendor_id' => $ps_vendor_id, 'payment_method_name' => vmGet($d, 'payment_method_name'), 'payment_class' => vmGet($d, 'payment_class'), 'shopper_group_id' => vmRequest::getInt('shopper_group_id'), 'payment_method_discount' => vmRequest::getFloat('payment_method_discount'), 'payment_method_discount_is_percent' => vmGet($d, 'payment_method_discount_is_percent'), 'payment_method_discount_max_amount' => (double) str_replace(',', '.', $d["payment_method_discount_max_amount"]), 'payment_method_discount_min_amount' => (double) str_replace(',', '.', $d["payment_method_discount_min_amount"]), 'payment_method_code' => vmGet($d, 'payment_method_code'), 'enable_processor' => vmGet($d, 'enable_processor'), 'list_order' => vmRequest::getInt('list_order'), 'is_creditcard' => vmGet($d, 'is_creditcard'), 'payment_enabled' => vmGet($d, 'payment_enabled'), 'accepted_creditcards' => vmGet($d, 'accepted_creditcards'), 'payment_extrainfo' => vmGet($_POST, 'payment_extrainfo', null, VMREQUEST_ALLOWRAW));
     $db->buildQuery('INSERT', '#__{vm}_payment_method', $fields);
     $db->query();
     $_REQUEST['payment_method_id'] = $db->last_insert_id();
     return True;
 }
Esempio n. 22
0
 /**
  * Creates a new function record
  * @author pablo, soeren
  *
  * @param array $d
  * @return boolean
  */
 function add(&$d)
 {
     global $vmLogger, $VM_LANG;
     $db = new ps_DB();
     $timestamp = time();
     if (!$this->validate_add($d)) {
         return False;
     }
     $fields = array('group_name' => $d["group_name"], 'group_level' => (int) $d["group_level"]);
     $db->buildQuery('INSERT', $this->_table_name, $fields);
     if ($db->query()) {
         $vmLogger->info($VM_LANG->_('VM_USER_GROUP_ADDED'));
     }
     $_REQUEST['function_id'] = $db->last_insert_id();
     return True;
 }
Esempio n. 23
0
 /**
  * Upload a file & Create a new File entry
  * @author soeren
  * @param array $d
  * @return boolean
  */
 function add(&$d)
 {
     global $mosConfig_absolute_path, $database, $VM_LANG, $vmLogger;
     $db = new ps_DB();
     $timestamp = time();
     if (!$this->validate_add($d)) {
         return False;
     }
     if (empty($d["file_published"])) {
         $d["file_published"] = 0;
     }
     if (empty($d["file_create_thumbnail"])) {
         $d["file_create_thumbnail"] = 0;
     }
     // Do we have an uploaded file?
     if (!empty($_FILES['file_upload']['name'])) {
         if (!$this->handleFileUpload($d)) {
             return false;
         }
         $is_image = $d['is_image'];
         $filename = $d['uploaddir'] . $d['filename'];
         $ext = $d['ext'];
         $upload_success = $d['upload_success'];
         $file_image_height = intval(@$d['file_image_height']);
         $file_image_width = intval(@$d['file_image_width']);
         $file_image_thumb_height = intval(@$d['file_image_thumb_height']);
         $file_image_thumb_width = intval(@$d['file_image_thumb_width']);
     } else {
         // No file uploaded, but specified by URL
         $is_image = stristr($d['file_type'], "image") ? '1' : '0';
         if (!empty($d['file_url'])) {
             $filename = '';
         } else {
             $filename = DOWNLOADROOT . @$d['downloadable_file'];
             $d["file_title"] = basename(@$d['downloadable_file']);
         }
         $ext = "";
         $upload_success = true;
         $file_image_height = $file_image_width = $file_image_thumb_height = $file_image_thumb_width = "";
     }
     if ($d['file_type'] == 'product_images' || $d['file_type'] == 'product_full_image' || $d['file_type'] == 'product_thumb_image') {
         // Handle Product Images
         $filename = @str_replace(IMAGEPATH . 'product/', '', $filename);
         $fullimage = @str_replace(IMAGEPATH . 'product/', '', $filename);
         $thumbimage = @str_replace(IMAGEPATH . 'product/', '', $d['fileout']);
         $q = 'UPDATE `#__{vm}_product` SET ';
         if ($d['file_type'] == 'product_images' || $d['file_type'] == 'product_full_image') {
             $q .= '`product_full_image`=\'' . $fullimage . '\'';
         }
         if ($d['file_type'] == 'product_images') {
             $q .= ', `product_thumb_image`=\'' . $thumbimage . '\'';
         }
         if ($d['file_type'] == 'product_thumb_image') {
             $q .= '`product_thumb_image`=\'' . $db->getEscaped($filename) . '\'';
         }
         $q .= ' WHERE `product_id` =' . intval($d["product_id"]);
         $db->query($q);
         $vmLogger->info($VM_LANG->_('VM_PRODUCT_FILES_IMAGES_SET'));
         return true;
     } else {
         // erase $mosConfig_absolute_path to have a relative path
         $filename = str_replace($mosConfig_absolute_path, '', $filename);
         if (empty($filename) && !empty($d['file_url'])) {
             $filename = vmGet($d, 'file_url');
         }
         if ($d['file_type'] == 'downloadable_file') {
             if ($filename == $d['file_url']) {
                 $attribute_value = $filename;
             } else {
                 $attribute_value = basename($filename);
             }
             $d['file_title'] = $attribute_value;
             // Insert an attribute called "download", attribute_value: filename
             $fields = array('product_id' => $d["product_id"], 'attribute_name' => 'download', 'attribute_value' => $attribute_value);
             $db->buildQuery('INSERT', '#__{vm}_product_attribute', $fields);
             $db->query();
         }
         $fields = array('file_product_id' => $d["product_id"], 'file_name' => $db->getEscaped($filename), 'file_title' => $db->getEscaped($d["file_title"]), 'file_extension' => $ext, 'file_mimetype' => $_FILES['file_upload']['type'], 'file_url' => $d['file_url'], 'file_published' => $d["file_published"], 'file_is_image' => $is_image, 'file_image_height' => $file_image_height, 'file_image_width' => $file_image_width, 'file_image_thumb_height' => $file_image_thumb_height, 'file_image_thumb_width' => $file_image_thumb_width);
         $db->buildQuery('INSERT', '#__{vm}_product_files', $fields);
         if ($db->query() !== false) {
             $vmLogger->info($VM_LANG->_('VM_PRODUCT_FILES_ADDED'));
             $_REQUEST['file_id'] = $db->last_insert_id();
         } else {
             return false;
         }
     }
     return True;
 }