Files
dev-chiefworks f76abffdcd first commit
2022-05-31 16:21:53 -04:00

131 lines
4.9 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Admin_Controller extends SAV_Controller {
const NONE_COUNT_RECORD = false;
const TEMP_DIRECTORY_UPLOAD = 'application/cache/upload';
const TEMP_DIRECTORY_DOWNLOAD = 'application/cache/download';
protected $read_replica;
var $template = array(
'table_open' => "<table style='background-color:aliceblue' 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>'
);
var $template_small = array(
'table_open' => "<table class='table table-striped table-hover table-bordered table-condensed' style='font-size:10px;'>",
'thead_open' => '<thead class=\'bg-teal\'>',
'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();
$this->read_replica = $this->load->database('savvy_replica', TRUE);
if (!isset($_SESSION['username']) or $_SESSION['username'] == '' or $_SESSION['firstname'] == '') {
redirect('logout');
}
}
protected function renderCardPage($page_name, $data) {
$this->load->view('admin/view_admin_header', $data);
$this->load->view('cards/' . $page_name, $data);
$this->load->view('admin/view_admin_footer', $data);
}
protected function renderEmissionPage($page_name, $data){
$this->load->view('admin/view_admin_header', $data);
$this->load->view('emission/' . $page_name, $data);
$this->load->view('admin/view_admin_footer', $data);
}
protected function returnAdminTable($tbq, $pgLink, $config = []) {
$this->load->library('pagination');
$query = $this->read_replica->query($tbq['count_query']);
$config['total_rows'] = $query->num_rows();
$config['base_url'] = base_url() . $pgLink;
$config['per_page'] = $config['per_page'] ?? 5;
$config['reuse_query_string'] = $config['reuse_query_string'] ?? FALSE;
$config['uri_segment'] = $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($config['uri_segment'])) ? $this->uri->segment($config['uri_segment']) : 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->read_replica->query($mysql);
$data['limited_data'] = $query->result_array();
$data['output_table'] = $this->table->generate($query);
$data['links'] = $this->pagination->create_links();
return $data;
}
protected function makeGoogleAddress($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;
}
}