Example #1
0
		private function _CommitPage($PageId, &$Data, &$err)
		{
			// Commit the details for the page to the database
			$query = "";
			$err = null;

			// Update other pages if this page is set as the home page
			if($Data['pageishomepage'] == 1) {
				$updatedPage = array(
					"pageishomepage" => 0
				);
				$GLOBALS['ISC_CLASS_DB']->UpdateQuery("pages", $updatedPage);
			}

			if ($PageId == 0) {
				// ----- Build the query for the news table -----

				// Linked pages can't be the home page
				if ((int) $Data['pagetype'] == 1) {
					$Data['pageishomepage'] = 0;
				}

				$newPage = array(
					"pagetitle" => $Data['pagetitle'],
					"pagelink" => $Data['pagelink'],
					"pagefeed" => $Data['pagefeed'],
					"pageemail" => $Data['pageemail'],
					"pagecontent" => $Data['pagecontent'],
					"pagestatus" => (int)$Data['pagestatus'],
					"pageparentid" => (int)$Data['pageparentid'],
					"pagesort" => $Data['pagesort'],
					"pagekeywords" => $Data['pagekeywords'],
					"pagemetatitle" => $Data['pagemetatitle'],
					"pagedesc" => $Data['pagedesc'],
					"pagesearchkeywords" => $Data['pagesearchkeywords'],
					"pagetype" => (int)$Data['pagetype'],
					"pagecontactfields" => $Data['pagecontactfields'],
					"pageishomepage" => 0,
					"pagelayoutfile" => $Data['pagelayoutfile'],
					"pagecustomersonly" => $Data['pagecustomersonly'],
					"pageparentlist" => "",
					'pagevendorid' => (int)$Data['pagevendorid'],
					"page_enable_optimizer" => (int)$Data['page_enable_optimizer'],
				);

				if (!$GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetVendorId()) {
					$newPage["pageishomepage"] = (int)$Data['pageishomepage'];
				}

				$PageId = $GLOBALS['ISC_CLASS_DB']->InsertQuery("pages", $newPage);

				if($PageId) {
					// Now we need to store the page parent list
					$parentList = $this->_BuildPageParentList($PageId);
					$updatedPage = array(
						"pageparentlist" => $parentList
					);
					$GLOBALS['ISC_CLASS_DB']->UpdateQuery("pages", $updatedPage, "pageid='".$GLOBALS['ISC_CLASS_DB']->Quote((int)$PageId)."'");

					// Rebuild the nested-set tree
					// @todo if this process becomes too slow on sites with many pages, this can be optimized to do only a partial update - see: how category create works
					$nested = new ISC_NESTEDSET_PAGES();
					$nested->rebuildTree();
				}

				$err = $GLOBALS["ISC_CLASS_DB"]->GetError();

			} else {
				$query = "";

				// Only a normal page can be a home page
				if ((int) $Data['pagetype'] == 1) {
					$Data['pageishomepage'] = 0;
				}

				// Update the existing pages details
				$updatedPage = array(
					"pagetitle" => $Data['pagetitle'],
					"pagelink" => $Data['pagelink'],
					"pagefeed" => $Data['pagefeed'],
					"pageemail" => $Data['pageemail'],
					"pagecontent" => $Data['pagecontent'],
					"pagestatus" => (int)$Data['pagestatus'],
					"pageparentid" => (int)$Data['pageparentid'],
					"pagesort" => $Data['pagesort'],
					"pagekeywords" => $Data['pagekeywords'],
					"pagemetatitle" => $Data['pagemetatitle'],
					"pagedesc" => $Data['pagedesc'],
					"pagesearchkeywords" => $Data['pagesearchkeywords'],
					"pagetype" => (int)$Data['pagetype'],
					"pagecontactfields" => $Data['pagecontactfields'],
					"pageishomepage" => (int)$Data['pageishomepage'],
					"pagelayoutfile" => $Data['pagelayoutfile'],
					"pagecustomersonly" => $Data['pagecustomersonly'],
					'pagevendorid' => (int)$Data['pagevendorid'],
					"page_enable_optimizer" => (int)$Data['page_enable_optimizer'],
				);

				$GLOBALS['ISC_CLASS_DB']->UpdateQuery("pages", $updatedPage, "pageid='".$GLOBALS['ISC_CLASS_DB']->Quote((int)$PageId)."'");
				$err = $GLOBALS["ISC_CLASS_DB"]->GetError();

				if($err[0] == "") {
					// Rebuild the nested-set tree
					// @todo if this process becomes too slow on sites with many pages, this can be optimized to do only a partial update
					$nested = new ISC_NESTEDSET_PAGES();
					$nested->rebuildTree();
				}
			}

			// Update the pages cache
			$GLOBALS['ISC_CLASS_DATA_STORE']->UpdatePages();

			$optimizer = getClass('ISC_ADMIN_OPTIMIZER');
			if(isset($Data["page_enable_optimizer"]) && $Data["page_enable_optimizer"] == 1) {
				$optimizer->savePerItemOptimizerConfig('page', $PageId);
			} else {
				$optimizer->deletePerItemOptimizerConfig('page', array($PageId));
			}


			if($err[0] != "") {
				return false;
			}

			// Add/edit out search record
			$savedata = array(
				"pageid" => $PageId,
				"pagetitle" => $Data['pagetitle'],
				"pagecontent" => stripHTMLForSearchTable($Data['pagecontent']),
				"pagedesc" => stripHTMLForSearchTable($Data['pagedesc']),
				"pagesearchkeywords" => $Data['pagesearchkeywords']
			);

			$query = "SELECT pagesearchid
						FROM [|PREFIX|]page_search
						WHERE pageid=" . (int)$PageId;

			$searchId = $GLOBALS["ISC_CLASS_DB"]->FetchOne($query);

			if (isId($searchId)) {
				$GLOBALS["ISC_CLASS_DB"]->UpdateQuery("page_search", $savedata, "pagesearchid=" . (int)$searchId);
			} else {
				$GLOBALS["ISC_CLASS_DB"]->InsertQuery("page_search", $savedata);
			}

			// Save the words to the news_words table for search spelling suggestions
			Store_SearchSuggestion::manageSuggestedWordDatabase("page", $PageId, $Data['pagetitle']);

			return true;
		}
