getId(); $ret = $kdb->query("SELECT * FROM psyhvel_tests WHERE userID=".$userID." AND testID=".$id); $tinfo = mysql_fetch_array($ret); $this->setTestID($id); $this->setTitle($tinfo['title']); $this->setActive($tinfo['active']); $this->setCreator($tinfo['userID']); $this->setCreated($tinfo['created']); $this->setDescription($tinfo['description']); $this->setSecurity($tinfo['security']); $ret = $kdb->query("SELECT * FROM psyhvel_testrelations WHERE testID=".$id); $ttargets = array(); while ($ttarget = mysql_fetch_array($ret)) { $ttargets []= $ttarget['groupID']; } $this->setTargets($ttargets); } else { $this->setTestID("new"); $this->setTitle(""); $this->setCreator(-1); $this->setDescription(""); $this->setSecurity("private"); $this->setActive(0); } } function getTestID() { return $this->tid; } function setTestID($d) { $this->tid = $d; } function getTitle() { return $this->title; } function setTitle($d) { $this->title = $d; } function getCreator() { return $this->creator; } function setCreator($d) { $this->creator = $d; } function getCreated() { return $this->created; } function setCreated($d) { $this->created = $d; } function getActive() { return $this->active; } function setActive($d) { $this->active = $d; } function getDescription() { return $this->description; } function setDescription($d) { $this->description = $d; } function getSecurity() { return $this->security; } function setSecurity($d) { if (in_array($d, array("private", "public"))) { $this->security = $d; } } function getTargets() { return $this->groups; } function setTargets($d) { $this->groups = $d; } function getGroups() { return array(array('id'=>1, 'title'=>'KEF09'),array('id'=>2, 'title'=>'KEF10')); //return $this->groups; } function getTargetsList() { global $kdb; $list = array(); foreach ( $this->groups as $gid) { $ret = $kdb->query("SELECT groupName FROM psyhvel_groups WHERE groupID=".$gid); $res = mysql_fetch_array($ret); $list []= $res['groupName']; } return join(", ", $list); } function getMyGamepacks() { global $kdb, $user; $ret = $kdb->query("SELECT * FROM psyhvel_gamepacks WHERE userID=".$user->getID()); $gps = array(); while ($gp = mysql_fetch_array($ret)) { $gps []= $gp; } return $gps; } function renderTestTable($width=600, $owidth=200) { global $user; $objects = array(); $table = array(); $counter = 0; $testObjects = array(); $nrOfObjs = count($testObjects); $notActive = true; $table []= ''; $isEditor = false; if (1==1) $isEditor = true; //isEditor foreach ($testObjects as $obj) { $url = ""; if (1==2) { //isLocked if (!$isEditor) { $objects []= ''; } else { $objects []= ''; } } else if ($notActive) { if (!$isEditor) { $objects []= ''; } else { $objects []= ''; } } else { $objects []= ''; } if (1==1) { //getCurrentPage()==0: $notActive = true; } $counter++; } if ($isEditor) { $url = '?pid=Test&mode=select&tid='.$this->getTestID(); $objects []= ''; } $nrOfObjs = count($objects); $rows = ($nrOfObjs*$owidth/$width)+1; $max_objs = $width/$owidth; if ($nrOfObjs < $max_objs) { $max_objs = $nrOfObjs; } foreach (range(0,$rows) as $line) { $table []= ''; $lines = array(); $spacer = array(); foreach (range(0, $max_objs*2-1) as $i) { if (count($objects) > 0 && $i%2 == 0) { $ob = $objects[0]; $objects = array_splice($objects, 1); $lines []= $ob; if ($i==$max_objs*2-2) { $spacer []= ''; } else { $spacer []= ''; } } else if (count($objects) > 0 && $i%2 != 0 && $line%2 == 0) { $lines []= ''; $spacer []= ''; } else if (count($objects) > 0 && $i%2 != 0 && $line%2 != 0) { $lines []= ''; $spacer []= ''; } else { $lines []= ''; $spacer []= ''; } } if ($line%2 != 0 ) { array_reverse($lines); array_reverse($spacer); } foreach ($lines as $li) { $table []= $li; } $table []= ''; // line + 1 sest muidu pani siia asja kylge kui ei ole enam vaja siis v6iks 2ra if ( $line+1 != $rows ) { $table []= ''; foreach ($spacer as $sp) { $table []= $sp; } $table []= ''; } $table []= '
'.gettext('Test').' '.($counter+1).''.gettext('Test').' '.($counter+1).''.gettext('Test').' '.(counter+1).''.gettext('Test').' '.($counter+1).''.gettext('Test').' '.($counter+1).''.gettext('Add Test').'
'; } return join("", $table); } /** * @Secured(roles={'member'}) * */ function actionSaveTest() { global $user, $kdb; $_SESSION['psyhvel_notice'] = gettext("Test not saved!"); if (isset($_POST['title']) && $_POST['title']!="") { $title = $_POST['title']; $description = $_POST['description']; $active = 0; if (isset($_POST['activeTest']) && $_POST['activeTest']) $active = 1; if (!is_numeric($this->getTestID())) { $q = "INSERT INTO psyhvel_tests (title, description, active, userID) values ('".$title."', '".$description."', ".$active.", ".$user->getID().")"; $kdb->query($q); $tid = mysql_insert_id(); $this->setTestID($tid); $_SESSION['psyhvel_notice'] = gettext("Test created!"); } else { $q = "UPDATE psyhvel_tests SET title='".$title."', description='".$description."', active=".$active.", userID=".$user->getID().", modified=NOW() WHERE testID=".$this->getTestID(); $kdb->query($q); $_SESSION['psyhvel_notice'] = gettext("Test changes saved!"); } $q = "DELETE FROM psyhvel_testrelations WHERE testID=".$this->getTestID(); $kdb->query($q); $targets = array(); if (isset($_POST['testTargets'])) $targets = $_POST['testTargets']; //if (!is_array($targets)) $targets = array($_POST['testTargets']); foreach ($targets as $gid) { $sq = "INSERT INTO psyhvel_testrelations (testID, groupID) values (".$this->getTestID().", ".$gid.")"; $kdb->query($sq); } return array('pid' => 'Test', 'tid' => $this->getTestID()); } return array('pid' => 'Tests'); } /** * @Secured(roles={'member'}) * */ function actionCancel() { $_SESSION['psyhvel_notice'] = gettext("Test not saved!"); return array('pid' => 'Tests'); } } ?>