"
",
'thead_open' => '',
'thead_close' => '',
'heading_row_start' => '',
'heading_row_end' => '
',
'heading_cell_start' => '',
'heading_cell_end' => ' | ',
'tbody_open' => '',
'tbody_close' => '',
'row_start' => '',
'row_end' => '
',
'cell_start' => '',
'cell_end' => ' | ',
'row_alt_start' => '',
'row_alt_end' => '
',
'cell_alt_start' => '',
'cell_alt_end' => ' | ',
'table_close' => '
'
);
var $template_nohead = array(
'table_open' => "",
'thead_open' => '',
'thead_close' => '',
'heading_row_start' => '',
'heading_row_end' => '
',
'heading_cell_start' => '',
'heading_cell_end' => ' | ',
'tbody_open' => '',
'tbody_close' => '',
'row_start' => '',
'row_end' => '
',
'cell_start' => '',
'cell_end' => ' | ',
'row_alt_start' => '',
'row_alt_end' => '
',
'cell_alt_start' => '',
'cell_alt_end' => ' | ',
'table_close' => '
'
);
public $data = array();
function __construct() {
parent::__construct();
}
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 savvy_api($in, &$out) {
global $coregrade;
$ret = -1;
$in['pid'] = 115;
$in['backoffice'] = 1;
error_log(json_encode($in));
$out = $coregrade->coregrade_api($in);
$ret = $out["retval"];
error_log("ret = $ret");
error_log(json_encode($out));
return $ret;
}
protected function main_api_post($endpoint,$payload) {
global $coregrade;
$httpAuthToken = $coregrade->cfgReadChar('system.oauth2_token');
$encryptionAlg = $coregrade->cfgReadChar('encryption.algorithm');
$encryptionKey = $coregrade->cfgReadChar('encryption.key');
$encryptionIV = $coregrade->cfgReadChar('encryption.iv');
$encrypted_payload = bin2hex(
openssl_encrypt(
$payload,
$encryptionAlg,
$encryptionKey,
OPENSSL_RAW_DATA,
$encryptionIV
));
$postdata = "{\"encrypted_payload\": \"${encrypted_payload}\"}";
$url = $coregrade->cfgReadChar('system.api_url').$endpoint;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_VERBOSE, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($postdata),
'Authorization: Server-Token ' . $httpAuthToken)
);
$body = curl_exec($ch);
$result = json_decode($body,true);
if (is_array($result) && array_key_exists('payload',$result)) {
$decrypted = openssl_decrypt(
hex2bin(
$result['payload']
),
$encryptionAlg,
$encryptionKey,
OPENSSL_RAW_DATA,
$encryptionIV
);
} else {
$decrypted = $body; // Attempt without encryption
}
$payload = json_decode($decrypted, true);
return [$payload,$decrypted,$result,$body];
}
protected function main_api_get($endpoint,$payload) {
global $coregrade;
$httpAuthToken = $coregrade->cfgReadChar('system.oauth2_token');
$encryptionAlg = $coregrade->cfgReadChar('encryption.algorithm');
$encryptionKey = $coregrade->cfgReadChar('encryption.key');
$encryptionIV = $coregrade->cfgReadChar('encryption.iv');
$url = $coregrade->cfgReadChar('system.api_url').$endpoint.$payload;
//echo $url;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_VERBOSE, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Server-Token ' . $httpAuthToken)
);
$body = curl_exec($ch);
$result = json_decode($body,true);
if (is_array($result) && array_key_exists('payload',$result)) {
$decrypted = openssl_decrypt(
hex2bin(
$result['payload']
),
$encryptionAlg,
$encryptionKey,
OPENSSL_RAW_DATA,
$encryptionIV
);
} else {
$decrypted = $body; // Attempt without encryption
}
$payload = json_decode($decrypted, true);
return [$payload,$decrypted,$result,$body];
}
function formatedMesage($msgType, $theMessage) {
return "";
}
protected function renderAdminPage($page_type, $page_name, $data) {
$this->load->view('admin_template/view_admin_header', $data);
$this->load->view($page_type.'/' . $page_name, $data);
$this->load->view('admin_template/view_admin_footer', $data);
}
}