Example #2
0
		/**
		 * Save our search record
		 *
		 * Method will add/update the search record
		 *
		 * @access private
		 * @param int $catId The category ID
		 * @return bool TRUE if the search was added/edited successfully, FALSE if not
		 */
		private function saveSearch($catId)
		{
			if (!isId($catId)) {
				return false;
			}

			// Update our search record
			$savedata = array(
				"categoryid" => $catId,
				"catname" => $_POST["catname"],
				"catdesc" => stripHTMLForSearchTable($_POST["catdesc"]),
				"catsearchkeywords" => $_POST["catsearchkeywords"]
			);

			$query = "SELECT categorysearchid
						FROM [|PREFIX|]category_search
						WHERE categoryid=" . (int)$catId;

			$searchId = $this->db->FetchOne($query);

			if (isId($searchId)) {
				$rtn = $this->db->UpdateQuery("category_search", $savedata, "categorysearchid=" . (int)$searchId);
			} else {
				$rtn = $this->db->InsertQuery("category_search", $savedata);
			}

			if ($rtn === false) {
				return false;
			}

			return true;
		}
Example #3
0
		public function _CommitNews($NewsId=0)
		{
			// Commit the details for the news post to the database
			include_once(ISC_BASE_PATH.'/lib/api/news.api.php');
			$news = new API_NEWS();
			if ($NewsId == 0) {
				if(isset($_POST['wysiwyg_html'])) {
					$_POST['newscontent'] = $_POST['wysiwyg_html'];
				}
				else {
					$_POST['newscontent'] = $_POST['wysiwyg'];
				}
				$_POST['newsdate'] = time();
				$NewsId = $news->create();
			} else {
				if(isset($_POST['wysiwyg_html'])) {
					$_POST['newscontent'] = $_POST['wysiwyg_html'];
				}
				else {
					$_POST['newscontent'] = $_POST['wysiwyg'];
				}
				if(isset($_POST['newsvisible'])) {
					$_POST['newsvisible' ] = 1;
				}
				else {
					$_POST['newsvisible'] = 0;
				}
				$news->load($NewsId);
				$news->save();
			}

			if(!$news->error) {
				// Log this action
				$GLOBALS['ISC_CLASS_LOG']->LogAdminAction($NewsId, $_POST['newstitle']);

				$savedata = array(
					"newsid" => $NewsId,
					"newstitle" => $_POST["newstitle"],
					"newscontent" => stripHTMLForSearchTable($_POST["newscontent"]),
					"newssearchkeywords" => $_POST["newssearchkeywords"]
				);

				$query = "SELECT newssearchid
							FROM [|PREFIX|]news_search
							WHERE newsid=" . (int)$NewsId;

				$searchId = $GLOBALS["ISC_CLASS_DB"]->FetchOne($query);

				if (isId($searchId)) {
					$GLOBALS["ISC_CLASS_DB"]->UpdateQuery("news_search", $savedata, "newssearchid=" . (int)$searchId);
				} else {
					$GLOBALS["ISC_CLASS_DB"]->InsertQuery("news_search", $savedata);
				}

				// Save the words to the news_words table for search spelling suggestions
				Store_SearchSuggestion::manageSuggestedWordDatabase("news", $NewsId, $_POST["newstitle"]);
			}

			return $news->error;
		}
