Replace Spreadsheet_Excel_Writer/Writer with PHPExcel

1.10.x
Julio Montoya 10 years ago
parent 7d2579b36e
commit 003ee63187
  1. 90
      main/exercice/exercise_result.class.php
  2. 73
      main/exercice/hotpotatoes_exercise_result.class.php
  3. 24
      main/gradebook/lib/gradebook_result.class.php
  4. 104
      main/inc/lib/pear/Spreadsheet_Excel_Writer/Writer.php
  5. 261
      main/inc/lib/pear/Spreadsheet_Excel_Writer/Writer/BIFFwriter.php
  6. 1114
      main/inc/lib/pear/Spreadsheet_Excel_Writer/Writer/Format.php
  7. 1703
      main/inc/lib/pear/Spreadsheet_Excel_Writer/Writer/Parser.php
  8. 230
      main/inc/lib/pear/Spreadsheet_Excel_Writer/Writer/Validator.php
  9. 1591
      main/inc/lib/pear/Spreadsheet_Excel_Writer/Writer/Workbook.php
  10. 3534
      main/inc/lib/pear/Spreadsheet_Excel_Writer/Writer/Worksheet.php
  11. 6
      main/inc/lib/pear/Spreadsheet_Excel_Writer/Writer/index.html
  12. 6
      main/inc/lib/pear/Spreadsheet_Excel_Writer/index.html
  13. 41
      main/mySpace/current_courses.php
  14. 90
      main/survey/survey.lib.php
  15. 42
      main/tracking/course_session_report.php
  16. 7
      main/tracking/exams.php
  17. 91
      main/tracking/lp_results_by_user.php
  18. 41
      main/tracking/question_course_report.php

@ -409,17 +409,15 @@ class ExerciseResult
) { ) {
global $charset; global $charset;
$this->getExercisesReporting($document_path, $user_id, $export_filter, $exercise_id, $hotpotato_name); $this->getExercisesReporting($document_path, $user_id, $export_filter, $exercise_id, $hotpotato_name);
$filename = 'exercise_results_'.date('YmdGis').'.xls'; $filename = 'exercise_results_'.api_get_local_time().'.xls';
if (!empty($user_id)) { if (!empty($user_id)) {
$filename = 'exercise_results_user_'.$user_id.'_'.date('YmdGis').'.xls'; $filename = 'exercise_results_user_'.$user_id.'_'.api_get_local_time().'.xls';
} }
$workbook = new Spreadsheet_Excel_Writer();
$workbook->setTempDir(api_get_path(SYS_ARCHIVE_PATH));
$workbook->setVersion(8); // BIFF8
$workbook->send($filename); $spreadsheet = new PHPExcel();
$worksheet =& $workbook->addWorksheet('Report '.date('YmdGis')); $spreadsheet->setActiveSheetIndex(0);
$worksheet->setInputEncoding(api_get_system_encoding()); $worksheet = $spreadsheet->getActiveSheet();
$line = 0; $line = 0;
$column = 0; //skip the first column (row titles) $column = 0; //skip the first column (row titles)
@ -436,26 +434,26 @@ class ExerciseResult
if ($with_column_user) { if ($with_column_user) {
if (api_is_western_name_order()) { if (api_is_western_name_order()) {
$worksheet->write($line, $column,get_lang('FirstName')); $worksheet->SetCellValueByColumnAndRow($line, $column,get_lang('FirstName'));
$column++; $column++;
$worksheet->write($line, $column,get_lang('LastName')); $worksheet->SetCellValueByColumnAndRow($line, $column,get_lang('LastName'));
$column++; $column++;
} else { } else {
$worksheet->write($line, $column,get_lang('LastName')); $worksheet->SetCellValueByColumnAndRow($line, $column,get_lang('LastName'));
$column++; $column++;
$worksheet->write($line, $column,get_lang('FirstName')); $worksheet->SetCellValueByColumnAndRow($line, $column,get_lang('FirstName'));
$column++; $column++;
} }
if ($officialCodeInList === 'true') { if ($officialCodeInList === 'true') {
$worksheet->write($line, $column, get_lang('OfficialCode')); $worksheet->SetCellValueByColumnAndRow($line, $column, get_lang('OfficialCode'));
$column++; $column++;
} }
$worksheet->write($line, $column, get_lang('Email')); $worksheet->SetCellValueByColumnAndRow($line, $column, get_lang('Email'));
$column++; $column++;
} }
$worksheet->write($line, $column, get_lang('Groups')); $worksheet->SetCellValueByColumnAndRow($line, $column, get_lang('Groups'));
$column++; $column++;
if ($export_user_fields) { if ($export_user_fields) {
@ -464,28 +462,28 @@ class ExerciseResult
//show the fields names for user fields //show the fields names for user fields
foreach ($extra_user_fields as $field) { foreach ($extra_user_fields as $field) {
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($field[3]), ENT_QUOTES, $charset)); $worksheet->SetCellValueByColumnAndRow($line,$column,api_html_entity_decode(strip_tags($field[3]), ENT_QUOTES, $charset));
$column++; $column++;
} }
} }
$worksheet->write($line, $column, get_lang('Title')); $worksheet->SetCellValueByColumnAndRow($line, $column, get_lang('Title'));
$column++; $column++;
$worksheet->write($line, $column, get_lang('StartDate')); $worksheet->SetCellValueByColumnAndRow($line, $column, get_lang('StartDate'));
$column++; $column++;
$worksheet->write($line, $column, get_lang('EndDate')); $worksheet->SetCellValueByColumnAndRow($line, $column, get_lang('EndDate'));
$column++; $column++;
$worksheet->write($line, $column, get_lang('Duration').' ('.get_lang('MinMinutes').')'); $worksheet->SetCellValueByColumnAndRow($line, $column, get_lang('Duration').' ('.get_lang('MinMinutes').')');
$column++; $column++;
$worksheet->write($line, $column, get_lang('Score')); $worksheet->SetCellValueByColumnAndRow($line, $column, get_lang('Score'));
$column++; $column++;
$worksheet->write($line, $column, get_lang('Total')); $worksheet->SetCellValueByColumnAndRow($line, $column, get_lang('Total'));
$column++; $column++;
$worksheet->write($line, $column, get_lang('Status')); $worksheet->SetCellValueByColumnAndRow($line, $column, get_lang('Status'));
$column++; $column++;
$worksheet->write($line, $column, get_lang('ToolLearnpath')); $worksheet->SetCellValueByColumnAndRow($line, $column, get_lang('ToolLearnpath'));
$column++; $column++;
$worksheet->write($line, $column, get_lang('UserIsCurrentlySubscribed')); $worksheet->SetCellValueByColumnAndRow($line, $column, get_lang('UserIsCurrentlySubscribed'));
$line++; $line++;
foreach ($this->results as $row) { foreach ($this->results as $row) {
@ -493,59 +491,63 @@ class ExerciseResult
if ($with_column_user) { if ($with_column_user) {
if (api_is_western_name_order()) { if (api_is_western_name_order()) {
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)); $worksheet->SetCellValueByColumnAndRow($line,$column,api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset));
$column++; $column++;
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset)); $worksheet->SetCellValueByColumnAndRow($line,$column,api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset));
$column++; $column++;
} else { } else {
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset)); $worksheet->SetCellValueByColumnAndRow($line,$column,api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset));
$column++; $column++;
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)); $worksheet->SetCellValueByColumnAndRow($line,$column,api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset));
$column++; $column++;
} }
if ($officialCodeInList === 'true') { if ($officialCodeInList === 'true') {
$worksheet->write($line, $column,api_html_entity_decode(strip_tags($row['official_code']), ENT_QUOTES, $charset)); $worksheet->SetCellValueByColumnAndRow($line, $column,api_html_entity_decode(strip_tags($row['official_code']), ENT_QUOTES, $charset));
$column++; $column++;
} }
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['email']), ENT_QUOTES, $charset)); $worksheet->SetCellValueByColumnAndRow($line,$column,api_html_entity_decode(strip_tags($row['email']), ENT_QUOTES, $charset));
$column++; $column++;
} }
$worksheet->write($line,$column,api_html_entity_decode(strip_tags(implode(", ", GroupManager :: get_user_group_name($row['user_id']))), ENT_QUOTES, $charset)); $worksheet->SetCellValueByColumnAndRow($line,$column,api_html_entity_decode(strip_tags(implode(", ", GroupManager :: get_user_group_name($row['user_id']))), ENT_QUOTES, $charset));
$column++; $column++;
if ($export_user_fields) { if ($export_user_fields) {
//show user fields data, if any, for this user //show user fields data, if any, for this user
$user_fields_values = UserManager::get_extra_user_data($row['user_id'],false,false, false, true); $user_fields_values = UserManager::get_extra_user_data($row['user_id'],false,false, false, true);
foreach($user_fields_values as $value) { foreach($user_fields_values as $value) {
$worksheet->write($line,$column, api_html_entity_decode(strip_tags($value), ENT_QUOTES, $charset)); $worksheet->SetCellValueByColumnAndRow($line,$column, api_html_entity_decode(strip_tags($value), ENT_QUOTES, $charset));
$column++; $column++;
} }
} }
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['title']), ENT_QUOTES, $charset)); $worksheet->SetCellValueByColumnAndRow($line,$column,api_html_entity_decode(strip_tags($row['title']), ENT_QUOTES, $charset));
$column++; $column++;
$worksheet->write($line, $column, $row['start_date']); $worksheet->SetCellValueByColumnAndRow($line, $column, $row['start_date']);
$column++; $column++;
$worksheet->write($line, $column, $row['end_date']); $worksheet->SetCellValueByColumnAndRow($line, $column, $row['end_date']);
$column++; $column++;
$worksheet->write($line, $column, $row['duration']); $worksheet->SetCellValueByColumnAndRow($line, $column, $row['duration']);
$column++; $column++;
$worksheet->write($line, $column, $row['result']); $worksheet->SetCellValueByColumnAndRow($line, $column, $row['result']);
$column++; $column++;
$worksheet->write($line, $column, $row['max']); $worksheet->SetCellValueByColumnAndRow($line, $column, $row['max']);
$column++; $column++;
$worksheet->write($line, $column, $row['status']); $worksheet->SetCellValueByColumnAndRow($line, $column, $row['status']);
$column++; $column++;
$worksheet->write($line, $column, $row['lp_name']); $worksheet->SetCellValueByColumnAndRow($line, $column, $row['lp_name']);
$column++; $column++;
$worksheet->write($line, $column, $row['is_user_subscribed']); $worksheet->SetCellValueByColumnAndRow($line, $column, $row['is_user_subscribed']);
$line++; $line++;
} }
//output the results
$workbook->close(); $file = api_get_path(SYS_ARCHIVE_PATH).api_replace_dangerous_char($filename);
$writer = new PHPExcel_Writer_Excel2007($spreadsheet);
$writer->save($file);
DocumentManager::file_send_for_download($file, true, $filename);
return true; return true;
} }
} }

