PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/adminstrator/tabs/AdminEmployees.php

http://marocmall.googlecode.com/
PHP | 229 lines | 185 code | 17 blank | 27 comment | 21 complexity | 2317ce0475928a65be68790009435694 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /*
  3. * 2007-2011 PrestaShop
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@prestashop.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
  18. * versions in the future. If you wish to customize PrestaShop for your
  19. * needs please refer to http://www.prestashop.com for more information.
  20. *
  21. * @author PrestaShop SA <contact@prestashop.com>
  22. * @copyright 2007-2011 PrestaShop SA
  23. * @version Release: $Revision: 8943 $
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. * International Registered Trademark & Property of PrestaShop SA
  26. */
  27. class AdminEmployees extends AdminTab
  28. {
  29. /** @var array profiles list */
  30. private $profilesArray = array();
  31. public function __construct()
  32. {
  33. global $cookie;
  34. $this->table = 'employee';
  35. $this->className = 'Employee';
  36. $this->lang = false;
  37. $this->edit = true;
  38. $this->delete = true;
  39. $this->_select = 'pl.`name` AS profile';
  40. $this->_join = 'LEFT JOIN `'._DB_PREFIX_.'profile` p ON a.`id_profile` = p.`id_profile`
  41. LEFT JOIN `'._DB_PREFIX_.'profile_lang` pl ON (pl.`id_profile` = p.`id_profile` AND pl.`id_lang` = '.(int)($cookie->id_lang).')';
  42. $profiles = Profile::getProfiles((int)($cookie->id_lang));
  43. if (!$profiles)
  44. $this->_errors[] = Tools::displayError('No profile');
  45. else
  46. foreach ($profiles AS $profile)
  47. $this->profilesArray[$profile['name']] = $profile['name'];
  48. $this->fieldsDisplay = array(
  49. 'id_employee' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
  50. 'lastname' => array('title' => $this->l('Last name'), 'width' => 130),
  51. 'firstname' => array('title' => $this->l('First name'), 'width' => 130),
  52. 'email' => array('title' => $this->l('E-mail address'), 'width' => 180),
  53. 'profile' => array('title' => $this->l('Profile'), 'width' => 90, 'type' => 'select', 'select' => $this->profilesArray, 'filter_key' => 'pl!name'),
  54. 'active' => array('title' => $this->l('Can log in'), 'align' => 'center', 'active' => 'status', 'type' => 'bool'));
  55. $this->optionTitle = $this->l('Employees options');
  56. $this->_fieldsOptions = array(
  57. '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')),
  58. '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(
  59. '0' => array('value' => 0, 'name' => $this->l('No')),
  60. '1' => array('value' => 1, 'name' => $this->l('Yes'))
  61. ))
  62. );
  63. parent::__construct();
  64. }
  65. protected function _childValidation()
  66. {
  67. if (!($obj = $this->loadObject(true)))
  68. return false;
  69. $email = $this->getFieldValue($obj, 'email');
  70. if (!Validate::isEmail($email))
  71. $this->_errors[] = Tools::displayError('Invalid e-mail');
  72. elseif (Employee::employeeExists($email) AND !Tools::getValue('id_employee'))
  73. $this->_errors[] = Tools::displayError('An account already exists for this e-mail address:').' '.$email;
  74. }
  75. public function displayForm($isMainTab = true)
  76. {
  77. global $currentIndex, $cookie;
  78. parent::displayForm();
  79. if (!($obj = $this->loadObject(true)))
  80. return;
  81. $profiles = Profile::getProfiles((int)($cookie->id_lang));
  82. echo '<script type="text/javascript" src="'._PS_JS_DIR_.'/jquery/jquery-colorpicker.js"></script>
  83. <script type="text/javascript">
  84. var employeePage = true;
  85. </script>
  86. <form action="'.$currentIndex.'&submitAdd'.$this->table.'=1&token='.$this->token.((int)$this->tabAccess['view'] ? '' : '&updateemployee&id_employee='.(int)$obj->id).'" method="post" enctype="multipart/form-data" autocomplete="off">
  87. '.($obj->id ? '<input type="hidden" name="id_'.$this->table.'" value="'.$obj->id.'" />' : '').'
  88. '.((int)$this->tabAccess['view'] ? '' : '<input type="hidden" name="back" value="'.$currentIndex.'&token='.$this->token.'&updateemployee&id_employee='.(int)$obj->id.'" />').'
  89. <fieldset class="width3"><legend><img src="../img/admin/nav-user.gif" />'.$this->l('Employees').'</legend>
  90. <label>'.$this->l('Last name:').' </label>
  91. <div class="margin-form">
  92. <input type="text" size="33" name="lastname" value="'.htmlentities($this->getFieldValue($obj, 'lastname'), ENT_COMPAT, 'UTF-8').'" /> <sup>*</sup>
  93. </div>
  94. <label>'.$this->l('First name:').' </label>
  95. <div class="margin-form">
  96. <input type="text" size="33" name="firstname" value="'.htmlentities($this->getFieldValue($obj, 'firstname'), ENT_COMPAT, 'UTF-8').'" /> <sup>*</sup>
  97. </div>
  98. <label>'.$this->l('Password:').' </label>
  99. <div class="margin-form">
  100. <input type="password" size="33" name="passwd" value="" /> <sup>*</sup>
  101. <p>'.($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').' -_').'</p>
  102. </div>
  103. <label>'.$this->l('E-mail address:').' </label>
  104. <div class="margin-form">
  105. <input type="text" size="33" name="email" value="'.htmlentities($this->getFieldValue($obj, 'email'), ENT_COMPAT, 'UTF-8').'" /> <sup>*</sup>
  106. </div><div class="clear">&nbsp;</div>
  107. <label>'.$this->l('Back office color:').' </label>
  108. <div class="margin-form">';
  109. // Note : width= fix Firefox 4 display bug related to colorpicker librarie
  110. echo '<input type="color" width="50px" data-hex="true" class="color mColorPickerInput" name="bo_color" value="'.htmlentities($this->getFieldValue($obj, 'bo_color'), ENT_COMPAT, 'UTF-8').'" />
  111. <p>'.$this->l('Back office background will be displayed in this color. HTML colors only (e.g.,').' "lightblue", "#CC6600")</p>
  112. </div><div class="clear">&nbsp;</div>
  113. <label>'.$this->l('Language:').' </label>
  114. <div class="margin-form">
  115. <select name="id_lang">';
  116. foreach (Language::getLanguages() as $lang)
  117. echo ' <option value="'.(int)$lang['id_lang'].'" '.($this->getFieldValue($obj, 'id_lang') == $lang['id_lang'] ? 'selected="selected"' : '').'>'.Tools::htmlentitiesUTF8($lang['name']).'</option>';
  118. echo ' </select> <sup>*</sup>
  119. </div><div class="clear">&nbsp;</div>
  120. <label>'.$this->l('Theme:').' </label>
  121. <div class="margin-form">
  122. <select name="bo_theme">';
  123. $path = dirname(__FILE__).'/../themes/';
  124. foreach (scandir($path) as $theme)
  125. if ($theme[0] != '.' AND file_exists($path.$theme.'/admin.css'))
  126. echo ' <option value="'.Tools::htmlentitiesUTF8($theme).'" '.($this->getFieldValue($obj, 'bo_theme') == $theme ? 'selected="selected"' : '').'>'.Tools::htmlentitiesUTF8($theme).'</option>';
  127. echo ' </select> <sup>*</sup>
  128. </div>';
  129. if ((int)$this->tabAccess['edit'])
  130. {
  131. echo '<div class="clear">&nbsp;</div>
  132. <label>'.$this->l('UI mode:').' </label>
  133. <div class="margin-form">
  134. <input type="radio" name="bo_uimode" id="uimode_on" value="hover" '.($this->getFieldValue($obj, 'bo_uimode') == 'hover' ? 'checked="checked" ' : '').'/>
  135. <label class="t" for="uimode_on">'.$this->l('Hover on tabs').'</label>
  136. <input type="radio" name="bo_uimode" id="uimode_off" value="click" '.($this->getFieldValue($obj, 'bo_uimode') == 'click' ? 'checked="checked" ' : '').'/>
  137. <label class="t" for="uimode_off">'.$this->l('Click on tabs').'</label>
  138. </div><div class="clear">&nbsp;</div>
  139. <label>'.$this->l('Show screencast:').' </label>
  140. <div class="margin-form">
  141. <input type="radio" name="bo_show_screencast" id="bo_show_screencast_on" value="1" '.($this->getFieldValue($obj, 'bo_show_screencast') ? 'checked="checked" ' : '').'/>
  142. <label class="t" for="active_on"> <img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" /></label>
  143. <input type="radio" name="bo_show_screencast" id="bo_show_screencast_off" value="0" '.(!$this->getFieldValue($obj, 'bo_show_screencast') ? 'checked="checked" ' : '').'/>
  144. <label class="t" for="active_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label>
  145. <p>'.$this->l('Show the welcome video on the dashbord of the back office').'</p>
  146. </div>
  147. <label>'.$this->l('Status:').' </label>
  148. <div class="margin-form">
  149. <input type="radio" name="active" id="active_on" value="1" '.($this->getFieldValue($obj, 'active') ? 'checked="checked" ' : '').'/>
  150. <label class="t" for="active_on"> <img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" /></label>
  151. <input type="radio" name="active" id="active_off" value="0" '.(!$this->getFieldValue($obj, 'active') ? 'checked="checked" ' : '').'/>
  152. <label class="t" for="active_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" /></label>
  153. <p>'.$this->l('Allow or disallow this employee to log into this Back Office').'</p>
  154. </div>
  155. <label>'.$this->l('Profile:').' </label>
  156. <div class="margin-form">
  157. <select name="id_profile">
  158. <option value="">'.$this->l('-- Choose --').'</option>';
  159. foreach ($profiles AS $profile)
  160. echo '<option value="'.$profile['id_profile'].'"'.($profile['id_profile'] === $this->getFieldValue($obj, 'id_profile') ? ' selected="selected"' : '').'>'.$profile['name'].'</option>';
  161. echo '</select> <sup>*</sup>
  162. </div>';
  163. }
  164. echo '<div class="clear">&nbsp;</div>
  165. <center>
  166. <input type="submit" value="'.$this->l(' Save ').'" name="submitAdd'.$this->table.'" class="button" />
  167. </center><div class="clear">&nbsp;</div>
  168. <div class="small"><sup>*</sup> '.$this->l('Required field').'</div>
  169. </fieldset>
  170. </form>';
  171. }
  172. public function postProcess()
  173. {
  174. global $cookie;
  175. if (Tools::isSubmit('deleteemployee') OR Tools::isSubmit('status') OR Tools::isSubmit('statusemployee'))
  176. {
  177. if ($cookie->id_employee == Tools::getValue('id_employee'))
  178. {
  179. $this->_errors[] = Tools::displayError('You cannot disable or delete your own account.');
  180. return false;
  181. }
  182. $employee = new Employee(Tools::getValue('id_employee'));
  183. if ($employee->isLastAdmin())
  184. {
  185. $this->_errors[] = Tools::displayError('You cannot disable or delete the last administrator account.');
  186. return false;
  187. }
  188. }
  189. elseif (Tools::isSubmit('submitAddemployee'))
  190. {
  191. $employee = new Employee((int)Tools::getValue('id_employee'));
  192. if (!(int)$this->tabAccess['edit'])
  193. $_POST['id_profile'] = $_GET['id_profile'] = $employee->id_profile;
  194. if ($employee->isLastAdmin())
  195. {
  196. if (Tools::getValue('id_profile') != (int)_PS_ADMIN_PROFILE_)
  197. {
  198. $this->_errors[] = Tools::displayError('You should have at least one employee in the administrator group.');
  199. return false;
  200. }
  201. if (Tools::getvalue('active') == 0)
  202. {
  203. $this->_errors[] = Tools::displayError('You cannot disable or delete the last administrator account.');
  204. return false;
  205. }
  206. }
  207. }
  208. return parent::postProcess();
  209. }
  210. }