// Merge -> revision 8952

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8957 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
rMalie
2011-10-03 09:14:01 +00:00
parent f1e265fad4
commit ef17d0b7da
44 changed files with 622 additions and 366 deletions
+50 -46
View File
@@ -1,6 +1,6 @@
<?php
/*
* 2007-2011 PrestaShop
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
@@ -28,54 +28,57 @@
class EmployeeCore extends ObjectModel
{
public $id;
/** @var string Determine employee profile */
public $id_profile;
/** @var string employee language */
public $id_lang;
/** @var string Lastname */
public $lastname;
/** @var string Firstname */
public $firstname;
/** @var string e-mail */
public $email;
/** @var string Password */
public $passwd;
/** @var datetime Password */
public $last_passwd_gen;
public $stats_date_from;
public $stats_date_to;
/** @var string Display back office background in the specified color */
public $bo_color;
/** @var string employee's chosen theme */
public $bo_theme;
/** @var string / enum hover or click mode */
public $bo_uimode;
/** @var bool, true */
public $bo_show_screencast;
/** @var boolean Status */
public $active = 1;
/** @var boolean show screencast */
public $show_screencast = 1;
public $remote_addr;
protected $fieldsRequired = array('lastname', 'firstname', 'email', 'passwd', 'id_profile', 'id_lang');
protected $fieldsSize = array('lastname' => 32, 'firstname' => 32, 'email' => 128, 'passwd' => 32, 'bo_color' => 32, 'bo_theme' => 32);
protected $fieldsValidate = array('lastname' => 'isName', 'firstname' => 'isName', 'email' => 'isEmail', 'id_lang' => 'isUnsignedInt',
'passwd' => 'isPasswdAdmin', 'active' => 'isBool', 'id_profile' => 'isInt', 'bo_color' => 'isColor', 'bo_theme' => 'isGenericName',
'bo_uimode' => 'isGenericName', 'show_screencast' => 'isBool');
protected $fieldsValidate = array('lastname' => 'isName', 'firstname' => 'isName', 'email' => 'isEmail', 'id_lang' => 'isUnsignedInt',
'passwd' => 'isPasswdAdmin', 'active' => 'isBool', 'id_profile' => 'isInt', 'bo_color' => 'isColor', 'bo_theme' => 'isGenericName',
'bo_uimode' => 'isGenericName', 'show_screencast' => 'isBool', 'bo_show_screencast' => 'isBool');
protected $table = 'employee';
protected $identifier = 'id_employee';
@@ -88,12 +91,12 @@ class EmployeeCore extends ObjectModel
'passwd' => array('setter' => 'setWsPasswd'),
),
);
public function getFields()
{
$this->validateFields();
$fields['id_profile'] = (int)$this->id_profile;
$fields['id_lang'] = (int)$this->id_lang;
$fields['lastname'] = pSQL($this->lastname);
@@ -101,21 +104,22 @@ class EmployeeCore extends ObjectModel
$fields['email'] = pSQL($this->email);
$fields['passwd'] = pSQL($this->passwd);
$fields['last_passwd_gen'] = pSQL($this->last_passwd_gen);
if (empty($this->stats_date_from))
$this->stats_date_from = date('Y-m-d 00:00:00');
$fields['stats_date_from'] = pSQL($this->stats_date_from);
if (empty($this->stats_date_to))
$this->stats_date_to = date('Y-m-d 23:59:59');
$fields['stats_date_to'] = pSQL($this->stats_date_to);
$fields['bo_color'] = pSQL($this->bo_color);
$fields['bo_theme'] = pSQL($this->bo_theme);
$fields['bo_uimode'] = pSQL($this->bo_uimode);
$fields['bo_show_screencast'] = (int)$this->bo_show_screencast;
$fields['active'] = (int)$this->active;
$fields['show_screencast'] = (int)$this->show_screencast;
return $fields;
}
@@ -124,10 +128,10 @@ class EmployeeCore extends ObjectModel
$this->last_passwd_gen = date('Y-m-d H:i:s', strtotime('-'.Configuration::get('PS_PASSWD_TIME_BACK').'minutes'));
return parent::add($autodate, $nullValues);
}
/**
* Return employee instance from its e-mail (optionnaly check password)
*
*
* @param string $email e-mail
* @param string $passwd Password is also checked if specified
* @return Employee instance
@@ -138,7 +142,7 @@ class EmployeeCore extends ObjectModel
die(Tools::displayError());
$result = Db::getInstance()->getRow('
SELECT *
SELECT *
FROM `'._DB_PREFIX_.'employee`
WHERE `active` = 1
AND `email` = \''.pSQL($email).'\'
@@ -152,12 +156,12 @@ class EmployeeCore extends ObjectModel
$this->{$key} = $value;
return $this;
}
public static function employeeExists($email)
{
if (!Validate::isEmail($email))
die (Tools::displayError());
return (bool)Db::getInstance()->getValue('
SELECT `id_employee`
FROM `'._DB_PREFIX_.'employee`
@@ -166,7 +170,7 @@ class EmployeeCore extends ObjectModel
/**
* Check if employee password is the right one
*
*
* @param string $passwd Password
* @return boolean result
*/
@@ -174,7 +178,7 @@ class EmployeeCore extends ObjectModel
{
if (!Validate::isUnsignedId($id_employee) OR !Validate::isPasswd($passwd, 8))
die (Tools::displayError());
return Db::getInstance()->getValue('
SELECT `id_employee`
FROM `'._DB_PREFIX_.'employee`
@@ -182,24 +186,24 @@ class EmployeeCore extends ObjectModel
AND `passwd` = \''.pSQL($passwd).'\'
AND active = 1');
}
public static function countProfile($id_profile, $activeOnly = false)
{
return Db::getInstance()->getValue('
SELECT COUNT(*)
FROM `'._DB_PREFIX_.'employee`
FROM `'._DB_PREFIX_.'employee`
WHERE `id_profile` = '.(int)$id_profile.'
'.($activeOnly ? ' AND `active` = 1' : ''));
}
public function isLastAdmin()
{
return ($this->id_profile == _PS_ADMIN_PROFILE_
AND Employee::countProfile($this->id_profile, true) == 1
AND $this->active
return ($this->id_profile == _PS_ADMIN_PROFILE_
&& Employee::countProfile($this->id_profile, true) == 1
&& $this->active
);
}
public function setWsPasswd($passwd)
{
if ($this->id != 0)
@@ -211,7 +215,7 @@ class EmployeeCore extends ObjectModel
$this->passwd = Tools::encrypt($passwd);
return true;
}
/**
* Check employee informations saved into cookie and return employee validity
*
@@ -221,12 +225,12 @@ class EmployeeCore extends ObjectModel
{
/* Employee is valid only if it can be load and if cookie password is the same as database one */
return ($this->id
AND Validate::isUnsignedId($this->id)
AND Employee::checkPassword($this->id, $this->passwd)
AND (!isset($this->remote_addr) OR $this->remote_addr == ip2long(Tools::getRemoteAddr()) OR !Configuration::get('PS_COOKIE_CHECKIP'))
&& Validate::isUnsignedId($this->id)
&& Employee::checkPassword($this->id, $this->passwd)
&& (!isset($this->remote_addr) || $this->remote_addr == ip2long(Tools::getRemoteAddr()) || !Configuration::get('PS_COOKIE_CHECKIP'))
);
}
/**
* Logout
*/