Exemple #1
0
 public function login()
 {
     $json = array();
     $data = array('login' => strip_tags($_POST['name']), 'pass' => strip_tags($_POST['pass']));
     $valid = array('login' => array('required' => true), 'pass' => array('required' => true));
     $fields = array('login' => 'Логин', 'pass' => 'Пароль');
     $validator = new Libs_Validator($fields);
     if ($validator->isValid($data, $valid)) {
         $res = DAO_Admin_Login::getUser($data['login'], md5($data['pass']));
         if (empty($res)) {
             $json['error'] = true;
             $json['mess'] = 'Не верный логин или пароль';
         } else {
             Libs_Session::start()->setParam('admin_id', $res['id']);
             $json['callback'] = 'function callback(){window.location.reload()}';
         }
     } else {
         $json['error'] = true;
         $json['mess'] = $validator->getErrors();
     }
     $this->putJSON($json);
 }
Exemple #2
0
 /**
  * @param array $data
  * @return bool
  */
 public function updatePage($data = array())
 {
     $tree = new Entity_Tree();
     $tree->setId($this->isAjax() ? strip_tags($_POST['id']) : $data['id']);
     $tree->setTitle($this->isAjax() ? strip_tags($_POST['title']) : $data['tree_title']);
     $tree->setName($this->isAjax() ? strip_tags($_POST['name']) : $data['tree_name']);
     $id = $tree->getId();
     $title = $tree->getTitle();
     $name = $tree->getName();
     $validator = new Libs_Validator(array('title' => 'Титулка', 'name' => 'Имя', 'pid' => 'Ид родителя'));
     $data = array('title' => $title, 'name' => $name, 'id' => $id);
     $valid = array('title' => array('required' => true), 'name' => array('required' => true), 'id' => array('required' => true));
     if (!$validator->isValid($data, $valid)) {
         if ($this->isAjax()) {
             $json = array('error' => true, 'mess' => $validator->getErrors());
             $this->putJSON($json);
         }
         return $validator->getErrors();
     }
     $entity = new Entity_Page();
     $entity->setSeoTitle($this->isAjax() ? strip_tags($_POST['seo_title']) : $data['seo_title']);
     $entity->setSeoKeywords($this->isAjax() ? strip_tags($_POST['seo_keywords']) : $data['seo_keywords']);
     $entity->setSeoDescription($this->isAjax() ? strip_tags($_POST['seo_description']) : $data['seo_description']);
     $id = $this->pageModel->updatePage($tree, $entity);
     if ($this->isAjax()) {
         $json = array();
         if ($id) {
             $json['error'] = false;
             $json['mess'] = 'Обновлено';
             $json['clear'] = false;
             $json['callback'] = 'function callback(){reloadMenu();}';
         } else {
             $json['error'] = true;
             $json['mess'] = 'Ошибка';
         }
         $this->putJSON($json);
     }
     return $id;
 }
Exemple #3
0
 public function updateType($data = null)
 {
     $id = $this->isAjax() ? strip_tags($_POST['id']) : $data['id'];
     $name = $this->isAjax() ? strip_tags($_POST['name']) : $data['name'];
     $title = $this->isAjax() ? strip_tags($_POST['title']) : $data['title'];
     $validator = new Libs_Validator(array('title' => 'Титулка', 'name' => 'Имя', 'pid' => 'Ид родителя'));
     $data = array('title' => $title, 'name' => $name, 'id' => $id);
     $valid = array('title' => array('required' => true), 'name' => array('required' => true), 'id' => array('required' => true));
     if (!$validator->isValid($data, $valid)) {
         if ($this->isAjax()) {
             $json = array('error' => true, 'mess' => $validator->getErrors());
             $this->putJSON($json);
         }
         return $validator->getErrors();
     }
     $seo = $this->isAjax() ? intval($_POST['seo']) == 1 : intval($data['seo']) == 1;
     $json = array();
     $cnt = $this->isAjax() ? count($_POST['cnt']) : count($data['cnt']);
     for ($i = 0; $i < $cnt; $i++) {
         $tmp = array();
         $tmp['name'] = $this->isAjax() ? strip_tags($_POST['name-' . $i]) : $data['name-' . $i];
         $tmp['title'] = $this->isAjax() ? strip_tags($_POST['title-' . $i]) : $data['title-' . $i];
         $tmp['type'] = $this->isAjax() ? strip_tags($_POST['type-' . $i]) : $data['type-' . $i];
         $tmp['variants'] = array();
         $tmpCnt = $this->isAjax() ? count($_POST['variants-' . $i]) : count($data['variants-' . $i]);
         for ($j = 0; $j < $tmpCnt; $j++) {
             $tmp['variants'][] = $this->isAjax() ? strip_tags($_POST['variants-' . $i][$j]) : $data['variants-' . $i][$j];
         }
         $tmp['selects'] = $this->isAjax() ? strip_tags($_POST['selects-' . $i]) : $data['selects-' . $i];
         $tmp['int'] = $this->isAjax() ? intval($_POST['int-' . $i]) == 1 : intval($data['int-' . $i]) == 1;
         $json[] = $tmp;
     }
     $this->typeModel->updateType($id, $title, $name, $json, $seo);
     $result['error'] = false;
     $result['clear'] = false;
     $result['mess'] = 'Тип обновлен';
     if ($this->isAjax()) {
         $this->putJSON($result);
     }
     return $result;
 }
Exemple #4
0
 /**
  * @param array $data
  * @return bool
  */
 public function updateBlock($data = array())
 {
     $tree = new Entity_Tree();
     $tree->setId($this->isAjax() ? strip_tags($_POST['id']) : $data['id']);
     $tree->setTitle($this->isAjax() ? strip_tags($_POST['title']) : $data['tree_title']);
     $tree->setName($this->isAjax() ? strip_tags($_POST['name']) : $data['tree_name']);
     $id = $tree->getId();
     $title = $tree->getTitle();
     $name = $tree->getName();
     $validator = new Libs_Validator(array('title' => 'Титулка', 'name' => 'Имя', 'pid' => 'Ид родителя'));
     $data = array('title' => $title, 'name' => $name, 'id' => $id);
     $valid = array('title' => array('required' => true), 'name' => array('required' => true), 'id' => array('required' => true));
     if (!$validator->isValid($data, $valid)) {
         if ($this->isAjax()) {
             $json = array('error' => true, 'mess' => $validator->getErrors());
             $this->putJSON($json);
         }
         return $validator->getErrors();
     }
     $entity = new Entity_Block();
     $entity->setSide($this->isAjax() ? strip_tags($_POST['block_side']) : $data['block_side']);
     $entity->setText($this->isAjax() ? strip_tags($_POST['block_text']) : $data['block_text']);
     $entity->setIsText($this->isAjax() ? strip_tags($_POST['block_is_text']) : $data['block_is_text']);
     $result = $this->blockModel->updateBlock($tree, $entity);
     if ($this->isAjax()) {
         $json = array();
         if ($result) {
             $json['error'] = false;
             $json['mess'] = 'Обновлено';
             $json['clear'] = false;
             $json['callback'] = 'function callback(){reloadMenu();}';
         } else {
             $json['error'] = true;
             $json['mess'] = 'Ошибка';
         }
         $this->putJSON($json);
     }
     return $result;
 }