http://www.fsf.org/ or write * to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. * */ /* GROUPS HANDLING */ /** * cmsdAm group handling class. * This is the group class, if you need to do users group operations you'll find here all you need, * ... :-)

* Class instance: $cms->groups * @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net> */ class cmsdam_groups { /** * You should not use this variable from your section. * @access private */ var $dbms; /** * You should not use this variable from your section. * @access private */ var $users; /** * You should not use this variable from your section. * @access private */ var $ldap; /** * You should not use this variable from your section. * @access private */ var $logs; /** * You should not use this variable from your section. * @access private */ var $debug; /** * Returns an array with all the userIDs in "$group" group. * You can use this method to get all the ID for the users of the group "$group".
* Return false on errors, null on empty groups, array on success.

* NOTE: This method doesn't work with LDAP due to ldap structure. * @param str group The group name you want the users IDs of * @return array Array with all userIDs * @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net> */ function group_users_id($group) { // Returns an array with all the userids in "$group" group // WARNING: This method doesn't work with LDAP $useldap = $this->ldap->ldap_ldapconnect(); if ($useldap != false) { // We can use LDAP, ready to begin $this->ldap->ldap_not_implemented("group_users_id"); return false; } if ($this->dbms->db_connected != 1) { // DB not connected $this->debug->debug_write(4, "DATABASE connection to server failed, givin' up!!"); $this->logs->log_note(4, "DATABASE connection to server failed, givin' up!!"); } else { // We are connected to the DB // Try to get data from the groups table $query = "select cmsdam_users_id from " . $this->dbms->DB_tbl_prefix . "groups where group_name = \"$group\""; if ($this->dbms->dbquery($query) == false) { // DB error return false; } else { // Users returned if ($this->dbms->dbnum_rows() > 0) { // There are users in the table for ($rows = 0; $rows < $this->dbms->dbnum_rows(); $rows++) { // Getting data from the database $data = $this->dbms->dbfetch_row(); // Building the array $rows_arr[$rows] = $data[0]; } return $rows_arr; } return null; } } return false; } /** * Returns an array with all the userNAMESs in "$group" group. * You can use this method to get all the NAMES for the users of the group "$group".
* Return false on errors, null on empty groups, array on success.

* NOTE: This method works correctly with LDAP. * @param str group The group name you want the users NAMES of * @return array Array with all userNAMES * @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net> */ function group_users_name($group) { // Returns an array with all the usernames in "$group" group $useldap = $this->ldap->ldap_ldapconnect(); if ($useldap != false) { // We can use LDAP, ready to begin $rows_arr = $this->ldap->ldap_group_users_name($group); if (count ($rows_arr) > 0) { // LDAP returned something return $rows_arr; } else { return false; } } if ($this->dbms->db_connected != 1) { // DB not connected $this->debug->debug_write(4, "DATABASE connection to server failed, givin' up!!"); $this->logs->log_note(4, "DATABASE connection to server failed, givin' up!!"); } else { // We are connected to the DB // Try to get data from the groups table $query = "select users.user_name from " . $this->dbms->DB_tbl_prefix . "groups as groups, " . $this->dbms->DB_tbl_prefix . "users as users where users.id = groups.cmsdam_users_id and groups.group_name = \"$group\""; if ($this->dbms->dbquery($query) == false) { // DB error return false; } else { // Users returned if ($this->dbms->dbnum_rows() > 0) { // There are users in the table for ($rows = 0; $rows < $this->dbms->dbnum_rows(); $rows++) { // Getting data from the database $data = $this->dbms->dbfetch_row(); // Building the array $rows_arr[$rows] = $data[0]; } return $rows_arr; } return null; } } return false; } /** * Returns an array with all the group NAMES. * You can use this method to get all the group NAMES.
* Return false on errors, array on success.

* NOTE: This method works correctly with LDAP. * @return array Array with all group NAMES * @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net> */ function group_names() { // Returns an array with all the group names $useldap = $this->ldap->ldap_ldapconnect(); if ($useldap != false) { // We can use LDAP, ready to begin $rows_arr = $this->ldap->ldap_group_names(); if (count ($rows_arr) > 0) { // LDAP returned something return $rows_arr; } else { if ($this->conf->LDAP_exclusive == 1) { // We don't want to use DB $this->debug->debug_write(6, "DATABASE connection to server is disabled by configuration option LDAP_exclusive!"); $this->logs->log_note(4, "DATABASE connection to server is disabled by configuration option LDAP_exclusive!"); return false; } else { $this->debug->debug_write(7, "No groups returned by ldap, using DB"); $this->logs->log_note(5, "No groups returned by ldap, using DB"); } } } if ($this->dbms->db_connected != 1) { // DB not connected $this->debug->debug_write(4, "DATABASE connection to server failed, givin' up!!"); $this->logs->log_note(4, "DATABASE connection to server failed, givin' up!!"); } else { // We are connected to the DB // Try to get data from the users table $query = "select distinct group_name from " . $this->dbms->DB_tbl_prefix . "groups order by group_name"; if ($this->dbms->dbquery($query) == false) { // DB error return false; } else { // Users returned if ($this->dbms->dbnum_rows() > 0) { // There are users in the table for ($rows = 0; $rows < $this->dbms->dbnum_rows(); $rows++) { // Getting data from the database $data = $this->dbms->dbfetch_row(); // Building the array $rows_arr[$rows] = $data[0]; } return $rows_arr; } return null; } } return false; } /** * Add the "$username" user to the "$groupname" group, or creates the "$groupname" group with * "$username" user if it does not exists. * Return false on errors, true on success.

* @param str groupname The name of the group. If it does not exists, it will be created * @param str grouptype Reserved for future uses. For now use 1 * @param str username The user to add to the group * @param str groupip The IP address of the people that's using this method * @return bool False on error, True on success * @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net> */ function group_add_user($groupname, $grouptype = "", $username, $groupip = "") { // Add a group with the user $username. $username = trim(htmlspecialchars($username)); $useremail = trim(htmlspecialchars($useremail)); $basedn = $this->ldap->conf->LDAP_basedn; $useldap = $this->ldap->ldap_ldapconnect(); if ($useldap != false) { // We can use LDAP, ready to begin return $this->ldap->ldap_group_add($groupname, $username); } $groupname=trim(htmlspecialchars($groupname)); if ($this->dbms->db_connected != 1) { // DB not connected $this->debug->debug_write(4, "DATABASE connection to server failed, givin' up!!"); $this->logs->log_note(4, "DATABASE connection to server failed, givin' up!!"); } else { // We are connected to the DB // Try to get data from the users table $uid = $this->users->user_id($username); if ($uid == "") { // User does not exist return false; } $query = "select cmsdam_users_id from " . $this->dbms->DB_tbl_prefix . "groups where group_name=\"$groupname\" and cmsdam_users_id=" . $uid; if ($this->dbms->dbquery($query) == true) { // DB OK if ($this->dbms->dbnum_rows() > 0) { // There are users in the table return false; } else { // Good! No users with that name in this group was found!! We can proceed! if (($groupname != "") and ($grouptype != "") and ($groupip != "")) { // All parameters passed $query = "insert into " . $this->dbms->DB_tbl_prefix . "groups (id, group_name, group_type, group_date, cmsdam_users_id, ip) VALUES (NULL, \"$groupname\", $grouptype, now(), $uid, \"$groupip\")"; if ($this->dbms->dbquery($query) == true) { // ! DB error return true; } } } } } return false; } /** * Delete the "$username" user from the "$groupname" group, if this is the last user, the group * will be deleted. * Return false on errors, true on success.

* NOTE: This method doesn't work with LDAP for now. * @param str groupname The name of the group * @param str username The user to delete from the group. If it's the last user delete the group. * @return bool False on error, True on success * @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net> */ function group_del_user($groupname, $username) { // Delete $username from group $groupname. // WARNING: This method doesn't work with LDAP $useldap = $this->ldap->ldap_ldapconnect(); if ($useldap != false) { // We can use LDAP, ready to begin return $this->ldap->ldap_group_del_user($groupname, $username); } // If $username is the last user in that group the group will be removed. $groupname=trim(htmlspecialchars($groupname)); if ($this->dbms->db_connected != 1) { // DB not connected $this->debug->debug_write(4, "DATABASE connection to server failed, givin' up!!"); $this->logs->log_note(4, "DATABASE connection to server failed, givin' up!!"); } else { // We are connected to the DB // Try to get data from the users table $uid = $this->users->user_id($username); if ($uid == "") { // User does not exist return false; } $query = "select cmsdam_users_id from " . $this->dbms->DB_tbl_prefix . "groups where group_name=\"$groupname\" and cmsdam_users_id=" . $uid; if ($this->dbms->dbquery($query) == true) { // ! DB error if (!($this->dbms->dbnum_rows() > 0)) { // There are NO users in the table return false; } else { // Good! Users with that name in this group was found!! We can proceed! if ($groupname != "") { // All parameters passed $query = "delete from " . $this->dbms->DB_tbl_prefix . "groups where group_name=\"$groupname\" and cmsdam_users_id=$uid"; if ($this->dbms->dbquery($query) == true) { // ! DB error return true; } } } } } return false; } /** * Returns the string with the user "$username" subscription date for the "$groupname" group. * You can use this method to get the subscription date for the user "$username" in the * group "$groupname".

* NOTE: This method doesn't work with LDAP for now. * @param str groupname The group name you want the subscription date * @param str username The user name you want the subscription date * @return str Subscription date string for user "$username" into group "$groupname" * @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net> */ function group_date($groupname, $username) { // Returns the user $username subscription date for the group $groupname // WARNING: This method doesn't work with LDAP $useldap = $this->ldap->ldap_ldapconnect(); if ($useldap != false) { // We can use LDAP, ready to begin $this->ldap->ldap_not_implemented("group_date"); return false; } $groupname=trim(htmlspecialchars($groupname)); if ($this->dbms->db_connected != 1) { // DB not connected $this->debug->debug_write(4, "DATABASE connection to server failed, givin' up!!"); $this->logs->log_note(4, "DATABASE connection to server failed, givin' up!!"); } else { // We are connected to the DB // Try to get data from the users table $uid = $this->users->user_id($username); if ($uid == "") { // User does not exist return false; } $query = "select cmsdam_users_id, group_date from " . $this->dbms->DB_tbl_prefix . "groups where group_name=\"$groupname\" and cmsdam_users_id=" . $uid; if ($this->dbms->dbquery($query) == true) { // ! DB error if (!($this->dbms->dbnum_rows() > 0)) { // There are NO users in the table return false; } else { // Good! Users with that name in this group was found!! We can proceed! if ($groupname != "") { // All parameters passed $data = $this->dbms->dbfetch_row(); $groupdata = $data[1]; return $groupdata; } } } } return false; } /** * Returns the user "$username" subscription type for the "$groupname" group. * You can use this method to get the subscription type for the user "$username" in the * group "$groupname".

* NOTE: This method doesn't work with LDAP due to the LDAP structure.
* NOTE: This method is experimental and is reserved for future uses. * @param str groupname The group name you want the subscription type * @param str username The user name you want the subscription type * @return int Subscription type for user "$username" into group "$groupname" * @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net> */ function group_type($groupname, $username) { // Returns the user $username subscription type for the group $groupname // WARNING: This method doesn't work with LDAP $useldap = $this->ldap->ldap_ldapconnect(); if ($useldap != false) { // We can use LDAP, ready to begin $this->ldap->ldap_not_implemented("group_type"); return false; } $groupname=trim(htmlspecialchars($groupname)); if ($this->dbms->db_connected != 1) { // DB not connected $this->debug->debug_write(4, "DATABASE connection to server failed, givin' up!!"); $this->logs->log_note(4, "DATABASE connection to server failed, givin' up!!"); } else { // We are connected to the DB // Try to get data from the users table $uid = $this->users->user_id($username); if ($uid == "") { // User does not exist return false; } $query = "select cmsdam_users_id, group_type from " . $this->dbms->DB_tbl_prefix . "groups where group_name=\"$groupname\" and cmsdam_users_id=" . $uid; if ($this->dbms->dbquery($query) == true) { // ! DB error if (!($this->dbms->dbnum_rows() > 0)) { // There are NO users in the table return false; } else { // Good! Users with that name in this group was found!! We can proceed! if ($groupname != "") { // All parameters passed $data = $this->dbms->dbfetch_row(); $groupdata = $data[1]; return $groupdata; } } } } return false; } /** * Returns the user "$username" subscription IP address for the "$groupname" group. * You can use this method to get the subscription IP address for the user "$username" in the * group "$groupname".

* NOTE: This method doesn't work with LDAP due to the LDAP structure.
* @param str groupname The group name you want the subscription type * @param str username The user name you want the subscription type * @return str Subscription IP address for user "$username" into group "$groupname" * @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net> */ function group_ip($groupname, $username) { // Returns the user $username subscription IP for the group $groupname // WARNING: This method doesn't work with LDAP $useldap = $this->ldap->ldap_ldapconnect(); if ($useldap != false) { // We can use LDAP, ready to begin $this->ldap->ldap_not_implemented("group_ip"); return false; } $groupname=trim(htmlspecialchars($groupname)); if ($this->dbms->db_connected != 1) { // DB not connected $this->debug->debug_write(4, "DATABASE connection to server failed, givin' up!!"); $this->logs->log_note(4, "DATABASE connection to server failed, givin' up!!"); } else { // We are connected to the DB // Try to get data from the users table $uid = $this->users->user_id($username); if ($uid == "") { // User does not exist return false; } $query = "select cmsdam_users_id, ip from " . $this->dbms->DB_tbl_prefix . "groups where group_name=\"$groupname\" and cmsdam_users_id=" . $uid; if ($this->dbms->dbquery($query) == true) { // ! DB error if (!($this->dbms->dbnum_rows() > 0)) { // There are NO users in the table return false; } else { // Good! Users with that name in this group was found!! We can proceed! if ($groupname != "") { // All parameters passed $data = $this->dbms->dbfetch_row(); $groupdata = $data[1]; return $groupdata; } } } } return false; } } ?>