Skip to content
Snippets Groups Projects
Commit caa00015 authored by Peter Rotich's avatar Peter Rotich
Browse files

Remove LEFT JOIN to time zone table in order to support upgrading from 1.6* to...

Remove LEFT JOIN to time zone table in order to support upgrading from 1.6* to 1.7 + Fix bug on getDepts
parent b7781ead
Branches
Tags
No related merge requests found
...@@ -37,13 +37,11 @@ class Staff { ...@@ -37,13 +37,11 @@ class Staff {
if(!$var && !($var=$this->getId())) if(!$var && !($var=$this->getId()))
return false; return false;
$sql='SELECT staff.*, grp.*, tz.offset as tz_offset ' $sql='SELECT staff.*, staff.created as added, grp.* '
.' ,TIME_TO_SEC(TIMEDIFF(NOW(),IFNULL(staff.passwdreset,staff.created))) as passwd_change_sec '
.' FROM '.STAFF_TABLE.' staff ' .' FROM '.STAFF_TABLE.' staff '
.' LEFT JOIN '.GROUP_TABLE.' grp ON(grp.group_id=staff.group_id) ' .' LEFT JOIN '.GROUP_TABLE.' grp ON(grp.group_id=staff.group_id) ';
.' LEFT JOIN '.TIMEZONE_TABLE.' tz ON(tz.id=staff.timezone_id) ';
$sql.=sprintf('WHERE %s=%s',is_numeric($var)?'staff_id':'username',db_input($var)); $sql.=sprintf(' WHERE %s=%s',is_numeric($var)?'staff_id':'username',db_input($var));
if(!($res=db_query($sql)) || !db_num_rows($res)) if(!($res=db_query($sql)) || !db_num_rows($res))
return NULL; return NULL;
...@@ -51,11 +49,20 @@ class Staff { ...@@ -51,11 +49,20 @@ class Staff {
$this->ht=db_fetch_array($res); $this->ht=db_fetch_array($res);
$this->id = $this->ht['staff_id']; $this->id = $this->ht['staff_id'];
$this->teams =$this->ht['teams']=$this->getTeams(); $this->teams = $this->ht['teams']= array();
$this->teams=array();
$this->stats=array(); $this->stats=array();
//WE have to patch info here to support upgrading from old versions.
if(($time=strtotime($this->ht['passwdreset']?$this->ht['passwdreset']:$this->ht['added'])))
$this->ht['passwd_change'] = time()-$time; //XXX: check timezone issues.
/* TODO: Add timezone class
if($this->ht['timezone_id'])
$this->ht['tz_offset'] = Timezone::getOffsetById($this->ht['timezone_id']);
elseif($this->ht['timezone_offset'])
$this->ht['tz_offset'] = $this->ht['timezone_offset'];
*/
return ($this->id); return ($this->id);
} }
...@@ -96,7 +103,7 @@ class Staff { ...@@ -96,7 +103,7 @@ class Staff {
function isPasswdResetDue() { function isPasswdResetDue() {
global $cfg; global $cfg;
return ($cfg && $cfg->getPasswdResetPeriod() return ($cfg && $cfg->getPasswdResetPeriod()
&& $this->ht['passwd_change_sec']>($cfg->getPasswdResetPeriod()*30*24*60*60)); && $this->ht['passwd_change']>($cfg->getPasswdResetPeriod()*30*24*60*60));
} }
function isPasswdChangeDue() { function isPasswdChangeDue() {
...@@ -169,7 +176,7 @@ class Staff { ...@@ -169,7 +176,7 @@ class Staff {
function getDepts() { function getDepts() {
//Departments the user is allowed to access...based on the group they belong to + user's dept. //Departments the user is allowed to access...based on the group they belong to + user's dept.
return array_filter(array_unique(array_merge(explode(',', $this->ht['dept_access']), array($this->dept_id)))); //Neptune help us return array_filter(array_unique(array_merge(explode(',', $this->ht['dept_access']), array($this->getDeptId())))); //Neptune help us
} }
function getDepartments() { function getDepartments() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment