quote($login); $sql .= " AND u.status = 1"; $res = $mdb2->query($sql); if (is_a($res, 'PEAR_Error')) { return; } $val = $res->fetchRow(); if ($val['id'] > 0) { $this->login = $val['login']; $this->name = $val['name']; $this->id = $val['id']; $this->team_id = $val['team_id']; $this->role = $val['role']; $this->client_id = $val['client_id']; $this->email = $val['email']; $this->lang = $val['lang']; $this->decimal_mark = $val['decimal_mark']; $this->date_format = $val['date_format']; $this->time_format = $val['time_format']; $this->week_start = $val['week_start']; $this->tracking_mode = $val['tracking_mode']; $this->record_type = $val['record_type']; $this->uncompleted_entries = $val['uncompleted_indicators']; $this->team = $val['team_name']; $this->address = $val['address']; $this->currency = $val['currency']; $this->plugins = $val['plugins']; $this->lock_spec = $val['lock_spec']; $this->workday_hours = $val['workday_hours']; $this->custom_logo = $val['custom_logo']; // Set "on behalf" id and name. if (isset($_SESSION['behalf_id'])) { $this->behalf_id = $_SESSION['behalf_id']; $this->behalf_name = $_SESSION['behalf_name']; } // Set user rights. if ($this->role == ROLE_USER) { $this->rights = right_data_entry|right_view_charts|right_view_reports; } elseif ($this->role == ROLE_CLIENT) { $this->rights = right_view_reports|right_view_invoices; // TODO: how about right_view_charts, too? } elseif ($this->role == ROLE_COMANAGER) { $this->rights = right_data_entry|right_view_charts|right_view_reports|right_view_invoices|right_manage_team; } elseif ($this->role == ROLE_MANAGER) { $this->rights = right_data_entry|right_view_charts|right_view_reports|right_view_invoices|right_manage_team|right_assign_roles|right_export_team; } elseif ($this->role == ROLE_SITE_ADMIN) { $this->rights = right_administer_site; } } } // The getActiveUser returns user id on behalf of whom current user is operating. function getActiveUser() { return ($this->behalf_id ? $this->behalf_id : $this->id); } // isAdmin - determines whether current user is admin (has right_administer_site). function isAdmin() { return (right_administer_site & $this->role); } // isManager - determines whether current user is team manager. function isManager() { return (ROLE_MANAGER == $this->role); } // isCoManager - determines whether current user is team comanager. function isCoManager() { return (ROLE_COMANAGER == $this->role); } // isClient - determines whether current user is a client. function isClient() { return (ROLE_CLIENT == $this->role); } // canManageTeam - determines whether current user is manager or co-manager. function canManageTeam() { return (right_manage_team & $this->role); } // isPluginEnabled checks whether a plugin is enabled for user. function isPluginEnabled($plugin) { return in_array($plugin, explode(',', $this->plugins)); } // getAssignedProjects - returns an array of assigned projects. function getAssignedProjects() { $result = array(); $mdb2 = getConnection(); // Do a query with inner join to get assigned projects. $sql = "select p.id, p.name, p.description, p.tasks, upb.rate from tt_projects p inner join tt_user_project_binds upb on (upb.user_id = ".$this->getActiveUser()." and upb.project_id = p.id and upb.status = 1) where p.team_id = $this->team_id and p.status = 1 order by p.name"; $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { while ($val = $res->fetchRow()) { $result[] = $val; } } return $result; } // isDateLocked checks whether a specifc date is locked for modifications. function isDateLocked($date) { if ($this->isPluginEnabled('lk') && $this->lock_spec) { // Override for managers. if ($this->canManageTeam()) return false; require_once(LIBRARY_DIR.'/tdcron/class.tdcron.php'); require_once(LIBRARY_DIR.'/tdcron/class.tdcron.entry.php'); // Calculate the last occurrence of a lock. $last = tdCron::getLastOccurrence($this->lock_spec, mktime()); $lockdate = new DateAndTime(DB_DATEFORMAT, strftime('%Y-%m-%d', $last)); if ($date->before($lockdate)) { return true; } } return false; } }