Esempio n. 1
0
 /**
  * Loads a user by username.
  *
  * @param mixed $username Username to load
  * @param mixed $password Password to check against
  * @param mixed $activeonly Only load the user if they are active
  * @param mixed $adminaccessonly Only load the user if they have admin access
  *
  * @returns mixed If successful, the filled User object.  If it fails, it returns false.
  * @since 0.6.1
  */
 function &LoadUserByUsername($username, $password = '', $activeonly = true, $adminaccessonly = false)
 {
     $result = false;
     global $gCms;
     $db =& $gCms->GetDb();
     $params = array();
     $where = array();
     $joins = array();
     $query = "SELECT u.user_id FROM " . cms_db_prefix() . "users u";
     $where[] = 'username = ?';
     $params[] = $username;
     if ($password != '') {
         $where[] = 'password = ?';
         $params[] = md5($password);
     }
     if ($activeonly == true) {
         $joins[] = cms_db_prefix() . "user_groups ug ON u.user_id = ug.user_id";
         //$joins[] = cms_db_prefix()."groups g ON ug.group_id = g.group_id";
         $where[] = "u.active = 1";
         //$where[] = "g.active = 1";
     }
     if ($adminaccessonly == true) {
         $where[] = "admin_access = 1";
     }
     if (!empty($joins)) {
         $query .= ' LEFT JOIN ' . implode(' LEFT JOIN ', $joins);
     }
     if (!empty($where)) {
         $query .= ' WHERE ' . implode(' AND ', $where);
     }
     $id = $db->GetOne($query, $params);
     if ($id) {
         $result =& UserOperations::LoadUserByID($id);
     }
     return $result;
 }
 /**
  * Get the username of the currently logged in admin user.
  *
  * @deprecated
  * @param int $uid
  * @return string
  */
 function GetAdminUsername($uid)
 {
     $user = UserOperations::LoadUserByID($uid);
     return $user->username;
 }