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