ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSurveyEvaluationGUI.php
Go to the documentation of this file.
1 <?php
2  /*
3  +----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +----------------------------------------------------------------------------+
22 */
23 
24 include_once "./Modules/Survey/classes/inc.SurveyConstants.php";
25 
38 {
39  var $object;
40  var $lng;
41  var $tpl;
42  var $ctrl;
43 
52  function ilSurveyEvaluationGUI($a_object)
53  {
54  global $lng, $tpl, $ilCtrl;
55 
56  $this->lng =& $lng;
57  $this->tpl =& $tpl;
58  $this->ctrl =& $ilCtrl;
59  $this->object =& $a_object;
60  }
61 
65  function &executeCommand()
66  {
67  $cmd = $this->ctrl->getCmd();
68  $next_class = $this->ctrl->getNextClass($this);
69 
70  $cmd = $this->getCommand($cmd);
71  switch($next_class)
72  {
73  default:
74  $ret =& $this->$cmd();
75  break;
76  }
77  return $ret;
78  }
79 
80  function getCommand($cmd)
81  {
82  return $cmd;
83  }
84 
93  {
94  global $rbacsystem;
95  global $ilUser;
96 
97  if ($rbacsystem->checkAccess("write", $_GET["ref_id"]))
98  {
99  // people with write access always have access to the evaluation
100  $_SESSION["anon_evaluation_access"] = $_GET["ref_id"];
101  return $this->evaluation();
102  }
103  if ($this->object->getEvaluationAccess() == EVALUATION_ACCESS_ALL)
104  {
105  // if the evaluation access is open for all users, grant it
106  $_SESSION["anon_evaluation_access"] = $_GET["ref_id"];
107  return $this->evaluation();
108  }
109  $surveycode = $this->object->getUserAccessCode($ilUser->getId());
110  if ($this->object->isAnonymizedParticipant($surveycode))
111  {
112  $_SESSION["anon_evaluation_access"] = $_GET["ref_id"];
113  return $this->evaluation();
114  }
115  $this->tpl->setVariable("TABS", "");
116  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_evaluation_checkaccess.html", "Modules/Survey");
117  $this->tpl->setCurrentBlock("adm_content");
118  $this->tpl->setVariable("AUTHENTICATION_NEEDED", $this->lng->txt("svy_check_evaluation_authentication_needed"));
119  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "checkAnonymizedEvaluationAccess"));
120  $this->tpl->setVariable("EVALUATION_CHECKACCESS_INTRODUCTION", $this->lng->txt("svy_check_evaluation_access_introduction"));
121  $this->tpl->setVariable("VALUE_CHECK", $this->lng->txt("ok"));
122  $this->tpl->setVariable("VALUE_CANCEL", $this->lng->txt("cancel"));
123  $this->tpl->setVariable("TEXT_SURVEY_CODE", $this->lng->txt("survey_code"));
124  $this->tpl->parseCurrentBlock();
125  }
126 
135  {
136  $surveycode = $_POST["surveycode"];
137  if ($this->object->isAnonymizedParticipant($surveycode))
138  {
139  $_SESSION["anon_evaluation_access"] = $_GET["ref_id"];
140  $this->evaluation();
141  }
142  else
143  {
144  ilUtil::sendFailure($this->lng->txt("svy_check_evaluation_wrong_key", true));
145  $this->cancelEvaluationAccess();
146  }
147  }
148 
157  {
158  global $ilCtrl;
159 
160  include_once "./Services/Utilities/classes/class.ilUtil.php";
161  global $tree;
162  $path = $tree->getPathFull($this->object->getRefID());
163  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id",
164  $path[count($path) - 2]["child"]);
165  $ilCtrl->redirectByClass("ilrepositorygui", "frameset");
166  }
167 
175  function evaluationdetails()
176  {
177  $this->evaluation(1);
178  }
179 
180  function exportCumulatedResults($details = 0)
181  {
182  $format_bold = "";
183  $format_percent = "";
184  $format_datetime = "";
185  $format_title = "";
186 
187  switch ($_POST["export_format"])
188  {
189  case TYPE_XLS:
190  include_once "./Services/Excel/classes/class.ilExcelWriterAdapter.php";
191  $excelfile = ilUtil::ilTempnam();
192  $adapter = new ilExcelWriterAdapter($excelfile, FALSE);
193  $workbook = $adapter->getWorkbook();
194  $workbook->setVersion(8); // Use Excel97/2000 Format
195  // Creating a worksheet
196  $format_bold =& $workbook->addFormat();
197  $format_bold->setBold();
198  $format_percent =& $workbook->addFormat();
199  $format_percent->setNumFormat("0.00%");
200  $format_datetime =& $workbook->addFormat();
201  $format_datetime->setNumFormat("DD/MM/YYYY hh:mm:ss");
202  $format_title =& $workbook->addFormat();
203  $format_title->setBold();
204  $format_title->setColor('black');
205  $format_title->setPattern(1);
206  $format_title->setFgColor('silver');
207  $format_title->setAlign('center');
208  // Creating a worksheet
209  include_once ("./Services/Excel/classes/class.ilExcelUtils.php");
210  $mainworksheet =& $workbook->addWorksheet();
211  $column = 0;
212  switch ($_POST['export_label'])
213  {
214  case 'label_only':
215  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("label"), $_POST["export_format"]), $format_bold);
216  break;
217  case 'title_only':
218  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("title"), $_POST["export_format"]), $format_bold);
219  break;
220  default:
221  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("title"), $_POST["export_format"]), $format_bold);
222  $column++;
223  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("label"), $_POST["export_format"]), $format_bold);
224  break;
225  }
226  $column++;
227  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("question"), $_POST["export_format"]), $format_bold);
228  $column++;
229  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("question_type"), $_POST["export_format"]), $format_bold);
230  $column++;
231  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("users_answered"), $_POST["export_format"]), $format_bold);
232  $column++;
233  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("users_skipped"), $_POST["export_format"]), $format_bold);
234  $column++;
235  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("mode"), $_POST["export_format"]), $format_bold);
236  $column++;
237  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("mode_text"), $_POST["export_format"]), $format_bold);
238  $column++;
239  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("mode_nr_of_selections"), $_POST["export_format"]), $format_bold);
240  $column++;
241  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("median"), $_POST["export_format"]), $format_bold);
242  $column++;
243  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("arithmetic_mean"), $_POST["export_format"]), $format_bold);
244  break;
245  case (TYPE_SPSS):
246  $csvfile = array();
247  $csvrow = array();
248  switch ($_POST['export_label'])
249  {
250  case 'label_only':
251  array_push($csvrow, $this->lng->txt("label"));
252  break;
253  case 'title_only':
254  array_push($csvrow, $this->lng->txt("title"));
255  break;
256  default:
257  array_push($csvrow, $this->lng->txt("title"));
258  array_push($csvrow, $this->lng->txt("label"));
259  break;
260  }
261  array_push($csvrow, $this->lng->txt("question"));
262  array_push($csvrow, $this->lng->txt("question_type"));
263  array_push($csvrow, $this->lng->txt("users_answered"));
264  array_push($csvrow, $this->lng->txt("users_skipped"));
265  array_push($csvrow, $this->lng->txt("mode"));
266 
267  //array_push($csvrow, $this->lng->txt("mode_text"));
268 
269 
270  array_push($csvrow, $this->lng->txt("mode_nr_of_selections"));
271  array_push($csvrow, $this->lng->txt("median"));
272  array_push($csvrow, $this->lng->txt("arithmetic_mean"));
273  array_push($csvfile, $csvrow);
274  break;
275  }
276  $questions =& $this->object->getSurveyQuestions();
277  $counter++;
278  foreach ($questions as $data)
279  {
280  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
281  $question = SurveyQuestion::_instanciateQuestion($data["question_id"]);
282 
283  $eval = $this->object->getCumulatedResults($question);
284  switch ($_POST["export_format"])
285  {
286  case TYPE_XLS:
287  $counter = $question->setExportCumulatedXLS($mainworksheet, $format_title, $format_bold, $eval, $counter, $_POST['export_label']);
288  break;
289  case (TYPE_SPSS):
290  $csvrows =& $question->setExportCumulatedCVS($eval, $_POST['export_label']);
291  foreach ($csvrows as $csvrow)
292  {
293  array_push($csvfile, $csvrow);
294  }
295  break;
296  }
297  if ($details)
298  {
299  switch ($_POST["export_format"])
300  {
301  case TYPE_XLS:
302  $question->setExportDetailsXLS($workbook, $format_title, $format_bold, $eval, $_POST['export_label']);
303  break;
304  }
305  }
306  }
307 
308  // #11179
309  if(!$details)
310  {
311  $type = $this->lng->txt("svy_eval_cumulated");
312  }
313  else
314  {
315  $type = $this->lng->txt("svy_eval_detail");
316  }
317  $surveyname = $this->object->getTitle()." ".$type." ".date("Y-m-d");
318  $surveyname = preg_replace("/\s/", "_", trim($surveyname));
319  $surveyname = ilUtil::getASCIIFilename($surveyname);
320 
321  switch ($_POST["export_format"])
322  {
323  case TYPE_XLS:
324  // Let's send the file
325  $workbook->close();
326  ilUtil::deliverFile($excelfile, "$surveyname.xls", "application/vnd.ms-excel");
327  exit();
328  break;
329  case TYPE_SPSS:
330  $csv = "";
331  $separator = ";";
332  foreach ($csvfile as $csvrow)
333  {
334  $csvrow =& $this->object->processCSVRow($csvrow, TRUE, $separator);
335  $csv .= join($csvrow, $separator) . "\n";
336  }
337  include_once "./Services/Utilities/classes/class.ilUtil.php";
338  ilUtil::deliverData($csv, "$surveyname.csv");
339  exit();
340  break;
341  }
342  }
343 
344  public function exportData()
345  {
346  if (strlen($_POST["export_format"]))
347  {
348  $this->exportCumulatedResults(0);
349  return;
350  }
351  else
352  {
353  $this->ctrl->redirect($this, 'evaluation');
354  }
355  }
356 
357  public function exportDetailData()
358  {
359  if (strlen($_POST["export_format"]))
360  {
361  $this->exportCumulatedResults(1);
362  return;
363  }
364  else
365  {
366  $this->ctrl->redirect($this, 'evaluation');
367  }
368  }
369 
370  public function printEvaluation()
371  {
372  ilUtil::sendInfo($this->lng->txt('use_browser_print_function'), true);
373  $this->ctrl->redirect($this, 'evaluation');
374  }
375 
376  function evaluation($details = 0)
377  {
378  global $ilUser;
379  global $rbacsystem;
380  global $ilias;
381  global $ilToolbar;
382 
383  if (!$rbacsystem->checkAccess("read",$_GET["ref_id"]))
384  {
385  ilUtil::sendFailure($this->lng->txt("permission_denied"));
386  return;
387  }
388 
389  $ilToolbar->setFormAction($this->ctrl->getFormAction($this));
390 
391  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
392  $format = new ilSelectInputGUI("", "export_format");
393  $format->setOptions(array(
394  "excel" => $this->lng->txt('exp_type_excel'),
395  "csv" => $this->lng->txt('exp_type_csv')
396  ));
397  $ilToolbar->addInputItem($format);
398 
399  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
400  $label = new ilSelectInputGUI("", "export_label");
401  $label->setOptions(array(
402  'label_only' => $this->lng->txt('export_label_only'),
403  'title_only' => $this->lng->txt('export_title_only'),
404  'title_label'=> $this->lng->txt('export_title_label')
405  ));
406  $ilToolbar->addInputItem($label);
407 
408  if ($details)
409  {
410  $ilToolbar->addFormButton($this->lng->txt("export"), 'exportDetailData');
411  }
412  else
413  {
414  $ilToolbar->addFormButton($this->lng->txt("export"), 'exportData');
415  }
416 
417  switch ($this->object->getEvaluationAccess())
418  {
420  if (!$rbacsystem->checkAccess("write", $_GET["ref_id"]))
421  {
422  ilUtil::sendFailure($this->lng->txt("permission_denied"));
423  return;
424  }
425  break;
427  include_once "./Modules/Survey/classes/class.ilObjSurveyAccess.php";
428  if (!($rbacsystem->checkAccess("write",$_GET["ref_id"]) || ilObjSurveyAccess::_hasEvaluationAccess($this->object->getId(), $ilUser->getId())))
429  {
430  ilUtil::sendFailure($this->lng->txt("permission_denied"));
431  return;
432  }
433  break;
435  if (($this->object->getAnonymize() == 1) && ($_SESSION["anon_evaluation_access"] != $_GET["ref_id"]))
436  {
438  return;
439  }
440  break;
441  }
442 
443  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_evaluation.html", "Modules/Survey");
444  $questions =& $this->object->getSurveyQuestions();
445  $data = array();
446  $counter = 1;
447  $last_questionblock_id = null;
448  foreach ($questions as $qdata)
449  {
450  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
451  $question_gui = SurveyQuestion::_instanciateQuestionGUI($qdata["question_id"]);
452  $question = $question_gui->object;
453  $c = $question->getCumulatedResultData($this->object->getSurveyId(), $counter);
454  if (is_array($c[0]))
455  {
456  foreach ($c as $a)
457  {
458  array_push($data, $a);
459  }
460  }
461  else
462  {
463  array_push($data, $c);
464  }
465  $counter++;
466  if ($details)
467  {
468  // questionblock title handling
469  if($qdata["questionblock_id"] && $qdata["questionblock_id"] != $last_questionblock_id)
470  {
471  $qblock = $this->object->getQuestionblock($qdata["questionblock_id"]);
472  if($qblock["show_blocktitle"])
473  {
474  $this->tpl->setCurrentBlock("detail_qblock");
475  $this->tpl->setVariable("BLOCKTITLE", $qdata["questionblock_title"]);
476  $this->tpl->parseCurrentBlock();
477  }
478 
479  $last_questionblock_id = $qdata["questionblock_id"];
480  }
481 
482  $detail = $question_gui->getCumulatedResultsDetails($this->object->getSurveyId(), $counter-1);
483  $this->tpl->setCurrentBlock("detail");
484  $this->tpl->setVariable("DETAIL", $detail);
485  $this->tpl->parseCurrentBlock();
486  }
487  }
488 
489  include_once "./Modules/Survey/classes/tables/class.ilSurveyResultsCumulatedTableGUI.php";
490  $table_gui = new ilSurveyResultsCumulatedTableGUI($this, 'evaluation', $detail);
491  $table_gui->setData($data);
492  $this->tpl->setVariable('CUMULATED', $table_gui->getHTML());
493  $this->tpl->addCss("./Modules/Survey/templates/default/survey_print.css", "print");
494  $this->tpl->setVariable('FORMACTION', $this->ctrl->getFormAction($this, 'evaluation'));
495  }
496 
504  function exportUserSpecificResults($export_format, $export_label = "")
505  {
506  global $ilLog;
507 
508  $csvfile = array();
509  $csvrow = array();
510  $csvrow2 = array();
511  $questions = array();
512  $questions =& $this->object->getSurveyQuestions(true);
513  array_push($csvrow, $this->lng->txt("lastname")); // #12756
514  array_push($csvrow, $this->lng->txt("firstname"));
515  array_push($csvrow, $this->lng->txt("login"));
516  array_push($csvrow2, "");
517  array_push($csvrow2, "");
518  array_push($csvrow2, "");
519  if ($this->object->canExportSurveyCode())
520  {
521  array_push($csvrow, $this->lng->txt("codes"));
522  array_push($csvrow2, "");
523  }
524  /* #8211
525  if ($this->object->getAnonymize() == ANONYMIZE_OFF)
526  {
527  array_push($csvrow, $this->lng->txt("gender"));
528  }
529  */
530  $cellcounter = 1;
531 
532  foreach ($questions as $question_id => $question_data)
533  {
534  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
535  $question = SurveyQuestion::_instanciateQuestion($question_data["question_id"]);
536  switch ($export_label)
537  {
538  case "label_only":
539  $question->addUserSpecificResultsExportTitles($csvrow, true);
540  break;
541 
542  case "title_only":
543  $question->addUserSpecificResultsExportTitles($csvrow, false);
544  break;
545 
546  default:
547  $question->addUserSpecificResultsExportTitles($csvrow, false);
548  $question->addUserSpecificResultsExportTitles($csvrow2, true, false);
549  break;
550  }
551 
552  $questions[$question_data["question_id"]] = $question;
553  }
554  array_push($csvfile, $csvrow);
555  if(sizeof($csvrow2) && implode("", $csvrow2))
556  {
557  array_push($csvfile, $csvrow2);
558  }
559  $participants =& $this->object->getSurveyFinishedIds();
560  foreach ($participants as $user_id)
561  {
562  $resultset =& $this->object->getEvaluationByUser($questions, $user_id);
563  $csvrow = array();
564 
565  // #12756
566  array_push($csvrow, (trim($resultset["lastname"]))
567  ? $resultset["lastname"]
568  : $resultset["name"]); // anonymous
569  array_push($csvrow, $resultset["firstname"]);
570 
571  array_push($csvrow, $resultset["login"]); // #10579
572  if ($this->object->canExportSurveyCode())
573  {
574  array_push($csvrow, $user_id);
575  }
576  /* #8211
577  if ($this->object->getAnonymize() == ANONYMIZE_OFF)
578  {
579  array_push($csvrow, $resultset["gender"]);
580  }
581  */
582  foreach ($questions as $question_id => $question)
583  {
584  $question->addUserSpecificResultsData($csvrow, $resultset);
585  }
586  $wt = $this->object->getWorkingtimeForParticipant($user_id);
587  array_push($csvrow, $wt);
588  array_push($csvfile, $csvrow);
589  }
590 
591  // #11179
592  $surveyname = $this->object->getTitle()." ".$this->lng->txt("svy_eval_user")." ".date("Y-m-d");
593  $surveyname = preg_replace("/\s/", "_", trim($surveyname));
594  $surveyname = ilUtil::getASCIIFilename($surveyname);
595 
596  switch ($export_format)
597  {
598  case TYPE_XLS:
599  include_once "./Services/Excel/classes/class.ilExcelWriterAdapter.php";
600  $excelfile = ilUtil::ilTempnam();
601  $adapter = new ilExcelWriterAdapter($excelfile, FALSE);
602  $workbook = $adapter->getWorkbook();
603  $workbook->setVersion(8); // Use Excel97/2000 Format
604  // Creating a worksheet
605  $format_bold =& $workbook->addFormat();
606  $format_bold->setBold();
607  $format_percent =& $workbook->addFormat();
608  $format_percent->setNumFormat("0.00%");
609  $format_datetime =& $workbook->addFormat();
610  $format_datetime->setNumFormat("DD/MM/YYYY hh:mm:ss");
611  $format_title =& $workbook->addFormat();
612  $format_title->setBold();
613  $format_title->setColor('black');
614  $format_title->setPattern(1);
615  $format_title->setFgColor('silver');
616  $format_title_plain =& $workbook->addFormat();
617  $format_title_plain->setColor('black');
618  $format_title_plain->setPattern(1);
619  $format_title_plain->setFgColor('silver');
620  // Creating a worksheet
621  $pages = floor((count($csvfile[0])) / 250) + 1;
622  $worksheets = array();
623  for ($i = 0; $i < $pages; $i++)
624  {
625  $worksheets[$i] =& $workbook->addWorksheet();
626  }
627  $row = 0;
628  include_once "./Services/Excel/classes/class.ilExcelUtils.php";
629  $contentstartrow = 0;
630  foreach ($csvfile as $csvrow)
631  {
632  $col = 0;
633  if ($row == 0)
634  {
635  $worksheet = 0;
636  $mainworksheet =& $worksheets[$worksheet];
637  foreach ($csvrow as $text)
638  {
639  if (is_array($text))
640  {
641  $textcount = 0;
642  foreach ($text as $string)
643  {
644  $mainworksheet->writeString($row + $textcount, $col, ilExcelUtils::_convert_text($string, $_POST["export_format"]), $format_title);
645  $textcount++;
646  $contentstartrow = max($contentstartrow, $textcount);
647  }
648  $col++;
649  }
650  else
651  {
652  $mainworksheet->writeString($row, $col++, ilExcelUtils::_convert_text($text, $_POST["export_format"]), $format_title);
653  }
654  if ($col % 251 == 0)
655  {
656  $worksheet++;
657  $col = 1;
658  $mainworksheet =& $worksheets[$worksheet];
659  $mainworksheet->writeString($row, 0, ilExcelUtils::_convert_text($csvrow[0], $_POST["export_format"]), $format_title);
660  }
661  }
662  $mainworksheet->writeString($row, $col++, ilExcelUtils::_convert_text($this->lng->txt('workingtime'), $_POST['export_format']), $format_title);
663  $row = $contentstartrow;
664  }
665  else
666  {
667  $worksheet = 0;
668  $mainworksheet =& $worksheets[$worksheet];
669  foreach ($csvrow as $text)
670  {
671  if (is_numeric($text))
672  {
673  $mainworksheet->writeNumber($row, $col++, $text);
674  }
675  else
676  {
677  $mainworksheet->writeString($row, $col++, ilExcelUtils::_convert_text($text, $_POST["export_format"]));
678  }
679  if ($col % 251 == 0)
680  {
681  $worksheet++;
682  $col = 1;
683  $mainworksheet =& $worksheets[$worksheet];
684  $mainworksheet->writeString($row, 0, ilExcelUtils::_convert_text($csvrow[0], $_POST["export_format"]));
685  }
686  }
687  }
688  $row++;
689  }
690  $workbook->close();
691  ilUtil::deliverFile($excelfile, "$surveyname.xls", "application/vnd.ms-excel");
692  exit();
693  break;
694  case TYPE_SPSS:
695  $csv = "";
696  $separator = ";";
697  foreach ($csvfile as $csvrow)
698  {
699  $csvrow =& str_replace("\n", " ", $this->object->processCSVRow($csvrow, TRUE, $separator));
700  $csv .= join($csvrow, $separator) . "\n";
701  }
702  include_once "./Services/Utilities/classes/class.ilUtil.php";
703  ilUtil::deliverData($csv, "$surveyname.csv");
704  exit();
705  break;
706  }
707  }
708 
716  function evaluationuser()
717  {
718  global $ilAccess, $ilLog, $ilToolbar;
719 
720  if (!$ilAccess->checkAccess("write", "", $this->object->getRefId()))
721  {
722  ilUtil::sendFailure($this->lng->txt("no_permission"), TRUE);
723  $this->ctrl->redirectByClass("ilObjSurveyGUI", "infoScreen");
724  }
725  if (!is_array($_POST))
726  {
727  $_POST = array();
728  }
729  if (array_key_exists("export_format", $_POST))
730  {
731  return $this->exportUserSpecificResults($_POST["export_format"], $_POST["export_label"]);
732  }
733 
734  $userResults =& $this->object->getUserSpecificResults();
735  $questions =& $this->object->getSurveyQuestions(true);
736  $participants =& $this->object->getSurveyParticipants();
737  $tabledata = array();
738  foreach ($participants as $data)
739  {
740  $questioncounter = 1;
741  $question = "";
742  $results = "";
743  $first = true;
744  foreach ($questions as $question_id => $question_data)
745  {
746  $found = $userResults[$question_id][$data["active_id"]];
747  $text = "";
748  if (is_array($found))
749  {
750  $text = implode("<br />", $found);
751  }
752  else
753  {
754  $text = $found;
755  }
756  if (strlen($text) == 0) $text = $this->lng->txt("skipped");
757  $wt = $this->object->getWorkingtimeForParticipant($data['active_id']);
758  if ($first)
759  {
760  array_push($tabledata, array(
761  'username' => $data["sortname"],
762  // 'gender' => $data["gender"],
763  'question' => $questioncounter++ . ". " . $question_data["title"],
764  'results' => $text,
765  'workingtime' => $wt
766  ));
767  $first = false;
768  }
769  else
770  {
771  array_push($tabledata, array(
772  'username' => " ",
773  // 'gender' => " ",
774  'question' => $questioncounter++ . ". " . $question_data["title"],
775  'results' => $text,
776  'workingtime' => null
777  ));
778  }
779  }
780  }
781 
782  $this->tpl->addCss("./Modules/Survey/templates/default/survey_print.css", "print");
783  $this->tpl->setCurrentBlock("generic_css");
784  $this->tpl->setVariable("LOCATION_GENERIC_STYLESHEET", "./Modules/Survey/templates/default/evaluation_print.css");
785  $this->tpl->setVariable("MEDIA_GENERIC_STYLESHEET", "print");
786  $this->tpl->parseCurrentBlock();
787 
788  $ilToolbar->setFormAction($this->ctrl->getFormAction($this, "evaluationuser"));
789 
790  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
791  $format = new ilSelectInputGUI("", "export_format");
792  $format->setOptions(array(
793  "excel" => $this->lng->txt('exp_type_excel'),
794  "csv" => $this->lng->txt('exp_type_csv')
795  ));
796  $ilToolbar->addInputItem($format);
797 
798  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
799  $label = new ilSelectInputGUI("", "export_label");
800  $label->setOptions(array(
801  'label_only' => $this->lng->txt('export_label_only'),
802  'title_only' => $this->lng->txt('export_title_only'),
803  'title_label'=> $this->lng->txt('export_title_label')
804  ));
805  $ilToolbar->addInputItem($label);
806 
807  $ilToolbar->addFormButton($this->lng->txt("export"), 'evaluationuser');
808 
809  $ilToolbar->addSeparator();
810 
811  $ilToolbar->addButton($this->lng->txt("print"), "#", "", "", "onclick=\"javascript:window.print()\"");
812 
813  include_once "./Modules/Survey/classes/tables/class.ilSurveyResultsUserTableGUI.php";
814  $table_gui = new ilSurveyResultsUserTableGUI($this, 'evaluationuser', $this->object->getAnonymize());
815  $table_gui->setData($tabledata);
816  $this->tpl->setContent($table_gui->getHTML());
817  }
818 }
819 
820 ?>