/**
	* Returns a flat count of all pages, used for paging purposes. Must use the same visibility rules as the getTree method.
	*
	* @return int
	*/
	public function countAll()
	{
		// isc page management does not flag all child nodes as not-visible when you untick a parent page, so we can't simply count(*) to get a count of all visible pages
		// use the nested set query to do a select, but discard the results and then use a FOUND_ROWS call afterwards to get the true count of all visible pages

		$set = new ISC_NESTEDSET_PAGES();

		$sql = $set->generateGetTreeSql(array('pageid'), ISC_NESTEDSET_START_ROOT, $this->getMaximumDepth(), null, null, true, $this->_getRestrictions());

		$result = $GLOBALS['ISC_CLASS_DB']->Query($sql);
		if (!$result) {
			return false;
		}

		$result = $GLOBALS['ISC_CLASS_DB']->Query("SELECT FOUND_ROWS()");
		return $GLOBALS['ISC_CLASS_DB']->FetchOne($result);
	}
	/**
	* Returns an array of Id's for all pages
	*
	* @return array Array of page Id's
	*/
	private function getPageIds()
	{
		$nested = new ISC_NESTEDSET_PAGES();
		$pages = $nested->getTree(
			array('pageid')
		);
		$pageIds = array();
		foreach ($pages as $page) {
			$pageIds[] = $page['pageid'];
		}

		return $pageIds;
	}
