From 941c251304385f4c63c0fedd67778179fcebb525 Mon Sep 17 00:00:00 2001 From: Adrian Greeve Date: Tue, 14 Aug 2012 13:25:36 +0800 Subject: [PATCH] MDL-34429 - lib - Changed the log downloads to use the new CSV class. --- course/lib.php | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/course/lib.php b/course/lib.php index 06fb241774c..3f2a2a54e45 100644 --- a/course/lib.php +++ b/course/lib.php @@ -534,10 +534,19 @@ function print_mnet_log($hostid, $course, $user=0, $date=0, $order="l.time ASC", function print_log_csv($course, $user, $date, $order='l.time DESC', $modname, $modid, $modaction, $groupid) { - global $DB; + global $DB, $CFG; - $text = get_string('course')."\t".get_string('time')."\t".get_string('ip_address')."\t". - get_string('fullnameuser')."\t".get_string('action')."\t".get_string('info'); + require_once($CFG->libdir . '/csvlib.class.php'); + + $csvexporter = new csv_export_writer('tab'); + + $header = array(); + $header[] = get_string('course'); + $header[] = get_string('time'); + $header[] = get_string('ip_address'); + $header[] = get_string('fullnameuser'); + $header[] = get_string('action'); + $header[] = get_string('info'); if (!$logs = build_logs_array($course, $user, $date, $order, '', '', $modname, $modid, $modaction, $groupid)) { @@ -564,16 +573,10 @@ function print_log_csv($course, $user, $date, $order='l.time DESC', $modname, $strftimedatetime = get_string("strftimedatetime"); - $filename = 'logs_'.userdate(time(),get_string('backupnameformat', 'langconfig'),99,false); - $filename .= '.txt'; - header("Content-Type: application/download\n"); - header("Content-Disposition: attachment; filename=\"$filename\""); - header("Expires: 0"); - header("Cache-Control: must-revalidate,post-check=0,pre-check=0"); - header("Pragma: public"); - - echo get_string('savedat').userdate(time(), $strftimedatetime)."\n"; - echo $text."\n"; + $csvexporter->set_filename('logs', '.txt'); + $title = array(get_string('savedat').userdate(time(), $strftimedatetime)); + $csvexporter->add_data($title); + $csvexporter->add_data($header); if (empty($logs['logs'])) { return true; @@ -603,9 +606,9 @@ function print_log_csv($course, $user, $date, $order='l.time DESC', $modname, $firstField = format_string($courses[$log->course], true, array('context' => $coursecontext)); $fullname = fullname($log, has_capability('moodle/site:viewfullnames', $coursecontext)); $row = array($firstField, userdate($log->time, $strftimedatetime), $log->ip, $fullname, $log->module.' '.$log->action, $log->info); - $text = implode("\t", $row); - echo $text." \n"; + $csvexporter->add_data($row); } + $csvexporter->download_file(); return true; }