* @copyright 2007-2011 PrestaShop SA
* @version Release: $Revision: 7499 $
* @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 AdminWebservice extends AdminTab
{
public function __construct()
{
$this->table = 'webservice_account';
$this->className = 'WebserviceKey';
$this->lang = false;
$this->edit = true;
$this->delete = true;
$this->id_lang_default = Configuration::get('PS_LANG_DEFAULT');
$this->fieldsDisplay = array(
'key' => array('title' => $this->l('Key'), 'align' => 'center', 'width' => 32),
'active' => array('title' => $this->l('Enabled'), 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false),
'description' => array('title' => $this->l('Key description'), 'align' => 'center', 'orderby' => false)
);
if (file_exists(_PS_ROOT_DIR_.'/.htaccess'))
$this->optionsList = array(
'general' => array(
'title' => $this->l('Configuration'),
'fields' => array(
'PS_WEBSERVICE' => array('title' => $this->l('Enable PrestaShop Webservice:'),
'desc' => $this->l('Before activating the webservice, you must be sure to: ').
'
- '.$this->l('be certain URL rewrite is available on this server').
'
- '.$this->l('be certain that the 5 methods GET, POST, PUT, DELETE and HEAD are supported by this server').
'
',
'cast' => 'intval',
'type' => 'bool'),
),
),
);
parent::__construct();
}
protected function afterAdd($object)
{
WebserviceKey::setPermissionForAccount($object->id, Tools::getValue('resources', array()));
}
protected function afterUpdate($object)
{
WebserviceKey::setPermissionForAccount($object->id, Tools::getValue('resources', array()));
}
public function checkForWarning()
{
$warnings = array();
if (!file_exists(_PS_ROOT_DIR_.'/.htaccess'))
$warnings[] = $this->l('In order to enable the PrestaShop Webservice, please generate the .htaccess file via the "Generators" tab (in the "Tools" tab).');
if (strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') === false)
$warnings[] = $this->l('To avoid operating problems, please use an Apache server.');
{
if (function_exists('apache_get_modules'))
{
$apache_modules = apache_get_modules();
if (!in_array('mod_auth_basic', $apache_modules))
$warnings[] = $this->l('Please activate the Apache module \'mod_auth_basic\' to allow authentication of PrestaShop webservice.');
if (!in_array('mod_rewrite', $apache_modules))
$warnings[] = $this->l('Please activate the Apache module \'mod_rewrite\' to allow using the PrestaShop webservice.');
}
else
{
$warnings[] = $this->l('We could not check if basic authentication and rewrite extensions are activated. Please manually check if they are activated in order to use the PrestaShop webservice.');
}
}
if (!extension_loaded('SimpleXML'))
$warnings[] = $this->l('Please activate the PHP extension \'SimpleXML\' to allow testing of PrestaShop webservice.');
if (!configuration::get('PS_SSL_ENABLED'))
$warnings[] = $this->l('If possible, it is preferable to use SSL (https) for webservice calls, as it avoids the security issues of type "man in the middle".');
$this->displayWarning($warnings);
foreach ($this->_list as $k => $item)
if ($item['is_module'] && $item['class_name'] && $item['module_name'] &&
($instance = Module::getInstanceByName($item['module_name'])) &&
!$instance->useNormalPermissionBehaviour())
unset($this->_list[$k]);
parent::displayList();
}
public function displayForm($isMainTab = true)
{
parent::displayForm();
if (!($obj = $this->loadObject(true)))
return;
echo '
';
}
public function postProcess()
{
if (Tools::getValue('key') && strlen(Tools::getValue('key')) < 32)
$this->_errors[] = Tools::displayError($this->l('Key length must be 32 character long'));
if (WebserviceKey::keyExists(Tools::getValue('key')) && !Tools::getValue('id_webservice_account'))
$this->_errors[] = Tools::displayError($this->l('Key already exists'));
return parent::postProcess();
}
public function display()
{
// Include other tab in current tab
if ($this->includeSubTab('display', array('submitAdd2', 'add', 'update', 'view'))){}
// Include current tab
elseif ((Tools::getValue('submitAdd'.$this->table) AND sizeof($this->_errors)) OR isset($_GET['add'.$this->table]))
{
if ($this->tabAccess['add'] === '1')
{
$this->displayForm();
if ($this->tabAccess['view'])
echo '
'.((Tools::getValue('back')) ? $this->l('Back') : $this->l('Back to list')).'
';
}
else
echo $this->l('You do not have permission to add here');
}
elseif (isset($_GET['update'.$this->table]))
{
if ($this->tabAccess['edit'] === '1' OR ($this->table == 'employee' AND $this->context->employee->id == Tools::getValue('id_employee')))
{
$this->displayForm();
if ($this->tabAccess['view'])
echo '
'.((Tools::getValue('back')) ? $this->l('Back') : $this->l('Back to list')).'
';
}
else
echo $this->l('You do not have permission to edit here');
}
elseif (isset($_GET['view'.$this->table]))
$this->{'view'.$this->table}();
else
{
$this->checkForWarning();
$this->getList($this->context->language->id);
$this->displayList();
$this->displayRequiredFields();
$this->includeSubTab('display');
$assos_shop = Shop::getAssoTables();
if (isset($assos_shop[$this->table]) AND $assos_shop[$this->table]['type'] == 'shop')
$this->displayAssoShop();
elseif (isset($assos_shop[$this->table]) AND $assos_shop[$this->table]['type'] == 'group_shop')
$this->displayAssoShop('group_shop');
$this->displayOptionsList();
}
}
}