Advertisement
Guest User

Untitled

a guest
Dec 23rd, 2011
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.70 KB | None | 0 0
  1. <?php defined('SYSPATH') or die('No direct script access.');
  2.  
  3. class Controller_Admin_Cruds_Tours extends Controller {
  4.  
  5.     function before() {
  6.         $this -> model = Model::factory('admin_cruds_tours');
  7.     }
  8.    
  9.     function action_index() {
  10.         $view = View::factory('admin/cruds/tours/list');
  11.        
  12.         if (isset($_POST["activestatus"]) && isset($_POST['rowid'])) {
  13.             $action = db::update('c_tours', array('is_active' => $_POST['activestatus']), array('id' => $_POST['rowid']));
  14.             if ($action) {
  15.                 die('true');
  16.             } else {
  17.                 die('false');
  18.             }
  19.         }
  20.     }
  21.  
  22.     function action_new() {
  23.         if (isset($_POST["var0"])) {
  24.             $action = $this->model->save($_POST);
  25.             if (!$action) {
  26.                 Message::error(Kohana::message('crud', 'error.entrycreated'));
  27.                 $this->request->redirect('cruds/tours');       
  28.             } else {
  29.                 Message::success(Kohana::message('crud', 'success.entrycreated'));
  30.                 $this->request->redirect('cruds/tours'.(isset($_POST["saveandedit"]) ? "/edit/" . mysql_insert_id() : ""));
  31.             }
  32.  
  33.         }
  34.        
  35.         $view = View::factory('admin/cruds/tours/new');
  36.         $this->response->body($view);
  37.     }
  38.  
  39.     function action_edit() {
  40.         $id = (int) $this->request->param('id');
  41.        
  42.         if (isset($_POST["var0"])) {
  43.             $action = $this->model->update($id, $_POST);
  44.             if (!action) {
  45.                 Message::error(Kohana::message('crud', 'error.entrycreated'));
  46.                 $this->request->redirect('cruds/tours');   
  47.             } else {
  48.                 Message::success(Kohana::message('crud', 'success.entrycreated'));
  49.                 $this->request->redirect('cruds/tours'.(isset($_POST["saveandedit"]) ? "/edit/" . mysql_insert_id() : ""));
  50.             }
  51.  
  52.             $view = View::factory('admin/cruds/tours/edit');
  53.             $view->row = db::fetchone("SELECT * FROM $table WHERE id={$id}");
  54.             $this->response->body($view);
  55.         }
  56.  
  57.         function action_delete() {
  58.             /*
  59.             if(isset($this->request->param('id')) && is_numeric($this->request->param('id'))) {
  60.                 $id = $this->request->param('id');
  61.             }
  62.             */
  63.            
  64.             if (isset($id)) {
  65.                 $action = db::delete("c_tours", array("id" => $_GET["del"]));
  66.                 if ($action) {
  67.                     Message::success(Kohana::message('crud', 'success.entrydeleted'));
  68.                     $this->request->redirect('cruds/tours');
  69.                 } else {
  70.                     Message::error(Kohana::message('crud', 'error.entrydeleted'));
  71.                     $this->request->redirect('cruds/tours');
  72.                 }
  73.             }else
  74.  
  75.             if (isset($_POST["tableitems"])) {
  76.                 foreach ($_POST["tableitems"] as $id) {
  77.                     $action = db::delete("c_tours", array("id" => $id));
  78.                     if (!$action) {
  79.                         Message::error(Kohana::message('crud', 'error.entrydeleted'));
  80.                         $this->request->redirect('cruds/tours');
  81.                     }
  82.                 }
  83.                 Message::success(Kohana::message('crud', 'success.entrydeleted'));
  84.                 $this->request->redirect('cruds/tours');
  85.             }
  86.         }
  87.  
  88.     }
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement