/** * Fetch an account * * @param integer $id the account id to fetch * @param boolean $use_cache read the record from the cache, should (just about) always be true * * @return object the account as a phpgw_account derived object */ public function get($id, $use_cache = true) { $id = (int) $id; $account = null; static $cache = array(); if (isset($cache[$id])) { return $cache[$id]; } if ($use_cache) { $account = phpgwapi_cache::system_get('phpgwapi', "account_{$id}"); if (is_object($account)) { return $account; } } $this->db->query("SELECT * FROM phpgw_accounts WHERE account_id = {$id}", __LINE__, __FILE__); if ($this->db->next_record()) { $record = array('id' => $this->db->f('account_id'), 'lid' => $this->db->f('account_lid'), 'passwd_hash' => $this->db->f('account_pwd', true), 'firstname' => $this->db->f('account_firstname', true), 'lastname' => $this->db->f('account_lastname', true), 'last_login' => $this->db->f('account_lastlogin'), 'last_login_from' => $this->db->f('account_lastloginfrom'), 'last_passwd_change' => $this->db->f('account_lastpwd_change'), 'enabled' => $this->db->f('account_status') == 'A', 'expires' => $this->db->f('account_expires'), 'person_id' => $this->db->f('person_id'), 'quota' => $this->db->f('account_quota'), 'type' => $this->db->f('account_type')); if ($this->db->f('account_type') == 'g') { $account = new phpgwapi_group(); } else { $account = new phpgwapi_user(); } $account->init($record); phpgwapi_cache::system_set('phpgwapi', "account_{$id}", $account); } $cache[$id] = $account; return $account; }
/** * Update the account data * * @param array $data the account data to use * * @return object the account * * @internal does not write it to the storage backend */ public function update_data($data) { if ($this->get_type($data->id) == 'g') { $account = new phpgwapi_group(); } else { $account = new phpgwapi_user(); } $account->init($data); $this->account = $account; return $this->account; }
public function get($id, $use_cache = true) { $id = (int) $id; $account = null; if (!$id) { return null; } if ($use_cache) { $account = phpgwapi_cache::system_get('phpgwapi', "account_{$id}"); if (is_object($account)) { return $account; } } $acct_type = $this->get_type($id); /* search the dn for the given uid */ if ($acct_type == phpgwapi_account::TYPE_GROUP && $this->group_context) { $sri = ldap_search($this->ds, $this->group_context, "gidnumber={$id}"); } else { if ($acct_type == phpgwapi_account::TYPE_USER && $this->user_context) { $sri = ldap_search($this->ds, $this->user_context, "uidnumber={$id}"); } else { throw new Exception('Invalid account requested'); } } $entries = ldap_get_entries($this->ds, $sri); // first in best dressed - we can't tell which one is the correct one $entry = $entries[0]; unset($entries); $record = array(); /* Now dump it into the array; take first entry found */ if (isset($entry['phpgwcontactid'])) { $record['person_id'] = $entry['phpgwcontactid'][0]; } $record['dn'] = $entry['dn']; $record['fullname'] = $entry['cn'][0]; if ($acct_type == 'g') { $record['id'] = $entry['gidnumber'][0]; $record['lid'] = $entry['cn'][0]; $record['firstname'] = $entry['cn'][0]; $record['lastname'] = lang('group'); $record['type'] = 'g'; $account = new phpgwapi_group(); } else { $record['id'] = $entry['uidnumber'][0]; $record['lid'] = $entry['uid'][0]; $record['firstname'] = isset($entry['givenname']) && isset($entry['givenname'][0]) ? $entry['givenname'][0] : ''; $record['lastname'] = isset($entry['sn']) && isset($entry['sn'][0]) ? $entry['sn'][0] : ''; $record['expires'] = $record['account_expires'] = $entry['phpgwaccountexpires'][0]; // $record['homedirectory'] = isset($entry['homedirectory']) ? $entry['homedirectory'][0] : self::FALLBACK_HOMEDIRECTORY; // $record['loginshell'] = isset($entry['loginshell']) ? $entry['loginshell'][0] : self::FALLBACK_LOGINSHELL; $record['enabled'] = isset($entry['phpgwaccountstatus']) && $entry['phpgwaccountstatus'][0] == 'A' ? true : false; $record['type'] = 'u'; if (!isset($entry['phpgwquota']) || $entry['phpgwquota'] === '') { $record['quota'] = $this->quota; // set to 0 by default } else { $record['quota'] = $entry['phpgwquota'][0]; } $account = new phpgwapi_user(); } $account->init($record); phpgwapi_cache::system_set('phpgwapi', "account_{$id}", $account); return $account; }