@ -226,17 +226,16 @@ class HotpotatoesExerciseResult
) { ) {
global $charset; global $charset;
$this->getExercisesReporting($document_path, $user_id, $export_filter, $exercise_id, $hotpotato_name); $this->getExercisesReporting($document_path, $user_id, $export_filter, $exercise_id, $hotpotato_name);
$filename = 'exercise_results_'.date('YmdGis').'.xls'; $filename = 'exercise_results_'.api_get_local_time().'.xls';
if (!empty($user_id)) { if (!empty($user_id)) {
$filename = 'exercise_results_user_'.$user_id.'_'.date('YmdGis').'.xls'; $filename = 'exercise_results_user_'.$user_id.'_'.api_get_local_time().'.xls';
} }
$workbook = new Spreadsheet_Excel_Writer();
$workbook->setTempDir(api_get_path(SYS_ARCHIVE_PATH));
$workbook->setVersion(8); // BIFF8
$workbook->send($filename); $spreadsheet = new PHPExcel();
$worksheet =& $workbook->addWorksheet('Report '.date('YmdGis')); $spreadsheet->setActiveSheetIndex(0);
$worksheet->setInputEncoding(api_get_system_encoding()); $worksheet = $spreadsheet->getActiveSheet();
$line = 0; $line = 0;
$column = 0; //skip the first column (row titles) $column = 0; //skip the first column (row titles)
@ -250,18 +249,18 @@ class HotpotatoesExerciseResult
} }
if ($with_column_user) { if ($with_column_user) {
$worksheet->write($line,$column,get_lang('Email')); $worksheet->SetCellValueByColumnAndRow($line,$column,get_lang('Email'));
$column++; $column++;
if (api_is_western_name_order()) { if (api_is_western_name_order()) {
$worksheet->write($line,$column,get_lang('FirstName')); $worksheet->SetCellValueByColumnAndRow($line,$column,get_lang('FirstName'));
$column++; $column++;
$worksheet->write($line,$column,get_lang('LastName')); $worksheet->SetCellValueByColumnAndRow($line,$column,get_lang('LastName'));
$column++; $column++;
} else { } else {
$worksheet->write($line,$column,get_lang('LastName')); $worksheet->SetCellValueByColumnAndRow($line,$column,get_lang('LastName'));
$column++; $column++;
$worksheet->write($line,$column,get_lang('FirstName')); $worksheet->SetCellValueByColumnAndRow($line,$column,get_lang('FirstName'));
$column++; $column++;
} }
} }
@ -272,42 +271,42 @@ class HotpotatoesExerciseResult
//show the fields names for user fields //show the fields names for user fields
foreach ($extra_user_fields as $field) { foreach ($extra_user_fields as $field) {
$worksheet->write($line, $column, api_html_entity_decode(strip_tags($field[3]), ENT_QUOTES, $charset)); $worksheet->SetCellValueByColumnAndRow($line, $column, api_html_entity_decode(strip_tags($field[3]), ENT_QUOTES, $charset));
$column++; $column++;
} }
} }
$worksheet->write($line,$column, get_lang('Title')); $worksheet->SetCellValueByColumnAndRow($line,$column, get_lang('Title'));
$column++; $column++;
$worksheet->write($line,$column, get_lang('StartDate')); $worksheet->SetCellValueByColumnAndRow($line,$column, get_lang('StartDate'));
$column++; $column++;
$worksheet->write($line,$column, get_lang('EndDate')); $worksheet->SetCellValueByColumnAndRow($line,$column, get_lang('EndDate'));
$column++; $column++;
$worksheet->write($line,$column, get_lang('Duration').' ('.get_lang('MinMinutes').')'); $worksheet->SetCellValueByColumnAndRow($line,$column, get_lang('Duration').' ('.get_lang('MinMinutes').')');
$column++; $column++;
$worksheet->write($line,$column, get_lang('Score')); $worksheet->SetCellValueByColumnAndRow($line,$column, get_lang('Score'));
$column++; $column++;
$worksheet->write($line,$column, get_lang('Total')); $worksheet->SetCellValueByColumnAndRow($line,$column, get_lang('Total'));
$column++; $column++;
$worksheet->write($line,$column, get_lang('Status')); $worksheet->SetCellValueByColumnAndRow($line,$column, get_lang('Status'));
$line++; $line++;
foreach ($this->results as $row) { foreach ($this->results as $row) {
$column = 0; $column = 0;
if ($with_column_user) { if ($with_column_user) {
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['email']), ENT_QUOTES, $charset)); $worksheet->SetCellValueByColumnAndRow($line,$column,api_html_entity_decode(strip_tags($row['email']), ENT_QUOTES, $charset));
$column++; $column++;
if (api_is_western_name_order()) { if (api_is_western_name_order()) {
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)); $worksheet->SetCellValueByColumnAndRow($line,$column,api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset));
$column++; $column++;
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset)); $worksheet->SetCellValueByColumnAndRow($line,$column,api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset));
$column++; $column++;
} else { } else {
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset)); $worksheet->SetCellValueByColumnAndRow($line,$column,api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset));
$column++; $column++;
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)); $worksheet->SetCellValueByColumnAndRow($line,$column,api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset));
$column++; $column++;
} }
} }
@ -316,28 +315,32 @@ class HotpotatoesExerciseResult
//show user fields data, if any, for this user //show user fields data, if any, for this user
$user_fields_values = UserManager::get_extra_user_data($row['user_id'],false,false, false, true); $user_fields_values = UserManager::get_extra_user_data($row['user_id'],false,false, false, true);
foreach($user_fields_values as $value) { foreach($user_fields_values as $value) {
$worksheet->write($line,$column, api_html_entity_decode(strip_tags($value), ENT_QUOTES, $charset)); $worksheet->SetCellValueByColumnAndRow($line,$column, api_html_entity_decode(strip_tags($value), ENT_QUOTES, $charset));
$column++; $column++;
} }
} }
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['title']), ENT_QUOTES, $charset)); $worksheet->SetCellValueByColumnAndRow($line,$column,api_html_entity_decode(strip_tags($row['title']), ENT_QUOTES, $charset));
$column++; $column++;
$worksheet->write($line,$column,$row['start_date']); $worksheet->SetCellValueByColumnAndRow($line,$column,$row['start_date']);
$column++; $column++;
$worksheet->write($line,$column,$row['end_date']); $worksheet->SetCellValueByColumnAndRow($line,$column,$row['end_date']);
$column++; $column++;
$worksheet->write($line,$column,$row['duration']); $worksheet->SetCellValueByColumnAndRow($line,$column,$row['duration']);
$column++; $column++;
$worksheet->write($line,$column,$row['result']); $worksheet->SetCellValueByColumnAndRow($line,$column,$row['result']);
$column++; $column++;
$worksheet->write($line,$column,$row['max']); $worksheet->SetCellValueByColumnAndRow($line,$column,$row['max']);
$column++; $column++;
$worksheet->write($line,$column,$row['status']); $worksheet->SetCellValueByColumnAndRow($line,$column,$row['status']);
$line++; $line++;
} }
$workbook->close(); $file = api_get_path(SYS_ARCHIVE_PATH).api_replace_dangerous_char($filename);
$writer = new PHPExcel_Writer_Excel2007($spreadsheet);
$writer->save($file);
DocumentManager::file_send_for_download($file, true, $filename);
return true; return true;
} }
} }

