示例#1
0
    foreach ($users as $login => $value) {
        $workSheet->write($row, 1, formatLogin($login), $fieldLeftFormat);
        $workSheet->write($row, 2, $value['accesses'], $fieldCenterFormat);
        $time = EfrontTimes::formatTimeForReporting($value['seconds']);
        $workSheet->write($row++, 3, $time['time_string'], $fieldCenterFormat);
    }
    $workSheet =& $workBook->addWorkSheet("Analytic log");
    $workSheet->setInputEncoding('utf-8');
    $workSheet->setColumn(0, 0, 5);
    $workSheet->write(1, 1, _ANALYTICLOG, $headerFormat);
    $workSheet->mergeCells(1, 1, 1, 7);
    $workSheet->setColumn(1, 6, 30);
    $workSheet->write(2, 1, _LOGIN, $fieldLeftFormat);
    $workSheet->write(2, 2, _LESSON, $fieldLeftFormat);
    $workSheet->write(2, 3, _UNIT, $fieldLeftFormat);
    $workSheet->write(2, 4, _ACTION, $fieldLeftFormat);
    $workSheet->write(2, 5, _TIME, $fieldLeftFormat);
    $workSheet->write(2, 6, _IPADDRESS, $fieldLeftFormat);
    $row = 3;
    foreach ($analytic_log as $value) {
        $workSheet->write($row, 1, formatLogin($value['users_LOGIN']), $fieldLeftFormat);
        $workSheet->write($row, 2, $value['lesson_name'], $fieldCenterFormat);
        $workSheet->write($row, 3, $value['content_name'], $fieldLeftFormat);
        $workSheet->write($row, 4, $actions[$value['action']], $fieldLeftFormat);
        $workSheet->write($row, 5, formatTimestamp($value['timestamp'], 'time'), $fieldLeftFormat);
        $workSheet->write($row++, 6, eF_decodeIP($value['session_ip']), $fieldLeftFormat);
    }
    $workBook->send('system_reports.xls');
    $workBook->close();
    exit(0);
}
示例#2
0
 /**
  * Get user online times
  *
  * This function calculates the time a user spent online. If the optional interval parameter is set, then
  * statistics are calculated only for this time period.
  * <br/>Example:
  * <code>
  * $interval = array('from' => time()-86400, 'to' => time());        //Calculate statistics for the last 24 hours
  * $times = EfrontStats :: getUserTimes('john', $interval);
  * print_r($times);
  * //Returns:
  *Array
  *(
  *    [duration] => Array
  *        (
  *            [0] => 19
  *            [1] => 120
  *            [2] => 63
  *        )
  *
  *    [times] => Array
  *        (
  *           [0] => 1118770769
  *           [1] => 1118824615
  *           [2] => 1118824760
  *        )
  *)
  * </code>
  *
  * @param string $login The user login name
  * @param array $interval The time interval to calculate statistics for
  * @return array The login times and durations (in seconds)
  * @version 1.0 27/10/2005
  */
 public static function getUserTimes($login, $interval = false)
 {
     $times = array('duration' => array(), 'time' => array(), 'session_ip' => array());
     if (isset($interval['from']) && eF_checkParameter($interval['from'], 'timestamp') && isset($interval['to']) && eF_checkParameter($interval['to'], 'timestamp')) {
         $result = eF_getTableDataFlat("logs", "timestamp, action, session_ip", "timestamp > " . $interval['from'] . " and timestamp < " . $interval['to'] . " and users_LOGIN='******' and (action='login' or action = 'logout')", "timestamp");
     } else {
         $result = eF_getTableDataFlat("logs", "timestamp, action, session_ip", "users_LOGIN='******' and (action='login' or action = 'logout')", "timestamp");
     }
     if (sizeof($result) > 0) {
         for ($i = 0; $i < sizeof($result['action']) - 1; $i++) {
             //The algorithm goes like this: We search for the 'login' actions in the log. When one is found, then we search either for the next 'login' or 'logout' action, if there are no other actions, or the last non-login or logout action. This way, we calculate the true time spent inside the system. If we calculated only the logout-login times, then when a user had closed a window without logging out first, the online time would be reported falsely
             if ($result['action'][$i] == 'login') {
                 $count = $i + 1;
                 $end_action = $result['timestamp'][$count];
                 while ($result['action'][$count] != 'logout' && $result['action'][$count] != 'login' && $count < sizeof($result['action'])) {
                     $end_action = $result['timestamp'][$count];
                     $count++;
                 }
                 if ($end_action - $result['timestamp'][$i] <= 3600) {
                     //only take into account intervals less than one hour
                     $times['duration'][] = $end_action - $result['timestamp'][$i];
                     $times['time'][] = $result['timestamp'][$i];
                     $times['session_ip'][] = eF_decodeIP($result['session_ip'][$i]);
                 }
             }
         }
     }
     return $times;
 }