/var/www/hkosl.com/ifapc/html_20210817/IFAPC2021/application/core/MY_Controller.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
<?php
class MY_Controller extends CI_Controller
{
    protected 
$model;
    protected 
$table;
    protected 
$redirect_link;
    protected 
$view_page;
    protected 
$check_sys;
    protected 
$upload_path;

    protected 
$per_page 15;

    protected 
$languages = array();
    protected 
$permission = array();

    protected 
$multiple_language_fields = array();
    protected 
$updated_multiple_language_fields = array();
    protected 
$multiple_language_encpytion_fields = array();
    protected 
$multiple_language_validate_fields = array();

    protected 
$single_language_fields = array();
    protected 
$updated_single_language_fields = array();
    protected 
$single_language_encpytion_fields = array();
    protected 
$single_language_validate_fields = array();

    protected 
$additional_submit_data = array();
    protected 
$ajax_upload_file_fields = array();

    protected 
$run_validation true;
    protected 
$submit_post_data true;
    protected 
$trim_post_data true;
    protected 
$submit_bypass false;
    protected 
$upload_thumb false;
    protected 
$upload_allowed_types 'jpeg|jpg|png';
    protected 
$validate_massages = array();
    protected 
$block_methods = array();
    protected 
$tmp_data = array();

    public function 
_remap($method$parameters = array())
    {
        
$this->check_sys = empty($this->check_sys) ? $this->table $this->check_sys;

        return 
call_user_func_array(array($this$method), $parameters);
    }

    protected function 
check_block_method($method)
    {
        if (
in_array($method$this->block_methods)) {
            
show_404();
            exit();
        }
    }

    public function 
__construct($table)
    {
        
parent::__construct();

        
$this->table $table;

        
$model ucwords($table) . '_model';
        
$this->model = new $model();

        
$this->redirect_link admin_url('bk_' $this->table);

        
$this->load->model('Phprbac_roles_model');
        
$this->load->library('encryption');
        
// $this->load->helper('cryptojs-aes');

        
$this->permission = array(
            
'create' => 'create_' $table,
            
'update' => 'update_' $table,
            
'delete' => 'delete_' $table,
            
'view' => 'view_' $table,
        );

        
// $this->validate_massages = array(
        //     'required' => __('Please enter validated ') . '%s',
        // );

        
$temp_languages Master_type_code_model::get_data_by_type_code('LANGUAGE');
        foreach (
$temp_languages as $temp_language) {
            
$this->languages[$temp_language['code']] = $temp_language['name'];
        }

        
$this->upload_path FCPATH 'assets' DIRECTORY_SEPARATOR 'upload' DIRECTORY_SEPARATOR $this->table DIRECTORY_SEPARATOR;
    }

    protected function 
get_page_link_by_total($total)
    {
        
$this->load->library('pagination');
        
$pagination = array(
            
'total_rows' => $total,
            
'per_page' => $this->per_page,
            
'use_page_numbers' => true,
            
'full_tag_open' => '<div class="col-lg-6 col-lg-offset-3 text-center"><ul class="pagination">',
            
'full_tag_close' => '</ul></div>',
            
'num_tag_open' => '<li>',
            
'num_tag_close' => '</li>',
            
'cur_tag_open' => '<li class="disabled"><li class="active"><a href="#">',
            
'cur_tag_close' => '<span class="sr-only"></span></a></li>',
            
'next_tag_open' => '<li>',
            
'next_tagl_close' => '</li>',
            
'prev_tag_open' => '<li>',
            
'prev_tagl_close' => '</li>',
            
'first_tag_open' => '<li>',
            
'first_tagl_close' => '</li>',
            
'last_tag_open' => '<li>',
            
'last_tagl_close' => '</li>',
        );
        
$this->pagination->initialize($pagination);

        return 
$this->pagination->create_links();
    }

