Commit 64236bf1ede867b481d8596fd1fae9471d845f3b

Authored by mukhtar
1 parent 7efb36d7

for user group removal


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@1237 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/groups/Group.inc
... ... @@ -35,6 +35,10 @@ class Group {
35 35 $this->bIsUnitAdmin = $bNewValue;
36 36 }
37 37  
  38 + function setID($iNewValue) {
  39 + $this->iId = $iNewValue;
  40 + }
  41 +
38 42 function getSysAdmin() {
39 43 return $this->bIsSysAdmin;
40 44 }
... ...
lib/groups/GroupUserLink.inc
... ... @@ -84,16 +84,31 @@ class GroupUserLink {
84 84 function create() {
85 85 global $default, $lang_err_database, $lang_err_object_exists;
86 86 //if the object hasn't been created
87   - if ($this->iId < 0) {
  87 + if ($this->iId < 0)
  88 + {
88 89 $sql = $default->db;
89   - $result = $sql->query("INSERT INTO " . $default->owl_users_groups_table . " (group_id, user_id) VALUES ($this->iGroupID, $this->iUserID)");
90   - if ($result) {
91   - $this->iId = $sql->insert_id();
92   - return true;
  90 + $query = "SELECT user_id, group_id FROM ". $default->owl_users_groups_table ." WHERE user_id = '" . $this->iUserID . "' and group_id = '". $this->iGroupID ."'";
  91 + $sql->query($query);
  92 + $rows = $sql->num_rows($sql);
  93 +
  94 + if ($rows > 0)
  95 + {
  96 + // duplicate username
  97 + $_SESSION["errorMessage"] = "GroupUserLink::The id " . $this->iUnitID . " already exists!";
  98 + return false;
  99 + }
  100 + else
  101 + {
  102 + $sql = $default->db;
  103 + $result = $sql->query("INSERT INTO " . $default->owl_users_groups_table . " (group_id, user_id) VALUES ($this->iGroupID, $this->iUserID)");
  104 + if ($result) {
  105 + $this->iId = $sql->insert_id();
  106 + return true;
93 107 }
94 108 $_SESSION["errorMessage"] = $lang_err_database;
95 109 return false;
96 110 }
  111 + }
97 112 $_SESSION["errorMessage"] = $lang_err_object_exists . "id = " . $this->iId . " table = $default->owl_users_groups_table";
98 113 return false;
99 114 }
... ... @@ -194,5 +209,60 @@ class GroupUserLink {
194 209 return false;
195 210 }
196 211  
  212 + function getGroups($iUserID) {
  213 + global $default, $lang_err_database;
  214 + $aGroupUserLink;
  215 + settype($aGroupUserLink, "array");
  216 + $sql = $default->db;
  217 + $result = $sql->query("SELECT group_id FROM " . $default->owl_users_groups_table . " Where user_id = ". $iUserID);
  218 + if ($result) {
  219 + $iCount = 0;
  220 + while ($sql->next_record()) {
  221 + //$oGroupUserLink = & GroupUserLink::get($sql->f("id"));
  222 + $aGroupUserLink[$iCount] = $sql->f("group_id");
  223 + $iCount++;
  224 + }
  225 + return $aGroupUserLink;
  226 + }
  227 + $_SESSION["errorMessage"] = $lang_err_database;
  228 + return false;
  229 + }
  230 + /*
  231 + * static function
  232 + *
  233 + * test to see if group exists already
  234 + *
  235 + * @param false or a value
  236 + *
  237 + */
  238 +
  239 + function userBelongsToGroup($iUserID)
  240 + {
  241 + global $default;
  242 +
  243 + $value = lookupField("$default->owl_users_groups_table", "group_id", "user_id", $iUserID );
  244 +
  245 + return $value;
  246 +
  247 + }
  248 +
  249 + /*
  250 + * static function
  251 + *
  252 + * sets the id of the groupunit using their groupid
  253 + *
  254 + * @param String
  255 + * The unit_ID
  256 + *
  257 + */
  258 +
  259 + function setUserGroupID($iUserId)
  260 + {
  261 + global $default;
  262 +
  263 + $id = lookupID($default->owl_users_groups_table, "user_id", $iUserId);
  264 +
  265 + $this->iId= $id;
  266 + }
197 267 }
198 268 ?>
... ...