table) { $join = " LEFT JOIN " . DB_PREFIX . $this->getTable() . " t ON b.id=t.base_id "; } $data = query_row("SELECT * FROM " . DB_PREFIX . "base_object b" . $join . "WHERE b.id='{$id}'"); if ($data) { $this->id = $id; $this->setTitle($data->title); $this->setInstructions($data->instructions); $this->setInstructionsTop($data->instructions_top); $this->setCreated($data->created); $this->setModified($data->modified); $this->setCreator($data->creator); $this->setTime($data->time); $this->setTimeButton($data->time_button); $this->setInfo($data->info); $this->setRights($data->rights); $this->setStatus($data->status); $this->setSecurity($data->security); $this->setFolder($data->folder); $this->setPosition($data->position); $this->setLocked($data->locked); $this->setScreenshot($data->screenshot); return $data; } return false; } function create() { $this->setCreator(get_logged_in_user()->getId()); $q = query_row("SELECT count(id) as count FROM " . DB_PREFIX . "base_object WHERE folder=".$this->getFolder()); $pos = ($q->count)+1; $insert = query_insert("INSERT INTO " . DB_PREFIX . "base_object (type, title, instructions, instructions_top, time, time_button, created, creator, info, rights, folder, position) values ('".mysql_real_escape_string($this->getType())."', '".mysql_real_escape_string($this->getTitle())."', '".mysql_real_escape_string($this->getInstructions())."', ".$this->getInstructionsTop().", ".$this->getTime().", ".$this->getTimeButton().", NOW(), ".$this->getCreator().", '".mysql_real_escape_string($this->getInfo())."', '".mysql_real_escape_string($this->getRights())."', ".$this->getFolder().", ".$pos.")"); return $insert; } function save() { $update = query_update("UPDATE " . DB_PREFIX . "base_object SET title='".$this->getTitle()."', instructions='".mysql_real_escape_string($this->getInstructions())."', instructions_top=".$this->getInstructionsTop().", time=".$this->getTime().", time_button=".$this->getTimeButton().", modified=NOW(), info='".$this->getInfo()."', rights='".$this->getRights()."', screenshot=".$this->getScreenshot()." WHERE id=".$this->getId()); return $update; } function copy($locked=false) { $crt = $this->create(); if ($crt && $locked) { $lock = $this->lock($crt); } return $crt; } function lock($id=null) { if (!$id) $id = $this->getId(); return query_update("UPDATE " . DB_PREFIX . "base_object SET locked=1 WHERE id=".$id); } function build($data) { if (!isset($data["title"]) || empty($data["title"])) { return false; } else { $this->setTitle($data["title"]); if (isset($data["instructions"])) $this->setInstructions($data["instructions"]); if (isset($data["instructions_top"])) $this->setInstructionsTop($data["instructions_top"]); if (isset($data["time"])) $this->setTime($data["time"]); $this->setTimeButton(0); if (isset($data["time_button"])) $this->setTimeButton($data["time_button"]); if (isset($data["rights"])) $this->setRights($data["rights"]); if (isset($data["info"])) $this->setInfo($data["info"]); if (isset($data["folder"])) $this->setFolder($data["folder"]); } return true; } function delete() { if (is_numeric($this->getId()) && $this->getId() > 0) { if (is_admin() || $this->creator==get_logged_in_user()->getId()) { return query("DELETE FROM " . DB_PREFIX . "base_object WHERE id=".$this->getId()); } } return false; } function reposition() { return query_update("UPDATE " . DB_PREFIX . "base_object SET position=position-1 WHERE folder=".$this->getFolder()." AND position>".$this->getPosition()." AND position>1"); } function move_up() { $max_pos = query_row("SELECT count(id) as count FROM " . DB_PREFIX . "base_object WHERE folder=".$this->getFolder()); if (query_update("UPDATE " . DB_PREFIX . "base_object SET position=position+1 WHERE folder=".$this->getFolder()." AND position=".($this->getPosition()-1)." AND position>0 AND position<".$max_pos->count)) { return query_update("UPDATE " . DB_PREFIX . "base_object SET position=position-1 WHERE folder=".$this->getFolder()." AND id=".$this->getId()." AND position>0"); } return false; } function move_down() { $max_pos = query_row("SELECT count(id) as count FROM " . DB_PREFIX . "base_object WHERE folder=".$this->getFolder()); if (query_update("UPDATE " . DB_PREFIX . "base_object SET position=position-1 WHERE folder=".$this->getFolder()." AND position=".($this->getPosition()+1)." AND position>2")) { return query_update("UPDATE " . DB_PREFIX . "base_object SET position=position+1 WHERE folder=".$this->getFolder()." AND id=".$this->getId()." AND position<".$max_pos->count." AND position>0"); } return false; } function getScreenshot() { return $this->screenshot; } function setScreenshot($screenshot_id) { return $this->screenshot = $screenshot_id; } function takeScreenshot($screenshot_string) { if ($this->getScreenshot() > 0) { $screenshot = new Screenshot($this->getScreenshot()); } else { $screenshot = new Screenshot(); } $screenshot_id = $screenshot->saveScreenshot($screenshot_string, $this->getTitle()); if ($screenshot_id) { $this->setScreenshot($screenshot_id); $this->save(); } } public function getId() { return $this->id; } public function setId($id) { $this->id = $id; } public function getType() { return $this->type; } function setType($type) { $this->type = $type; } public function getTable() { return $this->table; } function setTable($table) { $this->table = $table; } public function getName() { return $this->name; } function setName($name) { $this->name = $name; } function getActions() { return $this->actions; } function setActions($actions) { $this->actions = $actions; } public function getLocked() { return $this->locked; } public function setLocked($locked) { if ($locked) { $this->locked = 1; } else { $this->locked = 0; } } public function getTitle() { return $this->title; } function setTitle($title) { $this->title = $title; } public function getInstructions() { return $this->instructions; } function setInstructions($desc) { $this->instructions = $desc; } public function getInstructionsTop() { return $this->instructions_top; } function setInstructionsTop($top) { if ($top) { $this->instructions_top = 1; } else { $this->instructions_top = 0; } } public function getCreated() { return $this->created; } function setCreated($created) { $this->created = $created; } public function getModified() { return $this->modified; } function setModified($modified) { $this->modified = $modified; } public function getCreator() { return $this->creator; } function setCreator($creator) { $this->creator = $creator; } public function getAuthors() { return $this->authors; } function setAuthors($authors) { $this->authors = $authors; } public function getTime() { return $this->time; } function setTime($time) { if (!$time) $time = 0; $this->time = $time; } public function getTimeButton() { return $this->time_button; } function setTimeButton($but) { if ($but) { $this->time_button = 1; } else { $this->time_button = 0; } } public function getRights() { return $this->rights; } function setRights($rights) { $this->rights = $rights; } public function getInfo() { return $this->info; } function setInfo($info) { $this->info = $info; } public function getStatus() { return $this->status; } function setStatus($status) { $this->status = $status; } public function getSecurity() { return $this->security; } function setSecurity($security) { $this->security = $security; } public function getFolder() { return $this->folder; } function setFolder($folder) { $this->folder = $folder; } public function getPosition() { return $this->position; } function setPosition($pos) { $this->position = $pos; } function addBuildError($err) { $this->build_error []= $err; } function getBuildError() { return $this->build_error; } function viewImage($id, $thumb=false, $mini = false) { $image = new Image($id); return $image->view($thumb, $mini); } public function isLocked() { return false; } public function answer($data) { return true; } function collect($examinees) { return array(); } function buildFromXML($obj, $folder=0, $dir, $version=1) { $this->setFolder($folder); $this->setTitle($obj->title[0][0]); if (isset($obj->description[0][0])) { $this->setInstructions($obj->description[0][0]); if (isset($obj->descriptionIsTop) && $obj->descriptionIsTop[0][0] && $obj->descriptionIsTop[0][0] != "False") { $this->setInstructionsTop(1); } else { $this->setInstructionsTop(0); } } else if (isset($obj->instructions[0][0])) { $this->setInstructions($obj->instructions[0][0]); $this->setInstructionsTop($obj->instructionsTop[0][0]); } $this->setAuthors($obj->author[0][0]); if (!empty($obj->rights[0][0])) $this->setRights(implode("\n", $obj->rights[0][0])); if (!empty($obj->info[0][0])) $this->setInfo(implode("\n", $obj->info[0][0])); $this->setCreated($obj->created[0][0]); } public function getBaseXML() { $xml = "\n\n"; $xml .= "".$this->getType()."\n"; $xml .= "getCreated()."]]>\n"; $xml .= "<![CDATA[".$this->getTitle()."]]>\n"; $xml .= "getInstructions()."]]>\n"; $xml .= "getInstructionsTop()."]]>\n"; $xml .= "getCreator()."]]>\n"; $xml .= "getRights()."]]>\n"; $xml .= "getInfo()."]]>\n"; $xml .= $this->getObjectsXML(); $xml .= "\n"; return $xml; } public function getNavigationTree() { $nav = array(); $folder = $this->getFolder(); $level = 2; $fd_level = 1; $f_level = 1; if ($folder>0) { $fd = query_row("SELECT id, title, folder FROM " . DB_PREFIX . "test_folder WHERE id=".$folder); if ($fd->folder) { $f = query_row("SELECT id, title, folder FROM " . DB_PREFIX . "folder WHERE id=".$fd->folder); $nav []= array('title' => $f->title, 'url'=>"library/Folder/".$f->id."/view", 'current'=>false, 'level'=>$f_level); $fd_level = 2; $level = 3; } $nav []= array('title' => $fd->title, 'url'=>"library/TestFolder/".$folder."/view", 'current'=>false, 'level'=>$fd_level); } $nav []= array('title' => $this->getTitle(), 'url'=>"library/".$this->getType()."/".$this->getId()."/view", 'current'=>true, 'level'=>$level); return $nav; } public function arrayCoordinatesAsNr($coordinates, $table_width) { return $table_width * $coordinates[0] + $coordinates[1]; } public function timer($data) { $load = 0; $start = 0; $end = 0; $submit= 0; if (isset($data["timer"]) && !empty($data["timer"])) { $t = json_decode($data["timer"], true); if (isset($t["load"])) { $load = $t["load"]; } if (isset($t["start"])) { $start = $t["start"]; } if (isset($t["end"])) { $end = $t["end"]; } if (isset($t["submit"])) { $submit = $t["submit"]; } } return array("load"=>$load, "start"=>$start, "end"=>$end, "submit"=>$submit); } } ?>