/**
	* Handles XHR 'providerAction 'requests from the settings > email integration forms, and routes them to the correct provider module
	*
	* @param array $data
	*/
	public function handleProviderAction($data)
	{
		$providerAction = $data['providerAction'];
		$provider = $data['provider'];
		unset($data['providerAction'], $data['provider']);

		GetModuleById('emailintegration', /** @var ISC_EMAILINTEGRATION */$module, $provider);
		if (!$module) {
			ISC_JSON::output('Unknown module: ' . $provider, false);
			return;
		}

		$method = 'remote' . $providerAction;

		if (!is_callable(array($module, $method))) {
			ISC_JSON::output('Provider action not "' . $providerAction . '" found for provider "' . $provider . '"', false);
			return;
		}

		// api auth details will be included in the request, based on the form - this should be separated before sending it to the provider module
		$auth = @$data['auth'];
		if (!$auth) {
			$auth = array();
		}
		unset($data['auth']);

		$result = $module->$method($auth, $data);

		// result expected from provider module is array containing at least 'message' and 'success'; any other elements will be sent back as json too but message and success are stripped out and handled separately due to how ISC_JSON works
		$message = @$result['message'];
		$success = !!$result['success'];
		unset($result['message'], $result['success']);
		ISC_JSON::output($message, $success, $result);
	}
示例#2
0
	public function jobStatusGetProgressAction()
	{
		if(!isset($_REQUEST['id']) || !($id = $_REQUEST['id']))
			return;

		$controller = Job_Controller::get($id);
		echo ISC_JSON::output($controller->getProgress());
	}
	private function saveNewRedirectURL()
	{
		$newUrl = trim($_POST['newurl']);
		$redirectId = (int)$_POST['id'];

		if(empty($newUrl) || $newUrl == "/") {
			ISC_JSON::output(GetLang('InvalidRedirect'));
		}

		GetLib('class.redirects');
		$newUrl = ISC_REDIRECTS::normalizeNewURLForDatabase($newUrl, $error);
		if ($newUrl === false) {
			if (empty($error)) {
				$error = GetLang('InvalidRedirect');
			}
			ISC_JSON::output($error);
		}
		$returnData = array('url' => $newUrl, 'id' => $redirectId);

		if($redirectId == 0 && substr($_POST['id'], 0, 3) == 'tmp') {
			$redirectId = $GLOBALS['ISC_CLASS_DB']->InsertQuery('redirects',  array('redirectpath'=> '', 'redirectmanual' => $newUrl, 'redirectassoctype' => ISC_REDIRECTS::REDIRECT_TYPE_MANUAL, 'redirectassocid'=>0));
			//echo "REdirect iD is " . $GLOBALS['ISC_CLASS_DB']->getErrorMsg();
			if($redirectId) {
				$returnData['id'] = $redirectId;
				$returnData['tmpredirectid'] = $_POST['id'];
				ISC_JSON::output('', true, $returnData);
				return;
			}
		} else {
			if($GLOBALS['ISC_CLASS_DB']->UpdateQuery('redirects', array('redirectmanual' => $newUrl), 'redirectid=' . $redirectId)) {
				ISC_JSON::output('', true, $returnData);
				return;
			}
		}

		ISC_JSON::output(GetLang('RedirectSaveErrorDatabase'));
	}
	/**
	* Begins an actual export job sequence based on requested data -- the job class itself will validate most of this info before attempting an export
	*
	* @param array $data
	*/
	protected function _moduleExportCommenceCommon($data)
	{
		$keystore = Interspire_KeyStore::instance();

		// find a unique export id to use
		do {
			$id = md5(uniqid('',true));
		} while ($keystore->exists('email:module_export:id:' . $id));
		$keystore->set('email:module_export:id:' . $id, $id);

		$prefix = 'email:module_export:' . $id;

		if (!isset($data['exportSearch'])) {
			$data['exportSearch'] = array();
		}

		if (!isset($data['exportMap'])) {
			$data['exportMap'] = array();
		}

		$keystore->set($prefix . ':started', time());
		$keystore->set($prefix . ':abort', 0);
		$keystore->set($prefix . ':skip', 0);
		$keystore->set($prefix . ':type', $data['exportType']);
		$keystore->set($prefix . ':module', $data['exportModule']);
		$keystore->set($prefix . ':list', $data['exportList']);
		$keystore->set($prefix . ':search', ISC_JSON::encode($data['exportSearch']));
		$keystore->set($prefix . ':map', ISC_JSON::encode($data['exportMap']));
		$keystore->set($prefix . ':success_count', 0);
		$keystore->set($prefix . ':error_count', 0);
		$keystore->set($prefix . ':doubleoptin', $data['exportDoubleOptin']);
		$keystore->set($prefix . ':updateexisting', $data['exportUpdateExisting']);

		// so we can send an email later, or diagnose troublesome users
		$user = $GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetUser();
		$keystore->set($prefix . ':owner:id', $user['pk_userid']);
		$keystore->set($prefix . ':owner:username', $user['username']);
		$keystore->set($prefix . ':owner:email', $user['useremail']);

		$jobData = array(
			'id' => $id,
		);

		$json = array(
			'success' => (bool)Interspire_TaskManager::createTask('emailintegration', 'Job_EmailIntegration_ModuleExport', $jobData),
			'id' => $id,
		);

		if (isset($data['return']) && $data['return']) {
			return $json;
		}

		ISC_JSON::output($json);
	}
