kdb->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 $kdb, $user; $grname = $_POST['grname']; $q = "SELECT groupID FROM psyhvel_groups WHERE groupName='".$_POST['grname']."'"; if (mysql_num_rows($kdb->query($q))>0) { $_SESSION['psyhvel_notice'] = sprintf(gettext("Group named %s has already been created. Creating group were cancelled!"),$_POST['grname']); } else { $q = "INSERT INTO psyhvel_groups (groupName) values ('%s')"; $q = sprintf($q, $grname); $kdb->query($q); $_SESSION['psyhvel_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 FROM psyhvel_groups WHERE groupID=".$_GET['gid']; $ret = $kdb->query($q); $grgr = mysql_fetch_array($ret); return $grgr; } function getCurrentMembers() { global $kdb; $q = "SELECT userID, uname, concat(firstname, ' ', lastname) as fullname FROM psyhvel_grouprelations LEFT JOIN psyhvel_users ON psyhvel_users.id=psyhvel_grouprelations.userID LEFT JOIN psyhvel_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() { global $psyhvel, $user, $kdb; $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 $kdb; if (isset($_POST['groupid']) && isset($_POST['grname'])) { $gid = $_POST['groupid']; $q = "UPDATE psyhvel_groups SET groupName='".$_POST['grname']."' WHERE groupID=".$gid; $kdb->query($q); $q2 = "DELETE FROM psyhvel_grouprelations WHERE groupID=".$gid; $kdb->query($q2); if ( isset($_POST['members'] ) ) { foreach ( $_POST['members'] as $m ) { //print $m; $kdb->query("INSERT INTO psyhvel_grouprelations (groupID, userID) values (".$gid.", ".$m.")"); } } } $_SESSION['psyhvel_notice'] = gettext("Saved!"); return array('pid' => 'GroupsManager'); } /** * @Secured('roles' = {'manager'}) * */ function actionDeleteGroup() { global $kdb; if ( isset($_POST['delete']) && is_array($_POST['delete']) ) { $keys = array_keys($_POST['delete']); foreach( $keys as $todel) { $q = "DELETE FROM psyhvel_groups where groupID=".$todel; $kdb->query($q); } $_SESSION['psyhvel_notice'] = gettext("Deleted!"); } else { $_SESSION['psyhvel_notice'] = gettext("Nothing selected for delete!"); } return array('pid' => 'GroupsManager'); } /** * @Secured('roles' = {'manager'}) * */ function actionCancel() { $_SESSION['psyhvel_notice'] = gettext("Action cancelled!"); return array('pid' => 'GroupsManager'); } } ?>