user->hasRole('manager')) { $q .= " WHERE schoolID=".$user->getSchoolID(); } $ret = $this->kdb->query($q); $res = array(); while ( $row = mysql_fetch_array($ret)) { $res[] = $row; } return $res; } function groupsmgm_handler() { return "groupsmgm"; } /** * @Secured('roles' = {'manager', 'schooladm'}) * */ function actionGotoNewGroup() { return array('pid' => 'GroupsManager', 'mode' => 'new_group_form'); } function _get_school_form($currval) { global $user, $kdb; $schoolform = ""; if ( !$user->hasRole('manager')) { $q = "SELECT * FROM schools WHERE schoolID=".$user->getSchoolID(); $ret = $kdb->query($q); $mres = mysql_fetch_array($ret); $schoolform = $mres['schoolName']; } else { $q = "SELECT * FROM schools"; $ret = $kdb->query($q); $schoolform = ""; } return $schoolform; } /** * @Secured('roles' = {'manager', 'schooladm'}) * */ function actionAddNewgroup() { global $kdb, $user; $grname = $_POST['grname']; $scID = $user->getSchoolID();; if ( $user->hasRole('manager')) { $scID = $_POST['schoolID']; } else { if ( $scID == NULL) { return "usersmgm"; } } $q = "SELECT groupID FROM groups WHERE groupName='".$_POST['grname']."' AND schoolID='".$_POST['schoolID']."'"; if (mysql_num_rows($kdb->query($q))>0) { $_SESSION['krihvel_notice'] = sprintf(gettext("Group named %s has already been created at you school. Creating group were cancelled!"),$_POST['grname']); } else { $q = "INSERT INTO groups (groupName, schoolID) values ('%s', %s)"; $q = sprintf($q, $grname, $scID); $kdb->query($q); $_SESSION['krihvel_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 $kdb; $q = "SELECT groupID, groupName, schoolID FROM groups WHERE groupID=".$_GET['gid']; $ret = $kdb->query($q); $grgr = mysql_fetch_array($ret); //$grname = $grgr['groupName']; //$grid = $grgr['groupID']; //$scid = $grgr['schoolID']; return $grgr; } function getCurrentMembers() { global $kdb; $q = "SELECT userID, uname, concat(firstname, ' ', lastname) as fullname FROM grouprelations LEFT JOIN users ON users.id=grouprelations.userID LEFT JOIN userinfo USING(userid) WHERE groupID=".$_GET['gid']." ORDER BY lastname ASC, firstname ASC"; $ret = $kdb->query($q); $cm = array(); while ( $u = mysql_fetch_array($ret) ) { $cm []= $u; } return $cm; } function getAvailableUsers($scid) { global $krihvel, $user, $kdb; $users = $user->getUsersBySchool($scid); $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', 'schooladm'}) * */ function actionModifyExistingGroup() { global $kdb; if (isset($_POST['groupid']) && isset($_POST['grname'])) { $gid = $_POST['groupid']; $q = "UPDATE groups SET groupName='".$_POST['grname']."' WHERE groupID=".$gid; $kdb->query($q); $q2 = "DELETE FROM grouprelations WHERE groupID=".$gid; $kdb->query($q2); if ( isset($_POST['members'] ) ) { foreach ( $_POST['members'] as $m ) { //print $m; $kdb->query("INSERT INTO grouprelations (groupID, userID) values (".$gid.", ".$m.")"); } } } $_SESSION['krihvel_notice'] = gettext("Saved"); return array('pid' => 'GroupsManager'); } /** * @Secured('roles' = {'manager', 'schooladm'}) * */ function actionDeleteGroup() { global $kdb; if ( isset($_POST['delete']) && is_array($_POST['delete']) ) { $keys = array_keys($_POST['delete']); foreach( $keys as $todel) { $q = "DELETE FROM groups where groupID=".$todel; $kdb->query($q); } $_SESSION['krihvel_notice'] = gettext("Deleted!"); } else { $_SESSION['krihvel_notice'] = gettext("Nothing selected for delete!"); } return array('pid' => 'GroupsManager'); } /** * @Secured('roles' = {'manager', 'schooladm'}) * */ function actionCancel() { $_SESSION['krihvel_notice'] = gettext("Action cancelled!"); return array('pid' => 'GroupsManager'); } } ?>