setExerciseData(""); $this->setCorrectData(""); } else { // type specific data loading global $kdb; $typeData = $kdb->getTypeData($rid, self::$table); $this->setExerciseData($typeData['data']); $this->setCorrectData($typeData['correct']); } } protected function setExerciseData($d) { $this->exerciseData = $d; } public function getExerciseData() { return $this->exerciseData; } protected function setCorrectData($d) { $this->correctData = $d; } public function getCorrectData() { return $this->correctData; } protected function makeCorrectData() { $res = Array(); $i = 0; while ( isset($_POST['forgap_'.$i]) ) { // forgap_sel_0 $rsel = 0; if ( isset($_POST['forgap_sel_'.$i]) ) { $rsel = $_POST['forgap_sel_'.$i]; } array_push($res, array($_POST['forgap_'.$i], $rsel)); $i++; } return serialize($res); } public function makeFillInForm(){ $ff = ""; $opts = unserialize($this->getCorrectData()); $matches = preg_split("/\[(.*?)\]/", $this->getExerciseData(), -1, PREG_SPLIT_DELIM_CAPTURE); $c = 0; for ($i=0; $i'; $tmp .= ''; $choicecount = 0; foreach ( $opts[$c][0] as $op => $val) { if ( strlen(trim($val)) == 0 ) { continue; } $choicecount++; $tmp .= ''; } $tmp .= ""; if ( $choicecount == 1 ) { $tmp = '  '; } $ff .= $tmp; } $c++; } return $ff; } public function makeFillInAnswerForm(){ $aobj = $this->getAnswerObject(); $answers = explode(":", $aobj->getCorrect()); $ui = explode(":;:", $aobj->getAnswer()); $ff = ""; $opts = unserialize($this->getCorrectData()); $matches = preg_split("/\[(.*?)\]/", $this->getExerciseData(), -1, PREG_SPLIT_DELIM_CAPTURE); $c = 0; for ($i=0; $i'; $tmp .= ''; $choicecount = 0; foreach ( $opts[$c][0] as $op => $val) { if ( strlen(trim($val)) == 0 ) { continue; } $choicecount++; $sell = ""; if ( !strcmp($ui[$c], $val) ) { $sell = ' selected="selected"'; } $tmp .= ''; } $tmp .= ""; if ( $choicecount == 1 ) { $tmp = '  '; } $tmp .= ''; if ( $answers[$c] ) { $tmp .= ''; } else { $tmp .= ''; } $tmp .= ''; $ff .= $tmp; } $c++; } return $ff; } function getOptions() { $vars = unserialize($this->getCorrectData()); if (!$vars) { return "var opts = Array();"; } $msg = "var opts = Array("; foreach( $vars as $var => $ops ) { $msg .= "Array("; $tmp = "Array("; foreach ( $ops as $op => $o ) { if ( is_array($o) ) { foreach( $o as $chs => $ch ) { $tmp .= '"'.$ch.'",'; } $tmp = substr($tmp, 0, strlen($tmp)-1); } else { $msg .= $o.","; } } $msg .= $tmp.")),"; } $msg = substr($msg, 0, strlen($msg)-1); $msg .= ");"; return $msg; } public function makeResourceFromXML($xml) { parent::makeResourceFromXML($xml); if ($this->getResourceID()!="new"){ global $kdb; $res = $kdb->query("INSERT INTO fillin (resourceID, data, correct) values (".$this->getResourceID().", '".$xml['data']."', '".$xml['correct']."')"); if ($res) { $_SESSION['krihvel_notice'] = "\"".gettext("Fillin")."\" ".gettext("has been imported successfully!"); } else { $_SESSION['krihvel_notice'] = gettext("Upload failed! Zip file was corrupted!"); } } return array('rid' => $this->getResourceID(), 'mode' => 'view'); } public function makeXML() { $xml = 'getCorrectData().']]>\n'; $xml .= 'getExerciseData().']]>\n'; return $xml; } /** * @Secured('roles' = {'authenticated'}, 'valid' = {}) * */ public function actionCopy() { global $kdb; $this->updateData($_POST); $rid = $this->getResourceID(); parent::copy(); if ($this->getResourceID() != $rid){ $res = $kdb->query("INSERT INTO fillin (resourceID, data, correct) values (".$this->getResourceID().", '".$this->getExerciseData()."', '".$this->getCorrectData()."')"); if ($res) { $_SESSION['krihvel_notice'] = gettext("You have new copy of")." \"".gettext("Fillin")."\""; } else { $_SESSION['krihvel_notice'] = gettext("Making copy failed"); } } return array('rid' => $this->getResourceID(), 'mode' => 'view'); } /** * @Secured('roles' = {'authenticated'}, 'valid' = {'isOwner'}) * */ public function actionSave() { $mode = "view"; if ($this->getResourceID() == "new"){ $mode = "compile"; } $this->updateData($_POST); $this->save(); $_SESSION['krihvel_notice'] = gettext("Saved"); return array('rid' => $this->getResourceID(), 'mode' => $mode); } protected function save() { global $kdb; $rid = $this->getResourceID(); parent::save(); if ($rid == "new"){ $kdb->query("INSERT INTO fillin (resourceID, data) values (".$this->getResourceID().", '".$this->getExerciseData()."')"); } } /** * @Secured('roles' = {'authenticated'}, 'valid' = {'isOwner'}) * */ public function actionCompile() { global $kdb; $this->setExerciseData($_POST['exercise']); $this->setCorrectData($this->makeCorrectData()); $kdb->query("UPDATE fillin SET data='".$this->getExerciseData()."', correct='".$this->getCorrectData()."' WHERE resourceID=".$this->getResourceID()); $this->updateFulltext(); $_SESSION['krihvel_notice'] = gettext("Saved"); return array('rid' => $this->getResourceID(), 'mode' => "settings"); } /** * @Secured('roles' = {'authenticated'}, 'valid' = {}) * */ public function actionAnswer() { global $user, $krihvel; //$aid = $this->answerData($_POST); $a = new FillinAnswer(); $a->setResourceID($this->getResourceID()); $a->setAssignmentID($_POST['assignment']); $a->setUserID($user->getId()); $a->setGrade(0); $a->setComment(""); $a->setExponate(0); include_once("utils.php"); $ansb = checkSolution($this, true); $inps = implode(":;:", collectInput($this)); $a->setAnswer($inps); $a->setCorrect(implode(':', $ansb)); $a->save(); $_SESSION['krihvel_notice'] = gettext("Answered"); return array('rid' => $this->getResourceID(), 'mode' => "answer"); } function fulltext() { return $this->getExerciseData(); } } ?>