    public function 
index($page 1)
    {
        
$this->check_block_method(__FUNCTION__);
        
check_sys_user_login(array($this->permission['view']));

        
$searches = empty($this->searches) ? $this->input->post('searches') : $this->searches;

        if (!
array_key_exists('model'$this->tmp_data)) {
            
$temp $this->model->get_index_data_by_paginate_and_searching($page$this->per_page$searches'webadmin');

            
$data['model'] = $temp['model'];
            
$total $temp['total'];
        } else {
            
$data['model'] = $this->tmp_data['model'];
            
$total $this->tmp_data['total'];
        }

        if (
$page != && count($data['model']) == 0) {
            
redirect($this->redirect_link);
        }

        if (!empty(
$total)) {
            
$data['page_links'] = $this->get_page_link_by_total($total);
        }

        
// decrypt in 'view' to reduce resource $CI->encryption->decrypt(string)

        
$data["page"] = $page;
        
$data["languages"] = $this->languages;
        
$data["table"] = $this->table;
        
$data["permission"] = $this->permission;
        
$data["block_methods"] = $this->block_methods;
        
$data["name_fields"] = $this->get_concat_single_and_multiple_language_fields('name');
        
$data["encrypt_fields"] = $this->get_concat_single_and_multiple_language_fields('encrypt');

        
$data["searches"] = $searches;

        if (empty(
$this->view_page)) {
            
$this->load->view('webadmin/' $this->table '_index'$data);
        } else {
            
$this->load->view('webadmin/' $this->view_page '_index'$data);
        }
    }

    public function 
sort($page 1)
    {
        
$this->check_block_method(__FUNCTION__);
        
check_sys_user_login(array($this->permission['update']));

        
$sorts $this->input->post('sort');
        if (!empty(
$sorts)) {
            foreach (
$sorts as $key => $sort) {
                
$data = array(
                    
'sort' => $sort,
                );
                
$old_data $this->model->where('id'$key)->where('deleted'0)->first();
                if (
$old_data['sort'] != $sort) {
                    
$this->model->where('id'$key)->where('deleted'0)->update($data);
                }
            }
        }
        
$_SESSION['success_msg'] = __('Update successfully');

        if (
$this->redirect_link == admin_url('bk_' $this->table) && $page != 1) {
            
$this->redirect_link admin_url('bk_' $this->table) . '/index/' $page;
        }

        
redirect($this->redirect_link);
    }

    protected function 
encrypt_fields(&$data)
    {
        
$encrypt_fields $this->get_concat_single_and_multiple_language_fields('encrypt');

        foreach (
$encrypt_fields as $field) {
            if (!empty(
$data[$field])) {
                
$data[$field] = $this->encryption->encrypt($data[$field]);
            }
        }
    }

    protected function 
decrypt_str($str)
    {
        return 
$this->encryption->decrypt($str) ? $this->encryption->decrypt($str) : '';
    }

    protected function 
decrypt_fields(&$data)
    {
        
$encrypt_fields $this->get_concat_single_and_multiple_language_fields('encrypt');

        foreach (
$encrypt_fields as $field) {
            if (!empty(
$data[$field])) {
                
$data[$field] = $this->encryption->decrypt($data[$field]) ? $this->encryption->decrypt($data[$field]) : '';
            }
        }
    }

    protected function 
get_concat_single_and_multiple_language_fields($type)
    {
        switch (
$type) {
            case 
'validate':
                
$single $this->single_language_validate_fields;
                
$multiple $this->multiple_language_validate_fields;
                break;
            case 
'name':
                
$single $this->single_language_fields;
                
$multiple $this->multiple_language_fields;
                break;
            case 
'update':
                
$single $this->updated_single_language_fields;
                
$multiple $this->updated_multiple_language_fields;
                break;
            case 
'encrypt':
                
$single $this->single_language_encpytion_fields;
                
$multiple $this->multiple_language_encpytion_fields;
                break;
        }

        
$temp_array = array();
        if (
$type == 'encrypt') {
            foreach (
$single as $field => $value) {
                
$temp_array[] = $value;
            }
        } else {
            
$temp_array $single;
        }

        foreach (
$this->languages as $lang => $language) {
            foreach (
$multiple as $field => $value) {
                if (
$type == 'name') {
                    
$temp_array[$field $lang] = $value ' [' __($language) . ']';
                } else if (
$type == 'encrypt') {
                    
$temp_array[] = $value $lang;
                } else {
                    
$temp_array[$field $lang] = $value;
                }
            }
        }

        return 
$temp_array;
    }

