| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly; |
| 3 |
|
| 4 |
class Wdk_messages extends Winter_MVC_Controller { |
| 5 |
|
| 6 |
public function __construct(){ |
| 7 |
parent::__construct(); |
| 8 |
} |
| 9 |
|
| 10 |
public function index() |
| 11 |
{ |
| 12 |
$this->load->model('messages_m'); |
| 13 |
|
| 14 |
$total_items = $this->messages_m->total(); |
| 15 |
|
| 16 |
$current_page = 1; |
| 17 |
if(isset($_GET['paged'])) |
| 18 |
$current_page = intval($_GET['paged']); |
| 19 |
|
| 20 |
$this->data['paged'] = $current_page; |
| 21 |
|
| 22 |
$per_page = 20; |
| 23 |
$offset = $per_page*($current_page-1); |
| 24 |
|
| 25 |
$this->data['pagination_output'] = ''; |
| 26 |
|
| 27 |
if(function_exists('wmvc_wp_paginate')) |
| 28 |
$this->data['pagination_output'] = wmvc_wp_paginate($total_items, $per_page); |
| 29 |
|
| 30 |
$this->data['messages'] = $this->messages_m->get_pagination($per_page, $offset); |
| 31 |
|
| 32 |
// Load view |
| 33 |
$this->load->view('wdk_messages/index', $this->data); |
| 34 |
} |
| 35 |
|
| 36 |
public function delete() |
| 37 |
{ |
| 38 |
$id = (int) $this->input->post_get('id'); |
| 39 |
$paged = (int) $this->input->post_get('paged'); |
| 40 |
|
| 41 |
$this->load->model('messages_m'); |
| 42 |
|
| 43 |
$this->messages_m->delete($id); |
| 44 |
|
| 45 |
wp_redirect(admin_url("admin.php?page=wdk_messages&paged=$paged")); |
| 46 |
} |
| 47 |
|
| 48 |
public function edit() |
| 49 |
{ |
| 50 |
$this->load->model('messages_m'); |
| 51 |
|
| 52 |
$id = $this->input->post_get('id'); |
| 53 |
wdk_access_check('messages_m', $id); |
| 54 |
$this->data['db_data'] = NULL; |
| 55 |
|
| 56 |
$this->data['form'] = &$this->form; |
| 57 |
|
| 58 |
//exit($this->db->last_query()); |
| 59 |
|
| 60 |
$rules = array( |
| 61 |
array( |
| 62 |
'field' => 'post_id', |
| 63 |
'label' => __('Listing Id', 'wpdirectorykit'), |
| 64 |
'rules' => 'required' |
| 65 |
), |
| 66 |
array( |
| 67 |
'field' => 'date', |
| 68 |
'label' => __('Date', 'wpdirectorykit'), |
| 69 |
'rules' => '' |
| 70 |
), |
| 71 |
array( |
| 72 |
'field' => 'message', |
| 73 |
'label' => __('Message', 'wpdirectorykit'), |
| 74 |
'rules' => '' |
| 75 |
), |
| 76 |
array( |
| 77 |
'field' => 'is_readed', |
| 78 |
'label' => __('Readed', 'wpdirectorykit'), |
| 79 |
'rules' => '' |
| 80 |
), |
| 81 |
); |
| 82 |
|
| 83 |
if($this->form->run($rules)) |
| 84 |
{ |
| 85 |
// Save procedure for basic data |
| 86 |
$data = $this->messages_m->prepare_data($this->input->post(), $rules); |
| 87 |
|
| 88 |
// Save standard wp post |
| 89 |
|
| 90 |
$insert_id = $this->messages_m->insert($data, $id); |
| 91 |
|
| 92 |
//exit($this->db->last_error()); |
| 93 |
|
| 94 |
// redirect |
| 95 |
if(!empty($insert_id) && empty($id)) |
| 96 |
{ |
| 97 |
wp_redirect(admin_url("admin.php?page=wdk_messages&id=$insert_id&is_updated=true")); |
| 98 |
exit; |
| 99 |
} |
| 100 |
|
| 101 |
} |
| 102 |
|
| 103 |
if(!empty($id)) |
| 104 |
{ |
| 105 |
$this->data['db_data'] = $this->messages_m->get($id, TRUE); |
| 106 |
} |
| 107 |
|
| 108 |
$this->load->view('wdk_messages/edit', $this->data); |
| 109 |
} |
| 110 |
|
| 111 |
} |
| 112 |
|