ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjSurveyGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
41 include_once "./classes/class.ilObjectGUI.php";
42 include_once "./Modules/Survey/classes/inc.SurveyConstants.php";
43 
45 {
50  function ilObjSurveyGUI()
51  {
52  global $lng, $ilCtrl;
53 
54  $this->type = "svy";
55  $lng->loadLanguageModule("survey");
56  $this->ctrl =& $ilCtrl;
57  $this->ctrl->saveParameter($this, "ref_id", "pgov", "pgov_pos");
58 
59  $this->ilObjectGUI("",$_GET["ref_id"], true, false);
60  }
61 
63  {
64  include_once "./Services/Utilities/classes/class.ilUtil.php";
65  $path = $this->tree->getPathFull($this->object->getRefID());
66  ilUtil::redirect($this->getReturnLocation("cancel","./repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
67  }
68 
72  function executeCommand()
73  {
74  global $ilAccess, $ilNavigationHistory,$ilCtrl;
75 
76  if ((!$ilAccess->checkAccess("read", "", $_GET["ref_id"])) && (!$ilAccess->checkAccess("visible", "", $_GET["ref_id"])))
77  {
78  global $ilias;
79  $ilias->raiseError($this->lng->txt("permission_denied"), $ilias->error_obj->MESSAGE);
80  }
81  // add entry to navigation history
82  if (!$this->getCreationMode() &&
83  $ilAccess->checkAccess("read", "", $_GET["ref_id"]))
84  {
85  $ilNavigationHistory->addItem($_GET["ref_id"],
86  "ilias.php?baseClass=ilObjSurveyGUI&cmd=infoScreen&ref_id=".$_GET["ref_id"], "svy");
87  }
88 
89  $cmd = $this->ctrl->getCmd("properties");
90 
91  // workaround for bug #6288, needs better solution
92  if ($cmd == "saveTags")
93  {
94  $ilCtrl->setCmdClass("ilinfoscreengui");
95  }
96 
97  // deep link from repository - "redirect" to page view
98  if(!$this->ctrl->getCmdClass() && $cmd == "questionsrepo")
99  {
100  $_REQUEST["pgov"] = 1;
101  $cmd = "questions";
102  $ilCtrl->setCmd($cmd);
103  }
104 
105  // return to questions in page view mode
106  if(in_array($cmd, array("cancelRemoveQuestions", "questions", "confirmRemoveQuestions",
107  "cancelDeleteAllUserData", "confirmDeleteAllUserData", "cancelCreateQuestion",
108  "cancelHeading", "cancelRemoveHeading", "confirmRemoveHeading", "cancelRemoveQuestions",
109  "cancelDefineQuestionblock"))
110  && $_REQUEST["pgov"])
111  {
112  $ilCtrl->setCmdClass("ilsurveypagegui");
113  if(!in_array($cmd, array("confirmRemoveQuestions", "confirmDeleteAllUserData",
114  "confirmRemoveHeading")))
115  {
116  $ilCtrl->setCmd("renderPage");
117  }
118  }
119 
120  $next_class = $this->ctrl->getNextClass($this);
121  $this->ctrl->setReturn($this, "properties");
122  $this->tpl->addCss(ilUtil::getStyleSheetLocation("output", "survey.css", "Modules/Survey"), "screen");
123  $this->prepareOutput();
124  //echo "<br>nextclass:$next_class:cmd:$cmd:qtype=$q_type";
125  switch($next_class)
126  {
127  case "ilinfoscreengui":
128  $this->addHeaderAction();
129  $this->infoScreen(); // forwards command
130  break;
131 
132  case 'ilmdeditorgui':
133  $this->addHeaderAction();
134  include_once 'Services/MetaData/classes/class.ilMDEditorGUI.php';
135  $md_gui =& new ilMDEditorGUI($this->object->getId(), 0, $this->object->getType());
136  $md_gui->addObserver($this->object,'MDUpdateListener','General');
137 
138  $this->ctrl->forwardCommand($md_gui);
139  break;
140 
141  case "ilsurveyevaluationgui":
142  $this->addHeaderAction();
143  include_once("./Modules/Survey/classes/class.ilSurveyEvaluationGUI.php");
144  $eval_gui = new ilSurveyEvaluationGUI($this->object);
145  $ret =& $this->ctrl->forwardCommand($eval_gui);
146  break;
147 
148  case 'ilrepositorysearchgui':
149  include_once('./Services/Search/classes/class.ilRepositorySearchGUI.php');
150  $rep_search =& new ilRepositorySearchGUI();
151  $rep_search->setCallback($this,
152  'inviteUserGroupObject',
153  array(
154  )
155  );
156 
157  // Set tabs
158  $this->ctrl->setReturn($this, 'invite');
159  $ret =& $this->ctrl->forwardCommand($rep_search);
160  $this->tabs_gui->setTabActive('invitation');
161  break;
162 
163  case "ilsurveyexecutiongui":
164  include_once("./Modules/Survey/classes/class.ilSurveyExecutionGUI.php");
165  $exec_gui = new ilSurveyExecutionGUI($this->object);
166  $ret =& $this->ctrl->forwardCommand($exec_gui);
167  break;
168 
169  case 'ilpermissiongui':
170  $this->addHeaderAction();
171  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
172  $perm_gui =& new ilPermissionGUI($this);
173  $ret =& $this->ctrl->forwardCommand($perm_gui);
174  break;
175 
176  case 'ilobjectcopygui':
177  include_once './Services/Object/classes/class.ilObjectCopyGUI.php';
178  $cp = new ilObjectCopyGUI($this);
179  $cp->setType('svy');
180  $this->ctrl->forwardCommand($cp);
181  break;
182 
183  case 'ilsurveypagegui':
184  $this->addHeaderAction();
185  include_once './Modules/Survey/classes/class.ilSurveyPageGUI.php';
186  $pg = new ilSurveyPageGUI($this);
187  $this->ctrl->forwardCommand($pg);
188  break;
189 
190  case "ilcommonactiondispatchergui":
191  include_once("Services/Object/classes/class.ilCommonActionDispatcherGUI.php");
193  $this->ctrl->forwardCommand($gui);
194  break;
195 
196  default:
197  $this->addHeaderAction();
198  $cmd.= "Object";
199  $ret =& $this->$cmd();
200  break;
201  }
202 
203  if (strtolower($_GET["baseClass"]) != "iladministrationgui" &&
204  $this->getCreationMode() != true)
205  {
206  $this->tpl->show();
207  }
208  }
209 
210  protected function addDidacticTemplateOptions(array &$a_options)
211  {
212  include_once "Services/Administration/classes/class.ilSettingsTemplate.php";
214  if($templates)
215  {
216  foreach($templates as $item)
217  {
218  $a_options["svytpl_".$item["id"]] = array($item["title"],
219  nl2br(trim($item["description"])));
220  }
221  }
222  }
223 
228  function afterSave(ilObject $a_new_object)
229  {
230  $tpl = $this->getDidacticTemplateVar("svytpl");
231  if($tpl)
232  {
233  $a_new_object->applySettingsTemplate($tpl);
234  }
235 
236  // always send a message
237  ilUtil::sendSuccess($this->lng->txt("object_added"),true);
238  ilUtil::redirect("ilias.php?baseClass=ilObjSurveyGUI&ref_id=".
239  $a_new_object->getRefId()."&cmd=properties");
240  }
241 
247  function cancelObject($in_rep = false)
248  {
249  ilUtil::redirect("repository.php?cmd=frameset&ref_id=".$_GET["ref_id"]);
250  }
251 
260  {
261  $this->ctrl->redirect($this, "properties");
262  }
263 
271  function handleWriteAccess()
272  {
273  global $ilAccess;
274  if (!$ilAccess->checkAccess("write", "", $this->ref_id))
275  {
276  // allow only write access
277  ilUtil::sendInfo($this->lng->txt("cannot_edit_survey"), TRUE);
278  $this->ctrl->redirect($this, "infoScreen");
279  }
280  }
281 
290  {
291  $form = $this->initPropertiesForm();
292  if ($form->checkInput())
293  {
294  // #10055
295  if ($_POST['online'] && count($this->object->questions) == 0)
296  {
297  $_POST['online'] = null;
298  ilUtil::sendFailure($this->lng->txt("cannot_switch_to_online_no_questions"), true);
299  }
300 
301  $template_settings = null;
302  $template = $this->object->getTemplate();
303  if($template)
304  {
305  include_once "Services/Administration/classes/class.ilSettingsTemplate.php";
306  $template = new ilSettingsTemplate($template);
307  $template_settings = $template->getSettings();
308  }
309 
310 
311  include_once 'Services/MetaData/classes/class.ilMD.php';
312  $md_obj =& new ilMD($this->object->getId(), 0, "svy");
313  $md_section = $md_obj->getGeneral();
314 
315  // title
316  $md_section->setTitle(ilUtil::stripSlashes($_POST['title']));
317  $md_section->update();
318 
319  // Description
320  $md_desc_ids = $md_section->getDescriptionIds();
321  if($md_desc_ids)
322  {
323  $md_desc = $md_section->getDescription(array_pop($md_desc_ids));
324  $md_desc->setDescription(ilUtil::stripSlashes($_POST['description']));
325  $md_desc->update();
326  }
327 
328  // both are saved in object, too
329  $this->object->setTitle(ilUtil::stripSlashes($_POST['title']));
330  $this->object->setDescription(ilUtil::stripSlashes($_POST['description']));
331  $this->object->update();
332 
333  $this->object->setStatus($_POST['online']);
334  $this->object->setEvaluationAccess($_POST["evaluation_access"]);
335 
336  if(!$template_settings["enabled_start_date"]["hide"])
337  {
338  $this->object->setStartDateEnabled($_POST["enabled_start_date"]);
339  if ($this->object->getStartDateEnabled())
340  {
341  $this->object->setStartDateAndTime($_POST["start_date"]['date'], $_POST["start_date"]['time']);
342  }
343  else
344  {
345  $this->object->setStartDate(null);
346  }
347  }
348 
349  if(!$template_settings["enabled_end_date"]["hide"])
350  {
351  $this->object->setEndDateEnabled($_POST["enabled_end_date"]);
352  if ($this->object->getEndDateEnabled())
353  {
354  $this->object->setEndDateAndTime($_POST["end_date"]['date'], $_POST["end_date"]['time']);
355  }
356  else
357  {
358  $this->object->setEndDate(null);
359  }
360  }
361 
362  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
363  $introduction = $_POST["introduction"];
364  $this->object->setIntroduction($introduction);
365  $outro = $_POST["outro"];
366  $this->object->setOutro($outro);
367 
368  $hasDatasets = $this->object->_hasDatasets($this->object->getSurveyId());
369  if (!$hasDatasets)
370  {
371  $anon_map = array('personalized' => ANONYMIZE_OFF,
372  'anonymize_with_code' => ANONYMIZE_ON,
373  'anonymize_without_code' => ANONYMIZE_FREEACCESS);
374  if(array_key_exists($_POST["anonymization_options"], $anon_map))
375  {
376  $this->object->setAnonymize($anon_map[$_POST["anonymization_options"]]);
377  if (strcmp($_POST['anonymization_options'], 'anonymize_with_code') == 0) $anonymize = ANONYMIZE_ON;
378  if (strcmp($_POST['anonymization_options'], 'anonymize_with_code_all') == 0) $anonymize = ANONYMIZE_CODE_ALL;
379  }
380  }
381 
382  if(!$template_settings["show_question_titles"]["hide"])
383  {
384  $this->object->setShowQuestionTitles($_POST["show_question_titles"]);
385  }
386 
387  if(!$template_settings["use_pool"]["hide"])
388  {
389  $this->object->setPoolUsage($_POST["use_pool"]);
390  }
391 
392  $this->object->setMailNotification($_POST['mailnotification']);
393  $this->object->setMailAddresses($_POST['mailaddresses']);
394  $this->object->setMailParticipantData($_POST['mailparticipantdata']);
395  $this->object->saveToDb();
396 
397  if (strcmp($_SESSION["info"], "") != 0)
398  {
399  ilUtil::sendSuccess($_SESSION["info"] . "<br />" . $this->lng->txt("settings_saved"), true);
400  }
401  else
402  {
403  ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
404  }
405  $this->ctrl->redirect($this, "properties");
406  }
407 
408  $form->setValuesByPost();
409  $this->propertiesObject($form);
410  }
411 
418  {
419  $template_settings = $hide_rte_switch = null;
420  $template = $this->object->getTemplate();
421  if($template)
422  {
423  include_once "Services/Administration/classes/class.ilSettingsTemplate.php";
424  $template = new ilSettingsTemplate($template);
425 
426  $template_settings = $template->getSettings();
427  $hide_rte_switch = $template_settings["rte_switch"]["hide"];
428  }
429 
430  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
431  $form = new ilPropertyFormGUI();
432  $form->setFormAction($this->ctrl->getFormAction($this));
433  $form->setTableWidth("100%");
434  $form->setId("survey_properties");
435 
436  // general properties
437  $header = new ilFormSectionHeaderGUI();
438  $header->setTitle($this->lng->txt("settings"));
439  $form->addItem($header);
440 
441  // online
442  $online = new ilCheckboxInputGUI($this->lng->txt("online"), "online");
443  $online->setValue(1);
444  $online->setChecked($this->object->isOnline());
445  $form->addItem($online);
446 
447 
448  // title & description (meta data)
449 
450  include_once 'Services/MetaData/classes/class.ilMD.php';
451  $md_obj = new ilMD($this->object->getId(), 0, "svy");
452  $md_section = $md_obj->getGeneral();
453 
454  $title = new ilTextInputGUI($this->lng->txt("title"), "title");
455  $title->setRequired(true);
456  $title->setValue($md_section->getTitle());
457  $form->addItem($title);
458 
459  $ids = $md_section->getDescriptionIds();
460  if($ids)
461  {
462  $desc_obj = $md_section->getDescription(array_pop($ids));
463 
464  $desc = new ilTextAreaInputGUI($this->lng->txt("description"), "description");
465  $desc->setCols(50);
466  $desc->setRows(4);
467  $desc->setValue($desc_obj->getDescription());
468  $form->addItem($desc);
469  }
470 
471  // pool usage
472  $pool_usage = new ilCheckboxInputGUI($this->lng->txt("survey_question_pool_usage"), "use_pool");
473  $pool_usage->setValue(1);
474  $pool_usage->setChecked($this->object->getPoolUsage());
475  $form->addItem($pool_usage);
476 
477  if(!$template_settings["anonymization_options"]["hide"] ||
478  !$template_settings["enabled_start_date"]["hide"] ||
479  !$template_settings["enabled_end_date"]["hide"])
480  {
481  // access properties
482  $acc = new ilFormSectionHeaderGUI();
483  $acc->setTitle($this->lng->txt("access"));
484  $form->addItem($acc);
485  }
486 
487  // anonymization
488  $anonymization_options = new ilRadioGroupInputGUI($this->lng->txt("survey_auth_mode"), "anonymization_options");
489  $hasDatasets = $this->object->_hasDatasets($this->object->getSurveyId());
490  if ($hasDatasets)
491  {
492  $anonymization_options->setDisabled(true);
493  }
494  $anonymization_options->addOption(new ilCheckboxOption($this->lng->txt("anonymize_personalized"),
495  'personalized', ''));
496  $anonymization_options->addOption(new ilCheckboxOption(
497  $this->lng->txt("anonymize_without_code"), 'anonymize_without_code', ''));
498  $anonymization_options->addOption(new ilCheckboxOption(
499  $this->lng->txt("anonymize_with_code"), 'anonymize_with_code', ''));
500  if(!$this->object->getAnonymize())
501  {
502  $anonymization_options->setValue('personalized');
503  }
504  else
505  {
506  $anonymization_options->setValue(($this->object->isAccessibleWithoutCode()) ?
507  'anonymize_without_code' : 'anonymize_with_code');
508  }
509  $anonymization_options->setInfo($this->lng->txt("anonymize_survey_description"));
510  $form->addItem($anonymization_options);
511 
512  // enable start date
513  $enablestartingtime = new ilCheckboxInputGUI($this->lng->txt("start_date"), "enabled_start_date");
514  $enablestartingtime->setValue(1);
515  // $enablestartingtime->setOptionTitle($this->lng->txt("enabled"));
516  $enablestartingtime->setChecked($this->object->getStartDateEnabled());
517  // start date
518  $startingtime = new ilDateTimeInputGUI('', 'start_date');
519  $startingtime->setShowDate(true);
520  $startingtime->setShowTime(true);
521  if ($this->object->getStartDateEnabled())
522  {
523  $startingtime->setDate(new ilDate($this->object->getStartDate(), IL_CAL_DATE));
524  }
525  else
526  {
527  $startingtime->setDate(new ilDate(time(), IL_CAL_UNIX));
528  }
529  $enablestartingtime->addSubItem($startingtime);
530  $form->addItem($enablestartingtime);
531 
532  // enable end date
533  $enableendingtime = new ilCheckboxInputGUI($this->lng->txt("end_date"), "enabled_end_date");
534  $enableendingtime->setValue(1);
535  // $enableendingtime->setOptionTitle($this->lng->txt("enabled"));
536  $enableendingtime->setChecked($this->object->getEndDateEnabled());
537  // end date
538  $endingtime = new ilDateTimeInputGUI('', 'end_date');
539  $endingtime->setShowDate(true);
540  $endingtime->setShowTime(true);
541  if ($this->object->getEndDateEnabled())
542  {
543  $endingtime->setDate(new ilDate($this->object->getEndDate(), IL_CAL_DATE));
544  }
545  else
546  {
547  $endingtime->setDate(new ilDate(time(), IL_CAL_UNIX));
548  }
549  $enableendingtime->addSubItem($endingtime);
550  $form->addItem($enableendingtime);
551 
552 
553  // presentation properties
554  $info = new ilFormSectionHeaderGUI();
555  $info->setTitle($this->lng->txt("svy_presentation_properties"));
556  $form->addItem($info);
557 
558  // show question titles
559  $show_question_titles = new ilCheckboxInputGUI($this->lng->txt("svy_show_questiontitles"), "show_question_titles");
560  $show_question_titles->setValue(1);
561  $show_question_titles->setChecked($this->object->getShowQuestionTitles());
562  $form->addItem($show_question_titles);
563 
564  // introduction
565  $intro = new ilTextAreaInputGUI($this->lng->txt("introduction"), "introduction");
566  $intro->setValue($this->object->prepareTextareaOutput($this->object->getIntroduction()));
567  $intro->setRows(10);
568  $intro->setCols(80);
569  $intro->setUseRte(TRUE);
570  $intro->setInfo($this->lng->txt("survey_introduction_info"));
571  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
572  $intro->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("survey"));
573  $intro->addPlugin("latex");
574  $intro->addButton("latex");
575  $intro->addButton("pastelatex");
576  $intro->setRTESupport($this->object->getId(), "svy", "survey", null, $hide_rte_switch, "3.4.7");
577  $form->addItem($intro);
578 
579  // final statement
580  $finalstatement = new ilTextAreaInputGUI($this->lng->txt("outro"), "outro");
581  $finalstatement->setValue($this->object->prepareTextareaOutput($this->object->getOutro()));
582  $finalstatement->setRows(10);
583  $finalstatement->setCols(80);
584  $finalstatement->setUseRte(TRUE);
585  $finalstatement->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("survey"));
586  $finalstatement->addPlugin("latex");
587  $finalstatement->addButton("latex");
588  $finalstatement->addButton("pastelatex");
589  $finalstatement->setRTESupport($this->object->getId(), "svy", "survey", null, $hide_rte_switch, "3.4.7");
590  $form->addItem($finalstatement);
591 
592 
593  // results properties
595  $results->setTitle($this->lng->txt("results"));
596  $form->addItem($results);
597 
598  // evaluation access
599  $evaluation_access = new ilRadioGroupInputGUI($this->lng->txt('evaluation_access'), "evaluation_access");
600  $evaluation_access->setInfo($this->lng->txt('evaluation_access_description'));
601  $evaluation_access->addOption(new ilCheckboxOption($this->lng->txt("evaluation_access_off"), EVALUATION_ACCESS_OFF, ''));
602  $evaluation_access->addOption(new ilCheckboxOption($this->lng->txt("evaluation_access_all"), EVALUATION_ACCESS_ALL, ''));
603  $evaluation_access->addOption(new ilCheckboxOption($this->lng->txt("evaluation_access_participants"), EVALUATION_ACCESS_PARTICIPANTS, ''));
604  $evaluation_access->setValue($this->object->getEvaluationAccess());
605  $form->addItem($evaluation_access);
606 
607  // mail notification
608  $mailnotification = new ilCheckboxInputGUI($this->lng->txt("mailnotification"), "mailnotification");
609  // $mailnotification->setOptionTitle($this->lng->txt("activate"));
610  $mailnotification->setValue(1);
611  $mailnotification->setChecked($this->object->getMailNotification());
612 
613  // addresses
614  $mailaddresses = new ilTextInputGUI($this->lng->txt("mailaddresses"), "mailaddresses");
615  $mailaddresses->setValue($this->object->getMailAddresses());
616  $mailaddresses->setSize(80);
617  $mailaddresses->setInfo($this->lng->txt('mailaddresses_info'));
618  $mailaddresses->setRequired(true);
619 
620  // participant data
621  $participantdata = new ilTextAreaInputGUI($this->lng->txt("mailparticipantdata"), "mailparticipantdata");
622  $participantdata->setValue($this->object->getMailParticipantData());
623  $participantdata->setRows(6);
624  $participantdata->setCols(80);
625  $participantdata->setUseRte(false);
626  $participantdata->setInfo($this->lng->txt('mailparticipantdata_info'));
627 
628  // #12755 - because of privacy concerns we restrict user data to a minimum
629  $placeholders = array(
630  "FIRST_NAME" => "firstname",
631  "LAST_NAME" => "lastname",
632  "LOGIN" => "login"
633  );
634  $txt = array($this->lng->txt("mailparticipantdata_placeholder"));
635  foreach($placeholders as $placeholder => $caption)
636  {
637  $txt[] = "[".strtoupper($placeholder)."]: ".$this->lng->txt($caption);
638  }
639  $txt = implode("<br />", $txt);
640  $participantdatainfo = new ilNonEditableValueGUI("", "", true);
641  $participantdatainfo->setValue($txt);
642 
643  $mailnotification->addSubItem($mailaddresses);
644  $mailnotification->addSubItem($participantdata);
645  $mailnotification->addSubItem($participantdatainfo);
646  $form->addItem($mailnotification);
647 
648  $form->addCommandButton("saveProperties", $this->lng->txt("save"));
649 
650  // remove items when using template
651  if($template_settings)
652  {
653  foreach($template_settings as $id => $item)
654  {
655  if($item["hide"])
656  {
657  $form->removeItemByPostVar($id);
658  }
659  }
660  }
661 
662  return $form;
663  }
664 
670  function propertiesObject(ilPropertyFormGUI $a_form = null)
671  {
672  global $ilAccess;
673 
674  if (!$ilAccess->checkAccess("write", "", $_GET["ref_id"]))
675  {
676  $this->ctrl->redirect($this, "");
677  }
678 
679  if(!$a_form)
680  {
681  $a_form = $this->initPropertiesForm();
682  }
683 
684  // using template?
685  $message = "";
686  if($this->object->getTemplate())
687  {
688  $link = $this->ctrl->getLinkTarget($this, "confirmResetTemplate");
689  $link = "<a href=\"".$link."\">".$this->lng->txt("survey_using_template_link")."</a>";
690  $message = "<div style=\"margin-top:10px\">".
691  $tpl->getMessageHTML(sprintf($this->lng->txt("survey_using_template"),
692  ilSettingsTemplate::lookupTitle($this->object->getTemplate()), $link), "info"). // #10651
693  "</div>";
694  }
695 
696  $this->tpl->setContent($a_form->getHTML().$message);
697  }
698 
707  {
708  $items = $this->gatherSelectedTableItems(true, true, true, true);
709  if (count($items["blocks"]) + count($items["questions"]) + count($items["headings"]) > 0)
710  {
711  ilUtil::sendQuestion($this->lng->txt("remove_questions"));
712  $this->removeQuestionsForm($items["blocks"], $items["questions"], $items["headings"]);
713  return;
714  }
715  else
716  {
717  ilUtil::sendInfo($this->lng->txt("no_question_selected_for_removal"), true);
718  $this->ctrl->redirect($this, "questions");
719  }
720  }
721 
725  public function insertQuestionsObject()
726  {
727  $inserted_objects = 0;
728  if (is_array($_POST['q_id']))
729  {
730  if($_REQUEST["pgov"])
731  {
732  include_once "Modules/Survey/classes/class.ilSurveyPageGUI.php";
733  $page_gui = new ilSurveyPageGUI($this);
734  $page_gui->determineCurrentPage();
735 
736  // as target position is predefined, insert in reverse order
737  $_POST['q_id'] = array_reverse($_POST['q_id']);
738  }
739  foreach ($_POST['q_id'] as $question_id)
740  {
741  if(!$_REQUEST["pgov"])
742  {
743  $this->object->insertQuestion($question_id);
744  }
745  else
746  {
747  // target position (pgov pos) is processed there
748  $page_gui->insertNewQuestion($question_id);
749  }
750  $inserted_objects++;
751  }
752  }
753  if ($inserted_objects)
754  {
755  $this->object->saveCompletionStatus();
756  ilUtil::sendSuccess($this->lng->txt("questions_inserted"), true);
757  if(!$_REQUEST["pgov"])
758  {
759  $this->ctrl->redirect($this, "questions");
760  }
761  else
762  {
763  $target_page = $_REQUEST["pgov"];
764  if(substr($_REQUEST["pgov_pos"], -1) == "c")
765  {
766  // see ilSurveyPageGUI::insertNewQuestion()
767  if((int)$_REQUEST["pgov_pos"])
768  {
769  $target_page++;
770  }
771  else
772  {
773  $target_page = 1;
774  }
775  }
776  $this->ctrl->setParameterByClass("ilsurveypagegui", "pgov", $target_page);
777  $this->ctrl->redirectByClass("ilsurveypagegui", "renderpage");
778  }
779  }
780  else
781  {
782  ilUtil::sendInfo($this->lng->txt("insert_missing_question"), true);
783  $this->ctrl->setParameter($this, "pgov", $_REQUEST["pgov"]);
784  $this->ctrl->setParameter($this, "pgov_pos", $_REQUEST["pgov_pos"]);
785  $this->ctrl->redirect($this, 'browseForQuestions');
786  }
787  }
788 
792  public function insertQuestionblocksObject()
793  {
794  $inserted_objects = 0;
795  if (is_array($_POST['cb']))
796  {
797  if($_REQUEST["pgov"])
798  {
799  include_once "Modules/Survey/classes/class.ilSurveyPageGUI.php";
800  $page_gui = new ilSurveyPageGUI($this);
801  $page_gui->determineCurrentPage();
802 
803  // as target position is predefined, insert in reverse order
804  $_POST['cb'] = array_reverse($_POST['cb']);
805  }
806  foreach ($_POST['cb'] as $questionblock_id)
807  {
808  if(!$_REQUEST["pgov"])
809  {
810  $this->object->insertQuestionblock($questionblock_id);
811  }
812  else
813  {
814  $page_gui->insertQuestionblock($questionblock_id);
815  }
816  $inserted_objects++;
817  }
818  }
819  if ($inserted_objects)
820  {
821  $this->object->saveCompletionStatus();
822  ilUtil::sendSuccess(($inserted_objects == 1) ? $this->lng->txt("questionblock_inserted") : $this->lng->txt("questionblocks_inserted"), true);
823  if(!$_REQUEST["pgov"])
824  {
825  $this->ctrl->redirect($this, "questions");
826  }
827  else
828  {
829  $target_page = $_REQUEST["pgov"];
830  if(substr($_REQUEST["pgov_pos"], -1) == "c")
831  {
832  $target_page++;
833  }
834  $this->ctrl->setParameterByClass("ilsurveypagegui", "pgov", $target_page);
835  $this->ctrl->redirectByClass("ilsurveypagegui", "renderpage");
836  }
837  }
838  else
839  {
840  ilUtil::sendInfo($this->lng->txt("insert_missing_questionblock"), true);
841  $this->ctrl->setParameter($this, "pgov", $_REQUEST["pgov"]);
842  $this->ctrl->setParameter($this, "pgov_pos", $_REQUEST["pgov_pos"]);
843  $this->ctrl->redirect($this, 'browseForQuestionblocks');
844  }
845  }
846 
850  public function changeDatatypeObject()
851  {
852  global $ilUser;
853  $ilUser->writePref('svy_insert_type', $_POST['datatype']);
854  $this->ctrl->setParameter($this, "pgov", $_REQUEST["pgov"]);
855  $this->ctrl->setParameter($this, "pgov_pos", $_REQUEST["pgov_pos"]);
856  switch ($_POST["datatype"])
857  {
858  case 0:
859  $this->ctrl->redirect($this, 'browseForQuestionblocks');
860  break;
861  case 1:
862  default:
863  $this->ctrl->redirect($this, 'browseForQuestions');
864  break;
865  }
866  }
867 
872  {
873  include_once "./Modules/Survey/classes/tables/class.ilSurveyQuestionblockbrowserTableGUI.php";
874  $table_gui = new ilSurveyQuestionblockbrowserTableGUI($this, 'browseForQuestionblocks');
875  $table_gui->writeFilterToSession();
876  $this->ctrl->setParameter($this, "pgov", $_REQUEST["pgov"]);
877  $this->ctrl->setParameter($this, "pgov_pos", $_REQUEST["pgov_pos"]);
878  $this->ctrl->redirect($this, 'browseForQuestionblocks');
879  }
880 
885  {
886  include_once "./Modules/Survey/classes/tables/class.ilSurveyQuestionblockbrowserTableGUI.php";
887  $table_gui = new ilSurveyQuestionblockbrowserTableGUI($this, 'browseForQuestionblocks');
888  $table_gui->resetFilter();
889  $this->ctrl->setParameter($this, "pgov", $_REQUEST["pgov"]);
890  $this->ctrl->setParameter($this, "pgov_pos", $_REQUEST["pgov_pos"]);
891  $this->ctrl->redirect($this, 'browseForQuestionblocks');
892  }
893 
897  public function browseForQuestionblocksObject($arrFilter = null)
898  {
899  global $rbacsystem;
900  global $ilUser;
901 
902  $this->ctrl->setParameter($this, "pgov", $_REQUEST["pgov"]);
903  $this->ctrl->setParameter($this, "pgov_pos", $_REQUEST["pgov_pos"]);
904 
906  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_questionbrowser.html", "Modules/Survey");
907  include_once "./Modules/Survey/classes/tables/class.ilSurveyQuestionblockbrowserTableGUI.php";
908  $table_gui = new ilSurveyQuestionblockbrowserTableGUI($this, 'browseForQuestionblocks', (($rbacsystem->checkAccess('write', $_GET['ref_id']) ? true : false)));
909  $table_gui->setEditable($rbacsystem->checkAccess('write', $_GET['ref_id']));
910  $arrFilter = array();
911  foreach ($table_gui->getFilterItems() as $item)
912  {
913  if ($item->getValue() !== false)
914  {
915  $arrFilter[$item->getPostVar()] = $item->getValue();
916  }
917  }
918  $data = $this->object->getQuestionblocksTable($arrFilter);
919  $table_gui->setData($data);
920  $this->tpl->setVariable('TABLE', $table_gui->getHTML());
921 
922  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, 'changeDatatype'));
923  $this->tpl->setVariable("OPTION_QUESTIONS", $this->lng->txt("questions"));
924  $this->tpl->setVariable("OPTION_QUESTIONBLOCKS", $this->lng->txt("questionblocks"));
925  $this->tpl->setVariable("SELECTED_QUESTIONBLOCKS", " selected=\"selected\"");
926  $this->tpl->setVariable("TEXT_DATATYPE", $this->lng->txt("display_all_available"));
927  $this->tpl->setVariable("BTN_CHANGE", $this->lng->txt("change"));
928  }
929 
933  public function filterQuestionBrowserObject()
934  {
935  include_once "./Modules/Survey/classes/tables/class.ilSurveyQuestionbrowserTableGUI.php";
936  $table_gui = new ilSurveyQuestionbrowserTableGUI($this, 'browseForQuestions');
937  $table_gui->writeFilterToSession();
938  $this->ctrl->setParameter($this, "pgov", $_REQUEST["pgov"]);
939  $this->ctrl->setParameter($this, "pgov_pos", $_REQUEST["pgov_pos"]);
940  $this->ctrl->redirect($this, 'browseForQuestions');
941  }
942 
947  {
948  include_once "./Modules/Survey/classes/tables/class.ilSurveyQuestionbrowserTableGUI.php";
949  $table_gui = new ilSurveyQuestionbrowserTableGUI($this, 'browseForQuestions');
950  $table_gui->resetFilter();
951  $this->ctrl->setParameter($this, "pgov", $_REQUEST["pgov"]);
952  $this->ctrl->setParameter($this, "pgov_pos", $_REQUEST["pgov_pos"]);
953  $this->ctrl->redirect($this, 'browseForQuestions');
954  }
955 
959  public function browseForQuestionsObject($arrFilter = null)
960  {
961  global $rbacsystem;
962  global $ilUser;
963 
964  $this->ctrl->setParameter($this, "pgov", $_REQUEST["pgov"]);
965  $this->ctrl->setParameter($this, "pgov_pos", $_REQUEST["pgov_pos"]);
966 
968  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_questionbrowser.html", "Modules/Survey");
969  include_once "./Modules/Survey/classes/tables/class.ilSurveyQuestionbrowserTableGUI.php";
970  $table_gui = new ilSurveyQuestionbrowserTableGUI($this, 'browseForQuestions', (($rbacsystem->checkAccess('write', $_GET['ref_id']) ? true : false)));
971  $table_gui->setEditable($rbacsystem->checkAccess('write', $_GET['ref_id']));
972  $arrFilter = array();
973  foreach ($table_gui->getFilterItems() as $item)
974  {
975  if ($item->getValue() !== false)
976  {
977  $arrFilter[$item->getPostVar()] = $item->getValue();
978  }
979  }
980  $data = $this->object->getQuestionsTable($arrFilter);
981 
982  // translate pools for proper sorting
983  if(sizeof($data))
984  {
985  $pools = $table_gui->getQuestionPools();
986  foreach($data as $idx => $row)
987  {
988  $data[$idx]["spl"] = $pools[$row["obj_fi"]];
989  }
990  }
991 
992  $table_gui->setData($data);
993  $this->tpl->setVariable('TABLE', $table_gui->getHTML());
994 
995  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, 'changeDatatype'));
996  $this->tpl->setVariable("OPTION_QUESTIONS", $this->lng->txt("questions"));
997  $this->tpl->setVariable("OPTION_QUESTIONBLOCKS", $this->lng->txt("questionblocks"));
998  $this->tpl->setVariable("SELECTED_QUESTIONS", " selected=\"selected\"");
999  $this->tpl->setVariable("TEXT_DATATYPE", $this->lng->txt("display_all_available"));
1000  $this->tpl->setVariable("BTN_CHANGE", $this->lng->txt("change"));
1001  }
1002 
1010  function removeQuestionsForm($checked_questionblocks, $checked_questions, $checked_headings)
1011  {
1012  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
1013  $cgui = new ilConfirmationGUI();
1014  $cgui->setHeaderText($this->lng->txt("survey_sure_delete_questions"));
1015 
1016  $cgui->setFormAction($this->ctrl->getFormAction($this, "confirmRemoveQuestions"));
1017  $cgui->setCancel($this->lng->txt("cancel"), "cancelRemoveQuestions");
1018  $cgui->setConfirm($this->lng->txt("confirm"), "confirmRemoveQuestions");
1019 
1020 
1021  $counter = 0;
1022  $surveyquestions =& $this->object->getSurveyQuestions();
1023  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
1024  foreach ($surveyquestions as $question_id => $data)
1025  {
1026  if (in_array($data["question_id"], $checked_questions))
1027  {
1028  $type = SurveyQuestion::_getQuestionTypeName($data["type_tag"]);
1029 
1030  $cgui->addItem("id_".$data["question_id"], $data["question_id"],
1031  $type.": ".$data["title"]);
1032  }
1033  else if((in_array($data["questionblock_id"], $checked_questionblocks)))
1034  {
1035  $type = SurveyQuestion::_getQuestionTypeName($data["type_tag"]);
1036 
1037  $cgui->addItem("id_qb_".$data["questionblock_id"], $data["questionblock_id"],
1038  $data["questionblock_title"]." - ".$type.": ".$data["title"]);
1039 
1040  /*
1041  $data["description"]
1042  ;
1043  */
1044  }
1045  else if (in_array($data["question_id"], $checked_headings))
1046  {
1047  $cgui->addItem("id_tb_".$data["question_id"], $data["question_id"],
1048  $data["heading"]);
1049  }
1050  }
1051 
1052  $this->tpl->setContent($cgui->getHTML());
1053  }
1054 
1055 
1062  function defineQuestionblock($questionblock_id = "", $question_ids = null)
1063  {
1064  $this->questionsSubtabs("questions");
1065  if ($questionblock_id)
1066  {
1067  $questionblock = $this->object->getQuestionblock($questionblock_id);
1068  }
1069 
1070  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1071  $form = new ilPropertyFormGUI();
1072  $form->setFormAction($this->ctrl->getFormAction($this, "saveDefineQuestionblock"));
1073  $form->setTableWidth("100%");
1074  $form->setId("survey_questionblock");
1075  $form->setTitle($this->lng->txt("define_questionblock"));
1076 
1077  $title = new ilTextInputGUI($this->lng->txt("title"), "title");
1078  $title->setRequired(true);
1079  if ($questionblock_id)
1080  {
1081  $title->setValue($questionblock["title"]);
1082  }
1083  $form->addItem($title);
1084 
1085  $toggle_blocktitle = new ilCheckboxInputGUI($this->lng->txt("survey_show_blocktitle"), "show_blocktitle");
1086  $toggle_blocktitle->setInfo($this->lng->txt("survey_show_blocktitle_description"));
1087  if (($questionblock["show_blocktitle"]) || (strlen($questionblock_id) == 0))
1088  {
1089  $toggle_blocktitle->setChecked(true);
1090  }
1091  $form->addItem($toggle_blocktitle);
1092 
1093  $toggle_questiontitle = new ilCheckboxInputGUI($this->lng->txt("show_questiontext"), "show_questiontext");
1094  $toggle_questiontitle->setInfo($this->lng->txt("show_questiontext_description"));
1095  if (($questionblock["show_questiontext"]) || (strlen($questionblock_id) == 0))
1096  {
1097  $toggle_questiontitle->setChecked(true);
1098  }
1099  $form->addItem($toggle_questiontitle);
1100 
1101  $form->addCommandButton("saveDefineQuestionblock", $this->lng->txt("save"));
1102  $form->addCommandButton("cancelDefineQuestionblock", $this->lng->txt("cancel"));
1103 
1104  if ($question_ids)
1105  {
1106  foreach ($question_ids as $q_id)
1107  {
1108  $hidden = new ilHiddenInputGUI("qids[]");
1109  $hidden->setValue($q_id);
1110  $form->addItem($hidden);
1111  }
1112  }
1113  if ($questionblock_id)
1114  {
1115  $hidden = new ilHiddenInputGUI("questionblock_id");
1116  $hidden->setValue($questionblock_id);
1117  $form->addItem($hidden);
1118  }
1119 
1120  $this->tpl->setContent($form->getHTML());
1121  }
1122 
1128  function createQuestionObject(ilPropertyFormGUI $a_form = null)
1129  {
1130  global $ilUser;
1131 
1132  if(!$this->object->isPoolActive())
1133  {
1134  $_POST["usage"] = 1;
1135  $_GET["sel_question_types"] = $_POST["sel_question_types"];
1136  return $this->executeCreateQuestionObject();
1137  }
1138 
1139  if(!$a_form)
1140  {
1141  if(!$_REQUEST["pgov"])
1142  {
1143  $this->questionsSubtabs("questions");
1144  }
1145  else
1146  {
1147  $this->questionsSubtabs("questions_per_page");
1148  }
1149 
1150  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
1151  $form = new ilPropertyFormGUI();
1152 
1153  $sel_question_types = (strlen($_POST["sel_question_types"])) ? $_POST["sel_question_types"] : $_GET["sel_question_types"];
1154  $this->ctrl->setParameter($this, "sel_question_types", $sel_question_types);
1155  $form->setFormAction($this->ctrl->getFormAction($this, "executeCreateQuestion"));
1156  }
1157  else
1158  {
1159  $form = $a_form;
1160  }
1161 
1162  $usage = new ilRadioGroupInputGUI($this->lng->txt("survey_pool_selection"), "usage");
1163  $usage->setRequired(true);
1164  $no_pool = new ilRadioOption($this->lng->txt("survey_no_pool"), 1);
1165  $usage->addOption($no_pool);
1166  $existing_pool = new ilRadioOption($this->lng->txt("survey_existing_pool"), 3);
1167  $usage->addOption($existing_pool);
1168  $new_pool = new ilRadioOption($this->lng->txt("survey_new_pool"), 2);
1169  $usage->addOption($new_pool);
1170  $form->addItem($usage);
1171 
1172  if(isset($_SESSION["svy_qpool_choice"]))
1173  {
1174  $usage->setValue($_SESSION["svy_qpool_choice"]);
1175  }
1176  else
1177  {
1178  // default: no pool
1179  $usage->setValue(1);
1180  }
1181 
1182  $questionpools =& $this->object->getAvailableQuestionpools(FALSE, TRUE, TRUE, "write");
1183  $pools = new ilSelectInputGUI($this->lng->txt("select_questionpool"), "sel_spl");
1184  $pools->setOptions($questionpools);
1185  $existing_pool->addSubItem($pools);
1186 
1187  $name = new ilTextInputGUI($this->lng->txt("cat_create_spl"), "name_spl");
1188  $name->setSize(50);
1189  $name->setMaxLength(50);
1190  $new_pool->addSubItem($name);
1191 
1192  if($a_form)
1193  {
1194  return $a_form;
1195  }
1196 
1197  $form->addCommandButton("executeCreateQuestion", $this->lng->txt("submit"));
1198  $form->addCommandButton("cancelCreateQuestion", $this->lng->txt("cancel"));
1199 
1200  return $this->tpl->setContent($form->getHTML());
1201  }
1202 
1209  {
1210  $this->ctrl->redirect($this, "questions");
1211  }
1212 
1219  {
1220  $addurl = "";
1221  if($_REQUEST["pgov"])
1222  {
1223  $addurl .= "&pgov=".$_REQUEST["pgov"]."&pgov_pos=".$_REQUEST["pgov_pos"];
1224  }
1225 
1226  include_once "./Services/Utilities/classes/class.ilUtil.php";
1227 
1228  $_SESSION["svy_qpool_choice"] = $_POST["usage"];
1229 
1230  // no pool
1231  if ($_POST["usage"] == 1)
1232  {
1233  ilUtil::redirect("ilias.php?baseClass=ilObjSurveyQuestionPoolGUI&ref_id=".
1234  $_GET["ref_id"]."&cmd=createQuestionForSurvey&new_for_survey=".
1235  $_GET["ref_id"]."&sel_question_types=".$_GET["sel_question_types"].$addurl);
1236  }
1237  // existing pool
1238  else if ($_POST["usage"] == 3 && strlen($_POST["sel_spl"]))
1239  {
1240  ilUtil::redirect("ilias.php?baseClass=ilObjSurveyQuestionPoolGUI&ref_id=".
1241  $_POST["sel_spl"]."&cmd=createQuestionForSurvey&new_for_survey=".$_GET["ref_id"].
1242  "&sel_question_types=".$_GET["sel_question_types"].$addurl);
1243  }
1244  // new pool
1245  elseif ($_POST["usage"] == 2 && strlen($_POST["name_spl"]))
1246  {
1247  $ref_id = $this->createQuestionPool($_POST["name_spl"]);
1248  ilUtil::redirect("ilias.php?baseClass=ilObjSurveyQuestionPoolGUI&ref_id=".$ref_id.
1249  "&cmd=createQuestionForSurvey&new_for_survey=".$_GET["ref_id"].
1250  "&sel_question_types=".$_GET["sel_question_types"].$addurl);
1251  }
1252  else
1253  {
1254  if(!$_POST["usage"])
1255  {
1256  ilUtil::sendFailure($this->lng->txt("select_one"), true);
1257  }
1258  else
1259  {
1260  ilUtil::sendFailure($this->lng->txt("err_no_pool_name"), true);
1261  }
1262  $this->ctrl->setParameter($this, "sel_question_types", $_GET["sel_question_types"]);
1263  $this->ctrl->redirect($this, "createQuestion");
1264  }
1265  }
1266 
1273  private function createQuestionPool($name = "dummy")
1274  {
1275  global $tree;
1276  $parent_ref = $tree->getParentId($this->object->getRefId());
1277  include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
1278  $qpl = new ilObjSurveyQuestionPool();
1279  $qpl->setType("spl");
1280  $qpl->setTitle($name);
1281  $qpl->setDescription("");
1282  $qpl->create();
1283  $qpl->createReference();
1284  $qpl->putInTree($parent_ref);
1285  $qpl->setPermissions($parent_ref);
1286  $qpl->setOnline(1); // must be online to be available
1287  $qpl->saveToDb();
1288  return $qpl->getRefId();
1289  }
1290 
1297  function addHeadingObject($checkonly = false, $question_id = "")
1298  {
1299  $this->questionsSubtabs("questions");
1300 
1301  global $ilAccess;
1302 
1303  $save = (strcmp($this->ctrl->getCmd(), "saveHeading") == 0) ? TRUE : FALSE;
1304 
1305  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1306  $form = new ilPropertyFormGUI();
1307  $form->setFormAction($this->ctrl->getFormAction($this));
1308  $form->setTableWidth("100%");
1309  $form->setId("survey_heading");
1310 
1311  // general properties
1312  $header = new ilFormSectionHeaderGUI();
1313  if ($question_id)
1314  {
1315  $header->setTitle($this->lng->txt("edit_heading"));
1316  }
1317  else
1318  {
1319  $header->setTitle($this->lng->txt("add_heading"));
1320  }
1321  $form->addItem($header);
1322 
1323  $survey_questions =& $this->object->getSurveyQuestions();
1324 
1325  // heading
1326  $heading = new ilTextAreaInputGUI($this->lng->txt("heading"), "heading");
1327  $heading->setValue($this->object->prepareTextareaOutput(array_key_exists('heading', $_POST) ? $_POST['heading'] : $survey_questions[$question_id]["heading"]));
1328  $heading->setRows(10);
1329  $heading->setCols(80);
1330  $heading->setUseRte(TRUE);
1331  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
1332  $heading->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("survey"));
1333  $heading->removePlugin("ibrowser");
1334  $heading->setRTESupport($this->object->getId(), "svy", "survey", null, false, "3.4.7");
1335  $heading->setRequired(true);
1336  $form->addItem($heading);
1337 
1338  $insertbefore = new ilSelectInputGUI($this->lng->txt("insert"), "insertbefore");
1339  $options = array();
1340  foreach ($survey_questions as $key => $value)
1341  {
1342  $options[$key] = $this->lng->txt("before") . ": \"" . $value["title"] . "\"";
1343  }
1344  $insertbefore->setOptions($options);
1345  $insertbefore->setValue((array_key_exists('insertbefore', $_REQUEST)) ? $_REQUEST['insertbefore'] : $question_id);
1346  $insertbefore->setRequired(true);
1347  if ($question_id || array_key_exists('insertbefore', $_REQUEST))
1348  {
1349  $insertbefore->setDisabled(true);
1350  }
1351  $form->addItem($insertbefore);
1352 
1353  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form->addCommandButton("saveHeading", $this->lng->txt("save"));
1354  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form->addCommandButton("cancelHeading", $this->lng->txt("cancel"));
1355  $errors = false;
1356 
1357  if ($save)
1358  {
1359  $errors = !$form->checkInput();
1360  $form->setValuesByPost();
1361  if ($errors) $checkonly = false;
1362  }
1363  if (!$checkonly) $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
1364  return $errors;
1365  }
1366 
1373  {
1374  // insert questions from test after confirmation
1375  foreach ($_POST as $key => $value) {
1376  if (preg_match("/id_(\d+)/", $key, $matches)) {
1377  if ($_GET["browsetype"] == 1)
1378  {
1379  $this->object->insertQuestion($matches[1]);
1380  }
1381  else
1382  {
1383  $this->object->insertQuestionBlock($matches[1]);
1384  }
1385  }
1386  }
1387  $this->object->saveCompletionStatus();
1388  ilUtil::sendSuccess($this->lng->txt("questions_inserted"), true);
1389  $this->ctrl->redirect($this, "questions");
1390  }
1391 
1398  {
1399  $this->ctrl->redirect($this, "questions");
1400  }
1401 
1410  {
1411  $hasErrors = $this->addHeadingObject(true);
1412  if (!$hasErrors)
1413  {
1414  $insertbefore = $_POST["insertbefore"];
1415  if (!$insertbefore)
1416  {
1417  $insertbefore = $_POST["insertbefore_original"];
1418  }
1419  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
1420  $this->object->saveHeading(ilUtil::stripSlashes($_POST["heading"], TRUE, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("survey")), $insertbefore);
1421  $this->ctrl->redirect($this, "questions");
1422  }
1423  }
1424 
1433  {
1434  $this->ctrl->redirect($this, "questions");
1435  }
1436 
1445  {
1446  $this->object->saveHeading("", $_POST["removeheading"]);
1447  $this->ctrl->redirect($this, "questions");
1448  }
1449 
1458  {
1459  $this->ctrl->redirect($this, "questions");
1460  }
1461 
1470  {
1471  ilUtil::sendQuestion($this->lng->txt("confirm_remove_heading"));
1472  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_confirm_removeheading.html", "Modules/Survey");
1473  $this->tpl->setCurrentBlock("adm_content");
1474  $this->tpl->setVariable("BTN_CONFIRM_REMOVE", $this->lng->txt("confirm"));
1475  $this->tpl->setVariable("BTN_CANCEL_REMOVE", $this->lng->txt("cancel"));
1476  $this->tpl->setVariable("REMOVE_HEADING", $_GET["removeheading"]);
1477  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "confirmRemoveHeading"));
1478  $this->tpl->parseCurrentBlock();
1479  }
1480 
1489  {
1490  $checked_questions = array();
1491  $checked_questionblocks = array();
1492  $checked_headings = array();
1493  foreach ($_POST as $key => $value)
1494  {
1495  if (preg_match("/id_(\d+)/", $key, $matches))
1496  {
1497  array_push($checked_questions, $matches[1]);
1498  }
1499  if (preg_match("/id_qb_(\d+)/", $key, $matches))
1500  {
1501  array_push($checked_questionblocks, $matches[1]);
1502  }
1503  if (preg_match("/id_tb_(\d+)/", $key, $matches))
1504  {
1505  array_push($checked_headings, $matches[1]);
1506  }
1507  }
1508 
1509  if(sizeof($checked_questions) || sizeof($checked_questionblocks))
1510  {
1511  $this->object->removeQuestions($checked_questions, $checked_questionblocks);
1512  }
1513  if($checked_headings)
1514  {
1515  foreach($checked_headings as $q_id)
1516  {
1517  $this->object->saveHeading("", $q_id);
1518  }
1519  }
1520  $this->object->saveCompletionStatus();
1521  ilUtil::sendSuccess($this->lng->txt("questions_removed"), true);
1522  $this->ctrl->redirect($this, "questions");
1523  }
1524 
1533  {
1534  $this->ctrl->redirect($this, "questions");
1535  }
1536 
1546  protected function gatherSelectedTableItems($allow_blocks = true, $allow_questions = true, $allow_headings = false, $allow_questions_in_blocks = false)
1547  {
1548  $block_map = array();
1549  foreach($this->object->getSurveyQuestions() as $item)
1550  {
1551  $block_map[$item["question_id"]] = $item["questionblock_id"];
1552  }
1553 
1554  $questions = $blocks = $headings = array();
1555  if($_POST["id"])
1556  {
1557  foreach ($_POST["id"] as $key)
1558  {
1559  // questions
1560  if ($allow_questions && preg_match("/cb_(\d+)/", $key, $matches))
1561  {
1562  if(($allow_questions_in_blocks || !$block_map[$matches[1]]) &&
1563  !in_array($block_map[$matches[1]], $blocks))
1564  {
1565  array_push($questions, $matches[1]);
1566  }
1567  }
1568  // blocks
1569  if ($allow_blocks && preg_match("/cb_qb_(\d+)/", $key, $matches))
1570  {
1571  array_push($blocks, $matches[1]);
1572  }
1573  // headings
1574  if ($allow_headings && preg_match("/cb_tb_(\d+)/", $key, $matches))
1575  {
1576  array_push($headings, $matches[1]);
1577  }
1578  }
1579  }
1580 
1581  return array("questions" => $questions,
1582  "blocks" => $blocks,
1583  "headings" => $headings);
1584  }
1585 
1594  {
1595  $items = $this->gatherSelectedTableItems(false, true, false, false);
1596  if(sizeof($_POST["qids"]))
1597  {
1598  $items["questions"] = $_POST["qids"];
1599  }
1600  if (count($items["questions"]) < 2)
1601  {
1602  ilUtil::sendInfo($this->lng->txt("qpl_define_questionblock_select_missing"), true);
1603  $this->ctrl->redirect($this, "questions");
1604  }
1605  else
1606  {
1607  $this->defineQuestionblock("", $items["questions"]);
1608  return;
1609  }
1610  }
1611 
1616  {
1617  if ($_POST["title"])
1618  {
1619  $show_questiontext = ($_POST["show_questiontext"]) ? 1 : 0;
1620  $show_blocktitle = ($_POST["show_blocktitle"]) ? 1 : 0;
1621  if ($_POST["questionblock_id"])
1622  {
1623  include_once "./Services/Utilities/classes/class.ilUtil.php";
1624  $this->object->modifyQuestionblock($_POST["questionblock_id"], ilUtil::stripSlashes($_POST["title"]), $show_questiontext, $show_blocktitle);
1625  }
1626  else
1627  {
1628  include_once "./Services/Utilities/classes/class.ilUtil.php";
1629  $this->object->createQuestionblock(ilUtil::stripSlashes($_POST["title"]), $show_questiontext, $show_blocktitle, $_POST["qids"]);
1630  }
1631  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true);
1632  $this->ctrl->setParameter($this, "pgov", $_REQUEST["pgov"]);
1633  $this->ctrl->redirect($this, "questions");
1634  }
1635  else
1636  {
1637  ilUtil::sendInfo($this->lng->txt("enter_questionblock_title"));
1638  $this->defineQuestionblockObject();
1639  return;
1640  }
1641  }
1642 
1646  public function unfoldQuestionblockObject()
1647  {
1648  $items = $this->gatherSelectedTableItems(true, false, false, false);
1649  if (count($items["blocks"]))
1650  {
1651  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true);
1652  $this->object->unfoldQuestionblocks($items["blocks"]);
1653  }
1654  else
1655  {
1656  ilUtil::sendInfo($this->lng->txt("qpl_unfold_select_none"), true);
1657  }
1658  $this->ctrl->redirect($this, "questions");
1659  }
1660 
1665  {
1666  ilUtil::sendInfo($this->lng->txt('msg_cancel'), true);
1667  $this->ctrl->redirect($this, "questions");
1668  }
1669 
1673  public function moveQuestionsObject()
1674  {
1675  $items = $this->gatherSelectedTableItems(true, true, false, false);
1676 
1677  $move_questions = $items["questions"];
1678  foreach ($items["blocks"] as $block_id)
1679  {
1680  foreach ($this->object->getQuestionblockQuestionIds($block_id) as $qid)
1681  {
1682  array_push($move_questions, $qid);
1683  }
1684  }
1685  if (count($move_questions) == 0)
1686  {
1687  ilUtil::sendInfo($this->lng->txt("no_question_selected_for_move"), true);
1688  $this->ctrl->redirect($this, "questions");
1689  }
1690  else
1691  {
1692  $_SESSION["move_questions"] = $move_questions;
1693  ilUtil::sendInfo($this->lng->txt("select_target_position_for_move_question"));
1694  $this->questionsObject();
1695  }
1696  }
1697 
1701  public function insertQuestions($insert_mode)
1702  {
1703  $insert_id = null;
1704  if($_POST["id"])
1705  {
1706  $items = $this->gatherSelectedTableItems(true, true, false, false);
1707 
1708  // we are using POST id for original order
1709  while(!$insert_id && sizeof($_POST["id"]))
1710  {
1711  $target = array_shift($_POST["id"]);
1712  if (preg_match("/^cb_(\d+)$/", $target, $matches))
1713  {
1714  // questions in blocks are not allowed
1715  if(in_array($matches[1], $items["questions"]))
1716  {
1717  $insert_id = $matches[1];
1718  }
1719  }
1720  if (!$insert_id && preg_match("/^cb_qb_(\d+)$/", $target, $matches))
1721  {
1722  $ids = $this->object->getQuestionblockQuestionIds($matches[1]);
1723  if (count($ids))
1724  {
1725  if ($insert_mode == 0)
1726  {
1727  $insert_id = $ids[0];
1728  }
1729  else if ($insert_mode == 1)
1730  {
1731  $insert_id = $ids[count($ids)-1];
1732  }
1733  }
1734  }
1735  }
1736  }
1737 
1738  if(!$insert_id)
1739  {
1740  ilUtil::sendInfo($this->lng->txt("no_target_selected_for_move"), true);
1741  }
1742  else
1743  {
1744  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true);
1745  $this->object->moveQuestions($_SESSION["move_questions"], $insert_id, $insert_mode);
1746  unset($_SESSION["move_questions"]);
1747  }
1748 
1749  $this->ctrl->redirect($this, "questions");
1750  }
1751 
1756  {
1757  $this->insertQuestions(0);
1758  }
1759 
1763  public function insertQuestionsAfterObject()
1764  {
1765  $this->insertQuestions(1);
1766  }
1767 
1771  public function saveObligatoryObject()
1772  {
1773  if(isset($_POST["order"]))
1774  {
1775  $position = -1;
1776  $order = array();
1777  asort($_POST["order"]);
1778  foreach(array_keys($_POST["order"]) as $id)
1779  {
1780  // block items
1781  if(substr($id, 0, 3) == "qb_")
1782  {
1783  $block_id = substr($id, 3);
1784  $block = $_POST["block_order"][$block_id];
1785  asort($block);
1786  foreach(array_keys($block) as $question_id)
1787  {
1788  $position++;
1789  $order[$question_id] = $position;
1790  }
1791  }
1792  else
1793  {
1794  $question_id = substr($id, 2);
1795  $position++;
1796  $order[$question_id] = $position;
1797  }
1798  }
1799  $this->object->updateOrder($order);
1800  }
1801 
1802  $obligatory = array();
1803  foreach ($_POST as $key => $value)
1804  {
1805  if (preg_match("/obligatory_(\d+)/", $key, $matches))
1806  {
1807  $obligatory[$matches[1]] = 1;
1808  }
1809  }
1810  $this->object->setObligatoryStates($obligatory);
1811  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true);
1812  $this->ctrl->redirect($this, "questions");
1813  }
1814 
1818  public function questionsObject()
1819  {
1820  global $rbacsystem, $ilToolbar, $ilUser;
1821 
1822  $this->handleWriteAccess();
1823 
1824  $hasDatasets = $this->object->_hasDatasets($this->object->getSurveyId());
1825  include_once "./Services/Utilities/classes/class.ilUtil.php";
1826  if ((!$rbacsystem->checkAccess("read", $this->ref_id)) && (!$rbacsystem->checkAccess("write", $this->ref_id)))
1827  {
1828  // allow only read and write access
1829  ilUtil::sendInfo($this->lng->txt("cannot_edit_survey"), true);
1830  $path = $this->tree->getPathFull($this->object->getRefID());
1831  ilUtil::redirect($this->getReturnLocation("cancel","./repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
1832  return;
1833  }
1834 
1835  if ($_GET["new_id"] > 0)
1836  {
1837  // add a question to the survey previous created in a questionpool
1838  $existing = $this->object->getExistingQuestions();
1839  if (!in_array($_GET["new_id"], $existing))
1840  {
1841  $inserted = $this->object->insertQuestion($_GET["new_id"]);
1842  if (!$inserted)
1843  {
1844  ilUtil::sendFailure($this->lng->txt("survey_error_insert_incomplete_question"));
1845  }
1846  }
1847  }
1848 
1849  if ($_GET["eqid"] and $_GET["eqpl"])
1850  {
1851  ilUtil::redirect("ilias.php?baseClass=ilObjSurveyQuestionPoolGUI&ref_id=" . $_GET["eqpl"] . "&cmd=editQuestionForSurvey&calling_survey=".$_GET["ref_id"]."&q_id=" . $_GET["eqid"]);
1852  }
1853 
1854 
1855  $_SESSION["calling_survey"] = $this->object->getRefId();
1856  unset($_SESSION["survey_id"]);
1857 
1858  if ($_GET["editheading"])
1859  {
1860  $this->addHeadingObject(false, $_GET["editheading"]);
1861  return;
1862  }
1863 
1864  /*
1865  if ($_GET["up"] > 0)
1866  {
1867  $this->object->moveUpQuestion($_GET["up"]);
1868  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'));
1869  }
1870  if ($_GET["down"] > 0)
1871  {
1872  $this->object->moveDownQuestion($_GET["down"]);
1873  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'));
1874  }
1875  if ($_GET["qbup"] > 0)
1876  {
1877  $this->object->moveUpQuestionblock($_GET["qbup"]);
1878  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'));
1879  }
1880  if ($_GET["qbdown"] > 0)
1881  {
1882  $this->object->moveDownQuestionblock($_GET["qbdown"]);
1883  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'));
1884  }
1885  */
1886 
1887  if ($_GET["removeheading"])
1888  {
1889  $this->confirmRemoveHeadingForm();
1890  return;
1891  }
1892 
1893  if ($_GET["editblock"])
1894  {
1895  $this->defineQuestionblock($_GET["editblock"]);
1896  return;
1897  }
1898 
1899  if ($_GET["add"])
1900  {
1901  // called after a new question was created from a questionpool
1902  $selected_array = array();
1903  array_push($selected_array, $_GET["add"]);
1904  ilUtil::sendQuestion($this->lng->txt("ask_insert_questions"));
1905  $this->insertQuestionsForm($selected_array);
1906  return;
1907  }
1908 
1909 
1910  $this->questionsSubtabs("questions");
1911 
1912  $read_only = (!$rbacsystem->checkAccess("write", $this->ref_id) || $hasDatasets);
1913 
1914 
1915  // toolbar
1916 
1917  if (!$read_only)
1918  {
1919  $qtypes = array();
1920  include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
1921  foreach (ilObjSurveyQuestionPool::_getQuestiontypes() as $translation => $data)
1922  {
1923  $qtypes[$data["type_tag"]] = $translation;
1924  }
1925 
1926  $ilToolbar->setFormAction($this->ctrl->getFormAction($this));
1927  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
1928  $types = new ilSelectInputGUI($this->lng->txt("create_new"), "sel_question_types");
1929  $types->setOptions($qtypes);
1930  $ilToolbar->addInputItem($types, "");
1931  $ilToolbar->addFormButton($this->lng->txt("svy_create_question"), "createQuestion");
1932 
1933  if($this->object->isPoolActive())
1934  {
1935  $ilToolbar->addSeparator();
1936 
1937  $cmd = ($ilUser->getPref('svy_insert_type') == 1 || strlen($ilUser->getPref('svy_insert_type')) == 0) ? 'browseForQuestions' : 'browseForQuestionblocks';
1938  $ilToolbar->addButton($this->lng->txt("browse_for_questions"),
1939  $this->ctrl->getLinkTarget($this, $cmd));
1940  }
1941 
1942  $ilToolbar->addSeparator();
1943 
1944  $ilToolbar->addButton($this->lng->txt("add_heading"),
1945  $this->ctrl->getLinkTarget($this, "addHeading"));
1946  }
1947  if ($hasDatasets)
1948  {
1949  // ilUtil::sendInfo($this->lng->txt("survey_has_datasets_warning"));
1950  $link = $this->ctrl->getLinkTarget($this, "maintenance");
1951  $link = "<a href=\"".$link."\">".$this->lng->txt("survey_has_datasets_warning_page_view_link")."</a>";
1952  ilUtil::sendInfo($this->lng->txt("survey_has_datasets_warning_page_view")." ".$link);
1953  }
1954 
1955 
1956  // table gui
1957 
1958  include_once "Modules/Survey/classes/class.ilSurveyQuestionTableGUI.php";
1959  $table = new ilSurveyQuestionTableGUI($this, "questions", $this->object,
1960  $read_only);
1961  $this->tpl->setContent($table->getHTML());
1962  }
1963 
1971  function evaluationObject()
1972  {
1973  include_once("./Modules/Survey/classes/class.ilSurveyEvaluationGUI.php");
1974  $eval_gui = new ilSurveyEvaluationGUI($this->object);
1975  $this->ctrl->setCmdClass(get_class($eval_gui));
1976  $this->ctrl->redirect($eval_gui, "evaluation");
1977  }
1978 
1982  public function disinviteUserGroupObject()
1983  {
1984  // disinvite users
1985  if (is_array($_POST["user_select"]))
1986  {
1987  foreach ($_POST["user_select"] as $user_id)
1988  {
1989  $this->object->disinviteUser($user_id);
1990  }
1991  }
1992  ilUtil::sendSuccess($this->lng->txt('msg_users_disinvited'), true);
1993  $this->ctrl->redirect($this, "invite");
1994  }
1995 
1999  public function inviteUserGroupObject($a_user_ids = array())
2000  {
2001  $invited = 0;
2002  // add users to invitation
2003  if (is_array($a_user_ids))
2004  {
2005  foreach ($a_user_ids as $user_id)
2006  {
2007  $this->object->inviteUser($user_id);
2008  $invited++;
2009  }
2010  }
2011  if ($invited == 0)
2012  {
2013  ilUtil::sendFailure($this->lng->txt('no_user_invited'), TRUE);
2014  return false;
2015  }
2016  else
2017  {
2018  ilUtil::sendSuccess(sprintf($this->lng->txt('users_invited'), $invited), TRUE);
2019  return false;
2020  }
2021  $this->ctrl->redirect($this, "invite");
2022  }
2023 
2027  public function saveInvitationStatusObject()
2028  {
2029  $mode = $_POST['invitation'];
2030  switch ($mode)
2031  {
2032  case 0:
2033  $this->object->setInvitation(0);
2034  break;
2035  case 1:
2036  $this->object->setInvitation(1);
2037  $this->object->setInvitationMode(0);
2038  break;
2039  case 2:
2040  $this->object->setInvitation(1);
2041  $this->object->setInvitationMode(1);
2042  break;
2043  }
2044  $this->object->saveToDb();
2045  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true);
2046  $this->ctrl->redirect($this, "invite");
2047  }
2048 
2049 
2053  public function inviteObject()
2054  {
2055  global $ilAccess;
2056  global $rbacsystem;
2057  global $ilToolbar;
2058  global $lng;
2059 
2060  if ((!$rbacsystem->checkAccess("visible,invite", $this->ref_id)) && (!$rbacsystem->checkAccess("write", $this->ref_id)))
2061  {
2062  // allow only read and write access
2063  ilUtil::sendInfo($this->lng->txt("cannot_edit_survey"), true);
2064  $path = $this->tree->getPathFull($this->object->getRefID());
2065  include_once "./Services/Utilities/classes/class.ilUtil.php";
2066  ilUtil::redirect($this->getReturnLocation("cancel","./repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
2067  return;
2068  }
2069 
2070  if ($this->object->getStatus() == STATUS_OFFLINE)
2071  {
2072  ilUtil::sendInfo($this->lng->txt("survey_offline_message"));
2073  return;
2074  }
2075 
2076  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
2077  $form = new ilPropertyFormGUI();
2078  $form->setFormAction($this->ctrl->getFormAction($this));
2079  $form->setTableWidth("500");
2080  $form->setId("invite");
2081 
2082  // invitation
2083  $header = new ilFormSectionHeaderGUI();
2084  $header->setTitle($this->lng->txt("invitation"));
2085  $form->addItem($header);
2086 
2087  // invitation mode
2088  $invitation = new ilRadioGroupInputGUI($this->lng->txt('invitation_mode'), "invitation");
2089  $invitation->setInfo($this->lng->txt('invitation_mode_desc'));
2090  $invitation->addOption(new ilRadioOption($this->lng->txt("invitation_off"), 0, ''));
2091  $surveySetting = new ilSetting("survey");
2092  if ($surveySetting->get("unlimited_invitation"))
2093  {
2094  $invitation->addOption(new ilRadioOption($this->lng->txt("unlimited_users"), 1, ''));
2095  }
2096  $invitation->addOption(new ilRadioOption($this->lng->txt("predefined_users"), 2, ''));
2097  $inv = 0;
2098  if ($this->object->getInvitation())
2099  {
2100  $inv = $this->object->getInvitationMode() + 1;
2101  }
2102  $invitation->setValue($inv);
2103  $form->addItem($invitation);
2104 
2105  $form->addCommandButton("saveInvitationStatus", $this->lng->txt("save"));
2106 
2107  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_invite.html", "Modules/Survey");
2108  $this->tpl->setVariable("INVITATION_TABLE", $form->getHTML());
2109 
2110  if ($this->object->getInvitation() && $this->object->getInvitationMode() == 1)
2111  {
2112  // search button
2113  include_once './Services/Search/classes/class.ilRepositorySearchGUI.php';
2115  $this,
2116  $tb,
2117  array(
2118  'auto_complete_name' => $lng->txt('user'),
2119  'submit_name' => $lng->txt('svy_invite')
2120  )
2121  );
2122 
2123  $ilToolbar->addSpacer();
2124 
2125  $ilToolbar->addButton($this->lng->txt("svy_search_users"),
2126  $this->ctrl->getLinkTargetByClass('ilRepositorySearchGUI',''));
2127 
2128  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
2129 
2130  $invited_users = $this->object->getUserData($this->object->getInvitedUsers());
2131  include_once "./Modules/Survey/classes/tables/class.ilSurveyInvitedUsersTableGUI.php";
2132  $table_gui = new ilSurveyInvitedUsersTableGUI($this, 'invite');
2133  $table_gui->setData($invited_users);
2134  $this->tpl->setVariable('TBL_INVITED_USERS', $table_gui->getHTML());
2135  }
2136  }
2137 
2141  public function deleteAllUserDataObject()
2142  {
2143  ilUtil::sendQuestion($this->lng->txt("confirm_delete_all_user_data"));
2144  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_maintenance.html", "Modules/Survey");
2145  $this->tpl->setCurrentBlock("adm_content");
2146  $this->tpl->setVariable("BTN_CONFIRM_DELETE_ALL", $this->lng->txt("confirm"));
2147  $this->tpl->setVariable("BTN_CANCEL_DELETE_ALL", $this->lng->txt("cancel"));
2148  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "deleteAllUserData"));
2149  $this->tpl->parseCurrentBlock();
2150  }
2151 
2156  {
2157  $this->object->deleteAllUserData();
2158  ilUtil::sendSuccess($this->lng->txt("svy_all_user_data_deleted"), true);
2159  $this->ctrl->redirect($this, "maintenance");
2160  }
2161 
2166  {
2167  $this->ctrl->redirect($this, "maintenance");
2168  }
2169 
2174  {
2175  $this->object->removeSelectedSurveyResults($_POST["chbUser"]);
2176  ilUtil::sendSuccess($this->lng->txt("svy_selected_user_data_deleted"), true);
2177  $this->ctrl->redirect($this, "maintenance");
2178  }
2179 
2184  {
2185  ilUtil::sendInfo($this->lng->txt('msg_cancel'), true);
2186  $this->ctrl->redirect($this, "maintenance");
2187  }
2188 
2193  {
2194  $this->handleWriteAccess();
2195 
2196  if (count($_POST["chbUser"]) == 0)
2197  {
2198  ilUtil::sendInfo($this->lng->txt('no_checkbox'), true);
2199  $this->ctrl->redirect($this, "maintenance");
2200  }
2201 
2202  ilUtil::sendQuestion($this->lng->txt("confirm_delete_single_user_data"));
2203  include_once "./Modules/Survey/classes/tables/class.ilSurveyMaintenanceTableGUI.php";
2204  $table_gui = new ilSurveyMaintenanceTableGUI($this, 'maintenance', true);
2205  $total =& $this->object->getSurveyParticipants();
2206  $data = array();
2207  foreach ($total as $user_data)
2208  {
2209  if (in_array($user_data['active_id'], $_POST['chbUser']))
2210  {
2211  $last_access = $this->object->_getLastAccess($user_data["active_id"]);
2212  array_push($data, array(
2213  'id' => $user_data["active_id"],
2214  'name' => $user_data["sortname"],
2215  'login' => $user_data["login"],
2216  'last_access' => $last_access
2217  ));
2218  }
2219  }
2220  $table_gui->setData($data);
2221  $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
2222  }
2223 
2227  public function maintenanceObject()
2228  {
2229  $this->handleWriteAccess();
2230 
2231  if ($_GET["fill"] > 0)
2232  {
2233  for ($i = 0; $i < $_GET["fill"]; $i++) $this->object->fillSurveyForUser();
2234  }
2235  include_once "./Modules/Survey/classes/tables/class.ilSurveyMaintenanceTableGUI.php";
2236  $table_gui = new ilSurveyMaintenanceTableGUI($this, 'maintenance');
2237  $total =& $this->object->getSurveyParticipants();
2238  $data = array();
2239  foreach ($total as $user_data)
2240  {
2241  $last_access = $this->object->_getLastAccess($user_data["active_id"]);
2242  array_push($data, array(
2243  'id' => $user_data["active_id"],
2244  'name' => $user_data["sortname"],
2245  'login' => $user_data["login"],
2246  'last_access' => $last_access
2247  ));
2248  }
2249  $table_gui->setData($data);
2250  $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
2251  }
2252 
2253  protected function initImportForm($a_new_type)
2254  {
2255  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
2256  $form = new ilPropertyFormGUI();
2257  $form->setTarget("_top");
2258  $form->setFormAction($this->ctrl->getFormAction($this));
2259  $form->setTitle($this->lng->txt("import"));
2260 
2261  include_once("./Services/Form/classes/class.ilFileInputGUI.php");
2262  $fi = new ilFileInputGUI($this->lng->txt("import_file"), "importfile");
2263  $fi->setSuffixes(array("zip"));
2264  $fi->setRequired(true);
2265  $form->addItem($fi);
2266 
2267  include_once("./Modules/Survey/classes/class.ilObjSurvey.php");
2268  $svy = new ilObjSurvey();
2269  $questionspools = $svy->getAvailableQuestionpools(true, true, true);
2270 
2271  $pools = new ilSelectInputGUI($this->lng->txt("select_questionpool_short"), "spl");
2272  $pools->setOptions(array(""=>$this->lng->txt("dont_use_questionpool")) + $questionspools);
2273  $pools->setRequired(false);
2274  $form->addItem($pools);
2275 
2276  $form->addCommandButton("importFile", $this->lng->txt("import"));
2277  $form->addCommandButton("cancel", $this->lng->txt("cancel"));
2278 
2279  return $form;
2280  }
2281 
2285  function importFileObject()
2286  {
2287  global $tpl, $ilErr;
2288 
2289  $parent_id = $_GET["ref_id"];
2290  $new_type = $_REQUEST["new_type"];
2291 
2292  // create permission is already checked in createObject. This check here is done to prevent hacking attempts
2293  if (!$this->checkPermissionBool("create", "", $new_type))
2294  {
2295  $ilErr->raiseError($this->lng->txt("no_create_permission"));
2296  }
2297 
2298  $this->lng->loadLanguageModule($new_type);
2299  $this->ctrl->setParameter($this, "new_type", $new_type);
2300 
2301  $form = $this->initImportForm($new_type);
2302  if ($form->checkInput())
2303  {
2304  include_once("./Modules/Survey/classes/class.ilObjSurvey.php");
2305  $newObj = new ilObjSurvey();
2306  $newObj->setType($new_type);
2307  $newObj->setTitle("dummy");
2308  $newObj->setDescription("dummy");
2309  $newObj->create(true);
2310  $this->putObjectInTree($newObj);
2311 
2312  // copy uploaded file to import directory
2313  $error = $newObj->importObject($_FILES["importfile"], $form->getInput("spl"));
2314  if (strlen($error))
2315  {
2316  $newObj->delete();
2317  $this->ilias->raiseError($error, $this->ilias->error_obj->MESSAGE);
2318  return;
2319  }
2320 
2321  ilUtil::sendSuccess($this->lng->txt("object_imported"),true);
2322  ilUtil::redirect("ilias.php?ref_id=".$newObj->getRefId().
2323  "&baseClass=ilObjSurveyGUI");
2324 
2325  // using template?
2326  include_once "Services/Administration/classes/class.ilSettingsTemplate.php";
2327  $templates = ilSettingsTemplate::getAllSettingsTemplates("svy");
2328  if($templates)
2329  {
2330  global $tpl;
2331  $tpl->addJavaScript("./Modules/Scorm2004/scripts/questions/jquery.js");
2332  // $tpl->addJavaScript("./Modules/Scorm2004/scripts/questions/jquery-ui-min.js");
2333 
2334  $this->tpl->setCurrentBlock("template_option");
2335  $this->tpl->setVariable("VAL_TEMPLATE_OPTION", "");
2336  $this->tpl->setVariable("TXT_TEMPLATE_OPTION", $this->lng->txt("none"));
2337  $this->tpl->parseCurrentBlock();
2338 
2339  foreach($templates as $item)
2340  {
2341  $this->tpl->setCurrentBlock("template_option");
2342  $this->tpl->setVariable("VAL_TEMPLATE_OPTION", $item["id"]);
2343  $this->tpl->setVariable("TXT_TEMPLATE_OPTION", $item["title"]);
2344  $this->tpl->parseCurrentBlock();
2345 
2346  $desc = str_replace("\n", "", nl2br($item["description"]));
2347  $desc = str_replace("\r", "", $desc);
2348 
2349  $this->tpl->setCurrentBlock("js_data");
2350  $this->tpl->setVariable("JS_DATA_ID", $item["id"]);
2351  $this->tpl->setVariable("JS_DATA_TEXT", $desc);
2352  $this->tpl->parseCurrentBlock();
2353  }
2354 
2355  $this->tpl->setCurrentBlock("templates");
2356  $this->tpl->setVariable("TXT_TEMPLATE", $this->lng->txt("svy_settings_template"));
2357  $this->tpl->parseCurrentBlock();
2358  }
2359  }
2360 
2361  // display form to correct errors
2362  $form->setValuesByPost();
2363  $tpl->setContent($form->getHtml());
2364  }
2365 
2366  /*
2367  * list all export files
2368  */
2369  public function exportObject()
2370  {
2371  $this->handleWriteAccess();
2372 
2373  $export_dir = $this->object->getExportDirectory();
2374  $export_files = $this->object->getExportFiles($export_dir);
2375  $data = array();
2376  if(count($export_files) > 0)
2377  {
2378  foreach($export_files as $exp_file)
2379  {
2380  $file_arr = explode("__", $exp_file);
2381  $date = new ilDateTime($file_arr[0], IL_CAL_UNIX);
2382  array_push($data, array(
2383  'file' => $exp_file,
2384  'size' => filesize($export_dir."/".$exp_file),
2385  'date' => $date->get(IL_CAL_DATETIME)
2386  ));
2387  }
2388  }
2389 
2390  include_once "./Modules/Survey/classes/tables/class.ilSurveyExportTableGUI.php";
2391  $table_gui = new ilSurveyExportTableGUI($this, 'export');
2392  $table_gui->setData($data);
2393  $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
2394  }
2395 
2399  public function createExportFileObject()
2400  {
2401  $this->handleWriteAccess();
2402  include_once("./Modules/Survey/classes/class.ilSurveyExport.php");
2403  $survey_exp = new ilSurveyExport($this->object);
2404  $survey_exp->buildExportFile();
2405  $this->ctrl->redirect($this, "export");
2406  }
2407 
2411  public function downloadExportFileObject()
2412  {
2413  if(!isset($_POST["file"]))
2414  {
2415  ilUtil::sendFailure($this->lng->txt("no_checkbox"), true);
2416  $this->ctrl->redirect($this, "export");
2417  }
2418 
2419  if (count($_POST["file"]) > 1)
2420  {
2421  ilUtil::sendFailure($this->lng->txt("select_max_one_item"), true);
2422  $this->ctrl->redirect($this, "export");
2423  }
2424 
2425  $file = basename($_POST["file"][0]);
2426 
2427  $export_dir = $this->object->getExportDirectory();
2428  include_once "./Services/Utilities/classes/class.ilUtil.php";
2429  ilUtil::deliverFile($export_dir."/".$file, $file);
2430  }
2431 
2436  {
2437  $this->handleWriteAccess();
2438 
2439  if (!isset($_POST["file"]))
2440  {
2441  ilUtil::sendFailure($this->lng->txt("no_checkbox"), true);
2442  $this->ctrl->redirect($this, "export");
2443  }
2444 
2445  ilUtil::sendQuestion($this->lng->txt("info_delete_sure"));
2446 
2447  $export_dir = $this->object->getExportDirectory();
2448  $export_files = $this->object->getExportFiles($export_dir);
2449  $data = array();
2450  if (count($_POST["file"]) > 0)
2451  {
2452  foreach ($_POST["file"] as $exp_file)
2453  {
2454  $file_arr = explode("__", $exp_file);
2455  $date = new ilDateTime($file_arr[0], IL_CAL_UNIX);
2456  array_push($data, array(
2457  'file' => $exp_file,
2458  'size' => filesize($export_dir."/".$exp_file),
2459  'date' => $date->get(IL_CAL_DATETIME)
2460  ));
2461  }
2462  }
2463 
2464  include_once "./Modules/Survey/classes/tables/class.ilSurveyExportTableGUI.php";
2465  $table_gui = new ilSurveyExportTableGUI($this, 'export', true);
2466  $table_gui->setData($data);
2467  $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
2468  }
2469 
2470 
2475  {
2476  ilUtil::sendInfo($this->lng->txt('msg_cancel'), true);
2477  $this->ctrl->redirect($this, "export");
2478  }
2479 
2480 
2484  public function deleteExportFileObject()
2485  {
2486  $export_dir = $this->object->getExportDirectory();
2487  foreach ($_POST["file"] as $file)
2488  {
2489  $file = basename($file);
2490 
2491  $exp_file = $export_dir."/".$file;
2492  $exp_dir = $export_dir."/".substr($file, 0, strlen($file) - 4);
2493  if (@is_file($exp_file))
2494  {
2495  unlink($exp_file);
2496  }
2497  if (@is_dir($exp_dir))
2498  {
2499  include_once "./Services/Utilities/classes/class.ilUtil.php";
2500  ilUtil::delDir($exp_dir);
2501  }
2502  }
2503  ilUtil::sendSuccess($this->lng->txt('msg_deleted_export_files'), true);
2504  $this->ctrl->redirect($this, "export");
2505  }
2506 
2510  public function setCodeLanguageObject()
2511  {
2512  if (strcmp($_POST["lang"], "-1") != 0)
2513  {
2514  global $ilUser;
2515  $ilUser->writePref("survey_code_language", $_POST["lang"]);
2516  }
2517  ilUtil::sendSuccess($this->lng->txt('language_changed'), true);
2518  $this->ctrl->redirect($this, 'codes');
2519  }
2520 
2524  public function codesObject()
2525  {
2526  $this->handleWriteAccess();
2527  $this->setCodesSubtabs();
2528  global $ilUser, $ilToolbar;
2529  if ($this->object->getAnonymize() != 1 && !$this->object->isAccessibleWithCodeForAll())
2530  {
2531  return ilUtil::sendInfo($this->lng->txt("survey_codes_no_anonymization"));
2532  }
2533 
2534  $default_lang = $ilUser->getPref("survey_code_language");
2535 
2536  // creation buttons
2537  $ilToolbar->setFormAction($this->ctrl->getFormAction($this));
2538  $languages = $this->lng->getInstalledLanguages();
2539  $options = array();
2540  foreach ($languages as $lang)
2541  {
2542  $options[$lang] = $this->lng->txt("lang_$lang");
2543  }
2544  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
2545  $si = new ilSelectInputGUI($this->lng->txt("survey_codes_lang"), "lang");
2546  $si->setOptions($options);
2547  $si->setValue($default_lang);
2548  $ilToolbar->addInputItem($si, true);
2549  $ilToolbar->addFormButton($this->lng->txt("set"), "setCodeLanguage");
2550 
2551  include_once "./Modules/Survey/classes/tables/class.ilSurveyCodesTableGUI.php";
2552  $table_gui = new ilSurveyCodesTableGUI($this, 'codes');
2553  $survey_codes =& $this->object->getSurveyCodesTableData($default_lang);
2554  $table_gui->setData($survey_codes);
2555  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_codes.html", true);
2556  $this->tpl->setCurrentBlock("adm_content");
2557  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "codes"));
2558  $this->tpl->setVariable("TEXT_CREATE", $this->lng->txt("create"));
2559  $this->tpl->setVariable("TEXT_SURVEY_CODES", $this->lng->txt("new_survey_codes"));
2560  $this->tpl->setVariable('TABLE', $table_gui->getHTML());
2561  }
2562 
2566  public function deleteCodesObject()
2567  {
2568  if (is_array($_POST["chb_code"]) && (count($_POST["chb_code"]) > 0))
2569  {
2570  foreach ($_POST["chb_code"] as $survey_code)
2571  {
2572  $this->object->deleteSurveyCode($survey_code);
2573  }
2574  ilUtil::sendSuccess($this->lng->txt('codes_deleted'), true);
2575  }
2576  else
2577  {
2578  ilUtil::sendInfo($this->lng->txt('no_checkbox'), true);
2579  }
2580  $this->ctrl->redirect($this, 'codes');
2581  }
2582 
2586  public function exportCodesObject()
2587  {
2588  if (is_array($_POST["chb_code"]) && (count($_POST["chb_code"]) > 0))
2589  {
2590  $export = $this->object->getSurveyCodesForExport($_POST["chb_code"]);
2591  ilUtil::deliverData($export, ilUtil::getASCIIFilename($this->object->getTitle() . ".txt"));
2592  }
2593  else
2594  {
2595  ilUtil::sendFailure($this->lng->txt("no_checkbox"), true);
2596  $this->ctrl->redirect($this, 'codes');
2597  }
2598  }
2599 
2603  public function exportAllCodesObject()
2604  {
2605  $export = $this->object->getSurveyCodesForExport(array());
2606  ilUtil::deliverData($export, ilUtil::getASCIIFilename($this->object->getTitle() . ".txt"));
2607  }
2608 
2612  public function createSurveyCodesObject()
2613  {
2614  if (preg_match("/\d+/", $_POST["nrOfCodes"]))
2615  {
2616  $this->object->createSurveyCodes($_POST["nrOfCodes"]);
2617  ilUtil::sendSuccess($this->lng->txt('codes_created'), true);
2618  }
2619  else
2620  {
2621  ilUtil::sendFailure($this->lng->txt("enter_valid_number_of_codes"), true);
2622  }
2623  $this->ctrl->redirect($this, 'codes');
2624  }
2625 
2629  public function codesMailObject($checkonly = false)
2630  {
2631  global $ilAccess;
2632 
2633  $this->handleWriteAccess();
2634  $this->setCodesSubtabs();
2635 
2636  $savefields = (strcmp($this->ctrl->getCmd(), "saveMailTableFields") == 0) ? TRUE : FALSE;
2637 
2638  include_once "./Modules/Survey/classes/tables/class.ilSurveyCodesMailTableGUI.php";
2639  $data = $this->object->getExternalCodeRecipients();
2640  $table_gui = new ilSurveyCodesMailTableGUI($this, 'codesMail');
2641  $table_gui->setData($data);
2642  $table_gui->setTitle($this->lng->txt('externalRecipients'));
2643  $table_gui->completeColumns();
2644  $tabledata = $table_gui->getHTML();
2645 
2646  if (!$checkonly)
2647  {
2648  $this->tpl->setVariable('ADM_CONTENT', $tabledata);
2649  }
2650  return $errors;
2651  }
2652 
2653  public function insertSavedMessageObject()
2654  {
2655  $this->handleWriteAccess();
2656  $this->setCodesSubtabs();
2657 
2658  include_once("./Modules/Survey/classes/forms/FormMailCodesGUI.php");
2659  $form_gui = new FormMailCodesGUI($this);
2660  $form_gui->setValuesByPost();
2661  try
2662  {
2663  if ($form_gui->getSavedMessages()->getValue() > 0)
2664  {
2665  global $ilUser;
2666  $settings = $this->object->getUserSettings($ilUser->getId(), 'savemessage');
2667  $form_gui->getMailMessage()->setValue($settings[$form_gui->getSavedMessages()->getValue()]['value']);
2668  ilUtil::sendSuccess($this->lng->txt('msg_message_inserted'));
2669  }
2670  else
2671  {
2672  ilUtil::sendFailure($this->lng->txt('msg_no_message_inserted'));
2673  }
2674  }
2675  catch (Exception $e)
2676  {
2677  global $ilLog;
2678  $ilLog->write('Error: ' + $e->getMessage());
2679  }
2680  $this->tpl->setVariable("ADM_CONTENT", $form_gui->getHTML());
2681  }
2682 
2683  public function deleteSavedMessageObject()
2684  {
2685  $this->handleWriteAccess();
2686  $this->setCodesSubtabs();
2687 
2688  include_once("./Modules/Survey/classes/forms/FormMailCodesGUI.php");
2689  $form_gui = new FormMailCodesGUI($this);
2690  $form_gui->setValuesByPost();
2691  try
2692  {
2693  if ($form_gui->getSavedMessages()->getValue() > 0)
2694  {
2695  $this->object->deleteUserSettings($form_gui->getSavedMessages()->getValue());
2696  $form_gui = new FormMailCodesGUI($this);
2697  $form_gui->setValuesByPost();
2698  ilUtil::sendSuccess($this->lng->txt('msg_message_deleted'));
2699  }
2700  else
2701  {
2702  ilUtil::sendFailure($this->lng->txt('msg_no_message_deleted'));
2703  }
2704  }
2705  catch (Exception $e)
2706  {
2707  global $ilLog;
2708  $ilLog->write('Error: ' + $e->getMessage());
2709  }
2710  $this->tpl->setVariable("ADM_CONTENT", $form_gui->getHTML());
2711  }
2712 
2713  public function mailCodesObject()
2714  {
2715  $this->handleWriteAccess();
2716  $this->setCodesSubtabs();
2717 
2718  $mailData['m_subject'] = (array_key_exists('m_subject', $_POST)) ? $_POST['m_subject'] : sprintf($this->lng->txt('default_codes_mail_subject'), $this->object->getTitle());
2719  $mailData['m_message'] = (array_key_exists('m_message', $_POST)) ? $_POST['m_message'] : $this->lng->txt('default_codes_mail_message');
2720  $mailData['m_notsent'] = (array_key_exists('m_notsent', $_POST)) ? $_POST['m_notsent'] : '1';
2721 
2722  include_once("./Modules/Survey/classes/forms/FormMailCodesGUI.php");
2723  $form_gui = new FormMailCodesGUI($this);
2724  $form_gui->setValuesByArray($mailData);
2725  $this->tpl->setVariable("ADM_CONTENT", $form_gui->getHTML());
2726  }
2727 
2728  public function sendCodesMailObject()
2729  {
2730  global $ilUser;
2731 
2732  $this->handleWriteAccess();
2733  $this->setCodesSubtabs();
2734 
2735  include_once("./Modules/Survey/classes/forms/FormMailCodesGUI.php");
2736  $form_gui = new FormMailCodesGUI($this);
2737  if ($form_gui->checkInput())
2738  {
2739  $code_exists = strpos($_POST['m_message'], '[code]') !== FALSE;
2740  if (!$code_exists)
2741  {
2742  if (!$code_exists) ilUtil::sendFailure($this->lng->txt('please_enter_mail_code'));
2743  $form_gui->setValuesByPost();
2744  }
2745  else
2746  {
2747  if ($_POST['savemessage'] == 1)
2748  {
2749  global $ilUser;
2750  $title = (strlen($_POST['savemessagetitle'])) ? $_POST['savemessagetitle'] : ilStr::substr($_POST['m_message'], 0, 40) . '...';
2751  $this->object->saveUserSettings($ilUser->getId(), 'savemessage', $title, $_POST['m_message']);
2752  }
2753 
2754  $lang = $ilUser->getPref("survey_code_language");
2755  if(!$lang)
2756  {
2757  $lang = "en";
2758  }
2759  $this->object->sendCodes($_POST['m_notsent'], $_POST['m_subject'], $_POST['m_message'],$lang);
2760 
2761  ilUtil::sendSuccess($this->lng->txt('mail_sent'), true);
2762  $this->ctrl->redirect($this, 'codesMail');
2763  }
2764  }
2765  else
2766  {
2767  $form_gui->setValuesByPost();
2768  }
2769  $this->tpl->setVariable("ADM_CONTENT", $form_gui->getHTML());
2770  }
2771 
2772  public function cancelCodesMailObject()
2773  {
2774  $this->ctrl->redirect($this, 'codesMail');
2775  }
2776 
2778  {
2779  if (!is_array($_POST['chb_ext']) || count(is_array($_POST['chb_ext'])) == 0)
2780  {
2781  ilUtil::sendInfo($this->lng->txt("err_no_selection"), true);
2782  $this->ctrl->redirect($this, 'codesMail');
2783  }
2784  foreach ($_POST['chb_ext'] as $code)
2785  {
2786  $this->object->deleteSurveyCode($code);
2787  }
2788  ilUtil::sendSuccess($this->lng->txt('external_recipients_deleted'), true);
2789  $this->ctrl->redirect($this, 'codesMail');
2790  }
2791 
2793  {
2794  $hasErrors = $this->importExternalMailRecipientsObject(true, 2);
2795  if (!$hasErrors)
2796  {
2797  $data = array();
2798  $existingdata = $this->object->getExternalCodeRecipients();
2799  if (count($existingdata))
2800  {
2801  $first = array_shift($existingdata);
2802  foreach ($first as $key => $value)
2803  {
2804  if (strcmp($key, 'code') != 0 && strcmp($key, 'sent') != 0)
2805  {
2806  $data[$key] = $_POST[$key];
2807  }
2808  }
2809  }
2810  if (count($data))
2811  {
2812  $this->object->createSurveyCodesForExternalData(array($data));
2813  ilUtil::sendSuccess($this->lng->txt('external_recipients_imported'), true);
2814  }
2815  $this->ctrl->redirect($this, 'codesMail');
2816  }
2817  }
2818 
2820  {
2821  $hasErrors = $this->importExternalMailRecipientsObject(true, 1);
2822  if (!$hasErrors)
2823  {
2824  $data = preg_split("/[\n\r]/", $_POST['externaltext']);
2825  $fields = preg_split("/;/", array_shift($data));
2826  if (!in_array('email', $fields))
2827  {
2828  $_SESSION['externaltext'] = $_POST['externaltext'];
2829  ilUtil::sendFailure($this->lng->txt('err_external_rcp_no_email_column'), true);
2830  $this->ctrl->redirect($this, 'importExternalMailRecipients');
2831  }
2832  $existingdata = $this->object->getExternalCodeRecipients();
2833  $existingcolumns = array();
2834  if (count($existingdata))
2835  {
2836  $first = array_shift($existingdata);
2837  foreach ($first as $key => $value)
2838  {
2839  array_push($existingcolumns, $key);
2840  }
2841  }
2842  $founddata = array();
2843  foreach ($data as $datarow)
2844  {
2845  $row = preg_split("/;/", $datarow);
2846  if (count($row) == count($fields))
2847  {
2848  $dataset = array();
2849  foreach ($fields as $idx => $fieldname)
2850  {
2851  if (count($existingcolumns))
2852  {
2853  if (array_key_exists($idx, $existingcolumns))
2854  {
2855  $dataset[$fieldname] = $row[$idx];
2856  }
2857  }
2858  else
2859  {
2860  $dataset[$fieldname] = $row[$idx];
2861  }
2862  }
2863  if (strlen($dataset['email']))
2864  {
2865  array_push($founddata, $dataset);
2866  }
2867  }
2868  }
2869  $this->object->createSurveyCodesForExternalData($founddata);
2870  ilUtil::sendSuccess($this->lng->txt('external_recipients_imported'), true);
2871  $this->ctrl->redirect($this, 'codesMail');
2872  }
2873  }
2874 
2876  {
2877  $hasErrors = $this->importExternalMailRecipientsObject(true, 0);
2878  if (!$hasErrors)
2879  {
2880  include_once "./Services/Utilities/classes/class.ilCSVReader.php";
2881  $reader = new ilCSVReader();
2882  $reader->open($_FILES['externalmails']['tmp_name']);
2883  $data = $reader->getDataArrayFromCSVFile();
2884  $fields = array_shift($data);
2885  if (!in_array('email', $fields))
2886  {
2887  $reader->close();
2888  ilUtil::sendFailure($this->lng->txt('err_external_rcp_no_email'), true);
2889  $this->ctrl->redirect($this, 'codesMail');
2890  }
2891  $existingdata = $this->object->getExternalCodeRecipients();
2892  $existingcolumns = array();
2893  if (count($existingdata))
2894  {
2895  $first = array_shift($existingdata);
2896  foreach ($first as $key => $value)
2897  {
2898  array_push($existingcolumns, $key);
2899  }
2900  }
2901  $founddata = array();
2902  foreach ($data as $row)
2903  {
2904  if (count($row) == count($fields))
2905  {
2906  $dataset = array();
2907  foreach ($fields as $idx => $fieldname)
2908  {
2909  if (count($existingcolumns))
2910  {
2911  if (array_key_exists($idx, $existingcolumns))
2912  {
2913  $dataset[$fieldname] = $row[$idx];
2914  }
2915  }
2916  else
2917  {
2918  $dataset[$fieldname] = $row[$idx];
2919  }
2920  }
2921  if (strlen($dataset['email']))
2922  {
2923  array_push($founddata, $dataset);
2924  }
2925  }
2926  }
2927  $reader->close();
2928  $this->object->createSurveyCodesForExternalData($founddata);
2929  ilUtil::sendSuccess($this->lng->txt('external_recipients_imported'), true);
2930  $this->ctrl->redirect($this, 'codesMail');
2931  }
2932  }
2933 
2934  function importExternalMailRecipientsObject($checkonly = false, $formindex = -1)
2935  {
2936  global $ilAccess;
2937 
2938  $this->handleWriteAccess();
2939  $this->setCodesSubtabs();
2940 
2941  $savefields = (
2942  strcmp($this->ctrl->getCmd(), "importExternalRecipientsFromFile") == 0 ||
2943  strcmp($this->ctrl->getCmd(), "importExternalRecipientsFromText") == 0 ||
2944  strcmp($this->ctrl->getCmd(), "importExternalRecipientsFromDataset") == 0
2945  ) ? TRUE : FALSE;
2946 
2947  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
2948  $form_import_file = new ilPropertyFormGUI();
2949  $form_import_file->setFormAction($this->ctrl->getFormAction($this));
2950  $form_import_file->setTableWidth("100%");
2951  $form_import_file->setId("codes_import_file");
2952 
2953  $headerfile = new ilFormSectionHeaderGUI();
2954  $headerfile->setTitle($this->lng->txt("import_from_file"));
2955  $form_import_file->addItem($headerfile);
2956 
2957  $externalmails = new ilFileInputGUI($this->lng->txt("externalmails"), "externalmails");
2958  $externalmails->setInfo($this->lng->txt('externalmails_info'));
2959  $externalmails->setRequired(true);
2960  $form_import_file->addItem($externalmails);
2961  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form_import_file->addCommandButton("importExternalRecipientsFromFile", $this->lng->txt("import"));
2962  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form_import_file->addCommandButton("codesMail", $this->lng->txt("cancel"));
2963 
2964  // import text
2965 
2966  $form_import_text = new ilPropertyFormGUI();
2967  $form_import_text->setFormAction($this->ctrl->getFormAction($this));
2968  $form_import_text->setTableWidth("100%");
2969  $form_import_text->setId("codes_import_text");
2970 
2971  $headertext = new ilFormSectionHeaderGUI();
2972  $headertext->setTitle($this->lng->txt("import_from_text"));
2973  $form_import_text->addItem($headertext);
2974 
2975  $inp = new ilTextAreaInputGUI($this->lng->txt('externaltext'), 'externaltext');
2976  if (array_key_exists('externaltext', $_SESSION) && strlen($_SESSION['externaltext']))
2977  {
2978  $inp->setValue($_SESSION['externaltext']);
2979  }
2980  else
2981  {
2982  $inp->setValue($this->lng->txt('mail_import_example1') . "\n" . $this->lng->txt('mail_import_example2') . "\n" . $this->lng->txt('mail_import_example3') . "\n");
2983  }
2984  $inp->setRequired(true);
2985  $inp->setCols(80);
2986  $inp->setRows(10);
2987  $inp->setInfo($this->lng->txt('externaltext_info'));
2988  $form_import_text->addItem($inp);
2989  unset($_SESSION['externaltext']);
2990 
2991  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form_import_text->addCommandButton("importExternalRecipientsFromText", $this->lng->txt("import"));
2992  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form_import_text->addCommandButton("codesMail", $this->lng->txt("cancel"));
2993 
2994  // import dataset
2995 
2996  $form_import_dataset = new ilPropertyFormGUI();
2997  $form_import_dataset->setFormAction($this->ctrl->getFormAction($this));
2998  $form_import_dataset->setTableWidth("100%");
2999  $form_import_dataset->setId("codes_import_dataset");
3000 
3001  $headerfile = new ilFormSectionHeaderGUI();
3002  $headerfile->setTitle($this->lng->txt("import_from_dataset"));
3003  $form_import_dataset->addItem($headerfile);
3004 
3005  $existingdata = $this->object->getExternalCodeRecipients();
3006  $existingcolumns = array('email');
3007  if (count($existingdata))
3008  {
3009  $first = array_shift($existingdata);
3010  foreach ($first as $key => $value)
3011  {
3012  if (strcmp($key, 'email') != 0 && strcmp($key, 'code') != 0 && strcmp($key, 'sent') != 0)
3013  {
3014  array_push($existingcolumns, $key);
3015  }
3016  }
3017  }
3018 
3019  foreach ($existingcolumns as $column)
3020  {
3021  $inp = new ilTextInputGUI($column, $column);
3022  $inp->setSize(50);
3023  if (strcmp($column, 'email') == 0)
3024  {
3025  $inp->setRequired(true);
3026  }
3027  else
3028  {
3029  $inp->setRequired(false);
3030  }
3031  $form_import_dataset->addItem($inp);
3032  }
3033  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form_import_dataset->addCommandButton("importExternalRecipientsFromDataset", $this->lng->txt("import"));
3034  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form_import_dataset->addCommandButton("codesMail", $this->lng->txt("cancel"));
3035 
3036  $errors = false;
3037 
3038  if ($savefields)
3039  {
3040  switch ($formindex)
3041  {
3042  case 0:
3043  $errors = !$form_import_file->checkInput();
3044  $form_import_file->setValuesByPost();
3045  if ($errors) $checkonly = false;
3046  break;
3047  case 1:
3048  $errors = !$form_import_text->checkInput();
3049  $form_import_text->setValuesByPost();
3050  if ($errors) $checkonly = false;
3051  break;
3052  case 2:
3053  $errors = !$form_import_dataset->checkInput();
3054  $form_import_dataset->setValuesByPost();
3055  if ($errors) $checkonly = false;
3056  break;
3057  }
3058  }
3059 
3060  if (!$checkonly)
3061  {
3062  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_external_mail.html", "Modules/Survey");
3063  $this->tpl->setVariable("HEADLINE", $this->lng->txt("external_mails_import"));
3064  $this->tpl->setVariable("FORM1", $form_import_file->getHTML());
3065  $this->tpl->setVariable("FORM2", $form_import_text->getHTML());
3066  $this->tpl->setVariable("FORM3", $form_import_dataset->getHTML());
3067  }
3068  return $errors;
3069  }
3070 
3074  public function constraintsAddObject()
3075  {
3076  if (strlen($_POST["v"]) == 0)
3077  {
3078  ilUtil::sendFailure($this->lng->txt("msg_enter_value_for_valid_constraint"));
3079  return $this->constraintStep3Object();
3080  }
3081  $survey_questions =& $this->object->getSurveyQuestions();
3082  $structure =& $_SESSION["constraintstructure"];
3083  $include_elements = $_SESSION["includeElements"];
3084  foreach ($include_elements as $elementCounter)
3085  {
3086  if (is_array($structure[$elementCounter]))
3087  {
3088  if (strlen($_GET["precondition"]))
3089  {
3090  $this->object->updateConstraint($_GET['precondition'], $_POST["q"], $_POST["r"], $_POST["v"], $_POST['c']);
3091  }
3092  else
3093  {
3094  $constraint_id = $this->object->addConstraint($_POST["q"], $_POST["r"], $_POST["v"], $_POST['c']);
3095  foreach ($structure[$elementCounter] as $key => $question_id)
3096  {
3097  $this->object->addConstraintToQuestion($question_id, $constraint_id);
3098  }
3099  }
3100  if (count($structure[$elementCounter]) > 1)
3101  {
3102  $this->object->updateConjunctionForQuestions($structure[$elementCounter], $_POST['c']);
3103  }
3104  }
3105  }
3106  unset($_SESSION["includeElements"]);
3107  unset($_SESSION["constraintstructure"]);
3108  $this->ctrl->redirect($this, "constraints");
3109  }
3110 
3114  public function constraintStep1Object()
3115  {
3116  $survey_questions =& $this->object->getSurveyQuestions();
3117  $structure =& $_SESSION["constraintstructure"];
3118  $start = $_GET["start"];
3119  $option_questions = array();
3120  for ($i = 1; $i < $start; $i++)
3121  {
3122  if (is_array($structure[$i]))
3123  {
3124  foreach ($structure[$i] as $key => $question_id)
3125  {
3126  if ($survey_questions[$question_id]["usableForPrecondition"])
3127  {
3128  array_push($option_questions, array("question_id" => $survey_questions[$question_id]["question_id"], "title" => $survey_questions[$question_id]["title"], "type_tag" => $survey_questions[$question_id]["type_tag"]));
3129  }
3130  }
3131  }
3132  }
3133  if (count($option_questions) == 0)
3134  {
3135  unset($_SESSION["includeElements"]);
3136  unset($_SESSION["constraintstructure"]);
3137  ilUtil::sendInfo($this->lng->txt("constraints_no_nonessay_available"), true);
3138  $this->ctrl->redirect($this, "constraints");
3139  }
3140  $this->constraintForm(1, $_POST, $survey_questions, $option_questions);
3141  }
3142 
3146  public function constraintStep2Object()
3147  {
3148  $survey_questions =& $this->object->getSurveyQuestions();
3149  $option_questions = array();
3150  array_push($option_questions, array("question_id" => $_POST["q"], "title" => $survey_questions[$_POST["q"]]["title"], "type_tag" => $survey_questions[$_POST["q"]]["type_tag"]));
3151  $this->constraintForm(2, $_POST, $survey_questions, $option_questions);
3152  }
3153 
3157  public function constraintStep3Object()
3158  {
3159  $survey_questions =& $this->object->getSurveyQuestions();
3160  $option_questions = array();
3161  if (strlen($_GET["precondition"]))
3162  {
3163  $pc = $this->object->getPrecondition($_GET["precondition"]);
3164  $postvalues = array(
3165  "c" => $pc["conjunction"],
3166  "q" => $pc["question_fi"],
3167  "r" => $pc["relation_id"],
3168  "v" => $pc["value"]
3169  );
3170  array_push($option_questions, array("question_id" => $pc["question_fi"], "title" => $survey_questions[$pc["question_fi"]]["title"], "type_tag" => $survey_questions[$pc["question_fi"]]["type_tag"]));
3171  $this->constraintForm(3, $postvalues, $survey_questions, $option_questions);
3172  }
3173  else
3174  {
3175  array_push($option_questions, array("question_id" => $_POST["q"], "title" => $survey_questions[$_POST["q"]]["title"], "type_tag" => $survey_questions[$_POST["q"]]["type_tag"]));
3176  $this->constraintForm(3, $_POST, $survey_questions, $option_questions);
3177  }
3178  }
3179 
3180  public function constraintForm($step, $postvalues, &$survey_questions, $questions = FALSE)
3181  {
3182  if (strlen($_GET["start"])) $this->ctrl->setParameter($this, "start", $_GET["start"]);
3183  $this->ctrl->saveParameter($this, "precondition");
3184  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
3185  $form = new ilPropertyFormGUI();
3186  $form->setFormAction($this->ctrl->getFormAction($this));
3187  $form->setTableWidth("100%");
3188  $form->setId("constraintsForm");
3189 
3190  $title = "";
3191  if ($survey_questions[$_SESSION["constraintstructure"][$_GET["start"]][0]]["questionblock_id"] > 0)
3192  {
3193  $title = $this->lng->txt("questionblock") . ": " . $survey_questions[$_SESSION["constraintstructure"][$_GET["start"]][0]]["questionblock_title"];
3194  }
3195  else
3196  {
3197  $title = $this->lng->txt($survey_questions[$_SESSION["constraintstructure"][$_GET["start"]][0]]["type_tag"]) . ": " . $survey_questions[$_SESSION["constraintstructure"][$_GET["start"]][0]]["title"];
3198  }
3199  $header = new ilFormSectionHeaderGUI();
3200  $header->setTitle($title);
3201  $form->addItem($header);
3202 
3203  $fulfilled = new ilRadioGroupInputGUI($this->lng->txt("constraint_fulfilled"), "c");
3204  $fulfilled->addOption(new ilRadioOption($this->lng->txt("conjunction_and"), '0', ''));
3205  $fulfilled->addOption(new ilRadioOption($this->lng->txt("conjunction_or"), '1', ''));
3206  $fulfilled->setValue((strlen($postvalues['c'])) ? $postvalues['c'] : 0);
3207  $form->addItem($fulfilled);
3208 
3209  $step1 = new ilSelectInputGUI($this->lng->txt("step") . " 1: " . $this->lng->txt("select_prior_question"), "q");
3210  $options = array();
3211  if (is_array($questions))
3212  {
3213  foreach ($questions as $question)
3214  {
3215  $options[$question["question_id"]] = $question["title"] . " (" . SurveyQuestion::_getQuestionTypeName($question["type_tag"]) . ")";
3216  }
3217  }
3218  $step1->setOptions($options);
3219  $step1->setValue($postvalues["q"]);
3220  $form->addItem($step1);
3221 
3222  if ($step > 1)
3223  {
3224  $relations = $this->object->getAllRelations();
3225  $step2 = new ilSelectInputGUI($this->lng->txt("step") . " 2: " . $this->lng->txt("select_relation"), "r");
3226  $options = array();
3227  foreach ($relations as $rel_id => $relation)
3228  {
3229  if (in_array($relation["short"], $survey_questions[$postvalues["q"]]["availableRelations"]))
3230  {
3231  $options[$rel_id] = $relation['short'];
3232  }
3233  }
3234  $step2->setOptions($options);
3235  $step2->setValue($postvalues["r"]);
3236  $form->addItem($step2);
3237  }
3238 
3239  if ($step > 2)
3240  {
3241  $variables =& $this->object->getVariables($postvalues["q"]);
3242  $question_type = $survey_questions[$postvalues["q"]]["type_tag"];
3243  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
3244  SurveyQuestion::_includeClass($question_type);
3245  $question = new $question_type();
3246  $question->loadFromDb($postvalues["q"]);
3247 
3248  $step3 = $question->getPreconditionSelectValue($postvalues["v"], $this->lng->txt("step") . " 3: " . $this->lng->txt("select_value"), "v");
3249  $form->addItem($step3);
3250  }
3251 
3252  switch ($step)
3253  {
3254  case 1:
3255  $cmd_continue = "constraintStep2";
3256  $cmd_back = "constraints";
3257  break;
3258  case 2:
3259  $cmd_continue = "constraintStep3";
3260  $cmd_back = "constraintStep1";
3261  break;
3262  case 3:
3263  $cmd_continue = "constraintsAdd";
3264  $cmd_back = "constraintStep2";
3265  break;
3266  }
3267  $form->addCommandButton($cmd_back, $this->lng->txt("back"));
3268  $form->addCommandButton($cmd_continue, $this->lng->txt("continue"));
3269 
3270  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
3271  }
3272 
3276  public function deleteConstraintsObject()
3277  {
3278  $survey_questions =& $this->object->getSurveyQuestions();
3279  $structure =& $_SESSION["constraintstructure"];
3280  foreach ($_POST as $key => $value)
3281  {
3282  if (preg_match("/^constraint_(\d+)_(\d+)/", $key, $matches))
3283  {
3284  $this->object->deleteConstraint($matches[2]);
3285  }
3286  }
3287 
3288  $this->ctrl->redirect($this, "constraints");
3289  }
3290 
3292  {
3293  $include_elements = $_POST["includeElements"];
3294  if ((!is_array($include_elements)) || (count($include_elements) == 0))
3295  {
3296  ilUtil::sendInfo($this->lng->txt("constraints_no_questions_or_questionblocks_selected"), true);
3297  $this->ctrl->redirect($this, "constraints");
3298  }
3299  else if (count($include_elements) >= 1)
3300  {
3301  $_SESSION["includeElements"] = $include_elements;
3302  sort($include_elements, SORT_NUMERIC);
3303  $_GET["start"] = $include_elements[0];
3304  $this->constraintStep1Object();
3305  }
3306  }
3307 
3309  {
3310  $_SESSION["includeElements"] = array($_GET["start"]);
3311  $this->ctrl->setParameter($this, "precondition", $_GET["precondition"]);
3312  $this->ctrl->setParameter($this, "start", $_GET["start"]);
3313  $this->ctrl->redirect($this, "constraintStep3");
3314  }
3315 
3319  public function constraintsObject()
3320  {
3321  $this->handleWriteAccess();
3322 
3323  global $rbacsystem;
3324 
3325  $hasDatasets = $this->object->_hasDatasets($this->object->getSurveyId());
3326  $step = 0;
3327  if (array_key_exists("step", $_GET)) $step = $_GET["step"];
3328  switch ($step)
3329  {
3330  case 1:
3331  $this->constraintStep1Object();
3332  return;
3333  break;
3334  case 2:
3335  return;
3336  break;
3337  case 3:
3338  return;
3339  break;
3340  }
3341 
3342  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_constraints_list.html", "Modules/Survey");
3343  $survey_questions =& $this->object->getSurveyQuestions();
3344  $last_questionblock_id = 0;
3345  $counter = 1;
3346  $hasPreconditions = FALSE;
3347  $structure = array();
3348  $colors = array("tblrow1", "tblrow2");
3349  foreach ($survey_questions as $question_id => $data)
3350  {
3351  $title = $data["title"];
3352  $show = true;
3353  if ($data["questionblock_id"] > 0)
3354  {
3355  $title = $data["questionblock_title"];
3356  $type = $this->lng->txt("questionblock");
3357  if ($data["questionblock_id"] != $last_questionblock_id)
3358  {
3359  $last_questionblock_id = $data["questionblock_id"];
3360  $structure[$counter] = array();
3361  array_push($structure[$counter], $data["question_id"]);
3362  }
3363  else
3364  {
3365  array_push($structure[$counter-1], $data["question_id"]);
3366  $show = false;
3367  }
3368  }
3369  else
3370  {
3371  $structure[$counter] = array($data["question_id"]);
3372  $type = $this->lng->txt("question");
3373  }
3374  if ($show)
3375  {
3376  if ($counter == 1)
3377  {
3378  $this->tpl->setCurrentBlock("description");
3379  $this->tpl->setVariable("DESCRIPTION", $this->lng->txt("constraints_first_question_description"));
3380  $this->tpl->parseCurrentBlock();
3381  }
3382  else
3383  {
3384  $constraints =& $this->object->getConstraints($data["question_id"]);
3385  $rowcount = 0;
3386  if (count($constraints))
3387  {
3388  $hasPreconditions = TRUE;
3389  foreach ($constraints as $constraint)
3390  {
3391  $this->tpl->setCurrentBlock("constraint");
3392  $this->tpl->setVariable("SEQUENCE_ID", $counter);
3393  $this->tpl->setVariable("CONSTRAINT_ID", $constraint["id"]);
3394  $this->tpl->setVariable("CONSTRAINT_TEXT", $survey_questions[$constraint["question"]]["title"] . " " . $constraint["short"] . " " . $constraint["valueoutput"]);
3395  $this->tpl->setVariable("TEXT_EDIT_PRECONDITION", $this->lng->txt("edit"));
3396  $this->ctrl->setParameter($this, "precondition", $constraint["id"]);
3397  $this->ctrl->setParameter($this, "start", $counter);
3398  $this->tpl->setVariable("EDIT_PRECONDITION", $this->ctrl->getLinkTarget($this, "editPrecondition"));
3399  $this->ctrl->setParameter($this, "precondition", "");
3400  $this->ctrl->setParameter($this, "start", "");
3401  $this->tpl->parseCurrentBlock();
3402  }
3403  if (count($constraints) > 1)
3404  {
3405  $this->tpl->setCurrentBlock("conjunction");
3406  $this->tpl->setVariable("TEXT_CONJUNCTION", ($constraints[0]['conjunction']) ? $this->lng->txt('conjunction_or_title') : $this->lng->txt('conjunction_and_title'));
3407  $this->tpl->parseCurrentBlock();
3408  }
3409  }
3410  }
3411  if ($counter != 1)
3412  {
3413  $this->tpl->setCurrentBlock("include_elements");
3414  $this->tpl->setVariable("QUESTION_NR", "$counter");
3415  $this->tpl->parseCurrentBlock();
3416  }
3417  $this->tpl->setCurrentBlock("constraint_section");
3418  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
3419  $this->tpl->setVariable("QUESTION_NR", "$counter");
3420  $this->tpl->setVariable("TITLE", "$title");
3421  $icontype = "question.gif";
3422  if ($data["questionblock_id"] > 0)
3423  {
3424  $icontype = "questionblock.gif";
3425  }
3426  $this->tpl->setVariable("TYPE", "$type: ");
3427  include_once "./Services/Utilities/classes/class.ilUtil.php";
3428  $this->tpl->setVariable("ICON_HREF", ilUtil::getImagePath($icontype, "Modules/Survey"));
3429  $this->tpl->setVariable("ICON_ALT", $type);
3430  $this->tpl->parseCurrentBlock();
3431  $counter++;
3432  }
3433  }
3434  if ($rbacsystem->checkAccess("write", $this->ref_id) and !$hasDatasets)
3435  {
3436  if ($hasPreconditions)
3437  {
3438  $this->tpl->setCurrentBlock("selectall_preconditions");
3439  $this->tpl->setVariable("SELECT_ALL_PRECONDITIONS", $this->lng->txt("select_all"));
3440  $this->tpl->parseCurrentBlock();
3441  }
3442  $this->tpl->setCurrentBlock("selectall");
3443  $counter++;
3444  $this->tpl->setVariable("SELECT_ALL", $this->lng->txt("select_all"));
3445  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
3446  $this->tpl->parseCurrentBlock();
3447 
3448  if ($hasPreconditions)
3449  {
3450  $this->tpl->setCurrentBlock("delete_button");
3451  $this->tpl->setVariable("BTN_DELETE", $this->lng->txt("delete"));
3452  include_once "./Services/Utilities/classes/class.ilUtil.php";
3453  $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\">");
3454  $this->tpl->parseCurrentBlock();
3455  }
3456 
3457  $this->tpl->setCurrentBlock("buttons");
3458  $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\">");
3459  $this->tpl->setVariable("BTN_CREATE_CONSTRAINTS", $this->lng->txt("constraint_add"));
3460  $this->tpl->parseCurrentBlock();
3461  }
3462  $this->tpl->setCurrentBlock("adm_content");
3463  $this->tpl->setVariable("CONSTRAINTS_INTRODUCTION", $this->lng->txt("constraints_introduction"));
3464  $this->tpl->setVariable("DEFINED_PRECONDITIONS", $this->lng->txt("existing_constraints"));
3465  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "constraints"));
3466  $this->tpl->setVariable("CONSTRAINTS_HEADER", $this->lng->txt("constraints_list_of_entities"));
3467  $this->tpl->parseCurrentBlock();
3468  $_SESSION["constraintstructure"] = $structure;
3469  if ($hasDatasets)
3470  {
3471  // ilUtil::sendInfo($this->lng->txt("survey_has_datasets_warning"));
3472  $link = $this->ctrl->getLinkTarget($this, "maintenance");
3473  $link = "<a href=\"".$link."\">".$this->lng->txt("survey_has_datasets_warning_page_view_link")."</a>";
3474  ilUtil::sendInfo($this->lng->txt("survey_has_datasets_warning_page_view")." ".$link);
3475  }
3476  }
3477 
3483  function infoScreenObject()
3484  {
3485  $this->ctrl->setCmd("showSummary");
3486  $this->ctrl->setCmdClass("ilinfoscreengui");
3487  $this->infoScreen();
3488  }
3489 
3490  function setNewTemplate()
3491  {
3492  global $tpl;
3493  $tpl = new ilTemplate("tpl.il_svy_svy_main.html", TRUE, TRUE, "Modules/Survey");
3494  // load style sheet depending on user's settings
3495  $location_stylesheet = ilUtil::getStyleSheetLocation();
3496  $tpl->setVariable("LOCATION_STYLESHEET",$location_stylesheet);
3497  $tpl->setVariable("LOCATION_JAVASCRIPT",dirname($location_stylesheet));
3498  }
3499 
3503  function infoScreen()
3504  {
3505  global $ilAccess;
3506  global $ilUser;
3507 
3508  if (!$ilAccess->checkAccess("visible", "", $this->ref_id))
3509  {
3510  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
3511  }
3512 
3513  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
3514  $info = new ilInfoScreenGUI($this);
3515  include_once "./Modules/Survey/classes/class.ilSurveyExecutionGUI.php";
3516  $output_gui =& new ilSurveyExecutionGUI($this->object);
3517  $info->setFormAction($this->ctrl->getFormAction($output_gui, "infoScreen"));
3518  $info->enablePrivateNotes();
3519  $anonymize_key = NULL;
3520  if ($this->object->getAnonymize() == 1)
3521  {
3522  if ($_SESSION["anonymous_id"][$this->object->getId()])
3523  {
3524  $anonymize_key = $_SESSION["anonymous_id"][$this->object->getId()];
3525  }
3526  else if ($_POST["anonymous_id"])
3527  {
3528  $anonymize_key = $_POST["anonymous_id"];
3529  }
3530  }
3531  $canStart = $this->object->canStartSurvey($anonymize_key);
3532  $showButtons = $canStart["result"];
3533  if (!$showButtons)
3534  {
3535  if($canStart["edit_settings"] &&
3536  $ilAccess->checkAccess("write", "", $this->ref_id))
3537  {
3538  $canStart["messages"][] = "<a href=\"".$this->ctrl->getLinkTarget($this, "properties")."\">&raquo; ".
3539  $this->lng->txt("survey_edit_settings")."</a>";
3540  }
3541  ilUtil::sendInfo(implode("<br />", $canStart["messages"]));
3542  }
3543 
3544  $big_button = false;
3545  if ($showButtons)
3546  {
3547  // output of start/resume buttons for personalized surveys
3548  if (!$this->object->getAnonymize())
3549  {
3550  $survey_started = $this->object->isSurveyStarted($ilUser->getId(), "");
3551  // Anonymous User tries to start a personalized survey
3552  if ($_SESSION["AccountId"] == ANONYMOUS_USER_ID)
3553  {
3554  ilUtil::sendInfo($this->lng->txt("anonymous_with_personalized_survey"));
3555  }
3556  else
3557  {
3558  if ($survey_started === 1)
3559  {
3560  ilUtil::sendInfo($this->lng->txt("already_completed_survey"));
3561  }
3562  elseif ($survey_started === 0)
3563  {
3564  $big_button = array("resume", $this->lng->txt("resume_survey"));
3565  }
3566  elseif ($survey_started === FALSE)
3567  {
3568  $big_button = array("start", $this->lng->txt("start_survey"));
3569  }
3570  }
3571  }
3572  // output of start/resume buttons for anonymized surveys
3573  else if ($this->object->getAnonymize() && !$this->object->isAccessibleWithoutCode())
3574  {
3575  if (($_SESSION["AccountId"] == ANONYMOUS_USER_ID || $this->object->isAccessibleWithCodeForAll()) && (strlen($_POST["anonymous_id"]) == 0) && (strlen($_SESSION["anonymous_id"][$this->object->getId()]) == 0))
3576  {
3577  $info->setFormAction($this->ctrl->getFormAction($this, "infoScreen"));
3578  $info->addSection($this->lng->txt("anonymization"));
3579  $info->addProperty("", $this->lng->txt("anonymize_anonymous_introduction"));
3580  $info->addPropertyTextinput($this->lng->txt("enter_anonymous_id"), "anonymous_id", "", 8, "infoScreen", $this->lng->txt("submit"));
3581  }
3582  else
3583  {
3584  if (strlen($_POST["anonymous_id"]) > 0)
3585  {
3586  if (!$this->object->checkSurveyCode($_POST["anonymous_id"]))
3587  {
3588  ilUtil::sendInfo($this->lng->txt("wrong_survey_code_used"));
3589  }
3590  else
3591  {
3592  $anonymize_key = $_POST["anonymous_id"];
3593  }
3594  }
3595  else if (strlen($_SESSION["anonymous_id"][$this->object->getId()]) > 0)
3596  {
3597  if (!$this->object->checkSurveyCode($_SESSION["anonymous_id"][$this->object->getId()]))
3598  {
3599  ilUtil::sendInfo($this->lng->txt("wrong_survey_code_used"));
3600  }
3601  else
3602  {
3603  $anonymize_key = $_SESSION["anonymous_id"][$this->object->getId()];
3604  }
3605  }
3606  else
3607  {
3608  // registered users do not need to know that there is an anonymous key. The data is anonymized automatically
3609  $anonymize_key = $this->object->getUserAccessCode($ilUser->getId());
3610  if (!strlen($anonymize_key))
3611  {
3612  $anonymize_key = $this->object->createNewAccessCode();
3613  $this->object->saveUserAccessCode($ilUser->getId(), $anonymize_key);
3614  }
3615  }
3616  $info->addHiddenElement("anonymous_id", $anonymize_key);
3617  $survey_started = $this->object->isSurveyStarted($ilUser->getId(), $anonymize_key);
3618  if ($survey_started === 1)
3619  {
3620  ilUtil::sendInfo($this->lng->txt("already_completed_survey"));
3621  }
3622  elseif ($survey_started === 0)
3623  {
3624  $big_button = array("resume", $this->lng->txt("resume_survey"));
3625  }
3626  elseif ($survey_started === FALSE)
3627  {
3628  $big_button = array("start", $this->lng->txt("start_survey"));
3629  }
3630  }
3631  }
3632  else
3633  {
3634  // free access
3635  $survey_started = $this->object->isSurveyStarted($ilUser->getId(), "");
3636  if ($survey_started === 1)
3637  {
3638  ilUtil::sendInfo($this->lng->txt("already_completed_survey"));
3639  }
3640  elseif ($survey_started === 0)
3641  {
3642  $big_button = array("resume", $this->lng->txt("resume_survey"));
3643  }
3644  elseif ($survey_started === FALSE)
3645  {
3646  $big_button = array("start", $this->lng->txt("start_survey"));
3647  }
3648  }
3649  }
3650 
3651  if($big_button)
3652  {
3653  $big_button = '<div class="il_ButtonGroup" style="margin:25px; text-align:center; font-size:25px;">'.
3654  '<input type="submit" class="submit" name="cmd['.$big_button[0].']" value="'.
3655  $big_button[1].'" style="padding:10px;" /></div>';
3656  }
3657 
3658  if (strlen($this->object->getIntroduction()))
3659  {
3660  $introduction = $this->object->getIntroduction();
3661  $info->addSection($this->lng->txt("introduction"));
3662  $info->addProperty("", $this->object->prepareTextareaOutput($introduction).
3663  $big_button."<br />".$info->getHiddenToggleButton());
3664  }
3665  else
3666  {
3667  $info->addSection("");
3668  $info->addProperty("", $big_button.$info->getHiddenToggleButton());
3669  }
3670 
3671  $info->hideFurtherSections(false);
3672 
3673  $info->addSection($this->lng->txt("svy_general_properties"));
3674  if (strlen($this->object->getAuthor()))
3675  {
3676  $info->addProperty($this->lng->txt("author"), $this->object->getAuthor());
3677  }
3678  $info->addProperty($this->lng->txt("title"), $this->object->getTitle());
3679  switch ($this->object->getAnonymize())
3680  {
3681  case ANONYMIZE_OFF:
3682  $info->addProperty($this->lng->txt("anonymization"), $this->lng->txt("anonymize_personalized"));
3683  break;
3684  case ANONYMIZE_ON:
3685  if ($_SESSION["AccountId"] == ANONYMOUS_USER_ID)
3686  {
3687  $info->addProperty($this->lng->txt("anonymization"), $this->lng->txt("info_anonymize_with_code"));
3688  }
3689  else
3690  {
3691  $info->addProperty($this->lng->txt("anonymization"), $this->lng->txt("info_anonymize_registered_user"));
3692  }
3693  break;
3694  case ANONYMIZE_FREEACCESS:
3695  $info->addProperty($this->lng->txt("anonymization"), $this->lng->txt("info_anonymize_without_code"));
3696  break;
3697  }
3698  include_once "./Modules/Survey/classes/class.ilObjSurveyAccess.php";
3699  if ($ilAccess->checkAccess("write", "", $this->ref_id) || ilObjSurveyAccess::_hasEvaluationAccess($this->object->getId(), $ilUser->getId()))
3700  {
3701  $info->addProperty($this->lng->txt("evaluation_access"), $this->lng->txt("evaluation_access_info"));
3702  }
3703  $info->addMetaDataSections($this->object->getId(),0, $this->object->getType());
3704  $this->ctrl->forwardCommand($info);
3705  }
3706 
3712  function printViewObject()
3713  {
3714  global $ilias;
3715 
3716  $this->questionsSubtabs("printview");
3717  $template = new ilTemplate("tpl.il_svy_svy_printview.html", TRUE, TRUE, "Modules/Survey");
3718 
3719  include_once './Services/WebServices/RPC/classes/class.ilRPCServerSettings.php';
3720  if(ilRPCServerSettings::getInstance()->isEnabled())
3721  {
3722  $this->ctrl->setParameter($this, "pdf", "1");
3723  $template->setCurrentBlock("pdf_export");
3724  $template->setVariable("PDF_URL", $this->ctrl->getLinkTarget($this, "printView"));
3725  $this->ctrl->setParameter($this, "pdf", "");
3726  $template->setVariable("PDF_TEXT", $this->lng->txt("pdf_export"));
3727  $template->setVariable("PDF_IMG_ALT", $this->lng->txt("pdf_export"));
3728  $template->setVariable("PDF_IMG_URL", ilUtil::getHtmlPath(ilUtil::getImagePath("application-pdf.png")));
3729  $template->parseCurrentBlock();
3730  }
3731  $template->setVariable("PRINT_TEXT", $this->lng->txt("print"));
3732  $template->setVariable("PRINT_URL", "javascript:window.print();");
3733 
3734  $pages =& $this->object->getSurveyPages();
3735  foreach ($pages as $page)
3736  {
3737  if (count($page) > 0)
3738  {
3739  foreach ($page as $question)
3740  {
3741  $questionGUI = $this->object->getQuestionGUI($question["type_tag"], $question["question_id"]);
3742  if (is_object($questionGUI))
3743  {
3744  if (strlen($question["heading"]))
3745  {
3746  $template->setCurrentBlock("textblock");
3747  $template->setVariable("TEXTBLOCK", $question["heading"]);
3748  $template->parseCurrentBlock();
3749  }
3750  $template->setCurrentBlock("question");
3751  $template->setVariable("QUESTION_DATA", $questionGUI->getPrintView($this->object->getShowQuestionTitles(), $question["questionblock_show_questiontext"], $this->object->getSurveyId()));
3752  $template->parseCurrentBlock();
3753  }
3754  }
3755  if (count($page) > 1)
3756  {
3757  $template->setCurrentBlock("page");
3758  $template->setVariable("BLOCKTITLE", $page[0]["questionblock_title"]);
3759  $template->parseCurrentBlock();
3760  }
3761  else
3762  {
3763  $template->setCurrentBlock("page");
3764  $template->parseCurrentBlock();
3765  }
3766  }
3767  }
3768  $this->tpl->addCss("./Modules/Survey/templates/default/survey_print.css", "print");
3769  if (array_key_exists("pdf", $_GET) && ($_GET["pdf"] == 1))
3770  {
3771  $printbody = new ilTemplate("tpl.il_as_tst_print_body.html", TRUE, TRUE, "Modules/Test");
3772  $printbody->setVariable("TITLE", sprintf($this->lng->txt("tst_result_user_name"), $uname));
3773  $printbody->setVariable("ADM_CONTENT", $template->get());
3774  $printoutput = $printbody->get();
3775  $printoutput = preg_replace("/href=\".*?\"/", "", $printoutput);
3776  $fo = $this->object->processPrintoutput2FO($printoutput);
3777  $this->object->deliverPDFfromFO($fo);
3778  }
3779  else
3780  {
3781  $this->tpl->setVariable("ADM_CONTENT", $template->get());
3782  }
3783  }
3784 
3785  function addLocatorItems()
3786  {
3787  global $ilLocator;
3788  switch ($this->ctrl->getCmd())
3789  {
3790  case "next":
3791  case "previous":
3792  case "start":
3793  case "resume":
3794  case "redirectQuestion":
3795  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "infoScreen"), "", $_GET["ref_id"]);
3796  break;
3797  case "evaluation":
3798  case "checkEvaluationAccess":
3799  case "evaluationdetails":
3800  case "evaluationuser":
3801  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "evaluation"), "", $_GET["ref_id"]);
3802  break;
3803  case "create":
3804  case "save":
3805  case "cancel":
3806  case "importFile":
3807  case "cloneAll":
3808  break;
3809  case "infoScreen":
3810  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "infoScreen"), "", $_GET["ref_id"]);
3811  break;
3812  default:
3813  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, ""), "", $_GET["ref_id"]);
3814  break;
3815  }
3816  }
3817 
3825  function questionsSubtabs($a_cmd)
3826  {
3827  $questions_per_page = ($a_cmd == 'questions_per_page') ? true : false;
3828  $questions = ($a_cmd == 'questions') ? true : false;
3829  $printview = ($a_cmd == 'printview') ? true : false;
3830 
3831  $hidden_tabs = array();
3832  $template = $this->object->getTemplate();
3833  if($template)
3834  {
3835  include_once "Services/Administration/classes/class.ilSettingsTemplate.php";
3836  $template = new ilSettingsTemplate($template);
3837  $hidden_tabs = $template->getHiddenTabs();
3838  }
3839 
3840  $this->tabs_gui->addSubTabTarget("survey_per_page_view", $this->ctrl->getLinkTargetByClass("ilsurveypagegui", "renderPage"),
3841  "", "", "", $questions_per_page);
3842 
3843  if(!in_array("survey_question_editor", $hidden_tabs))
3844  {
3845  $this->ctrl->setParameter($this, "pgov", "");
3846  $this->tabs_gui->addSubTabTarget("survey_question_editor", $this->ctrl->getLinkTarget($this, "questions"),
3847  "", "", "", $questions);
3848  $this->ctrl->setParameter($this, "pgov", $_REQUEST["pgov"]);
3849  }
3850 
3851  $this->tabs_gui->addSubTabTarget("print_view", $this->ctrl->getLinkTarget($this, "printView"),
3852  "", "", "", $printview);
3853 
3854  if($this->object->getSurveyPages())
3855  {
3856  if($questions_per_page)
3857  {
3858  $this->ctrl->setParameterByClass("ilsurveyexecutiongui", "pgov", max(1, $_REQUEST["pg"]));
3859  }
3860  $this->ctrl->setParameterByClass("ilsurveyexecutiongui", "prvw", 1);
3861  $this->tabs_gui->addSubTabTarget("preview", $this->ctrl->getLinkTargetByClass("ilsurveyexecutiongui", "preview"),
3862  "", "", "", false);
3863  }
3864  }
3865 
3871  function setCodesSubtabs()
3872  {
3873  global $ilTabs;
3874  global $ilAccess;
3875 
3876  $ilTabs->addSubTabTarget
3877  (
3878  "codes",
3879  $this->ctrl->getLinkTarget($this,'codes'),
3880  array("codes", "createSurveyCodes", "setCodeLanguage", "deleteCodes", "exportCodes"),
3881  ""
3882  );
3883 
3884  $ilTabs->addSubTabTarget
3885  (
3886  "participating_users",
3887  $this->ctrl->getLinkTarget($this, "codesMail"),
3888  array("codesMail", "saveMailTableFields", "importExternalMailRecipients",
3889  'importExternalRecipientsFromFile', 'importExternalRecipientsFromText',
3890  'importExternalRecipientsFromDataset'),
3891  ""
3892  );
3893 
3894  $data = $this->object->getExternalCodeRecipients();
3895  if (count($data))
3896  {
3897  $ilTabs->addSubTabTarget
3898  (
3899  "mail_survey_codes",
3900  $this->ctrl->getLinkTarget($this, "mailCodes"),
3901  array("mailCodes", "sendCodesMail", "insertSavedMessage", "deleteSavedMessage"),
3902  ""
3903  );
3904  }
3905  }
3906 
3912  function setEvalSubtabs()
3913  {
3914  global $ilTabs;
3915  global $ilAccess;
3916 
3917  $ilTabs->addSubTabTarget(
3918  "svy_eval_cumulated",
3919  $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "evaluation"),
3920  array("evaluation", "checkEvaluationAccess"),
3921  ""
3922  );
3923 
3924  $ilTabs->addSubTabTarget(
3925  "svy_eval_detail",
3926  $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "evaluationdetails"),
3927  array("evaluationdetails"),
3928  ""
3929  );
3930 
3931  if ($ilAccess->checkAccess("write", "", $this->object->getRefId()))
3932  {
3933  $ilTabs->addSubTabTarget(
3934  "svy_eval_user",
3935  $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "evaluationuser"),
3936  array("evaluationuser"),
3937  ""
3938  );
3939  }
3940  }
3941 
3943  {
3944  global $ilAccess;
3945  global $ilTabs;
3946 
3947  if ($ilAccess->checkAccess("write", "", $this->ref_id))
3948  {
3949  if(!isset($_REQUEST["pgov"]))
3950  {
3951  $link = $this->ctrl->getLinkTarget($this, "questions");
3952  }
3953  else
3954  {
3955  $link = $this->ctrl->getLinkTargetByClass("ilsurveypagegui", "renderpage");
3956  }
3957  $ilTabs->setBackTarget($this->lng->txt("menubacktosurvey"), $link);
3958  $ilTabs->addTarget("browse_for_questions",
3959  $this->ctrl->getLinkTarget($this, "browseForQuestions"),
3960  array("browseForQuestions", "browseForQuestionblocks"),
3961  "", ""
3962  );
3963  }
3964  }
3965 
3971  function getTabs(&$tabs_gui)
3972  {
3973  global $ilAccess, $ilUser;
3974 
3975  if (strcmp($this->ctrl->getNextClass(), 'ilrepositorysearchgui') != 0)
3976  {
3977  switch ($this->ctrl->getCmd())
3978  {
3979  case "browseForQuestions":
3980  case "browseForQuestionblocks":
3981  case "insertQuestions":
3982  case "filterQuestions":
3983  case "resetFilterQuestions":
3984  case "changeDatatype":
3985  case "start":
3986  case "resume":
3987  case "next":
3988  case "previous":
3989  case "redirectQuestion":
3990  case "preview":
3991  return;
3992 
3993  case "evaluation":
3994  case "checkEvaluationAccess":
3995  case "evaluationdetails":
3996  case "evaluationuser":
3997  $this->setEvalSubtabs();
3998  break;
3999  }
4000  }
4001 
4002  $hidden_tabs = array();
4003  $template = $this->object->getTemplate();
4004  if($template)
4005  {
4006  include_once "Services/Administration/classes/class.ilSettingsTemplate.php";
4007  $template = new ilSettingsTemplate($template);
4008  $hidden_tabs = $template->getHiddenTabs();
4009  }
4010 
4011  // questions
4012  if ($ilAccess->checkAccess("write", "", $this->ref_id))
4013  {
4014  $force_active = ($_GET["up"] != "" || $_GET["down"] != "")
4015  ? true
4016  : false;
4017 
4018  $cmd = $this->ctrl->getLinkTargetByClass("ilsurveypagegui", "renderPage");
4019  // $cmd = $this->ctrl->getLinkTarget($this, "questions");
4020 
4021  $tabs_gui->addTarget("survey_questions",
4022  $cmd,
4023  array("questions", "browseForQuestions", "createQuestion",
4024  "filterQuestions", "resetFilterQuestions", "changeDatatype", "insertQuestions",
4025  "removeQuestions", "cancelRemoveQuestions", "confirmRemoveQuestions",
4026  "defineQuestionblock", "saveDefineQuestionblock", "cancelDefineQuestionblock",
4027  "unfoldQuestionblock", "moveQuestions",
4028  "insertQuestionsBefore", "insertQuestionsAfter", "saveObligatory",
4029  "addHeading", "saveHeading", "cancelHeading", "editHeading",
4030  "confirmRemoveHeading", "cancelRemoveHeading", "printView", "renderPage",
4031  "addQuestionToolbarForm", "deleteBlock", "movePageForm", "copyQuestionsToPool"),
4032  "", "", $force_active);
4033  }
4034 
4035  if ($ilAccess->checkAccess("visible", "", $this->ref_id))
4036  {
4037  $tabs_gui->addTarget("info_short",
4038  $this->ctrl->getLinkTarget($this,'infoScreen'),
4039  array("infoScreen", "showSummary"));
4040  }
4041 
4042  // properties
4043  if ($ilAccess->checkAccess("write", "", $this->ref_id))
4044  {
4045  $force_active = ($this->ctrl->getCmd() == "")
4046  ? true
4047  : false;
4048  $tabs_gui->addTarget("settings",
4049  $this->ctrl->getLinkTarget($this,'properties'),
4050  array("properties", "save", "cancel", 'saveProperties'), "",
4051  "", $force_active);
4052  }
4053 
4054  // questions
4055  if ($ilAccess->checkAccess("write", "", $this->ref_id) &&
4056  !in_array("constraints", $hidden_tabs))
4057  {
4058  // constraints
4059  $tabs_gui->addTarget("constraints",
4060  $this->ctrl->getLinkTarget($this, "constraints"),
4061  array("constraints", "constraintStep1", "constraintStep2",
4062  "constraintStep3", "constraintsAdd", "createConstraints",
4063  "editPrecondition"),
4064  "");
4065  }
4066 
4067  if (($ilAccess->checkAccess("write", "", $this->ref_id) || $ilAccess->checkAccess("invite", "", $this->ref_id)) &&
4068  !in_array("invitation", $hidden_tabs))
4069  {
4070  // invite
4071  $tabs_gui->addTarget("invitation",
4072  $this->ctrl->getLinkTarget($this, 'invite'),
4073  array("invite", "saveInvitationStatus",
4074  "inviteUserGroup", "disinviteUserGroup"),
4075  "");
4076  }
4077 
4078  if ($ilAccess->checkAccess("write", "", $this->ref_id))
4079  {
4080  // maintenance
4081  $tabs_gui->addTarget("maintenance",
4082  $this->ctrl->getLinkTarget($this,'maintenance'),
4083  array("maintenance", "deleteAllUserData"),
4084  "");
4085 
4086  if ($this->object->getAnonymize() == 1 || $this->object->isAccessibleWithCodeForAll())
4087  {
4088  // code
4089  $tabs_gui->addTarget("codes",
4090  $this->ctrl->getLinkTarget($this,'codes'),
4091  array("codes", "exportCodes", 'codesMail', 'saveMailTableFields', 'importExternalMailRecipients',
4092  'mailCodes', 'sendCodesMail', 'importExternalRecipientsFromFile', 'importExternalRecipientsFromText',
4093  'importExternalRecipientsFromDataset', 'insertSavedMessage', 'deleteSavedMessage'),
4094  "");
4095  }
4096  }
4097 
4098  include_once "./Modules/Survey/classes/class.ilObjSurveyAccess.php";
4099  if ($ilAccess->checkAccess("write", "", $this->ref_id) || ilObjSurveyAccess::_hasEvaluationAccess($this->object->getId(), $ilUser->getId()))
4100  {
4101  // evaluation
4102  $tabs_gui->addTarget("svy_evaluation",
4103  $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "evaluation"),
4104  array("evaluation", "checkEvaluationAccess", "evaluationdetails",
4105  "evaluationuser"),
4106  "");
4107  }
4108 
4109  if ($ilAccess->checkAccess("write", "", $this->ref_id))
4110  {
4111  if(!in_array("meta_data", $hidden_tabs))
4112  {
4113  // meta data
4114  $tabs_gui->addTarget("meta_data",
4115  $this->ctrl->getLinkTargetByClass('ilmdeditorgui','listSection'),
4116  "", "ilmdeditorgui");
4117  }
4118 
4119  if(!in_array("export", $hidden_tabs))
4120  {
4121  // export
4122  $tabs_gui->addTarget("export",
4123  $this->ctrl->getLinkTarget($this,'export'),
4124  array("export", "createExportFile", "confirmDeleteExportFile",
4125  "downloadExportFile"),
4126  ""
4127  );
4128  }
4129  }
4130 
4131  if ($ilAccess->checkAccess("edit_permission", "", $this->ref_id))
4132  {
4133  // permissions
4134  $tabs_gui->addTarget("perm_settings",
4135  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), array("perm","info","owner"), 'ilpermissiongui');
4136  }
4137  }
4138 
4144  function _goto($a_target, $a_access_code = "")
4145  {
4146  global $ilAccess, $ilErr, $lng;
4147  if ($ilAccess->checkAccess("read", "", $a_target))
4148  {
4149  include_once "./Services/Utilities/classes/class.ilUtil.php";
4150  if (strlen($a_access_code))
4151  {
4152  $_SESSION["anonymous_id"][ilObject::_lookupObjId($a_target)] = $a_access_code;
4153  $_GET["baseClass"] = "ilObjSurveyGUI";
4154  $_GET["cmd"] = "infoScreen";
4155  $_GET["ref_id"] = $a_target;
4156  include("ilias.php");
4157  exit;
4158  }
4159  else
4160  {
4161  $_GET["baseClass"] = "ilObjSurveyGUI";
4162  $_GET["cmd"] = "infoScreen";
4163  $_GET["ref_id"] = $a_target;
4164  include("ilias.php");
4165  exit;
4166  }
4167  }
4168  else if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
4169  {
4170  $_GET["cmd"] = "frameset";
4171  $_GET["target"] = "";
4172  $_GET["ref_id"] = ROOT_FOLDER_ID;
4173  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
4174  ilObject::_lookupTitle(ilObject::_lookupObjId($a_target))), true);
4175  include("repository.php");
4176  exit;
4177  }
4178 
4179  $ilErr->raiseError($lng->txt("msg_no_perm_read_lm"), $ilErr->FATAL);
4180  }
4181 
4186  {
4187  ilUtil::sendQuestion($this->lng->txt("survey_confirm_template_reset"));
4188  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_confirm_resettemplate.html", "Modules/Survey");
4189  $this->tpl->setCurrentBlock("adm_content");
4190  $this->tpl->setVariable("BTN_CONFIRM_REMOVE", $this->lng->txt("confirm"));
4191  $this->tpl->setVariable("BTN_CANCEL_REMOVE", $this->lng->txt("cancel"));
4192  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "resetTemplateObject"));
4193  $this->tpl->parseCurrentBlock();
4194  }
4195 
4200  {
4201  $this->object->setTemplate(null);
4202  $this->object->saveToDB();
4203 
4204  ilUtil::sendSuccess($this->lng->txt("survey_template_reset"), true);
4205  $this->ctrl->redirect($this, "properties");
4206  }
4207 
4208 
4212  public function copyQuestionsToPoolObject()
4213  {
4214  $items = $this->gatherSelectedTableItems(true, true, false, true);
4215 
4216  // gather questions from blocks
4217  $copy_questions = $items["questions"];
4218  foreach ($items["blocks"] as $block_id)
4219  {
4220  foreach ($this->object->getQuestionblockQuestionIds($block_id) as $qid)
4221  {
4222  array_push($copy_questions, $qid);
4223  }
4224  }
4225  $copy_questions = array_unique($copy_questions);
4226 
4227  // only if not already in pool
4228  if (count($copy_questions))
4229  {
4230  foreach($copy_questions as $idx => $question_id)
4231  {
4232  $question = ilObjSurvey::_instanciateQuestion($question_id);
4233  if($question->getOriginalId())
4234  {
4235  unset($copy_questions[$idx]);
4236  }
4237  }
4238 
4239  }
4240  if (count($copy_questions) == 0)
4241  {
4242  ilUtil::sendInfo($this->lng->txt("no_question_selected_for_copy_to_pool"), true);
4243  $this->ctrl->redirect($this, "questions");
4244  }
4245  else
4246  {
4247  $this->questionsSubtabs("questions");
4248 
4249  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
4250  $form = new ilPropertyFormGUI();
4251 
4252  $form->setFormAction($this->ctrl->getFormAction($this, "executeCreateQuestion"));
4253 
4254  $ids = new ilHiddenInputGUI("question_ids");
4255  $ids->setValue(implode(";", $copy_questions));
4256  $form->addItem($ids);
4257 
4258  $questionpools =& $this->object->getAvailableQuestionpools(false, false, true, "write");
4259  $pools = new ilSelectInputGUI($this->lng->txt("survey_copy_select_questionpool"), "sel_spl");
4260  $pools->setOptions($questionpools);
4261  $form->addItem($pools);
4262 
4263  $form->addCommandButton("executeCopyQuestionsToPool", $this->lng->txt("submit"));
4264  $form->addCommandButton("questions", $this->lng->txt("cancel"));
4265 
4266  return $this->tpl->setContent($form->getHTML());
4267  }
4268  }
4269 
4274  {
4275  $question_ids = explode(";", $_POST["question_ids"]);
4276  $pool_id = ilObject::_lookupObjId($_POST["sel_spl"]);
4277 
4278  foreach($question_ids as $qid)
4279  {
4280  // create copy (== pool "original")
4281  $new_question = ilObjSurvey::_instanciateQuestion($qid);
4282  $new_question->setId();
4283  $new_question->setObjId($pool_id);
4284  $new_question->saveToDb();
4285 
4286  // link "source" (survey) to copy (pool)
4287  SurveyQuestion::_changeOriginalId($qid, $new_question->getId(), $pool_id);
4288  }
4289 
4290  ilUtil::sendSuccess($this->lng->txt("survey_copy_to_questionpool_success"), true);
4291  $this->ctrl->redirect($this, "questions");
4292  }
4293 
4294 } // END class.ilObjSurveyGUI
4295 ?>