<?php

require_once("imp/_imp.php");

class Controllers {

//public vars
    public $smarty;
    public $hosturl;
    public $controllname;
    public $shcontrollname;
    public $active;
    public $time;
    public $today;

// it will run in everytime with
// default requried
    public function __construct() {
        require_once("../public/aw_config.php");
        require_once("imp/_autho.php"); //general functions
        $this->smarty = $smarty;
        $this->hosturl = $hosturl;

//here name of controll to known
        $this->controllname = 'programesetting';
        $this->shcontrollname = 'Programesetting';
        $this->smarty->assign('controllname', $this->controllname);
        $this->smarty->assign('shcontrollname', $this->shcontrollname);



//breadcrumbs
        require_once("../../_library/plugins/Breadcrumbs/Breadcrumbs.php");
        $acty = filter_input(INPUT_GET, 'ac');
        $bc = new breadcrumbs($hosturl, '', '', $acty);
        $bc->crumbs();
        $breadcrumbs = $bc->breadcrumbs;
        $smarty->assign('breadcrumbs', $breadcrumbs);

# here show the active page in menu
// array called active[] with level of active element
        $active[0] = 'programesetting'; //controller name or tab name
        $active[1] = 'programesetting'; //controller name

        $this->active = $active;



        #include upload function
        require_once("../../_library/plugins/classupload/uploadfunctions.php");

        //here will call all php pages
        require_once("_header.php");
        require_once("_sidebar.php");
        require_once("_leftsidebar.php");
        require_once("_footer.php");

        //find loading time
        $this->time = microtime(true);
        $this->today = date('Y-m-d');
    }

    public function index() {

        //check login
        autho::checkautho($this->hosturl);
        //check authoize
        autho::checkauthoize($this->controllname, $this->hosturl, $_SESSION['role_id']);

        //select table programesetting data to order by id
        $programesetting = R::getAll('select * from programesetting order by id desc');

        //send info to html
        $this->smarty->assign('programesetting', $programesetting[0]);

        //call other class with other content
        header::headershow($this->smarty, $this->hosturl);
        sidebar::sidebarshow($this->smarty, $this->hosturl, $this->active);
        $this->smarty->display('programesetting/add.html');
        leftsidebar::leftsidebarshow($this->smarty, $this->hosturl);
        footer::footershow($this->smarty, $this->hosturl);
    }