Esempio n. 3
0
		/**
		 * _CheckPermissions
		 * Create the database and perform other install-orientated tasks
		 *
		 * @param none
		 *
		 * @return void
		 */
		private function RunInstall()
		{
			
				$lk = '';
				if(isset($_POST['LK'])) {
					$lk = ech0($_POST['LK']);
				}

				if(!$lk) {
					$installMessage = GetLang('LKBad');
					$installCode = "badLicenseKey";
				}

			if(!isset($_POST['StoreCountryLocationId']) || !isId($_POST['StoreCountryLocationId'])) {
				$_POST['StoreCountryLocationId'] = 227; // United States
			}

			if(!isset($_POST['StoreCurrencyCode']) || $_POST['StoreCurrencyCode'] == '') {
				$_POST['StoreCurrencyCode'] = 'USD';
			}

			if(!isset($_POST['ShopPath']) || $_POST['ShopPath'] == '') {
				$installMessage = GetLang('InstallMissingShopPath');
				$installCode = "missingShopPath";
			}
			else if (isc_strlen($_POST['StoreCurrencyCode']) > 3) {
				$installMessage = GetLang('InstallInvalidStoreCurrencyCode');
				$installCode = "invalidStoreCurrencyCode";
			}
			else if(!isset($_POST['ShopPath']) || $_POST['ShopPath'] == '') {
				$installMessage = GetLang('InstallMissingShopPath');
				$installCode = "missingShopPath";
			}
			else if(!isset($_POST['UserEmail']) || $_POST['UserEmail'] == '') {
				$installMessage = GetLang('InstallMissingUserEmail');
				$installCode = "missingUserEmail";
			}
			else if(!isset($_POST['UserPass']) || $_POST['UserPass'] == '') {
				$installMessage = GetLang('InstallMissingUserPass');
				$installCode = "missingUserPass";
			}
			else if(!isset($_POST['dbServer']) || $_POST['dbServer'] == '') {
				$installMessage = GetLang('InstallMissingDbServer');
				$installCode = "missingDbServer";
			}
			else if(!isset($_POST['dbUser']) || $_POST['dbUser'] == '') {
				$installMessage = GetLang('InstallMissingDbUser');
				$installCode = "missingDbUser";
			}
			else if(!isset($_POST['dbPass'])) {
				$installMessage = GetLang('InstallMissingDbPass');
				$installCode = "missingDbPass";
			}
			else if(!isset($_POST['dbDatabase']) || $_POST['dbDatabase'] == '') {
				$installMessage = GetLang('InstallMissingDbDatabase');
				$installCode = "missingDbDatabase";
			}

			if(!isset($_POST['tablePrefix'])) {
				$_POST['tablePrefix'] = '';
			}

			// One or more error messages were detected
			if(isset($installMessage)) {
				$errors = array(
					0 => array(
						"code" => $installCode,
						"message" => $installMessage
					)
				);
				$this->ShowInstallErrors($installMessage, $errors, false, true);
				return;
			}

			// Try to connect to the database
			$db_type = GetConfig("dbType") . 'Db';
			$db = new $db_type();

			if(isset($GLOBALS['ISC_CFG']["dbEncoding"])) {
				$db->charset = $GLOBALS['ISC_CFG']["dbEncoding"];
			}

			$connection = $db->Connect($_POST['dbServer'], $_POST['dbUser'], $_POST['dbPass'], $_POST['dbDatabase']);
			$db->TablePrefix = $_POST['tablePrefix'];

			if($connection) {
				$GLOBALS["ISC_CLASS_DB"] = &$db;

				// Are we running the required version of MySQL?
				$ver = $GLOBALS["ISC_CLASS_DB"]->FetchOne("select version() as ver");

				$mysql_check = version_compare($ver, MYSQL_VERSION_REQUIRED);

				if($mysql_check < 0) {
					$message = sprintf(GetLang("MySQLV4Message"), MYSQL_VERSION_REQUIRED, $ver);
					$errors = array(
						0 => array(
							"code" => "mysqlVersion",
							"extra" => $ver,
							"message" => $message
						)
					);
					$this->ShowInstallErrors($message, $errors, false, true);
					return;
				}
				else {
					// Run the database commands
					$queries = $this->template->render('install.schema.tpl');
					$queries = str_replace("\r", "\n", str_replace("\r\n", "\n", $queries));
					$queries = explode(";\n", $queries);
					$GLOBALS["ISC_CLASS_DB"]->Query("start transaction");

					// Initialize the admin auth class to get the list of permissions
					$auth = new ISC_ADMIN_AUTH();

					require_once(dirname(__FILE__) . "/class.user.php");
					$userManager = GetClass('ISC_ADMIN_USER');
					$pass = $_POST['UserPass'];
					$token = $userManager->_GenerateUserToken();

					foreach($queries as $query) {
						$query = str_replace("%%PREFIX%%", $_POST['tablePrefix'], $query);
						$query = str_replace("%%EMAIL%%", $GLOBALS["ISC_CLASS_DB"]->Quote($_POST['UserEmail']), $query);
						$query = str_replace("%%TOKEN%%", $GLOBALS["ISC_CLASS_DB"]->Quote($token), $query);

						if(trim($query) != "") {
							$GLOBALS["ISC_CLASS_DB"]->Query($query);
						}
					}

					// update admin user password
					$user_id = $userManager->getUserByField('username', 'admin');
					$userManager->updatePassword($user_id, $pass);

					// Give the admin user permissions
					$constants = get_defined_constants();

					foreach($constants as $constant => $val) {
						if(is_numeric(strpos($constant, "AUTH_")) && strpos($constant, "AUTH_") == 0) {
							$newPermission = array(
								"permuserid" => $user_id,
								"permpermissionid" => $val
							);
							$GLOBALS['ISC_CLASS_DB']->InsertQuery("permissions", $newPermission);
						}
					}

					// Set the version
					$db_version = array(
						'database_version' => PRODUCT_VERSION_CODE
					);
					$GLOBALS['ISC_CLASS_DB']->InsertQuery('config', $db_version);

					// Install our default currency. We need to do it here as it also needs to be in the config file
					$GLOBALS['ISC_CLASS_DB']->Query("DELETE FROM [|PREFIX|]currencies");
					$GLOBALS['ISC_CLASS_DB']->Query("ALTER TABLE [|PREFIX|]currencies AUTO_INCREMENT=1");
					$currency = array(
						'currencycountryid'			=> $_POST['StoreCountryLocationId'],
						'currencycode'				=> isc_strtoupper($_POST['StoreCurrencyCode']),
						'currencyname'				=> GetLang('InstallDefaultCurrencyName'),
						'currencyexchangerate'		=> GetConfig('DefaultCurrencyRate'),
						'currencystring'			=> html_entity_decode(GetLang('InstallDefaultCurrencyString')),
						'currencystringposition'	=> isc_strtolower(GetLang('InstallDefaultCurrencyStringPosition')),
						'currencydecimalstring'		=> GetLang('InstallDefaultCurrencyDecimalString'),
						'currencythousandstring'	=> GetLang('InstallDefaultCurrencyThousandString'),
						'currencydecimalplace'		=> GetLang('InstallDefaultCurrencyDecimalPlace'),
						'currencylastupdated'		=> time(),
						'currencyisdefault'			=> 1,
						'currencystatus'			=> 1
					);
					$defaultCurrencyId = $GLOBALS['ISC_CLASS_DB']->InsertQuery('currencies', $currency);

					// Insert the default/master shipping zone
					$GLOBALS['ISC_CLASS_DB']->Query("DELETE FROM [|PREFIX|]shipping_zones");
					$GLOBALS['ISC_CLASS_DB']->Query("ALTER TABLE [|PREFIX|]shipping_zones AUTO_INCREMENT=1");
					$masterZone = array(
						'zonename' => 'Default Zone',
						'zonetype' => 'country',
						'zonefreeshipping' => 0,
						'zonefreeshippingtotal' => 0,
						'zonehandlingtype' => 'none',
						'zonehandlingfee' => 0,
						'zonehandlingseparate' => 1,
						'zoneenabled' => 1,
						'zonedefault' => 1
					);
					$GLOBALS['ISC_CLASS_DB']->InsertQuery('shipping_zones', $masterZone);

					// Is there a custom SQL file to include?
					$customPath = ISC_BASE_PATH.'/custom';
					if(file_exists($customPath.'/install.schema.tpl')) {
						$template = Interspire_Template::getInstance('custominstall', $customPath, array(
							'cache' => getAdminTwigTemplateCacheDirectory(),
							'auto_reload' => true
						));
						$queries = $template->render('install.schema.tpl');
						$queries = str_replace("\r", "\n", str_replace("\r\n", "\n", $queries));
						$queries = explode(";\n", $queries);
						$GLOBALS['ISC_CLASS_DB']->StartTransaction();
						foreach($queries as $query) {
							$query = str_replace("%%PREFIX%%", $_POST['tablePrefix'], $query);
							if(trim($query)) {
								$GLOBALS['ISC_CLASS_DB']->Query($query);
							}
						}
						$GLOBALS['ISC_CLASS_DB']->CommitTransaction();
					}

					// Was there an error?
					if($GLOBALS["ISC_CLASS_DB"]->Error() == "") {
						$GLOBALS["ISC_CLASS_DB"]->Query("commit");

						// Save the config file
						foreach($_POST as $k => $v) {
							$GLOBALS['ISC_NEW_CFG'][$k] = $v;
						}

						// Set the email address for this user as the store admin/order email address
						$GLOBALS['ISC_NEW_CFG']['AdminEmail'] = $_POST['UserEmail'];
						$GLOBALS['ISC_NEW_CFG']['OrderEmail'] = $_POST['UserEmail'];

						$GLOBALS['ISC_NEW_CFG']['serverStamp'] = $_POST['LK'];
						$GLOBALS['ISC_CFG']['serverStamp'] = $_POST['LK'];

						$settings = GetClass('ISC_ADMIN_SETTINGS');

						$GLOBALS['ISC_NEW_CFG']['HostingProvider'] = "";


						// Can we send server details back to Interspire?
						// If we can, the HostingProvider global will also be set
						if(isset($_POST['sendServerDetails'])) {
							$this->SendServerDetails();
							if(isset($GLOBALS['InfoImage'])) {
								$GLOBALS['HiddenImage'] = $GLOBALS['InfoImage'];
							}
						}


						$GLOBALS['ISC_NEW_CFG']['ShopPath'] = $_POST['ShopPath'];
						$GLOBALS['ISC_NEW_CFG']['DefaultCurrencyID'] = $defaultCurrencyId;

						if (isset($GLOBALS['ISC_NEW_CFG']['StoreCountryLocationId'])) {
							unset($GLOBALS['ISC_NEW_CFG']['StoreCountryLocationId']);
						}
						if (isset($GLOBALS['ISC_NEW_CFG']['StoreCurrencyCode'])) {
							unset($GLOBALS['ISC_NEW_CFG']['StoreCurrencyCode']);
						}

						// set up the product images sizes
						// load the product image class to get the constants
						GetClass('ISC_PRODUCT_IMAGE');
						$GLOBALS['ISC_NEW_CFG']['ProductImagesStorewideThumbnail_width'] = ISC_PRODUCT_DEFAULT_IMAGE_SIZE_THUMBNAIL;
						$GLOBALS['ISC_NEW_CFG']['ProductImagesStorewideThumbnail_height'] = ISC_PRODUCT_DEFAULT_IMAGE_SIZE_THUMBNAIL;
						$GLOBALS['ISC_NEW_CFG']['ProductImagesProductPageImage_width'] = ISC_PRODUCT_DEFAULT_IMAGE_SIZE_STANDARD;
						$GLOBALS['ISC_NEW_CFG']['ProductImagesProductPageImage_height'] = ISC_PRODUCT_DEFAULT_IMAGE_SIZE_STANDARD;
						$GLOBALS['ISC_NEW_CFG']['ProductImagesGalleryThumbnail_width'] = ISC_PRODUCT_DEFAULT_IMAGE_SIZE_TINY;
						$GLOBALS['ISC_NEW_CFG']['ProductImagesGalleryThumbnail_height'] = ISC_PRODUCT_DEFAULT_IMAGE_SIZE_TINY;
						$GLOBALS['ISC_NEW_CFG']['ProductImagesZoomImage_width'] = ISC_PRODUCT_DEFAULT_IMAGE_SIZE_ZOOM;
						$GLOBALS['ISC_NEW_CFG']['ProductImagesZoomImage_height'] = ISC_PRODUCT_DEFAULT_IMAGE_SIZE_ZOOM;
						$GLOBALS['ISC_NEW_CFG']['ProductImagesTinyThumbnailsEnabled'] = 1;
						$GLOBALS['ISC_NEW_CFG']['ProductImagesImageZoomEnabled'] = 1;

						// Build the unique encryption token
						$GLOBALS['ISC_NEW_CFG']['EncryptionToken'] = $this->_BuildEncryptionToken();

						// Set the install date
						$GLOBALS['ISC_NEW_CFG']['InstallDate'] = time();

						if ($settings->CommitSettings()) {
							// Calling commit settings a second time to ensure the config.backup.php file
							// Is written with valid data
							$settings->CommitSettings();

							// The installation is complete
							$GLOBALS['Password'] = $pass;

							// Do we need to install the sample product data? Copy that across
							if(isset($_POST['installSampleData']) && $_POST['installSampleData'] == 1) {
								$this->InstallSampleData();
							}

							// The install schemas can't predict the nested set values if custom install scripts arbitrarily add categories or pages
							// Rebuilt any nested sets instead of including their values in the install schema
							$nestedSet = new ISC_NESTEDSET_CATEGORIES();
							$nestedSet->rebuildTree();

							$nestedSet = new ISC_NESTEDSET_PAGES();
							$nestedSet->rebuildTree();

							// Remove any existing cookies
							ISC_UnsetCookie("STORESUITE_CP_TOKEN");

							//Initialize the data store system
							require_once ISC_BASE_PATH."/lib/class.datastore.php";
							$GLOBALS['ISC_CLASS_DATA_STORE'] = new ISC_DATA_STORE();

							// Clear the data store just in case it contains something
							$GLOBALS['ISC_CLASS_DATA_STORE']->Clear();

							$GLOBALS['ISC_LANG']['InstallationCompleted'] = sprintf(GetLang('InstallationCompleted'), $pass);

							unset($_SESSION['LK'.md5(strtolower($_POST['ShopPath']))]);

							// The installation was complete!
							if($this->apiMode == 'cli') {
								fwrite(STDOUT, "Success:\n");
								fwrite(STDOUT, "\n");
								fwrite(STDOUT, "ShopPath: ".$_POST['ShopPath']."\n");
								fwrite(STDOUT, "ControlPanel: ".$_POST['ShopPath']."admin/index.php\n");
								fwrite(STDOUT, "Username: admin\n");
								fwrite(STDOUT, "Password: "******"1.0" encoding="'.GetConfig("CharacterSet").'" ?'.">\n";
								echo "<response>\n";
								echo "  <status>OK</status>\n";
								echo "  <shop>\n";
								echo "      <shopPath>".$_POST['ShopPath']."</shopPath>\n";
								echo "      <controlPanel>".$_POST['ShopPath']."admin/index.php</controlPanel>\n";
								echo "  </shop>\n";
								echo "  <user>\n";
								echo "      <username>admin</username>\n";
								echo "      <password>".$_POST['UserPass']."</password>\n";
								echo "  </user>\n";
								echo "</response>\n";
								exit;
							}
							else {
								$this->template->display('install.done.tpl');
							}
						}
						else {
							$message = GetLang("ConfigErr");
							$errors = array(
								0 => array(
									"code" => "unableSaveConfig",
									"message" => $message
								)
							);
							$this->ShowInstallErrors($message, $errors, false, true);
							return;
						}
					}
					else {
						list($error, $level) = $db->GetError();
						$GLOBALS["ISC_CLASS_DB"]->Query("rollback");
						$message = sprintf(GetLang("DBErr"), $error);
						$errors = array(
							0 => array(
								"code" => "dbError",
								"message" => $GLOBALS["ISC_CLASS_DB"]->Error()
							)
						);
						$this->ShowInstallErrors($message, $errors, false, true);
						return;
					}
				}
			}
			else {
				list($error, $level) = $db->GetError();
				$message = sprintf(GetLang("DBErr"), $error);
				$errors = array(
					0 => array(
						"code" => "dbConnectError",
						"message" => $error
					)
				);
				$this->ShowInstallErrors($message, $errors, false, true);
				return;
			}
		}
Esempio n. 4
0
		private function EditPageStep2()
		{
			// Get the information from the form and add it to the database
			$pageId = (int)$_POST['pageId'];
			$arrData = array();
			$err = "";

			$existingPage = array();
			$this->_GetPageData($pageId, $existingPage);

			// Does this user have permission to edit this product?
			if($GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetVendorId() && $existingPage['pagevendorid'] != $GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetVendorId()) {
				FlashMessage(GetLang('Unauthorized'), MSG_ERROR, 'index.php?ToDo=viewPages');
			}

			$this->_GetPageData(0, $arrData);
			$arrData['pageid'] = $pageId;

			$currentTab = '0';
			if(isset($_POST['currentTab']) && $_POST['currentTab'] != ''){
				$currentTab = '&currentTab='.$_POST['currentTab'];
			}
			if(isset($_POST['addAnother']) || isset($_POST['addAnother2'])) {
				$url = 'index.php?ToDo=editPage&pageId='.$pageId.$currentTab;
			}
			else {
				$url = 'index.php?ToDo=viewPages';
			}

			if($this->_IsDuplicateTitle($arrData['pagetitle'], $pageId, $arrData['pagevendorid'])) {
				$this->EditPageStep1(GetLang('DuplicatePageTitle'), MSG_ERROR, true);
				die();
			}

			// Get a formatted list of all of the pages in the system
			$nested = new ISC_NESTEDSET_PAGES();
			$pages = $nested->getTree(
				array('pageid', 'pagetitle', 'pagevendorid'),
				$pageId,
				ISC_NESTEDSET_DEPTH_ALL,
				null,
				null,
				true,
				array('pagevendorid = ' . $GLOBALS['ISC_CLASS_ADMIN_AUTH']->GetVendorId())
			);

			$childList = array();
			foreach ($pages as $page) {
				if ($page['pageid'] != $pageId) {
					$childList[] = $page['pageid'];
				}
			}

			// don't let the current page assign itself or any decendants as it's parent page
			if($pageId == $arrData['pageparentid'] || in_array($arrData['pageparentid'], $childList)) {
				$this->EditPageStep1(GetLang('InvalidParentPage'), MSG_ERROR, true);
				die();
			}

			//Validate Google Website Optimizer form
			if(isset($arrData['page_enable_optimizer']) && $arrData['page_enable_optimizer']==1) {
				$optimizer = getClass('ISC_ADMIN_OPTIMIZER');
				$error = $optimizer->validateConfigForm();
				if($error!='') {
					$this->EditPageStep1($error, MSG_ERROR, true);
				}
			}

			// Commit the values to the database
			if ($this->_CommitPage($pageId, $arrData, $err)) {

				if($existingPage['pageparentid'] != $arrData['pageparentid']) {
					// Rebuild the 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)."'");

					// Now we also need to update the parent list of all child pages for this page
					$query = sprintf("SELECT pageid FROM [|PREFIX|]pages WHERE CONCAT(',', pageparentlist, ',') LIKE '%%,%s,%%'", $pageId);
					$result = $GLOBALS['ISC_CLASS_DB']->Query($query);
					while($child = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
						$parentList = $this->_BuildPageParentList($child['pageid']);
						// Update the parent list for this child
						$updatedPage = array(
							"pageparentlist" => $parentList
						);
						$GLOBALS['ISC_CLASS_DB']->UpdateQuery("pages", $updatedPage, "pageid='".$GLOBALS['ISC_CLASS_DB']->Quote($child['pageid'])."'");
					}
				}

				// Log this action
				$GLOBALS['ISC_CLASS_LOG']->LogAdminAction($pageId, $arrData['pagetitle']);
				FlashMessage(GetLang('PageUpdatedSuccessfully'), MSG_SUCCESS, $url);
			} else {
				FlashMessage(sprintf(GetLang('ErrPageNotUpdated'), $err), MSG_ERROR, $url);
			}
		}
Esempio n. 5
0
		/**
		 * Update the sort order of the pages
		 *
		 * @return void
		 **/
		private function UpdatePageOrders()
		{
			$GLOBALS['ISC_CLASS_ADMIN_ENGINE']->LoadLangFile('pages');
			$this->_BuildPageOrders($_POST['PageList']);

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

			// update the nested set values
			// @todo the front end currently does not tell the backend which page was moved, only the new structure - if this takes too long to run, the front end needs changing to include which page was moved so a partial update is possible
			$nested = new ISC_NESTEDSET_PAGES();
			$nested->rebuildTree();

			$tags[] = $this->MakeXMLTag('status', 1);
			$tags[] = $this->MakeXMLTag('message', GetLang('PageOrdersUpdated'), true);
			$this->SendXMLHeader();
			$this->SendXMLResponse($tags);
			die();
		}
Esempio n. 6
0
	public function rebuild_pages_nset()
	{
		$nested = new ISC_NESTEDSET_PAGES();
		return $nested->rebuildTree();
	}