ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f87
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("", "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);
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  $finished_ids = null;
601  if($appr_id)
602  {
603  $finished_ids = $this->object->getFinishedIdsForAppraiseeId($appr_id);
604  if(!sizeof($finished_ids))
605  {
606  $finished_ids = array(-1);
607  }
608  }
609 
610  $questions =& $this->object->getSurveyQuestions();
611  $data = array();
612  $counter = 1;
613  $last_questionblock_id = null;
614  foreach ($questions as $qdata)
615  {
616  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
617  $question_gui = SurveyQuestion::_instanciateQuestionGUI($qdata["question_id"]);
618  $question = $question_gui->object;
619  $c = $question->getCumulatedResultData($this->object->getSurveyId(), $counter, $finished_ids);
620  if (is_array($c[0]))
621  {
622  // keep only "main" entry - sub-items will be handled in tablegui
623  // this will enable proper sorting
624  $main = array_shift($c);
625  $main["subitems"] = $c;
626  array_push($data, $main);
627  }
628  else
629  {
630  array_push($data, $c);
631  }
632  $counter++;
633  if ($details)
634  {
635  // questionblock title handling
636  if($qdata["questionblock_id"] && $qdata["questionblock_id"] != $last_questionblock_id)
637  {
638  $qblock = $this->object->getQuestionblock($qdata["questionblock_id"]);
639  if($qblock["show_blocktitle"])
640  {
641  $this->tpl->setCurrentBlock("detail_qblock");
642  $this->tpl->setVariable("BLOCKTITLE", $qdata["questionblock_title"]);
643  $this->tpl->parseCurrentBlock();
644  }
645 
646  $last_questionblock_id = $qdata["questionblock_id"];
647  }
648 
649  $detail = $question_gui->getCumulatedResultsDetails($this->object->getSurveyId(), $counter-1, $finished_ids);
650  $this->tpl->setCurrentBlock("detail");
651  $this->tpl->setVariable("DETAIL", $detail);
652  $this->tpl->parseCurrentBlock();
653  }
654  }
655  }
656 
657  include_once "./Modules/Survey/classes/tables/class.ilSurveyResultsCumulatedTableGUI.php";
658  $table_gui = new ilSurveyResultsCumulatedTableGUI($this, $details ? 'evaluationdetails' : 'evaluation', $detail);
659  $table_gui->setData($data);
660  $this->tpl->setVariable('CUMULATED', $table_gui->getHTML());
661  $this->tpl->addCss("./Modules/Survey/templates/default/survey_print.css", "print");
662  $this->tpl->setVariable('FORMACTION', $this->ctrl->getFormAction($this, 'evaluation'));
663  }
664 
672  {
673  global $ilToolbar, $rbacsystem;
674 
675  if($this->object->get360Mode())
676  {
677  $appr_id = $this->getAppraiseeId();
678 
679  $options = array();
680  if(!$appr_id)
681  {
682  $options[""] = $this->lng->txt("please_select");
683  }
684  $no_appr = true;
685  foreach($this->object->getAppraiseesData() as $item)
686  {
687  if($item["closed"])
688  {
689  $options[$item["user_id"]] = $item["login"];
690  $no_appr = false;
691  }
692  }
693 
694  if(!$no_appr)
695  {
696  if ($rbacsystem->checkAccess("write", $this->object->getRefId()) ||
697  $this->object->get360Results() == ilObjSurvey::RESULTS_360_ALL)
698  {
699  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
700  $appr = new ilSelectInputGUI($this->lng->txt("survey_360_appraisee"), "appr_id");
701  $appr->setOptions($options);
702  $appr->setValue($this->getAppraiseeId());
703  $ilToolbar->addInputItem($appr, true);
704 
705  include_once "Services/UIComponent/Button/classes/class.ilSubmitButton.php";
706  $button = ilSubmitButton::getInstance();
707  $button->setCaption("survey_360_select_appraisee");
708  $button->setCommand($this->ctrl->getCmd());
709  $ilToolbar->addButtonInstance($button);
710 
711  if($appr_id)
712  {
713  $ilToolbar->addSeparator();
714  }
715  }
716  }
717  else
718  {
719  ilUtil::sendFailure($this->lng->txt("survey_360_no_closed_appraisees"));
720  }
721  }
722 
723  }
724 
725 
733  function exportUserSpecificResults($export_format, $export_label, $finished_ids)
734  {
735  global $ilLog;
736 
737  // #13620
739 
740  $csvfile = array();
741  $csvrow = array();
742  $csvrow2 = array();
743  $questions = array();
744  $questions =& $this->object->getSurveyQuestions(true);
745  array_push($csvrow, $this->lng->txt("lastname")); // #12756
746  array_push($csvrow, $this->lng->txt("firstname"));
747  array_push($csvrow, $this->lng->txt("login"));
748  array_push($csvrow, $this->lng->txt('workingtime')); // #13622
749  array_push($csvrow, $this->lng->txt('survey_results_finished'));
750  array_push($csvrow2, "");
751  array_push($csvrow2, "");
752  array_push($csvrow2, "");
753  array_push($csvrow2, "");
754  array_push($csvrow2, "");
755  if ($this->object->canExportSurveyCode())
756  {
757  array_push($csvrow, $this->lng->txt("codes"));
758  array_push($csvrow2, "");
759  }
760  /* #8211
761  if ($this->object->getAnonymize() == ilObjSurvey::ANONYMIZE_OFF)
762  {
763  array_push($csvrow, $this->lng->txt("gender"));
764  }
765  */
766  $cellcounter = 1;
767 
768  foreach ($questions as $question_id => $question_data)
769  {
770  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
771  $question = SurveyQuestion::_instanciateQuestion($question_data["question_id"]);
772  switch ($export_label)
773  {
774  case "label_only":
775  $question->addUserSpecificResultsExportTitles($csvrow, true);
776  break;
777 
778  case "title_only":
779  $question->addUserSpecificResultsExportTitles($csvrow, false);
780  break;
781 
782  default:
783  $question->addUserSpecificResultsExportTitles($csvrow, false);
784  $question->addUserSpecificResultsExportTitles($csvrow2, true, false);
785  break;
786  }
787 
788  $questions[$question_data["question_id"]] = $question;
789  }
790  array_push($csvfile, $csvrow);
791  if(sizeof($csvrow2) && implode("", $csvrow2))
792  {
793  array_push($csvfile, $csvrow2);
794  }
795  if(!$finished_ids)
796  {
797  $participants =& $this->object->getSurveyFinishedIds();
798  }
799  else
800  {
801  $participants = $finished_ids;
802  }
803  $finished_data = array();
804  foreach($this->object->getSurveyParticipants($participants) as $item)
805  {
806  $finished_data[$item["active_id"]] = $item;
807  }
808  foreach ($participants as $user_id)
809  {
810  if($user_id < 1)
811  {
812  continue;
813  }
814 
815  $resultset =& $this->object->getEvaluationByUser($questions, $user_id);
816  $csvrow = array();
817 
818  // #12756
819  array_push($csvrow, (trim($resultset["lastname"]))
820  ? $resultset["lastname"]
821  : $resultset["name"]); // anonymous
822  array_push($csvrow, $resultset["firstname"]);
823 
824  array_push($csvrow, $resultset["login"]); // #10579
825  if ($this->object->canExportSurveyCode())
826  {
827  array_push($csvrow, $user_id);
828  }
829  /* #8211
830  if ($this->object->getAnonymize() == ilObjSurvey::ANONYMIZE_OFF)
831  {
832  array_push($csvrow, $resultset["gender"]);
833  }
834  */
835  $wt = $this->object->getWorkingtimeForParticipant($user_id);
836  array_push($csvrow, $wt);
837 
838  $finished = $finished_data[$user_id];
839  if((bool)$finished["finished"])
840  {
841  if($export_format == self::TYPE_XLS)
842  {
843  // see ilObjUserFolder::createExcelExport()
844  $date = strftime("%Y-%m-%d %H:%M:%S", $finished["finished_tstamp"]);
845  if(preg_match("/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/", $date, $matches))
846  {
847  array_push($csvrow, array("excelTime", ilUtil::excelTime($matches[1],$matches[2],$matches[3],$matches[4],$matches[5],$matches[6])));
848  }
849  }
850  else
851  {
852  array_push($csvrow, ilDatePresentation::formatDate(new ilDateTime($finished["finished_tstamp"], IL_CAL_UNIX)));
853  }
854  }
855  else
856  {
857  array_push($csvrow, "-");
858  }
859 
860  foreach ($questions as $question_id => $question)
861  {
862  $question->addUserSpecificResultsData($csvrow, $resultset);
863  }
864 
865  array_push($csvfile, $csvrow);
866  }
867 
868  // #11179
869  $surveyname = $this->object->getTitle()." ".$this->lng->txt("svy_eval_user")." ".date("Y-m-d");
870  $surveyname = preg_replace("/\s/", "_", trim($surveyname));
871  $surveyname = ilUtil::getASCIIFilename($surveyname);
872 
873  switch ($export_format)
874  {
875  case self::TYPE_XLS:
876  include_once "./Services/Excel/classes/class.ilExcelWriterAdapter.php";
877  $excelfile = ilUtil::ilTempnam();
878  $adapter = new ilExcelWriterAdapter($excelfile, FALSE);
879  $workbook = $adapter->getWorkbook();
880  $workbook->setVersion(8); // Use Excel97/2000 Format
881  // Creating a worksheet
882  $format_bold =& $workbook->addFormat();
883  $format_bold->setBold();
884  $format_percent =& $workbook->addFormat();
885  $format_percent->setNumFormat("0.00%");
886  $format_datetime =& $workbook->addFormat();
887  $format_datetime->setNumFormat("DD/MM/YYYY hh:mm:ss");
888  $format_title =& $workbook->addFormat();
889  $format_title->setBold();
890  $format_title->setColor('black');
891  $format_title->setPattern(1);
892  $format_title->setFgColor('silver');
893  $format_title_plain =& $workbook->addFormat();
894  $format_title_plain->setColor('black');
895  $format_title_plain->setPattern(1);
896  $format_title_plain->setFgColor('silver');
897  // Creating a worksheet
898  $pages = floor((count($csvfile[0])) / 250) + 1;
899  $worksheets = array();
900  for ($i = 0; $i < $pages; $i++)
901  {
902  $worksheets[$i] =& $workbook->addWorksheet();
903  }
904  $row = 0;
905  include_once "./Services/Excel/classes/class.ilExcelUtils.php";
906  $contentstartrow = 0;
907  foreach ($csvfile as $csvrow)
908  {
909  $col = 0;
910  if ($row == 0)
911  {
912  $worksheet = 0;
913  $mainworksheet =& $worksheets[$worksheet];
914  foreach ($csvrow as $text)
915  {
916  if (is_array($text))
917  {
918  $textcount = 0;
919  foreach ($text as $string)
920  {
921  $mainworksheet->writeString($row + $textcount, $col, ilExcelUtils::_convert_text($string, $_POST["export_format"]), $format_title);
922  $textcount++;
923  $contentstartrow = max($contentstartrow, $textcount);
924  }
925  $col++;
926  }
927  else
928  {
929  $mainworksheet->writeString($row, $col++, ilExcelUtils::_convert_text($text, $_POST["export_format"]), $format_title);
930  }
931  if ($col % 251 == 0)
932  {
933  $worksheet++;
934  $col = 1;
935  $mainworksheet =& $worksheets[$worksheet];
936  $mainworksheet->writeString($row, 0, ilExcelUtils::_convert_text($csvrow[0], $_POST["export_format"]), $format_title);
937  }
938  }
939  $row = $contentstartrow;
940  }
941  else
942  {
943  $worksheet = 0;
944  $mainworksheet =& $worksheets[$worksheet];
945  foreach ($csvrow as $text)
946  {
947  if (is_array($text) && $text[0] == "excelTime")
948  {
949  $mainworksheet->write($row, $col++, $text[1], $format_datetime);
950  }
951  else if (is_numeric($text))
952  {
953  $mainworksheet->writeNumber($row, $col++, $text);
954  }
955  else
956  {
957  $mainworksheet->writeString($row, $col++, ilExcelUtils::_convert_text($text, $_POST["export_format"]));
958  }
959  if ($col % 251 == 0)
960  {
961  $worksheet++;
962  $col = 1;
963  $mainworksheet =& $worksheets[$worksheet];
964  $mainworksheet->writeString($row, 0, ilExcelUtils::_convert_text($csvrow[0], $_POST["export_format"]));
965  }
966  }
967  }
968  $row++;
969  }
970  $workbook->close();
971  ilUtil::deliverFile($excelfile, "$surveyname.xls", "application/vnd.ms-excel");
972  exit();
973  break;
974 
975  case self::TYPE_SPSS:
976  $csv = "";
977  $separator = ";";
978  foreach ($csvfile as $idx => $csvrow)
979  {
980  $csvrow =& str_replace("\n", " ", $this->object->processCSVRow($csvrow, TRUE, $separator));
981  $csv .= join($csvrow, $separator) . "\n";
982  }
983  include_once "./Services/Utilities/classes/class.ilUtil.php";
984  ilUtil::deliverData($csv, "$surveyname.csv");
985  exit();
986  break;
987  }
988  }
989 
991  {
992  $finished_ids = null;
993  if($this->object->get360Mode())
994  {
995  $appr_id = $_REQUEST["appr_id"];
996  if(!$appr_id)
997  {
998  $this->ctrl->redirect($this, "evaluationuser");
999  }
1000  $finished_ids = $this->object->getFinishedIdsForAppraiseeId($appr_id);
1001  if(!sizeof($finished_ids))
1002  {
1003  $finished_ids = array(-1);
1004  }
1005  }
1006 
1007  return $this->exportUserSpecificResults($_POST["export_format"], $_POST["export_label"], $finished_ids);
1008  }
1009 
1017  function evaluationuser()
1018  {
1019  global $ilAccess, $ilToolbar;
1020 
1021  if (!$ilAccess->checkAccess("write", "", $this->object->getRefId()))
1022  {
1023  ilUtil::sendFailure($this->lng->txt("no_permission"), TRUE);
1024  $this->ctrl->redirectByClass("ilObjSurveyGUI", "infoScreen");
1025  }
1026 
1027  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
1028  $ilToolbar->setFormAction($this->ctrl->getFormAction($this, "evaluationuser"));
1029 
1030  if($this->object->get360Mode())
1031  {
1032  $appr_id = $this->getAppraiseeId();
1033  $this->addApprSelectionToToolbar();
1034  }
1035 
1036  $tabledata = null;
1037  if(!$this->object->get360Mode() || $appr_id)
1038  {
1039  $format = new ilSelectInputGUI("", "export_format");
1040  $format->setOptions(array(
1041  self::TYPE_XLS => $this->lng->txt('exp_type_excel'),
1042  self::TYPE_SPSS => $this->lng->txt('exp_type_csv')
1043  ));
1044  $ilToolbar->addInputItem($format);
1045 
1046  $label = new ilSelectInputGUI("", "export_label");
1047  $label->setOptions(array(
1048  'label_only' => $this->lng->txt('export_label_only'),
1049  'title_only' => $this->lng->txt('export_title_only'),
1050  'title_label'=> $this->lng->txt('export_title_label')
1051  ));
1052  $ilToolbar->addInputItem($label);
1053 
1054  include_once "Services/UIComponent/Button/classes/class.ilSubmitButton.php";
1055  $button = ilSubmitButton::getInstance();
1056  $button->setCaption("export");
1057  $button->setCommand('exportevaluationuser');
1058  $button->setOmitPreventDoubleSubmission(true);
1059  $ilToolbar->addButtonInstance($button);
1060 
1061  $ilToolbar->addSeparator();
1062 
1063  include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
1064  $button = ilLinkButton::getInstance();
1065  $button->setCaption("print");
1066  $button->setOnClick("window.print(); return false;");
1067  $button->setOmitPreventDoubleSubmission(true);
1068  $ilToolbar->addButtonInstance($button);
1069 
1070  $finished_ids = null;
1071  if($appr_id)
1072  {
1073  $finished_ids = $this->object->getFinishedIdsForAppraiseeId($appr_id);
1074  if(!sizeof($finished_ids))
1075  {
1076  $finished_ids = array(-1);
1077  }
1078  }
1079 
1080  $userResults =& $this->object->getUserSpecificResults($finished_ids);
1081  $questions =& $this->object->getSurveyQuestions(true);
1082  $participants =& $this->object->getSurveyParticipants($finished_ids);
1083  $tabledata = array();
1084  $counter = -1;
1085  foreach ($participants as $data)
1086  {
1087  $questioncounter = 1;
1088  $question = "";
1089  $results = "";
1090  $first = true;
1091  foreach ($questions as $question_id => $question_data)
1092  {
1093  $found = $userResults[$question_id][$data["active_id"]];
1094  $text = "";
1095  if (is_array($found))
1096  {
1097  $text = implode("<br />", $found);
1098  }
1099  else
1100  {
1101  $text = $found;
1102  }
1103  if (strlen($text) == 0) $text = ilObjSurvey::getSurveySkippedValue();
1104  $wt = $this->object->getWorkingtimeForParticipant($data['active_id']);
1105  if ($first)
1106  {
1107  if($data["finished"])
1108  {
1109  $finished = $data["finished_tstamp"];
1110  }
1111  else
1112  {
1113  $finished = false;
1114  }
1115  $tabledata[++$counter] = array(
1116  'username' => $data["sortname"],
1117  // 'gender' => $data["gender"],
1118  'question' => $questioncounter++ . ". " . $question_data["title"],
1119  'results' => $text,
1120  'workingtime' => $wt,
1121  'finished' => $finished
1122  );
1123  $first = false;
1124  }
1125  else
1126  {
1127  $tabledata[$counter]["subitems"][] = array(
1128  'username' => " ",
1129  // 'gender' => " ",
1130  'question' => $questioncounter++ . ". " . $question_data["title"],
1131  'results' => $text,
1132  'workingtime' => null,
1133  'finished' => null
1134  );
1135  }
1136  }
1137  }
1138  }
1139 
1140  $this->tpl->addCss("./Modules/Survey/templates/default/survey_print.css", "print");
1141  $this->tpl->setCurrentBlock("generic_css");
1142  $this->tpl->setVariable("LOCATION_GENERIC_STYLESHEET", "./Modules/Survey/templates/default/evaluation_print.css");
1143  $this->tpl->setVariable("MEDIA_GENERIC_STYLESHEET", "print");
1144  $this->tpl->parseCurrentBlock();
1145 
1146  include_once "./Modules/Survey/classes/tables/class.ilSurveyResultsUserTableGUI.php";
1147  $table_gui = new ilSurveyResultsUserTableGUI($this, 'evaluationuser', $this->object->hasAnonymizedResults());
1148  $table_gui->setData($tabledata);
1149  $this->tpl->setContent($table_gui->getHTML());
1150  }
1151 
1158  function competenceEval()
1159  {
1160  global $ilUser, $lng, $ilCtrl, $ilToolbar, $tpl, $ilTabs;
1161 
1162  $survey = $this->object;
1163 
1164  $ilTabs->activateSubtab("svy_eval_competences");
1165  $ilTabs->activateTab("svy_results");
1166 
1167  $ilToolbar->setFormAction($this->ctrl->getFormAction($this, "competenceEval"));
1168 
1169  if($this->object->get360Mode())
1170  {
1171  $appr_id = $this->getAppraiseeId();
1172  $this->addApprSelectionToToolbar();
1173  }
1174 
1175  if ($appr_id == 0)
1176  {
1177  return;
1178  }
1179 
1180  // evaluation modes
1181  $eval_modes = array();
1182 
1183  // get all competences of survey
1184  include_once("./Modules/Survey/classes/class.ilSurveySkill.php");
1185  $sskill = new ilSurveySkill($survey);
1186  $opts = $sskill->getAllAssignedSkillsAsOptions();
1187  $skills = array();
1188  foreach ($opts as $id => $o)
1189  {
1190  $idarr = explode(":", $id);
1191  $skills[$id] = array("id" => $id, "title" => $o, "profiles" => array(),
1192  "base_skill" => $idarr[0], "tref_id" => $idarr[1]);
1193  }
1194 //var_dump($opts);
1195 
1196  // get matching user competence profiles
1197  // -> add gap analysis to profile
1198  include_once("./Services/Skill/classes/class.ilSkillProfile.php");
1199  $profiles = ilSkillProfile::getProfilesOfUser($appr_id);
1200  foreach ($profiles as $p)
1201  {
1202  $prof = new ilSkillProfile($p["id"]);
1203  $prof_levels = $prof->getSkillLevels();
1204  foreach ($prof_levels as $pl)
1205  {
1206  if (isset($skills[$pl["base_skill_id"].":".$pl["tref_id"]]))
1207  {
1208  $skills[$pl["base_skill_id"].":".$pl["tref_id"]]["profiles"][] =
1209  $p["id"];
1210 
1211  $eval_modes["gap_".$p["id"]] =
1212  $lng->txt("svy_gap_analysis").": ".$prof->getTitle();
1213  }
1214  }
1215  }
1216 //var_dump($skills);
1217 //var_dump($eval_modes);
1218 
1219  // if one competence does not match any profiles
1220  // -> add "competences of survey" alternative
1221  reset($skills);
1222  foreach ($skills as $sk)
1223  {
1224  if (count($sk["profiles"]) == 0)
1225  {
1226  $eval_modes["skills_of_survey"] = $lng->txt("svy_all_survey_competences");
1227  }
1228  }
1229 
1230  // final determination of current evaluation mode
1231  $comp_eval_mode = $_GET["comp_eval_mode"];
1232  if ($_POST["comp_eval_mode"] != "")
1233  {
1234  $comp_eval_mode = $_POST["comp_eval_mode"];
1235  }
1236 
1237  if (!isset($eval_modes[$comp_eval_mode]))
1238  {
1239  reset($eval_modes);
1240  $comp_eval_mode = key($eval_modes);
1241  $ilCtrl->setParameter($this, "comp_eval_mode", $comp_eval_mode);
1242  }
1243 
1244  $ilCtrl->saveParameter($this, "comp_eval_mode");
1245 
1246  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
1247  $mode_sel = new ilSelectInputGUI($lng->txt("svy_analysis"), "comp_eval_mode");
1248  $mode_sel->setOptions($eval_modes);
1249  $mode_sel->setValue($comp_eval_mode);
1250  $ilToolbar->addInputItem($mode_sel, true);
1251 
1252  $ilToolbar->addFormButton($lng->txt("select"), "competenceEval");
1253 
1254  if (substr($comp_eval_mode, 0, 4) == "gap_")
1255  {
1256  // gap analysis
1257  $profile_id = (int) substr($comp_eval_mode, 4);
1258 
1259  include_once("./Services/Skill/classes/class.ilPersonalSkillsGUI.php");
1260  $pskills_gui = new ilPersonalSkillsGUI();
1261  $pskills_gui->setProfileId($profile_id);
1262  $pskills_gui->setGapAnalysisActualStatusModePerObject($survey->getId(), $lng->txt("survey_360_raters"));
1263  if ($survey->getFinishedIdForAppraiseeIdAndRaterId($appr_id, $appr_id) > 0)
1264  {
1265  $sskill = new ilSurveySkill($survey);
1266  $self_levels = array();
1267  foreach ($sskill->determineSkillLevelsForAppraisee($appr_id, true) as $sl)
1268  {
1269  $self_levels[$sl["base_skill_id"]][$sl["tref_id"]] = $sl["new_level_id"];
1270  }
1271  $pskills_gui->setGapAnalysisSelfEvalLevels($self_levels);
1272  }
1273  $html = $pskills_gui->getGapAnalysisHTML($appr_id);
1274 
1275  $tpl->setContent($html);
1276  }
1277  else // must be all survey competences
1278  {
1279  include_once("./Services/Skill/classes/class.ilPersonalSkillsGUI.php");
1280  $pskills_gui = new ilPersonalSkillsGUI();
1281  $pskills_gui->setGapAnalysisActualStatusModePerObject($survey->getId(), $lng->txt("survey_360_raters"));
1282  if ($survey->getFinishedIdForAppraiseeIdAndRaterId($appr_id, $appr_id) > 0)
1283  {
1284  $sskill = new ilSurveySkill($survey);
1285  $self_levels = array();
1286  foreach ($sskill->determineSkillLevelsForAppraisee($appr_id, true) as $sl)
1287  {
1288  $self_levels[$sl["base_skill_id"]][$sl["tref_id"]] = $sl["new_level_id"];
1289  }
1290  $pskills_gui->setGapAnalysisSelfEvalLevels($self_levels);
1291  }
1292  $sk = array();
1293  foreach ($skills as $skill)
1294  {
1295  $sk[] = array(
1296  "base_skill_id" => (int) $skill["base_skill"],
1297  "tref_id" => (int) $skill["tref_id"]
1298  );
1299  }
1300  $html = $pskills_gui->getGapAnalysisHTML($appr_id, $sk);
1301 
1302  $tpl->setContent($html);
1303  }
1304 
1305  }
1306 }
1307 
1308 ?>
< a tabindex="-1" style="border-style: none;" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = './securimage_show.php?sid=' + Math.random(); this.blur(); return false">< img src="./images/refresh.png" alt="Reload Image" height="32" width="32" onclick="this.blur()" align="bottom" border="0"/></a >< br/>< strong > Enter Code *if($_SERVER['REQUEST_METHOD']=='POST' &&@ $_POST['do']=='contact') $_SESSION['ctform']['success']
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.
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.
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()
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)
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.
const TYPE_SPSS
determineAppraiseeId()
Determine appraisee id.