"
",
'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 $savvyext;
$ret = -1;
$in['pid'] = 115;
$in['backoffice'] = 1;
error_log(json_encode($in));
$out = $savvyext->savvyext_api($in);
$ret = $out["retval"];
error_log("ret = $ret");
error_log(json_encode($out));
return $ret;
}
protected function savvy_admin($endpoint, $in, &$out)
{
global $savvyext;
$ret = -1;
$in['pid'] = 115;
$in['backoffice'] = 1;
error_log(json_encode($in));
$out = $savvyext->savvyext_admin($endpoint,$in);
//var_dump($out);exit;
$ret = $out["retval"];
error_log("ret = $ret");
error_log(json_encode($out));
return $ret;
}
// call API with no default params
protected function savvy_api_clearly($in, &$out)
{
global $savvyext;
$ret = -1;
error_log(json_encode($in));
$out = $savvyext->savvyext_api($in);
$ret = $out["retval"];
error_log("ret = $ret");
error_log(json_encode($out));
return $ret;
}
protected function main_api_post($endpoint, $payload)
{
global $savvyext;
$httpAuthToken = $savvyext->cfgReadChar('system.oauth2_token');
$encryptionAlg = $savvyext->cfgReadChar('encryption.algorithm');
$encryptionKey = $savvyext->cfgReadChar('encryption.key');
$encryptionIV = $savvyext->cfgReadChar('encryption.iv');
$encrypted_payload = bin2hex(
openssl_encrypt(
$payload,
$encryptionAlg,
$encryptionKey,
OPENSSL_RAW_DATA,
$encryptionIV
)
);
$postdata = "{\"encrypted_payload\": \"${encrypted_payload}\"}";
$url = $savvyext->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 $savvyext;
$httpAuthToken = $savvyext->cfgReadChar('system.oauth2_token');
$encryptionAlg = $savvyext->cfgReadChar('encryption.algorithm');
$encryptionKey = $savvyext->cfgReadChar('encryption.key');
$encryptionIV = $savvyext->cfgReadChar('encryption.iv');
$url = $savvyext->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,
"client_id: BackOffice"
)
);
$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 renderMemberPage($page_name, $data)
{
$this->load->view('admin/view_admin_header', $data);
$this->load->view('member/' . $page_name, $data);
$this->load->view('admin/view_admin_footer', $data);
}
protected function renderAdminPage($page_name, $data)
{
$this->load->view('admin/view_admin_header', $data);
$this->load->view('admin/' . $page_name, $data);
$this->load->view('admin/view_admin_footer', $data);
}
protected function renderUploadPage($page_name, $data)
{
$this->load->view('admin/view_admin_header', $data);
$this->load->view('upload/' . $page_name, $data);
$this->load->view('admin/view_admin_footer', $data);
}
}