<?php

class COR_Controller extends CI_Controller {

    var $template = array(
        'table_open' => "<table class='table-responsive table-striped table-hover table-bordered table-condensed'>",
        'thead_open' => '<thead class=\'bg-indigo\'>',
        'thead_close' => '</thead>',
        'heading_row_start' => '<tr style=\'padding:1px;\'>',
        'heading_row_end' => '</tr>',
        'heading_cell_start' => '<th>',
        'heading_cell_end' => '</th>',
        'tbody_open' => '<tbody>',
        'tbody_close' => '</tbody>',
        'row_start' => '<tr style=\'padding:0px;\'>',
        '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->load->library(array('session'));
    }

    protected function smart_htmlspecialchars($str) {
        if (substr($str, 0, 1) == '<')
            return $str;
        return htmlspecialchars($str);
    }

    protected function sql_escape_func($inp) {
        if (is_array($inp)) {
            return array_map(__METHOD__, $inp);
        }


        if (!empty($inp) && is_string($inp)) {
            return str_replace(array('\\', "\0", "\n", "\r", "'", '"', "\x1a"), array('\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'), $inp);
        }

        return $inp;
    }

    protected function coregrade_webapi($action, $in, &$out) {
        $this->load->model('backend_model');
        $in["action"] = $action;
        $in["pid"] = 100;
      //  print_r($in);
        $ret = $this->backend_model->coregrade_api($in, $out);
        //echo $ret;
        return $ret;
    }

    function formatedMesage($msgType, $theMessage) {
        return "<div class=\"text-left\"><div class=\"alert alert-danger no-border\">" . $theMessage . "</div></div>";
    }

    protected function renderMemberPages($pagename, $data) {
        $this->load->view('member/view_securehead');
        $this->load->view('member/' . $pagename, $data);
        $this->load->view('member/view_securefoot');
        return 0;
    }

    protected function renderAuthPages($pagename, $data) {

        $this->load->view('auth/view_head');
        $this->load->view('auth/' . $pagename, $data);
        $this->load->view('auth/view_foot');
        return 0;
    }

}

