<?php

class Backend_model extends CI_Model {

    var $thisUser = 'oameye';
    var $USER = '';
    var $coregrade;

    function __construct() {

        $this->USER = $_SERVER['SCRIPT_FILENAME'];
        $this->USER = str_replace('/home', '', $this->USER);
        $this->USER = strtok($this->USER, '/');
        if ($this->USER == 'opt') {
            $this->USER = 'root';
        }
        $this->thisUser = $this->USER;
    }

    public function coregrade_api($in, &$out) {
        if (!is_array($out))
            return -1;
        $this->coregrade_load();
        $rrr = array();
        $coregrade = $this->coregrade;
        $ret = $coregrade->coregrade_api($in, $rrr);
        //print_r( $in );
        //echo "-----\n";
        //print_r( $rrr );
        $out = $rrr;
        return $ret;
    }

    public function cfgReadChar($str) {
        $this->coregrade_load();
        $ret = $this->coregrade->cfgReadChar($str);
        return $ret;
    }

    private function coregrade_load() {
        // $this->$USER = $_SERVER['SCRIPT_FILENAME'];
        $coregrade_class = 'coregrade_api_' . $this->USER . '\\coregrade';
        if (!is_object($this->coregrade)) {
            $this->coregrade = new $coregrade_class();
        }
    }

}