示例#5
0
	/**
	* Processes the next site that needs its cache updated
	*
	*/
	private function continueEbayCacheUpdateAction()
	{
		$ebayClass = GetClass('ISC_ADMIN_EBAY');
		$expiredSites = $ebayClass->getExpiredCacheSites();

		// no more to update
		if (empty($expiredSites)) {
			ISC_JSON::output('', true, array('done' => true));
		}

		// the next site to update
		$nextSiteId = current($expiredSites);

		$keystore = Interspire_KeyStore::instance();
		$prefix = 'ebay:details:last_update:site:';

		try {
			$xml = $ebayClass->GeteBayDetailsAction($nextSiteId);
		}
		catch (ISC_EBAY_API_EXCEPTION $ex) {
			FlashMessage($ex->getMessage(), MSG_ERROR, '', 'EbayConfig');
			ISC_JSON::output('', false);
		}

		// Write the content to local file system
		if(!$ebayClass->WriteCache($nextSiteId, $xml->asXML())) {
			FlashMessage(GetLang('EbayRequestProblem'), MSG_ERROR, '', 'EbayConfig');
			ISC_JSON::output('', false);
		}

		// set the last update time for the site
		if (!$keystore->set($prefix . $nextSiteId, time())) {
			FlashMessage(GetLang('EbayRequestProblem'), MSG_ERROR, '', 'EbayConfig');
			ISC_JSON::output('', false);
		}

		ISC_JSON::output('', true);
	}
