<?php

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

class Admin_Controller extends MDT_Controller {

    var $template = array(
        'table_open' => "<table class='table table-striped table-hover table-bordered table-condensed'>",
        'thead_open' => '<thead class=\'bg-indigo\'>',
        'thead_close' => '</thead>',
        'heading_row_start' => '<tr>',
        'heading_row_end' => '</tr>',
        'heading_cell_start' => '<th>',
        'heading_cell_end' => '</th>',
        'tbody_open' => '<tbody>',
        'tbody_close' => '</tbody>',
        'row_start' => '<tr>',
        'row_end' => '</tr>',
        'cell_start' => '<td>',
        'cell_end' => '</td>',
        'row_alt_start' => '<tr>',
        'row_alt_end' => '</tr>',
        'cell_alt_start' => '<td>',
        'cell_alt_end' => '</td>',
        'table_close' => '</table>'
    );
    public $data = array();

    function __construct() {
        parent::__construct();
        if (!isset($_SESSION['username']) or $_SESSION['username'] == '') {
            redirect('site');
        }
    }

    //  protected 



    protected function returnAdminTable($tbq, $pgLink) {

        $this->load->library('pagination');
        $config = array();
        $query = $this->db->query($tbq['count_query']);
        $config["total_rows"] = $query->num_rows();
        $config["base_url"] = base_url() . $pgLink;
        $config["per_page"] = 5;
        $config["uri_segment"] = 3;
        $config["num_links"] = 5;
        $config['full_tag_open'] = "<ul class='pagination'>";
        $config['full_tag_close'] = "</ul>";
        $config['num_tag_open'] = '<li>';
        $config['num_tag_close'] = '</li>';
        $config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
        $config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
        $config['next_tag_open'] = "<li>";
        $config['next_tagl_close'] = "</li>";
        $config['prev_tag_open'] = "<li>";
        $config['prev_tagl_close'] = "</li>";
        $config['first_tag_open'] = "<li>";
        $config['first_tagl_close'] = "</li>";
        $config['last_tag_open'] = "<li>";
        $config['last_tagl_close'] = "</li>";

        $this->pagination->initialize($config);
        $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        $page = is_numeric($page) ? $page : 0;

        $mysql = $tbq['query'] . " LIMIT " . $config["per_page"] . " OFFSET " . $page;

        $this->load->library('table');
        $this->table->set_template($this->template);
        $query = $this->db->query($mysql);

        //    $this->table->set_heading(array('data' => 'Added/ID', 'style' => 'width:100px'), 'Title', 'Client', array('data' => 'Action', 'style' => 'width:70px'));


        $data['output_table'] = $this->table->generate($query);
        $data["links"] = $this->pagination->create_links();

        return $data;
    }

    protected function makeGoogleAddress($rect) {
        //print_r($rect);
        $data['directionsStart'] = $rect['to_street'] . "," . $rect['to_city'] . "," . $rect['to_state'] . " " . $rect['to_zipcode'] . ", USA";
        $data['directionsEnd'] = $rect['from_street'] . "," . $rect['from_city'] . "," . $rect['from_state'] . " " . $rect['from_zipcode'] . ", USA";

        return $data;
    }

}
