* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 7540 $ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ class AdminEmployees extends AdminTab { /** @var array profiles list */ private $profilesArray = array(); public function __construct() { global $cookie; $this->table = 'employee'; $this->className = 'Employee'; $this->lang = false; $this->edit = true; $this->delete = true; $this->_select = 'pl.`name` AS profile'; $this->_join = 'LEFT JOIN `'._DB_PREFIX_.'profile` p ON a.`id_profile` = p.`id_profile` LEFT JOIN `'._DB_PREFIX_.'profile_lang` pl ON (pl.`id_profile` = p.`id_profile` AND pl.`id_lang` = '.(int)($cookie->id_lang).')'; $profiles = Profile::getProfiles((int)($cookie->id_lang)); if (!$profiles) $this->_errors[] = Tools::displayError('No profile'); else foreach ($profiles AS $profile) $this->profilesArray[$profile['name']] = $profile['name']; $this->fieldsDisplay = array( 'id_employee' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 'lastname' => array('title' => $this->l('Last name'), 'width' => 130), 'firstname' => array('title' => $this->l('First name'), 'width' => 130), 'email' => array('title' => $this->l('E-mail address'), 'width' => 180), 'profile' => array('title' => $this->l('Profile'), 'width' => 90, 'type' => 'select', 'select' => $this->profilesArray, 'filter_key' => 'pl!name'), 'active' => array('title' => $this->l('Can log in'), 'align' => 'center', 'active' => 'status', 'type' => 'bool')); $this->optionTitle = $this->l('Employees options'); $this->_fieldsOptions = array( 'PS_PASSWD_TIME_BACK' => array('title' => $this->l('Password regenerate:'), 'desc' => $this->l('Security minimum time to wait to regenerate a new password'), 'cast' => 'intval', 'size' => 5, 'type' => 'text', 'suffix' => ' '.$this->l('minutes')), 'PS_BO_ALLOW_EMPLOYEE_FORM_LANG' => array('title' => $this->l('Memorize form language:'), 'desc' => $this->l('Allow employees to save their own default form language'), 'cast' => 'intval', 'type' => 'select', 'identifier' => 'value', 'list' => array( '0' => array('value' => 0, 'name' => $this->l('No')), '1' => array('value' => 1, 'name' => $this->l('Yes')) )) ); parent::__construct(); } protected function _childValidation() { if (!($obj = $this->loadObject(true))) return false; $email = $this->getFieldValue($obj, 'email'); if (!Validate::isEmail($email)) $this->_errors[] = Tools::displayError('Invalid e-mail'); elseif (Employee::employeeExists($email) AND !Tools::getValue('id_employee')) $this->_errors[] = Tools::displayError('An account already exists for this e-mail address:').' '.$email; } public function displayForm($isMainTab = true) { global $currentIndex, $cookie; parent::displayForm(); if (!($obj = $this->loadObject(true))) return; $profiles = Profile::getProfiles((int)($cookie->id_lang)); echo '
'.($obj->id ? '' : '').' '.((int)$this->tabAccess['view'] ? '' : '').'
'.$this->l('Employees').'
*
*
*

'.($obj->id ? $this->l('Leave blank if you do not want to change your password') : $this->l('Min. 8 characters; use only letters, numbers or').' -_').'

*
 
'; // Note : width= fix Firefox 4 display bug related to colorpicker librarie echo '

'.$this->l('Back office background will be displayed in this color. HTML colors only (e.g.,').' "lightblue", "#CC6600")

 
*
 
*
'; if ((int)$this->tabAccess['edit']) { echo '
 
getFieldValue($obj, 'bo_uimode') == 'hover' ? 'checked="checked" ' : '').'/> getFieldValue($obj, 'bo_uimode') == 'click' ? 'checked="checked" ' : '').'/>
 
getFieldValue($obj, 'active') ? 'checked="checked" ' : '').'/> getFieldValue($obj, 'active') ? 'checked="checked" ' : '').'/>

'.$this->l('Allow or disallow this employee to log into this Back Office').'

*
'; } echo '
 
 
* '.$this->l('Required field').'
'; } public function postProcess() { global $cookie; if (Tools::isSubmit('deleteemployee') OR Tools::isSubmit('status') OR Tools::isSubmit('statusemployee')) { if ($cookie->id_employee == Tools::getValue('id_employee')) { $this->_errors[] = Tools::displayError('You cannot disable or delete your own account.'); return false; } $employee = new Employee(Tools::getValue('id_employee')); if ($employee->isLastAdmin()) { $this->_errors[] = Tools::displayError('You cannot disable or delete the last administrator account.'); return false; } } elseif (Tools::isSubmit('submitAddemployee')) { $employee = new Employee((int)Tools::getValue('id_employee')); if (!(int)$this->tabAccess['edit']) $_POST['id_profile'] = $_GET['id_profile'] = $employee->id_profile; if ($employee->isLastAdmin()) { if (Tools::getValue('id_profile') != (int)_PS_ADMIN_PROFILE_) { $this->_errors[] = Tools::displayError('You should have at least one employee in the administrator group.'); return false; } if (Tools::getvalue('active') == 0) { $this->_errors[] = Tools::displayError('You cannot disable or delete the last administrator account.'); return false; } } } return parent::postProcess(); } }