289 lines
8.4 KiB
PHP
289 lines
8.4 KiB
PHP
<?php
|
|
$ValidAccess = 2010;
|
|
|
|
require_once("include/globals.php");
|
|
|
|
|
|
//
|
|
// Ensure that the user is logged in
|
|
//
|
|
if (SessionActive() != 1 || !UserLoggedIn()) {
|
|
$error_message = getLanguageText('ERRORMSG-ACCESS-DENIED');
|
|
$action = '';
|
|
$naction = '';
|
|
header("Location: /?action=$action&naction=$naction$headerArgs&form_message=" . urlencode($form_message) . "&error_message=" . urlencode($error_message));
|
|
exit();
|
|
}
|
|
|
|
|
|
$school_name = $school_record['school_name'];
|
|
$report_title = getLanguageText('TEXT-ACTIVITY-LOG-REPORT')." - $school_name";
|
|
$document_name = getLanguageText('TEXT-ACTIVITY-LOG-REPORT');
|
|
$file_name = "activity.log.pdf";
|
|
|
|
|
|
unset($user_num);
|
|
unset($start_date);
|
|
unset($end_date);
|
|
unset($selected_userid);
|
|
unset($selected_ip);
|
|
unset($selected_activity);
|
|
unset($search_text);
|
|
if (array_key_exists('user_num',$_GET)) $user_num = intval($_GET['user_num']);
|
|
if (array_key_exists('start_date',$_GET)) $start_date = db_escape_string($_GET['start_date']);
|
|
if (array_key_exists('end_date',$_GET)) $end_date = db_escape_string($_GET['end_date']);
|
|
if (array_key_exists('selected_userid',$_GET)) $selected_userid = db_escape_string($_GET['selected_userid']);
|
|
if (array_key_exists('selected_ip',$_GET)) $selected_ip = db_escape_string($_GET['selected_ip']);
|
|
if (array_key_exists('selected_activity',$_GET)) $selected_activity = db_escape_string($_GET['selected_activity']);
|
|
if (array_key_exists('search_text',$_GET)) $search_text = db_escape_string($_GET['search_text']);
|
|
|
|
|
|
//
|
|
// Parse any parameters
|
|
//
|
|
$where = "where school_num = $school_num ";
|
|
|
|
|
|
// Handle selected date ranges
|
|
if (!isset($start_date)) $start_date = date("Y-m-d 00:00:00",time());
|
|
if (!isset($end_date)) $end_date = date("Y-m-d 23:59:59",time());
|
|
|
|
$start_date = date("Y-m-d 00:00:00",strtotime($start_date));
|
|
|
|
if ($end_date < substr($start_date,0,10)) {
|
|
$end_date = substr($start_date,0,10);
|
|
$error_message = getLanguageText('ERRORMSG-DATE-RANGE-ERROR');
|
|
}
|
|
|
|
$end_date = date("Y-m-d 23:59:59",strtotime($end_date));
|
|
|
|
$sdate = substr($start_date,0,10);
|
|
$edate = substr($end_date,0,10);
|
|
|
|
$stime = strtotime($start_date);
|
|
$etime = strtotime($end_date);
|
|
|
|
|
|
$where .= "and activity_time between $stime and $etime ";
|
|
$report_subtitle = getLanguageText('TEXT-ACTIVITY-TIME') . ": $sdate - $edate";
|
|
|
|
|
|
// View only a selected userid
|
|
if (isset($selected_userid) && strlen($selected_userid) > 0) {
|
|
$where .= "and userid = '" . db_escape_string($selected_userid) . "' ";
|
|
$report_subtitle .= " / " . getLanguageText('TEXT-USER-ID') . ": " . $selected_userid;
|
|
}
|
|
|
|
// View only a selected ip
|
|
if (isset($selected_ip) && strlen($selected_ip) > 0) {
|
|
$where .= "and user_ip = '$selected_ip' ";
|
|
$report_subtitle .= " / " . getLanguageText('TEXT-IP-ADDRESS') . ": " . $selected_ip;
|
|
}
|
|
|
|
// View only a selected activity
|
|
if (isset($selected_activity) && strlen($selected_activity) > 0) {
|
|
$where .= "and activity = '$selected_activity' ";
|
|
$report_subtitle .= " / " . getLanguageText('TEXT-ACTIVITY') . ": " . $selected_activity;
|
|
}
|
|
|
|
// Search text processing
|
|
if (isset($search_text) && strlen($search_text) > 0) {
|
|
$where .= "and information LIKE '%$search_text%' ";
|
|
$report_subtitle .= " / " . getLanguageText('TEXT-SEARCH-TEXT') . ": " . $search_text;
|
|
}
|
|
|
|
if ($_SESSION['UserInfo']['type'] != 'SuperUser') {
|
|
$where .= "and userid != 'superuser' ";
|
|
}
|
|
|
|
|
|
|
|
//
|
|
// Setup the PDF
|
|
//
|
|
$document_font = $school_record['document_font'];
|
|
if (strlen($document_font) == 0) $document_font = "Helvetica";
|
|
|
|
$document_font_weight = "";
|
|
$document_text_color = "#000000";
|
|
$document_font_size = 9;
|
|
|
|
|
|
// Setup parameters for this document
|
|
$max_rows = 250;
|
|
$title_width = 190;
|
|
$left_col = 10;
|
|
|
|
$start_row = 10;
|
|
$incr = 4;
|
|
|
|
$cols = array();
|
|
$widths = array();
|
|
$cols[0] = $left_col;
|
|
$widths[] = 50;
|
|
$widths[] = 50;
|
|
$widths[] = 40;
|
|
$widths[] = 50;
|
|
|
|
// Setup columns based on width values
|
|
for ($i = 0; $i < count($widths); $i++) {
|
|
$cols[$i + 1] = $cols[$i] + $widths[$i];
|
|
}
|
|
|
|
$headings = array(getLanguageText('TEXT-NAME'), getLanguageText('TEXT-ACTIVITY-TIME'), getLanguageText('TEXT-IP-ADDRESS'), getLanguageText('TEXT-ACTIVITY'));
|
|
|
|
|
|
|
|
//
|
|
// Setup PDF document
|
|
//
|
|
require("tcpdf/config/lang/eng.php");
|
|
require("tcpdf/tcpdf.php");
|
|
|
|
$logo_url = $school_record['logo_url'];
|
|
$logo_image = "images/" . $school_record['logo_image'];
|
|
$logo_row = $max_rows + 5;
|
|
|
|
class PDF extends TCPDF {
|
|
function Header() {
|
|
global $incr, $left_col, $start_row, $title_width, $document_font, $document_font_size, $report_title, $report_subtitle, $cols, $widths, $headings;
|
|
|
|
$row = $start_row;
|
|
|
|
// Print the header
|
|
$this->SetFillColor(hexdec("cc"),hexdec("cc"),hexdec("cc"));
|
|
$this->SetFont($document_font,"B",$document_font_size + 1);
|
|
$this->SetXY($left_col,$row);
|
|
$this->Cell($title_width,$incr + 1,$report_title,'0',1,'L',true,'',1);
|
|
|
|
$this->SetFont($document_font,"B",$document_font_size);
|
|
if (isset($report_subtitle) && strlen($report_subtitle) > 0) {
|
|
$row = $row + $incr + 2;
|
|
$this->SetXY($left_col,$row);
|
|
$this->Cell($title_width,$incr + 1,$report_subtitle,'0',1,'L',true,'',1);
|
|
}
|
|
|
|
$this->SetFillColor(hexdec("dd"),hexdec("dd"),hexdec("dd"));
|
|
if (isset($headings) && is_array($headings) && count($headings)) {
|
|
$row += $incr * 2;
|
|
for ($i = 0; $i < count($headings); $i++) {
|
|
$col = $cols[$i];
|
|
$width = $widths[$i];
|
|
$this->SetXY($col,$row);
|
|
$this->Cell($width,$incr + 1,' ' . $headings[$i],'1',1,'L',true,'',1);
|
|
}
|
|
}
|
|
}
|
|
|
|
function Footer() {
|
|
global $incr, $left_col, $title_width, $max_rows, $document_font, $document_font_size, $document_name, $logo_image, $logo_url, $logo_row, $school_name;
|
|
|
|
// Print the date
|
|
$this->SetFont($document_font,"",$document_font_size - 1);
|
|
$this->SetXY($left_col,$logo_row);
|
|
$date = dateString('datetime');
|
|
$this->Cell($title_width,$incr - 1,"$document_name: $date",'0',1,'R','',1);
|
|
|
|
$this->SetXY($left_col,$logo_row + $incr);
|
|
$this->Cell($title_width,$incr - 1,"$school_name",'0',1,'R','',1);
|
|
|
|
$this->Image($logo_image,10,$logo_row, 50);
|
|
|
|
$this->SetXY(20,$logo_row + 9);
|
|
$this->SetFont($document_font,"B",$document_font_size);
|
|
$this->Cell($title_width,$incr,$logo_url,'0',1,'L','',1);
|
|
}
|
|
}
|
|
|
|
// Force exact physical size for Letter: 8.5 x 11 inches => 215.9mm x 279.4mm (portrait)
|
|
$pageFormat = array(215.9, 279.4);
|
|
|
|
$pdf= new PDF('P', 'mm', $pageFormat, true, 'UTF-8', false);
|
|
|
|
// set default monospaced font
|
|
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
|
|
|
|
//set margins
|
|
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
|
|
|
|
//set auto page breaks
|
|
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
|
|
|
|
//set image scale factor
|
|
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
|
|
|
|
$font_red = hexdec("00");
|
|
$font_green = hexdec("00");
|
|
$font_blue = hexdec("00");
|
|
|
|
$pdf->SetTextColor($font_red,$font_green,$font_blue);
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
|
|
$pdf->addPage();
|
|
|
|
|
|
//
|
|
// Get set of records
|
|
//
|
|
$query = "SELECT userid,activity_datetime,user_ip,activity_time,activity " .
|
|
"FROM activity_log $where order by activity_time desc,activity";
|
|
$activities = db_query($query);
|
|
|
|
|
|
//
|
|
// Generate the report
|
|
//
|
|
$curr_row = $start_row + 5 * $incr;
|
|
$count = 0;
|
|
|
|
while ($row = db_fetch_array($activities)) {
|
|
|
|
// New page if current page is full
|
|
if ($curr_row > $max_rows - $incr - 2) {
|
|
$pdf->addPage();
|
|
$curr_row = $start_row + 5 * $incr;
|
|
$count = 0;
|
|
}
|
|
|
|
extract($row);
|
|
|
|
$pdf->SetFont($document_font,"",$document_font_size);
|
|
$pdf->SetFillColor(hexdec("ee"),hexdec("ee"),hexdec("ee"));
|
|
|
|
$fill = true;
|
|
if ($count % 2) $fill = false;
|
|
$count++;
|
|
|
|
$data = array();
|
|
$name = db_getVal("SELECT concat(first_name,' ',last_name) FROM users WHERE school_num = $base_school_num AND userid = '" . db_escape_string($userid) . "'");
|
|
if (strlen($name) == 0) $name = $userid;
|
|
|
|
$data[0] = $name;
|
|
$data[1] = $activity_datetime;
|
|
$data[2] = $user_ip;
|
|
$data[3] = $activity;
|
|
|
|
for ($i = 0; $i < count($headings); $i++) {
|
|
$col = $cols[$i];
|
|
$width = $widths[$i];
|
|
$pdf->SetXY($col,$curr_row);
|
|
$pdf->Cell($width,$incr,$data[$i],'1',1,'L',$fill,'',1);
|
|
}
|
|
|
|
$curr_row += $incr;
|
|
}
|
|
|
|
|
|
// Output the completed PDF
|
|
header('Pragma: public');
|
|
header('Expires: 0');
|
|
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
|
header('Cache-Control: private',false);
|
|
header('Content-type: application/pdf');
|
|
header("Content-Disposition: attachment; filename=$file_name");
|
|
|
|
$pdf->Output($file_name,"D");
|
|
return;
|
|
|
|
?>
|