@ -244,37 +244,37 @@ class GradeBookResult
*/ */
public function exportCompleteReportXLS($data) public function exportCompleteReportXLS($data)
{ {
$filename = 'gradebook-results-'.date('Y-m-d-h:i:s').'.xls'; $filename = 'gradebook-results-'.api_get_local_time().'.xls';
include api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer.php';
$workbook = new Spreadsheet_Excel_Writer();
$workbook->setVersion(8); // BIFF8
$workbook->setTempDir(api_get_path(SYS_ARCHIVE_PATH));
$workbook->send($filename);
$worksheet =& $workbook->addWorksheet('Report'); $spreadsheet = new PHPExcel();
$worksheet->setInputEncoding(api_get_system_encoding()); $spreadsheet->setActiveSheetIndex(0);
$worksheet = $spreadsheet->getActiveSheet();
$line = 0; $line = 0;
$column = 0; //skip the first column (row titles) $column = 0; //skip the first column (row titles)
//headers //headers
foreach ($data[0] as $header_col) { foreach ($data[0] as $header_col) {
$worksheet->write($line, $column, $header_col); $worksheet->SetCellValueByColumnAndRow($line, $column, $header_col);
$column++; $column++;
} }
$line++; $line++;
$cant_students = count($data[1]); $cant_students = count($data[1]);
for ($i=0;$i<$cant_students;$i++) { for ($i = 0; $i < $cant_students; $i++) {
$column = 0; $column = 0;
foreach ($data[1][$i] as $col_name) { foreach ($data[1][$i] as $col_name) {
$worksheet->write($line,$column, html_entity_decode(strip_tags($col_name))); $worksheet->SetCellValueByColumnAndRow($line,$column, html_entity_decode(strip_tags($col_name)));
$column++; $column++;
} }
$line++; $line++;
} }
$workbook->close();
$file = api_get_path(SYS_ARCHIVE_PATH).api_replace_dangerous_char($filename);
$writer = new PHPExcel_Writer_Excel2007($spreadsheet);
$writer->save($file);
DocumentManager::file_send_for_download($file, true, $filename);
exit; exit;
} }

@ -1,104 +0,0 @@
<?php
/*
* Module written/ported by Xavier Noguer <xnoguer@rezebra.com>
*
* PERL Spreadsheet::WriteExcel module.
*
* The author of the Spreadsheet::WriteExcel module is John McNamara
* <jmcnamara@cpan.org>
*
* I _DO_ maintain this code, and John McNamara has nothing to do with the
* porting of this code to PHP. Any questions directly related to this
* class library should be directed to me.
*
* License Information:
*
* Spreadsheet_Excel_Writer: A library for generating Excel Spreadsheets
* Copyright (c) 2002-2003 Xavier Noguer xnoguer@rezebra.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
//require_once(api_get_path(LIBRARY_PATH).'pear/PEAR.php');
require_once 'Writer/Workbook.php';
/**
* Class for writing Excel Spreadsheets. This class should change COMPLETELY.
*
* @author Xavier Noguer <xnoguer@rezebra.com>
* @category FileFormats
* @package Spreadsheet_Excel_Writer
*/
class Spreadsheet_Excel_Writer extends Spreadsheet_Excel_Writer_Workbook
{
/**
* The constructor. It just creates a Workbook
*
* @param string $filename The optional filename for the Workbook.
* @return Spreadsheet_Excel_Writer_Workbook The Workbook created
*/
function Spreadsheet_Excel_Writer($filename = '')
{
$this->_filename = $filename;
$this->Spreadsheet_Excel_Writer_Workbook($filename);
}
/**
* Send HTTP headers for the Excel file.
*
* @param string $filename The filename to use for HTTP headers
* @access public
*/
function send($filename)
{
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
header("Pragma: public");
}
/**
* Utility function for writing formulas
* Converts a cell's coordinates to the A1 format.
*
* @access public
* @static
* @param integer $row Row for the cell to convert (0-indexed).
* @param integer $col Column for the cell to convert (0-indexed).
* @return string The cell identifier in A1 format
*/
function rowcolToCell($row, $col)
{
if ($col > 255) { //maximum column value exceeded
return new PEAR_Error("Maximum column value exceeded: $col");
}
$int = (int)($col / 26);
$frac = $col % 26;
$chr1 = '';
if ($int > 0) {
$chr1 = chr(ord('A') + $int - 1);
}
$chr2 = chr(ord('A') + $frac);
$row++;
return $chr1 . $chr2 . $row;
}
}
?>

