Esempio n. 1
0
function ZimAPI_getStatistic()
{
    $CI =& get_instance();
    $CI->load->helper('printerlog');
    return PrinterLog_getStats();
}
Esempio n. 2
0
function PrinterLog__logStats($array_stats = array())
{
    $json_data = array();
    $temp_filename = FALSE;
    $folder_path = NULL;
    $CI =& get_instance();
    // ignore invalid or empty input
    if (!is_array($array_stats) || count($array_stats) == 0) {
        return FALSE;
    }
    // return if stats is off
    if (FALSE == PrinterLog_getStats()) {
        return TRUE;
    }
    //TODO think if we take DNT into account or not (Do not track me)
    // 	if (isset($_SERVER['HTTP_DNT']) && $_SERVER['HTTP_DNT'] == 1) {
    // 		return TRUE;
    // 	}
    // treat required items: category and action
    if (isset($array_stats[PRINTERLOG_STATS_TITLE_CATEGORY]) && isset($array_stats[PRINTERLOG_STATS_TITLE_ACTION])) {
        $json_data[PRINTERLOG_STATS_TITLE_CATEGORY] = PRINTERLOG_STATS_TITLE_CATEGORY . '=' . $array_stats[PRINTERLOG_STATS_TITLE_CATEGORY];
        $json_data[PRINTERLOG_STATS_TITLE_ACTION] = PRINTERLOG_STATS_TITLE_ACTION . '=' . $array_stats[PRINTERLOG_STATS_TITLE_ACTION];
    } else {
        return FALSE;
    }
    // treat optional items: label and value
    if (isset($array_stats[PRINTERLOG_STATS_TITLE_LABEL])) {
        $item_data = $array_stats[PRINTERLOG_STATS_TITLE_LABEL];
        if (is_array($item_data)) {
            $item_data = json_encode($item_data);
        }
        $json_data[PRINTERLOG_STATS_TITLE_LABEL] = PRINTERLOG_STATS_TITLE_LABEL . '=' . $item_data;
    }
    if (isset($array_stats[PRINTERLOG_STATS_TITLE_VALUE])) {
        $json_data[PRINTERLOG_STATS_TITLE_VALUE] = PRINTERLOG_STATS_TITLE_VALUE . '=' . $array_stats[PRINTERLOG_STATS_TITLE_VALUE];
    }
    // add serial
    $CI->load->helper('zimapi');
    $json_data[PRINTERLOG_STATS_TITLE_SERIAL] = PRINTERLOG_STATS_TITLE_SERIAL . '=' . ZimAPI_getSerial();
    // generate temp curl json file
    $folder_path = $CI->config->item('temp') . PRINTERLOG_STATS_TEMPFILE_FOLDER;
    if (!file_exists($folder_path)) {
        mkdir($folder_path);
    }
    $temp_filename = tempnam($folder_path, PRINTERLOG_STATS_TEMPFILE_PREFIX);
    if ($temp_filename == FALSE || !file_exists($temp_filename)) {
        return FALSE;
    }
    $fp = fopen($temp_filename, 'w');
    if ($fp) {
        //TODO check if we need unescapse unicode
        // 		$CI->load->helper('json');
        // 		fwrite($fp, json_encode_unicode($json_data));
        fwrite($fp, json_encode($json_data));
        fclose($fp);
        chmod($temp_filename, 0777);
    } else {
        return FALSE;
    }
    exec($CI->config->item('siteutil') . PRINTERLOG_STATS_SITEUTILS_CMD . $temp_filename);
    return TRUE;
}