ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilSurveyEvaluationGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
16 {
17  const TYPE_XLS = "excel";
18  const TYPE_SPSS = "csv";
19 
20  var $object;
21  var $lng;
22  var $tpl;
23  var $ctrl;
24  var $appr_id = null;
25 
34  function ilSurveyEvaluationGUI($a_object)
35  {
36  global $lng, $tpl, $ilCtrl;
37 
38  $this->lng =& $lng;
39  $this->tpl =& $tpl;
40  $this->ctrl =& $ilCtrl;
41  $this->object =& $a_object;
42  if ($this->object->get360Mode())
43  {
44  $this->determineAppraiseeId();
45  }
46  }
47 
51  function &executeCommand()
52  {
53  include_once("./Services/Skill/classes/class.ilSkillManagementSettings.php");
54  $skmg_set = new ilSkillManagementSettings();
55  if ($this->object->get360SkillService() && $skmg_set->isActivated())
56  {
57  $cmd = $this->ctrl->getCmd("competenceEval");
58  }
59  else
60  {
61  $cmd = $this->ctrl->getCmd("evaluation");
62  }
63 
64  $next_class = $this->ctrl->getNextClass($this);
65 
66  $cmd = $this->getCommand($cmd);
67  switch($next_class)
68  {
69  default:
70  $this->setEvalSubTabs();
71  $ret =& $this->$cmd();
72  break;
73  }
74  return $ret;
75  }
76 
77  function getCommand($cmd)
78  {
79  return $cmd;
80  }
81 
87  function setEvalSubtabs()
88  {
89  global $ilTabs;
90  global $ilAccess;
91 
92  include_once("./Services/Skill/classes/class.ilSkillManagementSettings.php");
93  $skmg_set = new ilSkillManagementSettings();
94  if ($this->object->get360SkillService() && $skmg_set->isActivated())
95  {
96  $ilTabs->addSubTabTarget(
97  "svy_eval_competences",
98  $this->ctrl->getLinkTarget($this, "competenceEval"),
99  array("competenceEval")
100  );
101  }
102 
103  $ilTabs->addSubTabTarget(
104  "svy_eval_cumulated",
105  $this->ctrl->getLinkTarget($this, "evaluation"),
106  array("evaluation", "checkEvaluationAccess")
107  );
108 
109  $ilTabs->addSubTabTarget(
110  "svy_eval_detail",
111  $this->ctrl->getLinkTarget($this, "evaluationdetails"),
112  array("evaluationdetails")
113  );
114 
115  if ($ilAccess->checkAccess("write", "", $this->object->getRefId()))
116  {
117  $ilTabs->addSubTabTarget(
118  "svy_eval_user",
119  $this->ctrl->getLinkTarget($this, "evaluationuser"),
120  array("evaluationuser")
121  );
122  }
123  }
124 
125 
131  function setAppraiseeId($a_val)
132  {
133  $this->appr_id = $a_val;
134  }
135 
141  function getAppraiseeId()
142  {
143  return $this->appr_id;
144  }
145 
150  {
151  global $ilUser, $rbacsystem;
152 
153  $appr_id = "";
154 
155  // always start with current user
156  if ($_REQUEST["appr_id"] == "")
157  {
158  $req_appr_id = $ilUser->getId();
159  }
160  else
161  {
162  $req_appr_id = (int) $_REQUEST["appr_id"];
163  }
164 
165  // write access? allow selection
166  if ($req_appr_id > 0)
167  {
168  $all_appr = ($this->object->get360Results() == ilObjSurvey::RESULTS_360_ALL);
169 
170  $valid = array();
171  foreach($this->object->getAppraiseesData() as $item)
172  {
173  if ($item["closed"] &&
174  ($item["user_id"] == $ilUser->getId() ||
175  $rbacsystem->checkAccess("write", $this->object->getRefId()) ||
176  $all_appr))
177  {
178  $valid[] = $item["user_id"];
179  }
180  }
181  if(in_array($req_appr_id, $valid))
182  {
183  $appr_id = $req_appr_id;
184  }
185  else
186  {
187  // current selection / user is not valid, use 1st valid instead
188  $appr_id = array_shift($valid);
189  }
190  }
191 
192  $this->ctrl->setParameter($this, "appr_id", $appr_id);
193  $this->setAppraiseeId($appr_id);
194  }
195 
196 
205  {
206  global $ilUser;
207 
208  if($this->object->getAnonymize() == 1 &&
209  $_SESSION["anon_evaluation_access"] == $_GET["ref_id"])
210  {
211  return true;
212  }
213 
214  include_once "Modules/Survey/classes/class.ilObjSurveyAccess.php";
216  {
217  if($this->object->getAnonymize() == 1)
218  {
219  $_SESSION["anon_evaluation_access"] = $_GET["ref_id"];
220  }
221  return true;
222  }
223 
224  if($this->object->getAnonymize() == 1)
225  {
226  // autocode
227  $surveycode = $this->object->getUserAccessCode($ilUser->getId());
228  if ($this->object->isAnonymizedParticipant($surveycode))
229  {
230  $_SESSION["anon_evaluation_access"] = $_GET["ref_id"];
231  return true;
232  }
233 
234  /* try to find code for current (registered) user from existing run
235  if($this->object->findCodeForUser($ilUser->getId()))
236  {
237  $_SESSION["anon_evaluation_access"] = $_GET["ref_id"];
238  return true;
239  }
240  */
241 
242  // code needed
243  $this->tpl->setVariable("TABS", "");
244  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_evaluation_checkaccess.html", "Modules/Survey");
245  $this->tpl->setCurrentBlock("adm_content");
246  $this->tpl->setVariable("AUTHENTICATION_NEEDED", $this->lng->txt("svy_check_evaluation_authentication_needed"));
247  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "checkEvaluationAccess"));
248  $this->tpl->setVariable("EVALUATION_CHECKACCESS_INTRODUCTION", $this->lng->txt("svy_check_evaluation_access_introduction"));
249  $this->tpl->setVariable("VALUE_CHECK", $this->lng->txt("ok"));
250  $this->tpl->setVariable("VALUE_CANCEL", $this->lng->txt("cancel"));
251  $this->tpl->setVariable("TEXT_SURVEY_CODE", $this->lng->txt("survey_code"));
252  $this->tpl->parseCurrentBlock();
253  }
254 
255  $_SESSION["anon_evaluation_access"] = null;
256  return false;
257  }
258 
267  {
268  $surveycode = $_POST["surveycode"];
269  if ($this->object->isAnonymizedParticipant($surveycode))
270  {
271  $_SESSION["anon_evaluation_access"] = $_GET["ref_id"];
272  $this->evaluation();
273  }
274  else
275  {
276  ilUtil::sendFailure($this->lng->txt("svy_check_evaluation_wrong_key", true));
277  $this->cancelEvaluationAccess();
278  }
279  }
280 
289  {
290  global $ilCtrl;
291 
292  include_once "./Services/Utilities/classes/class.ilUtil.php";
293  global $tree;
294  $path = $tree->getPathFull($this->object->getRefID());
295  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id",
296  $path[count($path) - 2]["child"]);
297  $ilCtrl->redirectByClass("ilrepositorygui", "frameset");
298  }
299 
307  function evaluationdetails()
308  {
309  $this->evaluation(1);
310  }
311 
312  function exportCumulatedResults($details = 0)
313  {
314  $format_bold = "";
315  $format_percent = "";
316  $format_datetime = "";
317  $format_title = "";
318 
319  switch ($_POST["export_format"])
320  {
321  case self::TYPE_XLS:
322  include_once "./Services/Excel/classes/class.ilExcelWriterAdapter.php";
323  $excelfile = ilUtil::ilTempnam();
324  $adapter = new ilExcelWriterAdapter($excelfile, FALSE);
325  $workbook = $adapter->getWorkbook();
326  $workbook->setVersion(8); // Use Excel97/2000 Format
327  // Creating a worksheet
328  $format_bold =& $workbook->addFormat();
329  $format_bold->setBold();
330  $format_percent =& $workbook->addFormat();
331  $format_percent->setNumFormat("0.00%");
332  $format_datetime =& $workbook->addFormat();
333  $format_datetime->setNumFormat("DD/MM/YYYY hh:mm:ss");
334  $format_title =& $workbook->addFormat();
335  $format_title->setBold();
336  $format_title->setColor('black');
337  $format_title->setPattern(1);
338  $format_title->setFgColor('silver');
339  $format_title->setAlign('center');
340  // Creating a worksheet
341  include_once ("./Services/Excel/classes/class.ilExcelUtils.php");
342  $mainworksheet =& $workbook->addWorksheet();
343  $column = 0;
344  switch ($_POST['export_label'])
345  {
346  case 'label_only':
347  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("label"), $_POST["export_format"]), $format_bold);
348  break;
349  case 'title_only':
350  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("title"), $_POST["export_format"]), $format_bold);
351  break;
352  default:
353  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("title"), $_POST["export_format"]), $format_bold);
354  $column++;
355  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("label"), $_POST["export_format"]), $format_bold);
356  break;
357  }
358  $column++;
359  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("question"), $_POST["export_format"]), $format_bold);
360  $column++;
361  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("question_type"), $_POST["export_format"]), $format_bold);
362  $column++;
363  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("users_answered"), $_POST["export_format"]), $format_bold);
364  $column++;
365  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("users_skipped"), $_POST["export_format"]), $format_bold);
366  $column++;
367  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("mode"), $_POST["export_format"]), $format_bold);
368  $column++;
369  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("mode_text"), $_POST["export_format"]), $format_bold);
370  $column++;
371  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("mode_nr_of_selections"), $_POST["export_format"]), $format_bold);
372  $column++;
373  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("median"), $_POST["export_format"]), $format_bold);
374  $column++;
375  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("arithmetic_mean"), $_POST["export_format"]), $format_bold);
376  break;
377 
378  case self::TYPE_SPSS:
379  $csvfile = array();
380  $csvrow = array();
381  switch ($_POST['export_label'])
382  {
383  case 'label_only':
384  array_push($csvrow, $this->lng->txt("label"));
385  break;
386  case 'title_only':
387  array_push($csvrow, $this->lng->txt("title"));
388  break;
389  default:
390  array_push($csvrow, $this->lng->txt("title"));
391  array_push($csvrow, $this->lng->txt("label"));
392  break;
393  }
394  array_push($csvrow, $this->lng->txt("question"));
395  array_push($csvrow, $this->lng->txt("question_type"));
396  array_push($csvrow, $this->lng->txt("users_answered"));
397  array_push($csvrow, $this->lng->txt("users_skipped"));
398  array_push($csvrow, $this->lng->txt("mode"));
399 
400  //array_push($csvrow, $this->lng->txt("mode_text"));
401 
402 
403  array_push($csvrow, $this->lng->txt("mode_nr_of_selections"));
404  array_push($csvrow, $this->lng->txt("median"));
405  array_push($csvrow, $this->lng->txt("arithmetic_mean"));
406  array_push($csvfile, $csvrow);
407  break;
408  }
409 
410  $finished_ids = null;
411  if($this->object->get360Mode())
412  {
413  $appr_id = $_REQUEST["appr_id"];
414  if(!$appr_id)
415  {
416  $this->ctrl->redirect($this, $details ? "evaluationdetails" : "evaluation");
417  }
418  $finished_ids = $this->object->getFinishedIdsForAppraiseeId($appr_id);
419  if(!sizeof($finished_ids))
420  {
421  $finished_ids = array(-1);
422  }
423  }
424 
425  $questions =& $this->object->getSurveyQuestions();
426  $counter++;
427  foreach ($questions as $data)
428  {
429  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
430  $question = SurveyQuestion::_instanciateQuestion($data["question_id"]);
431  $eval = $this->object->getCumulatedResults($question, $finished_ids);
432  switch ($_POST["export_format"])
433  {
434  case self::TYPE_XLS:
435  $counter = $question->setExportCumulatedXLS($mainworksheet, $format_title, $format_bold, $eval, $counter, $_POST['export_label']);
436  break;
437 
438  case self::TYPE_SPSS:
439  $csvrows =& $question->setExportCumulatedCVS($eval, $_POST['export_label']);
440  foreach ($csvrows as $csvrow)
441  {
442  array_push($csvfile, $csvrow);
443  }
444  break;
445  }
446  if ($details)
447  {
448  switch ($_POST["export_format"])
449  {
450  case self::TYPE_XLS:
451  $question->setExportDetailsXLS($workbook, $format_title, $format_bold, $eval, $_POST['export_label']);
452  break;
453  }
454  }
455  }
456 
457  // #11179
458  if(!$details)
459  {
460  $type = $this->lng->txt("svy_eval_cumulated");
461  }
462  else
463  {
464  $type = $this->lng->txt("svy_eval_detail");
465  }
466  $surveyname = $this->object->getTitle()." ".$type." ".date("Y-m-d");
467  $surveyname = preg_replace("/\s/", "_", trim($surveyname));
468  $surveyname = ilUtil::getASCIIFilename($surveyname);
469 
470  switch ($_POST["export_format"])
471  {
472  case self::TYPE_XLS:
473  // Let's send the file
474  $workbook->close();
475  ilUtil::deliverFile($excelfile, "$surveyname.xls", "application/vnd.ms-excel");
476  exit();
477  break;
478 
479  case self::TYPE_SPSS:
480  $csv = "";
481  $separator = ";";
482  foreach ($csvfile as $csvrow)
483  {
484  $csvrow =& $this->object->processCSVRow($csvrow, TRUE, $separator);
485  $csv .= join($csvrow, $separator) . "\n";
486  }
487  include_once "./Services/Utilities/classes/class.ilUtil.php";
488  ilUtil::deliverData($csv, "$surveyname.csv");
489  exit();
490  break;
491  }
492  }
493 
494  public function exportData()
495  {
496  if (strlen($_POST["export_format"]))
497  {
498  $this->exportCumulatedResults(0);
499  return;
500  }
501  else
502  {
503  $this->ctrl->redirect($this, 'evaluation');
504  }
505  }
506 
507  public function exportDetailData()
508  {
509  if (strlen($_POST["export_format"]))
510  {
511  $this->exportCumulatedResults(1);
512  return;
513  }
514  else
515  {
516  $this->ctrl->redirect($this, 'evaluation');
517  }
518  }
519 
520  public function printEvaluation()
521  {
522  ilUtil::sendInfo($this->lng->txt('use_browser_print_function'), true);
523  $this->ctrl->redirect($this, 'evaluation');
524  }
525 
526  function evaluation($details = 0)
527  {
528  global $rbacsystem, $ilToolbar;
529 
530  // auth
531  if (!$rbacsystem->checkAccess("write", $_GET["ref_id"]))
532  {
533  if (!$rbacsystem->checkAccess("read",$_GET["ref_id"]))
534  {
535  ilUtil::sendFailure($this->lng->txt("permission_denied"));
536  return;
537  }
538 
539  switch ($this->object->getEvaluationAccess())
540  {
542  ilUtil::sendFailure($this->lng->txt("permission_denied"));
543  return;
544 
547  if(!$this->checkAnonymizedEvaluationAccess())
548  {
549  ilUtil::sendFailure($this->lng->txt("permission_denied"));
550  return;
551  }
552  break;
553  }
554  }
555 
556  $ilToolbar->setFormAction($this->ctrl->getFormAction($this));
557  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
558 
559  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_evaluation.html", "Modules/Survey");
560 
561  $data = null;
562 
563  if($this->object->get360Mode())
564  {
565  $appr_id = $this->getAppraiseeId();
566  $this->addApprSelectionToToolbar();
567  }
568 
569  if(!$this->object->get360Mode() || $appr_id)
570  {
571  $format = new ilSelectInputGUI($this->lng->txt("svy_export_format"), "export_format");
572  $format->setOptions(array(
573  self::TYPE_XLS => $this->lng->txt('exp_type_excel'),
574  self::TYPE_SPSS => $this->lng->txt('exp_type_csv')
575  ));
576  $ilToolbar->addInputItem($format, true);
577 
578  $label = new ilSelectInputGUI("", "export_label");
579  $label->setOptions(array(
580  'label_only' => $this->lng->txt('export_label_only'),
581  'title_only' => $this->lng->txt('export_title_only'),
582  'title_label'=> $this->lng->txt('export_title_label')
583  ));
584  $ilToolbar->addInputItem($label);
585 
586  include_once "Services/UIComponent/Button/classes/class.ilSubmitButton.php";
587  $button = ilSubmitButton::getInstance();
588  $button->setCaption("export");
589  if ($details)
590  {
591  $button->setCommand('exportDetailData');
592  }
593  else
594  {
595  $button->setCommand('exportData');
596  }
597  $button->setOmitPreventDoubleSubmission(true);
598  $ilToolbar->addButtonInstance($button);
599 
600  $ilToolbar->addSeparator();
601 
602  include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
603  $button = ilLinkButton::getInstance();
604  $button->setCaption("print");
605  $button->setOnClick("window.print(); return false;");
606  $button->setOmitPreventDoubleSubmission(true);
607  $ilToolbar->addButtonInstance($button);
608 
609  $finished_ids = null;
610  if($appr_id)
611  {
612  $finished_ids = $this->object->getFinishedIdsForAppraiseeId($appr_id);
613  if(!sizeof($finished_ids))
614  {
615  $finished_ids = array(-1);
616  }
617  }
618 
619  $questions =& $this->object->getSurveyQuestions();
620  $data = array();
621  $counter = 1;
622  $last_questionblock_id = null;
623  foreach ($questions as $qdata)
624  {
625  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
626  $question_gui = SurveyQuestion::_instanciateQuestionGUI($qdata["question_id"]);
627  $question = $question_gui->object;
628  $c = $question->getCumulatedResultData($this->object->getSurveyId(), $counter, $finished_ids);
629  if (is_array($c[0]))
630  {
631  // keep only "main" entry - sub-items will be handled in tablegui
632  // this will enable proper sorting
633  $main = array_shift($c);
634  $main["subitems"] = $c;
635  array_push($data, $main);
636  }
637  else
638  {
639  array_push($data, $c);
640  }
641  $counter++;
642  if ($details)
643  {
644  // questionblock title handling
645  if($qdata["questionblock_id"] && $qdata["questionblock_id"] != $last_questionblock_id)
646  {
647  $qblock = $this->object->getQuestionblock($qdata["questionblock_id"]);
648  if($qblock["show_blocktitle"])
649  {
650  $this->tpl->setCurrentBlock("detail_qblock");
651  $this->tpl->setVariable("BLOCKTITLE", $qdata["questionblock_title"]);
652  $this->tpl->parseCurrentBlock();
653  }
654 
655  $last_questionblock_id = $qdata["questionblock_id"];
656  }
657 
658  $detail = $question_gui->getCumulatedResultsDetails($this->object->getSurveyId(), $counter-1, $finished_ids);
659  $this->tpl->setCurrentBlock("detail");
660  $this->tpl->setVariable("DETAIL", $detail);
661  $this->tpl->parseCurrentBlock();
662  }
663  }
664  }
665 
666  include_once "./Modules/Survey/classes/tables/class.ilSurveyResultsCumulatedTableGUI.php";
667  $table_gui = new ilSurveyResultsCumulatedTableGUI($this, $details ? 'evaluationdetails' : 'evaluation', $detail);
668  $table_gui->setData($data);
669  $this->tpl->setVariable('CUMULATED', $table_gui->getHTML());
670  $this->tpl->addCss("./Modules/Survey/templates/default/survey_print.css", "print");
671  $this->tpl->setVariable('FORMACTION', $this->ctrl->getFormAction($this, 'evaluation'));
672  }
673 
681  {
682  global $ilToolbar, $rbacsystem;
683 
684  if($this->object->get360Mode())
685  {
686  $appr_id = $this->getAppraiseeId();
687 
688  $options = array();
689  if(!$appr_id)
690  {
691  $options[""] = $this->lng->txt("please_select");
692  }
693  $no_appr = true;
694  foreach($this->object->getAppraiseesData() as $item)
695  {
696  if($item["closed"])
697  {
698  $options[$item["user_id"]] = $item["login"];
699  $no_appr = false;
700  }
701  }
702 
703  if(!$no_appr)
704  {
705  if ($rbacsystem->checkAccess("write", $this->object->getRefId()) ||
706  $this->object->get360Results() == ilObjSurvey::RESULTS_360_ALL)
707  {
708  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
709  $appr = new ilSelectInputGUI($this->lng->txt("survey_360_appraisee"), "appr_id");
710  $appr->setOptions($options);
711  $appr->setValue($this->getAppraiseeId());
712  $ilToolbar->addInputItem($appr, true);
713 
714  include_once "Services/UIComponent/Button/classes/class.ilSubmitButton.php";
715  $button = ilSubmitButton::getInstance();
716  $button->setCaption("survey_360_select_appraisee");
717  $button->setCommand($this->ctrl->getCmd());
718  $ilToolbar->addButtonInstance($button);
719 
720  if($appr_id)
721  {
722  $ilToolbar->addSeparator();
723  }
724  }
725  }
726  else
727  {
728  ilUtil::sendFailure($this->lng->txt("survey_360_no_closed_appraisees"));
729  }
730  }
731 
732  }
733 
734 
742  function exportUserSpecificResults($export_format, $export_label, $finished_ids)
743  {
744  global $ilLog;
745 
746  // #13620
748 
749  $csvfile = array();
750  $csvrow = array();
751  $csvrow2 = array();
752  $questions = array();
753  $questions =& $this->object->getSurveyQuestions(true);
754  array_push($csvrow, $this->lng->txt("lastname")); // #12756
755  array_push($csvrow, $this->lng->txt("firstname"));
756  array_push($csvrow, $this->lng->txt("login"));
757  array_push($csvrow, $this->lng->txt('workingtime')); // #13622
758  array_push($csvrow, $this->lng->txt('survey_results_finished'));
759  array_push($csvrow2, "");
760  array_push($csvrow2, "");
761  array_push($csvrow2, "");
762  array_push($csvrow2, "");
763  array_push($csvrow2, "");
764  if ($this->object->canExportSurveyCode())
765  {
766  array_push($csvrow, $this->lng->txt("codes"));
767  array_push($csvrow2, "");
768  }
769  /* #8211
770  if ($this->object->getAnonymize() == ilObjSurvey::ANONYMIZE_OFF)
771  {
772  array_push($csvrow, $this->lng->txt("gender"));
773  }
774  */
775  $cellcounter = 1;
776 
777  foreach ($questions as $question_id => $question_data)
778  {
779  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
780  $question = SurveyQuestion::_instanciateQuestion($question_data["question_id"]);
781  switch ($export_label)
782  {
783  case "label_only":
784  $question->addUserSpecificResultsExportTitles($csvrow, true);
785  break;
786 
787  case "title_only":
788  $question->addUserSpecificResultsExportTitles($csvrow, false);
789  break;
790 
791  default:
792  $question->addUserSpecificResultsExportTitles($csvrow, false);
793  $question->addUserSpecificResultsExportTitles($csvrow2, true, false);
794  break;
795  }
796 
797  $questions[$question_data["question_id"]] = $question;
798  }
799  array_push($csvfile, $csvrow);
800  if(sizeof($csvrow2) && implode("", $csvrow2))
801  {
802  array_push($csvfile, $csvrow2);
803  }
804  if(!$finished_ids)
805  {
806  $participants =& $this->object->getSurveyFinishedIds();
807  }
808  else
809  {
810  $participants = $finished_ids;
811  }
812  $finished_data = array();
813  foreach($this->object->getSurveyParticipants($participants) as $item)
814  {
815  $finished_data[$item["active_id"]] = $item;
816  }
817  foreach ($participants as $user_id)
818  {
819  if($user_id < 1)
820  {
821  continue;
822  }
823 
824  $resultset =& $this->object->getEvaluationByUser($questions, $user_id);
825  $csvrow = array();
826 
827  // #12756
828  array_push($csvrow, (trim($resultset["lastname"]))
829  ? $resultset["lastname"]
830  : $resultset["name"]); // anonymous
831  array_push($csvrow, $resultset["firstname"]);
832 
833  array_push($csvrow, $resultset["login"]); // #10579
834  if ($this->object->canExportSurveyCode())
835  {
836  array_push($csvrow, $user_id);
837  }
838  /* #8211
839  if ($this->object->getAnonymize() == ilObjSurvey::ANONYMIZE_OFF)
840  {
841  array_push($csvrow, $resultset["gender"]);
842  }
843  */
844  $wt = $this->object->getWorkingtimeForParticipant($user_id);
845  array_push($csvrow, $wt);
846 
847  $finished = $finished_data[$user_id];
848  if((bool)$finished["finished"])
849  {
850  if($export_format == self::TYPE_XLS)
851  {
852  // see ilObjUserFolder::createExcelExport()
853  $date = strftime("%Y-%m-%d %H:%M:%S", $finished["finished_tstamp"]);
854  if(preg_match("/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/", $date, $matches))
855  {
856  array_push($csvrow, array("excelTime", ilUtil::excelTime($matches[1],$matches[2],$matches[3],$matches[4],$matches[5],$matches[6])));
857  }
858  }
859  else
860  {
861  array_push($csvrow, ilDatePresentation::formatDate(new ilDateTime($finished["finished_tstamp"], IL_CAL_UNIX)));
862  }
863  }
864  else
865  {
866  array_push($csvrow, "-");
867  }
868 
869  foreach ($questions as $question_id => $question)
870  {
871  $question->addUserSpecificResultsData($csvrow, $resultset);
872  }
873 
874  array_push($csvfile, $csvrow);
875  }
876 
877  // #11179
878  $surveyname = $this->object->getTitle()." ".$this->lng->txt("svy_eval_user")." ".date("Y-m-d");
879  $surveyname = preg_replace("/\s/", "_", trim($surveyname));
880  $surveyname = ilUtil::getASCIIFilename($surveyname);
881 
882  switch ($export_format)
883  {
884  case self::TYPE_XLS:
885  include_once "./Services/Excel/classes/class.ilExcelWriterAdapter.php";
886  $excelfile = ilUtil::ilTempnam();
887  $adapter = new ilExcelWriterAdapter($excelfile, FALSE);
888  $workbook = $adapter->getWorkbook();
889  $workbook->setVersion(8); // Use Excel97/2000 Format
890  // Creating a worksheet
891  $format_bold =& $workbook->addFormat();
892  $format_bold->setBold();
893  $format_percent =& $workbook->addFormat();
894  $format_percent->setNumFormat("0.00%");
895  $format_datetime =& $workbook->addFormat();
896  $format_datetime->setNumFormat("DD/MM/YYYY hh:mm:ss");
897  $format_title =& $workbook->addFormat();
898  $format_title->setBold();
899  $format_title->setColor('black');
900  $format_title->setPattern(1);
901  $format_title->setFgColor('silver');
902  $format_title_plain =& $workbook->addFormat();
903  $format_title_plain->setColor('black');
904  $format_title_plain->setPattern(1);
905  $format_title_plain->setFgColor('silver');
906  // Creating a worksheet
907  $pages = floor((count($csvfile[0])) / 250) + 1;
908  $worksheets = array();
909  for ($i = 0; $i < $pages; $i++)
910  {
911  $worksheets[$i] =& $workbook->addWorksheet();
912  }
913  $row = 0;
914  include_once "./Services/Excel/classes/class.ilExcelUtils.php";
915  $contentstartrow = 0;
916  foreach ($csvfile as $csvrow)
917  {
918  $col = 0;
919  if ($row == 0)
920  {
921  $worksheet = 0;
922  $mainworksheet =& $worksheets[$worksheet];
923  foreach ($csvrow as $text)
924  {
925  if (is_array($text))
926  {
927  $textcount = 0;
928  foreach ($text as $string)
929  {
930  $mainworksheet->writeString($row + $textcount, $col, ilExcelUtils::_convert_text($string, $_POST["export_format"]), $format_title);
931  $textcount++;
932  $contentstartrow = max($contentstartrow, $textcount);
933  }
934  $col++;
935  }
936  else
937  {
938  $mainworksheet->writeString($row, $col++, ilExcelUtils::_convert_text($text, $_POST["export_format"]), $format_title);
939  }
940  if ($col % 251 == 0)
941  {
942  $worksheet++;
943  $col = 1;
944  $mainworksheet =& $worksheets[$worksheet];
945  $mainworksheet->writeString($row, 0, ilExcelUtils::_convert_text($csvrow[0], $_POST["export_format"]), $format_title);
946  }
947  }
948  $row = $contentstartrow;
949  }
950  else
951  {
952  $worksheet = 0;
953  $mainworksheet =& $worksheets[$worksheet];
954  foreach ($csvrow as $text)
955  {
956  if (is_array($text) && $text[0] == "excelTime")
957  {
958  $mainworksheet->write($row, $col++, $text[1], $format_datetime);
959  }
960  else if (is_numeric($text))
961  {
962  $mainworksheet->writeNumber($row, $col++, $text);
963  }
964  else
965  {
966  $mainworksheet->writeString($row, $col++, ilExcelUtils::_convert_text($text, $_POST["export_format"]));
967  }
968  if ($col % 251 == 0)
969  {
970  $worksheet++;
971  $col = 1;
972  $mainworksheet =& $worksheets[$worksheet];
973  $mainworksheet->writeString($row, 0, ilExcelUtils::_convert_text($csvrow[0], $_POST["export_format"]));
974  }
975  }
976  }
977  $row++;
978  }
979  $workbook->close();
980  ilUtil::deliverFile($excelfile, "$surveyname.xls", "application/vnd.ms-excel");
981  exit();
982  break;
983 
984  case self::TYPE_SPSS:
985  $csv = "";
986  $separator = ";";
987  foreach ($csvfile as $idx => $csvrow)
988  {
989  $csvrow =& str_replace("\n", " ", $this->object->processCSVRow($csvrow, TRUE, $separator));
990  $csv .= join($csvrow, $separator) . "\n";
991  }
992  include_once "./Services/Utilities/classes/class.ilUtil.php";
993  ilUtil::deliverData($csv, "$surveyname.csv");
994  exit();
995  break;
996  }
997  }
998 
1000  {
1001  $finished_ids = null;
1002  if($this->object->get360Mode())
1003  {
1004  $appr_id = $_REQUEST["appr_id"];
1005  if(!$appr_id)
1006  {
1007  $this->ctrl->redirect($this, "evaluationuser");
1008  }
1009  $finished_ids = $this->object->getFinishedIdsForAppraiseeId($appr_id);
1010  if(!sizeof($finished_ids))
1011  {
1012  $finished_ids = array(-1);
1013  }
1014  }
1015 
1016  return $this->exportUserSpecificResults($_POST["export_format"], $_POST["export_label"], $finished_ids);
1017  }
1018 
1026  function evaluationuser()
1027  {
1028  global $ilAccess, $ilToolbar;
1029 
1030  if (!$ilAccess->checkAccess("write", "", $this->object->getRefId()))
1031  {
1032  ilUtil::sendFailure($this->lng->txt("no_permission"), TRUE);
1033  $this->ctrl->redirectByClass("ilObjSurveyGUI", "infoScreen");
1034  }
1035 
1036  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
1037  $ilToolbar->setFormAction($this->ctrl->getFormAction($this, "evaluationuser"));
1038 
1039  if($this->object->get360Mode())
1040  {
1041  $appr_id = $this->getAppraiseeId();
1042  $this->addApprSelectionToToolbar();
1043  }
1044 
1045  $tabledata = null;
1046  if(!$this->object->get360Mode() || $appr_id)
1047  {
1048  $format = new ilSelectInputGUI($this->lng->txt("svy_export_format"), "export_format");
1049  $format->setOptions(array(
1050  self::TYPE_XLS => $this->lng->txt('exp_type_excel'),
1051  self::TYPE_SPSS => $this->lng->txt('exp_type_csv')
1052  ));
1053  $ilToolbar->addInputItem($format, true);
1054 
1055  $label = new ilSelectInputGUI("", "export_label");
1056  $label->setOptions(array(
1057  'label_only' => $this->lng->txt('export_label_only'),
1058  'title_only' => $this->lng->txt('export_title_only'),
1059  'title_label'=> $this->lng->txt('export_title_label')
1060  ));
1061  $ilToolbar->addInputItem($label);
1062 
1063  include_once "Services/UIComponent/Button/classes/class.ilSubmitButton.php";
1064  $button = ilSubmitButton::getInstance();
1065  $button->setCaption("export");
1066  $button->setCommand('exportevaluationuser');
1067  $button->setOmitPreventDoubleSubmission(true);
1068  $ilToolbar->addButtonInstance($button);
1069 
1070  $ilToolbar->addSeparator();
1071 
1072  include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
1073  $button = ilLinkButton::getInstance();
1074  $button->setCaption("print");
1075  $button->setOnClick("window.print(); return false;");
1076  $button->setOmitPreventDoubleSubmission(true);
1077  $ilToolbar->addButtonInstance($button);
1078 
1079  $finished_ids = null;
1080  if($appr_id)
1081  {
1082  $finished_ids = $this->object->getFinishedIdsForAppraiseeId($appr_id);
1083  if(!sizeof($finished_ids))
1084  {
1085  $finished_ids = array(-1);
1086  }
1087  }
1088 
1089  $userResults =& $this->object->getUserSpecificResults($finished_ids);
1090  $questions =& $this->object->getSurveyQuestions(true);
1091  $participants =& $this->object->getSurveyParticipants($finished_ids);
1092  $tabledata = array();
1093  $counter = -1;
1094  foreach ($participants as $data)
1095  {
1096  $questioncounter = 1;
1097  $question = "";
1098  $results = "";
1099  $first = true;
1100  foreach ($questions as $question_id => $question_data)
1101  {
1102  $found = $userResults[$question_id][$data["active_id"]];
1103  $text = "";
1104  if (is_array($found))
1105  {
1106  $text = implode("<br />", $found);
1107  }
1108  else
1109  {
1110  $text = $found;
1111  }
1112  if (strlen($text) == 0) $text = ilObjSurvey::getSurveySkippedValue();
1113  $wt = $this->object->getWorkingtimeForParticipant($data['active_id']);
1114  if ($first)
1115  {
1116  if($data["finished"])
1117  {
1118  $finished = $data["finished_tstamp"];
1119  }
1120  else
1121  {
1122  $finished = false;
1123  }
1124  $tabledata[++$counter] = array(
1125  'username' => $data["sortname"],
1126  // 'gender' => $data["gender"],
1127  'question' => $questioncounter++ . ". " . $question_data["title"],
1128  'results' => $text,
1129  'workingtime' => $wt,
1130  'finished' => $finished
1131  );
1132  $first = false;
1133  }
1134  else
1135  {
1136  $tabledata[$counter]["subitems"][] = array(
1137  'username' => " ",
1138  // 'gender' => " ",
1139  'question' => $questioncounter++ . ". " . $question_data["title"],
1140  'results' => $text,
1141  'workingtime' => null,
1142  'finished' => null
1143  );
1144  }
1145  }
1146  }
1147  }
1148 
1149  $this->tpl->addCss("./Modules/Survey/templates/default/survey_print.css", "print");
1150  $this->tpl->setCurrentBlock("generic_css");
1151  $this->tpl->setVariable("LOCATION_GENERIC_STYLESHEET", "./Modules/Survey/templates/default/evaluation_print.css");
1152  $this->tpl->setVariable("MEDIA_GENERIC_STYLESHEET", "print");
1153  $this->tpl->parseCurrentBlock();
1154 
1155  include_once "./Modules/Survey/classes/tables/class.ilSurveyResultsUserTableGUI.php";
1156  $table_gui = new ilSurveyResultsUserTableGUI($this, 'evaluationuser', $this->object->hasAnonymizedResults());
1157  $table_gui->setData($tabledata);
1158  $this->tpl->setContent($table_gui->getHTML());
1159  }
1160 
1167  function competenceEval()
1168  {
1169  global $ilUser, $lng, $ilCtrl, $ilToolbar, $tpl, $ilTabs;
1170 
1171  $survey = $this->object;
1172 
1173  $ilTabs->activateSubtab("svy_eval_competences");
1174  $ilTabs->activateTab("svy_results");
1175 
1176  $ilToolbar->setFormAction($this->ctrl->getFormAction($this, "competenceEval"));
1177 
1178  if($this->object->get360Mode())
1179  {
1180  $appr_id = $this->getAppraiseeId();
1181  $this->addApprSelectionToToolbar();
1182  }
1183 
1184  if ($appr_id == 0)
1185  {
1186  return;
1187  }
1188 
1189  // evaluation modes
1190  $eval_modes = array();
1191 
1192  // get all competences of survey
1193  include_once("./Modules/Survey/classes/class.ilSurveySkill.php");
1194  $sskill = new ilSurveySkill($survey);
1195  $opts = $sskill->getAllAssignedSkillsAsOptions();
1196  $skills = array();
1197  foreach ($opts as $id => $o)
1198  {
1199  $idarr = explode(":", $id);
1200  $skills[$id] = array("id" => $id, "title" => $o, "profiles" => array(),
1201  "base_skill" => $idarr[0], "tref_id" => $idarr[1]);
1202  }
1203 //var_dump($opts);
1204 
1205  // get matching user competence profiles
1206  // -> add gap analysis to profile
1207  include_once("./Services/Skill/classes/class.ilSkillProfile.php");
1208  $profiles = ilSkillProfile::getProfilesOfUser($appr_id);
1209  foreach ($profiles as $p)
1210  {
1211  $prof = new ilSkillProfile($p["id"]);
1212  $prof_levels = $prof->getSkillLevels();
1213  foreach ($prof_levels as $pl)
1214  {
1215  if (isset($skills[$pl["base_skill_id"].":".$pl["tref_id"]]))
1216  {
1217  $skills[$pl["base_skill_id"].":".$pl["tref_id"]]["profiles"][] =
1218  $p["id"];
1219 
1220  $eval_modes["gap_".$p["id"]] =
1221  $lng->txt("svy_gap_analysis").": ".$prof->getTitle();
1222  }
1223  }
1224  }
1225 //var_dump($skills);
1226 //var_dump($eval_modes);
1227 
1228  // if one competence does not match any profiles
1229  // -> add "competences of survey" alternative
1230  reset($skills);
1231  foreach ($skills as $sk)
1232  {
1233  if (count($sk["profiles"]) == 0)
1234  {
1235  $eval_modes["skills_of_survey"] = $lng->txt("svy_all_survey_competences");
1236  }
1237  }
1238 
1239  // final determination of current evaluation mode
1240  $comp_eval_mode = $_GET["comp_eval_mode"];
1241  if ($_POST["comp_eval_mode"] != "")
1242  {
1243  $comp_eval_mode = $_POST["comp_eval_mode"];
1244  }
1245 
1246  if (!isset($eval_modes[$comp_eval_mode]))
1247  {
1248  reset($eval_modes);
1249  $comp_eval_mode = key($eval_modes);
1250  $ilCtrl->setParameter($this, "comp_eval_mode", $comp_eval_mode);
1251  }
1252 
1253  $ilCtrl->saveParameter($this, "comp_eval_mode");
1254 
1255  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
1256  $mode_sel = new ilSelectInputGUI($lng->txt("svy_analysis"), "comp_eval_mode");
1257  $mode_sel->setOptions($eval_modes);
1258  $mode_sel->setValue($comp_eval_mode);
1259  $ilToolbar->addInputItem($mode_sel, true);
1260 
1261  $ilToolbar->addFormButton($lng->txt("select"), "competenceEval");
1262 
1263  if (substr($comp_eval_mode, 0, 4) == "gap_")
1264  {
1265  // gap analysis
1266  $profile_id = (int) substr($comp_eval_mode, 4);
1267 
1268  include_once("./Services/Skill/classes/class.ilPersonalSkillsGUI.php");
1269  $pskills_gui = new ilPersonalSkillsGUI();
1270  $pskills_gui->setProfileId($profile_id);
1271  $pskills_gui->setGapAnalysisActualStatusModePerObject($survey->getId(), $lng->txt("survey_360_raters"));
1272  if ($survey->getFinishedIdForAppraiseeIdAndRaterId($appr_id, $appr_id) > 0)
1273  {
1274  $sskill = new ilSurveySkill($survey);
1275  $self_levels = array();
1276  foreach ($sskill->determineSkillLevelsForAppraisee($appr_id, true) as $sl)
1277  {
1278  $self_levels[$sl["base_skill_id"]][$sl["tref_id"]] = $sl["new_level_id"];
1279  }
1280  $pskills_gui->setGapAnalysisSelfEvalLevels($self_levels);
1281  }
1282  $html = $pskills_gui->getGapAnalysisHTML($appr_id);
1283 
1284  $tpl->setContent($html);
1285  }
1286  else // must be all survey competences
1287  {
1288  include_once("./Services/Skill/classes/class.ilPersonalSkillsGUI.php");
1289  $pskills_gui = new ilPersonalSkillsGUI();
1290  $pskills_gui->setGapAnalysisActualStatusModePerObject($survey->getId(), $lng->txt("survey_360_raters"));
1291  if ($survey->getFinishedIdForAppraiseeIdAndRaterId($appr_id, $appr_id) > 0)
1292  {
1293  $sskill = new ilSurveySkill($survey);
1294  $self_levels = array();
1295  foreach ($sskill->determineSkillLevelsForAppraisee($appr_id, true) as $sl)
1296  {
1297  $self_levels[$sl["base_skill_id"]][$sl["tref_id"]] = $sl["new_level_id"];
1298  }
1299  $pskills_gui->setGapAnalysisSelfEvalLevels($self_levels);
1300  }
1301  $sk = array();
1302  foreach ($skills as $skill)
1303  {
1304  $sk[] = array(
1305  "base_skill_id" => (int) $skill["base_skill"],
1306  "tref_id" => (int) $skill["tref_id"]
1307  );
1308  }
1309  $html = $pskills_gui->getGapAnalysisHTML($appr_id, $sk);
1310 
1311  $tpl->setContent($html);
1312  }
1313 
1314  }
1315 }
1316 
1317 ?>
static deliverData($a_data, $a_filename, $mime="application/octet-stream", $charset="")
deliver data for download via browser.
exit
Definition: login.php:54
$separator
$_POST['username']
Definition: cron.php:12
setEvalSubtabs()
Set the tabs for the evaluation output.
evaluationuser()
Print the survey evaluation for a selected user.
$_SESSION["AccountId"]
This class represents a selection list property in a property form.
const EVALUATION_ACCESS_OFF
const EVALUATION_ACCESS_PARTICIPANTS
$_GET["client_id"]
static getSurveySkippedValue()
_convert_text($a_text, $a_target="has been removed")
cancelEvaluationAccess()
Cancels the input of the survey access code for evaluation access.
ilSurveyEvaluationGUI($a_object)
ilSurveyEvaluationGUI constructor
$valid
$cmd
Definition: sahs_server.php:35
setAppraiseeId($a_val)
Set appraisee id.
static setUseRelativeDates($a_status)
set use relative dates
addApprSelectionToToolbar()
Add appraisee selection to toolbar.
const IL_CAL_UNIX
static getASCIIFilename($a_filename)
convert utf8 to ascii filename
checkEvaluationAccess()
Checks the evaluation access after entering the survey access code.
exportUserSpecificResults($export_format, $export_label, $finished_ids)
Export the user specific results for the survey.
Class ilExcelWriterAdapter.
global $ilCtrl
Definition: ilias.php:18
Skill/Competence handling in surveys.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
Personal skills GUI class.
& _instanciateQuestionGUI($question_id)
Creates an instance of a question GUI with a given question id.
static getProfilesOfUser($a_user_id)
Get profiles of a user.
$data
if(!is_array($argv)) $options
static _lookupObjId($a_id)
competenceEval()
Competence Evaluation.
static formatDate(ilDateTime $date)
Format a date public.
Date and time handling
checkAnonymizedEvaluationAccess()
Show the detailed evaluation.
$results
static deliverFile($a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
setOptions($a_options)
Set Options.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
const EVALUATION_ACCESS_ALL
static ilTempnam($a_temp_path=null)
Create a temporary file in an ILIAS writable directory.
global $ilUser
Definition: imgupload.php:15
$path
Definition: index.php:22
_hasEvaluationAccess($a_obj_id, $user_id)
$text
if($_REQUEST['ilias_path']) define('ILIAS_HTTP_PATH' $_REQUEST['ilias_path']
Definition: index.php:7
Survey evaluation graphical output.
evaluationdetails()
Show the detailed evaluation.
& _instanciateQuestion($question_id)
Creates an instance of a question with a given question id.
static excelTime($year="", $month="", $day="", $hour="", $minute="", $second="")
Calculates a Microsoft Excel date/time value.
$html
Definition: example_001.php:87
const TYPE_SPSS
determineAppraiseeId()
Determine appraisee id.