[CS-Project-svn_notify] SF.net SVN: cs-project: [777] trunk/lib/adminUserClass.php
Brought to you by:
crazedsanity
From: <cra...@us...> - 2008-02-04 23:12:46
|
Revision: 777 http://cs-project.svn.sourceforge.net/cs-project/?rev=777&view=rev Author: crazedsanity Date: 2008-02-04 15:12:12 -0800 (Mon, 04 Feb 2008) Log Message: ----------- Fix problem with users being attached multiple times to same group (issue #143). /lib/adminUserClass.php: * add_user_to_group(): -- pulls users from that group; if user is already in the list, no insert is performed. Modified Paths: -------------- trunk/lib/adminUserClass.php Modified: trunk/lib/adminUserClass.php =================================================================== --- trunk/lib/adminUserClass.php 2008-02-04 21:34:56 UTC (rev 776) +++ trunk/lib/adminUserClass.php 2008-02-04 23:12:12 UTC (rev 777) @@ -213,29 +213,34 @@ //========================================================================= public function add_user_to_group($uid,$groupId) { - //add the user to a group. - $sqlArr = array( - 'uid' => $uid, - 'group_id' => $groupId - ); - $sql = "INSERT INTO user_group_table ". string_from_array($sqlArr, 'insert', NULL, 'number'); - if(!$this->run_sql($sql)) { - //indications are it failed. - if(strlen($this->lastError)) { - $this->logsObj->log_dberror(__METHOD__ .": failed to add user to group (". $groupId ."): ". $this->lastError); + $groupData = $this->get_group_user($groupId); + $retval = FALSE; + if(!isset($groupData[$uid])) { + //add the user to a group. + $sqlArr = array( + 'uid' => $uid, + 'group_id' => $groupId + ); + + $sql = "INSERT INTO user_group_table ". string_from_array($sqlArr, 'insert', NULL, 'number'); + if(!$this->run_sql($sql)) { + //indications are it failed. + if(strlen($this->lastError)) { + $this->logsObj->log_dberror(__METHOD__ .": failed to add user to group (". $groupId ."): ". $this->lastError); + } + $retval = FALSE; } - $retval = FALSE; + else { + //it worked! + $retval = TRUE; + + //log it! + $groupData = $this->get_groups(FALSE); + $details = "Added user to group #". $groupId ." (". $groupData[$groupId]['name'] .")"; + $this->logsObj->log_by_class($details, 'update', $uid); + } } - else { - //it worked! - $retval = TRUE; - - //log it! - $groupData = $this->get_groups(FALSE); - $details = "Added user to group #". $groupId ." (". $groupData[$groupId]['name'] .")"; - $this->logsObj->log_by_class($details, 'update', $uid); - } return($retval); }//end add_user_to_group() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |