setExerciseData(""); $this->setGadget(""); } else { global $kdb; $typeData = $kdb->getTypeData($rid, self::$table); $this->setExerciseData($typeData['data']); $this->setGadget($typeData['gadget']); } } protected function setExerciseData($d) { $this->exerciseData = $d; } public function getExerciseData() { return $this->exerciseData; } protected function setGadget($d) { $this->gadget = $d; } public function getGadget() { return $this->gadget; } public function isNotGadget() { return 1; } public function makeResourceFromXML($xml) { parent::makeResourceFromXML($xml); if ($this->getResourceID()!="new"){ global $kdb; $res = $kdb->query("INSERT INTO gadget (resourceID, gadget, data) values (".$this->getResourceID().", '".$xml['gadget']."', '".$xml['data']."')"); if ($res) { $_SESSION['krihvel_notice'] = "\"".gettext("Gadget")."\" ".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 = 'getGadget().']]>\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 gadget (resourceID, gadget, data) values (".$this->getResourceID().", '".$this->getGadget()."', '".$this->getExerciseData()."')"); if ($res) { $_SESSION['krihvel_notice'] = gettext("You have new copy of")." \"".gettext("Gadget")."\""; } else { $_SESSION['krihvel_notice'] = gettext("Making copy failed"); } } return array('rid' => $this->getResourceID(), 'mode' => 'view'); } /** * @Secured('roles' = {'authenticated'}, 'valid' = {}) * */ 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 gadget (resourceID, gadget, data) values (".$this->getResourceID().", '".$this->getGadget()."', '".$this->getExerciseData()."')"); } } /** * @Secured('roles' = {'authenticated'}, 'valid' = {}) * */ public function actionCompile() { global $kdb; $kdb->query("UPDATE gadget SET gadget='".$_POST['gadget']."' WHERE resourceID=".$this->getResourceID()); $this->updateFulltext(); $_SESSION['krihvel_notice'] = gettext("Saved"); return array('rid' => $this->getResourceID(), 'mode' => "settings"); } function fulltext() { return $this->getExerciseData(); } } ?>