/** * Save the configuration variables for this module that come in from the POST * array. * * @param array An array of configuration variables. * @return boolean True if successful. */ public function SaveModuleSettings($settings = array()) { // Delete any current settings the module has $this->DeleteModuleSettings(); // Insert the new settings if (empty($settings)) { return true; } $shippingMethod = GetShippingMethodById($this->methodId); // Mark the module as being configured $newVar = array('zoneid' => $shippingMethod['zoneid'], 'methodid' => $this->methodId, 'modulename' => $this->GetId(), 'variablename' => 'is_setup', 'variableval' => 1, 'varvendorid' => $shippingMethod['methodvendorid']); $GLOBALS['ISC_CLASS_DB']->InsertQuery("shipping_vars", $newVar); $moduleVariables = $this->GetCustomVars(); // Loop through the options that this module has foreach ($settings as $name => $value) { $format = ''; if (isset($moduleVariables[$name]['format'])) { $format = $moduleVariables[$name]['format']; } if (is_array($value)) { foreach ($value as $childValue) { switch ($format) { case 'price': $value = DefaultPriceFormat($childValue); break; case 'weight': case 'dimension': $value = DefaultDimensionFormat($value); break; } // Mark the module as being configured $newVar = array('zoneid' => $shippingMethod['zoneid'], 'methodid' => $this->methodId, 'modulename' => $this->GetId(), 'variablename' => $name, 'variableval' => $childValue, 'varvendorid' => $shippingMethod['methodvendorid']); $GLOBALS['ISC_CLASS_DB']->InsertQuery("shipping_vars", $newVar); } } else { switch ($format) { case 'price': $value = DefaultPriceFormat($value); break; case 'weight': case 'dimension': $value = DefaultDimensionFormat($value); break; } // Mark the module as being configured $newVar = array('zoneid' => $shippingMethod['zoneid'], 'methodid' => $this->methodId, 'modulename' => $this->GetId(), 'variablename' => $name, 'variableval' => $value, 'varvendorid' => $shippingMethod['methodvendorid']); $GLOBALS['ISC_CLASS_DB']->InsertQuery("shipping_vars", $newVar); } } return true; }
/** * _GetVariationData * Load the variation data for a product either from the form or database * * @param Int $ProductId The ID of the product to load variations for. 0 if it's a new product * @param String $RefArray The array to store the variation details in * @return Void */ public function _GetVariationData($ProductId = 0, &$RefArray = array()) { if ($ProductId == 0) { // First, do we even have a variation selected? if (isset($_POST['variationId']) && is_numeric($_POST['variationId']) && isset($_POST['options'])) { foreach ($_POST['options'] as $option_counter => $option) { $tmp = array(); // The combination ID hasn't been assigned yet if (isset($option['id'])) { $tmp['combinationid'] = $option['id']; } else { $tmp['combinationid'] = 0; } // The product ID hasn't been assigned yet $tmp['vcproductid'] = 0; // The variation id $tmp['vcvariationid'] = (int) $_POST['variationId']; // Is the combination enabled? $tmp['vcenabled'] = 0; if (isset($option['enabled'])) { $tmp['vcenabled'] = 1; } // The variation option combination $ids = preg_replace("/^#/", "", $option['variationcombination']); $ids = str_replace("#", ",", $ids); $tmp['vcoptionids'] = $ids; // The product option's SKU $tmp['vcsku'] = $option['sku']; // The price difference type $tmp['vcpricediff'] = $option['pricediff']; // The price difference or fixed price $tmp['vcprice'] = DefaultPriceFormat($option['price']); // The weight difference type $tmp['vcweightdiff'] = $option['weightdiff']; // The weight difference or fixed weight $tmp['vcweight'] = DefaultDimensionFormat($option['weight']); // The image for this product option (if it's set) if ($this->_IsValidVariationImage($option_counter)) { $tmp['vcimage'] = $this->_StoreOptionImageAndReturnId($option_counter); } else { // Do we need to remove the image? if (isset($option['delimage'])) { $tmp['vcimage'] = "REMOVE"; } else { $tmp['vcimage'] = ""; } } // The thumbnail image for this product option if ($tmp['vcimage'] != "") { $tmp['vcthumb'] = $this->_AutoGenerateThumb($tmp['vcimage']); } else { $tmp['vcthumb'] = ""; } // The current stock level if (isset($option['currentstock'])) { $tmp['vcstock'] = (int) $option['currentstock']; } else { $tmp['vcstock'] = 0; } // The low stock level if (isset($option['lowstock'])) { $tmp['vclowstock'] = (int) $option['lowstock']; } else { $tmp['vclowstock'] = 0; } // Push the option to the stack array_push($RefArray, $tmp); } } } }
/** * Save the configuration variables for this module that come in from the POST * array. * * @param array An array of configuration variables. * @return boolean True if successful. */ public function SaveModuleSettings($settings = array()) { foreach (array_keys($settings) as $setting) { list($fieldType, ) = explode('_', $setting, 2); switch ($fieldType) { case 'upper': case 'lower': $settings[$setting] = DefaultDimensionFormat($settings[$setting]); break; case 'cost': $settings[$setting] = DefaultPriceFormat($settings[$setting]); break; } } parent::SaveModuleSettings($settings); }
/** * Imports an actual product record in to the database. * * @param array Array of record data */ protected function _ImportRecord($record) { if(empty($record['prodname'])) { $this->ImportSession['Results']['Failures'][] = implode(",", $record['original_record'])." ".GetLang('ImportProductsMissingName'); return; } if ($message = strtokenize($_REQUEST, '#')) { $this->ImportSession['Results']['Failures'][] = implode(",", $record['original_record'])." ".GetLang(B('UmVhY2hlZFByb2R1Y3RMaW1pdA==')); return; } $record = $this->normalizeInventoryTracking($record); $productHash = uniqid('IMPORT', true); $productId = 0; $hasThumb = false; $productFiles = array(); $productImages = array(); $existing = null; $isOverrideDuplicates = !empty($this->ImportSession['OverrideDuplicates']); $dupeCheckWhere = ''; // Is there an existing product with this product ID ? if (!empty($record['productid'])) { $query = "SELECT * FROM [|PREFIX|]products WHERE productid = " . (int)$record['productid']; $result = $GLOBALS["ISC_CLASS_DB"]->Query($query); if($existing = $GLOBALS["ISC_CLASS_DB"]->Fetch($result)) { // Overriding existing products, set the product id if($isOverrideDuplicates) { $productId = $existing['productid']; $this->addImportResult('Updates', $record['prodname']); } else { // a product was found, but we're not updating existing record: skip $this->addImportResult('Duplicates', $record['prodname']); return; } // merge existing product details with the incoming record $record = $this->mergeExistingRecord($record, $existing); } else { // no product for this id was found, skip $this->addImportResult('Failures', $record['productid'] . " " . GetLang('ImportProductNotFound')); return; } $dupeCheckWhere = " AND productid != " . (int)$record['productid']; } // Check if there is a different product with the same name $query = "SELECT * FROM [|PREFIX|]products WHERE prodname = '" . $GLOBALS['ISC_CLASS_DB']->Quote($record['prodname']) . "'" . $dupeCheckWhere; $result = $GLOBALS["ISC_CLASS_DB"]->Query($query); $differentProductWithSameName = $GLOBALS['ISC_CLASS_DB']->Fetch($result); if($differentProductWithSameName) { if($existing || !$isOverrideDuplicates) { $this->addImportResult('Duplicates', $record['prodname']); return; } $existing = $differentProductWithSameName; $productId = $existing['productid']; $this->addImportResult('Updates', $record['prodname']); $record = $this->mergeExistingRecord($record, $existing); } // Apply any default data $defaults = array( 'prodprice' => 0, 'prodcostprice' => 0, 'prodretailprice' => 0, 'prodsaleprice' => 0, 'prodweight' => 0, 'prodheight' => 0, 'prodwidth' => 0, 'proddepth' => 0, 'prodsearchkeywords' => '', 'prodsortorder' => 0, 'prodvisible' => 1, 'prodfeatured' => 0, 'prodrelatedproducts' => '-1', 'prodoptionsrequired' => 0, 'prodfreeshipping' => 0, 'prodlayoutfile' => '', 'prodtags' => '', 'prodcondition' => 'New', 'prodshowcondition' => 0, 'prodallowpurchases' => 1, 'prodeventdaterequired' => 0, 'prodeventdatefieldname' => '', 'prodeventdatelimited' => 0, 'prodeventdatelimitedtype' => 0, 'prodeventdatelimitedstartdate' => 0, 'prodeventdatelimitedenddate' => 0, 'prodbrandid' => 0, 'tax_class_name' => '', 'upc' => '', 'category' => null, ); $record += $defaults; // check validity of price columns $priceFields = array( 'prodprice', 'prodcostprice', 'prodsaleprice', 'prodretailprice' ); foreach ($priceFields as $field) { // price was invalid if (!IsPrice($record[$field])) { if ($productId) { // using existing price $record[$field] = $existing[$field]; } else { $record[$field] = 0; } $this->addImportResult('Warnings', $record['prodname']." ".GetLang('ImportProductInvalidPrice')); } } // Do we have a product file? $productFiles = array(); if (!$this->ImportSession['IsBulkEdit']) { if (!empty($record['prodfile'])) { $productFile = $this->_ImportFile($record); if ($productFile) { $productFiles[] = $productFile; } } } else { // bulk import files for ($x = 1; $x <= $this->ImportSession['MultiFieldCount']['files']; $x++) { if (empty($record['prodfile' . $x])) { continue; } $productFile = $this->_ImportFile($record, $x); if ($productFile) { $productFiles[] = $productFile; } } } // Do we have an image? $productImages = array(); if (!$this->ImportSession['IsBulkEdit']) { if(!empty($record['prodimagefile'])) { $importedImage = $this->_ImportImage($productId, $record); if ($importedImage) { $productImages[] = $importedImage; } } } else { // bulk import images for ($x = 1; $x <= $this->ImportSession['MultiFieldCount']['images']; $x++) { if (empty($record['prodimagefile' . $x])) { if (empty($record['prodimageid' . $x])) { continue; } // image file is empty but an ID was supplied, we should delete the image if ($productId) { try { $image = new ISC_PRODUCT_IMAGE($record['prodimageid' . $x]); // ensure this image is associated with this product if ($image->getProductId() == $productId) { $image->delete(); } } catch (Exception $ex) { } } continue; } $importedImage = $this->_ImportImage($productId, $record, $x); if ($importedImage) { $productImages[] = $importedImage; } } } // a category is not required if we have an existing record and ignore blanks is enabled $requireCatsField = !(!empty($record['productid']) && $this->ignoreBlankFields()); $cats = $this->getImportRecordCategories($record); if($requireCatsField && empty($cats)) { $this->addImportResult('Failures', implode(",", $record['original_record'])." ".GetLang('ImportProductsMissingCategory')); return; } // If there's a tax class, we need to fetch it now $record['tax_class_id'] = 0; if(!empty($record['tax_class_name'])) { static $taxClassCache = array(); if(!isset($taxClassCache[$record['tax_class_name']])) { $query = " SELECT id FROM [|PREFIX|]tax_classes WHERE name='".$GLOBALS['ISC_CLASS_DB']->quote($record['tax_class_name'])."' "; $taxClassCache[$record['tax_class_name']] = $GLOBALS['ISC_CLASS_DB']->fetchOne($query); } // Still don't have a matching tax class? Must be new. if(!$taxClassCache[$record['tax_class_name']]) { $newTaxClass = array( 'name' => $record['tax_class_name'] ); $taxClassCache[$record['tax_class_name']] = $GLOBALS['ISC_CLASS_DB']->insertQuery('tax_classes', $newTaxClass); } $record['tax_class_id'] = $taxClassCache[$record['tax_class_name']]; } // check the condition is valid $validConditions = array('new', 'used', 'refurbished'); if (!isset($record['prodcondition']) || !in_array(isc_strtolower($record['prodcondition']), $validConditions)) { $record['prodcondition'] = 'New'; } // Does the brand already exist? if(isset($record['brandname']) && $record['brandname'] != '') { $query = sprintf("select brandid from [|PREFIX|]brands where brandname='%s'", $GLOBALS['ISC_CLASS_DB']->Quote($record['brandname'])); $result = $GLOBALS['ISC_CLASS_DB']->Query($query); if($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) { $brandId = $row['brandid']; } // Create new brand else { // do we have permission to create brands? if ($GLOBALS["ISC_CLASS_ADMIN_AUTH"]->HasPermission(AUTH_Add_Brands)) { $newBrand = array( "brandname" => $record['brandname'] ); $brandId = $GLOBALS['ISC_CLASS_DB']->InsertQuery("brands", $newBrand); } else { // no brand creation permission, abort this record $this->addImportResult('Failures', $record['prodname'] . " " . GetLang('ImportNoPermissionCreateBrand')); return; } } $record['prodbrandid'] = $brandId; } else if(!$this->ignoreBlankFields()){ $record['prodbrandid'] = 0; } if (isset($record['prodfile']) && $record['prodfile'] != '') { $productType = 2; } else if (isset($existing['prodtype']) && isId($existing['prodtype'])) { $productType = (int)$existing['prodtype']; } else { $productType = 1; } // event date $record['prodeventdaterequired'] = $this->StringToYesNoInt($record['prodeventdaterequired']); if ($record['prodeventdaterequired']) { // we must have an event name if (empty($record['prodeventdatefieldname'])) { $record['prodeventdaterequired'] = 0; $this->addImportResult('Warnings', $record['prodname'] . ' ' . GetLang('ImportNoEventDateName')); } else { $record['prodeventdatelimited'] = $this->StringToYesNoInt($record['prodeventdatelimited']); if ($record['prodeventdatelimited']) { if (!empty($record['prodeventdatelimitedstartdate'])) { $record['prodeventdatelimitedstartdate'] = (int)@ConvertDateToTime($record['prodeventdatelimitedstartdate']); } if (!empty($record['prodeventdatelimitedenddate'])) { $record['prodeventdatelimitedenddate'] = (int)@ConvertDateToTime($record['prodeventdatelimitedenddate']); } // determine what type of event date it is if ($record['prodeventdatelimitedstartdate'] > 0 && $record['prodeventdatelimitedenddate'] == 0) { $record['prodeventdatelimitedtype'] = 2; // start date } elseif ($record['prodeventdatelimitedstartdate'] == 0 && $record['prodeventdatelimitedenddate'] > 0) { $record['prodeventdatelimitedtype'] = 3; // end date } elseif ($record['prodeventdatelimitedenddate'] > $record['prodeventdatelimitedstartdate']) { $record['prodeventdatelimitedtype'] = 1; // date range } else { $record['prodeventdatelimited'] = 0; $this->addImportResults('Warnings', $record['prodname'] . ' ' . GetLang('ImportEventDateInvalid')); } } } } // Verify the inventory tracking method is valid. if($record['prodinvtrack'] == 2 && !($existing && $existing['prodvariationid'])) { $this->addImportResult('Warnings', $record['prodname'] . ' ' . GetLang('ImportProductTrackInventoryNoVariations')); $record['prodinvtrack'] = $existing['prodinvtrack']; } // This is our product $productData = array( "prodname" => $record['prodname'], "prodcode" => @$record['prodcode'], "proddesc" => @$record['proddesc'], "prodsearchkeywords" => @$record['prodsearchkeywords'], "prodtype" => $productType, "prodprice" => DefaultPriceFormat($record['prodprice']), "prodcostprice" => DefaultPriceFormat($record['prodcostprice']), "prodretailprice" => DefaultPriceFormat($record['prodretailprice']), "prodsaleprice" => DefaultPriceFormat($record['prodsaleprice']), "prodavailability" => @$record['prodavailability'], "prodsortorder" => $record['prodsortorder'], "prodvisible" => (int)$record['prodvisible'], "prodfeatured" => $record['prodfeatured'], "prodrelatedproducts" => $record['prodrelatedproducts'], "prodinvtrack" => (int)@$record['prodinvtrack'], "prodcurrentinv" => (int)@$record['prodcurrentinv'], "prodlowinv" => (int)@$record['prodlowinv'], "prodoptionsrequired" => $record['prodoptionsrequired'], "prodwarranty" => @$record['prodwarranty'], "prodheight" => DefaultDimensionFormat(@$record['prodheight']), "prodweight" => DefaultDimensionFormat(@$record['prodweight']), "prodwidth" => DefaultDimensionFormat(@$record['prodwidth']), "proddepth" => DefaultDimensionFormat(@$record['proddepth']), "prodfreeshipping" => (int)$record['prodfreeshipping'], "prodfixedshippingcost" => DefaultPriceFormat(@$record['prodfixedshippingcost']), "prodbrandid" => (int)$record['prodbrandid'], "prodcats" => $cats, "prodpagetitle" => @$record['prodpagetitle'], "prodmetakeywords" => @$record['prodmetakeywords'], "prodmetadesc" => @$record['prodmetadesc'], "prodlayoutfile" => $record['prodlayoutfile'], 'prodtags' => $record['prodtags'], 'prodmyobasset' => '', 'prodmyobincome' => '', 'prodmyobexpense' => '', 'prodpeachtreegl' => '', 'prodcondition' => $record['prodcondition'], 'prodshowcondition' => (bool)$record['prodshowcondition'], 'prodallowpurchases' => (bool)$record['prodallowpurchases'], 'prodeventdaterequired' => $record['prodeventdaterequired'], 'prodeventdatefieldname' => $record['prodeventdatefieldname'], 'prodeventdatelimited' => $record['prodeventdatelimited'], 'prodeventdatelimitedtype' => $record['prodeventdatelimitedtype'], 'prodeventdatelimitedstartdate' => $record['prodeventdatelimitedstartdate'], 'prodeventdatelimitedenddate' => $record['prodeventdatelimitedenddate'], 'tax_class_id' => $record['tax_class_id'], 'upc' => $record['upc'], 'last_import' => $this->ImportSession['StartTime'], ); /** * The variation is part of the product record, so it will have to be attached to the record if this is an * update AND the existing product already has a variation */ if (isset($existing) && is_array($existing) && isId($existing['prodvariationid'])) { $productData['prodvariationid'] = $existing['prodvariationid']; } $empty = array(); // Save it $err = ''; if (!$GLOBALS['ISC_CLASS_ADMIN_PRODUCT']->_CommitProduct($productId, $productData, $empty, $empty, $empty, $err, $empty, true)) { $this->addImportResult('Failures', $record['prodname'] . " " . GetLang('ImportDatabaseError')); return; } if($productId == 0) { $productId = $GLOBALS['NewProductId']; } // Post process images $existingImages = new ISC_PRODUCT_IMAGE_ITERATOR("SELECT * FROM `[|PREFIX|]product_images` WHERE imageprodid = " . (int)$productId); $maxSort = count($existingImages); if ($this->ImportSession['DeleteImages']) { foreach ($existingImages as $existingImage) { $existingImage->delete(false); } $maxSort = 0; } if(!empty($productImages)) { // sort the images usort($productImages, array($this, "_compare_images")); // update our images with the product id foreach ($productImages as $image) { $image->setProductId($productId); // ensure that an image doesn't have a sort set higher than max, or if no sort specified, then also set it to the highest. if ($image->getSort() > $maxSort || $image->getSort() === null) { $image->setSort($maxSort); $maxSort++; } $image->saveToDatabase(false); } } // Delete existing files if ($this->ImportSession['DeleteDownloads']) { $query = " SELECT * FROM [|PREFIX|]product_downloads WHERE productid = " . $productId; $result = $GLOBALS['ISC_CLASS_DB']->Query($query); while ($download = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) { // Remove the file from the file system @unlink(GetConfig('DownloadDirectory') . "/" . $download['downfile']); // Delete from the database $GLOBALS['ISC_CLASS_DB']->DeleteQuery('product_downloads', 'WHERE downloadid = ' . $download['downloadid']); } } // Process product files if(!empty($productFiles)) { foreach($productFiles as $file) { $file['productid'] = $productId; $GLOBALS['ISC_CLASS_DB']->InsertQuery("product_downloads", $file); } } ++$this->ImportSession['Results']['SuccessCount']; }
/** * _GetVariationData * Load the variation data for a product either from the form or database * * @param Int $ProductId The ID of the product to load variations for. 0 if it's a new product * @param String $RefArray The array to store the variation details in * @return Void */ public function _GetVariationData($ProductId = 0, &$RefArray = array()) { if($ProductId == 0) { // First, do we even have a variation selected? if(isset($_POST['variationId']) && is_numeric($_POST['variationId']) && isset($_POST['options'])) { foreach($_POST['options'] as $option_counter => $option) { $tmp = array(); // The combination ID hasn't been assigned yet if(isset($option['id'])) { $tmp['combinationid'] = $option['id']; } else { $tmp['combinationid'] = 0; } // The product ID hasn't been assigned yet $tmp['vcproductid'] = 0; // The variation id $tmp['vcvariationid'] = (int)$_POST['variationId']; // Is the combination enabled? $tmp['vcenabled'] = 0; if(isset($option['enabled'])) { $tmp['vcenabled'] = 1; } // The variation option combination $ids = preg_replace("/^#/", "", $option['variationcombination']); $ids = str_replace("#", ",", $ids); $tmp['vcoptionids'] = $ids; // The product option's SKU $tmp['vcsku'] = $option['sku']; // The price difference type $tmp['vcpricediff'] = $option['pricediff']; // The price difference or fixed price $tmp['vcprice'] = DefaultPriceFormat($option['price']); // The weight difference type $tmp['vcweightdiff'] = $option['weightdiff']; // The weight difference or fixed weight $tmp['vcweight'] = DefaultDimensionFormat($option['weight']); $tmp['vcimage'] = ''; $tmp['vcimagezoom'] = ''; $tmp['vcimagestd'] = ''; $tmp['vcimagethumb'] = ''; if (isset($_FILES['options']['name'][$option_counter]['image']) && $_FILES['options']['name'][$option_counter]['image'] != '') { try { $image = ISC_PRODUCT_IMAGE::importImage( $_FILES['options']['tmp_name'][$option_counter]['image'], $_FILES['options']['name'][$option_counter]['image'], false, false, true, false ); $tmp['vcimage'] = $image->getSourceFilePath(); $tmp['vcimagezoom'] = $image->getResizedFilePath(ISC_PRODUCT_IMAGE_SIZE_ZOOM, true, false); $tmp['vcimagestd'] = $image->getResizedFilePath(ISC_PRODUCT_IMAGE_SIZE_STANDARD, true, false); $tmp['vcimagethumb'] = $image->getResizedFilePath(ISC_PRODUCT_IMAGE_SIZE_THUMBNAIL, true, false); } catch (Exception $ex) { } } elseif (isset($option['delimage'])) { $tmp['vcimage'] = "REMOVE"; } // The current stock level if(isset($option['currentstock'])) { $tmp['vcstock'] = (int)$option['currentstock']; } else { $tmp['vcstock'] = 0; } // The low stock level if(isset($option['lowstock'])) { $tmp['vclowstock'] = (int)$option['lowstock']; } else { $tmp['vclowstock'] = 0; } // Push the option to the stack array_push($RefArray, $tmp); } } } }
/** * Save the configuration variables for this module that come in from the POST * array. * * @param array An array of configuration variables. * @param bool RUE to delete any existing module settings, FALSE not to. Default is TRUE * @return boolean True if successful. */ public function SaveModuleSettings($settings = array(), $deleteFirst = true) { // Delete any current settings the module has if we are set to if ($deleteFirst) { $this->DeleteModuleSettings(); } // If we weren't supplied any settings and this module has one or more settings // don't continue and don't mark it as being set up yet if (empty($settings) && $this->GetNumSettings() > 0) { return true; } // Mark the module has being configured $newVar = array('modulename' => $this->GetId(), 'variablename' => 'is_setup', 'variableval' => 1); $GLOBALS['ISC_CLASS_DB']->InsertQuery('module_vars', $newVar); $moduleVariables = $this->GetCustomVars(); // Loop through the options that this module has foreach ($settings as $name => $value) { $format = ''; if (isset($moduleVariables[$name]['format'])) { $format = $moduleVariables[$name]['format']; } if (is_array($value)) { foreach ($value as $childValue) { switch ($format) { case 'price': $value = DefaultPriceFormat($childValue); break; case 'weight': case 'dimension': $value = DefaultDimensionFormat($value); break; } $newVar = array('modulename' => $this->GetId(), 'variablename' => $name, 'variableval' => $childValue); $GLOBALS['ISC_CLASS_DB']->InsertQuery('module_vars', $newVar); } } else { switch ($format) { case 'price': $value = DefaultPriceFormat($value); break; case 'weight': case 'dimension': $value = DefaultDimensionFormat($value); break; } $newVar = array('modulename' => $this->GetId(), 'variablename' => $name, 'variableval' => $value); $GLOBALS['ISC_CLASS_DB']->InsertQuery('module_vars', $newVar); } } return true; }
/** * The email integration modules save differently than other module types, so this method is overridden. * * @param array $settings * @param bool $deleteFirst This is ignored for email integration modules * @return boolean */ public function SaveModuleSettings($settings = array(), $deleteFirst = true) { $moduleVariables = $this->GetCustomVars(); /** @var mysqldb */ $db = $GLOBALS['ISC_CLASS_DB']; // general/api settings foreach ($settings as $name => $value) { if (!isset($moduleVariables[$name])) { continue; } $moduleVariable = $moduleVariables[$name]; if (isset($moduleVariable['format'])) { $format = $moduleVariable['format']; } else { $format = ''; } switch($format) { case 'boolean': if ($value) { $value = 1; } else { $value = 0; } break; case 'price': $value = DefaultPriceFormat($value); break; case 'weight': case 'dimension': $value = DefaultDimensionFormat($value); break; } $exists = $db->FetchOne("SELECT COUNT(*) FROM [|PREFIX|]module_vars WHERE modulename = '" . $db->Quote($this->GetId()) . "' AND variablename = '" . $db->Quote($name) . "'"); if ($exists > 0) { $db->UpdateQuery('module_vars', array('variableval' => $value), "modulename = '" . $db->Quote($this->GetId()) . "' AND variablename = '" . $db->Quote($name) . "'"); } else { $row = array( 'modulename' => $this->GetId(), 'variablename' => $name, 'variableval' => $value ); $db->InsertQuery('module_vars', $row); } $this->moduleVariables[$name] = $value; } // if provided, process rule builder POST data and serialize to config $commitRules = false; $decodedRules = false; $returnValue = true; GetLib('class.json'); /** @var ISC_LOG */ $log = $GLOBALS['ISC_CLASS_LOG']; // if rules are not set, do not save them if (isset($settings['rules'])) { if ($settings['rules']) { $decodedRules = ISC_JSON::decode($settings['rules'], true); if ($decodedRules) { $commitRules = true; } else { // do not save rules if they are set but failed to decode $log->LogSystemError(array('emailintegration', $this->GetName()), 'Failed to decode email integration rules JSON packet', $settings['rules']); $returnValue = false; } } else { // rules are set, but blank, so delete all rules $decodedRules = array(); $commitRules = true; } } if ($commitRules) { // parse and save each rule - _Rule class will handle insert or update $ruleIds = array(); $db->StartTransaction(); $transactionOk = true; $ruleIds = array(); if (!empty($decodedRules)) { foreach ($decodedRules as $rule) { $rule = Interspire_EmailIntegration_Rule::fromJSON($rule); if (!$rule) { $log->LogSystemError(array('emailintegration', $this->GetName()), 'Failed to translate email integration rule from JSON to EmailIntegration_Rule class.', $settings['rules']); $transactionOk = false; continue; } if (!$rule->save()) { $transactionOk = false; continue; } $ruleIds[] = $rule->id; } if ($transactionOk) { // rules saved ok - delete rules that should no longer exist if (!$db->DeleteQuery('email_rules', "WHERE `provider` = '" . $db->Quote($this->GetId()) . "' AND `id` NOT IN (" . implode(',', $ruleIds) . ")")) { $transactionOk = false; $log->LogSystemError(array('emailintegration', $this->GetName()), 'Failed to remove old integration rules due to database error.'); } } } else { if (!$db->DeleteQuery('email_rules', "WHERE `provider` = '" . $db->Quote($this->GetId()) . "'")) { $transactionOk = false; $log->LogSystemError(array('emailintegration', $this->GetName()), 'Failed to remove old integration rules due to database error.'); } } if ($transactionOk) { $db->CommitTransaction(); self::flushRules(); } else { $db->RollbackTransaction(); $returnValue = false; } } return $returnValue; }