'.$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').
- '
',
+ '
+
'.$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'),
),
@@ -63,138 +78,97 @@ class AdminWebserviceControllerCore extends AdminController
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()
- {
- if (!file_exists(_PS_ROOT_DIR_.'/.htaccess'))
- $this->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)
- $this->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))
- $this->warnings[] = $this->l('Please activate the Apache module \'mod_auth_basic\' to allow authentication of PrestaShop webservice.');
- if (!in_array('mod_rewrite', $apache_modules))
- $this->warnings[] = $this->l('Please activate the Apache module \'mod_rewrite\' to allow using the PrestaShop webservice.');
- }
- else
- {
- $this->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'))
- $this->warnings[] = $this->l('Please activate the PHP extension \'SimpleXML\' to allow testing of PrestaShop webservice.');
- if (!configuration::get('PS_SSL_ENABLED'))
- $this->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".');
-
- 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]);
- $this->initList();
- }
-
- /** @todo : to fill $this->fields_form in order to generate
- * the form automatically..
- *
- */
- public function initForm($isMainTab = true)
+ public function initForm()
{
- $content = '';
+ $this->fields_form = array(
+ 'legend' => array(
+ 'title' => $this->l('Webservice Accounts:'),
+ 'image' => '../img/admin/access.png'
+ ),
+ 'input' => array(
+ array(
+ 'type' => 'text',
+ 'label' => $this->l('Key:'),
+ 'name' => 'key',
+ 'id' => 'code',
+ 'size' => 32,
+ 'required' => true,
+ 'p' => $this->l('Webservice account key'),
+ ),
+ array(
+ 'type' => 'textarea',
+ 'label' => $this->l('Key description:'),
+ 'name' => 'description',
+ 'rows' => 3,
+ 'cols' => 110,
+ 'p' => $this->l('Key description'),
+ ),
+ array(
+ 'type' => 'radio',
+ 'label' => $this->l('Status:'),
+ 'name' => 'active',
+ 'required' => false,
+ 'class' => 't',
+ 'is_bool' => true,
+ 'values' => array(
+ array(
+ 'id' => 'active_on',
+ 'value' => 1,
+ 'label' => $this->l('Enabled')
+ ),
+ array(
+ 'id' => 'active_off',
+ 'value' => 0,
+ 'label' => $this->l('Disabled')
+ )
+ )
+ ),
+ array(
+ 'type' => 'resources',
+ 'label' => $this->l('Permissions:'),
+ 'name' => 'resources',
+ )
+ )
+ );
+
+ if (Shop::isFeatureActive())
+ {
+ $this->fields_form['input'][] = array(
+ 'type' => 'shop',
+ 'label' => $this->l('Shop association:'),
+ 'name' => 'checkBoxShopAsso',
+ 'values' => Shop::getTree()
+ );
+ }
+
+ $this->fields_form['submit'] = array(
+ 'title' => $this->l(' Save '),
+ 'class' => 'button'
+ );
+
if (!($obj = $this->loadObject(true)))
return;
-
- $content = '
- ';
- $this->tpl_form_vars['custom_form'] = $content;
+
+ $this->tpl_form_vars = array(
+ 'ressources' => $ressources,
+ 'permissions' => $permissions
+ );
+
return parent::initForm();
}
+ public function initContent()
+ {
+ if ($this->display != 'add' && $this->display != 'edit')
+ $this->checkForWarning();
+
+ parent::initContent();
+ }
+
public function postProcess()
{
if (Tools::getValue('key') && strlen(Tools::getValue('key')) < 32)
@@ -204,57 +178,49 @@ class AdminWebserviceControllerCore extends AdminController
return parent::postProcess();
}
- public function initContent()
+ protected function afterAdd($object)
{
- $content = '';
- // Include other tab in current tab
- if ($this->includeSubTab('display', array('submitAdd2', 'add', 'update', 'view'))){}
+ WebserviceKey::setPermissionForAccount($object->id, Tools::getValue('resources', array()));
+ }
- // Include current tab
- elseif ((Tools::getValue('submitAdd'.$this->table) AND sizeof($this->_errors)) OR isset($_GET['add'.$this->table]))
+ protected function afterUpdate($object)
+ {
+ WebserviceKey::setPermissionForAccount($object->id, Tools::getValue('resources', array()));
+ }
+
+ public function checkForWarning()
+ {
+ if (!file_exists(_PS_ROOT_DIR_.'/.htaccess'))
+ $this->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)
{
- if ($this->tabAccess['add'] === '1')
+ $this->warnings[] = $this->l('To avoid operating problems, please use an Apache server.');
+ if (function_exists('apache_get_modules'))
{
- $this->display = 'add';
-// $content .= $this->initForm();
- if ($this->tabAccess['view'])
- $content .= '
'.((Tools::getValue('back')) ? $this->l('Back') : $this->l('Back to list')).' ';
+ $apache_modules = apache_get_modules();
+ if (!in_array('mod_auth_basic', $apache_modules))
+ $this->warnings[] = $this->l('Please activate the Apache module \'mod_auth_basic\' to allow authentication of PrestaShop webservice.');
+ if (!in_array('mod_rewrite', $apache_modules))
+ $this->warnings[] = $this->l('Please activate the Apache module \'mod_rewrite\' to allow using the PrestaShop webservice.');
}
else
- $content .= $this->l('You do not have permission to add here');
+ $this->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.');
}
- elseif (isset($_GET['update'.$this->table]))
- {
- if ($this->tabAccess['edit'] === '1' OR ($this->table == 'employee' AND $this->context->employee->id == Tools::getValue('id_employee')))
- {
- $content .= $this->initForm();
- if ($this->tabAccess['view'])
- $content .= '
'.((Tools::getValue('back')) ? $this->l('Back') : $this->l('Back to list')).' ';
- }
- else
- $content .= $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();
-*/
- }
- parent::initContent();
+ if (!extension_loaded('SimpleXML'))
+ $this->warnings[] = $this->l('Please activate the PHP extension \'SimpleXML\' to allow testing of PrestaShop webservice.');
+ if (!configuration::get('PS_SSL_ENABLED'))
+ $this->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".');
+
+ 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]);
+
+ $this->initList();
}
}