예제 #1
0
 /**
  * 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;
 }