· 7 years ago · Sep 24, 2018, 12:14 PM
1<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2/* modules/customer/controllers/admin.php */
3class Admin extends Al_Admin_Controller
4{
5
6 private $moudle;
7
8 function __construct()
9 {
10 parent::__construct();
11 // Check for access permission
12 check('Accommodation');
13 // load MCustomers model
14
15 $this->load->model('MAccommodation');
16 $this->load->model('pages/MPages');
17 $this->load->model('zone/MZone');
18 $this->load->model('accommodation_category/MAccommodationCategory');
19 $this->load->model('accommodation_ideal/MAccommodationIdeal');
20 $this->load->model('accommodation_member/MAccommodationMember');
21 $this->load->model('accommodation_style/MAccommodationStyle');
22 $this->load->model('accommodation_type/MAccommodationType');
23 $this->bep_assets->load_asset_group('dataTables');
24 $this->bep_assets->load_asset_group('JqueryTabs');
25 $this->bep_assets->load_asset_group('JqueryFileUpload');
26 $this->bep_assets->load_asset_group('multiSelect');
27 // Loading helpers
28 $this->load->helper(array('form', 'url'));
29
30 // Loading Librabry
31 $this->load->library('upload');
32
33 // Check for access permission. Only if you have permission, you can access to Calendar
34 $this->module=basename(dirname(dirname(__FILE__)));
35
36 // Set breadcrumb
37 log_message('debug', 'BackendPro : Accomodation class loaded');
38 $this->bep_site->set_crumb($this->lang->line('backendpro_accommodation_'),$this->module.'/admin');
39 mb_internal_encoding('UTF-8');
40 }
41
42 function index() {
43
44 $data['title'] = "Manage Accomodation";
45 $data['accommodation'] = $this->MKaimonokago->getAllSimple($this->module, '','','table_id');
46 $data['header'] = $this->lang->line('backendpro_access_control');
47 $data['page'] = $this->config->item('backendpro_template_admin') . "admin_accommodation_home";
48 $data['module'] = $this->module;
49 $this->load->view($this->_container,$data);
50 }
51
52 function _fields() {
53 $data = array(
54 'name' => db_clean($_POST['name'],25),
55 'zone_id' => id_clean($_POST['zone_id']),
56 'accommodation_type_id' => id_clean($_POST['accommodation_type_id']),
57 'accommodation_style_id' => id_clean($_POST['accommodation_style_id']),
58 'accommodation_member_id' => id_clean($_POST['accommodation_member_id']),
59 'address1' => db_clean($_POST['address1'],25),
60 'address2' => db_clean($_POST['address2'],25),
61 'city' => db_clean($_POST['city'],25),
62 'pincode' => db_clean($_POST['pincode']),
63 'telephone' => db_clean($_POST['telephone']),
64 'fax' => db_clean($_POST['fax']),
65 'email' => db_clean($_POST['email']),
66 'website' => db_clean($_POST['website']),
67 'established' => db_clean($_POST['established']),
68 'last_renewal' => db_clean($_POST['last_renewal']),
69 'rating_star' => db_clean($_POST['rating_star']),
70 'room_numbers' => db_clean($_POST['room_numbers']),
71 'night_minimum' => db_clean($_POST['night_minimum']),
72 'price_minimum' => db_clean($_POST['price_minimum']),
73 'nearest_spot' => db_clean($_POST['nearest_spot']),
74 // 'language_spoken' => db_clean($_POST['language_spoken']),
75 'lat' => db_clean($_POST['lat']),
76 'lng' => db_clean($_POST['lng']),
77 'lang_id' => id_clean($_POST['lang_id']),
78 'table_id' => id_clean($_POST['table_id']));
79 return $data;
80 }
81
82 function create() {
83 $this->bep_assets->load_asset_group('TINYMCE');
84
85 if ($this->input->post('name')) {
86 $rules['name'] = 'required';
87
88 $this->form_validation->set_rules($rules);
89
90 if ($this->form_validation->run() == TRUE) {
91 $this->form_validation->output_errors();
92 //redirect($this->module.'/admin/create');
93 $data['title'] = "Create Accomodation ";
94 // Set breadcrumb
95 $this->bep_site->set_crumb($this->lang->line('kago_create')." ".$this->lang->line('kago_accommodation'),$this->module.'/admin/create');
96 $data['header'] = $this->lang->line('backendpro_access_control');
97 $data['page'] = $this->config->item('backendpro_template_admin') . "admin_accommodation_create";
98 $data['cancel_link']= $this->module."/admin/index/";
99 $data['module'] = $this->module;
100 $this->load->view($this->_container,$data);
101 }else{
102
103 $data = $this->_fields();
104 $id = $this->MKaimonokago->addItem($this->module, $data, $return_id=TRUE);
105 /*if (!file_exists($folder_album)) { //if a folder not exists
106 mkdir($folder_album); //create
107 mkdir($folder_thumb); //create thumbnails
108 }*/
109 //flashMsg('success','Accomodation created');
110 redirect($this->module.'/admin/edit/'.$id.'#tab2','refresh');
111 }
112 }else{
113 $data['title'] = "Create Accomodation ";
114 $this->do_upload();
115 // Set breadcrumb
116 $this->bep_site->set_crumb($this->lang->line('kago_create')." ".$this->lang->line('kago_accommodation'),$this->module.'/admin/create');
117 $data['header'] = $this->lang->line('backendpro_access_control');
118 $data['page'] = $this->config->item('backendpro_template_admin') . "admin_accommodation_create";
119 $data['cancel_link']= $this->module."/admin/index/";
120 $data['module'] = $this->module;
121 $data['zone'] = $this->MZone->getIdwithnoneLang();
122 $data['member'] = $this->MAccommodationMember->getIdwithnoneLang();
123 $data['style'] = $this->MAccommodationStyle->getIdwithnoneLang();
124 $data['type'] = $this->MAccommodationType->getIdwithnoneLang();
125
126 $this->load->view($this->_container,$data);
127 }
128 }
129
130 function edit($id=0)
131 {
132 $this->bep_assets->load_asset_group('TINYMCE');
133 $multilang = $this->preference->item('multi_language');
134 $data['multilang']=$multilang;
135
136 if ($this->input->post('name')) {
137 $rules['name'] = 'required';
138
139 $this->form_validation->set_rules($rules);
140 if ($this->form_validation->run() == FALSE)
141 {
142 $this->form_validation->output_errors();
143 $temp_id = $this->input->post('id');
144 redirect($this->module.'/admin/edit/'.$temp_id,'refresh');
145 }
146 else
147 { print_r($data); die;
148 $data = $this->_fields();
149
150 $this->MKaimonokago->updateItem($this->module, $data);
151 flashMsg('success','Accomodation editted');
152 redirect($this->module.'/admin/index','refresh');
153 }
154 }
155 else
156 {
157 //$data['title'] = "Edit Zone";
158 $data['title'] = $this->lang->line('kago_edit')." ".$this->lang->line('kago_category');
159 $data['page'] = $this->config->item('backendpro_template_admin') . "admin_accommodation_edit";
160 $data['accommodation'] = $this->MKaimonokago->getInfo($this->module,$id);
161
162 $table_id = $this->uri->segment(4);
163
164 if (!count($data['accommodation']))
165 {
166 redirect($this->module.'/accommodation/index','refresh');
167 }
168 $data['header'] = $this->lang->line('backendpro_access_control');
169 $data['translanguages'] =$this->MLangs->getTransLang($this->module,$table_id);
170
171 // Set breadcrumb
172 $this->bep_site->set_crumb($this->lang->line('kago_edit')." ".$this->lang->line('kago_accommodation'),$this->module.'/admin/edit');
173 $data['cancel_link']= $this->module."/admin/index/";
174 $data['module'] = $this->module;
175 $data['zone'] = $this->MZone->getIdwithnoneLang();
176 $data['member'] = $this->MAccommodationMember->getIdwithnoneLang();
177 $data['style'] = $this->MAccommodationStyle->getIdwithnoneLang();
178 $data['type'] = $this->MAccommodationType->getIdwithnoneLang();
179 $data['languages'] =$this->MLangs->getLangDropDownWithId();
180 $this->load->view($this->_container,$data);
181 }
182 }
183
184 function delete($id)
185 {
186 // delete button is hidden in the page, but
187 // check if parentid is not 0
188 $accommodation = $this->MAccommodation->getAccommodation($id);
189 //print_r($accommodation);
190 //$parentid = $accommodation['parentid'];
191 $this->MAccommodation->deleteAccommodation($id);
192 flashMsg('success',$this->lang->line('userlib_accommodation_deleted'));
193 redirect('accommodation/admin/index','refresh');
194
195 }
196
197 function langcreate()
198 {
199 $this->bep_assets->load_asset_group('TINYMCE');
200 if ($this->input->post('name'))
201 {
202 // info is filled out, so the followings
203 $this->MAccommodation->addAccommodation();
204 // This is CI way to show flashdata
205 // $this->session->set_flashdata('message','Page updated');
206 // But here we use Bep way to display flash msg
207 flashMsg('success',$this->lang->line('kago_translation_added'));
208 redirect('accommodation/admin/index','refresh');
209 }
210 else
211 {
212 // segment 4 is table_id
213 $table_id = $this->uri->segment(4);
214 // need to send it to a view for table_id
215 $data['table_id']=$table_id;
216 $lang_id = $this->uri->segment(5);
217 $data['lang_id']=$lang_id;
218 // get all the languages
219 $data['languages'] =$this->MLangs->getLangDropDownWithId();
220 // get all the translated languages
221 $data['translanguages'] =$this->MLangs->getTransLang($this->module,$table_id);
222 $table ='languages';
223 $selected_lang = $this->MKaimonokago->getinfo($table,$lang_id);
224 $data['selected_lang']= $selected_lang;
225 $data['accommodation'] = $this->MAccommodation->getAccommodation($table_id);
226 $data['title'] = $this->lang->line('kago_add_translation').ucwords($selected_lang['langname']);
227 $data['page'] = $this->config->item('backendpro_template_admin') . "admin_lang_create";
228 $selected_lang=ucfirst($selected_lang['langname']);// using this in bread crumb
229 $this->bep_site->set_crumb($this->lang->line('kago_edit_home'),'menus/admin/edit/');
230 $data['header'] = $this->lang->line('backendpro_access_control');
231 $data['cancel_link']= $this->module."/admin/index/";
232 $data['module'] = $this->module;
233 $this->load->view($this->_container,$data);
234 }
235 }
236
237 function upload() {
238 error_reporting(E_ALL | E_STRICT);
239
240 $this->load->helper("upload.class");
241
242 $upload_handler = new UploadHandler();
243
244 header('Pragma: no-cache');
245 header('Cache-Control: no-store, no-cache, must-revalidate');
246 header('Content-Disposition: inline; filename="files.json"');
247 header('X-Content-Type-Options: nosniff');
248 header('Access-Control-Allow-Origin: *');
249 header('Access-Control-Allow-Methods: OPTIONS, HEAD, GET, POST, PUT, DELETE');
250 header('Access-Control-Allow-Headers: X-File-Name, X-File-Type, X-File-Size');
251
252 switch ($_SERVER['REQUEST_METHOD']) {
253 case 'OPTIONS':
254 break;
255 case 'HEAD':
256 case 'GET':
257 $upload_handler->get();
258 break;
259 case 'POST':
260 if (isset($_REQUEST['_method']) && $_REQUEST['_method'] === 'DELETE') {
261 $upload_handler->delete();
262 } else {
263 $upload_handler->post();
264 }
265 break;
266 case 'DELETE':
267 $upload_handler->delete();
268 break;
269 default:
270 header('HTTP/1.1 405 Method Not Allowed');
271 }
272
273 }
274
275 function do_upload() {
276
277 $upload_path_url = base_url().'assets/uploads/accommodation/original/';
278
279 $config['upload_path'] = FCPATH.'assets/uploads/accommodation/thumbs/';
280 $config['allowed_types'] = 'jpg';
281 $config['max_size'] = '30000';
282
283 //$this->load->library('upload', $config);
284
285 if ( ! $this->upload->do_upload())
286 {
287 $error = array('error' => $this->upload->display_errors());
288 //$this->load->view('upload', $error);
289 }
290 else
291 {
292 $data = $this->upload->data();
293 /*
294 // to re-size for thumbnail images un-comment and set path here and in json array
295 $config = array(
296 'source_image' => $data['full_path'],
297 'new_image' => $this->$upload_path_url '/thumbs',
298 'maintain_ration' => true,
299 'width' => 80,
300 'height' => 80
301 );
302
303 $this->load->library('image_lib', $config);
304 $this->image_lib->resize();
305 */
306 //set the data for the json array
307 $info->name = $data['file_name'];
308 $info->size = $data['file_size'];
309 $info->type = $data['file_type'];
310 $info->url = $upload_path_url .$data['file_name'];
311 $info->thumbnail_url = $upload_path_url .$data['file_name'];//I set this to original file since I did not create thumbs. change to thumbnail directory if you do = $upload_path_url .'/thumbs' .$data['file_name']
312 $info->delete_url = base_url().'upload/deleteImage/'.$data['file_name'];
313 $info->delete_type = 'DELETE';
314 if (IS_AJAX) { //this is why we put this in the constants to pass only json data
315 echo "prince"; die;
316 echo json_encode(array($info));
317 //this has to be the only the only data returned or you will get an error.
318 //if you don't give this a json array it will give you a Empty file upload result error
319 //it you set this without the if(IS_AJAX)...else... you get ERROR:TRUE (my experience anyway)
320 }else { // so that this will still work if javascript is not enabled
321 $file_data['upload_data'] = $this->upload->data();
322 print_r($file_data); die;
323 $this->load->view('admin/upload_success', $file_data);
324 }
325 }
326
327}
328
329 public function deleteImage($file){
330 //gets the job done but you might want to add error checking and security
331
332 $success =unlink(FCPATH.'uploads/' .$file);
333 //info to see if it is doing what it is supposed to
334 $info->sucess =$success;
335 $info->path =base_url().'uploads/' .$file;
336 $info->file =is_file(FCPATH.'uploads/' .$file);
337 if (IS_AJAX) {//I don't think it matters if this is set but good for error checking in the console/firebug
338 echo json_encode(array($info));
339 } else { //here you will need to decide what you want to show for a successful delete
340 $file_data['delete_data'] = $file;
341 $this->load->view('admin/delete_success', $file_data);
342 }
343 }
344
345}
346?>