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