    public function 
create()
    {
        
$this->check_block_method(__FUNCTION__);
        
check_sys_user_login(array($this->permission['create']));

        if (
array_key_exists('model'$this->tmp_data) && !empty($this->tmp_data['model'])) {
            
$data $this->tmp_data['model'];
            
$data $data->toArray();
            
$this->decrypt_fields($data);
        }

        
$data["languages"] = $this->languages;
        
$data["table"] = $this->table;
        
$data["permission"] = $this->permission;
        
$data["block_methods"] = $this->block_methods;
        
$data["redirect_link"] = $this->redirect_link;

        
$data['validate_fields'] = $this->get_concat_single_and_multiple_language_fields('validate');
        
$data['name_fields'] = $this->get_concat_single_and_multiple_language_fields('name');

        if (empty(
$this->view_page)) {
            
$this->load->view('webadmin/' $this->table '_form'$data);
        } else {
            
$this->load->view('webadmin/' $this->view_page '_form'$data);
        }
    }

    public function 
modify($id)
    {
        
$this->check_block_method(__FUNCTION__);
        
check_sys_user_login(array($this->permission['view']));

        if (!
array_key_exists('model'$this->tmp_data)) {
            
$data $this->model->get_certain($id'webadmin');
        } else {
            
$data $this->tmp_data['model'];
        }

        if (empty(
$data)) {
            
redirect($this->redirect_link);
        } else {
            if (!
is_array($data)) {
                
$data $data->toArray();
            }
            
$this->decrypt_fields($data);
        }

        foreach (
$data as $field => $value) {
            
$data[$field] = htmlspecialchars_decode($data[$field], ENT_QUOTES);
        }

        
$data["id"] = $id;
        
$data["languages"] = $this->languages;
        
$data["table"] = $this->table;
        
$data["permission"] = $this->permission;
        
$data["block_methods"] = $this->block_methods;
        
$data["redirect_link"] = $this->redirect_link;

        
$data['validate_fields'] = $this->get_concat_single_and_multiple_language_fields('validate');
        
$data['name_fields'] = $this->get_concat_single_and_multiple_language_fields('name');

        if (empty(
$this->view_page)) {
            
$this->load->view('webadmin/' $this->table '_form'$data);
        } else {
            
$this->load->view('webadmin/' $this->view_page '_form'$data);
        }
    }

    protected function 
delete_other_tables($id)
    {
        
//override it if necessary;
    
}

    public function 
delete($id$page 1)
    {
        
$this->check_block_method(__FUNCTION__);
        
check_sys_user_login(array($this->permission['delete']));

        
$data = array(
            
"deleted" => 1,
            
"deleted_by" => $_SESSION['sys_user_id'],
            
"deleted_at" => date('Y-m-d H:i:s'),
        );

        if (
array_key_exists('model'$this->tmp_data)) {
            
$model $this->tmp_data['model'];
        } else {
            
$model $this->model->get_certain($id'webadmin');
        }

        if (!empty(
$model)) {
            
$mod $model->update($data);
            
$this->delete_other_tables($id);
            
$_SESSION['success_msg'] = __('Delete successfully');
        }

        if (
$this->redirect_link == admin_url('bk_' $this->table) && $page != 1) {
            
$this->redirect_link admin_url('bk_' $this->table) . '/index/' $page;
        }

        
redirect($this->redirect_link);
    }

