* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 7636 $
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
include_once(dirname(__FILE__).'/../../classes/AdminTab.php');
class AdminStores extends AdminTab
{
/** @var array countries list */
private $countriesArray = array();
public function __construct()
{
global $cookie;
$this->table = 'store';
$this->className = 'Store';
$this->lang = false;
$this->edit = true;
$this->delete = true;
$this->fieldImageSettings = array('name' => 'image', 'dir' => 'st');
$this->_select = 'cl.`name` country, st.`name` state';
$this->_join = '
LEFT JOIN `'._DB_PREFIX_.'country_lang` cl ON (cl.`id_country` = a.`id_country` AND cl.`id_lang` = '.(int)($cookie->id_lang).')
LEFT JOIN `'._DB_PREFIX_.'state` st ON (st.`id_state` = a.`id_state`)';
$countries = Country::getCountries((int)($cookie->id_lang));
foreach ($countries AS $country)
$this->countriesArray[$country['id_country']] = $country['name'];
$this->fieldsDisplay = array(
'id_store' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
'country' => array('title' => $this->l('Country'), 'width' => 100),
'state' => array('title' => $this->l('State'), 'width' => 100),
'city' => array('title' => $this->l('City'), 'width' => 100),
'postcode' => array('title' => $this->l('Zip code'), 'width' => 50),
'name' => array('title' => $this->l('Name'), 'width' => 120),
'phone' => array('title' => $this->l('Phone'), 'width' => 70),
'fax' => array('title' => $this->l('Fax'), 'width' => 70),
'active' => array('title' => $this->l('Enabled'), 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false)
);
$this->optionTitle = $this->l('Parameters');
$this->_fieldsOptions = array(
'PS_STORES_DISPLAY_FOOTER' => array('title' => $this->l('Display in the footer:'), 'desc' => $this->l('Display a link to the store locator in the footer'), 'cast' => 'intval', 'type' => 'bool'),
'PS_STORES_DISPLAY_SITEMAP' => array('title' => $this->l('Display in the sitemap page:'), 'desc' => $this->l('Display a link to the store locator in the sitemap page'), 'cast' => 'intval', 'type' => 'bool'),
'PS_STORES_SIMPLIFIED' => array('title' => $this->l('Show a simplified store locator:'), 'desc' => $this->l('No map, no search, only a store directory'), 'cast' => 'intval', 'type' => 'bool'),
'PS_STORES_CENTER_LAT' => array('title' => $this->l('Latitude by default:'), 'desc' => $this->l('Used for the default map position'), 'cast' => 'floatval', 'type' => 'float', 'size' => '10'),
'PS_STORES_CENTER_LONG' => array('title' => $this->l('Longitude by default:'), 'desc' => $this->l('Used for the default map position'), 'cast' => 'floatval', 'type' => 'float', 'size' => '10'));
parent::__construct();
}
protected function postImage($id)
{
$ret = parent::postImage($id);
if (($id_store = (int)(Tools::getValue('id_store'))) AND isset($_FILES) AND sizeof($_FILES) AND file_exists(_PS_STORE_IMG_DIR_.$id_store.'.jpg'))
{
$imagesTypes = ImageType::getImagesTypes('stores');
foreach ($imagesTypes AS $k => $imageType)
imageResize(_PS_STORE_IMG_DIR_.$id_store.'.jpg', _PS_STORE_IMG_DIR_.$id_store.'-'.stripslashes($imageType['name']).'.jpg', (int)($imageType['width']), (int)($imageType['height']));
}
return $ret;
}
public function displayOptionsList()
{
parent::displayOptionsList();
echo '
'.$this->l('You can also replace the icon representing your store in Google Maps. Go to the Preferences tab, and then the Appearance subtab.').'
'; } public function postProcess() { if (isset($_POST['submitAdd'.$this->table])) { /* Cleaning fields */ foreach ($_POST as $kp => $vp) $_POST[$kp] = trim($vp); /* If the selected country does not contain states */ $id_state = (int)(Tools::getValue('id_state')); if ($id_country = Tools::getValue('id_country') AND $country = new Country((int)($id_country)) AND !(int)($country->contains_states) AND $id_state) $this->_errors[] = Tools::displayError('You have selected a state for a country that does not contain states.'); /* If the selected country contains states, then a state have to be selected */ if ((int)($country->contains_states) AND !$id_state) $this->_errors[] = Tools::displayError('An address located in a country containing states must have a state selected.'); $latitude = (int)(Tools::getValue('latitude')); $longitude = (int)(Tools::getValue('longitude')); if(empty($latitude) OR empty($longitude)) $this->_errors[] = Tools::displayError('Latitude and longitude are required.'); /* Check zip code */ if ($country->need_zip_code) { $zip_code_format = $country->zip_code_format; if (($postcode = Tools::getValue('postcode')) AND $zip_code_format) { $zip_regexp = '/^'.$zip_code_format.'$/ui'; $zip_regexp = str_replace(' ', '( |)', $zip_regexp); $zip_regexp = str_replace('-', '(-|)', $zip_regexp); $zip_regexp = str_replace('N', '[0-9]', $zip_regexp); $zip_regexp = str_replace('L', '[a-zA-Z]', $zip_regexp); $zip_regexp = str_replace('C', $country->iso_code, $zip_regexp); if (!preg_match($zip_regexp, $postcode)) $this->_errors[] = Tools::displayError('Your zip/postal code is incorrect.').'