| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly; |
| 3 |
|
| 4 |
class Wdk_resultitem extends Winter_MVC_Controller { |
| 5 |
|
| 6 |
public function __construct(){ |
| 7 |
parent::__construct(); |
| 8 |
} |
| 9 |
|
| 10 |
public function index() |
| 11 |
{ |
| 12 |
$this->load->model('resultitem_m'); |
| 13 |
$this->load->model('field_m'); |
| 14 |
|
| 15 |
$id = 1; |
| 16 |
wdk_access_check('resultitem_m', $id); |
| 17 |
$this->data['db_data'] = NULL; |
| 18 |
|
| 19 |
$this->data['form'] = &$this->form; |
| 20 |
|
| 21 |
$this->data['fields'] = $this->field_m->get(); |
| 22 |
|
| 23 |
$rules = array( |
| 24 |
array( |
| 25 |
'field' => 'resultitem_name', |
| 26 |
'label' => __('Name', 'wpdirectorykit'), |
| 27 |
'rules' => 'required' |
| 28 |
), |
| 29 |
array( |
| 30 |
'field' => 'is_multiline_enabled', |
| 31 |
'label' => __('Multiline enabled', 'wpdirectorykit'), |
| 32 |
'rules' => '' |
| 33 |
), |
| 34 |
array( |
| 35 |
'field' => 'is_label_disable', |
| 36 |
'label' => __('Show only icons', 'wpdirectorykit'), |
| 37 |
'rules' => '' |
| 38 |
), |
| 39 |
array( |
| 40 |
'field' => 'is_show_agent_details', |
| 41 |
'label' => __('Show agent details', 'wpdirectorykit'), |
| 42 |
'rules' => '', |
| 43 |
), |
| 44 |
array( |
| 45 |
'field' => 'resultitem_json', |
| 46 |
'label' => __('Search Form Json/Structure', 'wpdirectorykit'), |
| 47 |
'rules' => '' |
| 48 |
), |
| 49 |
); |
| 50 |
|
| 51 |
if($this->form->run($rules)) |
| 52 |
{ |
| 53 |
|
| 54 |
// Check _wpnonce |
| 55 |
check_admin_referer( 'wdk-resultitem-edit_'.$id, '_wpnonce' ); |
| 56 |
|
| 57 |
// Save procedure for basic data |
| 58 |
$data = $this->resultitem_m->prepare_data(wdk_get_post(), $rules); |
| 59 |
|
| 60 |
// Save standard wp post |
| 61 |
|
| 62 |
if($this->resultitem_m->total() == 0) |
| 63 |
{ |
| 64 |
$id = NULL; |
| 65 |
$data['idresultitem'] = 1; |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
$insert_id = $this->resultitem_m->insert($data, $id); |
| 70 |
|
| 71 |
// redirect |
| 72 |
|
| 73 |
if(!empty($insert_id) && empty($id)) |
| 74 |
{ |
| 75 |
wp_redirect(admin_url("admin.php?page=wdk_resultitem&id=$insert_id&is_updated=true")); |
| 76 |
exit; |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
if(!empty($id)) |
| 81 |
{ |
| 82 |
$this->data['db_data'] = $this->resultitem_m->get($id, TRUE); |
| 83 |
|
| 84 |
// generate/decode used fields |
| 85 |
$used_fields = NULL; |
| 86 |
|
| 87 |
if(is_object($this->data['db_data'])) |
| 88 |
$used_fields = json_decode($this->data['db_data']->resultitem_json); |
| 89 |
$this->data['used_fields'] = array(); |
| 90 |
$this->data['used_fields_sub'] = array(); |
| 91 |
|
| 92 |
if(is_array($used_fields)) |
| 93 |
foreach($used_fields as $key=>$used_fields_sub) |
| 94 |
{ |
| 95 |
foreach($used_fields_sub as $used_field) |
| 96 |
{ |
| 97 |
$this->data['used_fields'][$used_field->field_id] = $used_field; |
| 98 |
$this->data['used_fields_sub'][$key+1][$used_field->field_id] = $used_field; |
| 99 |
} |
| 100 |
|
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
$this->load->view('wdk_resultitem/resultitem_edit', $this->data); |
| 105 |
} |
| 106 |
|
| 107 |
} |
| 108 |
|