header("Pragma: no-cache"); header("Expires: 0"); $startnum = inet_aton(DEFAULTROUTE); $endnum = inet_aton(ALLNETS); // if a specific network template exists, use that, else use generic template $template = new IPplanIPTemplate("basetemplate", $cust); $err = $template->is_error(); $result = $ds->GetBase($startnum, $endnum, '', $cust); while ($row = $result->FetchRow()) { echo inet_ntoa($row["baseaddr"]) . FIELDS_TERMINATED_BY . $row["descrip"] . FIELDS_TERMINATED_BY . inet_ntoa(inet_aton(ALLNETS) + 1 - $row["subnetsize"]) . FIELDS_TERMINATED_BY; if (!$err) { $result_template =& $ds->ds->Execute("SELECT info, infobin\n FROM baseadd\n WHERE baseindex=" . $row["baseindex"]); if ($rowadd = $result_template->FetchRow()) { $template->Merge($template->decode($rowadd["info"])); foreach ($template->userfld as $arr) { $tmpfield = csv_escape($arr["value"]); echo FIELDS_TERMINATED_BY . $arr["value"]; } } } echo "\n"; } // wrap any multiline string with quotes // this function only works with php 5 and above function csv_escape($str) { if (PHP_VERSION >= 5) { $str = str_replace(array('"', ',', "\n", "\r"), array('""', ',', "\n", "\r"), $str, $count); if ($count) { return '"' . $str . '"'; } else {
} if ($is_editor) { if (isset($_GET['enc']) and $_GET['enc'] == '1253') { $charset = 'Windows-1253'; } else { $charset = 'UTF-8'; } $crlf = "\r\n"; header("Content-Type: text/csv; charset={$charset}"); header("Content-Disposition: attachment; filename=groupuserduration.csv"); if (isset($_REQUEST['u_date_start']) and isset($_REQUEST['u_date_end'])) { $u_date_start = $_REQUEST['u_date_start']; $u_date_end = $_REQUEST['u_date_end']; } else { $min_date = Database::get()->querySingle("SELECT MIN(day) AS minday FROM actions_daily WHERE course_id = ?d", $course_id)->minday; $u_date_start = strftime('%Y-%m-%d', strtotime($min_date)); $u_date_end = strftime('%Y-%m-%d', strtotime('now')); } if (isset($u_date_start) and isset($u_date_end)) { $first_line = "{$langFrom} {$u_date_start} {$langAs} {$u_date_end}"; } else { $date_spec = ''; } echo csv_escape($first_line), $crlf, $crlf, join(';', array_map("csv_escape", array($langSurname, $langName, $langAm, $langGroup, $langDuration))), $crlf; $totalDuration = 0; $result = user_duration_query($course_id, $u_date_start, $u_date_end, $group_id); foreach ($result as $row) { echo csv_escape($row->surname) . ";" . csv_escape($row->givenname) . ";" . csv_escape($row->am) . ";" . csv_escape($group_name) . ";" . csv_escape(format_time_duration(0 + $row->duration)) . ";" . csv_escape(round($row->duration / 3600)); echo $crlf; } }
$answer_total = 0; foreach ($answers as $a) { $answer_counts[] = $a->count; $answer_total += $a->count; if ($a->aid < 0) { $answer_text[] = $langPollUnknown; } else { $answer_text[] = $a->answer; } } echo csv_escape($langAnswers), ';', csv_escape($langResults), ' (%)', $crlf; foreach ($answer_counts as $i => $count) { $percentage = round(100 * ($count / $answer_total)); $label = $answer_text[$i]; echo csv_escape($label), ';', csv_escape($count), ';', csv_escape($percentage), $crlf; } echo $crlf; } else { // free text questions echo csv_escape($q->question_text), $crlf; $answers = Database::get()->queryArray("SELECT answer_text, user_id FROM poll_answer_record\n WHERE qid = ?d", $q->pqid); $k = 0; foreach ($answers as $a) { $k++; $student_name = $anonymized ? "{$langStudent} {$k}" : uid_to_name($a->user_id); echo csv_escape($student_name), ';', csv_escape($a->answer_text), $crlf; } echo $crlf; } } }
$pageName = $langUserDuration; $navigation[] = array('url' => 'index.php?course=' . $course_code, 'name' => $langUsage); statistics_tools($course_code, "userduration"); // display number of users $tool_content .= "\n <div class='alert alert-info'>\n <b>{$langDumpUserDurationToFile}: </b>1. <a href='userduration.php?course={$course_code}&format=csv'>{$langcsvenc2}</a>\n 2. <a href='userduration.php?course={$course_code}&format=csv&enc=1253'>{$langcsvenc1}</a>\n </div>"; $tool_content .= "\n <table class='tbl_alt' width='99%'>\n <tr>\n <th class='left'> {$langSurname} {$langName}</th>\n <th>{$langAm}</th>\n <th>{$langGroup}</th>\n <th>{$langDuration}</th>\n </tr>"; } $result = user_duration_query($course_id); if (count($result) > 0) { $i = 0; foreach ($result as $row) { $i++; $grp_name = user_groups($course_id, $row->id, $format); if ($format == 'html') { if ($i % 2 == 0) { $tool_content .= "<tr class='even'>"; } else { $tool_content .= "<tr class='odd'>"; } $tool_content .= "<td class='bullet'>" . display_user($row->id) . "</td>\n <td class='center'>{$row->am}</td>\n <td class='center'>{$grp_name}</td>\n <td class='center'>" . format_time_duration(0 + $row->duration) . "</td>\n </tr>"; } else { echo csv_escape($row->surname . ' ' . $row->givenname), ';', csv_escape($row->am), ';', csv_escape($grp_name), ';', csv_escape(format_time_duration(0 + $row->duration)), $crlf; } } if ($format == 'html') { $tool_content .= "</table>"; } } if ($format == 'html') { draw($tool_content, 2); }
} else { $answers = Database::get()->queryArray("SELECT COUNT(arid) AS count, answer_text, user_id FROM poll_answer_record WHERE qid = ?d GROUP BY answer_text", $q->pqid); } $answer_counts = array(); $answer_text = array(); $answer_total = 0; foreach ($answers as $a) { $answer_counts[] = $a->count; $answer_total += $a->count; if ($q->qtype == QTYPE_SINGLE or $q->qtype == QTYPE_MULTIPLE) { if ($a->aid < 0) { $answer_text[] = $langPollUnknown; } else { $answer_text[] = $a->answer; } } else { $answer_text[] = $a->answer_text; } } echo csv_escape($langAnswers), ';', csv_escape($langResults), ';', csv_escape($langResults), ' (%)', $crlf; foreach ($answer_counts as $i => $count) { $percentage = round(100 * ($count / $answer_total)); $label = $answer_text[$i]; echo csv_escape($label), ';', csv_escape($count), ';', csv_escape($percentage), $crlf; } echo $crlf; } } }
$crlf; // display a list of user and their respective progress $sql = "SELECT U.`surname`, U.`givenname`, U.`id` FROM `user` AS U, `course_user` AS CU WHERE U.`id`= CU.`user_id` AND CU.`course_id` = $course_id ORDER BY U.`surname` ASC, U.`givenname` ASC"; $usersList = get_limited_list($sql, 500000); foreach ($usersList as $user) { echo "$crlf"; $learningPathList = Database::get()->queryArray("SELECT learnPath_id FROM lp_learnPath WHERE course_id = ?d", $course_id); $iterator = 1; $globalprog = 0; foreach ($learningPathList as $learningPath) { // % progress $prog = get_learnPath_progress($learningPath->learnPath_id, $user->id); if ($prog >= 0) { $globalprog += $prog; } $iterator++; } $total = round($globalprog / ($iterator - 1)); echo csv_escape(uid_to_name($user->id)) . ";" . csv_escape(uid_to_am($user->id)) . ";" . csv_escape(user_groups($course_id, $user->id, 'csv')) . ";" . $total . "%"; } echo $crlf;
$i = 0; foreach ($result as $row) { $i++; $grp_name = user_groups($course_id, $row->id, $format); if ($format == 'html') { if ($i % 2 == 0) { $tool_content .= "<tr class='even'>"; } else { $tool_content .= "<tr class='odd'>"; } $tool_content .= "<td class='bullet'>" . display_user($row->id) . "</td> <td class='center'>$row->am</td> <td class='center'>$grp_name</td> <td class='center'>" . format_time_duration(0 + $row->duration) . "</td> </tr>"; } else { echo csv_escape($row->surname . ' ' . $row->givenname), ';', csv_escape($row->am), ';', csv_escape($grp_name), ';', csv_escape(format_time_duration(0 + $row->duration)), $crlf; } } if ($format == 'html') { $tool_content .= "</table>"; } } if ($format == 'html') { draw($tool_content, 2); }
$sid = $row->uid; $surname = uid_to_name($sid,'surname'); $name = uid_to_name($sid,'givenname'); $am = uid_to_am($sid); $result2 = Database::get()->queryArray("SELECT DATE_FORMAT(record_start_date, '%Y-%m-%d / %H:%i') AS record_start_date, record_end_date, TIME_TO_SEC(TIMEDIFF(record_end_date, record_start_date)) AS time_duration, total_score, total_weighting FROM `exercise_user_record` WHERE uid = ?d AND eid = ?d", $sid, $exerciseId); foreach ($result2 as $row2) { $output .= csv_escape($surname) . "\t"; $output .= csv_escape($name) . "\t"; $output .= csv_escape($am) . "\t"; $recordStartDate = $row2->record_start_date; $output .= csv_escape($recordStartDate) . "\t"; if ($row2->time_duration == '00:00:00' or empty($row2->time_duration)) { // for compatibility $output .= csv_escape($langNotRecorded) . "\t"; } else { $output .= csv_escape(format_time_duration($row2->time_duration)) . "\t"; } $totalScore = $row2->total_score; $totalWeighting = $row2->total_weighting; $output .= csv_escape("( $totalScore/$totalWeighting )") . "\t"; $output .= "$crlf"; } } echo iconv('UTF-8', 'UTF-16LE', $output); } // end of initial if
$charset = 'Windows-1253'; $sendSep = true; } else { $charset = 'UTF-8'; $sendSep = false; } $crlf = "\r\n"; header("Content-Type: text/csv; charset=$charset"); header("Content-Disposition: attachment; filename=listattendanceusers.csv"); if ($sendSep) { echo 'sep=;', $crlf; } $sql = Database::get()->queryArray("SELECT id, title FROM attendance_activities WHERE attendance_id = ?d", $_GET['attendance_id']); foreach ($sql as $act) { $title = !empty($act->title) ? $act->title : $langGradebookNoTitle; echo csv_escape($title). "$crlf"; echo join(';', array_map("csv_escape", array($langSurname, $langName, $langAm, $langUsername, $langEmail, $langAttendanceAbsences))); echo $crlf; $sql2 = Database::get()->queryArray("SELECT uid, attend FROM attendance_book WHERE attendance_activity_id = ?d", $act->id); foreach ($sql2 as $u) { $userdata = Database::get()->querySingle("SELECT surname, givenname, username, am, email FROM user WHERE id = ?d", $u->uid); echo join(';', array_map("csv_escape", array($userdata->surname, $userdata->givenname, $userdata->am, $userdata->username, $userdata->email, $u->attend))); echo "$crlf"; } echo "$crlf"; echo "$crlf"; }
$crlf = "\r\n"; $output = "{$bom}{$langSurname}\t{$langName}\t{$langAm}\t{$langExerciseStart}\t{$langExerciseDuration}\t{$langYourTotalScore2}{$crlf}"; $output .= "{$crlf}"; $result = Database::get()->queryArray("SELECT DISTINCT uid FROM `exercise_user_record` WHERE eid = ?d", $exerciseId); foreach ($result as $row) { $sid = $row->uid; $surname = uid_to_name($sid, 'surname'); $name = uid_to_name($sid, 'givenname'); $am = uid_to_am($sid); $result2 = Database::get()->queryArray("SELECT DATE_FORMAT(record_start_date, '%Y-%m-%d / %H:%i') AS record_start_date,\n\t\t\trecord_end_date, TIME_TO_SEC(TIMEDIFF(record_end_date, record_start_date)) AS time_duration,\n\t\t\ttotal_score, total_weighting\n\t\t\tFROM `exercise_user_record` WHERE uid = ?d AND eid = ?d", $sid, $exerciseId); foreach ($result2 as $row2) { $output .= csv_escape($surname) . "\t"; $output .= csv_escape($name) . "\t"; $output .= csv_escape($am) . "\t"; $recordStartDate = $row2->record_start_date; $output .= csv_escape($recordStartDate) . "\t"; if ($row2->time_duration == '00:00:00' or empty($row2->time_duration)) { // for compatibility $output .= csv_escape($langNotRecorded) . "\t"; } else { $output .= csv_escape(format_time_duration($row2->time_duration)) . "\t"; } $totalScore = $row2->total_score; $totalWeighting = $row2->total_weighting; $output .= csv_escape("( {$totalScore}/{$totalWeighting} )") . "\t"; $output .= "{$crlf}"; } } echo iconv('UTF-8', 'UTF-16LE', $output); } // end of initial if
$u_date_start = $_REQUEST['u_date_start']; $u_date_end = $_REQUEST['u_date_end']; } else { $min_date = Database::get()->querySingle("SELECT MIN(day) AS minday FROM actions_daily WHERE course_id = ?d", $course_id)->minday; $u_date_start = strftime('%Y-%m-%d', strtotime($min_date)); $u_date_end = strftime('%Y-%m-%d', strtotime('now')); } if (isset($u_date_start) and isset($u_date_end)) { $first_line = "$langFrom $u_date_start $langAs $u_date_end"; } else { $date_spec = ''; } echo csv_escape($first_line), $crlf, $crlf, join(';', array_map("csv_escape", array($langSurname, $langName, $langAm, $langGroup, $langDuration))), $crlf; $totalDuration = 0; $result = user_duration_query($course_id, $u_date_start, $u_date_end, $group_id); foreach ($result as $row) { echo csv_escape($row->surname) . ";" . csv_escape($row->givenname) . ";" . csv_escape($row->am) . ";" . csv_escape($group_name) . ";" . csv_escape(format_time_duration(0 + $row->duration)) . ";" . csv_escape(round($row->duration / 3600)); echo $crlf; }
} echo csv_escape($for); if (is_array($friend['meeting_sex'])) { $sex = implode(' ', $friend['meeting_sex']); } else { $sex = ''; } echo csv_escape($sex); if (is_array($friend['interests'])) { $interests = implode(' ', $friend['interests']); } else { $interests = ''; } echo csv_escape($interests); echo csv_escape($friend['uid']); echo csv_escape($friend['profile_url']); echo "\n"; flush(); } break; default: die('Invalid format'); break; } function csv_escape($text) { $text = mb_convert_encoding($text, 'UTF-16LE', 'UTF-8'); $text = str_replace("\r", ' ', $text); $text = str_replace("\n", ' ', $text); $text = str_replace('"', '""', $text); $text = '"' . $text . '",';
function export_csv($csv_file, &$results, &$percentile_times) { if (empty($csv_file)) { return TRUE; } if (($fp = fopen($csv_file, 'w')) === FALSE) { return FALSE; } if (fputs($fp, csv_escape('Test') . CSV_SEP . csv_escape('Time') . CSV_SEP . csv_escape('Percentile') . CSV_NL) === FALSE) { @fclose($fp); unlink($csv_file); return FALSE; } foreach ($results as $test => $time) { if (fputs($fp, csv_escape($test) . CSV_SEP . csv_escape(sprintf('%.04f', $time)) . CSV_SEP . csv_escape(sprintf('%.03f', $percentile_times[$test])) . CSV_NL) === FALSE) { @fclose($fp); unlink($csv_file); return FALSE; } } if (fclose($fp) === FALSE) { return FALSE; } return TRUE; }
require_once 'include/lib/learnPathLib.inc.php'; require_once 'modules/group/group_functions.php'; if (isset($_GET['enc']) and $_GET['enc'] == '1253') { $charset = 'Windows-1253'; } else { $charset = 'UTF-8'; } $crlf = "\r\n"; header("Content-Type: text/csv; charset={$charset}"); header("Content-Disposition: attachment; filename=userslearningpathstats.csv"); echo join(';', array_map("csv_escape", array($langStudent, $langAm, $langGroup, $langProgress))), $crlf; // display a list of user and their respective progress $sql = "SELECT U.`surname`, U.`givenname`, U.`id`\n\t\tFROM `user` AS U, `course_user` AS CU\n\t\tWHERE U.`id`= CU.`user_id`\n\t\tAND CU.`course_id` = {$course_id}\n\t\tORDER BY U.`surname` ASC, U.`givenname` ASC"; $usersList = get_limited_list($sql, 500000); foreach ($usersList as $user) { echo "{$crlf}"; $learningPathList = Database::get()->queryArray("SELECT learnPath_id FROM lp_learnPath WHERE course_id = ?d", $course_id); $iterator = 1; $globalprog = 0; foreach ($learningPathList as $learningPath) { // % progress $prog = get_learnPath_progress($learningPath->learnPath_id, $user->id); if ($prog >= 0) { $globalprog += $prog; } $iterator++; } $total = round($globalprog / ($iterator - 1)); echo csv_escape(uid_to_name($user->id)) . ";" . csv_escape(uid_to_am($user->id)) . ";" . csv_escape(user_groups($course_id, $user->id, 'csv')) . ";" . $total . "%"; } echo $crlf;