@ -1,261 +0,0 @@
<?php
/*
* Module written/ported by Xavier Noguer <xnoguer@php.net>
*
* The majority of this is _NOT_ my code. I simply ported it from the
* PERL Spreadsheet::WriteExcel module.
*
* The author of the Spreadsheet::WriteExcel module is John McNamara
* <jmcnamara@cpan.org>
*
* I _DO_ maintain this code, and John McNamara has nothing to do with the
* porting of this code to PHP. Any questions directly related to this
* class library should be directed to me.
*
* License Information:
*
* Spreadsheet_Excel_Writer: A library for generating Excel Spreadsheets
* Copyright (c) 2002-2003 Xavier Noguer xnoguer@php.net
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
require_once 'PEAR.php';
/**
* Class for writing Excel BIFF records.
*
* From "MICROSOFT EXCEL BINARY FILE FORMAT" by Mark O'Brien (Microsoft Corporation):
*
* BIFF (BInary File Format) is the file format in which Excel documents are
* saved on disk. A BIFF file is a complete description of an Excel document.
* BIFF files consist of sequences of variable-length records. There are many
* different types of BIFF records. For example, one record type describes a
* formula entered into a cell; one describes the size and location of a
* window into a document; another describes a picture format.
*
* @author Xavier Noguer <xnoguer@php.net>
* @category FileFormats
* @package Spreadsheet_Excel_Writer
*/
class Spreadsheet_Excel_Writer_BIFFwriter extends PEAR
{
/**
* The BIFF/Excel version (5).
* @var integer
*/
var $_BIFF_version = 0x0500;
/**
* The byte order of this architecture. 0 => little endian, 1 => big endian
* @var integer
*/
var $_byte_order;
/**
* The string containing the data of the BIFF stream
* @var string
*/
var $_data;
/**
* The size of the data in bytes. Should be the same as strlen($this->_data)
* @var integer
*/
var $_datasize;
/**
* The maximun length for a BIFF record. See _addContinue()
* @var integer
* @see _addContinue()
*/
var $_limit;
/**
* The temporary dir for storing the OLE file
* @var string
*/
var $_tmp_dir;
/**
* Constructor
*
* @access public
*/
function Spreadsheet_Excel_Writer_BIFFwriter()
{
$this->_byte_order = '';
$this->_data = '';
$this->_datasize = 0;
$this->_limit = 2080;
$this->_tmp_dir = '';
// Set the byte order
$this->_setByteOrder();
}
/**
* Determine the byte order and store it as class data to avoid
* recalculating it for each call to new().
*
* @access private
*/
function _setByteOrder()
{
// Check if "pack" gives the required IEEE 64bit float
$teststr = pack("d", 1.2345);
$number = pack("C8", 0x8D, 0x97, 0x6E, 0x12, 0x83, 0xC0, 0xF3, 0x3F);
if ($number == $teststr) {
$byte_order = 0; // Little Endian
} elseif ($number == strrev($teststr)){
$byte_order = 1; // Big Endian
} else {
// Give up. I'll fix this in a later version.
return $this->raiseError("Required floating point format ".
"not supported on this platform.");
}
$this->_byte_order = $byte_order;
}
/**
* General storage function
*
* @param string $data binary data to prepend
* @access private
*/
function _prepend($data)
{
if (strlen($data) > $this->_limit) {
$data = $this->_addContinue($data);
}
$this->_data = $data.$this->_data;
$this->_datasize += strlen($data);
}
/**
* General storage function
*
* @param string $data binary data to append
* @access private
*/
function _append($data)
{
if (strlen($data) > $this->_limit) {
$data = $this->_addContinue($data);
}
$this->_data = $this->_data.$data;
$this->_datasize += strlen($data);
}
/**
* Writes Excel BOF record to indicate the beginning of a stream or
* sub-stream in the BIFF file.
*
* @param integer $type Type of BIFF file to write: 0x0005 Workbook,
* 0x0010 Worksheet.
* @access private
*/
function _storeBof($type)
{
$record = 0x0809; // Record identifier
// According to the SDK $build and $year should be set to zero.
// However, this throws a warning in Excel 5. So, use magic numbers.
if ($this->_BIFF_version == 0x0500) {
$length = 0x0008;
$unknown = '';
$build = 0x096C;
$year = 0x07C9;
} elseif ($this->_BIFF_version == 0x0600) {
$length = 0x0010;
$unknown = pack("VV", 0x00000041, 0x00000006); //unknown last 8 bytes for BIFF8
$build = 0x0DBB;
$year = 0x07CC;
}
$version = $this->_BIFF_version;
$header = pack("vv", $record, $length);
$data = pack("vvvv", $version, $type, $build, $year);
$this->_prepend($header . $data . $unknown);
}
/**
* Writes Excel EOF record to indicate the end of a BIFF stream.
*
* @access private
*/
function _storeEof()
{
$record = 0x000A; // Record identifier
$length = 0x0000; // Number of bytes to follow
$header = pack("vv", $record, $length);
$this->_append($header);
}
/**
* Excel limits the size of BIFF records. In Excel 5 the limit is 2084 bytes. In
* Excel 97 the limit is 8228 bytes. Records that are longer than these limits
* must be split up into CONTINUE blocks.
*
* This function takes a long BIFF record and inserts CONTINUE records as
* necessary.
*
* @param string $data The original binary data to be written
* @return string A very convenient string of continue blocks
* @access private
*/
function _addContinue($data)
{
$limit = $this->_limit;
$record = 0x003C; // Record identifier
// The first 2080/8224 bytes remain intact. However, we have to change
// the length field of the record.
$tmp = substr($data, 0, 2).pack("v", $limit-4).substr($data, 4, $limit - 4);
$header = pack("vv", $record, $limit); // Headers for continue records
// Retrieve chunks of 2080/8224 bytes +4 for the header.
$data_length = strlen($data);
for ($i = $limit; $i < ($data_length - $limit); $i += $limit) {
$tmp .= $header;
$tmp .= substr($data, $i, $limit);
}
// Retrieve the last chunk of data
$header = pack("vv", $record, strlen($data) - $i);
$tmp .= $header;
$tmp .= substr($data, $i, strlen($data) - $i);
return $tmp;
}
/**
* Sets the temp dir used for storing the OLE file
*
* @access public
* @param string $dir The dir to be used as temp dir
* @return true if given dir is valid, false otherwise
*/
function setTempDir($dir)
{
if (is_dir($dir)) {
$this->_tmp_dir = $dir;
return true;
}
return false;
}
}
?>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -1,230 +0,0 @@
<?php
/*
* Module written by Herman Kuiper <herman@ozuzo.net>
*
* License Information:
*
* Spreadsheet_Excel_Writer: A library for generating Excel Spreadsheets
* Copyright (c) 2002-2003 Xavier Noguer xnoguer@rezebra.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
//require_once('PEAR.php');
// Possible operator types
/*
FIXME: change prefixes
*/
define("OP_BETWEEN", 0x00);
define("OP_NOTBETWEEN", 0x01);
define("OP_EQUAL", 0x02);
define("OP_NOTEQUAL", 0x03);
define("OP_GT", 0x04);
define("OP_LT", 0x05);
define("OP_GTE", 0x06);
define("OP_LTE", 0x07);
/**
* Baseclass for generating Excel DV records (validations)
*
* @author Herman Kuiper
* @category FileFormats
* @package Spreadsheet_Excel_Writer
*/
class Spreadsheet_Excel_Writer_Validator
{
var $_type;
var $_style;
var $_fixedList;
var $_blank;
var $_incell;
var $_showprompt;
var $_showerror;
var $_title_prompt;
var $_descr_prompt;
var $_title_error;
var $_descr_error;
var $_operator;
var $_formula1;
var $_formula2;
/**
* The parser from the workbook. Used to parse validation formulas also
* @var Spreadsheet_Excel_Writer_Parser
*/
var $_parser;
function Spreadsheet_Excel_Writer_Validator(&$parser)
{
$this->_parser = $parser;
$this->_type = 0x01; // FIXME: add method for setting datatype
$this->_style = 0x00;
$this->_fixedList = false;
$this->_blank = false;
$this->_incell = false;
$this->_showprompt = false;
$this->_showerror = true;
$this->_title_prompt = "\x00";
$this->_descr_prompt = "\x00";
$this->_title_error = "\x00";
$this->_descr_error = "\x00";
$this->_operator = 0x00; // default is equal
$this->_formula1 = '';
$this->_formula2 = '';
}
function setPrompt($promptTitle = "\x00", $promptDescription = "\x00", $showPrompt = true)
{
$this->_showprompt = $showPrompt;
$this->_title_prompt = $promptTitle;
$this->_descr_prompt = $promptDescription;
}
function setError($errorTitle = "\x00", $errorDescription = "\x00", $showError = true)
{
$this->_showerror = $showError;
$this->_title_error = $errorTitle;
$this->_descr_error = $errorDescription;
}
function allowBlank()
{
$this->_blank = true;
}
function onInvalidStop()
{
$this->_style = 0x00;
}
function onInvalidWarn()
{
$this->_style = 0x01;
}
function onInvalidInfo()
{
$this->_style = 0x02;
}
function setFormula1($formula)
{
// Parse the formula using the parser in Parser.php
$error = $this->_parser->parse($formula);
if (PEAR::isError($error)) {
return $this->_formula1;
}
$this->_formula1 = $this->_parser->toReversePolish();
if (PEAR::isError($this->_formula1)) {
return $this->_formula1;
}
return true;
}
function setFormula2($formula)
{
// Parse the formula using the parser in Parser.php
$error = $this->_parser->parse($formula);
if (PEAR::isError($error)) {
return $this->_formula2;
}
$this->_formula2 = $this->_parser->toReversePolish();
if (PEAR::isError($this->_formula2)) {
return $this->_formula2;
}
return true;
}
function _getOptions()
{
$options = $this->_type;
$options |= $this->_style << 3;
if ($this->_fixedList) {
$options |= 0x80;
}
if ($this->_blank) {
$options |= 0x100;
}
if (!$this->_incell) {
$options |= 0x200;
}
if ($this->_showprompt) {
$options |= 0x40000;
}
if ($this->_showerror) {
$options |= 0x80000;
}
$options |= $this->_operator << 20;
return $options;
}
function _getData()
{
$title_prompt_len = strlen($this->_title_prompt);
$descr_prompt_len = strlen($this->_descr_prompt);
$title_error_len = strlen($this->_title_error);
$descr_error_len = strlen($this->_descr_error);
$formula1_size = strlen($this->_formula1);
$formula2_size = strlen($this->_formula2);
$data = pack("V", $this->_getOptions());
$data .= pack("vC", $title_prompt_len, 0x00) . $this->_title_prompt;
$data .= pack("vC", $title_error_len, 0x00) . $this->_title_error;
$data .= pack("vC", $descr_prompt_len, 0x00) . $this->_descr_prompt;
$data .= pack("vC", $descr_error_len, 0x00) . $this->_descr_error;
$data .= pack("vv", $formula1_size, 0x0000) . $this->_formula1;
$data .= pack("vv", $formula2_size, 0x0000) . $this->_formula2;
return $data;
}
}
/*class Spreadsheet_Excel_Writer_Validation_List extends Spreadsheet_Excel_Writer_Validation
{
function Spreadsheet_Excel_Writer_Validation_list()
{
parent::Spreadsheet_Excel_Writer_Validation();
$this->_type = 0x03;
}
function setList($source, $incell = true)
{
$this->_incell = $incell;
$this->_fixedList = true;
$source = implode("\x00", $source);
$this->_formula1 = pack("CCC", 0x17, strlen($source), 0x0c) . $source;
}
function setRow($row, $col1, $col2, $incell = true)
{
$this->_incell = $incell;
//$this->_formula1 = ...;
}
function setCol($col, $row1, $row2, $incell = true)
{
$this->_incell = $incell;
//$this->_formula1 = ...;
}
}*/
?>

