コード例 #1
0
ファイル: User.php プロジェクト: sebbie42/casebox
 /**
  * get profile data for a user.
  * This function receives userId as param because
  * user profile data can be edited by another user (owner).
  */
 public function getProfileData($userId = false)
 {
     if (!$this->isVerified()) {
         return array('success' => false, 'verify' => true);
     }
     if ($userId === false) {
         $userId = static::getId();
     }
     if (!Security::canEditUser($userId)) {
         throw new \Exception(L\get('Access_denied'));
     }
     $rez = array();
     $languageSettings = Config::get('language_settings');
     $r = $this->getPreferences($userId);
     if (!empty($r)) {
         $cfg = $r['cfg'];
         unset($r['cfg']);
         $language_index = empty($r['language_id']) ? Config::get('user_language_index') - 1 : $r['language_id'] - 1;
         $r['language'] = Config::get('languages')[$language_index];
         $r['long_date_format'] = empty($cfg['long_date_format']) ? $languageSettings[$r['language']]['long_date_format'] : $cfg['long_date_format'];
         $r['short_date_format'] = empty($cfg['short_date_format']) ? $languageSettings[$r['language']]['short_date_format'] : $cfg['short_date_format'];
         if (!empty($cfg['country_code'])) {
             $r['country_code'] = $cfg['country_code'];
         }
         if (!empty($cfg['phone'])) {
             $r['phone'] = $cfg['phone'];
         }
         if (!empty($cfg['timezone'])) {
             $r['timezone'] = $cfg['timezone'];
         }
         if (!empty($cfg['canAddUsers'])) {
             $r['canAddUsers'] = $cfg['canAddUsers'];
         }
         if (!empty($cfg['canAddGroups'])) {
             $r['canAddGroups'] = $cfg['canAddGroups'];
         }
         $r['template_id'] = User::getTemplateId();
         $rez = $r;
     }
     //get possible associated objects for display in grid
     if (!empty($rez['data'])) {
         $assocObjects = Objects::getAssociatedObjects(array('template_id' => $rez['template_id'], 'data' => $rez['data']));
         if (!empty($assocObjects['data'])) {
             $rez['assocObjects'] = $assocObjects['data'];
         }
     }
     $rez['success'] = true;
     return $rez;
 }
コード例 #2
0
 /**
  * Retreive user details data to be displayed in user details window
  */
 public function getUserData($p)
 {
     if (!User::isVerified()) {
         return array('success' => false, 'verify' => true);
     }
     if ($_SESSION['user']['id'] != $p['data']['id'] && !Security::canManage()) {
         throw new \Exception(L\get('Access_denied'));
     }
     $user_id = $p['data']['id'];
     $rez = array('success' => false, 'msg' => L\get('Wrong_id'));
     $res = DB\dbQuery('SELECT id
             ,cid
             ,name
             ,first_name
             ,last_name
             ,sex
             ,email
             ,enabled
             ,data
             ,last_action_time
             ,cdate
             ,cid
         FROM users_groups u
         WHERE id = $1', $user_id) or die(DB\dbQueryError());
     if ($r = $res->fetch_assoc()) {
         $r['title'] = User::getDisplayName($r);
         $r['data'] = Util\toJSONArray($r['data']);
         $r['last_action_time'] = Util\formatMysqlTime($r['last_action_time']);
         $r['cdate'] = Util\formatMysqlTime($r['cdate']);
         $r['owner'] = User::getDisplayName($r['cid']);
         $rez = array('success' => true, 'data' => $r);
     }
     $res->close();
     if ($rez['success'] == false) {
         throw new \Exception(L\get('Wrong_id'));
     }
     $rez['data']['template_id'] = User::getTemplateId();
     return $rez;
 }