示例#6
0
		private function DisableStoreMaintenance()
		{
			$result = false;
			if ($GLOBALS['ISC_CLASS_ADMIN_AUTH']->HasPermission(AUTH_See_Store_During_Maintenance)) {
				$GLOBALS['ISC_NEW_CFG']['DownForMaintenance'] = 0;
				$settings = GetClass('ISC_ADMIN_SETTINGS');
				$result = $settings->CommitSettings();
			}

			GetLib('class.json');
			ISC_JSON::output('', $result);
		}
	/**
	 * Generates html for a gift certificate using sample data.
	 * Ouputs the result in JSON.
	 **/
	private function exampleGiftCertificate()
	{
		$id = !empty($_REQUEST['id']) ? $_REQUEST['id'] : null;
		$html = !empty($_REQUEST['html']) ? $_REQUEST['html'] : null;

		if($id) {
			// load a gift certificate theme by id
			if(!$theme = ISC_GIFTCERTIFICATE_THEME::findById($id)) {
				return;
			}
		}
		else if($html) {
			// build a temporary theme object using template html
			$theme = new ISC_GIFTCERTIFICATE_THEME();
			$theme->setTemplateContents($html);
		}
		else {
			// no id or template html passed, abort
			return;
		}

		$certificate = array(
			"giftcertto" => GetLang('GiftCertificateSampleTo'),
			"giftcerttoemail" => GetLang('GiftCertificateSampleToEmail'),
			"giftcertfrom" => GetLang('GiftCertificateSampleFrom'),
			"giftcertfromemail" => GetLang('GiftCertificateSampleFromEmail'),
			"giftcertmessage" => GetLang('GiftCertificateSampleMessage'),
			"giftcertcode" => GetLang('GiftCertificateSampleCode'),
			"giftcertamount" => GetLang('GiftCertificateSampleAmount'),
			"giftcertexpirydate" => GetLang('GiftCertificateSampleExpiryDate'),
			);

		$html = $theme->generateGiftCertificateHTML($certificate);
		$data = array('html' => $html);

		ISC_JSON::output('', true, $data);
	}
	private function continueRebuildVariationsAction()
	{
		$sessionId = $_POST['session'];

		if (!isset($_SESSION['variations'][$sessionId])) {
			ISC_JSON::output('session ' . $sessionId . ' not found', false);
		}

		$session = &$_SESSION['variations'][$sessionId];

		// get the next product id
		$query = "
			SELECT
				productid
			FROM
				[|PREFIX|]products
			WHERE
				productid > " . $session['lastProductId'] . " AND
				prodvariationid = " . $session['variationId'] . "
			ORDER BY
				productid
			LIMIT
				1
		";

		$res = $this->db->Query($query);
		$productId = $this->db->FetchOne($res);

		// no more products to process? done.
		if (empty($productId)) {
			unset($_SESSION['variations'][$sessionId]);
			if (empty($_SESSION['variations'])) {
				unset($_SESSION['variations']);
			}
			ISC_JSON::output('', true, array('done' => true));
		}

		if ($this->db->StartTransaction() === false) {
			ISC_JSON::output('failed to start transaction', false);
		}

		$existingData = $session['existingData'];

		// were new option values (eg a new colour) added? we'll need to create some blank combinations to fill in the missing gaps.
		if (!empty($session['newValues'])) {
			$newValues = $session['newValues'];

			// iterate over the new option values
			foreach ($newValues as $optionName => $newValueIds) {
				foreach ($newValueIds as $newValueId) {
					// build combination id set
					$optionIdSets = array();

					foreach ($existingData['options'] as $optionIndex => $option) {
						if ($optionName == $option['name']) {
							$optionIdSets[$optionIndex][] = $newValueId;
							continue;
						}

						foreach ($option['values'] as $valueIndex => $value) {
							$optionIdSets[$optionIndex][] = $value['valueid'];
						}
					}

					// build a cartesian product of all the combinations that we need to generate
					$cartesian = Interspire_Array::generateCartesianProduct($optionIdSets);

					// iterate over each combination and insert to DB for all products using this variation
					foreach ($cartesian as $combination) {
						$combinationString = implode(',', $combination);

						$newCombination = array(
							'vcproductid'		=> $productId,
							'vcvariationid'		=> $session['variationId'],
							'vcoptionids'		=> $combinationString,
							'vclastmodified'	=> time(),
						);

						$this->db->InsertQuery('product_variation_combinations', $newCombination);
					}
				}
			}
		}

		// process new option set (eg. Material)
		if (!empty($session['newOptionValues'])) {
			$valuesForNewOption = $session['newOptionValues'];

			$likeMatch = str_repeat(",%", count($existingData['options']) - 2);
			$likeMatch = "%" . $likeMatch;

			foreach ($valuesForNewOption as $newOptionIndex => $newValueIds) {
				$newOptionCount = 0;

				foreach ($newValueIds as $newValueId) {
					// for the first new option value, we don't want to insert new combinations, but update the existing ones
					// store the option id for later and continue on
					if ($newOptionCount == 0) {
						$delayForUpdate = $newValueId;

						$newOptionCount++;
						continue;
					}

					$query = "
						INSERT INTO
							[|PREFIX|]product_variation_combinations (vcproductid, vcproducthash, vcvariationid, vcenabled, vcoptionids, vcsku, vcpricediff, vcprice, vcweightdiff, vcweight, vcimage, vcimagezoom, vcimagestd, vcimagethumb, vcstock, vclowstock, vclastmodified)
							SELECT
								vcproductid,
								vcproductid,
								vcvariationid,
								vcenabled,
								CONCAT(vcoptionids, ',', " . $newValueId . "),
								vcsku,
								vcpricediff,
								vcprice,
								vcweightdiff,
								vcweight,
								vcimage,
								vcimagezoom,
								vcimagestd,
								vcimagethumb,
								vcstock,
								vclowstock,
								" . time() . "
							FROM
								[|PREFIX|]product_variation_combinations
							WHERE
								vcproductid = " . $productId . " AND
								vcproducthash = ''
					";

					$this->db->Query($query);

					$newOptionCount++;
				}
			}

			// for the first new option id, add it onto the remaining existing row
			if (!empty($delayForUpdate)) {
				$query = "
					UPDATE
						[|PREFIX|]product_variation_combinations
					SET
						vcoptionids = CONCAT(vcoptionids, ',', " . $delayForUpdate . ")
					WHERE
						vcproductid = " . $productId . " AND
						vcproducthash = ''
				";

				$this->db->Query($query);
			}

			// blank the hash
			$query = "
				UPDATE
					[|PREFIX|]product_variation_combinations
				SET
					vcproducthash = ''
				WHERE
					vcproductid = " . $productId . "
			";
			$this->db->Query($query);
		}

		if ($this->db->CommitTransaction() === false) {
			$this->db->RollbackTransaction();
			ISC_JSON::output('failed to commit transaction', false);
		}

		$session['lastProductId'] = $productId;

		ISC_JSON::output('', true);
	}
	private function toggleCategoryVisiblity()
	{
		$errorMsg = GetLang('ErrCategoryVisibilityNotChanged');
		if (empty($_GET['catId'])) {
			ISC_JSON::output($errorMsg, false);
		}

		$catId = (int)$_GET['catId'];

		$query = "
			SELECT
				catname,
				catvisible,
				catparentlist,
				catnsetleft,
				catnsetright
			FROM
				[|PREFIX|]categories WHERE categoryid = " . $catId;
		$result = $this->db->Query($query);
		$category = $this->db->Fetch($result);

		// is the category currently visible?
		$catVisible = (bool)$category['catvisible'];

		$affectedCategories = array($catId);

		// toggle visibility
		$update = array(
			'catvisible' => (int)!$catVisible
		);

		// if the category is currently visible, we need only hide this one
		if ($catVisible) {
			$where = 'categoryid = ' . $catId;
		}
		// to make the invisible category visible we need to make this and the parent categories visible
		else {
			if (trim($category['catparentlist']) !== '') {
				$parentCategories = explode(',', $category['catparentlist']);
				$affectedCategories = array_unique(array_merge($affectedCategories, $parentCategories));
				//$where = 'catnsetleft <= ' . $category['catnsetleft'] . ' AND catnsetright >= ' . $category['catnsetright'];
				$where = "categoryid IN (" . implode(',', $affectedCategories) . ")";
			} else {
				// no parent
				$where = 'categoryid = ' . $catId;
			}
		}

		if ($this->db->UpdateQuery('categories', $update, $where)) {
			// Log this action
			$GLOBALS['ISC_CLASS_LOG']->LogAdminAction($catId, $category['catname']);

			// Update the data store
			$GLOBALS['ISC_CLASS_DATA_STORE']->UpdateRootCategories();

			// does this category have child categories?
			$hasChildren = false;
			if (($category['catnsetleft'] + 1) < $category['catnsetright']) {
				$hasChildren = true;
			}

			$andSubCats = '';
			if ($hasChildren) {
				$andSubCats = GetLang('SubCategories');
			}
			$successMsg = GetLang('CategoryVisibilitySuccessfully', array('andSubCats' => $andSubCats));

			ISC_JSON::output($successMsg, true, array('visible' => !$catVisible, 'affected' => $affectedCategories));
		}

		ISC_JSON::output($errorMsg, false);
	}