Example #4
0
		public function _CommitProduct($ProductId, &$Data, &$Variations, &$CustomFields, $DiscountRules=array(), &$Err = null, &$ProductFields=array(), $isImport=false)
		{
			$GLOBALS["ISC_CLASS_DB"]->clearError();

			// Commit the details for the product to the database
			$query = "";
			$err = null;
			$searchData = array(
				"prodname" => $Data['prodname'],
				"prodcode" => $Data['prodcode'],
				"proddesc" => stripHTMLForSearchTable($Data['proddesc']),
				"prodsearchkeywords" => $Data['prodsearchkeywords']
			);

			// Start the transaction
			$GLOBALS["ISC_CLASS_DB"]->Query("start transaction");
			$updateImageQuery = "";

			if ($ProductId == 0) {
				// Add the date this product was modified
				$prodId = $this->productEntity->add($Data);

				$GLOBALS['NewProductId'] = $prodId;

				// ---- Build the query for the product_search table ----
				$searchData['productid'] = $prodId;
				$GLOBALS['ISC_CLASS_DB']->InsertQuery("product_search", $searchData);

				// Build the queries for the videos table -----



				// Set some $_GET variables so the newest product appears at the top of the list
				$_GET['sortField'] = "productid";
				$_GET['sortOrder'] = "desc";

				// Save the product tags
				$this->SaveProductTags($Data['prodtags'], $prodId, true);
			}
			else {
				// Update the existing products details
				$prodId = $Data['productid'] = (int)$ProductId;
				$this->productEntity->edit($Data);

				// Update the search data
				$GLOBALS['ISC_CLASS_DB']->UpdateQuery("product_search", $searchData, "productid='".$GLOBALS['ISC_CLASS_DB']->Quote($prodId)."'");

				if (isset($Data['prodcats']) && $Data['prodcats'] != null) {
					// Remove the existing category associations
					$query = sprintf("DELETE FROM [|PREFIX|]categoryassociations WHERE productid='%d'", $prodId);
					$GLOBALS['ISC_CLASS_DB']->Query($query);
				}

				// Save the product tags
				$this->SaveProductTags($Data['prodtags'], $ProductId, false);
			}

			// Save the videos associated with the product
			if (isset($Data['product_videos'])) {
				// need the isset check as the importer isn't providing video data
				$this->saveProductVideos($prodId, $Data['product_videos']);
			}

			//save optimizer settings for this product
			$optimizer = getClass('ISC_ADMIN_OPTIMIZER');
			if(isset($Data['product_enable_optimizer']) && $Data['product_enable_optimizer']==1) {
				$optimizer->savePerItemOptimizerConfig('product', $prodId);
			} else {
				$optimizer->deletePerItemOptimizerConfig('product', array($prodId));
			}

			// Build the queries for the category associations table -----
			$accessibleCategories = array();
			if($GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetVendorId()) {
				$vendorInfo = $GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetVendor();
				if($vendorInfo['vendoraccesscats']) {
					$accessibleCategories = explode(',', $vendorInfo['vendoraccesscats']);
				}
			}
			if(isset($Data['prodcats'])) {
				foreach ($Data['prodcats'] as $cat) {
					// If this user doesn't have permission to place products in this category, skip over it
					if(!empty($accessibleCategories) && !in_array($cat, $accessibleCategories)) {
						continue;
					}
					$newAssociation = array(
						"productid" => $prodId,
						"categoryid" => $cat
					);
					$GLOBALS['ISC_CLASS_DB']->InsertQuery("categoryassociations", $newAssociation);
				}
			}

			/**
			 * Was this product commited from the batch importer? If so then exit now or we'll ruin all the other product linked tables
			 */
			if ($isImport) {
				if($GLOBALS["ISC_CLASS_DB"]->GetErrorMsg() == "") {
					// The product was commited successfully, commit the transaction
					$GLOBALS["ISC_CLASS_DB"]->Query("commit");
					return true;
				}
				else {
					// The product commit failed
					$GLOBALS["ISC_CLASS_DB"]->Query("rollback");
					return false;
				}
			}

			// Build the queries for the product variation combinations table -----
			// first delete any temporary combinations NOT for the chosen variation
			if (!empty($Data['prodhash'])) {
				$prodIdOrHash = $Data['prodhash'];
			}
			else {
				$prodIdOrHash = $prodId;
			}

			$this->DeleteTemporaryCombinationsForProduct($prodIdOrHash, $Data['prodvariationid']);


			/**
			 * Associated any hashed variations with the new product ID
			 */
			if (isset($Data['prodhash']) && $Data['prodhash'] !== '') {
				$savedata = array(
					'vcproductid' => $prodId,
					'vcproducthash' => '',
					'vclastmodified' => time()
				);

				$GLOBALS['ISC_CLASS_DB']->UpdateQuery('product_variation_combinations', $savedata, "vcproducthash='" . $GLOBALS['ISC_CLASS_DB']->Quote($Data['prodhash']) . "'");
			}


			if(isset($Data['prodvariationid']) && $Data['prodvariationid'] != 0 && isset($Variations) && is_array($Variations) && $Data['prodtype'] == PT_PHYSICAL) {
				// have we selected a variation that isn't the original variation? we need to move temp combinations to real ones
				// except if this is a variation switch for copied product (no dupe rows to delete)
				if ($ProductId != 0 && $Data['productVariationExisting'] != $Data['prodvariationid']) {
					// first nuke off any existing variation data
					if ($Data['productVariationExisting'] > 0) {
						$this->_DeleteVariationCombinationsForProduct($prodId);
					}

					$savedata = array(
						'vcproductid' => $prodId,
						'vcproducthash' => ''
					);

					$GLOBALS['ISC_CLASS_DB']->UpdateQuery('product_variation_combinations', $savedata, "vcproducthash='" . $GLOBALS['ISC_CLASS_DB']->Quote($prodId) . "'");
				}


				// update existing variations
				foreach($Variations as $Variation) {
					// First up, do we need to delete the image?
					if($Variation['vcimage'] == "REMOVE") {
						// Yes, get the image details
						$query = "
							SELECT
								vcimage,
								vcimagezoom,
								vcimagestd,
								vcimagethumb
							FROM
								[|PREFIX|]product_variation_combinations
							WHERE
								combinationid = " . $Variation['combinationid'];
						$result = $GLOBALS["ISC_CLASS_DB"]->Query($query);
						$row = $GLOBALS["ISC_CLASS_DB"]->Fetch($result);

						$this->DeleteVariationImagesForRow($row);
					}

					// Now update the record
					$updatedCombo = array(
						"vcproductid" => $prodId,
						"vcvariationid" => $Variation['vcvariationid'],
						"vcenabled" => $Variation['vcenabled'],
						"vcoptionids" => $Variation['vcoptionids'],
						"vcsku" => $Variation['vcsku'],
						"vcpricediff" => $Variation['vcpricediff'],
						"vcprice" => $Variation['vcprice'],
						"vcweightdiff" => $Variation['vcweightdiff'],
						"vcweight" => $Variation['vcweight'],
						"vcstock" => $Variation['vcstock'],
						"vclowstock" => $Variation['vclowstock'],
						"vclastmodified" => time()
					);

					// Only update the images if they've changed
					if($Variation['vcimage'] == "REMOVE") {
						$updatedCombo['vcimage'] = "";
						$updatedCombo['vcimagezoom'] = "";
						$updatedCombo['vcimagestd'] = "";
						$updatedCombo['vcimagethumb'] = "";
					}
					else if($Variation['vcimagezoom'] != "") {
						$updatedCombo['vcimage'] = $Variation['vcimage'];
						$updatedCombo['vcimagezoom'] = $Variation['vcimagezoom'];
						$updatedCombo['vcimagestd'] = $Variation['vcimagestd'];
						$updatedCombo['vcimagethumb'] = $Variation['vcimagethumb'];
					}

					$GLOBALS['ISC_CLASS_DB']->UpdateQuery("product_variation_combinations", $updatedCombo, "combinationid='".$GLOBALS['ISC_CLASS_DB']->Quote($Variation['combinationid'])."'");
				}

				// If the inventory tracking is happening per product variation then we need to add
				// the current and low stock level sums to the products table
				// ISC-982: do this for ALL variations of this product, not just those on current page
				if ($Data['prodinvtrack'] == 2) {
					$invQuery = "
						SELECT
							SUM(vcstock) AS prodcurrentinv,
							SUM(vclowstock) AS prodlowinv
						FROM
							[|PREFIX|]product_variation_combinations
						WHERE
							vcproductid = '".$GLOBALS['ISC_CLASS_DB']->Quote($prodId)."'";
					$result = $GLOBALS["ISC_CLASS_DB"]->Query($invQuery);
					$inv = $GLOBALS["ISC_CLASS_DB"]->Fetch($result);
					$GLOBALS['ISC_CLASS_DB']->UpdateQuery("products", $inv,  "productid='".$GLOBALS['ISC_CLASS_DB']->Quote($prodId)."'");
				}
			}
			else {
				// If it's an existing product then we need to delete all of the variation combinations, images, etc
				if($prodId > 0) {
					$this->_DeleteVariationCombinationsForProduct($prodId);
				}
			}

			// Build the queries for the custom fields table -----
			$GLOBALS['ISC_CLASS_DB']->Query("DELETE FROM [|PREFIX|]product_customfields WHERE fieldprodid='".$GLOBALS['ISC_CLASS_DB']->Quote((int) $prodId)."'");
			if (!empty($CustomFields)) {
				foreach ($CustomFields as $c) {
					$newField = array(
						"fieldprodid" => $prodId,
						"fieldname" => $c['name'],
						"fieldvalue" => $c['value']
					);
					$GLOBALS['ISC_CLASS_DB']->InsertQuery("product_customfields", $newField);
				}
			}

			$this->_SaveProductFields($ProductFields, $prodId);

			// Upload any product downloads if we have them
			if(isset($_FILES) && isset($_FILES['newdownload']) && isset($_FILES['newdownload']['name']) && $_FILES['newdownload']['name'] != '') {
				$this->SaveProductDownload($err);
			}

			// Associate any product images and downloads which were uploaded earlier with this product
			if(isset($Data['prodhash']) && $Data['prodhash'] !== '') {
				$updateImages = array(
					"imageprodid" => $prodId,
					"imageprodhash" => ''
				);
				$GLOBALS['ISC_CLASS_DB']->UpdateQuery("product_images", $updateImages, "imageprodhash='".$GLOBALS['ISC_CLASS_DB']->Quote($Data['prodhash'])."'".$updateImageQuery);

				$updatedDownloads = array(
					"productid" => $prodId,
					"prodhash" => ''
				);
				$GLOBALS['ISC_CLASS_DB']->UpdateQuery("product_downloads", $updatedDownloads, "prodhash='".$GLOBALS['ISC_CLASS_DB']->Quote($Data['prodhash'])."'");
			}

			// Now we add our discount rules
			$GLOBALS['ISC_CLASS_DB']->DeleteQuery('product_discounts', 'WHERE discountprodid=' . (int)$prodId);

			// If we have variations then do not process them
			if((!isset($Data['prodvariationid']) || !isId($Data['prodvariationid'])) && empty($Variations)) {
				foreach ($DiscountRules as $rule) {

					// If the min and max quantities are astrixes then convert them to 0
					if ($rule['quantitymin'] == '*') {
						$rule['quantitymin'] = 0;
					}

					if ($rule['quantitymax'] == '*') {
						$rule['quantitymax'] = 0;
					}

					// Change the type of the amount, just in case
					if (isc_strtolower($rule['type']) == 'percent') {
						$rule['amount'] = (int)$rule['amount'];
					}

					// Fix for bug ISC-219: Removed code
					// Casting $rule['amount'] to a float using (float) here, if the amount was a dollar amount, would change a string of '12,000.00' to 12 (it'd cut at the comma)
					// If the amount is not a percentage, DefaultPriceFormat() below will ensure the amount is formatted and sanitized properly

					$newRule = array(
						'discountprodid' => (int)$prodId,
						'discountquantitymin' => (int)$rule['quantitymin'],
						'discountquantitymax' => (int)$rule['quantitymax'],
						'discounttype' => isc_strtolower($rule['type']),
						'discountamount' => DefaultPriceFormat($rule['amount'])
					);

					$GLOBALS['ISC_CLASS_DB']->InsertQuery('product_discounts', $newRule);
				}
			}

			// save shopping comparison data
			$comparisons = array();

			if(isset($_POST['comparisons']))
				$comparisons = (array)$_POST['comparisons'];

			$this->saveComparisons($prodId, $comparisons);

			if ($GLOBALS["ISC_CLASS_DB"]->GetErrorMsg() == "") {
				// The product was commited successfully, commit the transaction
				$GLOBALS["ISC_CLASS_DB"]->Query("commit");
				return true;
			}
			else {
				// The product commit failed
				$GLOBALS["ISC_CLASS_DB"]->Query("rollback");
				return false;
			}
		}
