* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 1.4 $ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ class AdminShopUrl extends AdminTab { public function __construct() { $this->table = 'shop_url'; $this->className = 'ShopUrl'; $this->edit = true; $this->delete = true; $this->_select = 's.name AS shop_name, CONCAT(a.physical_uri, a.virtual_uri) AS uri'; $this->_join = 'LEFT JOIN `'._DB_PREFIX_.'shop` s ON (s.id_shop = a.id_shop)'; $this->_listSkipDelete = array(1); $this->fieldsDisplay = array( 'id_shop_url' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 'domain' => array('title' => $this->l('Domain'), 'width' => 130, 'filter_key' => 'domain'), 'domain_ssl' => array('title' => $this->l('Domain SSL'), 'width' => 130, 'filter_key' => 'domain'), 'uri' => array('title' => $this->l('Uri'), 'width' => 130, 'filter_key' => 'uri'), 'shop_name' => array('title' => $this->l('Shop name'), 'width' => 70), 'main' => array('title' => $this->l('Main URL'), 'align' => 'center', 'activeVisu' => 'main', 'type' => 'bool', 'orderby' => false, 'filter_key' => 'main'), 'active' => array('title' => $this->l('Enabled'), 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false, 'filter_key' => 'active'), ); parent::__construct(); } public function postProcess() { $token = Tools::getValue('token') ? Tools::getValue('token') : $this->token; if (Tools::isSubmit('submitAdd'.$this->table)) { $object = $this->loadObject(true); if ($object->id && Tools::getValue('main')) $object->setMain(); if ($object->main && !Tools::getValue('main')) $this->_errors[] = Tools::displayError('You can\'t change a main url to a non main url, you have to set an other url as main url for selected shop'); if (($object->main || Tools::getValue('main')) && !Tools::getValue('active')) $this->_errors[] = Tools::displayError('You can\'t disable a main url'); if ($object->canAddThisUrl(Tools::getValue('domain'), Tools::getValue('domain_ssl'), Tools::getValue('physical_uri'), Tools::getValue('virtual_uri'))) $this->_errors[] = Tools::displayError('A shop url that use this domain and uri already exists'); parent::postProcess(); Tools::generateHtaccess(dirname(__FILE__).'/../../.htaccess', Configuration::get('PS_REWRITING_SETTINGS'), Configuration::get('PS_HTACCESS_CACHE_CONTROL'), ''); } elseif ((isset($_GET['status'.$this->table]) OR isset($_GET['status'])) AND Tools::getValue($this->identifier)) { if ($this->tabAccess['edit'] === '1') { if (Validate::isLoadedObject($object = $this->loadObject())) { if ($object->main) $this->_errors[] = Tools::displayError('You can\'t disable a main url'); else if ($object->toggleStatus()) Tools::redirectAdmin(self::$currentIndex.'&conf=5&token='.$token); else $this->_errors[] = Tools::displayError('An error occurred while updating status.'); } else $this->_errors[] = Tools::displayError('An error occurred while updating status for object.').' '.$this->table.' '.Tools::displayError('(cannot load object)'); } else $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); } else return parent::postProcess(); } protected function afterUpdate($object) { if (Tools::getValue('main')) $object->setMain(); } public function displayForm($isMainTab = true) { parent::displayForm($isMainTab = true); if (!($obj = $this->loadObject(true))) return; $currentShop = Shop::initialize(); $listShopWithUrl = array(); foreach (Shop::getShops(false, null, true) as $id) $listShopWithUrl[$id] = (bool)count(ShopUrl::getShopUrls($id)); $jsShopUrl = Tools::jsonEncode($listShopWithUrl); echo << // EOF; echo ' '.($obj->id ? '' : '').' '.$this->l('Shop Url').' '.$this->l('Domain').' '.$this->l('Domain SSL').' '.$this->l('Physical URI').' '.$this->l('Physical folder of your store on your server. Leave this field empty if your store is installed on root path.').' '; echo ''.$this->l('Virtual URI').' '.$this->l('This virtual folder must not exist on your server and is used to associate an URI to a shop.').''.$this->l('URL rewriting must be activated on your server to use this feature.').' '; echo ' '.$this->l('Your final URL will be').' '.$this->l('Shop').' '; foreach (Shop::getTree() AS $gID => $gData) { echo ''; foreach ($gData['shops'] as $sID => $sData) echo 'id_shop == $sID ? 'selected="selected"' : '').'>'.$sData['name'].''; echo ''; } echo ' '.$this->l('Main URL:').' getFieldValue($obj, 'main') ? 'checked="checked" ' : '').'/> getFieldValue($obj, 'main') ? 'checked="checked" ' : '').'/> '.$this->l('If you set this url as main url for selected shop, all urls set to this shop will be redirected to this url (you can only have one main url per shop).').' '.$this->l('Since the selected shop has no main url, you have to set this url as main').' '.$this->l('The selected shop has already a main url, if you set this one as main url, the older one will be set as normal url').' '.$this->l('Status:').' getFieldValue($obj, 'active') ? 'checked="checked" ' : '').'/> getFieldValue($obj, 'active') ? 'checked="checked" ' : '').'/> '.$this->l('Enable or disable URL').' * '.$this->l('Required field').' '; } protected function displayAddButton() { echo ' '.$this->l('Add new shop URL').''; } }
'.$this->l('Physical folder of your store on your server. Leave this field empty if your store is installed on root path.').'
'.$this->l('This virtual folder must not exist on your server and is used to associate an URI to a shop.').''.$this->l('URL rewriting must be activated on your server to use this feature.').'
'.$this->l('If you set this url as main url for selected shop, all urls set to this shop will be redirected to this url (you can only have one main url per shop).').'
'.$this->l('Since the selected shop has no main url, you have to set this url as main').'
'.$this->l('The selected shop has already a main url, if you set this one as main url, the older one will be set as normal url').'
'.$this->l('Enable or disable URL').'