ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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->getLinkTargetByClass("ilsurveyevaluationgui", "competenceEval"),
99  array("competenceEval"),
100  ""
101  );
102  }
103 
104  $ilTabs->addSubTabTarget(
105  "svy_eval_cumulated",
106  $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "evaluation"),
107  array("evaluation", "checkEvaluationAccess"),
108  ""
109  );
110 
111  $ilTabs->addSubTabTarget(
112  "svy_eval_detail",
113  $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "evaluationdetails"),
114  array("evaluationdetails"),
115  ""
116  );
117 
118  if ($ilAccess->checkAccess("write", "", $this->object->getRefId()))
119  {
120  $ilTabs->addSubTabTarget(
121  "svy_eval_user",
122  $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "evaluationuser"),
123  array("evaluationuser"),
124  ""
125  );
126  }
127  }
128 
129 
135  function setAppraiseeId($a_val)
136  {
137  $this->appr_id = $a_val;
138  }
139 
145  function getAppraiseeId()
146  {
147  return $this->appr_id;
148  }
149 
154  {
155  global $ilUser, $rbacsystem;
156 
157  $appr_id = "";
158 
159  // always start with current user
160  if ($_REQUEST["appr_id"] == "")
161  {
162  $req_appr_id = $ilUser->getId();
163  }
164  else
165  {
166  $req_appr_id = (int) $_REQUEST["appr_id"];
167  }
168 
169  // write access? allow selection
170  if ($req_appr_id > 0)
171  {
172  $all_appr = ($this->object->get360Results() == ilObjSurvey::RESULTS_360_ALL);
173 
174  $valid = array();
175  foreach($this->object->getAppraiseesData() as $item)
176  {
177  if ($item["closed"] &&
178  ($item["user_id"] == $ilUser->getId() ||
179  $rbacsystem->checkAccess("write", $this->object->getRefId()) ||
180  $all_appr))
181  {
182  $valid[] = $item["user_id"];
183  }
184  }
185  if(in_array($req_appr_id, $valid))
186  {
187  $appr_id = $req_appr_id;
188  }
189  else
190  {
191  // current selection / user is not valid, use 1st valid instead
192  $appr_id = array_shift($valid);
193  }
194  }
195 
196  $this->ctrl->setParameter($this, "appr_id", $appr_id);
197  $this->setAppraiseeId($appr_id);
198  }
199 
200 
209  {
210  global $ilUser;
211 
212  if($this->object->getAnonymize() == 1 &&
213  $_SESSION["anon_evaluation_access"] == $_GET["ref_id"])
214  {
215  return true;
216  }
217 
218  include_once "Modules/Survey/classes/class.ilObjSurveyAccess.php";
220  {
221  if($this->object->getAnonymize() == 1)
222  {
223  $_SESSION["anon_evaluation_access"] = $_GET["ref_id"];
224  }
225  return true;
226  }
227 
228  if($this->object->getAnonymize() == 1)
229  {
230  // autocode
231  $surveycode = $this->object->getUserAccessCode($ilUser->getId());
232  if ($this->object->isAnonymizedParticipant($surveycode))
233  {
234  $_SESSION["anon_evaluation_access"] = $_GET["ref_id"];
235  return true;
236  }
237 
238  /* try to find code for current (registered) user from existing run
239  if($this->object->findCodeForUser($ilUser->getId()))
240  {
241  $_SESSION["anon_evaluation_access"] = $_GET["ref_id"];
242  return true;
243  }
244  */
245 
246  // code needed
247  $this->tpl->setVariable("TABS", "");
248  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_evaluation_checkaccess.html", "Modules/Survey");
249  $this->tpl->setCurrentBlock("adm_content");
250  $this->tpl->setVariable("AUTHENTICATION_NEEDED", $this->lng->txt("svy_check_evaluation_authentication_needed"));
251  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "checkEvaluationAccess"));
252  $this->tpl->setVariable("EVALUATION_CHECKACCESS_INTRODUCTION", $this->lng->txt("svy_check_evaluation_access_introduction"));
253  $this->tpl->setVariable("VALUE_CHECK", $this->lng->txt("ok"));
254  $this->tpl->setVariable("VALUE_CANCEL", $this->lng->txt("cancel"));
255  $this->tpl->setVariable("TEXT_SURVEY_CODE", $this->lng->txt("survey_code"));
256  $this->tpl->parseCurrentBlock();
257  }
258 
259  $_SESSION["anon_evaluation_access"] = null;
260  return false;
261  }
262 
271  {
272  $surveycode = $_POST["surveycode"];
273  if ($this->object->isAnonymizedParticipant($surveycode))
274  {
275  $_SESSION["anon_evaluation_access"] = $_GET["ref_id"];
276  $this->evaluation();
277  }
278  else
279  {
280  ilUtil::sendFailure($this->lng->txt("svy_check_evaluation_wrong_key", true));
281  $this->cancelEvaluationAccess();
282  }
283  }
284 
293  {
294  global $ilCtrl;
295 
296  include_once "./Services/Utilities/classes/class.ilUtil.php";
297  global $tree;
298  $path = $tree->getPathFull($this->object->getRefID());
299  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id",
300  $path[count($path) - 2]["child"]);
301  $ilCtrl->redirectByClass("ilrepositorygui", "frameset");
302  }
303 
311  function evaluationdetails()
312  {
313  $this->evaluation(1);
314  }
315 
316  function exportCumulatedResults($details = 0)
317  {
318  $format_bold = "";
319  $format_percent = "";
320  $format_datetime = "";
321  $format_title = "";
322 
323  switch ($_POST["export_format"])
324  {
325  case self::TYPE_XLS:
326  include_once "./Services/Excel/classes/class.ilExcelWriterAdapter.php";
327  $excelfile = ilUtil::ilTempnam();
328  $adapter = new ilExcelWriterAdapter($excelfile, FALSE);
329  $workbook = $adapter->getWorkbook();
330  $workbook->setVersion(8); // Use Excel97/2000 Format
331  // Creating a worksheet
332  $format_bold =& $workbook->addFormat();
333  $format_bold->setBold();
334  $format_percent =& $workbook->addFormat();
335  $format_percent->setNumFormat("0.00%");
336  $format_datetime =& $workbook->addFormat();
337  $format_datetime->setNumFormat("DD/MM/YYYY hh:mm:ss");
338  $format_title =& $workbook->addFormat();
339  $format_title->setBold();
340  $format_title->setColor('black');
341  $format_title->setPattern(1);
342  $format_title->setFgColor('silver');
343  $format_title->setAlign('center');
344  // Creating a worksheet
345  include_once ("./Services/Excel/classes/class.ilExcelUtils.php");
346  $mainworksheet =& $workbook->addWorksheet();
347  $column = 0;
348  switch ($_POST['export_label'])
349  {
350  case 'label_only':
351  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("label"), $_POST["export_format"]), $format_bold);
352  break;
353  case 'title_only':
354  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("title"), $_POST["export_format"]), $format_bold);
355  break;
356  default:
357  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("title"), $_POST["export_format"]), $format_bold);
358  $column++;
359  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("label"), $_POST["export_format"]), $format_bold);
360  break;
361  }
362  $column++;
363  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("question"), $_POST["export_format"]), $format_bold);
364  $column++;
365  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("question_type"), $_POST["export_format"]), $format_bold);
366  $column++;
367  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("users_answered"), $_POST["export_format"]), $format_bold);
368  $column++;
369  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("users_skipped"), $_POST["export_format"]), $format_bold);
370  $column++;
371  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("mode"), $_POST["export_format"]), $format_bold);
372  $column++;
373  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("mode_text"), $_POST["export_format"]), $format_bold);
374  $column++;
375  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("mode_nr_of_selections"), $_POST["export_format"]), $format_bold);
376  $column++;
377  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("median"), $_POST["export_format"]), $format_bold);
378  $column++;
379  $mainworksheet->writeString(0, $column, ilExcelUtils::_convert_text($this->lng->txt("arithmetic_mean"), $_POST["export_format"]), $format_bold);
380  break;
381 
382  case self::TYPE_SPSS:
383  $csvfile = array();
384  $csvrow = array();
385  switch ($_POST['export_label'])
386  {
387  case 'label_only':
388  array_push($csvrow, $this->lng->txt("label"));
389  break;
390  case 'title_only':
391  array_push($csvrow, $this->lng->txt("title"));
392  break;
393  default:
394  array_push($csvrow, $this->lng->txt("title"));
395  array_push($csvrow, $this->lng->txt("label"));
396  break;
397  }
398  array_push($csvrow, $this->lng->txt("question"));
399  array_push($csvrow, $this->lng->txt("question_type"));
400  array_push($csvrow, $this->lng->txt("users_answered"));
401  array_push($csvrow, $this->lng->txt("users_skipped"));
402  array_push($csvrow, $this->lng->txt("mode"));
403 
404  //array_push($csvrow, $this->lng->txt("mode_text"));
405 
406 
407  array_push($csvrow, $this->lng->txt("mode_nr_of_selections"));
408  array_push($csvrow, $this->lng->txt("median"));
409  array_push($csvrow, $this->lng->txt("arithmetic_mean"));
410  array_push($csvfile, $csvrow);
411  break;
412  }
413 
414  $finished_ids = null;
415  if($this->object->get360Mode())
416  {
417  $appr_id = $_REQUEST["appr_id"];
418  if(!$appr_id)
419  {
420  $this->ctrl->redirect($this, $details ? "evaluationdetails" : "evaluation");
421  }
422  $finished_ids = $this->object->getFinishedIdsForAppraiseeId($appr_id);
423  if(!sizeof($finished_ids))
424  {
425  $finished_ids = array(-1);
426  }
427  }
428 
429  $questions =& $this->object->getSurveyQuestions();
430  $counter++;
431  foreach ($questions as $data)
432  {
433  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
434  $question = SurveyQuestion::_instanciateQuestion($data["question_id"]);
435  $eval = $this->object->getCumulatedResults($question, $finished_ids);
436  switch ($_POST["export_format"])
437  {
438  case self::TYPE_XLS:
439  $counter = $question->setExportCumulatedXLS($mainworksheet, $format_title, $format_bold, $eval, $counter, $_POST['export_label']);
440  break;
441 
442  case self::TYPE_SPSS:
443  $csvrows =& $question->setExportCumulatedCVS($eval, $_POST['export_label']);
444  foreach ($csvrows as $csvrow)
445  {
446  array_push($csvfile, $csvrow);
447  }
448  break;
449  }
450  if ($details)
451  {
452  switch ($_POST["export_format"])
453  {
454  case self::TYPE_XLS:
455  $question->setExportDetailsXLS($workbook, $format_title, $format_bold, $eval, $_POST['export_label']);
456  break;
457  }
458  }
459  }
460 
461  // #11179
462  if(!$details)
463  {
464  $type = $this->lng->txt("svy_eval_cumulated");
465  }
466  else
467  {
468  $type = $this->lng->txt("svy_eval_detail");
469  }
470  $surveyname = $this->object->getTitle()." ".$type." ".date("Y-m-d");
471  $surveyname = preg_replace("/\s/", "_", trim($surveyname));
472  $surveyname = ilUtil::getASCIIFilename($surveyname);
473 
474  switch ($_POST["export_format"])
475  {
476  case self::TYPE_XLS:
477  // Let's send the file
478  $workbook->close();
479  ilUtil::deliverFile($excelfile, "$surveyname.xls", "application/vnd.ms-excel");
480  exit();
481  break;
482 
483  case self::TYPE_SPSS:
484  $csv = "";
485  $separator = ";";
486  foreach ($csvfile as $csvrow)
487  {
488  $csvrow =& $this->object->processCSVRow($csvrow, TRUE, $separator);
489  $csv .= join($csvrow, $separator) . "\n";
490  }
491  include_once "./Services/Utilities/classes/class.ilUtil.php";
492  ilUtil::deliverData($csv, "$surveyname.csv");
493  exit();
494  break;
495  }
496  }
497 
498  public function exportData()
499  {
500  if (strlen($_POST["export_format"]))
501  {
502  $this->exportCumulatedResults(0);
503  return;
504  }
505  else
506  {
507  $this->ctrl->redirect($this, 'evaluation');
508  }
509  }
510 
511  public function exportDetailData()
512  {
513  if (strlen($_POST["export_format"]))
514  {
515  $this->exportCumulatedResults(1);
516  return;
517  }
518  else
519  {
520  $this->ctrl->redirect($this, 'evaluation');
521  }
522  }
523 
524  public function printEvaluation()
525  {
526  ilUtil::sendInfo($this->lng->txt('use_browser_print_function'), true);
527  $this->ctrl->redirect($this, 'evaluation');
528  }
529 
530  function evaluation($details = 0)
531  {
532  global $rbacsystem;
533  global $ilToolbar;
534  global $ilUser;
535 
536  // auth
537  if (!$rbacsystem->checkAccess("write", $_GET["ref_id"]))
538  {
539  if (!$rbacsystem->checkAccess("read",$_GET["ref_id"]))
540  {
541  ilUtil::sendFailure($this->lng->txt("permission_denied"));
542  return;
543  }
544 
545  switch ($this->object->getEvaluationAccess())
546  {
548  ilUtil::sendFailure($this->lng->txt("permission_denied"));
549  return;
550 
553  if(!$this->checkAnonymizedEvaluationAccess())
554  {
555  ilUtil::sendFailure($this->lng->txt("permission_denied"));
556  return;
557  }
558  break;
559  }
560  }
561 
562  $ilToolbar->setFormAction($this->ctrl->getFormAction($this));
563  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
564 
565  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_evaluation.html", "Modules/Survey");
566 
567  $data = null;
568 
569  if($this->object->get360Mode())
570  {
571  $appr_id = $this->getAppraiseeId();
572  $this->addApprSelectionToToolbar();
573  }
574 
575  if(!$this->object->get360Mode() || $appr_id)
576  {
577  $format = new ilSelectInputGUI("", "export_format");
578  $format->setOptions(array(
579  self::TYPE_XLS => $this->lng->txt('exp_type_excel'),
580  self::TYPE_SPSS => $this->lng->txt('exp_type_csv')
581  ));
582  $ilToolbar->addInputItem($format);
583 
584  $label = new ilSelectInputGUI("", "export_label");
585  $label->setOptions(array(
586  'label_only' => $this->lng->txt('export_label_only'),
587  'title_only' => $this->lng->txt('export_title_only'),
588  'title_label'=> $this->lng->txt('export_title_label')
589  ));
590  $ilToolbar->addInputItem($label);
591 
592  if ($details)
593  {
594  $ilToolbar->addFormButton($this->lng->txt("export"), 'exportDetailData');
595  }
596  else
597  {
598  $ilToolbar->addFormButton($this->lng->txt("export"), 'exportData');
599  }
600 
601  $finished_ids = null;
602  if($appr_id)
603  {
604  $finished_ids = $this->object->getFinishedIdsForAppraiseeId($appr_id);
605  if(!sizeof($finished_ids))
606  {
607  $finished_ids = array(-1);
608  }
609  }
610 
611  $questions =& $this->object->getSurveyQuestions();
612  $data = array();
613  $counter = 1;
614  $last_questionblock_id = null;
615  foreach ($questions as $qdata)
616  {
617  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
618  $question_gui = SurveyQuestion::_instanciateQuestionGUI($qdata["question_id"]);
619  $question = $question_gui->object;
620  $c = $question->getCumulatedResultData($this->object->getSurveyId(), $counter, $finished_ids);
621  if (is_array($c[0]))
622  {
623  // keep only "main" entry - sub-items will be handled in tablegui
624  // this will enable proper sorting
625  $main = array_shift($c);
626  $main["subitems"] = $c;
627  array_push($data, $main);
628  }
629  else
630  {
631  array_push($data, $c);
632  }
633  $counter++;
634  if ($details)
635  {
636  // questionblock title handling
637  if($qdata["questionblock_id"] && $qdata["questionblock_id"] != $last_questionblock_id)
638  {
639  $qblock = $this->object->getQuestionblock($qdata["questionblock_id"]);
640  if($qblock["show_blocktitle"])
641  {
642  $this->tpl->setCurrentBlock("detail_qblock");
643  $this->tpl->setVariable("BLOCKTITLE", $qdata["questionblock_title"]);
644  $this->tpl->parseCurrentBlock();
645  }
646 
647  $last_questionblock_id = $qdata["questionblock_id"];
648  }
649 
650  $detail = $question_gui->getCumulatedResultsDetails($this->object->getSurveyId(), $counter-1, $finished_ids);
651  $this->tpl->setCurrentBlock("detail");
652  $this->tpl->setVariable("DETAIL", $detail);
653  $this->tpl->parseCurrentBlock();
654  }
655  }
656  }
657 
658  include_once "./Modules/Survey/classes/tables/class.ilSurveyResultsCumulatedTableGUI.php";
659  $table_gui = new ilSurveyResultsCumulatedTableGUI($this, $details ? 'evaluationdetails' : 'evaluation', $detail);
660  $table_gui->setData($data);
661  $this->tpl->setVariable('CUMULATED', $table_gui->getHTML());
662  $this->tpl->addCss("./Modules/Survey/templates/default/survey_print.css", "print");
663  $this->tpl->setVariable('FORMACTION', $this->ctrl->getFormAction($this, 'evaluation'));
664  }
665 
673  {
674  global $ilToolbar, $rbacsystem;
675 
676  if($this->object->get360Mode())
677  {
678  $appr_id = $this->getAppraiseeId();
679 
680  $options = array();
681  if(!$appr_id)
682  {
683  $options[""] = $this->lng->txt("please_select");
684  }
685  $no_appr = true;
686  foreach($this->object->getAppraiseesData() as $item)
687  {
688  if($item["closed"])
689  {
690  $options[$item["user_id"]] = $item["login"];
691  $no_appr = false;
692  }
693  }
694 
695  if(!$no_appr)
696  {
697  if ($rbacsystem->checkAccess("write", $this->object->getRefId()) ||
698  $this->object->get360Results() == ilObjSurvey::RESULTS_360_ALL)
699  {
700  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
701  $appr = new ilSelectInputGUI($this->lng->txt("survey_360_appraisee"), "appr_id");
702  $appr->setOptions($options);
703  $appr->setValue($this->getAppraiseeId());
704  $ilToolbar->addInputItem($appr, true);
705 
706  $ilToolbar->addFormButton($this->lng->txt("survey_360_select_appraisee"),
707  $this->ctrl->getCmd());
708 
709  if($appr_id)
710  {
711  $ilToolbar->addSeparator();
712  }
713  }
714  }
715  else
716  {
717  ilUtil::sendFailure($this->lng->txt("survey_360_no_closed_appraisees"));
718  }
719  }
720 
721  }
722 
723 
731  function exportUserSpecificResults($export_format, $export_label, $finished_ids)
732  {
733  global $ilLog;
734 
735  $csvfile = array();
736  $csvrow = array();
737  $csvrow2 = array();
738  $questions = array();
739  $questions =& $this->object->getSurveyQuestions(true);
740  array_push($csvrow, $this->lng->txt("lastname")); // #12756
741  array_push($csvrow, $this->lng->txt("firstname"));
742  array_push($csvrow, $this->lng->txt("login"));
743  array_push($csvrow2, "");
744  array_push($csvrow2, "");
745  array_push($csvrow2, "");
746  if ($this->object->canExportSurveyCode())
747  {
748  array_push($csvrow, $this->lng->txt("codes"));
749  array_push($csvrow2, "");
750  }
751  /* #8211
752  if ($this->object->getAnonymize() == ilObjSurvey::ANONYMIZE_OFF)
753  {
754  array_push($csvrow, $this->lng->txt("gender"));
755  }
756  */
757  $cellcounter = 1;
758 
759  foreach ($questions as $question_id => $question_data)
760  {
761  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
762  $question = SurveyQuestion::_instanciateQuestion($question_data["question_id"]);
763  switch ($export_label)
764  {
765  case "label_only":
766  $question->addUserSpecificResultsExportTitles($csvrow, true);
767  break;
768 
769  case "title_only":
770  $question->addUserSpecificResultsExportTitles($csvrow, false);
771  break;
772 
773  default:
774  $question->addUserSpecificResultsExportTitles($csvrow, false);
775  $question->addUserSpecificResultsExportTitles($csvrow2, true, false);
776  break;
777  }
778 
779  $questions[$question_data["question_id"]] = $question;
780  }
781  array_push($csvfile, $csvrow);
782  if(sizeof($csvrow2) && implode("", $csvrow2))
783  {
784  array_push($csvfile, $csvrow2);
785  }
786  if(!$finished_ids)
787  {
788  $participants =& $this->object->getSurveyFinishedIds();
789  }
790  else
791  {
792  $participants = $finished_ids;
793  }
794  foreach ($participants as $user_id)
795  {
796  if($user_id < 1)
797  {
798  continue;
799  }
800 
801  $resultset =& $this->object->getEvaluationByUser($questions, $user_id);
802  $csvrow = array();
803 
804  // #12756
805  array_push($csvrow, (trim($resultset["lastname"]))
806  ? $resultset["lastname"]
807  : $resultset["name"]); // anonymous
808  array_push($csvrow, $resultset["firstname"]);
809 
810  array_push($csvrow, $resultset["login"]); // #10579
811  if ($this->object->canExportSurveyCode())
812  {
813  array_push($csvrow, $user_id);
814  }
815  /* #8211
816  if ($this->object->getAnonymize() == ilObjSurvey::ANONYMIZE_OFF)
817  {
818  array_push($csvrow, $resultset["gender"]);
819  }
820  */
821  foreach ($questions as $question_id => $question)
822  {
823  $question->addUserSpecificResultsData($csvrow, $resultset);
824  }
825  $wt = $this->object->getWorkingtimeForParticipant($user_id);
826  array_push($csvrow, $wt);
827  array_push($csvfile, $csvrow);
828  }
829 
830  // #11179
831  $surveyname = $this->object->getTitle()." ".$this->lng->txt("svy_eval_user")." ".date("Y-m-d");
832  $surveyname = preg_replace("/\s/", "_", trim($surveyname));
833  $surveyname = ilUtil::getASCIIFilename($surveyname);
834 
835  switch ($export_format)
836  {
837  case self::TYPE_XLS:
838  include_once "./Services/Excel/classes/class.ilExcelWriterAdapter.php";
839  $excelfile = ilUtil::ilTempnam();
840  $adapter = new ilExcelWriterAdapter($excelfile, FALSE);
841  $workbook = $adapter->getWorkbook();
842  $workbook->setVersion(8); // Use Excel97/2000 Format
843  // Creating a worksheet
844  $format_bold =& $workbook->addFormat();
845  $format_bold->setBold();
846  $format_percent =& $workbook->addFormat();
847  $format_percent->setNumFormat("0.00%");
848  $format_datetime =& $workbook->addFormat();
849  $format_datetime->setNumFormat("DD/MM/YYYY hh:mm:ss");
850  $format_title =& $workbook->addFormat();
851  $format_title->setBold();
852  $format_title->setColor('black');
853  $format_title->setPattern(1);
854  $format_title->setFgColor('silver');
855  $format_title_plain =& $workbook->addFormat();
856  $format_title_plain->setColor('black');
857  $format_title_plain->setPattern(1);
858  $format_title_plain->setFgColor('silver');
859  // Creating a worksheet
860  $pages = floor((count($csvfile[0])) / 250) + 1;
861  $worksheets = array();
862  for ($i = 0; $i < $pages; $i++)
863  {
864  $worksheets[$i] =& $workbook->addWorksheet();
865  }
866  $row = 0;
867  include_once "./Services/Excel/classes/class.ilExcelUtils.php";
868  $contentstartrow = 0;
869  foreach ($csvfile as $csvrow)
870  {
871  $col = 0;
872  if ($row == 0)
873  {
874  $worksheet = 0;
875  $mainworksheet =& $worksheets[$worksheet];
876  foreach ($csvrow as $text)
877  {
878  if (is_array($text))
879  {
880  $textcount = 0;
881  foreach ($text as $string)
882  {
883  $mainworksheet->writeString($row + $textcount, $col, ilExcelUtils::_convert_text($string, $_POST["export_format"]), $format_title);
884  $textcount++;
885  $contentstartrow = max($contentstartrow, $textcount);
886  }
887  $col++;
888  }
889  else
890  {
891  $mainworksheet->writeString($row, $col++, ilExcelUtils::_convert_text($text, $_POST["export_format"]), $format_title);
892  }
893  if ($col % 251 == 0)
894  {
895  $worksheet++;
896  $col = 1;
897  $mainworksheet =& $worksheets[$worksheet];
898  $mainworksheet->writeString($row, 0, ilExcelUtils::_convert_text($csvrow[0], $_POST["export_format"]), $format_title);
899  }
900  }
901  $mainworksheet->writeString($row, $col++, ilExcelUtils::_convert_text($this->lng->txt('workingtime'), $_POST['export_format']), $format_title);
902  $row = $contentstartrow;
903  }
904  else
905  {
906  $worksheet = 0;
907  $mainworksheet =& $worksheets[$worksheet];
908  foreach ($csvrow as $text)
909  {
910  if (is_numeric($text))
911  {
912  $mainworksheet->writeNumber($row, $col++, $text);
913  }
914  else
915  {
916  $mainworksheet->writeString($row, $col++, ilExcelUtils::_convert_text($text, $_POST["export_format"]));
917  }
918  if ($col % 251 == 0)
919  {
920  $worksheet++;
921  $col = 1;
922  $mainworksheet =& $worksheets[$worksheet];
923  $mainworksheet->writeString($row, 0, ilExcelUtils::_convert_text($csvrow[0], $_POST["export_format"]));
924  }
925  }
926  }
927  $row++;
928  }
929  $workbook->close();
930  ilUtil::deliverFile($excelfile, "$surveyname.xls", "application/vnd.ms-excel");
931  exit();
932  break;
933 
934  case self::TYPE_SPSS:
935  $csv = "";
936  $separator = ";";
937  foreach ($csvfile as $csvrow)
938  {
939  $csvrow =& str_replace("\n", " ", $this->object->processCSVRow($csvrow, TRUE, $separator));
940  $csv .= join($csvrow, $separator) . "\n";
941  }
942  include_once "./Services/Utilities/classes/class.ilUtil.php";
943  ilUtil::deliverData($csv, "$surveyname.csv");
944  exit();
945  break;
946  }
947  }
948 
950  {
951  $finished_ids = null;
952  if($this->object->get360Mode())
953  {
954  $appr_id = $_REQUEST["appr_id"];
955  if(!$appr_id)
956  {
957  $this->ctrl->redirect($this, "evaluationuser");
958  }
959  $finished_ids = $this->object->getFinishedIdsForAppraiseeId($appr_id);
960  if(!sizeof($finished_ids))
961  {
962  $finished_ids = array(-1);
963  }
964  }
965 
966  return $this->exportUserSpecificResults($_POST["export_format"], $_POST["export_label"], $finished_ids);
967  }
968 
976  function evaluationuser()
977  {
978  global $ilAccess, $ilLog, $ilToolbar;
979 
980  if (!$ilAccess->checkAccess("write", "", $this->object->getRefId()))
981  {
982  ilUtil::sendFailure($this->lng->txt("no_permission"), TRUE);
983  $this->ctrl->redirectByClass("ilObjSurveyGUI", "infoScreen");
984  }
985 
986  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
987  $ilToolbar->setFormAction($this->ctrl->getFormAction($this, "evaluationuser"));
988 
989  if($this->object->get360Mode())
990  {
991  $appr_id = $this->getAppraiseeId();
992  $this->addApprSelectionToToolbar();
993  }
994 
995  $tabledata = null;
996  if(!$this->object->get360Mode() || $appr_id)
997  {
998  $format = new ilSelectInputGUI("", "export_format");
999  $format->setOptions(array(
1000  self::TYPE_XLS => $this->lng->txt('exp_type_excel'),
1001  self::TYPE_SPSS => $this->lng->txt('exp_type_csv')
1002  ));
1003  $ilToolbar->addInputItem($format);
1004 
1005  $label = new ilSelectInputGUI("", "export_label");
1006  $label->setOptions(array(
1007  'label_only' => $this->lng->txt('export_label_only'),
1008  'title_only' => $this->lng->txt('export_title_only'),
1009  'title_label'=> $this->lng->txt('export_title_label')
1010  ));
1011  $ilToolbar->addInputItem($label);
1012 
1013  $ilToolbar->addFormButton($this->lng->txt("export"), 'exportevaluationuser');
1014 
1015  $ilToolbar->addSeparator();
1016 
1017  $ilToolbar->addButton($this->lng->txt("print"), "#", "", "", "onclick=\"javascript:window.print()\"");
1018 
1019  $finished_ids = null;
1020  if($appr_id)
1021  {
1022  $finished_ids = $this->object->getFinishedIdsForAppraiseeId($appr_id);
1023  if(!sizeof($finished_ids))
1024  {
1025  $finished_ids = array(-1);
1026  }
1027  }
1028 
1029  $userResults =& $this->object->getUserSpecificResults($finished_ids);
1030  $questions =& $this->object->getSurveyQuestions(true);
1031  $participants =& $this->object->getSurveyParticipants($finished_ids);
1032  $tabledata = array();
1033  $counter = -1;
1034  foreach ($participants as $data)
1035  {
1036  $questioncounter = 1;
1037  $question = "";
1038  $results = "";
1039  $first = true;
1040  foreach ($questions as $question_id => $question_data)
1041  {
1042  $found = $userResults[$question_id][$data["active_id"]];
1043  $text = "";
1044  if (is_array($found))
1045  {
1046  $text = implode("<br />", $found);
1047  }
1048  else
1049  {
1050  $text = $found;
1051  }
1052  if (strlen($text) == 0) $text = ilObjSurvey::getSurveySkippedValue();
1053  $wt = $this->object->getWorkingtimeForParticipant($data['active_id']);
1054  if ($first)
1055  {
1056  $tabledata[++$counter] = array(
1057  'username' => $data["sortname"],
1058  // 'gender' => $data["gender"],
1059  'question' => $questioncounter++ . ". " . $question_data["title"],
1060  'results' => $text,
1061  'workingtime' => $wt
1062  );
1063  $first = false;
1064  }
1065  else
1066  {
1067  $tabledata[$counter]["subitems"][] = array(
1068  'username' => " ",
1069  // 'gender' => " ",
1070  'question' => $questioncounter++ . ". " . $question_data["title"],
1071  'results' => $text,
1072  'workingtime' => null
1073  );
1074  }
1075  }
1076  }
1077  }
1078 
1079  $this->tpl->addCss("./Modules/Survey/templates/default/survey_print.css", "print");
1080  $this->tpl->setCurrentBlock("generic_css");
1081  $this->tpl->setVariable("LOCATION_GENERIC_STYLESHEET", "./Modules/Survey/templates/default/evaluation_print.css");
1082  $this->tpl->setVariable("MEDIA_GENERIC_STYLESHEET", "print");
1083  $this->tpl->parseCurrentBlock();
1084 
1085  include_once "./Modules/Survey/classes/tables/class.ilSurveyResultsUserTableGUI.php";
1086  $table_gui = new ilSurveyResultsUserTableGUI($this, 'evaluationuser', $this->object->getAnonymize());
1087  $table_gui->setData($tabledata);
1088  $this->tpl->setContent($table_gui->getHTML());
1089  }
1090 
1097  function competenceEval()
1098  {
1099  global $ilUser, $lng, $ilCtrl, $ilToolbar, $tpl, $ilTabs;
1100 
1101  $survey = $this->object;
1102 
1103  $ilTabs->activateSubtab("svy_eval_competences");
1104  $ilTabs->activateTab("svy_results");
1105 
1106  $ilToolbar->setFormAction($this->ctrl->getFormAction($this, "competenceEval"));
1107 
1108  if($this->object->get360Mode())
1109  {
1110  $appr_id = $this->getAppraiseeId();
1111  $this->addApprSelectionToToolbar();
1112  }
1113 
1114  if ($appr_id == 0)
1115  {
1116  return;
1117  }
1118 
1119  // evaluation modes
1120  $eval_modes = array();
1121 
1122  // get all competences of survey
1123  include_once("./Modules/Survey/classes/class.ilSurveySkill.php");
1124  $sskill = new ilSurveySkill($survey);
1125  $opts = $sskill->getAllAssignedSkillsAsOptions();
1126  $skills = array();
1127  foreach ($opts as $id => $o)
1128  {
1129  $idarr = explode(":", $id);
1130  $skills[$id] = array("id" => $id, "title" => $o, "profiles" => array(),
1131  "base_skill" => $idarr[0], "tref_id" => $idarr[1]);
1132  }
1133 //var_dump($opts);
1134 
1135  // get matching user competence profiles
1136  // -> add gap analysis to profile
1137  include_once("./Services/Skill/classes/class.ilSkillProfile.php");
1139  foreach ($profiles as $p)
1140  {
1141  $prof = new ilSkillProfile($p["id"]);
1142  $prof_levels = $prof->getSkillLevels();
1143  foreach ($prof_levels as $pl)
1144  {
1145  if (isset($skills[$pl["base_skill_id"].":".$pl["tref_id"]]))
1146  {
1147  $skills[$pl["base_skill_id"].":".$pl["tref_id"]]["profiles"][] =
1148  $p["id"];
1149 
1150  $eval_modes["gap_".$p["id"]] =
1151  $lng->txt("svy_gap_analysis").": ".$prof->getTitle();
1152  }
1153  }
1154  }
1155 //var_dump($skills);
1156 //var_dump($eval_modes);
1157 
1158  // if one competence does not match any profiles
1159  // -> add "competences of survey" alternative
1160  reset($skills);
1161  foreach ($skills as $sk)
1162  {
1163  if (count($sk["profiles"]) == 0)
1164  {
1165  $eval_modes["skills_of_survey"] = $lng->txt("svy_all_survey_competences");
1166  }
1167  }
1168 
1169  // final determination of current evaluation mode
1170  $comp_eval_mode = $_GET["comp_eval_mode"];
1171  if ($_POST["comp_eval_mode"] != "")
1172  {
1173  $comp_eval_mode = $_POST["comp_eval_mode"];
1174  }
1175 
1176  if (!isset($eval_modes[$comp_eval_mode]))
1177  {
1178  reset($eval_modes);
1179  $comp_eval_mode = key($eval_modes);
1180  $ilCtrl->setParameter($this, "comp_eval_mode", $comp_eval_mode);
1181  }
1182 
1183  $ilCtrl->saveParameter($this, "comp_eval_mode");
1184 
1185  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
1186  $mode_sel = new ilSelectInputGUI($lng->txt("svy_analysis"), "comp_eval_mode");
1187  $mode_sel->setOptions($eval_modes);
1188  $mode_sel->setValue($comp_eval_mode);
1189  $ilToolbar->addInputItem($mode_sel, true);
1190 
1191  $ilToolbar->addFormButton($lng->txt("select"), "competenceEval");
1192 
1193  if (substr($comp_eval_mode, 0, 4) == "gap_")
1194  {
1195  // gap analysis
1196  $profile_id = (int) substr($comp_eval_mode, 4);
1197 
1198  include_once("./Services/Skill/classes/class.ilPersonalSkillsGUI.php");
1199  $pskills_gui = new ilPersonalSkillsGUI();
1200  $pskills_gui->setProfileId($profile_id);
1201  $pskills_gui->setGapAnalysisActualStatusModePerObject($survey->getId(), $lng->txt("survey_360_raters"));
1202  if ($survey->getFinishedIdForAppraiseeIdAndRaterId($appr_id, $appr_id) > 0)
1203  {
1204  $sskill = new ilSurveySkill($survey);
1205  $self_levels = array();
1206  foreach ($sskill->determineSkillLevelsForAppraisee($appr_id, true) as $sl)
1207  {
1208  $self_levels[$sl["base_skill_id"]][$sl["tref_id"]] = $sl["new_level_id"];
1209  }
1210  $pskills_gui->setGapAnalysisSelfEvalLevels($self_levels);
1211  }
1212  $html = $pskills_gui->getGapAnalysisHTML($appr_id);
1213 
1214  $tpl->setContent($html);
1215  }
1216  else // must be all survey competences
1217  {
1218  include_once("./Services/Skill/classes/class.ilPersonalSkillsGUI.php");
1219  $pskills_gui = new ilPersonalSkillsGUI();
1220  $pskills_gui->setGapAnalysisActualStatusModePerObject($survey->getId(), $lng->txt("survey_360_raters"));
1221  if ($survey->getFinishedIdForAppraiseeIdAndRaterId($appr_id, $appr_id) > 0)
1222  {
1223  $sskill = new ilSurveySkill($survey);
1224  $self_levels = array();
1225  foreach ($sskill->determineSkillLevelsForAppraisee($appr_id, true) as $sl)
1226  {
1227  $self_levels[$sl["base_skill_id"]][$sl["tref_id"]] = $sl["new_level_id"];
1228  }
1229  $pskills_gui->setGapAnalysisSelfEvalLevels($self_levels);
1230  }
1231  $sk = array();
1232  foreach ($skills as $skill)
1233  {
1234  $sk[] = array(
1235  "base_skill_id" => (int) $skill["base_skill"],
1236  "tref_id" => (int) $skill["tref_id"]
1237  );
1238  }
1239  $html = $pskills_gui->getGapAnalysisHTML($appr_id, $sk);
1240 
1241  $tpl->setContent($html);
1242  }
1243 
1244  }
1245 }
1246 
1247 ?>