/** * _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; } }
/** * 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(); }
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; }
public function rebuild_pages_nset() { $nested = new ISC_NESTEDSET_PAGES(); return $nested->rebuildTree(); }