    public function 
status($id$status$page 1)
    {
        
$this->check_block_method(__FUNCTION__);
        
check_sys_user_login(array($this->permission['delete']));

        
$data = array(
            
"status" => $status,
            
'updated_by' => $_SESSION["sys_user_id"],
        );

        if (
array_key_exists('model'$this->tmp_data)) {
            
$model $this->tmp_data['model'];
        } else {
            
$model $this->model->get_certain($id'webadmin');
        }

        if (!empty(
$model)) {
            
$model->update($data);
            
$_SESSION['success_msg'] = __('Update successfully');
        }

        if (
$this->redirect_link == admin_url('bk_' $this->table) && $page != 1) {
            
$this->redirect_link admin_url('bk_' $this->table) . '/index/' $page;
        }

        
redirect($this->redirect_link);
    }

    protected function 
update_other_tables($id$current_update_data$action)
    {
        
//override it if necessary;
    
}

    protected function 
validation_error($id null)
    {
        if (empty(
$id)) {
            
$this->create();
        } else {
            
$this->modify($id);
        }
    }

    public function 
real_delete($add_path)
    {
        
$path $this->upload_path $add_path;
        if (
file_exists($path)) {
            
unlink($path);
        }

        if (
$this->upload_thumb) {
            
$path $this->upload_path DIRECTORY_SEPARATOR 'thumb' DIRECTORY_SEPARATOR $add_path;
            if (
file_exists($path)) {
                
unlink($path);
            }
        }
    }

    public function 
ajax_delete_file()
    {
        
//ajax delete
        
check_sys_user_login(array($this->permission['update']));
        
$file_model ucwords($this->table) . '_file_model';
        
$file_model = new $file_model();

        
$result $file_model->get_certain($this->input->post('id'), 'webadmin');

        if (
$result['id']) {
            
$this->real_delete($result['file_name']);

            
$data = array(
                
"deleted" => 1,
                
"deleted_by" => $_SESSION['sys_user_id'],
                
"deleted_at" => date('Y-m-d H:i:s'),
            );
            
$result->update($data);

            
$response = ["response" => "SUCCESS"];
        } else {
            
$response = ["response" => "ERROR"];
        }

        
$response['updated_csrf'] = $this->security->get_csrf_hash();
        echo 
json_encode($response);
    }

    public function 
delete_file()
    {
        
//ajax delete
        
check_sys_user_login(array($this->permission['update']));

        
$result $this->model->get_certain($this->input->post('id'), 'webadmin');

        if (
$result['id']) {
            
$this->real_delete($result[$this->input->post('field') . '_name']);

            
$data[$this->input->post('field') . '_orig_name'] = null;
            
$data[$this->input->post('field') . '_name'] = null;
            
$result->update($data);

            
$response = ["response" => "SUCCESS"];
        } else {
            
$response = ["response" => "ERROR"];
        }

        
$response['updated_csrf'] = $this->security->get_csrf_hash();
        echo 
json_encode($response);
    }

    protected function 
real_upload($upload_field null$config = array())
    {
        if (empty(
$this->input->post('doc_temp_code'))) {
            
check_sys_user_login(array($this->permission['update']), 0);
        } else {
            
check_sys_user_login(array($this->permission['create'], 0));
        }

        if (!empty(
$_FILES[$upload_field]['name'])) {
            
$this->load->library('upload'$config);
            
$this->upload->initialize($config);
            
// File upload
            
if ($this->upload->do_upload($upload_field)) {
                
// Get data about the file
                
$uploadData $this->upload->data();

                if (
$this->upload_thumb) {
                    
$thumb_config['image_library'] = 'gd2';
                    
$thumb_config['source_image'] = $this->upload_path $uploadData['file_name'];
                    
$thumb_config['new_image'] = $this->upload_path DIRECTORY_SEPARATOR 'thumb' DIRECTORY_SEPARATOR $uploadData['file_name'];
                    
$thumb_config['maintain_ratio'] = true;
                    
$thumb_config['width'] = 327;
                    
$thumb_config['height'] = 327;

                    
$this->load->library('image_lib');
                    
$this->image_lib->initialize($thumb_config);
                    if (!
$this->image_lib->resize()) {
                        return array(
'error' => $this->image_lib->display_errors());
                    }
                }

                return array(
'filename' => $uploadData['file_name']);
            } else {
                return array(
'error' => $this->upload->display_errors());
            }
        }
        return array();
    }

