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->legacy_role = $val['role']; $this->role_id = $val['role_id']; $this->rights = explode(',', $val['rights']); $this->is_client = !in_array('track_own_time', $this->rights); $this->rank = $val['rank']; // Downgrade rank to legacy ROLE_MANAGER rank, until we have sub-groups implemented. if ($this->rank > ROLE_MANAGER) $this->rank = ROLE_MANAGER; $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->project_required = $val['project_required']; $this->task_required = $val['task_required']; $this->record_type = $val['record_type']; $this->bcc_email = $val['bcc_email']; $this->team = $val['team_name']; $this->currency = $val['currency']; $this->plugins = $val['plugins']; $this->lock_spec = $val['lock_spec']; $this->workday_minutes = $val['workday_minutes']; $this->custom_logo = $val['custom_logo']; $this->config = $val['config']; $config_array = explode(',', $this->config); // Set user config options. $this->show_holidays = in_array('show_holidays', $config_array); $this->punch_mode = in_array('punch_mode', $config_array); $this->allow_overlap = in_array('allow_overlap', $config_array); $this->future_entries = in_array('future_entries', $config_array); $this->uncompleted_indicators = in_array('uncompleted_indicators', $config_array); // Set "on behalf" id and name. if (isset($_SESSION['behalf_id'])) { $this->behalf_id = $_SESSION['behalf_id']; $this->behalf_name = $_SESSION['behalf_name']; } } } // The getActiveUser returns user id on behalf of whom the current user is operating. function getActiveUser() { return ($this->behalf_id ? $this->behalf_id : $this->id); } // can - determines whether user has a right to do something. function can($do_something) { return in_array($do_something, $this->rights); } // isAdmin - determines whether current user is admin (has right_administer_site). function isAdmin() { return $this->can('administer_site'); } // isManager - determines whether current user is team manager. // This is a legacy function that we are getting rid of by replacing with rights check. function isManager() { return $this->can('export_data'); // By default this is assigned to managers but not co-managers. // Which is sufficient for now until we refactor all calls // to this function and then remove it. } // isCoManager - determines whether current user is team comanager. // This is a legacy function that we are getting rid of by replacing with rights check. function isCoManager() { return ($this->can('manage_users') && !$this->can('export_data')); } // isClient - determines whether current user is a client. function isClient() { return $this->is_client; } // canManageTeam - determines whether current user is manager or co-manager. // This is a legacy function that we are getting rid of by replacing with rights check. function canManageTeam() { return $this->can('manage_users'); // By default this is assigned to co-managers (an managers). // Which is sufficient for now until we refactor all calls // to this function and then remove it. } // 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. if ($this->can('override_date_lock')) 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, time()); $lockdate = new DateAndTime(DB_DATEFORMAT, strftime('%Y-%m-%d', $last)); if ($date->before($lockdate)) { return true; } } return false; } }