    public function addit() {

        //check login
        autho::checkautho($this->hosturl);
        //check authoize
        autho::checkauthoize($this->controllname, $this->hosturl, $_SESSION['role_id']);


        //get all vars
        $color = filter_input(INPUT_POST, 'color');
        $left = filter_input(INPUT_POST, 'left');
        $right = filter_input(INPUT_POST, 'right');
        $center = filter_input(INPUT_POST, 'center');
        $centername = filter_input(INPUT_POST, 'centername');
        $doctorname = filter_input(INPUT_POST, 'doctorname');
        $address = filter_input(INPUT_POST, 'address');
        $phone = filter_input(INPUT_POST, 'phone');
        $spacial = filter_input(INPUT_POST, 'spacial');
        $gynalink = filter_input(INPUT_POST, 'gynalink');
        $antenatal = filter_input(INPUT_POST, 'antenatal');
        $fontsizeen = filter_input(INPUT_POST, 'fontsizeen');
        $fontsizear = filter_input(INPUT_POST, 'fontsizear');
        $alignttt = filter_input(INPUT_POST, 'alignttt');
        $ultrasound = filter_input(INPUT_POST, 'ultrasound');
        $patientnoaut = filter_input(INPUT_POST, 'patientnoaut');
        $addshours = filter_input(INPUT_POST, 'addshours');
        $above = filter_input(INPUT_POST, 'above');
        $buttom = filter_input(INPUT_POST, 'buttom');
        $ishide = filter_input(INPUT_POST, 'ishide');
        $simpleView = filter_input(INPUT_POST, 'simpleview');
        $displayDoctorName = filter_input(INPUT_POST, 'displaydoctorname');
        $entryorder = filter_input(INPUT_POST, 'entryorder');
        $investshow = filter_input(INPUT_POST, 'investshow');
        $prescriptioncashing = filter_input(INPUT_POST, 'prescriptioncashing');
        $visitsform = filter_input(INPUT_POST, 'visitsform');
        $diagnosshow = filter_input(INPUT_POST, 'diagnosshow');
        $backupdriver = filter_input(INPUT_POST, 'backupdriver');
        $hideId = filter_input(INPUT_POST, 'hideId');
        $loginbar = filter_input(INPUT_POST, 'loginbar');
        $email = filter_input(INPUT_POST, 'email');
        $password = filter_input(INPUT_POST, 'password');
        $above2 = filter_input(INPUT_POST, 'above2');
        $buttom2 = filter_input(INPUT_POST, 'buttom2');
        $fontsizeen2 = filter_input(INPUT_POST, 'fontsizeen2');
        $fontsizear2 = filter_input(INPUT_POST, 'fontsizear2');
        $visittype = filter_input(INPUT_POST, 'visittype');
        $presquantity = filter_input(INPUT_POST, 'presquantity');

        $system_type = filter_input(INPUT_POST, 'system_type');
        $system_lang = filter_input(INPUT_POST, 'system_lang');
        $start_hour = filter_input(INPUT_POST, 'start_hour');
        $end_hour = filter_input(INPUT_POST, 'end_hour');
        $rooms = filter_input(INPUT_POST, 'rooms');

        $surgeon = filter_input(INPUT_POST, 'surgeon');
        $triggering = filter_input(INPUT_POST, 'triggering');
        $ovum_tab = filter_input(INPUT_POST, 'ovum_tab');
        $embro_tab = filter_input(INPUT_POST, 'embro_tab');
        $others_tab = filter_input(INPUT_POST, 'others_tab');
        $notes = filter_input(INPUT_POST, 'notes');
        $organizations = filter_input(INPUT_POST, 'organizations');

        $menstrual = filter_input(INPUT_POST, 'menstrual');
        $contraception = filter_input(INPUT_POST, 'contraception');
        $obstetric = filter_input(INPUT_POST, 'obstetric');
        $past = filter_input(INPUT_POST, 'past');
        $family = filter_input(INPUT_POST, 'family');
        $medical = filter_input(INPUT_POST, 'medical');
        $surgical = filter_input(INPUT_POST, 'surgical');
        $gynecological = filter_input(INPUT_POST, 'gynecological');
        $art = filter_input(INPUT_POST, 'art');
        $sexual = filter_input(INPUT_POST, 'sexual');
        $personal = filter_input(INPUT_POST, 'personal');
        $past_visits = filter_input(INPUT_POST, 'past_visits');
        $barcode_print = filter_input(INPUT_POST, 'barcode_print');
        $temp_patient = filter_input(INPUT_POST, 'temp_patient');
        $fin_doc_dept = filter_input(INPUT_POST, 'fin_doc_dept');
        $infertility = filter_input(INPUT_POST, 'infertility');
        $gynalmp = filter_input(INPUT_POST, 'gynalmp');
        $entrydetails = filter_input(INPUT_POST, 'entrydetails');
        $head = filter_input(INPUT_POST, 'head');
        $chest = filter_input(INPUT_POST, 'chest');
        $abdomen = filter_input(INPUT_POST, 'abdomen');
        $pelvis = filter_input(INPUT_POST, 'pelvis');
        $extremitis = filter_input(INPUT_POST, 'extremitis');
        $case_summary = filter_input(INPUT_POST, 'case_summary');
        $national_id_req = filter_input(INPUT_POST, 'national_id_req');
        $confirm_attend = filter_input(INPUT_POST, 'confirm_attend');
        $birth_notify = filter_input(INPUT_POST, 'birth_notify');
        $visit_phones = filter_input(INPUT_POST, 'visit_phones');
        $voice_record = filter_input(INPUT_POST, 'voice_record');
        $whatsapp_sms = filter_input(INPUT_POST, 'whatsapp_sms');
        $rfc = filter_input(INPUT_POST, 'rfc');
        $whatsapp_txt = filter_input(INPUT_POST, 'whatsapp_txt');
        $past_search = filter_input(INPUT_POST, 'past_search');
        $diagnos_ant = filter_input(INPUT_POST, 'diagnos_ant');
        $attend_today = filter_input(INPUT_POST, 'attend_today');
        $search_result_no = (filter_input(INPUT_POST, 'search_result_no') > 0) ? filter_input(INPUT_POST, 'search_result_no') : 25;
        $search_letters_no = (filter_input(INPUT_POST, 'search_letters_no') > 0) ? filter_input(INPUT_POST, 'search_letters_no') : 1;



        $id = filter_input(INPUT_POST, 'id');


        //select table siteinfo data to order by id
        $programesetting = R::findAll('programesetting', 'order by id desc');
        if (count($programesetting) > 0) {
            //update current
            //get id vars in update statution
            $id = filter_input(INPUT_POST, 'id');
            $backgroundImageValue = filter_input(INPUT_POST, 'backgroundImageValue');
            if ($backgroundImageValue == 1) {
                $background = uploadupdate('bgfile', 'bimageurl', False, 0, 0, 'background');
            } else {
                $background = '';
            }

            $programesetting = R::load('programesetting', $id);
        } else {
            //insert new
            $background = uploadnew('bgfile', False, 0, 0, 'background');
            $programesetting = R::dispense('programesetting');
        }


        $programesetting->attend_today = $attend_today;
        $programesetting->search_result_no = $search_result_no;
        $programesetting->search_letters_no = $search_letters_no;
        $programesetting->past_search = $past_search;
        $programesetting->diagnos_ant = $diagnos_ant;
        $programesetting->case_summary = $case_summary;
        $programesetting->national_id_req = $national_id_req;
        $programesetting->confirm_attend = $confirm_attend;
        $programesetting->birth_notify = $birth_notify;
        $programesetting->whatsapp_txt = $whatsapp_txt;
        $programesetting->organizations = $organizations;
        $programesetting->surgeon = $surgeon;
        $programesetting->triggering = $triggering;
        $programesetting->ovum_tab = $ovum_tab;
        $programesetting->embro_tab = $embro_tab;
        $programesetting->others_tab = $others_tab;
        $programesetting->notes = $notes;
        $programesetting->menstrual = $menstrual;
        $programesetting->contraception = $contraception;
        $programesetting->obstetric = $obstetric;
        $programesetting->past = $past;
        $programesetting->family = $family;
        $programesetting->medical = $medical;
        $programesetting->surgical = $surgical;
        $programesetting->gynecological = $gynecological;
        $programesetting->art = $art;
        $programesetting->sexual = $sexual;
        $programesetting->personal = $personal;
        $programesetting->rooms = $rooms;
        $programesetting->backupdriver = $backupdriver;
        $programesetting->color = $color;
        $programesetting->above = $above;
        $programesetting->buttom = $buttom;
        $programesetting->pleft = $left;
        $programesetting->pright = $right;
        $programesetting->center = $center;
        $programesetting->centername = $centername;
        $programesetting->doctorname = $doctorname;
        $programesetting->address = $address;
        $programesetting->phone = $phone;
        $programesetting->spacial = $spacial;
        $programesetting->gynalink = $gynalink;
        $programesetting->antenatal = $antenatal;
        $programesetting->fontsizeen = $fontsizeen;
        $programesetting->fontsizear = $fontsizear;
        $programesetting->alignttt = $alignttt;
        $programesetting->ultrasound = $ultrasound;
        $programesetting->addshours = $addshours;
        $programesetting->patientnoaut = $patientnoaut;
        $programesetting->ishide = $ishide;
        $programesetting->simpleview = $simpleView;
        $programesetting->displaydoctorname = $displayDoctorName;
        $programesetting->entryorder = $entryorder;
        $programesetting->investshow = $investshow;
        $programesetting->diagnosshow = $diagnosshow;
        $programesetting->prescriptioncashing = $prescriptioncashing;
        $programesetting->visitsform = $visitsform;
        $programesetting->hideid = $hideId;
        $programesetting->email = $email;
        $programesetting->password = $password;
        $programesetting->loginbar = $loginbar;
        $programesetting->visittype = $visittype;
        $programesetting->presquantity = $presquantity;
        $programesetting->above2 = $above2;
        $programesetting->buttom2 = $buttom2;
        $programesetting->fontsizeen2 = $fontsizeen2;
        $programesetting->fontsizear2 = $fontsizear2;
        $programesetting->background = $background;
        $programesetting->temp_patient = $temp_patient;
        $programesetting->system_lang = $system_lang;
        $programesetting->system_type = $system_type;
        $programesetting->start_hour = $start_hour;
        $programesetting->end_hour = $end_hour;
        $programesetting->barcode_print = $barcode_print;
        $programesetting->head = $head;
        $programesetting->chest = $chest;
        $programesetting->abdomen = $abdomen;
        $programesetting->pelvis = $pelvis;
        $programesetting->extremitis = $extremitis;
        $programesetting->infertility = $infertility;
        $programesetting->gynalmp = $gynalmp;
        $programesetting->entrydetails = $entrydetails;
        $programesetting->visit_phones = $visit_phones;
        $programesetting->voice_record = $voice_record;
        $programesetting->whatsapp_sms = $whatsapp_sms;
        $programesetting->rfc = $rfc;

        $programesetting->fin_doc_dept = $fin_doc_dept;

        try {
            R::store($programesetting);
            header('Location:' . $this->hosturl . '/controllers/' . $this->controllname . '.php');
        } catch (Exception $e) {
            //print_r($e);
            header('Location:' . $this->hosturl . '/error/notadd/' . $this->controllname);
        }
    }

    // at the end of class call
    public function __destruct() {
        //close connection
        R::close();
    }

}
