setType("PictureStimulus"); $this->setName("Picture Stimulus"); $this->setTable("picture_stimulus"); $this->setActions(array("view"=>_("View"), "edit"=>_("Edit"))); if ($id) { $data = $this->load($id); if ($data) { $this->setBodyImage($data->body_image); } } } function create() { $bi1 = ""; $bi2 = ""; if ($this->getBodyImage()) { $bi1 = "body_image"; $bi2 = "'".mysql_real_escape_string($this->getBodyImage())."'"; } if ($id = parent::create()) { $insert = query_insert("INSERT INTO " . DB_PREFIX . $this->getTable() . " (base_id, ".$bi1.") values (".$id.", ".$bi2.")"); return $id; } return false; } function save() { if (parent::save()) { if ($this->getBodyImage()) { $upd = query_update("UPDATE " . DB_PREFIX . $this->getTable() . " SET body_image=".mysql_real_escape_string($this->getBodyImage())." WHERE base_id=".$this->getId()); } else { $upd = query_update("UPDATE " . DB_PREFIX . $this->getTable() . " SET body_image=NULL WHERE base_id=".$this->getId()); } if ($upd) { return $this->getId(); } else { $bi1 = ""; $bi2 = ""; if ($this->getBodyImage()) { $bi1 = "body_image"; $bi2 = "'".mysql_real_escape_string($this->getBodyImage())."'"; } return query_insert("INSERT INTO " . DB_PREFIX . $this->getTable() . " (base_id, ".$bi1.") values (".$this->getId().", ".$bi2.")"); } } return false; } function copy($locked=false) { // muuda $old_image = $this->getBodyImage(); $copy = $this->create(); if ($copy) { if ($locked) { $lock = $this->lock($copy); } if ($old_image) { $image = new Image($old_image); $this->load($copy); $this->setBodyImage($image->copy($locked)); } $this->save(); return true; } return false; } function build($data) { if (parent::build($data)) { $body_image = get_file("body_image"); if (!isset($body_image["error"]) || $body_image["error"] == 0) { if ($this->getBodyImage() > 0) { $image = new Image($this->getBodyImage()); } else { $image = new Image(); } $image_id = $image->upload($body_image); if ($image_id) { $this->setBodyImage($image_id); } } else if (get_input("delete_body_image", false)) { $image = new Image($this->getBodyImage()); if ($image->delete()) $this->setBodyImage(NULL); } if ($this->getId() > 0) { return $this->save(); } else { return $this->create(); } } return false; } function delete() { if (is_admin() || $this->getCreator() == get_logged_in_user()->getId()) { if (parent::delete()) { if ($this->getBodyImage()) { $img = new Image($this->getBodyImage()); // TODO pildi kustutamien jamab //$img->delete(); } return true; } } return false; } function getBodyImage() { return $this->body_image; } function setBodyImage($bt) { $this->body_image = $bt; } function buildFromXML($obj, $folder=0, $dir, $version=1) { parent::buildFromXML($obj, $folder, $dir); $img = $obj->imageFile[0][0]; if ($obj->imageFile[0][0]) { $image = new Image(); $image_id = $image->save_from_dir($dir, $obj->imageFile[0][0]); if ($image_id > 0) { $this->setBodyImage($image_id); } } $this->setId($this->create()); return $this->save(); } function getObjectsXML() { $xml = "getBodyImage()."]]>\n"; return $xml; } } ?>