Example #5
0
	private function rebuildSearchData($type)
	{
		$map = array();
		$stripped = array();

		switch (isc_strtolower($type)) {
			case "brand":
				$map = array(
						"brandid",
						"brandname",
						"brandpagetitle",
						"brandsearchkeywords"
				);

				break;

			case "category":
				$map = array(
						"categoryid",
						"catname",
						"catdesc",
						"catsearchkeywords"
				);

				$stripped = array("catdesc");

				break;

			case "page":
				$map = array(
						"pageid",
						"pagetitle",
						"pagecontent",
						"pagedesc",
						"pagesearchkeywords"
				);

				$stripped = array("pagecontent", "pagedesc");

				break;

			case "product";
				$map = array(
						"productid",
						"prodname",
						"prodcode",
						"proddesc",
						"prodsearchkeywords"
				);

				$stripped = array("proddesc");

				break;

			case "news":
				$map = array(
						"newsid",
						"newstitle",
						"newscontent",
						"newssearchkeywords"
				);

				$stripped = array("newscontent");

				break;

			default:
				return true;
		}

		$searchTable = $type . "_search";

		if ($GLOBALS["ISC_CLASS_DB"]->DeleteQuery($searchTable, "") === false) {
			$this->SetError($GLOBALS["ISC_CLASS_DB"]->GetErrorMsg());
			return false;
		}

		if ($type == "category") {
			$sourceTable = "categories";
		} else if ($type == "news") {
			$sourceTable = "news";
		} else {
			$sourceTable = $type . "s";
		}

		$query = "SELECT " . implode(",", $map) . "
					FROM [|PREFIX|]" . $sourceTable;

		$result = $GLOBALS["ISC_CLASS_DB"]->Query($query);
		while ($row = $GLOBALS["ISC_CLASS_DB"]->Fetch($result)) {
			foreach ($stripped as $strip) {
				if (array_key_exists($strip, $row)) {
					$row[$strip] = stripHTMLForSearchTable($row[$strip]);
				}
			}

			$GLOBALS["ISC_CLASS_DB"]->InsertQuery($searchTable, $row);
		}

		return true;
	}