示例#10
0
		public function processProductImages()
		{
			GetLib('class.json');

			/** @var ISC_LOG */
			$log = $GLOBALS['ISC_CLASS_LOG'];

			$query = "
				SELECT
					(SELECT COUNT(*) FROM [|PREFIX|]product_images) AS prodimagecount,
					(SELECT COUNT(DISTINCT vcimage, vcimagezoom, vcimagestd, vcimagethumb) FROM [|PREFIX|]product_variation_combinations WHERE vcimage != '') AS varimagecount
			";

			$result = $this->db->Query($query);
			$countrow = $this->db->Fetch($result);
			$total = $countrow['prodimagecount'] + $countrow['varimagecount'];

			$start = max(0, @(int)$_POST['start']);
			$limit = 10;
			$completed = 0;

			if ($start < $countrow['prodimagecount']) {
				$imageIterator = new ISC_PRODUCT_IMAGE_ITERATOR('select * from `[|PREFIX|]product_images` limit ' . $start . ', ' . $limit);

				foreach($imageIterator as $imageId => $image) {
					try {
						// the first argument to saveToDatabase is $generateImages. If true (is by default), the images will be regenerated
						$image->saveToDatabase();
					} catch (Exception $exception) {
						$log->LogSystemDebug('general', 'Exception while processing product image ' . $imageId, $exception->getMessage());
					}
					++$completed;
				}
			}

			// was there any remaining 'items' to process for this iteration? start on variation images
			$var_limit = $limit - $completed;

			if ($var_limit > 0) {
				$var_start = max(0, $start - $countrow['prodimagecount']);

				$query = '
					SELECT
						vcimage, vcimagezoom, vcimagestd, vcimagethumb
					FROM
						[|PREFIX|]product_variation_combinations
					WHERE
						vcimage != ""
					GROUP BY
						vcimage, vcimagezoom, vcimagestd, vcimagethumb
					ORDER BY
						vcimage
					LIMIT
						' . $var_start . ', ' . $var_limit;

				$result = $this->db->Query($query);
				while ($row = $this->db->Fetch($result)) {
					try {
						$image = new ISC_PRODUCT_IMAGE;
						$image->setSourceFilePath($row['vcimage']);

						if ($row['vcimagezoom']) {
							$image->setResizedFilePath(ISC_PRODUCT_IMAGE_SIZE_ZOOM, $row['vcimagezoom']);
						}

						if ($row['vcimagestd']) {
							$image->setResizedFilePath(ISC_PRODUCT_IMAGE_SIZE_STANDARD, $row['vcimagestd']);
						}

						if ($row['vcimagethumb']) {
							$image->setResizedFilePath(ISC_PRODUCT_IMAGE_SIZE_THUMBNAIL, $row['vcimagethumb']);
						}

						$updatedVariation = array(
							'vcimagezoom' 	=> $image->getResizedFilePath(ISC_PRODUCT_IMAGE_SIZE_ZOOM, true, false),
							'vcimagestd' 	=> $image->getResizedFilePath(ISC_PRODUCT_IMAGE_SIZE_STANDARD, true, false),
							'vcimagethumb' 	=> $image->getResizedFilePath(ISC_PRODUCT_IMAGE_SIZE_THUMBNAIL, true, false),
						);

						$this->db->UpdateQuery('product_variation_combinations', $updatedVariation, "vcimage = '" . $this->db->Quote($row['vcimage']) . "'");
					}
					catch (Exception $exception) {
						$log->LogSystemDebug('general', 'Exception while processing variation image ' . $row['vcimage'], $exception->getMessage());
					}

					++$completed;
				}
			}

			$result = array('completed' => $completed, 'start' => (int)$start, 'total'=> (int)$total);
			ISC_JSON::output('', true, $result);
			exit;
		}
示例#11
0
	/**
	* Handler for browser requests meant to trigger the internal task manager queue processor
	*
	* @return mixed If a task was not executed a null value will be returned, otherwise true or false will be returned depending on the successful (or not) execution of a task
	*/
	public static function handleTriggerRequest()
	{
		@ignore_user_abort(true);

		// run the task, if any
		self::executeNextTask();

		header("Expires: Mon, 23 Jul 1993 05:00:00 GMT");
		header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
		header("Cache-Control: no-store, no-cache, must-revalidate");
		header("Cache-Control: post-check=0, pre-check=0, max-age=0", false);

		$response = array(
			'remaining' => self::hasTasks(),
		);

		GetLib('class.json');
		ISC_JSON::output($response);
		exit;
	}
	public function stopShoppingComparisonFeedAction()
	{
		GetModuleById('shoppingcomparison',
			$module,
			$this->getValue($_REQUEST, 'mid'));

		if($module) {
			$module->abortExportTask();
			ISC_JSON::output(getLang('ShoppingComparisonExportCancelled'), true, null);
		}
	}