@ -1,6 +0,0 @@
<html>
<head>
</head>
<body>
</body>
</html>

@ -1,6 +0,0 @@
<html>
<head>
</head>
<body>
</body>
</html>

@ -4,15 +4,11 @@
* Report for current courses followed by the user * Report for current courses followed by the user
* @package chamilo.reporting * @package chamilo.reporting
*/ */
/**
* Code
*/
$cidReset = true; $cidReset = true;
require_once '../inc/global.inc.php'; require_once '../inc/global.inc.php';
$this_section = SECTION_TRACKING; $this_section = SECTION_TRACKING;
require_once api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer.php';
$filename = 'reporting.xls'; $filename = 'reporting.xls';
if (!api_is_allowed_to_create_course()) { if (!api_is_allowed_to_create_course()) {
@ -40,8 +36,6 @@ if (!empty($my_courses)) {
$teachers = CourseManager::get_teacher_list_from_course_code($course_code); $teachers = CourseManager::get_teacher_list_from_course_code($course_code);
$teacher_list = array(); $teacher_list = array();
//$teacher_list = array($course_info['titular']);
if (!empty($teachers)) { if (!empty($teachers)) {
foreach($teachers as $teacher) { foreach($teachers as $teacher) {
$teacher_list[]= $teacher['firstname'].' '.$teacher['lastname']; $teacher_list[]= $teacher['firstname'].' '.$teacher['lastname'];
@ -66,7 +60,10 @@ if (!empty($my_courses)) {
$t_lpi = Database :: get_course_table(TABLE_LP_ITEM); $t_lpi = Database :: get_course_table(TABLE_LP_ITEM);
$t_news = Database :: get_course_table(TABLE_ANNOUNCEMENT); $t_news = Database :: get_course_table(TABLE_ANNOUNCEMENT);
$total_tools_list = Tracking::get_tools_most_used_by_course($course_id, $session_id); $total_tools_list = Tracking::get_tools_most_used_by_course(
$course_id,
$session_id
);
$total_tools = 0; $total_tools = 0;
foreach($total_tools_list as $tool) { foreach($total_tools_list as $tool) {
@ -192,7 +189,6 @@ if (!empty($my_courses)) {
} }
} }
$headers = array( $headers = array(
get_lang('LearningPath'), get_lang('LearningPath'),
get_lang('Teachers'), get_lang('Teachers'),
@ -215,32 +211,32 @@ $headers = array(
if (isset($_GET['export'])) { if (isset($_GET['export'])) {
global $charset; global $charset;
$workbook = new Spreadsheet_Excel_Writer(); $spreadsheet = new PHPExcel();
$workbook ->setTempDir(api_get_path(SYS_ARCHIVE_PATH)); $spreadsheet->setActiveSheetIndex(0);
$workbook->send($filename); $worksheet = $spreadsheet->getActiveSheet();
$workbook->setVersion(8); // BIFF8
$worksheet =& $workbook->addWorksheet('Report');
//$worksheet->setInputEncoding(api_get_system_encoding());
$worksheet->setInputEncoding($charset);
$line = 0; $line = 0;
$column = 0; //skip the first column (row titles) $column = 0; //skip the first column (row titles)
foreach($headers as $header) { foreach ($headers as $header) {
$worksheet->write($line,$column, $header); $worksheet->SetCellValueByColumnAndRow($line, $column, $header);
$column++; $column++;
} }
$line++; $line++;
foreach ($array as $row) { foreach ($array as $row) {
$column = 0; $column = 0;
foreach ($row as $item) { foreach ($row as $item) {
$worksheet->write($line,$column,html_entity_decode(strip_tags($item))); $worksheet->SetCellValueByColumnAndRow($line, $column, html_entity_decode(strip_tags($item)));
$column++; $column++;
} }
$line++; $line++;
} }
$line++; $line++;
$workbook->close();
$file = api_get_path(SYS_ARCHIVE_PATH).api_replace_dangerous_char($filename);
$writer = new PHPExcel_Writer_Excel2007($spreadsheet);
$writer->save($file);
DocumentManager::file_send_for_download($file, true, $filename);
exit; exit;
} }
@ -248,10 +244,6 @@ $interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('MySpace'))
Display::display_header(get_lang('CurrentCourses')); Display::display_header(get_lang('CurrentCourses'));
if (!class_exists('HTML_Table')) {
require_once api_get_path(LIBRARY_PATH).'pear/HTML/Table.php';
}
$table = new HTML_Table(array('class' => 'data_table')); $table = new HTML_Table(array('class' => 'data_table'));
$row = 0; $row = 0;
$column = 0; $column = 0;
@ -272,7 +264,6 @@ foreach ($array as $row_table) {
$row++; $row++;
} }
echo '<div class="actions">'; echo '<div class="actions">';
echo '<a href="'.api_get_path(WEB_CODE_PATH).'mySpace">'.Display::return_icon('back.png', get_lang('Back'), array(), 32).'</a>'; echo '<a href="'.api_get_path(WEB_CODE_PATH).'mySpace">'.Display::return_icon('back.png', get_lang('Back'), array(), 32).'</a>';
echo '<a href="'.api_get_path(WEB_CODE_PATH).'mySpace/current_courses.php?export=1">'.Display::return_icon('export_excel.png', get_lang('CurrentCoursesReport'), array(), 32).'</a> '; echo '<a href="'.api_get_path(WEB_CODE_PATH).'mySpace/current_courses.php?export=1">'.Display::return_icon('export_excel.png', get_lang('CurrentCoursesReport'), array(), 32).'</a> ';

@ -2951,24 +2951,19 @@ class SurveyUtil
*/ */
static function export_complete_report_xls($survey_data, $filename, $user_id = 0) static function export_complete_report_xls($survey_data, $filename, $user_id = 0)
{ {
require_once api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer.php'; $spreadsheet = new PHPExcel();
$workbook = new Spreadsheet_Excel_Writer(); $spreadsheet->setActiveSheetIndex(0);
$workbook ->setTempDir(api_get_path(SYS_ARCHIVE_PATH)); $worksheet = $spreadsheet->getActiveSheet();
$workbook->send($filename);
$workbook->setVersion(8); // BIFF8
$worksheet =& $workbook->addWorksheet('Report 1');
$worksheet->setInputEncoding(api_get_system_encoding());
$line = 0; $line = 0;
$column = 1; // Skip the first column (row titles) $column = 1; // Skip the first column (row titles)
// Show extra fields blank space (enough for extra fields on next line) // Show extra fields blank space (enough for extra fields on next line)
$display_extra_user_fields = false;
//if (!empty($_REQUEST['fields_filter'])) { //if (!empty($_REQUEST['fields_filter'])) {
// Show user fields section with a big th colspan that spans over all fields // Show user fields section with a big th colspan that spans over all fields
$extra_user_fields = UserManager::get_extra_fields(0, 0, 5, 'ASC', false, true); $extra_user_fields = UserManager::get_extra_fields(0, 0, 5, 'ASC', false, true);
$num = count($extra_user_fields); $num = count($extra_user_fields);
for ($i = 0; $i < $num; $i++) { for ($i = 0; $i < $num; $i++) {
$worksheet->write($line, $column, ''); $worksheet->SetCellValueByColumnAndRow($line, $column, '');
$column++; $column++;
} }
$display_extra_user_fields = true; $display_extra_user_fields = true;
@ -2982,12 +2977,16 @@ class SurveyUtil
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
// First line (questions) // First line (questions)
$sql = "SELECT questions.question_id, questions.type, questions.survey_question, count(options.question_option_id) as number_of_options $sql = "SELECT
questions.question_id,
questions.type,
questions.survey_question,
count(options.question_option_id) as number_of_options
FROM $table_survey_question questions FROM $table_survey_question questions
LEFT JOIN $table_survey_question_option options LEFT JOIN $table_survey_question_option options
ON questions.question_id = options.question_id AND options.c_id = $course_id ON questions.question_id = options.question_id AND options.c_id = $course_id
WHERE WHERE
questions.survey_id = '".Database::escape_string($_GET['survey_id'])."' AND questions.survey_id = '".intval($_GET['survey_id'])."' AND
questions.c_id = $course_id questions.c_id = $course_id
GROUP BY questions.question_id GROUP BY questions.question_id
ORDER BY questions.sort ASC"; ORDER BY questions.sort ASC";
@ -3002,11 +3001,25 @@ class SurveyUtil
// We do not show comment and pagebreak question types // We do not show comment and pagebreak question types
if ($row['type'] != 'comment' && $row['type'] != 'pagebreak') { if ($row['type'] != 'comment' && $row['type'] != 'pagebreak') {
if ($row['number_of_options'] == 0 && $row['type'] == 'open') { if ($row['number_of_options'] == 0 && $row['type'] == 'open') {
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['survey_question']), ENT_QUOTES)); $worksheet->SetCellValueByColumnAndRow(
$line,
$column,
api_html_entity_decode(
strip_tags($row['survey_question']),
ENT_QUOTES
)
);
$column ++; $column ++;
} else { } else {
for ($ii = 0; $ii < $row['number_of_options']; $ii ++) { for ($ii = 0; $ii < $row['number_of_options']; $ii ++) {
$worksheet->write($line, $column, api_html_entity_decode(strip_tags($row['survey_question']), ENT_QUOTES)); $worksheet->SetCellValueByColumnAndRow(
$line,
$column,
api_html_entity_decode(
strip_tags($row['survey_question']),
ENT_QUOTES
)
);
$column ++; $column ++;
} }
} }
@ -3020,13 +3033,18 @@ class SurveyUtil
if ($display_extra_user_fields) { if ($display_extra_user_fields) {
// Show the fields names for user fields // Show the fields names for user fields
foreach ($extra_user_fields as & $field) { foreach ($extra_user_fields as & $field) {
$worksheet->write($line, $column, api_html_entity_decode(strip_tags($field[3]), ENT_QUOTES)); $worksheet->SetCellValueByColumnAndRow(
$line,
$column,
api_html_entity_decode(strip_tags($field[3]), ENT_QUOTES)
);
$column++; $column++;
} }
} }
// Getting all the questions and options (second line) // Getting all the questions and options (second line)
$sql = "SELECT survey_question.question_id, survey_question.survey_id, survey_question.survey_question, survey_question.display, survey_question.sort, survey_question.type, $sql = "SELECT
survey_question.question_id, survey_question.survey_id, survey_question.survey_question, survey_question.display, survey_question.sort, survey_question.type,
survey_question_option.question_option_id, survey_question_option.option_text, survey_question_option.sort as option_sort survey_question_option.question_option_id, survey_question_option.option_text, survey_question_option.sort as option_sort
FROM $table_survey_question survey_question FROM $table_survey_question survey_question
LEFT JOIN $table_survey_question_option survey_question_option LEFT JOIN $table_survey_question_option survey_question_option
@ -3041,10 +3059,19 @@ class SurveyUtil
// We show the options if // We show the options if
// 1. there is no question filter and the export button has not been clicked // 1. there is no question filter and the export button has not been clicked
// 2. there is a quesiton filter but the question is selected for display // 2. there is a quesiton filter but the question is selected for display
if (!($_POST['submit_question_filter']) || (is_array($_POST['questions_filter']) && in_array($row['question_id'], $_POST['questions_filter']))) { if (!($_POST['submit_question_filter']) ||
(is_array($_POST['questions_filter']) && in_array($row['question_id'], $_POST['questions_filter']))
) {
// We do not show comment and pagebreak question types // We do not show comment and pagebreak question types
if ($row['type'] != 'comment' && $row['type'] != 'pagebreak') { if ($row['type'] != 'comment' && $row['type'] != 'pagebreak') {
$worksheet->write($line,$column,api_html_entity_decode(strip_tags($row['option_text']), ENT_QUOTES)); $worksheet->SetCellValueByColumnAndRow(
$line,
$column,
api_html_entity_decode(
strip_tags($row['option_text']),
ENT_QUOTES
)
);
$possible_answers[$row['question_id']][$row['question_option_id']] = $row['question_option_id']; $possible_answers[$row['question_id']][$row['question_option_id']] = $row['question_option_id'];
$possible_answers_type[$row['question_id']] = $row['type']; $possible_answers_type[$row['question_id']] = $row['type'];
$column++; $column++;
@ -3060,7 +3087,7 @@ class SurveyUtil
$sql = "SELECT * FROM $table_survey_answer $sql = "SELECT * FROM $table_survey_answer
WHERE c_id = $course_id AND survey_id='".intval($_GET['survey_id'])."' "; WHERE c_id = $course_id AND survey_id='".intval($_GET['survey_id'])."' ";
if ($user_id != 0) { if ($user_id != 0) {
$sql .= "AND user='".Database::escape_string($user_id)."' "; $sql .= "AND user='".intval($user_id)."' ";
} }
$sql .= "ORDER BY user ASC"; $sql .= "ORDER BY user ASC";
@ -3068,9 +3095,15 @@ class SurveyUtil
$result = Database::query($sql); $result = Database::query($sql);
while ($row = Database::fetch_array($result)) { while ($row = Database::fetch_array($result)) {
if ($old_user != $row['user'] && $old_user != '') { if ($old_user != $row['user'] && $old_user != '') {
$return = SurveyUtil::export_complete_report_row_xls($survey_data, $possible_answers, $answers_of_user, $old_user, true); $return = SurveyUtil::export_complete_report_row_xls(
$survey_data,
$possible_answers,
$answers_of_user,
$old_user,
true
);
foreach ($return as $elem) { foreach ($return as $elem) {
$worksheet->write($line, $column, $elem); $worksheet->SetCellValueByColumnAndRow($line, $column, $elem);
$column++; $column++;
} }
$answers_of_user = array(); $answers_of_user = array();
@ -3092,12 +3125,19 @@ class SurveyUtil
$answers_of_user, $answers_of_user,
$old_user, $old_user,
true true
); // this is to display the last user );
// this is to display the last user
foreach ($return as $elem) { foreach ($return as $elem) {
$worksheet->write($line, $column, $elem); $worksheet->SetCellValueByColumnAndRow($line, $column, $elem);
$column++; $column++;
} }
$workbook->close();
$file = api_get_path(SYS_ARCHIVE_PATH).api_replace_dangerous_char($filename);
$writer = new PHPExcel_Writer_Excel2007($spreadsheet);
$writer->save($file);
DocumentManager::file_send_for_download($file, true, $filename);
return null; return null;
} }
@ -3120,7 +3160,9 @@ class SurveyUtil
$return = array(); $return = array();
if ($survey_data['anonymous'] == 0) { if ($survey_data['anonymous'] == 0) {
if (intval($user) !== 0) { if (intval($user) !== 0) {
$sql = 'SELECT firstname, lastname FROM '.Database::get_main_table(TABLE_MAIN_USER).' WHERE user_id='.intval($user); $sql = 'SELECT firstname, lastname
FROM '.Database::get_main_table(TABLE_MAIN_USER).'
WHERE user_id='.intval($user);
$rs = Database::query($sql); $rs = Database::query($sql);
if($row = Database::fetch_array($rs)) { if($row = Database::fetch_array($rs)) {
$user_displayed = api_get_person_name($row['firstname'], $row['lastname']); $user_displayed = api_get_person_name($row['firstname'], $row['lastname']);

@ -5,9 +5,9 @@
* Report * Report
* @package chamilo.tracking * @package chamilo.tracking
*/ */
$cidReset = true; $cidReset = true;
require_once '../inc/global.inc.php'; require_once '../inc/global.inc.php';
require_once api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer.php';
$this_section = "session_my_space"; $this_section = "session_my_space";
@ -212,48 +212,8 @@ if (!empty($users) && is_array($users)) {
Display::display_warning_message(get_lang('NoResults')); Display::display_warning_message(get_lang('NoResults'));
} }
if (!$export_to_xls) { if (!$export_to_xls) {
echo $html_result; echo $html_result;
} }
$filename = 'exam-reporting-'.date('Y-m-d-h:i:s').'.xls';
if ($export_to_xls) {
echo $html_result;
export_complete_report_xls($filename, $export_array);
exit;
}
function sort_user($a, $b) {
if (is_numeric($a['score']) && is_numeric($b['score'])) {
echo $a['score'].' : '.$b['score'];
echo '<br />';
if ($a['score'] < $b['score']) {
return 1;
}
return 0;
}
return 1;
}
function export_complete_report_xls($filename, $array) {
global $charset;
$workbook = new Spreadsheet_Excel_Writer();
$workbook ->setTempDir(api_get_path(SYS_ARCHIVE_PATH));
$workbook->send($filename);
$workbook->setVersion(8); // BIFF8
$worksheet =& $workbook->addWorksheet('Report');
//$worksheet->setInputEncoding(api_get_system_encoding());
$worksheet->setInputEncoding($charset);
/*
$line = 0;
$column = 1; // Skip the first column (row titles)
foreach ($array as $elem) {
$worksheet->write($line, $column, $elem);
$column++;
}
$workbook->close();*/
exit;
}
Display :: display_footer(); Display :: display_footer();

@ -1,9 +1,11 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
* Exams script * Exams script
* @package chamilo.tracking * @package chamilo.tracking
*/ */
require_once '../inc/global.inc.php'; require_once '../inc/global.inc.php';
$toolTable = Database::get_course_table(TABLE_TOOL_LIST); $toolTable = Database::get_course_table(TABLE_TOOL_LIST);
@ -403,8 +405,8 @@ function export_complete_report_xls($filename, $array)
$spreadsheet = new PHPExcel(); $spreadsheet = new PHPExcel();
$spreadsheet->setActiveSheetIndex(0); $spreadsheet->setActiveSheetIndex(0);
$worksheet = $spreadsheet->getActiveSheet(); $worksheet = $spreadsheet->getActiveSheet();
$line = 0; $line = 0;
$column = 0; //skip the first column (row titles) $column = 0; //skip the first column (row titles)
@ -479,7 +481,7 @@ function export_complete_report_xls($filename, $array)
$file = api_get_path(SYS_ARCHIVE_PATH).api_replace_dangerous_char($filename); $file = api_get_path(SYS_ARCHIVE_PATH).api_replace_dangerous_char($filename);
$writer = new PHPExcel_Writer_Excel2007($spreadsheet); $writer = new PHPExcel_Writer_Excel2007($spreadsheet);
$writer->save($file); $writer->save($file);
DocumentManager::file_send_for_download($file, false, $filename); DocumentManager::file_send_for_download($file, true, $filename);
exit; exit;
} }
@ -730,7 +732,6 @@ function processStudentList($filter_score, $global, $exercise, $courseInfo, $ses
$html .= '</tr>'; $html .= '</tr>';
$export_array_global[] = $globalRow; $export_array_global[] = $globalRow;
} }
return array( return array(
'html' => $html, 'html' => $html,
'export_array_global' => $export_array_global, 'export_array_global' => $export_array_global,

@ -1,5 +1,6 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
* *
* Exercise results from Learning paths * Exercise results from Learning paths
@ -7,12 +8,8 @@
* @todo implement pagination * @todo implement pagination
* @package chamilo.tracking * @package chamilo.tracking
*/ */
/**
* Code
*/
require_once '../inc/global.inc.php'; require_once '../inc/global.inc.php';
require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
require_once api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer.php';
$this_section = SECTION_TRACKING; $this_section = SECTION_TRACKING;
@ -115,7 +112,6 @@ if (!$export_to_csv) {
echo '</div>'; echo '</div>';
echo '<br /><br />'; echo '<br /><br />';
$form->display(); $form->display();
//echo '<h3>'.sprintf(get_lang('FilteringWithScoreX'), $filter_score).'%</h3>';
} }
$main_result = array(); $main_result = array();
$session_id = 0; $session_id = 0;
@ -125,7 +121,6 @@ foreach($course_list as $current_course ) {
$course_info = api_get_course_info($current_course['code']); $course_info = api_get_course_info($current_course['code']);
$_course = $course_info; $_course = $course_info;
//Getting LP list //Getting LP list
$list = new LearnpathList('', $current_course['code'], $session_id); $list = new LearnpathList('', $current_course['code'], $session_id);
$lp_list = $list->get_flat_list(); $lp_list = $list->get_flat_list();
@ -142,9 +137,8 @@ foreach($course_list as $current_course ) {
$course_info['real_id'], $course_info['real_id'],
$session_id $session_id
); );
//Looping Exercise Attempts // Looping Exercise Attempts
foreach($exercise_stats as $stats) { foreach ($exercise_stats as $stats) {
//$attempt_result[$exercise['id']]['users'][$stats['exe_user_id']][$stats['exe_id']] = array('exe_result' =>$stats['exe_result'],'exe_weighting' =>$stats['exe_weighting']);
$attempt_result[$exercise['id']]['users'][$stats['exe_user_id']][$stats['exe_id']] = $stats; $attempt_result[$exercise['id']]['users'][$stats['exe_user_id']][$stats['exe_id']] = $stats;
$user_list[$stats['exe_user_id']] = $stats['exe_user_id']; $user_list[$stats['exe_user_id']] = $stats['exe_user_id'];
} }
@ -155,11 +149,14 @@ foreach($course_list as $current_course ) {
} }
$main_result[$current_course['code']] = $lps; $main_result[$current_course['code']] = $lps;
} }
//echo '<pre>';print_r($main_result);
if (!empty($user_list)) { if (!empty($user_list)) {
foreach($user_list as $user_id) { foreach($user_list as $user_id) {
$user_data = api_get_user_info($user_id); $user_data = api_get_user_info($user_id);
$user_list_name[$user_id] = api_get_person_name($user_data['firstname'],$user_data['lastname']); $user_list_name[$user_id] = api_get_person_name(
$user_data['firstname'],
$user_data['lastname']
);
} }
} }
$export_array = array(); $export_array = array();
@ -180,10 +177,10 @@ if (!empty($main_result)) {
continue; continue;
} }
foreach($lps as $lp_id => $lp_data) { foreach ($lps as $lp_id => $lp_data) {
$exercises = $lp_data['exercises']; $exercises = $lp_data['exercises'];
foreach($exercises as $exercise_id => $exercise_data) { foreach ($exercises as $exercise_id => $exercise_data) {
$users = $exercise_data['users']; $users = $exercise_data['users'];
foreach($users as $user_id => $attempts) { foreach($users as $user_id => $attempts) {
$attempt = 1; $attempt = 1;
@ -199,7 +196,15 @@ if (!empty($main_result)) {
$html_result .= Display::tag('td', $result); $html_result .= Display::tag('td', $result);
$html_result .= '</tr>'; $html_result .= '</tr>';
$export_array[]= array($course_code, $lp_list_name[$lp_id], $exercise_list_name[$exercise_id], $user_list_name[$user_id], $attempt, api_get_local_time($attempt_data['exe_date']), $result); $export_array[] = array(
$course_code,
$lp_list_name[$lp_id],
$exercise_list_name[$exercise_id],
$user_list_name[$user_id],
$attempt,
api_get_local_time($attempt_data['exe_date']),
$result,
);
$attempt++; $attempt++;
} }
} }
@ -217,55 +222,23 @@ if ($export_to_csv) {
export_complete_report_csv($filename, $export_array); export_complete_report_csv($filename, $export_array);
exit; exit;
} }
function export_complete_report_csv($filename, $array) {
require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php'; function export_complete_report_csv($filename, $array)
$header[] = array(get_lang('Course'),get_lang('LearningPath'), get_lang('Exercise'), get_lang('User'),get_lang('Attempt'), get_lang('Date'),get_lang('Results')); {
$header[] = array(
get_lang('Course'),
get_lang('LearningPath'),
get_lang('Exercise'),
get_lang('User'),
get_lang('Attempt'),
get_lang('Date'),
get_lang('Results'),
);
if (!empty($array)) { if (!empty($array)) {
$array = array_merge($header, $array); $array = array_merge($header, $array);
Export :: arrayToCsv($array, $filename); Export :: arrayToCsv($array, $filename);
} }
exit; exit;
/*
* Too much encoding problems while exporting to XLS, keep it simple
*
*
global $global, $filter_score;
$workbook = new Spreadsheet_Excel_Writer();
$workbook ->setTempDir(api_get_path(SYS_ARCHIVE_PATH));
$workbook->send($filename);
$workbook->setVersion(8); // BIFF8
$worksheet =& $workbook->addWorksheet('Report');
$worksheet->setInputEncoding(api_get_system_encoding());
$line = 0;
$column = 0; //skip the first column (row titles)
$worksheet->write($line,$column,get_lang('Course'));
$column++;
$worksheet->write($line,$column,get_lang('LearningPath'));
$column++;
$worksheet->write($line,$column,get_lang('Exercise'));
$column++;
$worksheet->write($line,$column,get_lang('User'));
$column++;
$worksheet->write($line,$column,get_lang('Attempt'));
$column++;
$worksheet->write($line,$column,get_lang('Date'));
$column++;
$worksheet->write($line,$column,get_lang('Results'));
$column++;
$line++;
foreach ($array as $row) {
$column = 0;
foreach ($row as $item) {
$worksheet->write($line,$column,html_entity_decode(strip_tags($item)));
$column++;
}
$line++;
}
$line++;
$workbook->close();
exit;*/
} }
Display :: display_footer(); Display :: display_footer();

@ -215,45 +215,4 @@ if (!$export_to_xls) {
echo $html_result; echo $html_result;
} }
$filename = 'exam-reporting-'.date('Y-m-d-h:i:s').'.xls';
if ($export_to_xls) {
echo $html_result;
export_complete_report_xls($filename, $export_array);
exit;
}
function sort_user($a, $b)
{
if (is_numeric($a['score']) && is_numeric($b['score'])) {
echo $a['score'].' : '.$b['score'];
echo '<br />';
if ($a['score'] < $b['score']) {
return 1;
}
return 0;
}
return 1;
}
function export_complete_report_xls($filename, $array)
{
global $charset;
$workbook = new Spreadsheet_Excel_Writer();
$workbook ->setTempDir(api_get_path(SYS_ARCHIVE_PATH));
$workbook->send($filename);
$workbook->setVersion(8); // BIFF8
$worksheet =& $workbook->addWorksheet('Report');
//$worksheet->setInputEncoding(api_get_system_encoding());
$worksheet->setInputEncoding($charset);
/*
$line = 0;
$column = 1; // Skip the first column (row titles)
foreach ($array as $elem) {
$worksheet->write($line, $column, $elem);
$column++;
}
$workbook->close();*/
exit;
}
Display :: display_footer(); Display :: display_footer();

Loading…
Cancel
Save