tdb->query($q); $res = array(); while ( $row = mysql_fetch_array($ret)) { $res[] = $row; } return $res; } function groupsmgm_handler() { return "groupsmgm"; } /** * @Secured('roles' = {'manager'}) * */ function actionGotoNewGroup() { return array('pid' => 'GroupsManager', 'mode' => 'new_group_form'); } /** * @Secured('roles' = {'manager'}) * */ function actionAddNewgroup() { global $tdb, $user; $grname = $_POST['grname']; $q = "SELECT groupID FROM ".DB_PREFIX."_groups WHERE groupName='".$_POST['grname']."'"; if (mysql_num_rows($tdb->query($q))>0) { $_SESSION['".DB_PREFIX."_notice'] = sprintf(gettext("Group named %s has already been created. Creating group were cancelled!"),$_POST['grname']); } else { $q = "INSERT INTO ".DB_PREFIX."_groups (groupName) values ('%s')"; $q = sprintf($q, $grname); $tdb->query($q); $_SESSION['".DB_PREFIX."_notice'] = gettext("New group added!"); } return array('pid' => 'GroupsManager'); } function getSchoolForm() { if (isset($_GET['sid'])) { return $this->_get_school_form(intval($_GET['sid'])); } } function getGroupInfo() { global $tdb; $q = "SELECT groupID, groupName FROM ".DB_PREFIX."_groups WHERE groupID=".$_GET['gid']; $ret = $tdb->query($q); $grgr = mysql_fetch_array($ret); return $grgr; } function getCurrentMembers() { global $tdb; $q = "SELECT userID, uname, concat(firstname, ' ', lastname) as fullname FROM ".DB_PREFIX."_grouprelations LEFT JOIN ".DB_PREFIX."_users ON ".DB_PREFIX."_users.id=".DB_PREFIX."_grouprelations.userID LEFT JOIN ".DB_PREFIX."_userinfo USING(userid) WHERE groupID=".$_GET['gid']." ORDER BY lastname ASC, firstname ASC"; $ret = $tdb->query($q); $cm = array(); while ( $u = mysql_fetch_array($ret) ) { $cm []= $u; } return $cm; } function getAvailableUsers() { global $tops, $user, $tdb; $users = $user->getUsers(); $crms = array(); foreach ($this->getCurrentMembers() as $crm) { $crms []= $crm['userID']; } $cm = array(); if ($users) { while ( $u = mysql_fetch_array($users) ) { if (!in_array($u['id'], $crms)) { $cm []= $u; } } } return $cm; } /** * @Secured('roles' = {'manager'}) * */ function actionModifyExistingGroup() { global $tdb; if (isset($_POST['groupid']) && isset($_POST['grname'])) { $gid = $_POST['groupid']; $q = "UPDATE ".DB_PREFIX."_groups SET groupName='".$_POST['grname']."' WHERE groupID=".$gid; $tdb->query($q); $q2 = "DELETE FROM ".DB_PREFIX."_grouprelations WHERE groupID=".$gid; $tdb->query($q2); if ( isset($_POST['members'] ) ) { foreach ( $_POST['members'] as $m ) { //print $m; $tdb->query("INSERT INTO ".DB_PREFIX."_grouprelations (groupID, userID) values (".$gid.", ".$m.")"); } } } $_SESSION['".DB_PREFIX."_notice'] = gettext("Saved!"); return array('pid' => 'GroupsManager'); } /** * @Secured('roles' = {'manager'}) * */ function actionDeleteGroup() { global $tdb; if ( isset($_POST['delete']) && is_array($_POST['delete']) ) { $keys = array_keys($_POST['delete']); foreach( $keys as $todel) { $q = "DELETE FROM ".DB_PREFIX."_groups where groupID=".$todel; $tdb->query($q); } $_SESSION['".DB_PREFIX."_notice'] = gettext("Deleted!"); } else { $_SESSION['".DB_PREFIX."_notice'] = gettext("Nothing selected for delete!"); } return array('pid' => 'GroupsManager'); } /** * @Secured('roles' = {'manager'}) * */ function actionCancel() { $_SESSION['".DB_PREFIX."_notice'] = gettext("Action cancelled!"); return array('pid' => 'GroupsManager'); } } ?>