Commit ac438589252819480045427e1452f56699059424

Authored by michael
1 parent ac1f2ab6

(#2959) tidied and added function to update group search permission entries for …

…a new user in a group


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@2725 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing 1 changed file with 50 additions and 44 deletions
lib/groups/GroupUserLink.inc
@@ -99,31 +99,27 @@ class GroupUserLink { @@ -99,31 +99,27 @@ class GroupUserLink {
99 function create() { 99 function create() {
100 global $default, $lang_err_database, $lang_err_object_exists; 100 global $default, $lang_err_database, $lang_err_object_exists;
101 //if the object hasn't been created 101 //if the object hasn't been created
102 - if ($this->iId < 0)  
103 - { 102 + if ($this->iId < 0) {
104 $sql = $default->db; 103 $sql = $default->db;
105 $query = "SELECT user_id, group_id FROM ". $default->users_groups_table ." WHERE user_id = '" . $this->iUserID . "' and group_id = '". $this->iGroupID ."'"; 104 $query = "SELECT user_id, group_id FROM ". $default->users_groups_table ." WHERE user_id = '" . $this->iUserID . "' and group_id = '". $this->iGroupID ."'";
106 $sql->query($query); 105 $sql->query($query);
107 $rows = $sql->num_rows($sql); 106 $rows = $sql->num_rows($sql);
108 107
109 - if ($rows > 0)  
110 - {  
111 - // duplicate username  
112 - $_SESSION["errorMessage"] = "GroupUserLink::The id " . $this->iUnitID . " already exists!";  
113 - return false;  
114 - }  
115 - else  
116 - {  
117 - $sql = $default->db;  
118 - $result = $sql->query("INSERT INTO " . $default->users_groups_table . " (group_id, user_id) VALUES ($this->iGroupID, $this->iUserID)");  
119 - if ($result) {  
120 - $this->iId = $sql->insert_id();  
121 - return true;  
122 - }  
123 - $_SESSION["errorMessage"] = $lang_err_database;  
124 - return false; 108 + if ($rows > 0){
  109 + // duplicate username
  110 + $_SESSION["errorMessage"] = "GroupUserLink::The id " . $this->iUnitID . " already exists!";
  111 + return false;
  112 + } else {
  113 + $sql = $default->db;
  114 + $result = $sql->query("INSERT INTO " . $default->users_groups_table . " (group_id, user_id) VALUES ($this->iGroupID, $this->iUserID)");
  115 + if ($result) {
  116 + $this->iId = $sql->insert_id();
  117 + return true;
  118 + }
  119 + $_SESSION["errorMessage"] = $lang_err_database;
  120 + return false;
  121 + }
125 } 122 }
126 - }  
127 $_SESSION["errorMessage"] = $lang_err_object_exists . "id = " . $this->iId . " table = $default->users_groups_table"; 123 $_SESSION["errorMessage"] = $lang_err_object_exists . "id = " . $this->iId . " table = $default->users_groups_table";
128 return false; 124 return false;
129 } 125 }
@@ -197,7 +193,7 @@ class GroupUserLink { @@ -197,7 +193,7 @@ class GroupUserLink {
197 return false; 193 return false;
198 } 194 }
199 195
200 -/** 196 + /**
201 * Static function 197 * Static function
202 * Get a list of web documents 198 * Get a list of web documents
203 * 199 *
@@ -224,6 +220,29 @@ class GroupUserLink { @@ -224,6 +220,29 @@ class GroupUserLink {
224 return false; 220 return false;
225 } 221 }
226 222
  223 + /**
  224 + * Updates the search permissions for a group
  225 + */
  226 + function updateSearchPermissions() {
  227 + global $default;
  228 + // group permissions
  229 + $sGroupPerms = "INSERT INTO $default->search_permissions_table (user_id, document_id) " .
  230 + "SELECT UGL.user_id AS user_id, D.id AS document_id " .
  231 + "FROM $default->documents_table AS D INNER JOIN folders AS F ON D.folder_id = F.id " .
  232 + "INNER JOIN $default->groups_folders_table AS GFL ON GFL.folder_id = F.id " .
  233 + "INNER JOIN $default->users_groups_table AS UGL ON UGL.group_id = GFL.group_id " .
  234 + "WHERE GFL.group_id=$this->iGroupID";
  235 + $default->log->info("GroupUserLink groupPerms=$sGroupPerms");
  236 + $sql = $default->db;
  237 + if ($sql->query($sGroupPerms)) {
  238 + $default->log->debug("groupPerms succeeded");
  239 + return true;
  240 + } else {
  241 + $default->log->error("groupPerms failed");
  242 + return false;
  243 + }
  244 + }
  245 +
227 function getGroups($iUserID) { 246 function getGroups($iUserID) {
228 global $default, $lang_err_database; 247 global $default, $lang_err_database;
229 $aGroupUserLink; 248 $aGroupUserLink;
@@ -242,56 +261,43 @@ class GroupUserLink { @@ -242,56 +261,43 @@ class GroupUserLink {
242 $_SESSION["errorMessage"] = $lang_err_database; 261 $_SESSION["errorMessage"] = $lang_err_database;
243 return false; 262 return false;
244 } 263 }
245 - /* 264 +
  265 + /**
246 * static function 266 * static function
247 - *  
248 * test to see if group exists already 267 * test to see if group exists already
249 * 268 *
250 * @param false or a value 269 * @param false or a value
251 - *  
252 */ 270 */
253 -  
254 - function userBelongsToGroup($iUserID)  
255 - {  
256 - global $default;  
257 -  
258 - $value = lookupField("$default->users_groups_table", "group_id", "user_id", $iUserID );  
259 -  
260 - return $value;  
261 - 271 + function userBelongsToGroup($iUserID){
  272 + global $default;
  273 + $value = lookupField("$default->users_groups_table", "group_id", "user_id", $iUserID );
  274 + return $value;
262 } 275 }
263 276
264 - /* 277 + /**
265 * static function 278 * static function
266 - *  
267 * sets the id of the groupunit using their groupid 279 * sets the id of the groupunit using their groupid
268 * 280 *
269 * @param String 281 * @param String
270 * The unit_ID 282 * The unit_ID
271 - *  
272 */ 283 */
273 284
274 - function setUserGroupID($iGroupId, $iUserId)  
275 - { 285 + function setUserGroupID($iGroupId, $iUserId) {
276 global $default; 286 global $default;
277 $sql = $default->db; 287 $sql = $default->db;
278 $result = $sql->query("SELECT id FROM $default->users_groups_table WHERE user_id = $iUserId and group_id = $iGroupId"); 288 $result = $sql->query("SELECT id FROM $default->users_groups_table WHERE user_id = $iUserId and group_id = $iGroupId");
279 if ($result) { 289 if ($result) {
280 if ($sql->next_record()) { 290 if ($sql->next_record()) {
281 $id = $sql->f("id"); 291 $id = $sql->f("id");
282 -  
283 - }else{ 292 + } else{
284 $_SESSION["errorMessage"] = $lang_err_database; 293 $_SESSION["errorMessage"] = $lang_err_database;
285 return false; 294 return false;
286 } 295 }
287 -  
288 - }else{ 296 + } else{
289 $_SESSION["errorMessage"] = $lang_err_database; 297 $_SESSION["errorMessage"] = $lang_err_database;
290 return false; 298 return false;
291 } 299 }
292 -  
293 $this->iId = $id; 300 $this->iId = $id;
294 -  
295 } 301 }
296 } 302 }
297 -?> 303 -?>
  304 +?>
298 \ No newline at end of file 305 \ No newline at end of file