Example #1
0
function get_graph($machine_id)
{
    global $db;
    global $db_mach;
    global $db_user;
    // get all user that have been used the machine
    $user_on_machine = array();
    $req = 'SELECT distinct `user_id` from `log` where `machine_id`=' . $machine_id . '';
    $stmt = $db->prepare($req);
    $stmt->execute();
    $i = 0;
    foreach ($stmt as $row) {
        $user_on_machine[$i]["id"] = $row["user_id"];
        //failsafe
        if (!isset($db_user[$row["user_id"]])) {
            $db_user[$row["user_id"]]["name"] = "user not found";
        }
        $user_on_machine[$i]["title"] = $db_user[$row["user_id"]]["name"];
        $i++;
    }
    // now get all log entries, summed per day
    $req = 'SELECT sum(`usage`) as used_time, `user_id`, FLOOR(`timestamp`/86400)*86400 as date ';
    $req .= 'FROM `log` where `usage`>0 and `machine_id`=' . $machine_id . ' ';
    $req .= 'group by FLOOR(`timestamp`/86400), `user_id` ORDER BY `date` asc';
    //echo '<hr>'.$req.'<hr>';
    $stmt = $db->prepare($req);
    $stmt->execute();
    $collector = array();
    $log_entries = 0;
    foreach ($stmt as $row) {
        $log_entries++;
        //echo "Time:".$row["used_time"]." user id=".$row["user_id"]." date=".$row["date"]." / ".date("Y-m-d",$row["date"])."<br>";
        // find the right index in the collector
        $found = -1;
        for ($i = 0; $i < count($collector); $i++) {
            if (isset($collector[$i]["date"])) {
                if ($collector[$i]["date"] == $row["date"]) {
                    $found = $i;
                    break;
                }
            }
        }
        if ($found == -1) {
            //echo "not found, adding entries<br>";
            $found = count($collector);
            for ($i = 0; $i < count($user_on_machine); $i++) {
                $collector[$found]["user"][$i] = 0;
            }
            $collector[$found]["date"] = $row["date"];
            //echo "date:".$collector[$found]["date"]." data:".$collector[$found]["data"]."<br>";
        }
        // fill data
        for ($i = 0; $i < count($user_on_machine); $i++) {
            //echo "row[user_id]=".$row["user_id"]." == ".$user_on_machine[$i]["id"]."<br>";
            if ($row["user_id"] == $user_on_machine[$i]["id"]) {
                $collector[$found]["user"][$i] = floor($row["used_time"] / 60);
                //echo "set<br>";
                break;
            }
            //echo "found ".$found.",date:".$collector[$found]["date"]." data:".$collector[$found]["user"][$i]."<br>";
        }
    }
    // sum up the data as string
    $data = "";
    //echo "<hr><hr>".$db_mach[$row2["id"]]["name"]."<hr>";
    for ($i = 0; $i < count($collector); $i++) {
        $data .= '{ "category": "' . date("Y-m-d", $collector[$i]["date"]) . '"';
        for ($ii = 0; $ii < count($user_on_machine); $ii++) {
            $data .= ', "u' . $user_on_machine[$ii]["id"] . '":' . $collector[$i]["user"][$ii];
        }
        $data .= '},';
    }
    // remove trailing ","
    if (strlen($data) > 1) {
        $data = substr($data, 0, strlen($data) - 1);
    }
    // generate config section (which user are on this graph)
    $g_config = gen_config($user_on_machine);
    $ret[0] = gen_chart($g_config, $data, $db_mach[$machine_id]["name"]);
    $ret[1] = '<div id="' . $db_mach[$machine_id]["name"] . '" style="width: 100%; height: 300px; background-color: #FFFFFF;" ></div>';
    $ret[2] = $log_entries;
    return $ret;
}
Example #2
0
        $email = $_SESSION['email'];
    } else {
        $email = '';
    }
    $tpl->assign(array('VL_USR_NAME' => $first_name, 'VL_LAST_USRNAME' => $last_name, 'VL_USR_FIRM' => $company, 'VL_USR_POSTCODE' => $postal_code, 'VL_USRCITY' => $city, 'VL_COUNTRY' => $country, 'VL_STREET1' => $street1, 'VL_STREET2' => $street2, 'VL_PHONE' => $phone, 'VL_FAX' => $fax, 'VL_EMAIL' => $email));
}
/*
* Functions end
*/
/*
*
* static page messages.
*
*/
if (isset($_SESSION['user_id']) && $_SESSION['plan_id']) {
    $user_id = $_SESSION['user_id'];
    $plan_id = $_SESSION['plan_id'];
} else {
    system_message(tr('You do not have permission to access this interface!'));
}
gen_purchase_haf($tpl, $sql, $user_id);
gen_chart($tpl, $sql, $user_id, $plan_id);
gen_personal_data($tpl);
gen_page_message($tpl);
$tpl->assign(array('YOUR_CHART' => tr('Your Chart'), 'TR_COSTS' => tr('Costs'), 'TR_PACKAGE_PRICE' => tr('Price'), 'TR_PACKAGE_SETUPFEE' => tr('Setup fee'), 'TR_TOTAL' => tr('Total'), 'TR_CONTINUE' => tr('Purchase'), 'TR_CHANGE' => tr('Change'), 'TR_FIRSTNAME' => tr('First name'), 'TR_LASTNAME' => tr('Last name'), 'TR_COMPANY' => tr('Company'), 'TR_POST_CODE' => tr('Zip / Postal code'), 'TR_CITY' => tr('City'), 'TR_COUNTRY' => tr('Country'), 'TR_STREET1' => tr('Street 1'), 'TR_STREET2' => tr('Street 2'), 'TR_EMAIL' => tr('Email'), 'TR_PHONE' => tr('Phone'), 'TR_FAX' => tr('Fax'), 'TR_EMAIL' => tr('Email'), 'TR_PERSONAL_DATA' => tr('Personal Data')));
$tpl->parse('PAGE', 'page');
$tpl->prnt();
if (isset($cfg['DUMP_GUI_DEBUG'])) {
    dump_gui_debug();
}
unset_messages();