<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Dashboard extends MY_Controller {

    var $data_day;
    var $user, $noaroom;

    public function __construct() {
        parent::__construct();
        $this->load->model('booking');
            $this->load->helper('download');
            $this->load->library('zip');
        $this->data_day = $this->booking->data_day();
        $this->user = $this->session->userdata('name');
        $this->operator_id = $this->session->userdata('operator_id');
        if(get_ap('group',$this->operator_id)==1){ }else{ redirect("","refresh");}
        $this->noaroom[1] = "واحد سرير مزدوج";
        $this->noaroom[2] = "اثنين  سرير  مزدوج";
        $this->noaroom[3] = " واحد مزدوج واثنين فردي";
        $this->noaroom[4] = "اربعة فردي";
    }
       public function dbexport(){
           $this->booking->dbexport();
           
       }
    public function index() {
        $this->all();
    }

    function sum_bill($catid) {
        $this->db->select_sum('text1');
        $this->db->where(" catid=$catid ");
        $query = $this->db->get('model_billshawly')->row_array();
        return $query['text1'];
    }

    function all() {
        $this->db->from('booking_rooms')->where("  conter=1 ");
        $data['all_rooms_1'] = $this->db->count_all_results();

        $this->db->from('booking_rooms')->where("  conter=2 ");
        $data['all_rooms_2'] = $this->db->count_all_results();

        $this->db->from('booking_rooms')->where("  conter=3 ");
        $data['all_rooms_3'] = $this->db->count_all_results();
        $this->db->from('booking');
        $this->db->where("  datetext4 = '" . $this->data_day . "'  ");
        $data['all_booking_day'] = $this->db->count_all_results();
        $this->db->select_sum('bill');
        $this->db->where(" ( billexport=''  ) and datetext4 = '" . $this->data_day . "' ");
        $query = $this->db->get('booking')->row_array();
        $data['all_bill'] = $query['bill'];
        if (!$data['all_bill'])
            $data['all_bill'] = 0;
        $this->db->select_sum('knet');
        $this->db->where("  ( billexport=''  ) and datetext4 = '" . $this->data_day . "' and knet!=''");
        $query = $this->db->get('booking')->row_array();
        $data['all_knet'] = $query['knet'];

        $data['all_cash'] = ($this->sum_bill('1  and text3!=1') + $this->sum_bill('4') + $this->sum_bill('6')) - ($this->sum_bill('2  and text3!=1') + $this->sum_bill('5') + $this->sum_bill('3') + $this->sum_bill('8'));

        $data['all_cash'] = ($data['all_bill'] - $data['all_knet']) + $data['all_cash'];
        $this->db->from('booking');
        $this->db->where("  counter=1 ");
        $data['all_rooms'] = $this->db->count_all_results();

        $this->db->from('booking');
        $this->db->where("  counter=1 ");
        $iamgeall = 0;
        $data['all_roomscid'] = $this->db->get()->result_array();
        foreach ($data['all_roomscid'] as $row) {

            $query = $this->db->get_where('booking_clints', array('cid' => $row['cid']));
            $clints = $query->row_array();
            if ($clints['file1'] or $clints['file2']) {
                
            } else {
                $iamgeall++;
            }
        }
        if ($iamgeall > 0)
            $data['msg'][] = "يرجا ادخال عدد  :  $iamgeall بطايق عملاء";


        $data['msgview']='      <div class="row">
          <div class="box box-success box-solid">
            <div class="box-header with-border">
              <h3 class="box-title">رسالة جديد</h3>

           
              <!-- /.box-tools -->
            </div>
            <!-- /.box-header -->
            <div class="box-body">
              The body of the box
            </div>
             <br>  
               <div class="box-tools pull-right">
                     <a class="btn btn-success btn-xs" style="    margin-top: -20px;
    margin-right: 20px;">تم القراءة والتاكيد</a>
              </div>
       
             <br>
            <!-- /.box-body -->
          </div>
          <!-- /.box -->
        </div>';
        $this->db->from('booking');
        $this->db->where("  datetext4 = '" . $this->data_day . "'  ");
        $data['all_booking_day'] = $this->db->count_all_results();

        $this->db->from('booking');
        $this->db->where("  `counter` = '1' and (  timeend < " . $this->booking->tissme_now() . ") ");
        $data['clintsout'] = $this->db->count_all_results();



        $this->db->from('booking_rooms');
        $this->db->order_by('id', 'asc');

        $data['all_groups'] = $this->db->get()->result_array();
        $i = 0;
        foreach ($data['all_groups'] as $row) {

            $this->db->from('booking');
            $this->db->order_by('id', 'desc');
            $this->db->where(" room=" . $row['name'] . " and counter=1");

            if ($this->db->count_all_results() > 0 and $row['conter'] == '1') {

                $this->db->where('name', $row['name'])->where('conter', '1')->update('booking_rooms', ['conter' => '2']);
                //$data['all_groups'][$i]['conter']=$row['conter']='2';
            }
            /// if ($this->db->count_all_results() == 0 and $row['conter'] != '3') {
            ///      $this->db->where('room', $row['name'])->where('conter', '2')->update('booking_rooms', ['conter' => '1']);
            //$data['all_groups'][$i]['conter']=$row['conter']='1';
            ///  }


            $data['all_groups'][$i]['color'] = 'bg-yellow';
            $data['all_groups'][$i]['timeend'] = '';
            if ($row['conter'] == 1) {
                $data['all_groups'][$i]['color'] = 'bg-green';
                $data['all_groups'][$i]['noa'] = $this->noaroom[$row['noa']];
            }



            if ($row['conter'] == 4)
                $data['all_groups'][$i]['color'] = 'bg-gray';

            $data['all_groups'][$i]['bookig'] = '';

            if ($row['conter'] == 3) {
                $query = $this->db->order_by('id', 'desc')->limit('1')->get_where('booking', array('room' => $row['name'], 'counter' => '2'));

                $data['edit'] = $query->row_array();
                 $data['all_groups'][$i]['checkout'] = $data['edit']['checkout'];
                   
                        $data['all_groups'][$i]['checkclean'] = $data['edit']['checkclean'];
                $data['all_groups'][$i]['bookingid'] = $data['edit']['id'];
                $data['all_groups'][$i]['timeend2'] = $data['edit']['timeend2'];
            }

            if ($row['conter'] == 2) {
                $query = $this->db->order_by('id', 'desc')->limit('1')->get_where('booking', array('room' => $row['name'], 'counter' => '1'));

                $data['edit'] = $query->row_array();
                $MshrfAll2 = explode(" ", trim($data['edit']['name']));
                if (!isset($MshrfAll2[1]))
                    $MshrfAll2[1] = '';
                $data['all_groups'][$i]['bookingname'] = $MshrfAll2[0] . '  ' . $MshrfAll2[1];
                $data['all_groups'][$i]['bookingid'] = $data['edit']['id'];
                $data['all_groups'][$i]['outsite'] = $data['edit']['outsite'];
                
                   $data['all_groups'][$i]['checkout'] = $data['edit']['checkout'];
                   
                        $data['all_groups'][$i]['checkclean'] = $data['edit']['checkclean'];

                $data['all_groups'][$i]['color'] = 'bg-red';
                if ((int) $data['edit']['timeend'] < (int) $this->booking->tissme_now())
                    $data['all_groups'][$i]['color'] = 'bg-primary';
                $data['all_groups'][$i]['timeend'] = $data['edit']['timeend'];
                $data['all_groups'][$i]['commentnbeh'] = $data['edit']['commentnbeh'];
            }

            $i++;
        }



        $data['title'] = 'الرئيسية';
        $data['view'] = '../controllers/views/dashboard';
        $this->load->view('../controllers/views/layout', $data);
    }

    public function moveroom($id) {
        $roomnew = $this->input->post('roomnew');
        if (isset($roomnew)) {


            $query = $this->db->get_where('booking', array('id' => $id));
            $data['show'] = $query->row_array();
            $this->db->where('name', $data['show']['room'])->update('booking_rooms', array('conter' => '3'));
            $this->db->where('name', $roomnew)->update('booking_rooms', array('conter' => '2'));


            $this->db->where('id', $data['show']['id'])->update('booking', array('room' => $roomnew, 'msgmove' => $this->input->post('msgmove'), 'timemove' => $this->booking->tissme_now(), 'oldroom' => $data['show']['room']));


            $this->session->set_flashdata('msg', 'تم   عمل نقل الشقة بفضل الله!');
            ///$this->booking->add_rep_user("نقل شقة ".$data['show']['room']);
        }
        redirect(base_url() . 'dashboard');
    }

    public function backroom($id) {
        $roomnew = $this->input->post('roomnew');
        $query = $this->db->get_where('booking', array('id' => $id));
        $data['show'] = $query->row_array();
        $this->db->where('name', $data['show']['room'])->update('booking_rooms', array('conter' => '2'));


        $this->db->where('id', $data['show']['id'])->update('booking', array('counter' => '1', 'timeend2' => ''));
        $this->booking->add_rep_user(" استرجاع " . $data['show']['room']);
        $this->session->set_flashdata('msg', 'تم  استرجاع  الشقة بفضل الله!');
        redirect(base_url() . 'dashboard');
    }

    public function commentnbeh($id) {
        $commentnbeh = $this->input->post('commentnbeh');


        $this->db->where('id', $id)->update('booking', array('commentnbeh' => $commentnbeh, 'comment7' => $this->input->post('comment7'), 'comment8' => $this->input->post('comment8')));



        $this->session->set_flashdata('msg', 'تم   عمل وضع التنبيه بفضل الله!');
        redirect(base_url() . 'dashboard');
    }

    public function deltnbeh($id) {


        $this->db->where('id', $id)->update('booking', array('commentnbeh' => ''));



        $this->session->set_flashdata('msg', 'تم مسح  التنبيه بفضل الله!');
        redirect(base_url() . 'dashboard');
    }

    public function idend($id) {

        $query = $this->db->get_where('booking', array('id' => $id));
        $data['show'] = $query->row_array();



        $query = $this->db->get_where('booking_rooms', array('name' => $data['show']['room']));
        $data['room'] = $query->row_array();
        $comment = explode("##", $data['room']['comment']);
        $data['all_groups'] = array();
             $nao[1] = "الصالة";
        $nao[2] = " الماستر";
        $nao[3] = " الثانية";
        $nao[4] = " المطبخ";
        $nao[5] = "الحمام";
           $nao[6] = "حمام المساتر";
              $nao[7] = "الثالثة";

        $max = count($comment);
        if ($max > 30)
            $max = 24;
        for ($i = 0; $i < $max; $i++) {

            $commentsss = explode("|", $comment[$i]);
            if (isset($commentsss[1])) {

                $query = $this->db->get_where('booking_mhtwa', array('id' => $commentsss[1]));

                //$query = $this->db->get_where('booking_mhtwa', array('id' => $commentsss[1], 'text8' => '1'));

                $row = $query->row_array();
                if (isset($row['text1'])) {
                    $data['all_groups'][$i]['text1'] = $row['text1'];
                    $data['all_groups'][$i]['text2'] = $row['text2'];
                    $data['all_groups'][$i]['text3'] = $row['text3'];
                    $data['all_groups'][$i]['noa'] = '';
                    if ($row['text5'])
                        $data['all_groups'][$i]['noa'] = $nao[$row['text5']];
                    $query = $this->db->get_where('booking_mhtwah', array('text1' => $data['show']['room'], 'text2' => $row['id']));
                    $mhtwah = $query->row_array();
                    $data['all_groups'][$i]['com'] = '';
                    if (isset($commentsss[1]))
                        $data['all_groups'][$i]['com'] = $mhtwah['text3'];
                }
            }
        }



        if ($data['show']['counter'] == 1)
            $this->db->where('name', $data['show']['room'])->update('booking_rooms', array('conter' => '3'));

        $comment7 = $this->input->post('comment7');

        if ($this->input->post('comment1')) {


            $billback = $this->input->post('comment2');
            $billback2 = $this->input->post('comment22');
            if ($this->input->post('comment2') > 0) {




                $dataadd = array(
                    'catid' => '1',
                    'text3' => '',
                    'text1' => $this->input->post('comment2'),
                    'text2' => " غرامة شقة " . $data['show']['room'] . "بتاريخ    : " . $data['show']['datetext4'] . "رقم التسكين : " . $id,
                    'dateadd' => $this->data_day,
                    'counter' => '1',
                );
                $dataadd = $this->security->xss_clean($dataadd);
                $result = $this->db->insert('model_billshawly', $dataadd);
            }

            if ($billback != $billback2) {


                $this->booking->add_rep_user("  غرامة تاخير لمدة  " . $this->input->post('comment1') . " ساعات مدفع     $billback والمطلوب $billback2 تسكين رقم" . $data['show']['id']);
            }


            $comment7 = '';
            $this->db->where('id', $data['show']['id'])->update('booking', array('comment1' => $this->input->post('comment1'), 'comment2' => $this->input->post('comment2'), 'comment3' => $this->input->post('comment7'), 'comment5' => 'no'));
        }


        if ($data['show']['counter'] == 1) {

            $this->db->where('id', $data['show']['id'])->update('booking', array('counter' => '2', 'timeend2' => $this->booking->tissme_now(), 'dataend' => $this->data_day, 'user2' => $this->session->userdata('name'), 'comment7' => $comment7));
            $data['show']['timeend'] = $this->booking->tissme_now();
        } else {
            $data['show']['timeend'] = $data['show']['timeend2'];
        }





        $this->session->set_flashdata('msg', 'تم   عمل خروج بفضل الله!');


        $this->load->view('../controllers/views/show/printidout', $data);
        //redirect(base_url() . 'dashboard');  
    }

    public function toopen($id) {
        $this->db->where('name', $id)->update('booking_rooms', array('conter' => '1'));
        $this->session->set_flashdata('msg', 'تم    التغير الى متاحة بفضل الله!');

        redirect(base_url() . 'dashboard');
    }

    public function cleanfinsh($id) {
        $query = $this->db->get_where('booking', array('id' => $id));
        $data['show'] = $query->row_array();
        $this->db->where('name', $data['show']['room'])->update('booking_rooms', array('conter' => '1'));
        $this->session->set_flashdata('msg', 'تم    التغير الى متاحة بفضل الله!');

        $this->db->where('id', $data['show']['id'])->update('booking', array('timecleanfinsh' => $this->booking->tissme_now()));
        redirect(base_url() . 'dashboard');
    }

    public function roomtoprom($id) {
        $this->db->where('name', $id)->update('booking_rooms', array('conter' => '4'));
        $this->session->set_flashdata('msg', 'تم    التغير الى صيانة بفضل الله!');


        redirect(base_url() . 'dashboard');
    }

    public function gowait($id) {

        $query = $this->db->get_where('booking', array('id' => $id));
        $data['show'] = $query->row_array();



        $query = $this->db->get_where('booking_rooms', array('name' => $data['show']['room']));
        $data['room'] = $query->row_array();
        $comment = explode("##", $data['room']['comment']);
        $data['all_groups'] = array();
        $nao[1] = "الصالة";
        $nao[2] = " الماستر";
        $nao[3] = " الثانية";
        $nao[4] = " المطبخ";
        $nao[5] = "الحمام";
           $nao[6] = "حمام المساتر";
              $nao[7] = "الثالثة";
       
        $max = count($comment);
        if ($max > 30)
            $max = 24;
        for ($i = 0; $i < $max; $i++) {

            $commentsss = explode("|", $comment[$i]);
            if (isset($commentsss[1])) {


                $query = $this->db->get_where('booking_mhtwa', array('id' => $commentsss[1], 'text8' => '1'));

                $row = $query->row_array();
                if (isset($row['text1'])) {
                    $data['all_groups'][$i]['text1'] = $row['text1'];
                    $data['all_groups'][$i]['text2'] = $row['text2'];
                    $data['all_groups'][$i]['text3'] = $row['text3'];
                    $data['all_groups'][$i]['noa'] = '';
                    if ($row['text5'])
                        $data['all_groups'][$i]['noa'] = $nao[$row['text5']];
                    $query = $this->db->get_where('booking_mhtwah', array('text1' => $data['show']['room'], 'text2' => $row['id']));
                    $mhtwah = $query->row_array();
                    $data['all_groups'][$i]['com'] = '';
                    if (isset($commentsss[1]))
                        $data['all_groups'][$i]['com'] = $mhtwah['text3'];
                }
            }
        }






        $this->db->where('name', $data['show']['room'])->update('booking_rooms', array('conter' => '3'));

        $comment7 = $this->input->post('comment7');

        if ($this->input->post('comment1')) {
            $comment7 = '';
            $this->db->where('id', $data['show']['id'])->update('booking', array('comment1' => $this->input->post('comment1'), 'comment2' => $this->input->post('comment2'), 'comment3' => $this->input->post('comment7'), 'nowait' => $this->input->post('nowait'), 'comment5' => 'wait'));
            $this->db->where('cid', $data['show']['cid'])->update('booking_clints', array('oky' => 'ok', 'comment' => "عليه مبلغ " . $this->input->post('comment2') . "  بتاريخ " . $this->data_day));
        }




        $this->db->where('id', $data['show']['id'])->update('booking', array('counter' => '2', 'timeend2' => $this->booking->tissme_now(), 'dataend' => $this->data_day, 'user2' => $this->session->userdata('name'), 'comment7' => $comment7));


        $data['show']['timeend'] = $this->booking->tissme_now();

        $billback2 = $this->input->post('comment2');
        $billback1 = $this->input->post('comment2old');
        if ($billback1 != $billback2) {

            $this->booking->add_rep_user("  تحويل ايجار لم يتم الاستراد   عليه مبلغ " . $billback1 . "        والمطلوب $billback2 تسكين رقم" . $data['show']['id']);
        }


        $this->session->set_flashdata('msg', 'تم   عمل خروج بفضل الله!');
        $this->load->view('../controllers/views/show/printidout', $data);


        //redirect(base_url() . 'dashboard');  
    }

    public function idrenew($id) {

        $query = $this->db->get_where('booking', array('id' => $id));
        $data['show'] = $query->row_array();
        $this->db->where('id', $data['show']['id'])->update('booking', array('counter' => '2'));


        $data = array(
            'name' => $data['show']['name'],
            'datetext4' => $this->data_day,
            'mobile' => $data['show']['mobile'],
            'cid' => $data['show']['cid'],
            'room' => $data['show']['room'],
            'day' => $this->input->post('day'),
            'billexport' => '',
            'bill' => ($this->input->post('bill') + $this->input->post('knet')),
            'timeenter' => $data['show']['timeenter'],
            'timeend' => ($data['show']['timeend'] + (24 * 60 * 60 * $this->input->post('day'))),
            'billprint' => $this->input->post('billprint'),
            'counter' => '1',
            'knet' => $this->input->post('knet'),
            'comment8' => $this->input->post('comment8'),
            'noa' => $data['show']['noa'],
            '3gd' => $data['show']['3gd'],
            'comment' => $data['show']['comment'],
            'commentnbeh' => $data['show']['commentnbeh'],
            'bookingid' => $data['show']['bookingid'],
            'timerenew' => $this->booking->tissme_now(),
            'user' => $this->user,
        );
        /// print_r($data);exit;
        $data = $this->security->xss_clean($data);
        $result = $this->db->insert('booking', $data);

        $this->session->set_flashdata('msg', 'تم عمل التمديد بفضل الله');
        redirect(base_url() . 'dashboard');
    }

    public function blacklist($id) {

        $query = $this->db->get_where('booking_clints', array('id' => $id));
        $data['show'] = $query->row_array();


        $edit_data = array(
            'oky' => '',
        );
        $edit_data = $this->security->xss_clean($edit_data);
        $result = $this->db->where('id', $id)->update('booking_clints', $edit_data);


        $this->booking->add_rep_user(" تم ازالة البلاك لست  عن  الرقم المدني  " . $data['show']['cid'] . "    والسبب  كان " . $data['show']['comment']);

        $this->session->set_flashdata('msg', 'تم عمل ازالة البلاك لست بفضل الله');
        redirect(base_url() . 'dashboard');
    }

    public function editcomment($id) {


        $query = $this->db->get_where('booking', array('id' => $id));
        $data['show'] = $query->row_array();

        $mname = $this->input->post('mname');
        if (isset($mname)) {

            $comment = $data['show']['comment'];



            $comment .= $_POST["mname"] . "**" . $_POST["mcid"] . "**" . $_POST["mmobile"] . "**" . $_POST["mcountry"] . "|||";
            $dataedit = array(
                'comment' => $comment,
            );
            /// print_r($data);exit;
            $dataedit = $this->security->xss_clean($dataedit);
            $this->db->where('id', $id)->update('booking', $dataedit);

            $this->session->set_flashdata('msg', 'تم عمل اضافة المرافق بفضل الله');
            redirect(base_url() . 'dashboard');
        }
    }

    public function editbooking($id) {


        $query = $this->db->get_where('booking', array('id' => $id));
        $data['show'] = $query->row_array();




        $dataedit = array(
            'bill' => ($this->input->post('bill') + $this->input->post('knet')),
            'billprint' => $this->input->post('billprint'),
            'knet' => $this->input->post('knet'),
            'bookingnew' => $this->input->post('bookingnew'),
        );
        /// print_r($data);exit;
        $dataedit = $this->security->xss_clean($dataedit);
        $this->db->where('id', $id)->update('booking', $dataedit);


        $billback = $this->input->post('bill') + $this->input->post('knet');
        $billback2 = $this->input->post('billold');



        if ($billback != $billback2) {
            $this->booking->add_rep_user("  تعديل  مبلغ الى      $billback  من  $billback2 تسكين رقم" . $data['show']['id']);
        }

        $billback = $this->input->post('knet');
        $billback2 = $data['show']['knet'];



        if ($billback != $billback2) {
            $this->booking->add_rep_user("  تعديل  مبلغ الى   كي نت    $billback  من  $billback2 تسكين رقم" . $data['show']['id']);
        }





        $this->session->set_flashdata('msg', 'تم عمل التعديل بفضل الله');
        redirect(base_url() . 'dashboard');
    }

    public function editwait($id) {


        $query = $this->db->get_where('booking', array('id' => $id));
        $data['show'] = $query->row_array();

        
              $this->db->where('cid', $data['show']['cid'])->update('booking_clints', array('oky' => 'ok', 'comment' => "عليه مبلغ  ".$this->input->post('comment2')));

$comment5='wait';
        if($this->input->post('comment2')==0){
            $comment5='okwait';
      
          
                  $this->db->where('cid', $data['show']['cid'])->update('booking_clints', array('oky' => '', 'comment' => ""));
        }

        $dataedit = array(
            'comment5' => $comment5,
            'comment2' => $this->input->post('comment2'),
            'comment3' => $this->input->post('comment3'),
            'nowait' => $this->input->post('nowait'),
        );
        /// print_r($data);exit;
        $dataedit = $this->security->xss_clean($dataedit);
        $this->db->where('id', $id)->update('booking', $dataedit);
        $this->session->set_flashdata('msg', 'تم  تحويل المبلغ الى سلفه بفضل الله');
        redirect(base_url() . 'dashboard');
    }

    public function idbackwait($id) {

        $query = $this->db->get_where('booking', array('id' => $id));
        $data['show'] = $query->row_array();





        $billback = $this->input->post('billback');
        $billback2 = $this->input->post('billbackold');
        if ($billback > 0) {

            $dataadd = array(
                'catid' => '1',
                'text3' => '',
                'text1' => $billback,
                'text2' => " استرجاع شقة " . $data['show']['room'] . "بتاريخ    : " . $data['show']['datetext4'] . "رقم التسكين : " . $id,
                'dateadd' => $this->data_day,
                'counter' => '1',
            );
            $dataadd = $this->security->xss_clean($dataadd);
            $result = $this->db->insert('model_billshawly', $dataadd);
        }
        if ($billback != $billback2) {


            $this->booking->add_rep_user("  استراد مبلغ      $billback والمطلوب $billback2 تسكين رقم" . $data['show']['id']);
        }


        $this->db->where('cid', $data['show']['cid'])->update('booking_clints', array('oky' => '', 'comment' => ""));

        $this->db->where('id', $data['show']['id'])->update('booking', array('comment5' => 'okwait'));








        $this->session->set_flashdata('msg', 'تم   استرجاع المبلغ ورفع البلاك لست  بفضل الله!');


///$this->load->view('../controllers/views/show/printidout', $data);
        redirect(base_url() . 'dashboard');
    }

    public function outsite($id, $outsite) {

        $query = $this->db->get_where('booking', array('id' => $id));
        $data['show'] = $query->row_array();

        $this->db->where('id', $data['show']['id'])->update('booking', array('outsite' => $outsite));

        if ($outsite == 'ok')
            $this->db->where('id', $data['show']['id'])->update('booking', array('timeoutsite' => $this->booking->tissme_now()));
        else
            $this->db->where('id', $data['show']['id'])->update('booking', array('timeoutsite' => ''));

        $this->session->set_flashdata('msg', 'تم          التحديث بفضل الله !');
///$this->load->view('../controllers/views/show/printidout', $data);
        redirect(base_url() . 'dashboard');
    }

    public function upload_file($id) {

        $query = $this->db->get_where('booking', array('id' => $id));
        $data['show'] = $query->row_array();

        $query = $this->db->get_where('booking_clints', array('cid' => $data['show']['cid']));
        $clints = $query->row_array();
        $this->load->library('upload');
        $file1 = $clints['file1'];
        $fieldname = 'file1';
        if ($_FILES[$fieldname]['name'] != "") {
            if ($clints['file1'])
                unlink($file1);
            $upload_data = $this->booking->upload_many_photos($fieldname, $clints['cid'] . '1');
            $file1 = "upload/" . $upload_data["file_name"];
        }
        //sleep(31);
        $file2 = $clints['file2'];
        $fieldname2 = 'file2';
        if ($_FILES[$fieldname2]['name'] != "") {
            if ($clints['file2'])
                unlink($file2);
            $upload_data = $this->booking->upload_many_photos($fieldname2, $clints['cid'] . '2');
            $file2 = "upload/" . $upload_data["file_name"];
        }


        $edit_data = array(
            'file1' => $file1,
            'file2' => $file2,);
        $edit_data = $this->security->xss_clean($edit_data);
        $result = $this->db->where('id', $clints['id'])->update('booking_clints', $edit_data);



        $this->session->set_flashdata('msg', 'تم   رفع الاثبات  بفضل الله!');


        redirect(base_url() . 'dashboard');
    }
    // =====================================================
    function setting()
    {
      if(empty($this->session->userdata("is_admin_login"))) {
            redirect("auth/login","refresh");
        }
        $email =  $this->session->userdata("admin")['email'];
        if($this->input->server("REQUEST_METHOD")=="POST"){ 
            $datas= $this->input->post();  
            $company_title = $this->input->post('company_title');  
            $company_address = $this->input->post('company_address');
            $company_mobile = $this->input->post('company_mobile');
            $company_email = $this->input->post('company_email');
            $currency = $this->input->post('currency');
            $facbook = $this->input->post('facbook');
            $twitter = $this->input->post('twitter');
            $google_plus = $this->input->post('google_plus');
            $instrgram = $this->input->post('instrgram');
            $meta_title = $this->input->post('meta_title');
            $meta_description = $this->input->post('meta_description');
            $meta_keyword = $this->input->post('meta_keyword');
            $datas['update_on'] = date('Y-m-d h:m:sa');
            $res = $this->db->get('setting')->result();
            if(empty($res)){ 
            $d= $this->db->insert('setting',$datas); 
            }else{ 
            $this->db->where('setting_id',1); 
            $d= $this->db->update('setting',$datas); 
            }$data = '<?php defined("BASEPATH") OR exit("Can we together ?");
$config["company_title"] ="'.$company_title.'";
$config["company_fav"] = "'.@$company_fav.'";
$config["company_address"] = "'.$company_address.'";
$config["company_mobile"] = "'.$company_mobile.'";
$config["company_email"] = "'.$company_email.'";
$config["currency"] = "'.$currency.'";
$config["facbook"] = "'.$facbook.'";
$config["twitter"] = "'.$twitter.'";
$config["google_plus"] = "'.$google_plus.'";
$config["instrgram"] = "'.$instrgram.'";
$config["meta_title"] = "'.$meta_title.'";
$config["meta_description"] = "'.$meta_description.'";
$config["meta_keyword"] = "'.$meta_keyword.'";';
            file_put_contents("application/config/custom.php", $data);
            $this->session->set_flashdata('message', 'Successfully Updated');
            redirect('dashboard/setting', 'refresh');
        }
        $data['title'] = $this->lang->line('setting');
        // $data['view'] = '../controllers/views/setting/setting';
        $data['thispage'] = 'dashboard';
        $this->load->view('views/setting/setting', $data);
    }
}
?>