function save(){ $simpleElement = new SimpleElement($this->db,array("id"=>$this->id, "main_name"=>$this->main_name)); $simpleElement->save(); foreach($this->elementlocations as $curElementlocation){ $curElementlocation->save(); } foreach($this->names as $curName){ $curName->save(); } foreach($this->seasons as $curSeason){ $curSeason->save(); } }
public function editElementProcces() { if (!$this->session->userdata('logged_in')) { redirect('user/login'); } print "<pre>"; print_r($_POST); print "</pre>"; $element_id = $_POST['element_id']; // change main name $element = new SimpleElement($this->oh, $element_id); $element->main_name = $_POST['main_name']; $element->save(); print_query($this->db); unset($_POST['main_name']); //new name and season if ($_POST['newName']) { $season = -1; if ($_POST['newNameSeason'] && $_POST['newNameSeason'] != -1) { $season = $_POST['newNameSeason']; } $newSeason = new Season($this->db); $newSeason->element_id = $element_id; $newSeason->season = $season; $newSeason->save(); $newName = new Name($this->db); $newName->element_id = $element_id; $newName->name = $_POST['newName']; $newName->season = $newSeason; $newName->save(); unset($_POST['newName']); unset($_POST['newNameSeason']); } foreach ($_POST as $key => $value) { if (strpos($key, "elementLocationNew_") !== false) { $key = explode("_", $key); $location_id = $key[1]; $season = -1; if ($_POST["elementLocationSeasonNew_" . $location_id] && $_POST["elementLocationSeasonNew_" . $location_id] != "all") { $season = $_POST["elementLocationSeasonNew_" . $location_id]; } $seasonSize = -1; if ($_POST["elementLocationSeasonNew_" . $location_id] && $_POST["elementLocationSeasonNew_" . $location_id] != "infinite") { $seasonSize = $_POST["elementLocationSeasonNew_" . $location_id]; } $newSeason = new Season($this->db); $newSeason->element_id = $element_id; $newSeason->season = $season; $newSeason->save(); $newElementLocation = new ElementLocation($this->db); $newElementLocation->location = new Location($this->db, $location_id); $newElementLocation->element = new Element($this->db, $element_id); $newElementLocation->season = $newSeason; $newElementLocation->identifier = $value; $newElementLocation->seasonsize = $seasonSize; $newElementLocation->save(); unset($_POST[$key]); unset($_POST["elementLocationSeasonNew_" . $location_id]); continue; } if (strpos($key, "location_") !== false) { print "----------------<br>"; $key = explode("_", $key); $elementLocation_id = $key[1]; $oldSeason = $key[2]; if ($value || $_POST["locationSize_" . $elementLocation_id] && $_POST["locationSeason_" . $elementLocation_id]) { $season = -1; if ($_POST["locationSeason_" . $elementLocation_id] && $_POST["locationSeason_" . $elementLocation_id] != "all") { $season = $_POST["locationSeason_" . $elementLocation_id]; } $seasonSize = -1; if ($_POST["locationSize_" . $elementLocation_id] && $_POST["locationSize_" . $elementLocation_id] != "infinite") { $seasonSize = $_POST["locationSize_" . $elementLocation_id]; } $newSeason = new Season($this->db); $newSeason->element_id = $element_id; $newSeason->season = $season; $newSeason->save(); $newElementLocation = new ElementLocation($this->db, $elementLocation_id); print $newElementLocation->location->name . ": " . $newElementLocation->identifier . "<br>"; $newElementLocation->season = $newSeason; $newElementLocation->identifier = $value; $newElementLocation->seasonsize = $seasonSize; $newElementLocation->save(); } else { $newElementLocation = new ElementLocation($this->db, $elementLocation_id); $newElementLocation->delete(); } continue; } if (strpos($key, "name_") !== false) { print "----------------<br>"; $key = explode("_", $key); $name_id = $key[1]; if ($value) { $season = -1; if ($_POST["nameSeason_" . $name_id] && $_POST["nameSeason_" . $name_id] != "all") { $season = $_POST["nameSeason_" . $name_id]; } $newSeason = new Season($this->db); $newSeason->element_id = $element_id; $newSeason->season = $season; $newSeason->save(); $newName = new Name($this->db, $name_id); $newName->name = $value; $newName->season = $newSeason; $newName->save(); } else { $newName = new Name($this->db, $name_id); $newName->delete(); } continue; } } if (!isset($_POST['debug'])) { redirect('xem/editElement/' . $element_id); } }