    public function 
ajax_upload_file()
    {
        if (
$_SESSION['error_msg']) {
            
$response = ["response" => "ERROR"];
        } else {
            
$uploaded_file $this->real_upload('selected_file', array(
                
'upload_path' => $this->upload_path,
                
'allowed_types' => $this->upload_allowed_types,
                
'max_size' => 2048,
                
'encrypt_name' => true,
            ));

            if (
$uploaded_file['error']) {
                
$response = ["response" => "ERROR"];
            } else if (
$uploaded_file['filename']) {
                
$data['file_name'] = $uploaded_file['filename'];
                
$data['file_orig_name'] = $_FILES['selected_file']['name'];
                
$data['file_info'] = json_encode($_FILES['selected_file']);
                
$data['created_by'] = $_SESSION["sys_user_id"];
                
$data['updated_by'] = $_SESSION["sys_user_id"];
                
$data['type'] = $this->input->post('type');

                
$file_model ucwords($this->table) . '_file_model';
                
$file_model = new $file_model();

                if (!empty(
$this->input->post('file_tmp_code'))) {
                    
$data['file_tmp_code'] = $this->input->post('file_tmp_code');
                    
$data['sort'] = $file_model->where('file_tmp_code'$this->input->post('file_tmp_code'))->max('sort') + 1;
                } else if (!empty(
$this->input->post('ref_id'))) {
                    
$data['ref_id'] = $this->input->post('ref_id');
                    
$data['sort'] = $file_model->where('ref_id'$this->input->post('ref_id'))->max('sort') + 1;
                }
                foreach (
$this->ajax_upload_file_fields[$data['type']] as $field) {
                    
$data[$field] = $this->input->post($field);
                }

                
$result $file_model->create();
                
$result->update($data);

                
$response = ["response" => "SUCCESS""file_name" => $result->file_name"file_orig_name" => $result->file_orig_name"file_id" => $result->id];
            }
        }
        
$response['updated_csrf'] = $this->security->get_csrf_hash();
        echo 
json_encode($response);
    }

    protected function 
upload_file($field)
    {
        
$uploaded_file $this->real_upload($field, array(
            
'upload_path' => $this->upload_path,
            
'allowed_types' => $this->upload_allowed_types,
            
'max_size' => 2048,
            
'encrypt_name' => true,
        ));

        if (
$uploaded_file['error']) {
            
$_SESSION['error_msg'] = __($uploaded_file['error']);
        } else if (
$uploaded_file['filename']) {
            
$this->additional_submit_data[$field '_orig_name'] = $_FILES[$field]['name'];
            
$this->additional_submit_data[$field '_name'] = $uploaded_file['filename'];
        }
    }

    protected function 
submit_bypass($data$id null)
    {
        
//override it if necessary;
    
}

