<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class WelcomeKDS extends MY_Controller {
    
    function __construct() {
        parent::__construct();
        $this->load->model('dashboard/dashboardKDS_model');
    }
    
    public function index() {
        $existskdslines =   $this->dashboardKDS_model->checkkdslinesexisttable();
        $existskdstickets =   $this->dashboardKDS_model->checkkdsticketsexisttable();
        if($existskdslines==0 || $existskdstickets==0) {
            redirect(base_url().'dashboard/welcome');
        }
        
        $databoxes=$this->dashboardKDS_model->getdataboxes();
        if($databoxes!=null) {
            $i=0;
            $url='';
            $xml = simplexml_load_string(htmlspecialchars_decode($databoxes));
            $pagedata[]='';
            foreach ($xml as $key0 => $value) {
                foreach ($value->attributes() as $attributeskey0 => $attributesvalue1) {
                    if($attributeskey0=='key') {
                        $url = $attributesvalue1;
                    } else if($attributeskey0=='count') {
                        $pagedata['count'] = $attributesvalue1;
                    } else if($attributeskey0=='days') {
                        $pagedata['days'] = $attributesvalue1;
                    } else if($attributeskey0=='displayid') {
                        $pagedata['displayid'] = $attributesvalue1;
                    } else if($attributeskey0=='limit') {
                        $pagedata['limit'] = $attributesvalue1;
                    }
                }
                $data['databoxes'][$i]=$this->load->view('dashboard/databoxesKDS/'.$url, $pagedata, true);
                $i+=1;
                $url='';
            }
            $data['template'] = 'dashboard/dashboardKDS_view';
            $this->load->view('template',$data);
        } else {
            $data['template'] = 'dashboard/dashboardKDS_view';
            $this->load->view('template',$data);
        }
    }
    
}
