From 64236bf1ede867b481d8596fd1fae9471d845f3b Mon Sep 17 00:00:00 2001 From: mukhtar Date: Fri, 28 Feb 2003 16:47:20 +0000 Subject: [PATCH] for user group removal --- lib/groups/Group.inc | 4 ++++ lib/groups/GroupUserLink.inc | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 79 insertions(+), 5 deletions(-) diff --git a/lib/groups/Group.inc b/lib/groups/Group.inc index aff8f46..b9fd8ab 100644 --- a/lib/groups/Group.inc +++ b/lib/groups/Group.inc @@ -35,6 +35,10 @@ class Group { $this->bIsUnitAdmin = $bNewValue; } + function setID($iNewValue) { + $this->iId = $iNewValue; + } + function getSysAdmin() { return $this->bIsSysAdmin; } diff --git a/lib/groups/GroupUserLink.inc b/lib/groups/GroupUserLink.inc index 43cd45e..d5e7d0d 100644 --- a/lib/groups/GroupUserLink.inc +++ b/lib/groups/GroupUserLink.inc @@ -84,16 +84,31 @@ class GroupUserLink { function create() { global $default, $lang_err_database, $lang_err_object_exists; //if the object hasn't been created - if ($this->iId < 0) { + if ($this->iId < 0) + { $sql = $default->db; - $result = $sql->query("INSERT INTO " . $default->owl_users_groups_table . " (group_id, user_id) VALUES ($this->iGroupID, $this->iUserID)"); - if ($result) { - $this->iId = $sql->insert_id(); - return true; + $query = "SELECT user_id, group_id FROM ". $default->owl_users_groups_table ." WHERE user_id = '" . $this->iUserID . "' and group_id = '". $this->iGroupID ."'"; + $sql->query($query); + $rows = $sql->num_rows($sql); + + if ($rows > 0) + { + // duplicate username + $_SESSION["errorMessage"] = "GroupUserLink::The id " . $this->iUnitID . " already exists!"; + return false; + } + else + { + $sql = $default->db; + $result = $sql->query("INSERT INTO " . $default->owl_users_groups_table . " (group_id, user_id) VALUES ($this->iGroupID, $this->iUserID)"); + if ($result) { + $this->iId = $sql->insert_id(); + return true; } $_SESSION["errorMessage"] = $lang_err_database; return false; } + } $_SESSION["errorMessage"] = $lang_err_object_exists . "id = " . $this->iId . " table = $default->owl_users_groups_table"; return false; } @@ -194,5 +209,60 @@ class GroupUserLink { return false; } + function getGroups($iUserID) { + global $default, $lang_err_database; + $aGroupUserLink; + settype($aGroupUserLink, "array"); + $sql = $default->db; + $result = $sql->query("SELECT group_id FROM " . $default->owl_users_groups_table . " Where user_id = ". $iUserID); + if ($result) { + $iCount = 0; + while ($sql->next_record()) { + //$oGroupUserLink = & GroupUserLink::get($sql->f("id")); + $aGroupUserLink[$iCount] = $sql->f("group_id"); + $iCount++; + } + return $aGroupUserLink; + } + $_SESSION["errorMessage"] = $lang_err_database; + return false; + } + /* + * static function + * + * test to see if group exists already + * + * @param false or a value + * + */ + + function userBelongsToGroup($iUserID) + { + global $default; + + $value = lookupField("$default->owl_users_groups_table", "group_id", "user_id", $iUserID ); + + return $value; + + } + + /* + * static function + * + * sets the id of the groupunit using their groupid + * + * @param String + * The unit_ID + * + */ + + function setUserGroupID($iUserId) + { + global $default; + + $id = lookupID($default->owl_users_groups_table, "user_id", $iUserId); + + $this->iId= $id; + } } ?> -- libgit2 0.21.4