getUserID()==$user->getID()) { return 0; } return 1; } public function isAssignedTask() { if ($this->isOwner()==0) { return 0; } else if ($this->validateAssignment()) { return 1; } return 0; } public function isAssignedToMe() { if ($this->getAssignmentId()>0) { return 0; } return 1; } public function isAssigned() { $num = mysql_num_rows($this->getAssignmentsFDB()); if ($num > 0) { return 0; } return 1; } public function getAssignmentID() { if (isset($_GET['assignment'])) { if ($this->validateAssignment($_GET['assignment'])) { return $_GET['assignment']; } } return 0; } public function validateAssignment($assid=false) { global $user; $a = $this->getAssignmentsFDB($assid); $num = mysql_num_rows($a); if ($num > 0) { $ugroups = $user->getGroups(); $ugs = array(); foreach ($ugroups as $ug) { $ugs []= $ug['groupID']; } while ( $g = mysql_fetch_array($a) ) { if( in_array($g['groupID'], $ugs) ) { return true; } } } return false; } public function getAssignments() { global $kdb; $ass = array(); $assgs = $this->getAssignmentsFDB(); while ($as = mysql_fetch_array($assgs)) { $ass []= array('i'=>$as['assignmentID'],'g'=>$kdb->getGroupNameById($as['groupID']),'gid'=>$as['groupID'], 'n'=>$as['assignmentName'], 'd'=>$as['deadline'], 's'=>$as['startline'], 'a'=>$this->getNumberOfAnswersByAssId($as['assignmentID']), 'c'=>$this->getFullname($as['userID']), 'memberlist'=>$kdb->getGroupMemberListing($as['groupID'])); } return $ass; } protected function getAssignmentsFDB($assid=false) { global $kdb; date_default_timezone_set(TIME_ZONE); $time = strftime("%Y-%m-%d %H:%M", strtotime("now")); $timed = " AND deadline>'".$time."'"; $sorted = " ORDER BY deadline DESC"; if ($assid) { return $kdb->query("SELECT * FROM assignments WHERE resourceID=".$this->getResourceID()." AND assignmentID=".$assid.$timed.$sorted); } return $kdb->query("SELECT * FROM assignments WHERE resourceID=".$this->getResourceID().$sorted); } public function getAnswersAssignedFor() { global $kdb; $assgs = $kdb->getAssignmentsByRid($this->getResourceId()); $ass = array(); foreach ($assgs as $as) { $memberlist = $kdb->getAssignmentListing($as['assignmentID']); $memberanswers = array(); foreach ($memberlist as $member) { $manswers = $kdb->getAnswerByRID($this->getResourceId(), array('userID'=>$member, 'assignmentID'=>$as['assignmentID']),$this->getType()."Answer"); $memberanswers []= array('memberID'=>$member, 'answers'=>$manswers); } $ass []= array('assignmentID'=>$as['assignmentID'],'groupName'=>$kdb->getGroupNameById($as['groupID']),'groupID'=>$as['groupID'], 'assignmentName'=>$as['assignmentName'], 'deadline'=>$as['deadline'], 'startline'=>$as['startline'], 'creator'=>$this->getFullname($as['userID']), 'memberAnswers'=>$memberanswers); } return $ass; } public function getGroups() { global $kdb, $user; $groups = $kdb->getGroupsByUserId($user->getID()); return $groups; } protected function getNumberOfAnswersByAssId($assId) { global $kdb; $ret = $kdb->query("SELECT * FROM answers WHERE resourceID=".$this->getResourceId()." AND assignmentID=".$assId); $num = mysql_num_rows($ret); return $num; } /** * @Secured('roles' = {'member', 'manager'}, 'valid' = {}) * */ public function actionAssign() { $mess = "For assign task, please fill all fields"; if (isset($_POST['gid']) && is_numeric($_POST['gid']) && isset($_POST['startline_date']) && isset($_POST['deadline_date']) && isset($_POST['aname']) && $_POST['aname']!="") { $startline = $_POST['startline_date']; $deadline = $_POST['deadline_date']; if (isset($_POST['startline_h']) && isset($_POST['startline_m']) && isset($_POST['deadline_h']) && isset($_POST['deadline_m'])) { $startline .= " ".$_POST['startline_h'].":".$_POST['startline_m']; $deadline .= " ".$_POST['deadline_h'].":".$_POST['deadline_m']; } global $user, $kdb; $q = "INSERT INTO assignments (assignmentName, groupID, resourceID, userID, startline, deadline) values ('%s', %s, %s, %s, '%s','%s')"; $q = sprintf($q, $_POST['aname'], $_POST['gid'], $this->getResourceID(), $user->getID(), $startline, $deadline); $res = $kdb->query($q); $ass_id = mysql_insert_id(); if ($res) { $mess = "Assigning successful"; } else { $mess = "Assigning failed"; } foreach ($_POST['groupuserlisting'] as $uuser) { $q = "INSERT INTO assignment_relations (assignmentID, userID) values (%s, %s)"; $q = sprintf($q, $ass_id, $uuser); $res = $kdb->query($q); } } $_SESSION['krihvel_notice'] = gettext($mess); return array('rid' => $this->getResourceID(), 'mode' => "assignments"); } /** * @Secured('roles' = {'authenticated'}, 'valid' = {}) * */ public function actionDelete() { $delete = array(); $mess = "No assignments selected for delete!"; if (isset($_POST['del_assignments'])) { global $kdb; foreach ($_POST['del_assignments'] as $aid) { $kdb->query("DELETE FROM assignments WHERE assignmentID=".$aid); } $mess = "Selected assignments deleted"; } $_SESSION['krihvel_notice'] = gettext($mess); return array('rid' => $this->getResourceID(), 'mode' => "assignments"); } } ?>