Ejemplo n.º 1
0
 /**
  * @param bool $id
  * @return bool
  * @throws Kohana_Exception
  *
  * insert or update book
  */
 public function insBook($id = false)
 {
     $_POST = Arr::map('trim', $_POST);
     $post = Validation::factory($_POST);
     $post->rule('name', 'not_empty')->rule('name', 'alpha_numeric', array(':value', false))->rule('name', 'min_length', array(':value', 2))->rule('name', 'max_length', array(':value', 20))->rule('email', 'email')->rule('body', 'not_empty')->rule('body', 'max_length', array(':value', 1024));
     if ($post->check()) {
         if ($id) {
             $book = ORM::factory('Guestbook', $id);
         } else {
             $book = ORM::factory('Guestbook');
         }
         $book->name = Security::encode_php_tags(HTML::chars($_POST['name']));
         $book->email = Security::encode_php_tags(HTML::chars($_POST['email']));
         $book->body = Security::encode_php_tags(HTML::chars($_POST['body']));
         try {
             if ($id) {
                 $book->update();
             } else {
                 $book->create();
             }
             return true;
         } catch (ORM_Validation_Exception $e) {
             return false;
         }
     } else {
         //$errors = $post -> errors('validation');
         return false;
     }
 }
Ejemplo n.º 2
0
 /**
  * @throws Kohana_Exception
  *
  * delete news
  */
 public function action_del()
 {
     $id = $this->request->param('id');
     $id = Security::encode_php_tags(HTML::chars($id));
     $news = new Model_New();
     $news->delNew($id);
     HTTP::redirect($_SERVER['HTTP_REFERER']);
 }
Ejemplo n.º 3
0
 /**
  * @throws HTTP_Exception_404
  *
  * edit book
  */
 public function action_editbook()
 {
     $id = $this->request->param('id');
     $id = Security::encode_php_tags(HTML::chars($id));
     $session = Session::instance();
     $data['page'] = $session->get("page", '');
     $book = new Model_Guestbook();
     $data = $book->getBook($id);
     if ($data) {
         if ($_POST) {
             $book->insBook($id);
             $data['msg'] = 'Запись добавлена';
             HTTP::redirect($_SERVER['HTTP_REFERER']);
         } else {
             $data['msg'] = 'Запись не добавлена';
         }
         $content = View::factory($this->itemBookView);
         $content->bind('data', $data);
         $this->template->content = $content;
     } else {
         throw new HTTP_Exception_404('File not found!');
     }
 }
Ejemplo n.º 4
0
 /**
  * Tests Security::encode_php_tags()
  *
  * @test
  * @dataProvider provider_encode_php_tags
  * @covers Security::encode_php_tags
  */
 public function test_encode_php_tags($expected, $input)
 {
     $this->assertSame($expected, Security::encode_php_tags($input));
 }
Ejemplo n.º 5
0
 /**
  * @throws HTTP_Exception_404
  * @throws Kohana_Exception
  *
  * view pagination list book
  */
 public function action_viewguest()
 {
     if (isset($_GET['page'])) {
         $get['page'] = Security::encode_php_tags(HTML::chars($_GET['page']));
     } else {
         $get['page'] = 1;
     }
     $valid = Validation::factory($get);
     $valid->rule('page', 'numeric');
     if (!$valid->check()) {
         HTTP::redirect('/');
     }
     if ((int) $get['page'] <= 0) {
         $get['page'] = 1;
     }
     $items_per_page = Kohana::$config->load('pagination')->get('default')['items_per_page'];
     $books = new Model_Guestbook();
     $data = $books->getPagination(((int) $get['page'] - 1) * (int) $items_per_page, $items_per_page);
     if ($data) {
         $session = Session::instance();
         $session->set("page", $get['page']);
         $total_items = $books->getCount();
         $content = View::factory($this->bookView);
         $content->bind('data', $data);
         $content->pagination = Pagination::factory(array('total_items' => $total_items));
         $this->template->content = $content;
     } else {
         throw new HTTP_Exception_404('File not found!');
     }
 }
Ejemplo n.º 6
0
 public function action_catalogCounter()
 {
     $gid = Arr::get($_GET, 'gid', 0);
     foreach ($_GET as $key => $value) {
         $key = Security::encode_php_tags($key);
         $value = Security::encode_php_tags($value);
         $ready[$key] = $value;
     }
     $catalog = new Model_Material('group');
     if (isset($ready['go'])) {
         unset($ready['go']);
     }
     unset($ready['gid']);
     $config = Kohana::$config->load('main')->site;
     $search_string = Arr::get($ready, 'searchtext', NULL);
     $count = $catalog->getCountFullMaterials2($gid, $search_string, $ready);
     try {
         $count = $catalog->getCountFullMaterials2($gid, $search_string, $ready);
     } catch (Exception $e) {
         $count = 0;
     }
     echo $count;
 }