/** * Show a form for adding a new service * @throws \Exception */ public function add_service() { $this->to_tpl['success'] = false; $this->to_tpl['errors'] = false; $this->to_tpl['id'] = 0; $this->to_tpl['title'] = ""; $this->template = "admin/add-service"; if (isset($_POST['submit'])) { $errors = $this->check_input(); if (is_array($errors) && !empty($errors)) { $this->to_tpl['errors'] = $errors; } else { $service = new Service(); $service->title_sr = post_string('title_sr'); $service->body_sr = post_string('body_sr'); $service->title_en = post_string('title_en'); $service->body_en = post_string('body_en'); $service->date_created = new \DateTime("now"); $service->published = post_bool('published'); if ($id = $service->saveToDb()) { $this->to_tpl['success'] = true; $this->to_tpl['id'] = $id; $this->to_tpl['title'] = $service->title_sr; $_POST = array(); } } } return; }
/** * List all services * @param string $lang */ public function listAll($lang = "") { $this->set_page_name($this->language_titles["services"][$lang]); if (isset($lang) && array_key_exists($lang, self::$availableLanguages)) { $this->set_language($lang); $this->template = "services"; $services = new Service(); $services->fetchAllByFieldValue("published", 1); $this->to_tpl['lang'] = $lang; $this->to_tpl['services'] = $services->list; } else { $this->to_tpl['error'] = "Stranica ne postoji."; $this->template = "404"; } return; }