/**
  * 
  * @param type $options
  */
 public function __construct($options = array())
 {
     parent::__construct($options);
     // schedule disconnect from database
     Events::add('framework.controller.destruct.after', function ($name) {
         $database = Registry::get('database');
         $database->disconnect();
     });
     $this->_security = Registry::get('security');
     $this->_serverHost = RequestMethods::server('HTTP_HOST');
     $this->_cache = Registry::get('cache');
     $cfg = Registry::get('configuration');
     $links = $this->getCache()->get('links');
     if ($links !== null) {
         $links = $links;
     } else {
         $links = \App_Model_Link::all(array('active = ?' => true));
         $this->getCache()->set('links', $links);
     }
     $metaData = $this->getCache()->get('global_meta_data');
     if ($metaData !== null) {
         $metaData = $metaData;
     } else {
         $metaData = array('metadescription' => $cfg->meta_description, 'metarobots' => $cfg->meta_robots, 'metatitle' => $cfg->meta_title, 'metaogurl' => $cfg->meta_og_url, 'metaogtype' => $cfg->meta_og_type, 'metaogimage' => $cfg->meta_og_image, 'metaogsitename' => $cfg->meta_og_site_name);
         $this->getCache()->set('global_meta_data', $metaData);
     }
     $this->getLayoutView()->set('links', $links)->set('metatitle', $metaData['metatitle'])->set('metarobots', $metaData['metarobots'])->set('metadescription', $metaData['metadescription'])->set('metaogurl', $metaData['metaogurl'])->set('metaogtype', $metaData['metaogtype'])->set('metaogimage', $metaData['metaogimage'])->set('metaogsitename', $metaData['metaogsitename']);
 }
 /**
  * @before _secured, _admin
  */
 public function edit($id)
 {
     $view = $this->getActionView();
     $link = App_Model_Link::first(array('id = ?' => (int) $id));
     if ($link === null) {
         $view->warningMessage(self::ERROR_MESSAGE_2);
         $this->_willRenderActionView = false;
         self::redirect('/admin/link/');
     }
     $view->set('link', $link);
     if (RequestMethods::post('submitEditLink')) {
         if ($this->checkCSRFToken() !== true) {
             self::redirect('/admin/link/');
         }
         $link->title = RequestMethods::post('title');
         $link->uri = RequestMethods::post('url');
         $link->target = RequestMethods::post('target', '_blank');
         $link->rank = RequestMethods::post('rank', 1);
         $link->active = RequestMethods::post('active');
         if ($link->validate()) {
             $link->save();
             Event::fire('admin.log', array('success', 'Link Id: ' . $link->getId()));
             $view->successMessage(self::SUCCESS_MESSAGE_2);
             self::redirect('/admin/link/');
         } else {
             Event::fire('admin.log', array('fail', 'Link Id: ' . $link->getId()));
             $view->set('errors', $link->getErrors())->set('link', $link);
         }
     }
 }
 /**
  * @before _secured, _admin
  */
 public function settings()
 {
     $view = $this->getActionView();
     $config = Config::all();
     $view->set('config', $config);
     if (RequestMethods::post('submitEditSet')) {
         if ($this->checkCSRFToken() !== true) {
             self::redirect('/admin/');
         }
         $errors = array();
         foreach ($config as $conf) {
             $oldVal = $conf->getValue();
             $conf->value = RequestMethods::post($conf->getXkey(), '');
             if ($conf->validate()) {
                 Event::fire('admin.log', array('success', $conf->getXkey() . ': ' . $oldVal . ' - ' . $conf->getValue()));
                 $conf->save();
             } else {
                 Event::fire('admin.log', array('fail', $conf->getXkey() . ': ' . $conf->getValue()));
                 $errors[$conf->xkey] = array_shift($conf->getErrors());
             }
         }
         if (empty($errors)) {
             $view->successMessage(self::SUCCESS_MESSAGE_2);
             self::redirect('/admin/system/');
         } else {
             $view->set('errors', $errors);
         }
     }
 }
 /**
  * @before _secured, _admin
  */
 public function edit($id)
 {
     $view = $this->getActionView();
     $exam = App_Model_Exam::first(array('id = ?' => (int) $id));
     if ($exam === null) {
         $view->warningMessage(self::ERROR_MESSAGE_2);
         $this->_willRenderActionView = false;
         self::redirect('/admin/exam/');
     }
     $view->set('exam', $exam);
     if (RequestMethods::post('submitEditExam')) {
         if ($this->checkCSRFToken() !== true) {
             self::redirect('/admin/exam/');
         }
         $exam->title = RequestMethods::post('title');
         $exam->active = RequestMethods::post('active');
         $exam->description = RequestMethods::post('description');
         $exam->shortcut = RequestMethods::post('shortcut');
         $exam->rank = RequestMethods::post('rank', 1);
         if ($exam->validate()) {
             $exam->save();
             Event::fire('admin.log', array('success', 'Exam Id: ' . $exam->getId()));
             $view->successMessage(self::SUCCESS_MESSAGE_2);
             self::redirect('/admin/exam/');
         } else {
             Event::fire('admin.log', array('fail', 'Exam Id: ' . $exam->getId()));
             $view->set('errors', $exam->getErrors())->set('exam', $exam);
         }
     }
 }
 /**
  * 
  */
 public function logresolution()
 {
     $this->willRenderActionView = false;
     $this->willRenderLayoutView = false;
     $width = RequestMethods::post('scwidth');
     $height = RequestMethods::post('scheight');
     $res = $width . ' x ' . $height;
     Core::getLogger()->log($res, FILE_APPEND, true, 'scres.log');
 }
 /**
  * Verifies whether the post token was set, else dies with error
  * 
  * @return boolean
  */
 public function verifyRequest()
 {
     $checkPost = RequestMethods::issetpost(self::$_tokenname) && $this->isValidToken(RequestMethods::post(self::$_tokenname));
     $checkGet = RequestMethods::issetget(self::$_tokenname) && $this->isValidToken(RequestMethods::get(self::$_tokenname));
     $this->refreshToken();
     if ($checkGet || $checkPost) {
         return true;
     } else {
         return false;
     }
 }
 /**
  * 
  * @param type $tree
  * @param type $content
  * @return type
  */
 protected function _partial($tree, $content)
 {
     $address = trim($tree["raw"], " /");
     if (StringMethods::indexOf($address, "http") != 0) {
         $host = RequestMethods::server("HTTP_HOST");
         $address = "http://{$host}/{$address}";
     }
     $request = new Request();
     $response = addslashes(trim($request->get($address)));
     return "\$_text[] = \"{$response}\";";
 }
 /**
  * @before _secured, _admin
  * @param type $id
  */
 public function edit($id)
 {
     $view = $this->getActionView();
     $user = App_Model_User::first(array('id = ?' => (int) $id));
     if (NULL === $user) {
         $view->warningMessage(self::ERROR_MESSAGE_2);
         $this->_willRenderActionView = false;
         self::redirect('/admin/user/');
     } elseif ($user->role == 'role_superadmin' && $this->getUser()->getRole() != 'role_superadmin') {
         $view->warningMessage(self::ERROR_MESSAGE_4);
         $this->_willRenderActionView = false;
         self::redirect('/admin/user/');
     }
     $dogs = App_Model_Dog::fetchAllDogsByUserId($user->getId());
     $view->set('user', $user)->set('dogs', $dogs);
     if (RequestMethods::post('submitEditUser')) {
         if ($this->checkCSRFToken() !== true) {
             self::redirect('/admin/user/');
         }
         $errors = array();
         if (RequestMethods::post('password') !== RequestMethods::post('password2')) {
             $errors['password2'] = array('Hesla se neshodují');
         }
         if (RequestMethods::post('email') != $user->email) {
             $email = App_Model_User::first(array('email = ?' => RequestMethods::post('email', $user->email)), array('email'));
             if ($email) {
                 $errors['email'] = array('Tento email je již použit');
             }
         }
         $pass = RequestMethods::post('password');
         if ($pass === null || $pass == '') {
             $salt = $user->getSalt();
             $hash = $user->getPassword();
         } else {
             $salt = PasswordManager::createSalt();
             $hash = PasswordManager::hashPassword($pass, $salt);
         }
         if ($user->imgMain == '') {
             $cfg = Registry::get('configuration');
             $fileManager = new FileManager(array('thumbWidth' => $cfg->thumb_width, 'thumbHeight' => $cfg->thumb_height, 'thumbResizeBy' => $cfg->thumb_resizeby, 'maxImageWidth' => $cfg->photo_maxwidth, 'maxImageHeight' => $cfg->photo_maxheight));
             $photoNameRaw = RequestMethods::post('firstname') . '-' . RequestMethods::post('lastname');
             $photoName = $this->_createUrlKey($photoNameRaw);
             $fileErrors = $fileManager->uploadBase64Image(RequestMethods::post('croppedimage'), $photoName, 'members', time() . '_')->getUploadErrors();
             $files = $fileManager->getUploadedFiles();
             if (!empty($files)) {
                 foreach ($files as $i => $file) {
                     if ($file instanceof \THCFrame\Filesystem\Image) {
                         $imgMain = trim($file->getFilename(), '.');
                         $imgThumb = trim($file->getThumbname(), '.');
                         break;
                     }
                 }
             } else {
                 $errors['croppedimage'] = $fileErrors;
             }
         } else {
             $imgMain = $user->imgMain;
             $imgThumb = $user->imgThumb;
         }
         $user->firstname = RequestMethods::post('firstname');
         $user->lastname = RequestMethods::post('lastname');
         $user->email = RequestMethods::post('email');
         $user->password = $hash;
         $user->salt = $salt;
         $user->imgMain = $imgMain;
         $user->imgThumb = $imgThumb;
         $user->role = RequestMethods::post('role', $user->getRole());
         $user->active = RequestMethods::post('active');
         if (empty($errors) && $user->validate()) {
             $user->save();
             Event::fire('admin.log', array('success', 'User id: ' . $id));
             $view->successMessage(self::SUCCESS_MESSAGE_2);
             self::redirect('/admin/user/');
         } else {
             Event::fire('admin.log', array('fail', 'User id: ' . $id));
             $view->set('errors', $errors + $user->getErrors());
         }
     }
 }
 /**
  * 
  * @param type $options
  */
 public function __construct($options = array())
 {
     parent::__construct($options);
     $this->agent = RequestMethods::server('HTTP_USER_AGENT', 'Curl/PHP ' . PHP_VERSION);
 }
 /**
  * End of application profiling
  * 
  * @param string $identifier
  */
 public function stop($identifier = 'CORE')
 {
     if ($this->isActive()) {
         Event::fire('framework.profiler.stop.before', array($identifier));
         $this->_profiles[$identifier]['requestUri'] = RequestMethods::server('REQUEST_URI');
         $this->_profiles[$identifier]['totalTime'] = round(microtime(true) - $this->_profiles[$identifier]['startTime'], 8);
         $this->_profiles[$identifier]['endMemoryPeakUsage'] = $this->convert(memory_get_peak_usage());
         $this->_profiles[$identifier]['endMomoryUsage'] = $this->convert(memory_get_usage());
         $this->_profiles[$identifier]['dbProfiles'] = $this->_dbProfiles[$identifier];
         $this->_profiles[$identifier]['sessionArr'] = $_SESSION;
         $this->_profiles[$identifier]['postArr'] = $_POST;
         $this->_profiles[$identifier]['getArr'] = $_GET;
         $this->dbStop($identifier);
         $this->process();
         Event::fire('framework.profiler.stop.after', array($identifier));
     }
 }
 /**
  * @before _secured, _admin
  */
 public function edit($id)
 {
     $view = $this->getActionView();
     $dog = App_Model_Dog::fetchDogById((int) $id);
     if ($dog === null) {
         $view->warningMessage(self::ERROR_MESSAGE_2);
         $this->_willRenderActionView = false;
         self::redirect('/admin/dog/');
     }
     $dogExams = $dog->exams;
     $dogExamIds = array();
     if (!empty($dogExams)) {
         foreach ($dogExams as $dogExam) {
             $dogExamIds[] = $dogExam->examId;
         }
     }
     $exams = App_Model_Exam::all(array('active = ?' => true));
     $users = App_Model_User::all(array('role = ?' => 'role_member'), array('id', 'firstname', 'lastname'));
     $view->set('dog', $dog)->set('exams', $exams)->set('dogexamids', $dogExamIds)->set('users', $users);
     if (RequestMethods::post('submitEditDog')) {
         if ($this->checkCSRFToken() !== true) {
             self::redirect('/admin/dog/');
         }
         $errors = array();
         $cfg = Registry::get('configuration');
         $fileManager = new FileManager(array('thumbWidth' => $cfg->thumb_width, 'thumbHeight' => $cfg->thumb_height, 'thumbResizeBy' => $cfg->thumb_resizeby, 'maxImageWidth' => $cfg->photo_maxwidth, 'maxImageHeight' => $cfg->photo_maxheight));
         $imgMain = $imgThumb = '';
         if ($dog->imgMain == '') {
             $photoNameRaw = RequestMethods::post('user') . '-' . RequestMethods::post('dogname');
             $photoName = $this->_createUrlKey($photoNameRaw);
             $fileErrors = $fileManager->uploadBase64Image(RequestMethods::post('croppedimage'), $photoName, 'dog', time() . '_')->getUploadErrors();
             $files = $fileManager->getUploadedFiles();
             if (!empty($fileErrors)) {
                 $errors['croppedimage'] = $fileErrors;
             }
             if (!empty($files)) {
                 foreach ($files as $i => $file) {
                     if ($file instanceof \THCFrame\Filesystem\Image) {
                         $imgMain = trim($file->getFilename(), '.');
                         $imgThumb = trim($file->getThumbname(), '.');
                         break;
                     }
                 }
             }
         } else {
             $imgMain = $dog->imgMain;
             $imgThumb = $dog->imgThumb;
         }
         if ((int) RequestMethods::post('isactive') == 1) {
             App_Model_Dog::updateAll(array('isActive = ?' => true, 'userId = ?' => (int) RequestMethods::post('user')), array('isActive' => 0));
         }
         $dog->userId = RequestMethods::post('user');
         $dog->isActive = RequestMethods::post('isactive', 0);
         $dog->dogName = RequestMethods::post('dogname');
         $dog->race = RequestMethods::post('dograce');
         $dog->dob = RequestMethods::post('dogdob');
         $dog->information = RequestMethods::post('doginfo');
         $dog->active = RequestMethods::post('active');
         $dog->imgMain = $imgMain;
         $dog->imgThumb = $imgThumb;
         if (empty($errors) && $dog->validate()) {
             $dog->save();
             $examsArr = (array) RequestMethods::post('chexam');
             if ($examsArr[0] != '') {
                 $deleteStatus = App_Model_DogExam::deleteAll(array('dogId = ?' => (int) $dog->getId()));
                 if ($deleteStatus != -1) {
                     foreach ($examsArr as $exam) {
                         $de = new App_Model_DogExam(array('dogId' => (int) $dog->getId(), 'examId' => (int) $exam));
                         $de->save();
                         Event::fire('admin.log', array('success', 'Dog id: ' . $dog->getId() . ' has exam ' . $exam));
                     }
                 } else {
                     $errors['exams'] = array('Nastala chyba při ukládání zkoušek');
                 }
             }
             if (RequestMethods::post('uploadmorephotos') == '1') {
                 $fileErrors = $fileManager->newUpload()->uploadImage('secondfile', 'dog', time() . '_')->getUploadErrors();
                 $files = $fileManager->getUploadedFiles();
                 if (!empty($fileErrors)) {
                     $errors['secondfile'] = $fileErrors;
                 }
                 if (!empty($files)) {
                     foreach ($files as $i => $file) {
                         if ($file instanceof \THCFrame\Filesystem\Image) {
                             $info = $file->getOriginalInfo();
                             $photo = new App_Model_Photo(array('galleryId' => 2, 'imgMain' => trim($file->getFilename(), '.'), 'imgThumb' => trim($file->getThumbname(), '.'), 'description' => RequestMethods::post('description'), 'photoName' => pathinfo($file->getFilename(), PATHINFO_FILENAME), 'mime' => $info['mime'], 'format' => $info['format'], 'width' => $file->getWidth(), 'height' => $file->getHeight(), 'size' => $file->getSize()));
                             if ($photo->validate()) {
                                 $photoId = $photo->save();
                                 $dp = new App_Model_DogPhoto(array('dogId' => $dog->getId(), 'photoId' => $photoId));
                                 $dp->save();
                                 Event::fire('admin.log', array('success', 'Photo id: ' . $photoId));
                             } else {
                                 Event::fire('admin.log', array('fail'));
                                 $errors['secondfile'][] = $photo->getErrors();
                             }
                         }
                     }
                 }
                 if (empty($errors)) {
                     Event::fire('admin.log', array('success', 'Dog Id: ' . $id));
                     $view->successMessage(self::SUCCESS_MESSAGE_2);
                     self::redirect('/admin/dog/');
                 } else {
                     Event::fire('admin.log', array('fail'));
                     $view->set('errors', $errors)->set('dog', $dog);
                 }
             } else {
                 Event::fire('admin.log', array('success', 'Dog Id: ' . $id));
                 $view->successMessage(self::SUCCESS_MESSAGE_2);
                 self::redirect('/admin/dog/');
             }
         } else {
             Event::fire('admin.log', array('fail', 'Dog Id: ' . $dog->getId()));
             $view->set('errors', $errors + $dog->getErrors())->set('dog', $dog);
         }
     }
 }
 /**
  * @before _secured, _admin
  */
 public function edit($id)
 {
     $view = $this->getActionView();
     $content = App_Model_PageContent::first(array('id = ?' => (int) $id));
     if (NULL === $content) {
         $view->warningMessage('Obsah nenalezen');
         $this->_willRenderActionView = false;
         self::redirect('/admin/content/');
     }
     $view->set('content', $content);
     if (RequestMethods::post('submitEditContent')) {
         if ($this->checkCSRFToken() !== true) {
             self::redirect('/admin/content/');
         }
         $cache = Registry::get('cache');
         $errors = array();
         $urlKey = $this->_createUrlKey(RequestMethods::post('page'));
         if ($content->getUrlKey() !== $urlKey && !$this->_checkUrlKey($urlKey)) {
             $errors['title'] = array('Stránka s tímto názvem již existuje');
         }
         $content->pageName = RequestMethods::post('page');
         $content->urlKey = $urlKey;
         $content->body = RequestMethods::post('text');
         $content->bodyEn = RequestMethods::post('texten');
         $content->metaTitle = RequestMethods::post('metatitle');
         $content->metaDescription = RequestMethods::post('metadescription');
         $content->active = RequestMethods::post('active');
         if (empty($errors) && $content->validate()) {
             $content->save();
             Event::fire('admin.log', array('success', 'Content id: ' . $id));
             $view->successMessage(self::SUCCESS_MESSAGE_2);
             $cache->erase($content->getUrlKey());
             self::redirect('/admin/content/');
         } else {
             Event::fire('admin.log', array('fail', 'Content id: ' . $id));
             $view->set('errors', $content->getErrors())->set('content', $content);
         }
     }
 }
 /**
  * Action method shows and processes form used for uploading photos into
  * collection specified by param id
  * 
  * @before _secured, _admin
  * @param int $id   collection id
  */
 public function addPhoto($id)
 {
     $view = $this->getActionView();
     $gallery = App_Model_Gallery::first(array('id = ?' => (int) $id, 'active = ?' => true), array('id', 'title'));
     if ($gallery === null) {
         $view->warningMessage(self::ERROR_MESSAGE_2);
         self::redirect('/admin/gallery/');
     }
     $view->set('gallery', $gallery)->set('submstoken', $this->mutliSubmissionProtectionToken());
     if (RequestMethods::post('submitAddPhoto')) {
         if ($this->checkCSRFToken() !== true && $this->checkMutliSubmissionProtectionToken(RequestMethods::post('submstoken')) !== true) {
             self::redirect('/admin/gallery/');
         }
         $errors = array();
         $cfg = Registry::get('configuration');
         $fileManager = new FileManager(array('thumbWidth' => $cfg->thumb_width, 'thumbHeight' => $cfg->thumb_height, 'thumbResizeBy' => $cfg->thumb_resizeby, 'maxImageWidth' => $cfg->photo_maxwidth, 'maxImageHeight' => $cfg->photo_maxheight));
         $fileErrors = $fileManager->uploadImage('secondfile', 'gallery/' . $gallery->getId(), time() . '_')->getUploadErrors();
         $files = $fileManager->getUploadedFiles();
         if (!empty($files)) {
             foreach ($files as $i => $file) {
                 if ($file instanceof \THCFrame\Filesystem\Image) {
                     $info = $file->getOriginalInfo();
                     $photo = new App_Model_Photo(array('galleryId' => $gallery->getId(), 'imgMain' => trim($file->getFilename(), '.'), 'imgThumb' => trim($file->getThumbname(), '.'), 'description' => RequestMethods::post('description'), 'photoName' => pathinfo($file->getFilename(), PATHINFO_FILENAME), 'mime' => $info['mime'], 'format' => $info['format'], 'width' => $file->getWidth(), 'height' => $file->getHeight(), 'size' => $file->getSize()));
                     if ($photo->validate()) {
                         $aid = $photo->save();
                         Event::fire('admin.log', array('success', 'Photo id: ' . $aid . ' in gallery ' . $gallery->getId()));
                     } else {
                         Event::fire('admin.log', array('fail', 'Photo in gallery ' . $gallery->getId()));
                         $errors['secondfile'][] = $photo->getErrors();
                     }
                 }
             }
         }
         $errors['secondfile'] = $fileErrors;
         if (empty($errors['secondfile'])) {
             $view->successMessage(self::SUCCESS_MESSAGE_7);
             self::redirect('/admin/gallery/detail/' . $gallery->getId());
         } else {
             $view->set('errors', $errors);
         }
     }
 }
 /**
  * Static function for redirects
  * 
  * @param string $url
  */
 public static function redirect($url = null)
 {
     $schema = 'http';
     $host = RequestMethods::server('HTTP_HOST');
     if (NULL === $url) {
         header("Location: {$schema}://{$host}");
         exit;
     } else {
         header("Location: {$schema}://{$host}{$url}");
         exit;
     }
 }
 /**
  * @before _secured, _admin
  */
 public function load()
 {
     $this->willRenderActionView = false;
     $this->willRenderLayoutView = false;
     $page = (int) RequestMethods::post('page', 0);
     $search = RequestMethods::issetpost('sSearch') ? RequestMethods::post('sSearch') : '';
     if ($search != '') {
         $whereCond = "nw.created='?' OR nw.expirationDate='?' " . "OR nw.author LIKE '%%?%%' OR nw.title LIKE '%%?%%'";
         $query = App_Model_News::getQuery(array('nw.id', 'nw.author', 'nw.title', 'nw.expirationDate', 'nw.active', 'nw.created'))->wheresql($whereCond, $search, $search, $search, $search);
         if (RequestMethods::issetpost('iSortCol_0')) {
             $dir = RequestMethods::issetpost('sSortDir_0') ? RequestMethods::post('sSortDir_0') : 'asc';
             $column = RequestMethods::post('iSortCol_0');
             if ($column == 0) {
                 $query->order('nw.id', $dir);
             } elseif ($column == 2) {
                 $query->order('nw.title', $dir);
             } elseif ($column == 3) {
                 $query->order('nw.author', $dir);
             } elseif ($column == 4) {
                 $query->order('nw.expirationDate', $dir);
             } elseif ($column == 5) {
                 $query->order('nw.created', $dir);
             }
         } else {
             $query->order('nw.id', 'desc');
         }
         $limit = (int) RequestMethods::post('iDisplayLength');
         $query->limit($limit, $page + 1);
         $news = App_Model_News::initialize($query);
         $countQuery = App_Model_News::getQuery(array('nw.id'))->wheresql($whereCond, $search, $search, $search, $search);
         $newsCount = App_Model_News::initialize($countQuery);
         unset($countQuery);
         $count = count($newsCount);
         unset($newsCount);
     } else {
         $query = App_Model_News::getQuery(array('nw.id', 'nw.author', 'nw.title', 'nw.expirationDate', 'nw.active', 'nw.created'));
         if (RequestMethods::issetpost('iSortCol_0')) {
             $dir = RequestMethods::issetpost('sSortDir_0') ? RequestMethods::post('sSortDir_0') : 'asc';
             $column = RequestMethods::post('iSortCol_0');
             if ($column == 0) {
                 $query->order('nw.id', $dir);
             } elseif ($column == 2) {
                 $query->order('nw.title', $dir);
             } elseif ($column == 3) {
                 $query->order('nw.author', $dir);
             } elseif ($column == 4) {
                 $query->order('nw.expirationDate', $dir);
             } elseif ($column == 5) {
                 $query->order('nw.created', $dir);
             }
         } else {
             $query->order('nw.id', 'desc');
         }
         $limit = (int) RequestMethods::post('iDisplayLength');
         $query->limit($limit, $page + 1);
         $news = App_Model_News::initialize($query);
         $count = App_Model_News::count();
     }
     $draw = $page + 1 + time();
     $str = '{ "draw": ' . $draw . ', "recordsTotal": ' . $count . ', "recordsFiltered": ' . $count . ', "data": [';
     $returnArr = array();
     if ($news !== null) {
         foreach ($news as $_news) {
             if ($_news->active) {
                 $label = "<span class='labelProduct labelProductGreen'>Aktivní</span>";
             } else {
                 $label = "<span class='labelProduct labelProductRed'>Neaktivní</span>";
             }
             $arr = array();
             $arr[] = "[ \"" . $_news->getId() . "\"";
             $arr[] = "\"" . $_news->getTitle() . "\"";
             $arr[] = "\"" . $_news->getAuthor() . "\"";
             $arr[] = "\"" . $_news->getExpirationDate() . "\"";
             $arr[] = "\"" . $_news->getCreated() . "\"";
             $arr[] = "\"" . $label . "\"";
             $tempStr = "\"<a href='/admin/news/edit/" . $_news->id . "' class='btn btn3 btn_pencil' title='Upravit'></a>";
             if ($this->isAdmin()) {
                 $tempStr .= "<a href='/admin/news/delete/" . $_news->id . "' class='btn btn3 btn_trash ajaxDelete' title='Smazat'></a>";
             }
             $arr[] = $tempStr . "\"]";
             $returnArr[] = join(',', $arr);
         }
         $str .= join(',', $returnArr) . "]}";
         echo $str;
     } else {
         $str .= "[ \"\",\"\",\"\",\"\",\"\",\"\",\"\"]]}";
         echo $str;
     }
 }
 /**
  * Function to delete the current user authentication token from the DB and user cookies
  */
 public static function deleteAuthenticationToken()
 {
     if (RequestMethods::cookie('AUTHID') != '') {
         Authtoken::deleteAll(array('token = ?' => RequestMethods::cookie('AUTHID')));
         \setcookie('AUTHID', '', time() - 1800);
     }
 }
 /**
  * 
  * @return null
  */
 public function getHttpReferer()
 {
     if (RequestMethods::server('HTTP_REFERER') === false) {
         return null;
     } else {
         return RequestMethods::server('HTTP_REFERER');
     }
 }