From: <jhe...@us...> - 2002-08-05 08:15:27
|
Update of /cvsroot/upcase-project/UpCase/lib In directory usw-pr-cvs1:/tmp/cvs-serv28948 Modified Files: uc_accounts.php Log Message: Added some methods to user object, added global function to create a user in the db and one to retrieve groups from the db. Index: uc_accounts.php =================================================================== RCS file: /cvsroot/upcase-project/UpCase/lib/uc_accounts.php,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** uc_accounts.php 17 Jul 2002 10:58:25 -0000 1.2 --- uc_accounts.php 5 Aug 2002 08:15:24 -0000 1.3 *************** *** 10,25 **** var $lang; var $groups; function UcUser() { $this->groups = array(); } } // Fill a user object with data retrieved from the database function getUser($username, $uid) { global $ucsql_userget; - global $ucsql_usergroups; $db = new UcSQL(); --- 10,93 ---- var $lang; var $groups; + var $db; function UcUser() { $this->groups = array(); + $this->db = new UcSql(); } + + function getSecondaryGroups() + { + global $ucsql_usergroups; + $query = sprintf($ucsql_usergroups, $this->uid); + + $res = $this->db->Execute($query) or + die("Unable to get groups: " . $db->ErrorMsg()); + + unset($this->groups); + $this->groups = array(); + + while ($o = $res->FetchNextObject(true)) + $this->groups[] = $o->GID; + return $this->groups; + } + + function setPassword($passwd) + { + global $ucsql_usersetpw; + + $query = sprintf($ucsql_usersetpw, $passwd, $this->uid); + $this->db->Execute($query) or die("Unable to set user password: " + . $this->db->ErrorMsg()); + } + + function setLanguage($lang) + { + global $ucsql_usersetlang; + + $query = sprintf($ucsql_usersetlang, $lang, $this->uid); + $this->db->Execute($query) or die("Unable to set user lang: " + . $this->db->ErrorMsg()); + + $this->lang = $lang; + } + + function setPrimaryGroup($gid) + { + global $ucsql_usersetgid; + + $query = sprintf($ucsql_usersetgid, $gid, $this->uid); + $res = $this->db->Execute($query) + or die("Unable to set user primary group: " + . $this->db->ErrorMsg()); + $this->gid = $gid; + } + + function setSecondaryGroups($gids) + { + global $ucsql_memberrm; + global $ucsql_memberadd; + + $query = sprintf($ucsql_memberrm, $this->uid); + $this->db->Execute($query) or die("Unable to reset user memberships: " + . $this->db->ErrorMsg()); + foreach ($gids as $gid) + { + $query = sprintf($ucsql_memberadd, $gid,$this->uid); + $this->db->Execute($query) or die("Unable to add membership: " + . $thid->db->ErrorMsg()); + } + + $this->groups = $gids; + } + } + // Fill a user object with data retrieved from the database function getUser($username, $uid) { global $ucsql_userget; $db = new UcSQL(); *************** *** 31,34 **** --- 99,103 ---- if ($res->RecordCount() != 1) { + print("FOUND: " . $res->RecordCount() . "<br>"); die("Problem with your database: more than one user with same uid"); } *************** *** 40,61 **** $user->uid = $o->UID; $user->gid = $o->GROUPID; - $user->gidname = $o->GIDNAME; $user->lang = $o->PREFERRED_LANG; ! ! // groups ! $query = sprintf($ucsql_usergroups, $user->uid); ! $res = $db->Execute($query) or ! die("Unable to get groups: " . $db->ErrorMsg()); ! ! while (!$res->EOF) ! { ! $user->groups[$res->fields[0]] = $res->fields[1]; ! $res->MoveNext(); ! } return $user; } ?> --- 109,148 ---- $user->uid = $o->UID; $user->gid = $o->GROUPID; $user->lang = $o->PREFERRED_LANG; ! $user->groups = $user->getSecondaryGroups(); return $user; } + // Create a new user in the database + function createUser($username) + { + global $ucsql_useradd; + global $ucsql_userget; + + $db = new UcSql(); + $query = sprintf($ucsql_useradd, $username); + $db->Execute($query) or die("Unable to create new user: " + . $db->ErrorMsg()); + + return getUser($username, ''); + } + + + function getAllGroups() + { + global $ucsql_allgroups; + $db = new UcSql(); + $query = $ucsql_allgroups; + $res = $db->Execute($query) or die("Unable to get group list: " + . $db->ErrorMsg()); + $groups = array(); + while ($o = $res->FetchNextObject(TRUE)) + { + $groups[$o->GID] = $o->GROUPNAME; + } + return $groups; + } ?> |