    public function 
submit_form($id null)
    {
        
$this->check_block_method(__FUNCTION__);
        if (empty(
$id)) {
            
check_sys_user_login(array($this->permission['create']));
        } else {
            
check_sys_user_login(array($this->permission['update']));
        }

        if (!
is_numeric($id)) {
            
$id null;
        }

        
$name_fields $this->get_concat_single_and_multiple_language_fields('name');
        
$validate_fields $this->get_concat_single_and_multiple_language_fields('validate');

        foreach (
$name_fields as $field => $name) {
            
$valide_string str_replace('%replace_id%'$id$validate_fields[$field]);
            if (
$this->trim_post_data) {
                
$valides = empty($valide_string) ? array() : explode('|'$valide_string);
                if (!
in_array('trim'$valides)) {
                    
array_unshift($valides'trim');
                }
                
$valide_string implode('|'$valides);
            }
            if (!empty(
$valide_string)) {
                
$this->form_validation->set_rules($field$name_fields[$field], $valide_string$this->validate_massages);
            }
        }

        
//validate data
        
if ($this->run_validation && ($this->form_validation->run() == false || !empty($_SESSION['error_msg']))) {
            
$this->validation_error($id);
            return;
        } else {
            
// alocate $data to update DB
            
$data = array(
                
'updated_at' => date("Y-m-d H:i:s"),
                
'updated_by' => $_SESSION["sys_user_id"],
            );
            if (
$this->input->post('support_units')) {
                
$data['support_units'] = $this->input->post('support_units');
            }
            if (
$this->input->post('support_units_other')) {
                
$data['support_units_other'] = $this->input->post('support_units_other');
            }

            
$update_fields $this->get_concat_single_and_multiple_language_fields('update');
            foreach (
$update_fields as $field => $name) {
                if (
$this->submit_post_data) {
                    
$data[$field] = empty(set_value($field)) ? $this->input->post($field) : set_value($field);
                }
            }

            foreach (
$this->upload_field as $upload_field) {
                
$this->upload_file($upload_field);
            }

            if (!empty(
$this->additional_submit_data)) {
                
$data array_merge($data$this->additional_submit_data);
            }

            
$this->encrypt_fields($data);

            if (
$this->submit_bypass) {
                
$this->submit_bypass($data$id);
            } else {
                if (empty(
$id)) {
                    
$data['created_at'] = date("Y-m-d H:i:s");
                    
$data['created_by'] = $_SESSION["sys_user_id"];
                    if (!
in_array('sort'$this->block_methods)) {
                        
$data['sort'] = $this->model->get_latest_sort($data'webadmin');
                    }

                    
$model $this->model->create();

                    
$other_tables_data $this->update_other_tables($model->id$data'create');

                    if (!empty(
$other_tables_data)) {
                        
$data array_merge($data$other_tables_data);
                    }

                    if (empty(
$_SESSION['error_msg'])) {
                        foreach (
$data as $field => $value) {
                            
$model->update(array($field => $value));
                        }
                        
$_SESSION['success_msg'] = __('Create successfully');

                        
redirect($this->redirect_link);
                    } else {
                        
$this->validation_error();
                        return;
                    }
                } else {
                    
$other_tables_data $this->update_other_tables($id$data'update');

                    if (!empty(
$other_tables_data)) {
                        
$data array_merge($data$other_tables_data);
                    }

                    if (empty(
$_SESSION['error_msg'])) {
                        foreach (
$data as $field => $value) {
                            
$this->model->where('id'$id)->update(array($field => $value));
                        }
                        
$_SESSION['success_msg'] = __('Update successfully');

                        
redirect($this->redirect_link);
                    } else {
                        
$this->validation_error($id);
                        return;
                    }
                }
            }
        }
    }

    public function 
valid_email($str)
    {
        
// copy codeigniter native code because need to call other custom validate method
        
if (function_exists('idn_to_ascii') && preg_match('#\A([^@]+)@(.+)\z#'$str$matches)) {
            
$domain defined('INTL_IDNA_VARIANT_UTS46')
                ? 
idn_to_ascii($matches[2], 0INTL_IDNA_VARIANT_UTS46)
                : 
idn_to_ascii($matches[2]);
            
$str $matches[1] . '@' $domain;
        }
        return (bool) 
filter_var($strFILTER_VALIDATE_EMAIL);
    }

    public function 
valid_required($str)
    {
        return 
is_array($str)
            ? (empty(
$str) === false)
            : (
trim($str) !== '');
    }
}