ILIAS  eassessment Revision 61809
 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  $lng->loadLanguageModule("mail"); // Change Sn
57  $this->ctrl =& $ilCtrl;
58  $this->ctrl->saveParameter($this, "ref_id");
59 
60  $this->ilObjectGUI("",$_GET["ref_id"], true, false);
61  }
62 
64  {
65  include_once "./Services/Utilities/classes/class.ilUtil.php";
66  $path = $this->tree->getPathFull($this->object->getRefID());
67  ilUtil::redirect($this->getReturnLocation("cancel","./repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
68  }
69 
73  function executeCommand()
74  {
75  global $ilAccess, $ilNavigationHistory,$ilCtrl;
76 
77  if ((!$ilAccess->checkAccess("read", "", $_GET["ref_id"])) && (!$ilAccess->checkAccess("visible", "", $_GET["ref_id"])))
78  {
79  global $ilias;
80  $ilias->raiseError($this->lng->txt("permission_denied"), $ilias->error_obj->MESSAGE);
81  }
82  // add entry to navigation history
83  if (!$this->getCreationMode() &&
84  $ilAccess->checkAccess("read", "", $_GET["ref_id"]))
85  {
86  $ilNavigationHistory->addItem($_GET["ref_id"],
87  "ilias.php?baseClass=ilObjSurveyGUI&cmd=infoScreen&ref_id=".$_GET["ref_id"], "svy");
88  }
89 
90  $cmd = $this->ctrl->getCmd("properties");
91 
92  // workaround for bug #6288, needs better solution
93  if ($cmd == "saveTags")
94  {
95  $ilCtrl->setCmdClass("ilinfoscreengui");
96  }
97 
98  $next_class = $this->ctrl->getNextClass($this);
99  $this->ctrl->setReturn($this, "properties");
100  $this->tpl->addCss(ilUtil::getStyleSheetLocation("output", "survey.css", "Modules/Survey"), "screen");
101  $this->prepareOutput();
102  //echo "<br>nextclass:$next_class:cmd:$cmd:qtype=$q_type";
103  switch($next_class)
104  {
105  case "ilinfoscreengui":
106  $this->infoScreen(); // forwards command
107  break;
108  case 'ilmdeditorgui':
109  include_once 'Services/MetaData/classes/class.ilMDEditorGUI.php';
110  $md_gui =& new ilMDEditorGUI($this->object->getId(), 0, $this->object->getType());
111  $md_gui->addObserver($this->object,'MDUpdateListener','General');
112 
113  $this->ctrl->forwardCommand($md_gui);
114  break;
115 
116  case "ilsurveyevaluationgui":
117  include_once("./Modules/Survey/classes/class.ilSurveyEvaluationGUI.php");
118  $eval_gui = new ilSurveyEvaluationGUI($this->object);
119  $ret =& $this->ctrl->forwardCommand($eval_gui);
120  break;
121 
122  case 'ilrepositorysearchgui':
123  include_once('./Services/Search/classes/class.ilRepositorySearchGUI.php');
124  $rep_search =& new ilRepositorySearchGUI();
125  $rep_search->setCallback($this,
126  'inviteUserGroupObject',
127  array(
128  )
129  );
130 
131  // Set tabs
132  $this->ctrl->setReturn($this, 'invite');
133  $ret =& $this->ctrl->forwardCommand($rep_search);
134  $this->tabs_gui->setTabActive('invitation');
135  break;
136 
137  case "ilsurveyexecutiongui":
138  include_once("./Modules/Survey/classes/class.ilSurveyExecutionGUI.php");
139  $exec_gui = new ilSurveyExecutionGUI($this->object);
140  $ret =& $this->ctrl->forwardCommand($exec_gui);
141  break;
142 
143  case 'ilpermissiongui':
144  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
145  $perm_gui =& new ilPermissionGUI($this);
146  $ret =& $this->ctrl->forwardCommand($perm_gui);
147  break;
148 
149  case 'ilobjectcopygui':
150  include_once './Services/Object/classes/class.ilObjectCopyGUI.php';
151  $cp = new ilObjectCopyGUI($this);
152  $cp->setType('svy');
153  $this->ctrl->forwardCommand($cp);
154  break;
155 
156 
157  default:
158  $cmd.= "Object";
159  $ret =& $this->$cmd();
160  break;
161  }
162 
163  if (strtolower($_GET["baseClass"]) != "iladministrationgui" &&
164  $this->getCreationMode() != true)
165  {
166  $this->tpl->show();
167  }
168  }
169 
174  function saveObject()
175  {
176  global $rbacadmin;
177 
178  if (!strlen($_POST['Fobject']['title']))
179  {
180  ilUtil::sendFailure($this->lng->txt('title_required'), true);
181  $this->ctrl->setParameter($this, 'new_type', $_GET['new_type']);
182  $this->ctrl->redirect($this, 'create');
183  }
184 
185  // create and insert forum in objecttree
186  $newObj = parent::saveObject();
187  // always send a message
188  ilUtil::sendSuccess($this->lng->txt("object_added"),true);
189  ilUtil::redirect("ilias.php?baseClass=ilObjSurveyGUI&ref_id=".$newObj->getRefId()."&cmd=properties");
190  }
191 
197  function cancelObject($in_rep = false)
198  {
199  ilUtil::redirect("repository.php?cmd=frameset&ref_id=".$_GET["ref_id"]);
200  }
201 
210  {
211  $this->ctrl->redirect($this, "properties");
212  }
213 
221  function handleWriteAccess()
222  {
223  global $ilAccess;
224  if (!$ilAccess->checkAccess("write", "", $this->ref_id))
225  {
226  // allow only write access
227  ilUtil::sendInfo($this->lng->txt("cannot_edit_survey"), TRUE);
228  $this->ctrl->redirect($this, "infoScreen");
229  }
230  }
231 
240  {
241  $hasErrors = $this->propertiesObject(true);
242  if (!$hasErrors)
243  {
244  $result = $this->object->setStatus($_POST['online']);
245  $this->object->setEvaluationAccess($_POST["evaluation_access"]);
246  $this->object->setStartDateEnabled($_POST["enabled_start_date"]);
247  if ($this->object->getStartDateEnabled())
248  {
249  $this->object->setStartDateAndTime($_POST["start_date"]['date'], $_POST["start_date"]['time']);
250  }
251  else
252  {
253  $this->object->setStartDate(null);
254  }
255  $this->object->setEndDateEnabled($_POST["enabled_end_date"]);
256  if ($this->object->getEndDateEnabled())
257  {
258  $this->object->setEndDateAndTime($_POST["end_date"]['date'], $_POST["end_date"]['time']);
259  }
260  else
261  {
262  $this->object->setEndDate(null);
263  }
264 
265  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
266  $introduction = $_POST["introduction"];
267  $this->object->setIntroduction($introduction);
268  $outro = $_POST["outro"];
269  $this->object->setOutro($outro);
270  /* Change Sn */
271  $this->object->setRedirectAfterSurvey($_POST["redirect_after_survey"]);
272  $redirect_only_kiosk_mode = ($_POST["redirect_only_kiosk_mode"] ? 1 : 0);
273  $this->object->setRedirectOnlyKioskMode($redirect_only_kiosk_mode);
274  $mail_confirmation = ($_POST["mail_confirmation"] ? 1 : 0);
275  $this->object->setMailConfirmation($mail_confirmation);
276  $this->object->setMailConfirmationSubject($_POST["mail_confirmation_subject"]);
277  //$mail_confirmation_body = ilUtil::stripSlashes($_POST["mail_confirmation_body"], true, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("survey"));
278  $mail_confirmation_body = $_POST["mail_confirmation_body"];
279  $this->object->setMailConfirmationBody($mail_confirmation_body);
280  /* Change Sn End */
281  $hasDatasets = $this->object->_hasDatasets($this->object->getSurveyId());
282  if (!$hasDatasets)
283  {
284  $anonymize = $_POST["anonymization"];
285  if ($anonymize)
286  {
287  if (strcmp($_POST['anonymization_options'], 'anonymize_without_code') == 0) $anonymize = ANONYMIZE_FREEACCESS;
288  }
289  $this->object->setAnonymize($anonymize);
290  }
291  $this->object->setShowQuestionTitles($_POST["show_question_titles"]);
292  $this->object->setMailNotification($_POST['mailnotification']);
293  $this->object->setMailAddresses($_POST['mailaddresses']);
294  $this->object->setMailParticipantData($_POST['mailparticipantdata']);
295  $this->object->saveToDb();
296  if (strcmp($_SESSION["info"], "") != 0)
297  {
298  ilUtil::sendSuccess($_SESSION["info"] . "<br />" . $this->lng->txt("settings_saved"), true);
299  }
300  else
301  {
302  ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
303  }
304  $this->ctrl->redirect($this, "properties");
305  }
306  }
307 
313  function propertiesObject($checkonly = FALSE)
314  {
315  global $ilAccess;
316 
317  $save = (strcmp($this->ctrl->getCmd(), "saveProperties") == 0) ? TRUE : FALSE;
318 
319  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
320  $form = new ilPropertyFormGUI();
321  $form->setFormAction($this->ctrl->getFormAction($this));
322  $form->setTableWidth("100%");
323  $form->setId("survey_properties");
324 
325  // general properties
326  $header = new ilFormSectionHeaderGUI();
327  $header->setTitle($this->lng->txt("properties"));
328  $form->addItem($header);
329 
330  // online
331  $online = new ilCheckboxInputGUI($this->lng->txt("online"), "online");
332  $online->setValue(1);
333  $online->setChecked($this->object->isOnline());
334  $form->addItem($online);
335 
336  // introduction
337  $intro = new ilTextAreaInputGUI($this->lng->txt("introduction"), "introduction");
338  $intro->setValue($this->object->prepareTextareaOutput($this->object->getIntroduction()));
339  $intro->setRows(10);
340  $intro->setCols(80);
341  $intro->setUseRte(TRUE);
342  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
343  $intro->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("survey"));
344  $intro->addPlugin("latex");
345  $intro->addButton("latex");
346  $intro->addPlugin("pastelatex");
347  $intro->setRTESupport($this->object->getId(), "svy", "survey");
348  $form->addItem($intro);
349 
350  // enable start date
351  $enablestartingtime = new ilCheckboxInputGUI($this->lng->txt("start_date"), "enabled_start_date");
352  $enablestartingtime->setValue(1);
353  $enablestartingtime->setOptionTitle($this->lng->txt("enabled"));
354  $enablestartingtime->setChecked($this->object->getStartDateEnabled());
355  // start date
356  $startingtime = new ilDateTimeInputGUI('', 'start_date');
357  $startingtime->setShowDate(true);
358  $startingtime->setShowTime(true);
359  if ($this->object->getStartDateEnabled())
360  {
361  $startingtime->setDate(new ilDate($this->object->getStartDate(), IL_CAL_DATE));
362  }
363  else
364  {
365  $startingtime->setDate(new ilDate(time(), IL_CAL_UNIX));
366  }
367  $enablestartingtime->addSubItem($startingtime);
368  $form->addItem($enablestartingtime);
369 
370  // enable end date
371  $enableendingtime = new ilCheckboxInputGUI($this->lng->txt("end_date"), "enabled_end_date");
372  $enableendingtime->setValue(1);
373  $enableendingtime->setOptionTitle($this->lng->txt("enabled"));
374  $enableendingtime->setChecked($this->object->getEndDateEnabled());
375  // end date
376  $endingtime = new ilDateTimeInputGUI('', 'end_date');
377  $endingtime->setShowDate(true);
378  $endingtime->setShowTime(true);
379  if ($this->object->getEndDateEnabled())
380  {
381  $endingtime->setDate(new ilDate($this->object->getEndDate(), IL_CAL_DATE));
382  }
383  else
384  {
385  $endingtime->setDate(new ilDate(time(), IL_CAL_UNIX));
386  }
387  $enableendingtime->addSubItem($endingtime);
388  $form->addItem($enableendingtime);
389 
390  // anonymization
391  $anonymization = new ilCheckboxInputGUI($this->lng->txt("anonymization"), "anonymization");
392  $hasDatasets = $this->object->_hasDatasets($this->object->getSurveyId());
393  if ($hasDatasets)
394  {
395  $anonymization->setDisabled(true);
396  }
397  $anonymization->setOptionTitle($this->lng->txt("on"));
398  $anonymization->setValue(1);
399  $anonymization->setChecked($this->object->getAnonymize());
400  $anonymization->setInfo($this->lng->txt("anonymize_survey_description"));
401 
402  $anonymization_options = new ilRadioGroupInputGUI('', "anonymization_options");
403  if ($hasDatasets)
404  {
405  $anonymization_options->setDisabled(true);
406  }
407  $anonymization_options->addOption(new ilCheckboxOption($this->lng->txt("anonymize_without_code"), 'anonymize_without_code', ''));
408  $anonymization_options->addOption(new ilCheckboxOption($this->lng->txt("anonymize_with_code"), 'anonymize_with_code', ''));
409  $anonymization_options->setValue(($this->object->isAccessibleWithoutCode()) ? 'anonymize_without_code' : 'anonymize_with_code');
410 
411  $anonymization->addSubItem($anonymization_options);
412  $form->addItem($anonymization);
413 
414  // show question titles
415  $show_question_titles = new ilCheckboxInputGUI('', "show_question_titles");
416  $show_question_titles->setOptionTitle($this->lng->txt("svy_show_questiontitles"));
417  $show_question_titles->setValue(1);
418  $show_question_titles->setChecked($this->object->getShowQuestionTitles());
419  $form->addItem($show_question_titles);
420 
421  // final statement
422  $finalstatement = new ilTextAreaInputGUI($this->lng->txt("outro"), "outro");
423  $finalstatement->setValue($this->object->prepareTextareaOutput($this->object->getOutro()));
424  $finalstatement->setRows(10);
425  $finalstatement->setCols(80);
426  $finalstatement->setUseRte(TRUE);
427  $finalstatement->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("survey"));
428  $finalstatement->addPlugin("latex");
429  $finalstatement->addButton("latex");
430  $finalstatement->addPlugin("pastelatex");
431  $finalstatement->setRTESupport($this->object->getId(), "svy", "survey");
432  $form->addItem($finalstatement);
433 
434  /* Change Sn */
435  // redirect after survey
436  $redirect_after_survey = new ilTextInputGUI($this->lng->txt("redirect_after_survey"), "redirect_after_survey");
437  $redirect_after_survey->setSize(100);
438  $redirect_after_survey->setValue($this->object->getRedirectAfterSurvey());
439  $redirect_after_survey->setInfo($this->lng->txt("info_redirect_after_survey"));
440  $form->addItem($redirect_after_survey);
441 
442  // redirect only in kiosk mode
443  $redirect_only_kiosk_mode = new ilCheckboxInputGUI($this->lng->txt("redirect_only_kiosk_mode"), "redirect_only_kiosk_mode");
444  $redirect_only_kiosk_mode->setValue(1);
445  $redirect_only_kiosk_mode->setChecked($this->object->getRedirectOnlyKioskMode());
446  $redirect_only_kiosk_mode->setInfo($this->lng->txt("info_redirect_only_kiosk_mode"));
447  $form->addItem($redirect_only_kiosk_mode);
448 
449  //mail confirmation
450  $mail_confirmation = new ilCheckboxInputGUI($this->lng->txt("mail_confirmation"), "mail_confirmation");
451  $mail_confirmation->setValue(1);
452  $mail_confirmation->setChecked($this->object->getMailConfirmation());
453  //$mail_confirmation->setInfo($this->lng->txt("info_mail_confirmation"));
454  $form->addItem($mail_confirmation);
455 
456  $mail_confirmation_subject = new ilTextInputGUI($this->lng->txt("mail_confirmation_subject"), "mail_confirmation_subject");
457  $mail_confirmation_subject->setSize(100);
458  $mail_confirmation_subject->setValue($this->object->getMailConfirmationSubject());
459  //$mail_confirmation_subject->setInfo($this->lng->txt("info_mail_confirmation_subject"));
460  $form->addItem($mail_confirmation_subject);
461 
462  $mail_confirmation_body = new ilTextAreaInputGUI($this->lng->txt("mail_confirmation_body"), "mail_confirmation_body");
463  //$mail_confirmation_body->setValue($this->object->prepareTextareaOutput($this->object->getMailConfirmationBody()));
464  $mail_confirmation_body->setValue($this->object->getMailConfirmationBody());
465  $mail_confirmation_body->setRows(10);
466  $mail_confirmation_body->setCols(80);
467  $mail_confirmation_body->setInfo($this->lng->txt("info_mail_confirmation_body"));
468  $form->addItem($mail_confirmation_body);
469 
470  /* Change Sn End */
471  // results properties
473  $results->setTitle($this->lng->txt("results"));
474  $form->addItem($results);
475 
476  // evaluation access
477  $evaluation_access = new ilRadioGroupInputGUI($this->lng->txt('evaluation_access'), "evaluation_access");
478  $evaluation_access->setInfo($this->lng->txt('evaluation_access_description'));
479  $evaluation_access->addOption(new ilCheckboxOption($this->lng->txt("evaluation_access_off"), EVALUATION_ACCESS_OFF, ''));
480  $evaluation_access->addOption(new ilCheckboxOption($this->lng->txt("evaluation_access_all"), EVALUATION_ACCESS_ALL, ''));
481  $evaluation_access->addOption(new ilCheckboxOption($this->lng->txt("evaluation_access_participants"), EVALUATION_ACCESS_PARTICIPANTS, ''));
482  $evaluation_access->setValue($this->object->getEvaluationAccess());
483  $form->addItem($evaluation_access);
484 
485  // mail notification
486  $mailnotification = new ilCheckboxInputGUI($this->lng->txt("mailnotification"), "mailnotification");
487  $mailnotification->setOptionTitle($this->lng->txt("activate"));
488  $mailnotification->setValue(1);
489  $mailnotification->setChecked($this->object->getMailNotification());
490 
491  // addresses
492  $mailaddresses = new ilTextInputGUI($this->lng->txt("mailaddresses"), "mailaddresses");
493  $mailaddresses->setValue($this->object->getMailAddresses());
494  $mailaddresses->setSize(80);
495  $mailaddresses->setInfo($this->lng->txt('mailaddresses_info'));
496  $mailaddresses->setRequired(true);
497  if (($save) && !$_POST['mailnotification'])
498  {
499  $mailaddresses->setRequired(false);
500  }
501 
502  // participant data
503  $participantdata = new ilTextAreaInputGUI($this->lng->txt("mailparticipantdata"), "mailparticipantdata");
504  $participantdata->setValue($this->object->getMailParticipantData());
505  $participantdata->setRows(6);
506  $participantdata->setCols(80);
507  $participantdata->setUseRte(false);
508  $participantdata->setInfo($this->lng->txt('mailparticipantdata_info'));
509 
510  $mailnotification->addSubItem($mailaddresses);
511  $mailnotification->addSubItem($participantdata);
512  $form->addItem($mailnotification);
513 
514  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form->addCommandButton("saveProperties", $this->lng->txt("save"));
515  $errors = false;
516 
517  if ($save)
518  {
519  $errors = !$form->checkInput();
520  $form->setValuesByPost();
521  if (!$errors)
522  {
523  if (($online->getChecked()) && (count($this->object->questions) == 0))
524  {
525  $online->setAlert($this->lng->txt("cannot_switch_to_online_no_questions"));
526  ilUtil::sendFailure($this->lng->txt('form_input_not_valid'));
527  $errors = true;
528  }
529  }
530  if ($errors) $checkonly = false;
531  }
532  $mailaddresses->setRequired(true);
533  if (!$checkonly) $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
534  return $errors;
535  }
536 
545  {
546  $checked_questions = array();
547  $checked_questionblocks = array();
548  foreach ($_POST as $key => $value)
549  {
550  if (preg_match("/cb_(\d+)/", $key, $matches))
551  {
552  array_push($checked_questions, $matches[1]);
553  }
554  if (preg_match("/cb_qb_(\d+)/", $key, $matches))
555  {
556  array_push($checked_questionblocks, $matches[1]);
557  }
558  }
559  if (count($checked_questions) + count($checked_questionblocks) > 0)
560  {
561  ilUtil::sendQuestion($this->lng->txt("remove_questions"));
562  $this->removeQuestionsForm($checked_questions, $checked_questionblocks);
563  return;
564  }
565  else
566  {
567  ilUtil::sendInfo($this->lng->txt("no_question_selected_for_removal"), true);
568  $this->ctrl->redirect($this, "questions");
569  }
570  }
571 
575  public function insertQuestionsObject()
576  {
577  $inserted_objects = 0;
578  if (is_array($_POST['q_id']))
579  {
580  foreach ($_POST['q_id'] as $question_id)
581  {
582  $this->object->insertQuestion($question_id);
583  $inserted_objects++;
584  }
585  }
586  if ($inserted_objects)
587  {
588  $this->object->saveCompletionStatus();
589  ilUtil::sendSuccess($this->lng->txt("questions_inserted"), true);
590  $this->ctrl->redirect($this, "questions");
591  }
592  else
593  {
594  ilUtil::sendInfo($this->lng->txt("insert_missing_question"), true);
595  $this->ctrl->redirect($this, 'browseForQuestions');
596  }
597  }
598 
602  public function insertQuestionblocksObject()
603  {
604  $inserted_objects = 0;
605  if (is_array($_POST['cb']))
606  {
607  foreach ($_POST['cb'] as $questionblock_id)
608  {
609  $this->object->insertQuestionblock($questionblock_id);
610  $inserted_objects++;
611  }
612  }
613  if ($inserted_objects)
614  {
615  $this->object->saveCompletionStatus();
616  ilUtil::sendSuccess(($inserted_objects == 1) ? $this->lng->txt("questionblock_inserted") : $this->lng->txt("questionblocks_inserted"), true);
617  $this->ctrl->redirect($this, "questions");
618  }
619  else
620  {
621  ilUtil::sendInfo($this->lng->txt("insert_missing_questionblock"), true);
622  $this->ctrl->redirect($this, 'browseForQuestionblocks');
623  }
624  }
625 
629  public function changeDatatypeObject()
630  {
631  global $ilUser;
632  $ilUser->writePref('svy_insert_type', $_POST['datatype']);
633  switch ($_POST["datatype"])
634  {
635  case 0:
636  $this->ctrl->redirect($this, 'browseForQuestionblocks');
637  break;
638  case 1:
639  default:
640  $this->ctrl->redirect($this, 'browseForQuestions');
641  break;
642  }
643  }
644 
649  {
650  include_once "./Modules/Survey/classes/tables/class.ilSurveyQuestionblockbrowserTableGUI.php";
651  $table_gui = new ilSurveyQuestionblockbrowserTableGUI($this, 'browseForQuestionblocks');
652  $table_gui->writeFilterToSession();
653  $this->ctrl->redirect($this, 'browseForQuestionblocks');
654  }
655 
660  {
661  include_once "./Modules/Survey/classes/tables/class.ilSurveyQuestionblockbrowserTableGUI.php";
662  $table_gui = new ilSurveyQuestionblockbrowserTableGUI($this, 'browseForQuestionblocks');
663  $table_gui->resetFilter();
664  $this->ctrl->redirect($this, 'browseForQuestionblocks');
665  }
666 
670  public function browseForQuestionblocksObject($arrFilter = null)
671  {
672  global $rbacsystem;
673  global $ilUser;
674 
676  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_questionbrowser.html", "Modules/Survey");
677  include_once "./Modules/Survey/classes/tables/class.ilSurveyQuestionblockbrowserTableGUI.php";
678  $table_gui = new ilSurveyQuestionblockbrowserTableGUI($this, 'browseForQuestionblocks', (($rbacsystem->checkAccess('write', $_GET['ref_id']) ? true : false)));
679  $table_gui->setEditable($rbacsystem->checkAccess('write', $_GET['ref_id']));
680  $arrFilter = array();
681  foreach ($table_gui->getFilterItems() as $item)
682  {
683  if ($item->getValue() !== false)
684  {
685  $arrFilter[$item->getPostVar()] = $item->getValue();
686  }
687  }
688  $data = $this->object->getQuestionblocksTable($arrFilter);
689  $table_gui->setData($data);
690  $this->tpl->setVariable('TABLE', $table_gui->getHTML());
691 
692  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, 'changeDatatype'));
693  $this->tpl->setVariable("OPTION_QUESTIONS", $this->lng->txt("questions"));
694  $this->tpl->setVariable("OPTION_QUESTIONBLOCKS", $this->lng->txt("questionblocks"));
695  $this->tpl->setVariable("SELECTED_QUESTIONBLOCKS", " selected=\"selected\"");
696  $this->tpl->setVariable("TEXT_DATATYPE", $this->lng->txt("display_all_available"));
697  $this->tpl->setVariable("BTN_CHANGE", $this->lng->txt("change"));
698  }
699 
703  public function filterQuestionBrowserObject()
704  {
705  include_once "./Modules/Survey/classes/tables/class.ilSurveyQuestionbrowserTableGUI.php";
706  $table_gui = new ilSurveyQuestionbrowserTableGUI($this, 'browseForQuestions');
707  $table_gui->writeFilterToSession();
708  $this->ctrl->redirect($this, 'browseForQuestions');
709  }
710 
715  {
716  include_once "./Modules/Survey/classes/tables/class.ilSurveyQuestionbrowserTableGUI.php";
717  $table_gui = new ilSurveyQuestionbrowserTableGUI($this, 'browseForQuestions');
718  $table_gui->resetFilter();
719  $this->ctrl->redirect($this, 'browseForQuestions');
720  }
721 
725  public function browseForQuestionsObject($arrFilter = null)
726  {
727  global $rbacsystem;
728  global $ilUser;
729 
731  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_questionbrowser.html", "Modules/Survey");
732  include_once "./Modules/Survey/classes/tables/class.ilSurveyQuestionbrowserTableGUI.php";
733  $table_gui = new ilSurveyQuestionbrowserTableGUI($this, 'browseForQuestions', (($rbacsystem->checkAccess('write', $_GET['ref_id']) ? true : false)));
734  $table_gui->setEditable($rbacsystem->checkAccess('write', $_GET['ref_id']));
735  $arrFilter = array();
736  foreach ($table_gui->getFilterItems() as $item)
737  {
738  if ($item->getValue() !== false)
739  {
740  $arrFilter[$item->getPostVar()] = $item->getValue();
741  }
742  }
743  $data = $this->object->getQuestionsTable($arrFilter);
744  $table_gui->setData($data);
745  $this->tpl->setVariable('TABLE', $table_gui->getHTML());
746 
747  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, 'changeDatatype'));
748  $this->tpl->setVariable("OPTION_QUESTIONS", $this->lng->txt("questions"));
749  $this->tpl->setVariable("OPTION_QUESTIONBLOCKS", $this->lng->txt("questionblocks"));
750  $this->tpl->setVariable("SELECTED_QUESTIONS", " selected=\"selected\"");
751  $this->tpl->setVariable("TEXT_DATATYPE", $this->lng->txt("display_all_available"));
752  $this->tpl->setVariable("BTN_CHANGE", $this->lng->txt("change"));
753  }
754 
762  function removeQuestionsForm($checked_questions, $checked_questionblocks)
763  {
765  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_remove_questions.html", "Modules/Survey");
766  $colors = array("tblrow1", "tblrow2");
767  $counter = 0;
768  $surveyquestions =& $this->object->getSurveyQuestions();
769  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
770  foreach ($surveyquestions as $question_id => $data)
771  {
772  if (in_array($data["question_id"], $checked_questions) or (in_array($data["questionblock_id"], $checked_questionblocks)))
773  {
774  $this->tpl->setCurrentBlock("row");
775  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
776  $this->tpl->setVariable("TEXT_TITLE", $data["title"]);
777  $this->tpl->setVariable("TEXT_DESCRIPTION", $data["description"]);
778  $this->tpl->setVariable("TEXT_TYPE", SurveyQuestion::_getQuestionTypeName($data["type_tag"]));
779  $this->tpl->setVariable("TEXT_QUESTIONBLOCK", $data["questionblock_title"]);
780  $this->tpl->parseCurrentBlock();
781  $counter++;
782  }
783  }
784  foreach ($checked_questions as $id)
785  {
786  $this->tpl->setCurrentBlock("hidden");
787  $this->tpl->setVariable("HIDDEN_NAME", "id_$id");
788  $this->tpl->setVariable("HIDDEN_VALUE", "$id");
789  $this->tpl->parseCurrentBlock();
790  }
791  foreach ($checked_questionblocks as $id)
792  {
793  $this->tpl->setCurrentBlock("hidden");
794  $this->tpl->setVariable("HIDDEN_NAME", "id_qb_$id");
795  $this->tpl->setVariable("HIDDEN_VALUE", "$id");
796  $this->tpl->parseCurrentBlock();
797  }
798  $this->tpl->setCurrentBlock("adm_content");
799  $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
800  $this->tpl->setVariable("TEXT_DESCRIPTION", $this->lng->txt("description"));
801  $this->tpl->setVariable("TEXT_TYPE", $this->lng->txt("question_type"));
802  $this->tpl->setVariable("TEXT_QUESTIONBLOCK", $this->lng->txt("questionblock"));
803  $this->tpl->setVariable("BTN_CONFIRM", $this->lng->txt("confirm"));
804  $this->tpl->setVariable("BTN_CANCEL", $this->lng->txt("cancel"));
805  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "confirmRemoveQuestions"));
806  $this->tpl->parseCurrentBlock();
807  }
808 
809 
816  function defineQuestionblock($questionblock_id = "")
817  {
818  $this->questionsSubtabs("questions");
820  if ($questionblock_id)
821  {
822  $questionblock = $this->object->getQuestionblock($questionblock_id);
823  }
824  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_define_questionblock.html", "Modules/Survey");
825  foreach ($_POST as $key => $value)
826  {
827  if (preg_match("/cb_(\d+)/", $key, $matches))
828  {
829  $this->tpl->setCurrentBlock("hidden");
830  $this->tpl->setVariable("HIDDEN_NAME", "cb_$matches[1]");
831  $this->tpl->setVariable("HIDDEN_VALUE", $matches[1]);
832  $this->tpl->parseCurrentBlock();
833  }
834  }
835  if ($questionblock_id)
836  {
837  $this->tpl->setCurrentBlock("hidden");
838  $this->tpl->setVariable("HIDDEN_NAME", "questionblock_id");
839  $this->tpl->setVariable("HIDDEN_VALUE", $questionblock_id);
840  $this->tpl->parseCurrentBlock();
841  }
842  $this->tpl->setCurrentBlock("adm_content");
843  $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
844  if ($questionblock_id)
845  {
846  $this->tpl->setVariable("VALUE_TITLE", $questionblock["title"]);
847  }
848  $this->tpl->setVariable("TXT_QUESTIONTEXT_DESCRIPTION", $this->lng->txt("show_questiontext_description"));
849  $this->tpl->setVariable("TXT_QUESTIONTEXT", $this->lng->txt("show_questiontext"));
850  if (($questionblock["show_questiontext"]) || (strlen($questionblock_id) == 0))
851  {
852  $this->tpl->setVariable("CHECKED_QUESTIONTEXT", " checked=\"checked\"");
853  }
854  $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
855  $this->tpl->setVariable("HEADING_QUESTIONBLOCK", $this->lng->txt("define_questionblock"));
856  $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
857  $this->tpl->setVariable("CANCEL", $this->lng->txt("cancel"));
858  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "saveDefineQuestionblock"));
859  $this->tpl->parseCurrentBlock();
860  }
861 
868  {
869  global $ilUser;
870  $this->questionsSubtabs("questions");
871  $tpl = new ilTemplate("tpl.il_svy_svy_qpl_select.html", TRUE, TRUE, "Modules/Survey");
872  $questionpools =& $this->object->getAvailableQuestionpools(FALSE, TRUE, TRUE, "write");
873  if (count($questionpools))
874  {
875  foreach ($questionpools as $key => $value)
876  {
877  $tpl->setCurrentBlock("option");
878  $tpl->setVariable("VALUE_OPTION", $key);
879  $tpl->setVariable("TEXT_OPTION", $value);
880  $tpl->parseCurrentBlock();
881  }
882  $tpl->setCurrentBlock("selection");
883  $tpl->setVariable("TXT_QPL_SELECT", $this->lng->txt("select_questionpool"));
884  $tpl->parseCurrentBlock();
885  }
886  else
887  {
888  $tpl->setCurrentBlock("selection");
889  $tpl->setVariable("TXT_QPL_ENTER", $this->lng->txt("cat_create_spl"));
890  $tpl->parseCurrentBlock();
891  }
892  $tpl->setVariable("BTN_SUBMIT", $this->lng->txt("submit"));
893  $sel_question_types = (strlen($_POST["sel_question_types"])) ? $_POST["sel_question_types"] : $_GET["sel_question_types"];
894  $this->ctrl->setParameter($this, "sel_question_types", $sel_question_types);
895  $tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "executeCreateQuestion"));
896  $tpl->setVariable("BTN_CANCEL", $this->lng->txt("cancel"));
897  $this->tpl->setVariable("ADM_CONTENT", $tpl->get());
898  }
899 
906  {
907  $this->ctrl->redirect($this, "questions");
908  }
909 
916  {
917  if (strlen($_POST["sel_spl"]))
918  {
919  include_once "./Services/Utilities/classes/class.ilUtil.php";
920  ilUtil::redirect("ilias.php?baseClass=ilObjSurveyQuestionPoolGUI&ref_id=" . $_POST["sel_spl"] . "&cmd=createQuestionForSurvey&new_for_survey=".$_GET["ref_id"]."&sel_question_types=".$_GET["sel_question_types"]);
921  }
922  elseif (strlen($_POST["name_spl"]))
923  {
924  $ref_id = $this->createQuestionPool($_POST["name_spl"]);
925  ilUtil::redirect("ilias.php?baseClass=ilObjSurveyQuestionPoolGUI&ref_id=" . $ref_id . "&cmd=createQuestionForSurvey&new_for_survey=".$_GET["ref_id"]."&sel_question_types=".$_GET["sel_question_types"]);
926  }
927  else
928  {
929  ilUtil::sendFailure($this->lng->txt("err_no_pool_name"), true);
930  $this->ctrl->setParameter($this, "sel_question_types", $_GET["sel_question_types"]);
931  $this->ctrl->redirect($this, "createQuestion");
932  }
933  }
934 
941  private function createQuestionPool($name = "dummy")
942  {
943  global $tree;
944  $parent_ref = $tree->getParentId($this->object->getRefId());
945  include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
946  $qpl = new ilObjSurveyQuestionPool();
947  $qpl->setType("spl");
948  $qpl->setTitle($name);
949  $qpl->setDescription("");
950  $qpl->create();
951  $qpl->createReference();
952  $qpl->putInTree($parent_ref);
953  $qpl->setPermissions($parent_ref);
954  $qpl->setOnline(1); // must be online to be available
955  $qpl->saveToDb();
956  return $qpl->getRefId();
957  }
958 
965  function addHeadingObject($checkonly = false, $question_id = "")
966  {
967  $this->questionsSubtabs("questions");
968 
969  global $ilAccess;
970 
971  $save = (strcmp($this->ctrl->getCmd(), "saveHeading") == 0) ? TRUE : FALSE;
972 
973  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
974  $form = new ilPropertyFormGUI();
975  $form->setFormAction($this->ctrl->getFormAction($this));
976  $form->setTableWidth("100%");
977  $form->setId("survey_heading");
978 
979  // general properties
980  $header = new ilFormSectionHeaderGUI();
981  if ($question_id)
982  {
983  $header->setTitle($this->lng->txt("edit_heading"));
984  }
985  else
986  {
987  $header->setTitle($this->lng->txt("add_heading"));
988  }
989  $form->addItem($header);
990 
991  $survey_questions =& $this->object->getSurveyQuestions();
992 
993  // heading
994  $heading = new ilTextAreaInputGUI($this->lng->txt("heading"), "heading");
995  $heading->setValue($this->object->prepareTextareaOutput(array_key_exists('heading', $_POST) ? $_POST['heading'] : $survey_questions[$question_id]["heading"]));
996  $heading->setRows(10);
997  $heading->setCols(80);
998  $heading->setUseRte(TRUE);
999  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
1000  $heading->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("survey"));
1001  $heading->removePlugin("ibrowser");
1002  $heading->setRTESupport($this->object->getId(), "svy", "survey");
1003  $heading->setRequired(true);
1004  $form->addItem($heading);
1005 
1006  $insertbefore = new ilSelectInputGUI($this->lng->txt("insert"), "insertbefore");
1007  $options = array();
1008  foreach ($survey_questions as $key => $value)
1009  {
1010  $options[$key] = $this->lng->txt("before") . ": \"" . $value["title"] . "\"";
1011  }
1012  $insertbefore->setOptions($options);
1013  $insertbefore->setValue((array_key_exists('insertbefore', $_POST)) ? $_POST['insertbefore'] : $question_id);
1014  $insertbefore->setRequired(true);
1015  if ($question_id || array_key_exists('insertbefore', $_POST))
1016  {
1017  $insertbefore->setDisabled(true);
1018  }
1019  $form->addItem($insertbefore);
1020 
1021  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form->addCommandButton("saveHeading", $this->lng->txt("save"));
1022  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form->addCommandButton("cancelHeading", $this->lng->txt("cancel"));
1023  $errors = false;
1024 
1025  if ($save)
1026  {
1027  $errors = !$form->checkInput();
1028  $form->setValuesByPost();
1029  if ($errors) $checkonly = false;
1030  }
1031  if (!$checkonly) $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
1032  return $errors;
1033  }
1034 
1041  {
1042  // insert questions from test after confirmation
1043  foreach ($_POST as $key => $value) {
1044  if (preg_match("/id_(\d+)/", $key, $matches)) {
1045  if ($_GET["browsetype"] == 1)
1046  {
1047  $this->object->insertQuestion($matches[1]);
1048  }
1049  else
1050  {
1051  $this->object->insertQuestionBlock($matches[1]);
1052  }
1053  }
1054  }
1055  $this->object->saveCompletionStatus();
1056  ilUtil::sendSuccess($this->lng->txt("questions_inserted"), true);
1057  $this->ctrl->redirect($this, "questions");
1058  }
1059 
1066  {
1067  $this->ctrl->redirect($this, "questions");
1068  }
1069 
1078  {
1079  $hasErrors = $this->addHeadingObject(true);
1080  if (!$hasErrors)
1081  {
1082  $insertbefore = $_POST["insertbefore"];
1083  if (!$insertbefore)
1084  {
1085  $insertbefore = $_POST["insertbefore_original"];
1086  }
1087  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
1088  $this->object->saveHeading(ilUtil::stripSlashes($_POST["heading"], TRUE, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("survey")), $insertbefore);
1089  $this->ctrl->redirect($this, "questions");
1090  }
1091  }
1092 
1101  {
1102  $this->ctrl->redirect($this, "questions");
1103  }
1104 
1113  {
1114  $this->object->saveHeading("", $_POST["removeheading"]);
1115  $this->ctrl->redirect($this, "questions");
1116  }
1117 
1126  {
1127  $this->ctrl->redirect($this, "questions");
1128  }
1129 
1138  {
1139  ilUtil::sendQuestion($this->lng->txt("confirm_remove_heading"));
1140  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_confirm_removeheading.html", "Modules/Survey");
1141  $this->tpl->setCurrentBlock("adm_content");
1142  $this->tpl->setVariable("BTN_CONFIRM_REMOVE", $this->lng->txt("confirm"));
1143  $this->tpl->setVariable("BTN_CANCEL_REMOVE", $this->lng->txt("cancel"));
1144  $this->tpl->setVariable("REMOVE_HEADING", $_GET["removeheading"]);
1145  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "confirmRemoveHeading"));
1146  $this->tpl->parseCurrentBlock();
1147  }
1148 
1157  {
1158  $checked_questions = array();
1159  $checked_questionblocks = array();
1160  foreach ($_POST as $key => $value)
1161  {
1162  if (preg_match("/id_(\d+)/", $key, $matches))
1163  {
1164  array_push($checked_questions, $matches[1]);
1165  }
1166  if (preg_match("/id_qb_(\d+)/", $key, $matches))
1167  {
1168  array_push($checked_questionblocks, $matches[1]);
1169  }
1170  }
1171  $this->object->removeQuestions($checked_questions, $checked_questionblocks);
1172  $this->object->saveCompletionStatus();
1173  ilUtil::sendSuccess($this->lng->txt("questions_removed"), true);
1174  $this->ctrl->redirect($this, "questions");
1175  }
1176 
1185  {
1186  $this->ctrl->redirect($this, "questions");
1187  }
1188 
1197  {
1198  $questionblock = array();
1199  foreach ($_POST as $key => $value)
1200  {
1201  if (preg_match("/cb_(\d+)/", $key, $matches))
1202  {
1203  array_push($questionblock, $value);
1204  }
1205  }
1206  if (count($questionblock) < 2)
1207  {
1208  ilUtil::sendInfo($this->lng->txt("qpl_define_questionblock_select_missing"), true);
1209  $this->ctrl->redirect($this, "questions");
1210  }
1211  else
1212  {
1213  $this->defineQuestionblock();
1214  return;
1215  }
1216  }
1217 
1222  {
1223  if ($_POST["title"])
1224  {
1225  $show_questiontext = ($_POST["show_questiontext"]) ? 1 : 0;
1226  if ($_POST["questionblock_id"])
1227  {
1228  include_once "./Services/Utilities/classes/class.ilUtil.php";
1229  $this->object->modifyQuestionblock($_POST["questionblock_id"], ilUtil::stripSlashes($_POST["title"]), $show_questiontext);
1230  }
1231  else
1232  {
1233  $questionblock = array();
1234  foreach ($_POST as $key => $value)
1235  {
1236  if (preg_match("/cb_(\d+)/", $key, $matches))
1237  {
1238  array_push($questionblock, $value);
1239  }
1240  }
1241  include_once "./Services/Utilities/classes/class.ilUtil.php";
1242  $this->object->createQuestionblock(ilUtil::stripSlashes($_POST["title"]), $show_questiontext, $questionblock);
1243  }
1244  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true);
1245  $this->ctrl->redirect($this, "questions");
1246  }
1247  else
1248  {
1249  ilUtil::sendInfo($this->lng->txt("enter_questionblock_title"));
1250  $this->defineQuestionblockObject();
1251  return;
1252  }
1253  }
1254 
1258  public function unfoldQuestionblockObject()
1259  {
1260  $unfoldblocks = array();
1261  foreach ($_POST as $key => $value)
1262  {
1263  if (preg_match("/cb_qb_(\d+)/", $key, $matches))
1264  {
1265  array_push($unfoldblocks, $matches[1]);
1266  }
1267  }
1268  if (count($unfoldblocks))
1269  {
1270  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true);
1271  $this->object->unfoldQuestionblocks($unfoldblocks);
1272  }
1273  else
1274  {
1275  ilUtil::sendInfo($this->lng->txt("qpl_unfold_select_none"), true);
1276  }
1277  $this->ctrl->redirect($this, "questions");
1278  }
1279 
1284  {
1285  ilUtil::sendInfo($this->lng->txt('msg_cancel'), true);
1286  $this->ctrl->redirect($this, "questions");
1287  }
1288 
1292  public function moveQuestionsObject()
1293  {
1294  $move_questions = array();
1295  foreach ($_POST as $key => $value)
1296  {
1297  if (preg_match("/cb_(\d+)/", $key, $matches))
1298  {
1299  array_push($move_questions, $matches[1]);
1300  }
1301  if (preg_match("/cb_qb_(\d+)/", $key, $matches))
1302  {
1303  $ids = $this->object->getQuestionblockQuestionIds($matches[1]);
1304  foreach ($ids as $qkey => $qid)
1305  {
1306  array_push($move_questions, $qid);
1307  }
1308  }
1309  }
1310  if (count($move_questions) == 0)
1311  {
1312  ilUtil::sendInfo($this->lng->txt("no_question_selected_for_move"), true);
1313  $this->ctrl->redirect($this, "questions");
1314  }
1315  else
1316  {
1317  $_SESSION["move_questions"] = $move_questions;
1318  ilUtil::sendInfo($this->lng->txt("select_target_position_for_move_question"));
1319  $this->questionsObject();
1320  }
1321  }
1322 
1326  public function insertQuestions($insert_mode)
1327  {
1328  // get all questions to move
1329  $move_questions = $_SESSION["move_questions"];
1330  // get insert point
1331  $insert_id = -1;
1332  foreach ($_POST as $key => $value)
1333  {
1334  if (preg_match("/^cb_(\d+)$/", $key, $matches))
1335  {
1336  if ($insert_id < 0)
1337  {
1338  $insert_id = $matches[1];
1339  }
1340  }
1341  if (preg_match("/^cb_qb_(\d+)$/", $key, $matches))
1342  {
1343  if ($insert_id < 0)
1344  {
1345  $ids =& $this->object->getQuestionblockQuestionIds($matches[1]);
1346  if (count($ids))
1347  {
1348  if ($insert_mode == 0)
1349  {
1350  $insert_id = $ids[0];
1351  }
1352  else if ($insert_mode == 1)
1353  {
1354  $insert_id = $ids[count($ids)-1];
1355  }
1356  }
1357  }
1358  }
1359  }
1360  if ($insert_id <= 0)
1361  {
1362  ilUtil::sendInfo($this->lng->txt("no_target_selected_for_move"), true);
1363  }
1364  else
1365  {
1366  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true);
1367  $this->object->moveQuestions($move_questions, $insert_id, $insert_mode);
1368  }
1369  unset($_SESSION["move_questions"]);
1370  $this->ctrl->redirect($this, "questions");
1371  }
1372 
1377  {
1378  $this->insertQuestions(0);
1379  }
1380 
1384  public function insertQuestionsAfterObject()
1385  {
1386  $this->insertQuestions(1);
1387  }
1388 
1392  public function saveObligatoryObject()
1393  {
1394  $obligatory = array();
1395  foreach ($_POST as $key => $value)
1396  {
1397  if (preg_match("/obligatory_(\d+)/", $key, $matches))
1398  {
1399  $obligatory[$matches[1]] = 1;
1400  }
1401  }
1402  $this->object->setObligatoryStates($obligatory);
1403  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true);
1404  $this->ctrl->redirect($this, "questions");
1405  }
1406 
1410  public function questionsObject()
1411  {
1412  $this->handleWriteAccess();
1413  global $rbacsystem;
1414 
1415  $hasDatasets = $this->object->_hasDatasets($this->object->getSurveyId());
1416  include_once "./Services/Utilities/classes/class.ilUtil.php";
1417  if ((!$rbacsystem->checkAccess("read", $this->ref_id)) && (!$rbacsystem->checkAccess("write", $this->ref_id)))
1418  {
1419  // allow only read and write access
1420  ilUtil::sendInfo($this->lng->txt("cannot_edit_survey"), true);
1421  $path = $this->tree->getPathFull($this->object->getRefID());
1422  ilUtil::redirect($this->getReturnLocation("cancel","./repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
1423  return;
1424  }
1425 
1426  if ($_GET["new_id"] > 0)
1427  {
1428  // add a question to the survey previous created in a questionpool
1429  $existing = $this->object->getExistingQuestions();
1430  if (!in_array($_GET["new_id"], $existing))
1431  {
1432  $inserted = $this->object->insertQuestion($_GET["new_id"]);
1433  if (!$inserted)
1434  {
1435  ilUtil::sendFailure($this->lng->txt("survey_error_insert_incomplete_question"));
1436  }
1437  }
1438  }
1439 
1440  if ($_GET["eqid"] and $_GET["eqpl"])
1441  {
1442  ilUtil::redirect("ilias.php?baseClass=ilObjSurveyQuestionPoolGUI&ref_id=" . $_GET["eqpl"] . "&cmd=editQuestionForSurvey&calling_survey=".$_GET["ref_id"]."&q_id=" . $_GET["eqid"]);
1443  }
1444 
1445 
1446  $_SESSION["calling_survey"] = $this->object->getRefId();
1447  unset($_SESSION["survey_id"]);
1448 
1449  if ($_GET["editheading"])
1450  {
1451  $this->addHeadingObject(false, $_GET["editheading"]);
1452  return;
1453  }
1454 
1455  if ($_GET["up"] > 0)
1456  {
1457  $this->object->moveUpQuestion($_GET["up"]);
1458  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'));
1459  }
1460  if ($_GET["down"] > 0)
1461  {
1462  $this->object->moveDownQuestion($_GET["down"]);
1463  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'));
1464  }
1465  if ($_GET["qbup"] > 0)
1466  {
1467  $this->object->moveUpQuestionblock($_GET["qbup"]);
1468  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'));
1469  }
1470  if ($_GET["qbdown"] > 0)
1471  {
1472  $this->object->moveDownQuestionblock($_GET["qbdown"]);
1473  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'));
1474  }
1475 
1476  if ($_GET["removeheading"])
1477  {
1478  $this->confirmRemoveHeadingForm();
1479  return;
1480  }
1481 
1482  if ($_GET["editblock"])
1483  {
1484  $this->defineQuestionblock($_GET["editblock"]);
1485  return;
1486  }
1487 
1488  if ($_GET["add"])
1489  {
1490  // called after a new question was created from a questionpool
1491  $selected_array = array();
1492  array_push($selected_array, $_GET["add"]);
1493  ilUtil::sendQuestion($this->lng->txt("ask_insert_questions"));
1494  $this->insertQuestionsForm($selected_array);
1495  return;
1496  }
1497 
1498  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_questions.html", "Modules/Survey");
1499  $survey_questions =& $this->object->getSurveyQuestions();
1500  $questionpools =& $this->object->getQuestionpoolTitles();
1501  $colors = array("tblrow1", "tblrow2");
1502  $counter = 0;
1503  $title_counter = 0;
1504  $last_color_class = "";
1505  $obligatory = "<img src=\"" . ilUtil::getImagePath("obligatory.gif", "Modules/Survey") . "\" alt=\"" . $this->lng->txt("question_obligatory") . "\" title=\"" . $this->lng->txt("question_obligatory") . "\" />";
1506  include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
1507  $questiontypes =& ilObjSurveyQuestionPool::_getQuestiontypes();
1508  if (count($survey_questions) > 0)
1509  {
1510  foreach ($survey_questions as $question_id => $data)
1511  {
1512  $title_counter++;
1513  if (($last_questionblock_id > 0) && ($data["questionblock_id"] == 0))
1514  {
1515  $counter++;
1516  }
1517  if (($last_questionblock_id > 0) && ($data["questionblock_id"] > 0) && ($data["questionblock_id"] != $last_questionblock_id))
1518  {
1519  $counter++;
1520  }
1521  if (($data["questionblock_id"] > 0) and ($data["questionblock_id"] != $last_questionblock_id))
1522  {
1523  // add a separator line for the beginning of a question block
1524  $this->tpl->setCurrentBlock("separator");
1525  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
1526  $this->tpl->parseCurrentBlock();
1527  $this->tpl->setCurrentBlock("QTab");
1528  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
1529  $this->tpl->parseCurrentBlock();
1530 
1531  $this->tpl->setCurrentBlock("block");
1532  $this->tpl->setVariable("TYPE_ICON", "<img src=\"" . ilUtil::getImagePath("questionblock.gif", "Modules/Survey") . "\" alt=\"".$this->lng->txt("questionblock_icon")."\" />");
1533  $this->tpl->setVariable("TEXT_QUESTIONBLOCK", $this->lng->txt("questionblock") . ": " . $data["questionblock_title"]);
1534  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
1535  if ($rbacsystem->checkAccess("write", $this->ref_id) and !$hasDatasets)
1536  {
1537  if ($data["question_id"] != $this->object->questions[0])
1538  {
1539  $this->tpl->setVariable("BUTTON_UP", "<a href=\"" . $this->ctrl->getLinkTarget($this, "questions") . "&qbup=" . $data["questionblock_id"] . "\"><img src=\"" . ilUtil::getImagePath("a_up.gif") . "\" alt=\"" . $this->lng->txt("up") . "\" title=\"" . $this->lng->txt("up") . "\" border=\"0\" /></a>");
1540  }
1541  $akeys = array_keys($survey_questions);
1542  if ($data["questionblock_id"] != $survey_questions[$akeys[count($akeys)-1]]["questionblock_id"])
1543  {
1544  $this->tpl->setVariable("BUTTON_DOWN", "<a href=\"" . $this->ctrl->getLinkTarget($this, "questions") . "&qbdown=" . $data["questionblock_id"] . "\"><img src=\"" . ilUtil::getImagePath("a_down.gif") . "\" alt=\"" . $this->lng->txt("down") . "\" title=\"" . $this->lng->txt("down") . "\" border=\"0\" /></a>");
1545  }
1546  $this->tpl->setVariable("TEXT_EDIT", $this->lng->txt("edit"));
1547  $this->tpl->setVariable("HREF_EDIT", $this->ctrl->getLinkTarget($this, "questions") . "&editblock=" . $data["questionblock_id"]);
1548  }
1549  $this->tpl->parseCurrentBlock();
1550  $this->tpl->setCurrentBlock("QTab");
1551  $this->tpl->setVariable("QUESTION_ID", "qb_" . $data["questionblock_id"]);
1552  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
1553  $this->tpl->parseCurrentBlock();
1554  }
1555  if (($last_questionblock_id > 0) && ($data["questionblock_id"] == 0))
1556  {
1557  // add a separator line for the end of a question block
1558  $this->tpl->setCurrentBlock("separator");
1559  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
1560  $this->tpl->parseCurrentBlock();
1561  $this->tpl->setCurrentBlock("QTab");
1562  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
1563  $this->tpl->parseCurrentBlock();
1564  }
1565  if ($data["heading"])
1566  {
1567  $this->tpl->setCurrentBlock("heading");
1568  $this->tpl->setVariable("TEXT_HEADING", $data["heading"]);
1569  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
1570  if ($rbacsystem->checkAccess("write", $this->ref_id) and !$hasDatasets)
1571  {
1572  $this->tpl->setVariable("TEXT_EDIT", $this->lng->txt("edit"));
1573  $this->tpl->setVariable("HREF_EDIT", $this->ctrl->getLinkTarget($this, "questions") . "&editheading=" . $data["question_id"]);
1574  $this->tpl->setVariable("TEXT_DELETE", $this->lng->txt("remove"));
1575  $this->tpl->setVariable("HREF_DELETE", $this->ctrl->getLinkTarget($this, "questions") . "&removeheading=" . $data["question_id"]);
1576  }
1577  $this->tpl->parseCurrentBlock();
1578  $this->tpl->setCurrentBlock("QTab");
1579  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
1580  $this->tpl->parseCurrentBlock();
1581  }
1582  if (!$data["questionblock_id"])
1583  {
1584  $this->tpl->setCurrentBlock("checkable");
1585  $this->tpl->setVariable("QUESTION_ID", $data["question_id"]);
1586  $this->tpl->parseCurrentBlock();
1587  }
1588  $this->tpl->setCurrentBlock("QTab");
1589  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
1590  if ($rbacsystem->checkAccess("write", $this->ref_id) and !$hasDatasets)
1591  {
1592  $q_id = $data["question_id"];
1593  $qpl_ref_id = current(ilObject::_getAllReferences($data["obj_fi"]));
1594  $this->tpl->setVariable("QUESTION_TITLE", "$title_counter. <a href=\"" . $this->ctrl->getLinkTarget($this, "questions") . "&eqid=$q_id&eqpl=$qpl_ref_id" . "\">" . $data["title"] . "</a>");
1595  }
1596  else
1597  {
1598  $this->tpl->setVariable("QUESTION_TITLE", "$title_counter. ". $data["title"]);
1599  }
1600  $this->tpl->setVariable("TYPE_ICON", "<img src=\"" . ilUtil::getImagePath("question.gif", "Modules/Survey") . "\" alt=\"".$this->lng->txt("question_icon")."\" />");
1601  if ($rbacsystem->checkAccess("write", $this->ref_id) and !$hasDatasets)
1602  {
1603  $obligatory_checked = "";
1604  if ($data["obligatory"] == 1)
1605  {
1606  $obligatory_checked = " checked=\"checked\"";
1607  }
1608  $this->tpl->setVariable("QUESTION_OBLIGATORY", "<input type=\"checkbox\" name=\"obligatory_" . $data["question_id"] . "\" value=\"1\"$obligatory_checked />");
1609  }
1610  else
1611  {
1612  if ($data["obligatory"] == 1)
1613  {
1614  $this->tpl->setVariable("QUESTION_OBLIGATORY", $obligatory);
1615  }
1616  }
1617  $this->tpl->setVariable("QUESTION_COMMENT", $data["description"]);
1618  if ($rbacsystem->checkAccess("write", $this->ref_id) and !$hasDatasets)
1619  {
1620  if (!$data["questionblock_id"])
1621  {
1622  // up/down buttons for non-questionblock questions
1623  if ($data["question_id"] != $this->object->questions[0])
1624  {
1625  $this->tpl->setVariable("BUTTON_UP", "<a href=\"" . $this->ctrl->getLinkTarget($this, "questions") . "&up=" . $data["question_id"] . "\"><img src=\"" . ilUtil::getImagePath("a_up.gif") . "\" alt=\"".$this->lng->txt("up")."\" border=\"0\" /></a>");
1626  }
1627  if ($data["question_id"] != $this->object->questions[count($this->object->questions)-1])
1628  {
1629  $this->tpl->setVariable("BUTTON_DOWN", "<a href=\"" . $this->ctrl->getLinkTarget($this, "questions") . "&down=" . $data["question_id"] . "\"><img src=\"" . ilUtil::getImagePath("a_down.gif") . "\" alt=\"".$this->lng->txt("down")."\" border=\"0\" /></a>");
1630  }
1631  }
1632  else
1633  {
1634  // up/down buttons for questionblock questions
1635  if ($data["questionblock_id"] == $last_questionblock_id)
1636  {
1637  $this->tpl->setVariable("BUTTON_UP", "<a href=\"" . $this->ctrl->getLinkTarget($this, "questions") . "&up=" . $data["question_id"] . "\"><img src=\"" . ilUtil::getImagePath("a_up.gif") . "\" alt=\"".$this->lng->txt("up")."\" border=\"0\" /></a>");
1638  }
1639  $tmp_questions = array_keys($survey_questions);
1640  $blockkey = array_search($question_id, $tmp_questions);
1641  if (($blockkey !== FALSE) && ($blockkey < count($tmp_questions)-1))
1642  {
1643  if ($data["questionblock_id"] == $survey_questions[$tmp_questions[$blockkey+1]]["questionblock_id"])
1644  {
1645  $this->tpl->setVariable("BUTTON_DOWN", "<a href=\"" . $this->ctrl->getLinkTarget($this, "questions") . "&down=" . $data["question_id"] . "\"><img src=\"" . ilUtil::getImagePath("a_down.gif") . "\" alt=\"".$this->lng->txt("down")."\" border=\"0\" /></a>");
1646  }
1647  }
1648  }
1649  }
1650  foreach ($questiontypes as $trans => $typedata)
1651  {
1652  if (strcmp($typedata["type_tag"], $data["type_tag"]) == 0)
1653  {
1654  $this->tpl->setVariable("QUESTION_TYPE", $trans);
1655  }
1656  }
1657  $this->tpl->setVariable("QUESTION_AUTHOR", $data["author"]);
1658  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
1659  $last_color_class = $colors[$counter % 2];
1660  if (!$data["questionblock_id"])
1661  {
1662  $counter++;
1663  }
1664  $this->tpl->parseCurrentBlock();
1665  $last_questionblock_id = $data["questionblock_id"];
1666  }
1667 
1668  if ($rbacsystem->checkAccess("write", $this->ref_id) and !$hasDatasets)
1669  {
1670  $this->tpl->setCurrentBlock("selectall");
1671  $this->tpl->setVariable("SELECT_ALL", $this->lng->txt("select_all"));
1672  $this->tpl->setVariable("COLOR_CLASS", $last_color_class);
1673  $this->tpl->parseCurrentBlock();
1674  if (array_key_exists("move_questions", $_SESSION))
1675  {
1676  $this->tpl->setCurrentBlock("move_buttons");
1677  $this->tpl->setVariable("INSERT_BEFORE", $this->lng->txt("insert_before"));
1678  $this->tpl->setVariable("INSERT_AFTER", $this->lng->txt("insert_after"));
1679  $this->tpl->parseCurrentBlock();
1680  }
1681  $this->tpl->setCurrentBlock("QFooter");
1682  $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\">");
1683  $this->tpl->setVariable("REMOVE", $this->lng->txt("remove_question"));
1684  $this->tpl->setVariable("MOVE", $this->lng->txt("move"));
1685  $this->tpl->setVariable("QUESTIONBLOCK", $this->lng->txt("define_questionblock"));
1686  $this->tpl->setVariable("UNFOLD", $this->lng->txt("unfold"));
1687  $this->tpl->setVariable("SAVE", $this->lng->txt("save_obligatory_state"));
1688  $this->tpl->parseCurrentBlock();
1689  }
1690  }
1691  else
1692  {
1693  $this->tpl->setCurrentBlock("Emptytable");
1694  $this->tpl->setVariable("TEXT_EMPTYTABLE", $this->lng->txt("no_questions_available"));
1695  $this->tpl->parseCurrentBlock();
1696  }
1697  if (($last_questionblock_id > 0))
1698  {
1699  // add a separator line for the end of a question block (if the last question is a questionblock question)
1700  $this->tpl->setCurrentBlock("separator");
1701  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
1702  $this->tpl->parseCurrentBlock();
1703  $this->tpl->setCurrentBlock("QTab");
1704  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
1705  $this->tpl->parseCurrentBlock();
1706  }
1707 
1708  if ($rbacsystem->checkAccess("write", $this->ref_id) and !$hasDatasets)
1709  {
1710  $this->tpl->setCurrentBlock("QTypes");
1711  include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
1713  foreach ($qtypes as $translation => $data)
1714  {
1715  $this->tpl->setVariable("QUESTION_TYPE_ID", $data["type_tag"]);
1716  $this->tpl->setVariable("QUESTION_TYPE", $translation);
1717  $this->tpl->parseCurrentBlock();
1718  }
1719  $this->tpl->parseCurrentBlock();
1720  }
1721  $this->tpl->setCurrentBlock("adm_content");
1722  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "questions"));
1723  $this->tpl->setVariable("QUESTION_TITLE", $this->lng->txt("title"));
1724  $this->tpl->setVariable("QUESTION_COMMENT", $this->lng->txt("description"));
1725  $this->tpl->setVariable("QUESTION_OBLIGATORY", $this->lng->txt("obligatory"));
1726  $this->tpl->setVariable("QUESTION_SEQUENCE", $this->lng->txt("sequence"));
1727  $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("question_type"));
1728  $this->tpl->setVariable("QUESTION_AUTHOR", $this->lng->txt("author"));
1729 
1730  if ($rbacsystem->checkAccess("write", $this->ref_id) and !$hasDatasets)
1731  {
1732  $this->tpl->setVariable("BUTTON_INSERT_QUESTION", $this->lng->txt("browse_for_questions"));
1733  global $ilUser;
1734  $this->tpl->setVariable('BROWSE_COMMAND', ($ilUser->getPref('svy_insert_type') == 1 || strlen($ilUser->getPref('svy_insert_type')) == 0) ? 'browseForQuestions' : 'browseForQuestionblocks');
1735  $this->tpl->setVariable("TEXT_CREATE_NEW", " " . strtolower($this->lng->txt("or")) . " " . $this->lng->txt("create_new"));
1736  $this->tpl->setVariable("BUTTON_CREATE_QUESTION", $this->lng->txt("create"));
1737  $this->tpl->setVariable("HEADING", $this->lng->txt("add_heading"));
1738  }
1739  if ($hasDatasets)
1740  {
1741  ilUtil::sendInfo($this->lng->txt("survey_has_datasets_warning"));
1742  }
1743 
1744  $this->tpl->parseCurrentBlock();
1745  $this->questionsSubtabs("questions");
1746  }
1747 
1755  function evaluationObject()
1756  {
1757  include_once("./Modules/Survey/classes/class.ilSurveyEvaluationGUI.php");
1758  $eval_gui = new ilSurveyEvaluationGUI($this->object);
1759  $this->ctrl->setCmdClass(get_class($eval_gui));
1760  $this->ctrl->redirect($eval_gui, "evaluation");
1761  }
1762 
1766  public function disinviteUserGroupObject()
1767  {
1768  // disinvite users
1769  if (is_array($_POST["user_select"]))
1770  {
1771  foreach ($_POST["user_select"] as $user_id)
1772  {
1773  $this->object->disinviteUser($user_id);
1774  }
1775  }
1776  ilUtil::sendSuccess($this->lng->txt('msg_users_disinvited'), true);
1777  $this->ctrl->redirect($this, "invite");
1778  }
1779 
1783  public function inviteUserGroupObject()
1784  {
1785  $invited = 0;
1786  // add users to invitation
1787  if (is_array($_POST["user"]))
1788  {
1789  foreach ($_POST["user"] as $user_id)
1790  {
1791  $this->object->inviteUser($user_id);
1792  $invited++;
1793  }
1794  }
1795  if ($invited == 0)
1796  {
1797  ilUtil::sendFailure($this->lng->txt('no_user_invited'), TRUE);
1798  }
1799  else
1800  {
1801  ilUtil::sendSuccess(sprintf($this->lng->txt('users_invited'), $invited), TRUE);
1802  }
1803  $this->ctrl->redirect($this, "invite");
1804  }
1805 
1809  public function saveInvitationStatusObject()
1810  {
1811  $mode = $_POST['invitation'];
1812  switch ($mode)
1813  {
1814  case 0:
1815  $this->object->setInvitation(0);
1816  break;
1817  case 1:
1818  $this->object->setInvitation(1);
1819  $this->object->setInvitationMode(0);
1820  break;
1821  case 2:
1822  $this->object->setInvitation(1);
1823  $this->object->setInvitationMode(1);
1824  break;
1825  }
1826  $this->object->saveToDb();
1827  ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true);
1828  $this->ctrl->redirect($this, "invite");
1829  }
1830 
1831 
1835  public function inviteObject()
1836  {
1837  global $ilAccess;
1838  global $rbacsystem;
1839  global $ilToolbar;
1840 
1841  if ((!$rbacsystem->checkAccess("visible,invite", $this->ref_id)) && (!$rbacsystem->checkAccess("write", $this->ref_id)))
1842  {
1843  // allow only read and write access
1844  ilUtil::sendInfo($this->lng->txt("cannot_edit_survey"), true);
1845  $path = $this->tree->getPathFull($this->object->getRefID());
1846  include_once "./Services/Utilities/classes/class.ilUtil.php";
1847  ilUtil::redirect($this->getReturnLocation("cancel","./repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
1848  return;
1849  }
1850 
1851  if ($this->object->getStatus() == STATUS_OFFLINE)
1852  {
1853  ilUtil::sendInfo($this->lng->txt("survey_offline_message"));
1854  return;
1855  }
1856 
1857  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1858  $form = new ilPropertyFormGUI();
1859  $form->setFormAction($this->ctrl->getFormAction($this));
1860  $form->setTableWidth("500");
1861  $form->setId("invite");
1862 
1863  // invitation
1864  $header = new ilFormSectionHeaderGUI();
1865  $header->setTitle($this->lng->txt("invitation"));
1866  $form->addItem($header);
1867 
1868  // invitation mode
1869  $invitation = new ilRadioGroupInputGUI($this->lng->txt('invitation_mode'), "invitation");
1870  $invitation->setInfo($this->lng->txt('invitation_mode_desc'));
1871  $invitation->addOption(new ilRadioOption($this->lng->txt("invitation_off"), 0, ''));
1872  $surveySetting = new ilSetting("survey");
1873  if ($surveySetting->get("unlimited_invitation"))
1874  {
1875  $invitation->addOption(new ilRadioOption($this->lng->txt("unlimited_users"), 1, ''));
1876  }
1877  $invitation->addOption(new ilRadioOption($this->lng->txt("predefined_users"), 2, ''));
1878  $inv = 0;
1879  if ($this->object->getInvitation())
1880  {
1881  $inv = $this->object->getInvitationMode() + 1;
1882  }
1883  $invitation->setValue($inv);
1884  $form->addItem($invitation);
1885 
1886  $form->addCommandButton("saveInvitationStatus", $this->lng->txt("save"));
1887 
1888  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_invite.html", "Modules/Survey");
1889  $this->tpl->setVariable("INVITATION_TABLE", $form->getHTML());
1890 
1891  if ($this->object->getInvitation() && $this->object->getInvitationMode() == 1)
1892  {
1893  // search button
1894  $ilToolbar->addButton($this->lng->txt("svy_search_users"),
1895  $this->ctrl->getLinkTargetByClass('ilRepositorySearchGUI','start'));
1896 
1897  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
1898 
1899  $invited_users = $this->object->getUserData($this->object->getInvitedUsers());
1900  include_once "./Modules/Survey/classes/tables/class.ilSurveyInvitedUsersTableGUI.php";
1901  $table_gui = new ilSurveyInvitedUsersTableGUI($this, 'invite');
1902  $table_gui->setData($invited_users);
1903  $this->tpl->setVariable('TBL_INVITED_USERS', $table_gui->getHTML());
1904  }
1905  }
1906 
1910  public function deleteAllUserDataObject()
1911  {
1912  ilUtil::sendQuestion($this->lng->txt("confirm_delete_all_user_data"));
1913  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_maintenance.html", "Modules/Survey");
1914  $this->tpl->setCurrentBlock("adm_content");
1915  $this->tpl->setVariable("BTN_CONFIRM_DELETE_ALL", $this->lng->txt("confirm"));
1916  $this->tpl->setVariable("BTN_CANCEL_DELETE_ALL", $this->lng->txt("cancel"));
1917  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "deleteAllUserData"));
1918  $this->tpl->parseCurrentBlock();
1919  }
1920 
1925  {
1926  $this->object->deleteAllUserData();
1927  ilUtil::sendSuccess($this->lng->txt("svy_all_user_data_deleted"), true);
1928  $this->ctrl->redirect($this, "maintenance");
1929  }
1930 
1935  {
1936  $this->ctrl->redirect($this, "maintenance");
1937  }
1938 
1943  {
1944  $this->object->removeSelectedSurveyResults($_POST["chbUser"]);
1945  ilUtil::sendSuccess($this->lng->txt("svy_selected_user_data_deleted"), true);
1946  $this->ctrl->redirect($this, "maintenance");
1947  }
1948 
1953  {
1954  ilUtil::sendInfo($this->lng->txt('msg_cancel'), true);
1955  $this->ctrl->redirect($this, "maintenance");
1956  }
1957 
1962  {
1963  $this->handleWriteAccess();
1964 
1965  if (count($_POST["chbUser"]) == 0)
1966  {
1967  ilUtil::sendInfo($this->lng->txt('no_checkbox'), true);
1968  $this->ctrl->redirect($this, "maintenance");
1969  }
1970 
1971  ilUtil::sendQuestion($this->lng->txt("confirm_delete_single_user_data"));
1972  include_once "./Modules/Survey/classes/tables/class.ilSurveyMaintenanceTableGUI.php";
1973  $table_gui = new ilSurveyMaintenanceTableGUI($this, 'maintenance', true);
1974  $total =& $this->object->getSurveyParticipants();
1975  $data = array();
1976  foreach ($total as $user_data)
1977  {
1978  if (in_array($user_data['active_id'], $_POST['chbUser']))
1979  {
1980  $last_access = $this->object->_getLastAccess($user_data["active_id"]);
1981  array_push($data, array(
1982  'id' => $user_data["active_id"],
1983  'name' => $user_data["sortname"],
1984  'login' => $user_data["login"],
1985  'last_access' => $last_access
1986  ));
1987  }
1988  }
1989  $table_gui->setData($data);
1990  $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
1991  }
1992 
1996  public function maintenanceObject()
1997  {
1998  $this->handleWriteAccess();
1999 
2000  if ($_GET["fill"] > 0)
2001  {
2002  for ($i = 0; $i < $_GET["fill"]; $i++) $this->object->fillSurveyForUser();
2003  }
2004  include_once "./Modules/Survey/classes/tables/class.ilSurveyMaintenanceTableGUI.php";
2005  $table_gui = new ilSurveyMaintenanceTableGUI($this, 'maintenance');
2006  $total =& $this->object->getSurveyParticipants();
2007  $data = array();
2008  foreach ($total as $user_data)
2009  {
2010  $last_access = $this->object->_getLastAccess($user_data["active_id"]);
2011  array_push($data, array(
2012  'id' => $user_data["active_id"],
2013  'name' => $user_data["sortname"],
2014  'login' => $user_data["login"],
2015  'last_access' => $last_access
2016  ));
2017  }
2018  $table_gui->setData($data);
2019  $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
2020  }
2021 
2027  function importObject()
2028  {
2029  $this->getTemplateFile("import", "svy");
2030  $this->tpl->setCurrentBlock("option_qpl");
2031  include_once("./Modules/Survey/classes/class.ilObjSurvey.php");
2032  $svy = new ilObjSurvey();
2033  $questionpools =& $svy->getAvailableQuestionpools(TRUE, FALSE, TRUE);
2034  if (count($questionpools) == 0)
2035  {
2036  }
2037  else
2038  {
2039  foreach ($questionpools as $key => $value)
2040  {
2041  $this->tpl->setCurrentBlock("option_spl");
2042  $this->tpl->setVariable("OPTION_VALUE", $key);
2043  $this->tpl->setVariable("TXT_OPTION", $value);
2044  $this->tpl->parseCurrentBlock();
2045  }
2046  }
2047  $this->tpl->setVariable("TXT_SELECT_QUESTIONPOOL", $this->lng->txt("select_questionpool"));
2048  $this->tpl->setVariable("OPTION_SELECT_QUESTIONPOOL", $this->lng->txt("select_questionpool_option"));
2049  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "import"));
2050  $this->tpl->setVariable("BTN_NAME", "upload");
2051  $this->tpl->setVariable("TXT_UPLOAD", $this->lng->txt("upload"));
2052  $this->tpl->setVariable("TXT_IMPORT_TST", $this->lng->txt("import_tst"));
2053  $this->tpl->setVariable("TXT_SELECT_MODE", $this->lng->txt("select_mode"));
2054  $this->tpl->setVariable("TXT_SELECT_FILE", $this->lng->txt("select_file"));
2055 
2056  }
2057 
2064  function uploadObject($redirect = true)
2065  {
2066  if ($_POST["spl"] < 1)
2067  {
2068  ilUtil::sendInfo($this->lng->txt("svy_select_questionpools"));
2069  $this->importObject();
2070  return;
2071  }
2072  if (strcmp($_FILES["xmldoc"]["tmp_name"], "") == 0)
2073  {
2074  ilUtil::sendInfo($this->lng->txt("svy_select_file_for_import"));
2075  $this->importObject();
2076  return;
2077  }
2078 
2079  include_once("./Modules/Survey/classes/class.ilObjSurvey.php");
2080  $newObj = new ilObjSurvey();
2081  $newObj->setType($_GET["new_type"]);
2082  $newObj->setTitle("dummy");
2083  $newObj->setDescription("dummy");
2084  $newObj->create(true);
2085  $newObj->createReference();
2086  $newObj->putInTree($_GET["ref_id"]);
2087  $newObj->setPermissions($_GET["ref_id"]);
2088  $newObj->notify("new",$_GET["ref_id"],$_GET["parent_non_rbac_id"],$_GET["ref_id"],$newObj->getRefId());
2089  // copy uploaded file to import directory
2090  $error = $newObj->importObject($_FILES["xmldoc"], $_POST["spl"]);
2091  if (strlen($error))
2092  {
2093  $newObj->delete();
2094  $this->ilias->raiseError($error, $this->ilias->error_obj->MESSAGE);
2095  return;
2096  }
2097  else
2098  {
2099  $ref_id = $newObj->getRefId();
2100  }
2101  if ($redirect)
2102  {
2103  include_once "./Services/Utilities/classes/class.ilUtil.php";
2104  ilUtil::redirect($this->getReturnLocation("upload",$this->ctrl->getTargetScript()."?".$this->link_params));
2105  }
2106  return $ref_id;
2107  }
2108 
2112  function createObject()
2113  {
2114  global $rbacsystem;
2115  $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
2116  if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], $new_type))
2117  {
2118  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
2119  }
2120  else
2121  {
2122  $this->getTemplateFile("create", $new_type);
2123 
2124  include_once("./Modules/Survey/classes/class.ilObjSurvey.php");
2125  $svy = new ilObjSurvey();
2126 
2127  $this->fillCloneTemplate('DUPLICATE','svy');
2128  $questionpools =& $svy->getAvailableQuestionpools($use_obj_id = TRUE, $could_be_offline = TRUE, $showPath = TRUE);
2129  if (count($questionpools) > 0)
2130  {
2131  foreach ($questionpools as $key => $value)
2132  {
2133  $this->tpl->setCurrentBlock("option_spl");
2134  $this->tpl->setVariable("OPTION_VALUE", $key);
2135  $this->tpl->setVariable("TXT_OPTION", $value);
2136  if ($_POST["spl"] == $key)
2137  {
2138  $this->tpl->setVariable("OPTION_SELECTED", " selected=\"selected\"");
2139  }
2140  $this->tpl->parseCurrentBlock();
2141  }
2142  }
2143  // fill in saved values in case of error
2144  $data = array();
2145  $data["fields"] = array();
2146  include_once "./Services/Utilities/classes/class.ilUtil.php";
2147  $data["fields"]["title"] = ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["title"],true);
2148  $data["fields"]["desc"] = ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["desc"]);
2149 
2150  foreach ($data["fields"] as $key => $val)
2151  {
2152  $this->tpl->setVariable("TXT_".strtoupper($key), $this->lng->txt($key));
2153  $this->tpl->setVariable(strtoupper($key), $val);
2154 
2155  if ($this->prepare_output)
2156  {
2157  $this->tpl->parseCurrentBlock();
2158  }
2159  }
2160 
2161  $this->ctrl->setParameter($this, "new_type", $this->type);
2162  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, "create"));
2163  $this->tpl->setVariable("TXT_HEADER", $this->lng->txt($new_type."_new"));
2164  $this->tpl->setVariable("TXT_SELECT_QUESTIONPOOL", $this->lng->txt("select_questionpool_short"));
2165  $this->tpl->setVariable("OPTION_SELECT_QUESTIONPOOL", $this->lng->txt("select_questionpool_option"));
2166  $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
2167  $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt($new_type."_add"));
2168  $this->tpl->setVariable("CMD_SUBMIT", "save");
2169  $this->tpl->setVariable("TARGET", ' target="'.
2170  ilFrameTargetInfo::_getFrame("MainContent").'" ');
2171  $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
2172 
2173  $this->tpl->setVariable("TXT_IMPORT_SVY", $this->lng->txt("import_svy"));
2174  $this->tpl->setVariable("TXT_SVY_FILE", $this->lng->txt("svy_upload_file"));
2175  $this->tpl->setVariable("TXT_IMPORT", $this->lng->txt("import"));
2176 
2177  $this->tpl->setVariable("TYPE_IMG", ilUtil::getImagePath('icon_svy.gif'));
2178  $this->tpl->setVariable("ALT_IMG",$this->lng->txt("obj_svy"));
2179  $this->tpl->setVariable("TYPE_IMG2", ilUtil::getImagePath('icon_svy.gif'));
2180  $this->tpl->setVariable("ALT_IMG2",$this->lng->txt("obj_svy"));
2181  }
2182  }
2183 
2187  function importFileObject()
2188  {
2189  if ($_POST["spl"] < 1)
2190  {
2191  ilUtil::sendInfo($this->lng->txt("svy_select_questionpools"));
2192  $this->createObject();
2193  return;
2194  }
2195  if (strcmp($_FILES["xmldoc"]["tmp_name"], "") == 0)
2196  {
2197  ilUtil::sendInfo($this->lng->txt("svy_select_file_for_import"));
2198  $this->createObject();
2199  return;
2200  }
2201  $this->ctrl->setParameter($this, "new_type", $this->type);
2202  $ref_id = $this->uploadObject(false);
2203  // always send a message
2204  ilUtil::sendSuccess($this->lng->txt("object_imported"),true);
2205 
2206  ilUtil::redirect("ilias.php?ref_id=".$ref_id.
2207  "&baseClass=ilObjSurveyGUI");
2208 // $this->ctrl->redirect($this, "importFile");
2209  }
2210 
2211  /*
2212  * list all export files
2213  */
2214  public function exportObject()
2215  {
2216  $this->handleWriteAccess();
2217 
2218  $export_dir = $this->object->getExportDirectory();
2219  $export_files = $this->object->getExportFiles($export_dir);
2220  $data = array();
2221  if(count($export_files) > 0)
2222  {
2223  foreach($export_files as $exp_file)
2224  {
2225  $file_arr = explode("__", $exp_file);
2226  $date = new ilDateTime($file_arr[0], IL_CAL_UNIX);
2227  array_push($data, array(
2228  'file' => $exp_file,
2229  'size' => filesize($export_dir."/".$exp_file),
2230  'date' => $date->get(IL_CAL_DATETIME)
2231  ));
2232  }
2233  }
2234 
2235  include_once "./Modules/Survey/classes/tables/class.ilSurveyExportTableGUI.php";
2236  $table_gui = new ilSurveyExportTableGUI($this, 'export');
2237  $table_gui->setData($data);
2238  $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
2239  }
2240 
2244  public function createExportFileObject()
2245  {
2246  $this->handleWriteAccess();
2247  include_once("./Modules/Survey/classes/class.ilSurveyExport.php");
2248  $survey_exp = new ilSurveyExport($this->object);
2249  $survey_exp->buildExportFile();
2250  $this->ctrl->redirect($this, "export");
2251  }
2252 
2256  public function downloadExportFileObject()
2257  {
2258  if(!isset($_POST["file"]))
2259  {
2260  ilUtil::sendFailure($this->lng->txt("no_checkbox"), true);
2261  $this->ctrl->redirect($this, "export");
2262  }
2263 
2264  if (count($_POST["file"]) > 1)
2265  {
2266  ilUtil::sendFailure($this->lng->txt("select_max_one_item"), true);
2267  $this->ctrl->redirect($this, "export");
2268  }
2269 
2270 
2271  $export_dir = $this->object->getExportDirectory();
2272  include_once "./Services/Utilities/classes/class.ilUtil.php";
2273  ilUtil::deliverFile($export_dir."/".$_POST["file"][0],
2274  $_POST["file"][0]);
2275  }
2276 
2281  {
2282  $this->handleWriteAccess();
2283 
2284  if (!isset($_POST["file"]))
2285  {
2286  ilUtil::sendFailure($this->lng->txt("no_checkbox"), true);
2287  $this->ctrl->redirect($this, "export");
2288  }
2289 
2290  ilUtil::sendQuestion($this->lng->txt("info_delete_sure"));
2291 
2292  $export_dir = $this->object->getExportDirectory();
2293  $export_files = $this->object->getExportFiles($export_dir);
2294  $data = array();
2295  if (count($_POST["file"]) > 0)
2296  {
2297  foreach ($_POST["file"] as $exp_file)
2298  {
2299  $file_arr = explode("__", $exp_file);
2300  $date = new ilDateTime($file_arr[0], IL_CAL_UNIX);
2301  array_push($data, array(
2302  'file' => $exp_file,
2303  'size' => filesize($export_dir."/".$exp_file),
2304  'date' => $date->get(IL_CAL_DATETIME)
2305  ));
2306  }
2307  }
2308 
2309  include_once "./Modules/Survey/classes/tables/class.ilSurveyExportTableGUI.php";
2310  $table_gui = new ilSurveyExportTableGUI($this, 'export', true);
2311  $table_gui->setData($data);
2312  $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
2313  }
2314 
2315 
2320  {
2321  ilUtil::sendInfo($this->lng->txt('msg_cancel'), true);
2322  $this->ctrl->redirect($this, "export");
2323  }
2324 
2325 
2329  public function deleteExportFileObject()
2330  {
2331  $export_dir = $this->object->getExportDirectory();
2332  foreach ($_POST["file"] as $file)
2333  {
2334  $exp_file = $export_dir."/".$file;
2335  $exp_dir = $export_dir."/".substr($file, 0, strlen($file) - 4);
2336  if (@is_file($exp_file))
2337  {
2338  unlink($exp_file);
2339  }
2340  if (@is_dir($exp_dir))
2341  {
2342  include_once "./Services/Utilities/classes/class.ilUtil.php";
2343  ilUtil::delDir($exp_dir);
2344  }
2345  }
2346  ilUtil::sendSuccess($this->lng->txt('msg_deleted_export_files'), true);
2347  $this->ctrl->redirect($this, "export");
2348  }
2349 
2353  public function setCodeLanguageObject()
2354  {
2355  if (strcmp($_POST["lang"], "-1") != 0)
2356  {
2357  global $ilUser;
2358  $ilUser->writePref("survey_code_language", $_POST["lang"]);
2359  }
2360  ilUtil::sendSuccess($this->lng->txt('language_changed'), true);
2361  $this->ctrl->redirect($this, 'codes');
2362  }
2363 
2367  public function codesObject()
2368  {
2369  $this->handleWriteAccess();
2370  $this->setCodesSubtabs();
2371  global $ilUser, $ilToolbar;
2372  if ($this->object->getAnonymize() != 1)
2373  {
2374  return ilUtil::sendInfo($this->lng->txt("survey_codes_no_anonymization"));
2375  }
2376 
2377  $default_lang = $ilUser->getPref("survey_code_language");
2378 
2379  // creation buttons
2380  $ilToolbar->setFormAction($this->ctrl->getFormAction($this));
2381  $languages = $this->lng->getInstalledLanguages();
2382  $options = array();
2383  foreach ($languages as $lang)
2384  {
2385  $options[$lang] = $this->lng->txt("lang_$lang");
2386  }
2387  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
2388  $si = new ilSelectInputGUI($this->lng->txt("survey_codes_lang"), "lang");
2389  $si->setOptions($options);
2390  $si->setValue($default_lang);
2391  $ilToolbar->addInputItem($si, true);
2392  $ilToolbar->addFormButton($this->lng->txt("set"), "setCodeLanguage");
2393 
2394  include_once "./Modules/Survey/classes/tables/class.ilSurveyCodesTableGUI.php";
2395  $table_gui = new ilSurveyCodesTableGUI($this, 'codes');
2396  $survey_codes =& $this->object->getSurveyCodesTableData($default_lang);
2397  $table_gui->setData($survey_codes);
2398  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_codes.html", true);
2399  $this->tpl->setCurrentBlock("adm_content");
2400  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "codes"));
2401  $this->tpl->setVariable("TEXT_CREATE", $this->lng->txt("create"));
2402  $this->tpl->setVariable("TEXT_SURVEY_CODES", $this->lng->txt("new_survey_codes"));
2403  $this->tpl->setVariable('TABLE', $table_gui->getHTML());
2404  }
2405 
2409  public function deleteCodesObject()
2410  {
2411  if (is_array($_POST["chb_code"]) && (count($_POST["chb_code"]) > 0))
2412  {
2413  foreach ($_POST["chb_code"] as $survey_code)
2414  {
2415  $this->object->deleteSurveyCode($survey_code);
2416  }
2417  ilUtil::sendSuccess($this->lng->txt('codes_deleted'), true);
2418  }
2419  else
2420  {
2421  ilUtil::sendInfo($this->lng->txt('no_checkbox'), true);
2422  }
2423  $this->ctrl->redirect($this, 'codes');
2424  }
2425 
2429  public function exportCodesObject()
2430  {
2431  if (is_array($_POST["chb_code"]) && (count($_POST["chb_code"]) > 0))
2432  {
2433  $export = $this->object->getSurveyCodesForExport($_POST["chb_code"]);
2434  ilUtil::deliverData($export, ilUtil::getASCIIFilename($this->object->getTitle() . ".txt"));
2435  }
2436  else
2437  {
2438  ilUtil::sendFailure($this->lng->txt("no_checkbox"), true);
2439  $this->ctrl->redirect($this, 'codes');
2440  }
2441  }
2442 
2446  public function exportAllCodesObject()
2447  {
2448  $export = $this->object->getSurveyCodesForExport(array());
2449  ilUtil::deliverData($export, ilUtil::getASCIIFilename($this->object->getTitle() . ".txt"));
2450  }
2451 
2455  public function createSurveyCodesObject()
2456  {
2457  if (preg_match("/\d+/", $_POST["nrOfCodes"]))
2458  {
2459  $this->object->createSurveyCodes($_POST["nrOfCodes"]);
2460  ilUtil::sendSuccess($this->lng->txt('codes_created'), true);
2461  }
2462  else
2463  {
2464  ilUtil::sendFailure($this->lng->txt("enter_valid_number_of_codes"), true);
2465  }
2466  $this->ctrl->redirect($this, 'codes');
2467  }
2468 
2472  public function codesMailObject($checkonly = false)
2473  {
2474  global $ilAccess;
2475 
2476  $this->handleWriteAccess();
2477  $this->setCodesSubtabs();
2478 
2479  $savefields = (strcmp($this->ctrl->getCmd(), "saveMailTableFields") == 0) ? TRUE : FALSE;
2480 
2481  include_once "./Modules/Survey/classes/tables/class.ilSurveyCodesMailTableGUI.php";
2482  $data = $this->object->getExternalCodeRecipients();
2483  $table_gui = new ilSurveyCodesMailTableGUI($this, 'codesMail');
2484  $table_gui->setData($data);
2485  $table_gui->setTitle($this->lng->txt('externalRecipients'));
2486  $table_gui->completeColumns();
2487  $tabledata = $table_gui->getHTML();
2488 
2489  if (!$checkonly)
2490  {
2491  $this->tpl->setVariable('ADM_CONTENT', $tabledata);
2492  }
2493  return $errors;
2494  }
2495 
2496  public function insertSavedMessageObject()
2497  {
2498  $this->handleWriteAccess();
2499  $this->setCodesSubtabs();
2500 
2501  include_once("./Modules/Survey/classes/forms/FormMailCodesGUI.php");
2502  $form_gui = new FormMailCodesGUI($this);
2503  $form_gui->setValuesByPost();
2504  try
2505  {
2506  if ($form_gui->getSavedMessages()->getValue() > 0)
2507  {
2508  global $ilUser;
2509  $settings = $this->object->getUserSettings($ilUser->getId(), 'savemessage');
2510  $form_gui->getMailMessage()->setValue($settings[$form_gui->getSavedMessages()->getValue()]['value']);
2511  ilUtil::sendSuccess($this->lng->txt('msg_message_inserted'));
2512  }
2513  else
2514  {
2515  ilUtil::sendFailure($this->lng->txt('msg_no_message_inserted'));
2516  }
2517  }
2518  catch (Exception $e)
2519  {
2520  global $ilLog;
2521  $ilLog->write('Error: ' + $e->getMessage());
2522  }
2523  $this->tpl->setVariable("ADM_CONTENT", $form_gui->getHTML());
2524  }
2525 
2526  public function deleteSavedMessageObject()
2527  {
2528  $this->handleWriteAccess();
2529  $this->setCodesSubtabs();
2530 
2531  include_once("./Modules/Survey/classes/forms/FormMailCodesGUI.php");
2532  $form_gui = new FormMailCodesGUI($this);
2533  $form_gui->setValuesByPost();
2534  try
2535  {
2536  if ($form_gui->getSavedMessages()->getValue() > 0)
2537  {
2538  $this->object->deleteUserSettings($form_gui->getSavedMessages()->getValue());
2539  $form_gui = new FormMailCodesGUI($this);
2540  $form_gui->setValuesByPost();
2541  ilUtil::sendSuccess($this->lng->txt('msg_message_deleted'));
2542  }
2543  else
2544  {
2545  ilUtil::sendFailure($this->lng->txt('msg_no_message_deleted'));
2546  }
2547  }
2548  catch (Exception $e)
2549  {
2550  global $ilLog;
2551  $ilLog->write('Error: ' + $e->getMessage());
2552  }
2553  $this->tpl->setVariable("ADM_CONTENT", $form_gui->getHTML());
2554  }
2555 
2556  public function mailCodesObject()
2557  {
2558  $this->handleWriteAccess();
2559  $this->setCodesSubtabs();
2560 
2561  $mailData['m_subject'] = (array_key_exists('m_subject', $_POST)) ? $_POST['m_subject'] : sprintf($this->lng->txt('default_codes_mail_subject'), $this->object->getTitle());
2562  $mailData['m_message'] = (array_key_exists('m_message', $_POST)) ? $_POST['m_message'] : $this->lng->txt('default_codes_mail_message');
2563  $mailData['m_notsent'] = (array_key_exists('m_notsent', $_POST)) ? $_POST['m_notsent'] : '1';
2564 
2565  include_once("./Modules/Survey/classes/forms/FormMailCodesGUI.php");
2566  $form_gui = new FormMailCodesGUI($this);
2567  $form_gui->setValuesByArray($mailData);
2568  $this->tpl->setVariable("ADM_CONTENT", $form_gui->getHTML());
2569  }
2570 
2571  public function sendCodesMailObject()
2572  {
2573  $this->handleWriteAccess();
2574  $this->setCodesSubtabs();
2575 
2576  include_once("./Modules/Survey/classes/forms/FormMailCodesGUI.php");
2577  $form_gui = new FormMailCodesGUI($this);
2578  if ($form_gui->checkInput())
2579  {
2580  $code_exists = strpos($_POST['m_message'], '[code]') !== FALSE;
2581  if (!$code_exists)
2582  {
2583  if (!$code_exists) ilUtil::sendFailure($this->lng->txt('please_enter_mail_code'));
2584  $form_gui->setValuesByPost();
2585  }
2586  else
2587  {
2588  if ($_POST['savemessage'] == 1)
2589  {
2590  global $ilUser;
2591  $title = (strlen($_POST['savemessagetitle'])) ? $_POST['savemessagetitle'] : ilStr::substr($_POST['m_message'], 0, 40) . '...';
2592  $this->object->saveUserSettings($ilUser->getId(), 'savemessage', $title, $_POST['m_message']);
2593  }
2594  $this->object->sendCodes($_POST['m_notsent'], $_POST['m_subject'], $_POST['m_message']);
2595  ilUtil::sendSuccess($this->lng->txt('mail_sent'), true);
2596  $this->ctrl->redirect($this, 'codesMail');
2597  }
2598  }
2599  else
2600  {
2601  $form_gui->setValuesByPost();
2602  }
2603  $this->tpl->setVariable("ADM_CONTENT", $form_gui->getHTML());
2604  }
2605 
2606  public function cancelCodesMailObject()
2607  {
2608  $this->ctrl->redirect($this, 'codesMail');
2609  }
2610 
2612  {
2613  if (!is_array($_POST['chb_ext']) || count(is_array($_POST['chb_ext'])) == 0)
2614  {
2615  ilUtil::sendInfo($this->lng->txt("err_no_selection"), true);
2616  $this->ctrl->redirect($this, 'codesMail');
2617  }
2618  foreach ($_POST['chb_ext'] as $code)
2619  {
2620  $this->object->deleteSurveyCode($code);
2621  }
2622  ilUtil::sendSuccess($this->lng->txt('external_recipients_deleted'), true);
2623  $this->ctrl->redirect($this, 'codesMail');
2624  }
2625 
2627  {
2628  $hasErrors = $this->importExternalMailRecipientsObject(true, 2);
2629  if (!$hasErrors)
2630  {
2631  $data = array();
2632  $existingdata = $this->object->getExternalCodeRecipients();
2633  if (count($existingdata))
2634  {
2635  $first = array_shift($existingdata);
2636  foreach ($first as $key => $value)
2637  {
2638  if (strcmp($key, 'code') != 0 && strcmp($key, 'sent') != 0)
2639  {
2640  $data[$key] = $_POST[$key];
2641  }
2642  }
2643  }
2644  if (count($data))
2645  {
2646  $this->object->createSurveyCodesForExternalData(array($data));
2647  ilUtil::sendSuccess($this->lng->txt('external_recipients_imported'), true);
2648  }
2649  $this->ctrl->redirect($this, 'codesMail');
2650  }
2651  }
2652 
2654  {
2655  $hasErrors = $this->importExternalMailRecipientsObject(true, 1);
2656  if (!$hasErrors)
2657  {
2658  $data = preg_split("/[\n\r]/", $_POST['externaltext']);
2659  $fields = preg_split("/;/", array_shift($data));
2660  if (!in_array('email', $fields))
2661  {
2662  $_SESSION['externaltext'] = $_POST['externaltext'];
2663  ilUtil::sendFailure($this->lng->txt('err_external_rcp_no_email_column'), true);
2664  $this->ctrl->redirect($this, 'importExternalMailRecipients');
2665  }
2666  $existingdata = $this->object->getExternalCodeRecipients();
2667  $existingcolumns = array();
2668  if (count($existingdata))
2669  {
2670  $first = array_shift($existingdata);
2671  foreach ($first as $key => $value)
2672  {
2673  array_push($existingcolumns, $key);
2674  }
2675  }
2676  $founddata = array();
2677  foreach ($data as $datarow)
2678  {
2679  $row = preg_split("/;/", $datarow);
2680  if (count($row) == count($fields))
2681  {
2682  $dataset = array();
2683  foreach ($fields as $idx => $fieldname)
2684  {
2685  if (count($existingcolumns))
2686  {
2687  if (array_key_exists($idx, $existingcolumns))
2688  {
2689  $dataset[$fieldname] = $row[$idx];
2690  }
2691  }
2692  else
2693  {
2694  $dataset[$fieldname] = $row[$idx];
2695  }
2696  }
2697  if (strlen($dataset['email']))
2698  {
2699  array_push($founddata, $dataset);
2700  }
2701  }
2702  }
2703  $this->object->createSurveyCodesForExternalData($founddata);
2704  ilUtil::sendSuccess($this->lng->txt('external_recipients_imported'), true);
2705  $this->ctrl->redirect($this, 'codesMail');
2706  }
2707  }
2708 
2710  {
2711  $hasErrors = $this->importExternalMailRecipientsObject(true, 0);
2712  if (!$hasErrors)
2713  {
2714  include_once "./Services/Utilities/classes/class.ilCSVReader.php";
2715  $reader = new ilCSVReader();
2716  $reader->open($_FILES['externalmails']['tmp_name']);
2717  $data = $reader->getDataArrayFromCSVFile();
2718  $fields = array_shift($data);
2719  if (!in_array('email', $fields))
2720  {
2721  $reader->close();
2722  ilUtil::sendFailure($this->lng->txt('err_external_rcp_no_email'), true);
2723  $this->ctrl->redirect($this, 'codesMail');
2724  }
2725  $existingdata = $this->object->getExternalCodeRecipients();
2726  $existingcolumns = array();
2727  if (count($existingdata))
2728  {
2729  $first = array_shift($existingdata);
2730  foreach ($first as $key => $value)
2731  {
2732  array_push($existingcolumns, $key);
2733  }
2734  }
2735  $founddata = array();
2736  foreach ($data as $row)
2737  {
2738  if (count($row) == count($fields))
2739  {
2740  $dataset = array();
2741  foreach ($fields as $idx => $fieldname)
2742  {
2743  if (count($existingcolumns))
2744  {
2745  if (array_key_exists($idx, $existingcolumns))
2746  {
2747  $dataset[$fieldname] = $row[$idx];
2748  }
2749  }
2750  else
2751  {
2752  $dataset[$fieldname] = $row[$idx];
2753  }
2754  }
2755  if (strlen($dataset['email']))
2756  {
2757  array_push($founddata, $dataset);
2758  }
2759  }
2760  }
2761  $reader->close();
2762  $this->object->createSurveyCodesForExternalData($founddata);
2763  ilUtil::sendSuccess($this->lng->txt('external_recipients_imported'), true);
2764  $this->ctrl->redirect($this, 'codesMail');
2765  }
2766  }
2767 
2768  function importExternalMailRecipientsObject($checkonly = false, $formindex = -1)
2769  {
2770  global $ilAccess;
2771 
2772  $this->handleWriteAccess();
2773  $this->setCodesSubtabs();
2774 
2775  $savefields = (
2776  strcmp($this->ctrl->getCmd(), "importExternalRecipientsFromFile") == 0 ||
2777  strcmp($this->ctrl->getCmd(), "importExternalRecipientsFromText") == 0 ||
2778  strcmp($this->ctrl->getCmd(), "importExternalRecipientsFromDataset") == 0
2779  ) ? TRUE : FALSE;
2780 
2781  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
2782  $form_import_file = new ilPropertyFormGUI();
2783  $form_import_file->setFormAction($this->ctrl->getFormAction($this));
2784  $form_import_file->setTableWidth("100%");
2785  $form_import_file->setId("codes_import_file");
2786 
2787  $headerfile = new ilFormSectionHeaderGUI();
2788  $headerfile->setTitle($this->lng->txt("import_from_file"));
2789  $form_import_file->addItem($headerfile);
2790 
2791  $externalmails = new ilFileInputGUI($this->lng->txt("externalmails"), "externalmails");
2792  $externalmails->setInfo($this->lng->txt('externalmails_info'));
2793  $externalmails->setRequired(true);
2794  $form_import_file->addItem($externalmails);
2795  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form_import_file->addCommandButton("importExternalRecipientsFromFile", $this->lng->txt("import"));
2796  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form_import_file->addCommandButton("codesMail", $this->lng->txt("cancel"));
2797 
2798  // import text
2799 
2800  $form_import_text = new ilPropertyFormGUI();
2801  $form_import_text->setFormAction($this->ctrl->getFormAction($this));
2802  $form_import_text->setTableWidth("100%");
2803  $form_import_text->setId("codes_import_text");
2804 
2805  $headertext = new ilFormSectionHeaderGUI();
2806  $headertext->setTitle($this->lng->txt("import_from_text"));
2807  $form_import_text->addItem($headertext);
2808 
2809  $inp = new ilTextAreaInputGUI($this->lng->txt('externaltext'), 'externaltext');
2810  if (array_key_exists('externaltext', $_SESSION) && strlen($_SESSION['externaltext']))
2811  {
2812  $inp->setValue($_SESSION['externaltext']);
2813  }
2814  else
2815  {
2816  $inp->setValue($this->lng->txt('mail_import_example1') . "\n" . $this->lng->txt('mail_import_example2') . "\n" . $this->lng->txt('mail_import_example3') . "\n");
2817  }
2818  $inp->setRequired(true);
2819  $inp->setCols(80);
2820  $inp->setRows(10);
2821  $inp->setInfo($this->lng->txt('externaltext_info'));
2822  $form_import_text->addItem($inp);
2823  unset($_SESSION['externaltext']);
2824 
2825  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form_import_text->addCommandButton("importExternalRecipientsFromText", $this->lng->txt("import"));
2826  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form_import_text->addCommandButton("codesMail", $this->lng->txt("cancel"));
2827 
2828  // import dataset
2829 
2830  $form_import_dataset = new ilPropertyFormGUI();
2831  $form_import_dataset->setFormAction($this->ctrl->getFormAction($this));
2832  $form_import_dataset->setTableWidth("100%");
2833  $form_import_dataset->setId("codes_import_dataset");
2834 
2835  $headerfile = new ilFormSectionHeaderGUI();
2836  $headerfile->setTitle($this->lng->txt("import_from_dataset"));
2837  $form_import_dataset->addItem($headerfile);
2838 
2839  $existingdata = $this->object->getExternalCodeRecipients();
2840  $existingcolumns = array('email');
2841  if (count($existingdata))
2842  {
2843  $first = array_shift($existingdata);
2844  foreach ($first as $key => $value)
2845  {
2846  if (strcmp($key, 'email') != 0 && strcmp($key, 'code') != 0 && strcmp($key, 'sent') != 0)
2847  {
2848  array_push($existingcolumns, $key);
2849  }
2850  }
2851  }
2852 
2853  foreach ($existingcolumns as $column)
2854  {
2855  $inp = new ilTextInputGUI($column, $column);
2856  $inp->setSize(50);
2857  if (strcmp($column, 'email') == 0)
2858  {
2859  $inp->setRequired(true);
2860  }
2861  else
2862  {
2863  $inp->setRequired(false);
2864  }
2865  $form_import_dataset->addItem($inp);
2866  }
2867  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form_import_dataset->addCommandButton("importExternalRecipientsFromDataset", $this->lng->txt("import"));
2868  if ($ilAccess->checkAccess("write", "", $_GET["ref_id"])) $form_import_dataset->addCommandButton("codesMail", $this->lng->txt("cancel"));
2869 
2870  $errors = false;
2871 
2872  if ($savefields)
2873  {
2874  switch ($formindex)
2875  {
2876  case 0:
2877  $errors = !$form_import_file->checkInput();
2878  $form_import_file->setValuesByPost();
2879  if ($errors) $checkonly = false;
2880  break;
2881  case 1:
2882  $errors = !$form_import_text->checkInput();
2883  $form_import_text->setValuesByPost();
2884  if ($errors) $checkonly = false;
2885  break;
2886  case 2:
2887  $errors = !$form_import_dataset->checkInput();
2888  $form_import_dataset->setValuesByPost();
2889  if ($errors) $checkonly = false;
2890  break;
2891  }
2892  }
2893 
2894  if (!$checkonly)
2895  {
2896  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_external_mail.html", "Modules/Survey");
2897  $this->tpl->setVariable("HEADLINE", $this->lng->txt("external_mails_import"));
2898  $this->tpl->setVariable("FORM1", $form_import_file->getHTML());
2899  $this->tpl->setVariable("FORM2", $form_import_text->getHTML());
2900  $this->tpl->setVariable("FORM3", $form_import_dataset->getHTML());
2901  }
2902  return $errors;
2903  }
2904 
2908  public function constraintsAddObject()
2909  {
2910  if (strlen($_POST["v"]) == 0)
2911  {
2912  ilUtil::sendFailure($this->lng->txt("msg_enter_value_for_valid_constraint"));
2913  return $this->constraintStep3Object();
2914  }
2915  $survey_questions =& $this->object->getSurveyQuestions();
2916  $structure =& $_SESSION["constraintstructure"];
2917  $include_elements = $_SESSION["includeElements"];
2918  foreach ($include_elements as $elementCounter)
2919  {
2920  if (is_array($structure[$elementCounter]))
2921  {
2922  if (strlen($_GET["precondition"]))
2923  {
2924  $this->object->updateConstraint($_GET['precondition'], $_POST["q"], $_POST["r"], $_POST["v"], $_POST['c']);
2925  }
2926  else
2927  {
2928  $constraint_id = $this->object->addConstraint($_POST["q"], $_POST["r"], $_POST["v"], $_POST['c']);
2929  foreach ($structure[$elementCounter] as $key => $question_id)
2930  {
2931  $this->object->addConstraintToQuestion($question_id, $constraint_id);
2932  }
2933  }
2934  if (count($structure[$elementCounter]) > 1)
2935  {
2936  $this->object->updateConjunctionForQuestions($structure[$elementCounter], $_POST['c']);
2937  }
2938  }
2939  }
2940  unset($_SESSION["includeElements"]);
2941  unset($_SESSION["constraintstructure"]);
2942  $this->ctrl->redirect($this, "constraints");
2943  }
2944 
2948  public function constraintStep1Object()
2949  {
2950  $survey_questions =& $this->object->getSurveyQuestions();
2951  $structure =& $_SESSION["constraintstructure"];
2952  $start = $_GET["start"];
2953  $option_questions = array();
2954  for ($i = 1; $i < $start; $i++)
2955  {
2956  if (is_array($structure[$i]))
2957  {
2958  foreach ($structure[$i] as $key => $question_id)
2959  {
2960  if ($survey_questions[$question_id]["usableForPrecondition"])
2961  {
2962  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"]));
2963  }
2964  }
2965  }
2966  }
2967  if (count($option_questions) == 0)
2968  {
2969  unset($_SESSION["includeElements"]);
2970  unset($_SESSION["constraintstructure"]);
2971  ilUtil::sendInfo($this->lng->txt("constraints_no_nonessay_available"), true);
2972  $this->ctrl->redirect($this, "constraints");
2973  }
2974  $this->constraintForm(1, $_POST, $survey_questions, $option_questions);
2975  }
2976 
2980  public function constraintStep2Object()
2981  {
2982  $survey_questions =& $this->object->getSurveyQuestions();
2983  $option_questions = array();
2984  array_push($option_questions, array("question_id" => $_POST["q"], "title" => $survey_questions[$_POST["q"]]["title"], "type_tag" => $survey_questions[$_POST["q"]]["type_tag"]));
2985  $this->constraintForm(2, $_POST, $survey_questions, $option_questions);
2986  }
2987 
2991  public function constraintStep3Object()
2992  {
2993  $survey_questions =& $this->object->getSurveyQuestions();
2994  $option_questions = array();
2995  if (strlen($_GET["precondition"]))
2996  {
2997  $pc = $this->object->getPrecondition($_GET["precondition"]);
2998  $postvalues = array(
2999  "c" => $pc["conjunction"],
3000  "q" => $pc["question_fi"],
3001  "r" => $pc["relation_id"],
3002  "v" => $pc["value"]
3003  );
3004  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"]));
3005  $this->constraintForm(3, $postvalues, $survey_questions, $option_questions);
3006  }
3007  else
3008  {
3009  array_push($option_questions, array("question_id" => $_POST["q"], "title" => $survey_questions[$_POST["q"]]["title"], "type_tag" => $survey_questions[$_POST["q"]]["type_tag"]));
3010  $this->constraintForm(3, $_POST, $survey_questions, $option_questions);
3011  }
3012  }
3013 
3014  public function constraintForm($step, $postvalues, &$survey_questions, $questions = FALSE)
3015  {
3016  if (strlen($_GET["start"])) $this->ctrl->setParameter($this, "start", $_GET["start"]);
3017  $this->ctrl->saveParameter($this, "precondition");
3018  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
3019  $form = new ilPropertyFormGUI();
3020  $form->setFormAction($this->ctrl->getFormAction($this));
3021  $form->setTableWidth("100%");
3022  $form->setId("constraintsForm");
3023 
3024  $title = "";
3025  if ($survey_questions[$_SESSION["constraintstructure"][$_GET["start"]][0]]["questionblock_id"] > 0)
3026  {
3027  $title = $this->lng->txt("questionblock") . ": " . $survey_questions[$_SESSION["constraintstructure"][$_GET["start"]][0]]["questionblock_title"];
3028  }
3029  else
3030  {
3031  $title = $this->lng->txt($survey_questions[$_SESSION["constraintstructure"][$_GET["start"]][0]]["type_tag"]) . ": " . $survey_questions[$_SESSION["constraintstructure"][$_GET["start"]][0]]["title"];
3032  }
3033  $header = new ilFormSectionHeaderGUI();
3034  $header->setTitle($title);
3035  $form->addItem($header);
3036 
3037  $fulfilled = new ilRadioGroupInputGUI($this->lng->txt("constraint_fulfilled"), "c");
3038  $fulfilled->addOption(new ilRadioOption($this->lng->txt("conjunction_and"), '0', ''));
3039  $fulfilled->addOption(new ilRadioOption($this->lng->txt("conjunction_or"), '1', ''));
3040  $fulfilled->setValue((strlen($postvalues['c'])) ? $postvalues['c'] : 0);
3041  $form->addItem($fulfilled);
3042 
3043  $step1 = new ilSelectInputGUI($this->lng->txt("step") . " 1: " . $this->lng->txt("select_prior_question"), "q");
3044  $options = array();
3045  if (is_array($questions))
3046  {
3047  foreach ($questions as $question)
3048  {
3049  $options[$question["question_id"]] = $question["title"] . " (" . SurveyQuestion::_getQuestionTypeName($question["type_tag"]) . ")";
3050  }
3051  }
3052  $step1->setOptions($options);
3053  $step1->setValue($postvalues["q"]);
3054  $form->addItem($step1);
3055 
3056  if ($step > 1)
3057  {
3058  $relations = $this->object->getAllRelations();
3059  $step2 = new ilSelectInputGUI($this->lng->txt("step") . " 2: " . $this->lng->txt("select_relation"), "r");
3060  $options = array();
3061  foreach ($relations as $rel_id => $relation)
3062  {
3063  if (in_array($relation["short"], $survey_questions[$postvalues["q"]]["availableRelations"]))
3064  {
3065  $options[$rel_id] = $relation['short'];
3066  }
3067  }
3068  $step2->setOptions($options);
3069  $step2->setValue($postvalues["r"]);
3070  $form->addItem($step2);
3071  }
3072 
3073  if ($step > 2)
3074  {
3075  $variables =& $this->object->getVariables($postvalues["q"]);
3076  $question_type = $survey_questions[$postvalues["q"]]["type_tag"];
3077  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
3078  SurveyQuestion::_includeClass($question_type);
3079  $question = new $question_type();
3080  $question->loadFromDb($postvalues["q"]);
3081 
3082  $step3 = $question->getPreconditionSelectValue($postvalues["v"], $this->lng->txt("step") . " 3: " . $this->lng->txt("select_value"), "v");
3083  $form->addItem($step3);
3084  }
3085 
3086  switch ($step)
3087  {
3088  case 1:
3089  $cmd_continue = "constraintStep2";
3090  $cmd_back = "constraints";
3091  break;
3092  case 2:
3093  $cmd_continue = "constraintStep3";
3094  $cmd_back = "constraintStep1";
3095  break;
3096  case 3:
3097  $cmd_continue = "constraintsAdd";
3098  $cmd_back = "constraintStep2";
3099  break;
3100  }
3101  $form->addCommandButton($cmd_back, $this->lng->txt("back"));
3102  $form->addCommandButton($cmd_continue, $this->lng->txt("continue"));
3103 
3104  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
3105  }
3106 
3110  public function deleteConstraintsObject()
3111  {
3112  $survey_questions =& $this->object->getSurveyQuestions();
3113  $structure =& $_SESSION["constraintstructure"];
3114  foreach ($_POST as $key => $value)
3115  {
3116  if (preg_match("/^constraint_(\d+)_(\d+)/", $key, $matches))
3117  {
3118  $this->object->deleteConstraint($matches[2]);
3119  }
3120  }
3121 
3122  $this->ctrl->redirect($this, "constraints");
3123  }
3124 
3126  {
3127  $include_elements = $_POST["includeElements"];
3128  if ((!is_array($include_elements)) || (count($include_elements) == 0))
3129  {
3130  ilUtil::sendInfo($this->lng->txt("constraints_no_questions_or_questionblocks_selected"), true);
3131  $this->ctrl->redirect($this, "constraints");
3132  }
3133  else if (count($include_elements) >= 1)
3134  {
3135  $_SESSION["includeElements"] = $include_elements;
3136  sort($include_elements, SORT_NUMERIC);
3137  $_GET["start"] = $include_elements[0];
3138  $this->constraintStep1Object();
3139  }
3140  }
3141 
3143  {
3144  $_SESSION["includeElements"] = array($_GET["start"]);
3145  $this->ctrl->setParameter($this, "precondition", $_GET["precondition"]);
3146  $this->ctrl->setParameter($this, "start", $_GET["start"]);
3147  $this->ctrl->redirect($this, "constraintStep3");
3148  }
3149 
3153  public function constraintsObject()
3154  {
3155  $this->handleWriteAccess();
3156 
3157  global $rbacsystem;
3158 
3159  $hasDatasets = $this->object->_hasDatasets($this->object->getSurveyId());
3160  $step = 0;
3161  if (array_key_exists("step", $_GET)) $step = $_GET["step"];
3162  switch ($step)
3163  {
3164  case 1:
3165  $this->constraintStep1Object();
3166  return;
3167  break;
3168  case 2:
3169  return;
3170  break;
3171  case 3:
3172  return;
3173  break;
3174  }
3175 
3176  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_constraints_list.html", "Modules/Survey");
3177  $survey_questions =& $this->object->getSurveyQuestions();
3178  $last_questionblock_title = "";
3179  $counter = 1;
3180  $hasPreconditions = FALSE;
3181  $structure = array();
3182  $colors = array("tblrow1", "tblrow2");
3183  foreach ($survey_questions as $question_id => $data)
3184  {
3185  $title = $data["title"];
3186  $show = true;
3187  if ($data["questionblock_id"] > 0)
3188  {
3189  $title = $data["questionblock_title"];
3190  $type = $this->lng->txt("questionblock");
3191  if (strcmp($title, $last_questionblock_title) != 0)
3192  {
3193  $last_questionblock_title = $title;
3194  $structure[$counter] = array();
3195  array_push($structure[$counter], $data["question_id"]);
3196  }
3197  else
3198  {
3199  array_push($structure[$counter-1], $data["question_id"]);
3200  $show = false;
3201  }
3202  }
3203  else
3204  {
3205  $structure[$counter] = array($data["question_id"]);
3206  $type = $this->lng->txt("question");
3207  }
3208  if ($show)
3209  {
3210  if ($counter == 1)
3211  {
3212  $this->tpl->setCurrentBlock("description");
3213  $this->tpl->setVariable("DESCRIPTION", $this->lng->txt("constraints_first_question_description"));
3214  $this->tpl->parseCurrentBlock();
3215  }
3216  else
3217  {
3218  $constraints =& $this->object->getConstraints($data["question_id"]);
3219  $rowcount = 0;
3220  if (count($constraints))
3221  {
3222  $hasPreconditions = TRUE;
3223  foreach ($constraints as $constraint)
3224  {
3225  $this->tpl->setCurrentBlock("constraint");
3226  $this->tpl->setVariable("SEQUENCE_ID", $counter);
3227  $this->tpl->setVariable("CONSTRAINT_ID", $constraint["id"]);
3228  $this->tpl->setVariable("CONSTRAINT_TEXT", $survey_questions[$constraint["question"]]["title"] . " " . $constraint["short"] . " " . $constraint["valueoutput"]);
3229  $this->tpl->setVariable("TEXT_EDIT_PRECONDITION", $this->lng->txt("edit"));
3230  $this->ctrl->setParameter($this, "precondition", $constraint["id"]);
3231  $this->ctrl->setParameter($this, "start", $counter);
3232  $this->tpl->setVariable("EDIT_PRECONDITION", $this->ctrl->getLinkTarget($this, "editPrecondition"));
3233  $this->ctrl->setParameter($this, "precondition", "");
3234  $this->ctrl->setParameter($this, "start", "");
3235  $this->tpl->parseCurrentBlock();
3236  }
3237  if (count($constraints) > 1)
3238  {
3239  $this->tpl->setCurrentBlock("conjunction");
3240  $this->tpl->setVariable("TEXT_CONJUNCTION", ($constraints[0]['conjunction']) ? $this->lng->txt('conjunction_or_title') : $this->lng->txt('conjunction_and_title'));
3241  $this->tpl->parseCurrentBlock();
3242  }
3243  }
3244  }
3245  if ($counter != 1)
3246  {
3247  $this->tpl->setCurrentBlock("include_elements");
3248  $this->tpl->setVariable("QUESTION_NR", "$counter");
3249  $this->tpl->parseCurrentBlock();
3250  }
3251  $this->tpl->setCurrentBlock("constraint_section");
3252  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
3253  $this->tpl->setVariable("QUESTION_NR", "$counter");
3254  $this->tpl->setVariable("TITLE", "$title");
3255  $icontype = "question.gif";
3256  if ($data["questionblock_id"] > 0)
3257  {
3258  $icontype = "questionblock.gif";
3259  }
3260  $this->tpl->setVariable("TYPE", "$type: ");
3261  include_once "./Services/Utilities/classes/class.ilUtil.php";
3262  $this->tpl->setVariable("ICON_HREF", ilUtil::getImagePath($icontype, "Modules/Survey"));
3263  $this->tpl->setVariable("ICON_ALT", $type);
3264  $this->tpl->parseCurrentBlock();
3265  $counter++;
3266  }
3267  }
3268  if ($rbacsystem->checkAccess("write", $this->ref_id) and !$hasDatasets)
3269  {
3270  if ($hasPreconditions)
3271  {
3272  $this->tpl->setCurrentBlock("selectall_preconditions");
3273  $this->tpl->setVariable("SELECT_ALL_PRECONDITIONS", $this->lng->txt("select_all"));
3274  $this->tpl->parseCurrentBlock();
3275  }
3276  $this->tpl->setCurrentBlock("selectall");
3277  $counter++;
3278  $this->tpl->setVariable("SELECT_ALL", $this->lng->txt("select_all"));
3279  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
3280  $this->tpl->parseCurrentBlock();
3281 
3282  if ($hasPreconditions)
3283  {
3284  $this->tpl->setCurrentBlock("delete_button");
3285  $this->tpl->setVariable("BTN_DELETE", $this->lng->txt("delete"));
3286  include_once "./Services/Utilities/classes/class.ilUtil.php";
3287  $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\">");
3288  $this->tpl->parseCurrentBlock();
3289  }
3290 
3291  $this->tpl->setCurrentBlock("buttons");
3292  $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\">");
3293  $this->tpl->setVariable("BTN_CREATE_CONSTRAINTS", $this->lng->txt("constraint_add"));
3294  $this->tpl->parseCurrentBlock();
3295  }
3296  $this->tpl->setCurrentBlock("adm_content");
3297  $this->tpl->setVariable("CONSTRAINTS_INTRODUCTION", $this->lng->txt("constraints_introduction"));
3298  $this->tpl->setVariable("DEFINED_PRECONDITIONS", $this->lng->txt("existing_constraints"));
3299  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this, "constraints"));
3300  $this->tpl->setVariable("CONSTRAINTS_HEADER", $this->lng->txt("constraints_list_of_entities"));
3301  $this->tpl->parseCurrentBlock();
3302  $_SESSION["constraintstructure"] = $structure;
3303  if ($hasDatasets)
3304  {
3305  ilUtil::sendInfo($this->lng->txt("survey_has_datasets_warning"));
3306  }
3307  }
3308 
3314  function infoScreenObject()
3315  {
3316  $this->ctrl->setCmd("showSummary");
3317  $this->ctrl->setCmdClass("ilinfoscreengui");
3318  $this->infoScreen();
3319  }
3320 
3321  function setNewTemplate()
3322  {
3323  global $tpl;
3324  $tpl = new ilTemplate("tpl.il_svy_svy_main.html", TRUE, TRUE, "Modules/Survey");
3325  // load style sheet depending on user's settings
3326  $location_stylesheet = ilUtil::getStyleSheetLocation();
3327  $tpl->setVariable("LOCATION_STYLESHEET",$location_stylesheet);
3328  $tpl->setVariable("LOCATION_JAVASCRIPT",dirname($location_stylesheet));
3329  }
3330 
3334  function infoScreen()
3335  {
3336  global $ilAccess;
3337  global $ilUser;
3338 
3339  if (!$ilAccess->checkAccess("visible", "", $this->ref_id))
3340  {
3341  $this->ilias->raiseError($this->lng->txt("msg_no_perm_read"),$this->ilias->error_obj->MESSAGE);
3342  }
3343 
3344  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
3345  $info = new ilInfoScreenGUI($this);
3346  include_once "./Modules/Survey/classes/class.ilSurveyExecutionGUI.php";
3347  $output_gui =& new ilSurveyExecutionGUI($this->object);
3348  $info->setFormAction($this->ctrl->getFormAction($output_gui, "infoScreen"));
3349  $info->enablePrivateNotes();
3350  $anonymize_key = NULL;
3351  if ($this->object->getAnonymize() == 1)
3352  {
3353  if ($_SESSION["anonymous_id"][$this->object->getId()])
3354  {
3355  $anonymize_key = $_SESSION["anonymous_id"][$this->object->getId()];
3356  }
3357  else if ($_POST["anonymous_id"])
3358  {
3359  $anonymize_key = $_POST["anonymous_id"];
3360  }
3361  }
3362  $canStart = $this->object->canStartSurvey($anonymize_key);
3363  $showButtons = $canStart["result"];
3364  if (!$showButtons) ilUtil::sendInfo(implode("<br />", $canStart["messages"]));
3365 
3366  if ($showButtons)
3367  {
3368  // output of start/resume buttons for personalized surveys
3369  if (!$this->object->getAnonymize())
3370  {
3371  $survey_started = $this->object->isSurveyStarted($ilUser->getId(), "");
3372  // Anonymous User tries to start a personalized survey
3373  if ($_SESSION["AccountId"] == ANONYMOUS_USER_ID)
3374  {
3375  ilUtil::sendInfo($this->lng->txt("anonymous_with_personalized_survey"));
3376  }
3377  else
3378  {
3379  if ($survey_started === 1)
3380  {
3381  ilUtil::sendInfo($this->lng->txt("already_completed_survey"));
3382  }
3383  elseif ($survey_started === 0)
3384  {
3385  $info->addFormButton("resume", $this->lng->txt("resume_survey"));
3386  }
3387  elseif ($survey_started === FALSE)
3388  {
3389  $info->addFormButton("start", $this->lng->txt("start_survey"));
3390  }
3391  }
3392  }
3393  // output of start/resume buttons for anonymized surveys
3394  else if ($this->object->getAnonymize() && !$this->object->isAccessibleWithoutCode())
3395  {
3396  if (($_SESSION["AccountId"] == ANONYMOUS_USER_ID) && (strlen($_POST["anonymous_id"]) == 0) && (strlen($_SESSION["anonymous_id"][$this->object->getId()]) == 0))
3397  {
3398  $info->setFormAction($this->ctrl->getFormAction($this, "infoScreen"));
3399  $info->addSection($this->lng->txt("anonymization"));
3400  $info->addProperty("", $this->lng->txt("anonymize_anonymous_introduction"));
3401  $info->addPropertyTextinput($this->lng->txt("enter_anonymous_id"), "anonymous_id", "", 8, "infoScreen", $this->lng->txt("submit"));
3402  }
3403  else
3404  {
3405  if (strlen($_POST["anonymous_id"]) > 0)
3406  {
3407  if (!$this->object->checkSurveyCode($_POST["anonymous_id"]))
3408  {
3409  ilUtil::sendInfo($this->lng->txt("wrong_survey_code_used"));
3410  }
3411  else
3412  {
3413  $anonymize_key = $_POST["anonymous_id"];
3414  }
3415  }
3416  else if (strlen($_SESSION["anonymous_id"][$this->object->getId()]) > 0)
3417  {
3418  if (!$this->object->checkSurveyCode($_SESSION["anonymous_id"][$this->object->getId()]))
3419  {
3420  ilUtil::sendInfo($this->lng->txt("wrong_survey_code_used"));
3421  }
3422  else
3423  {
3424  $anonymize_key = $_SESSION["anonymous_id"][$this->object->getId()];
3425  }
3426  }
3427  else
3428  {
3429  // registered users do not need to know that there is an anonymous key. The data is anonymized automatically
3430  $anonymize_key = $this->object->getUserAccessCode($ilUser->getId());
3431  if (!strlen($anonymize_key))
3432  {
3433  $anonymize_key = $this->object->createNewAccessCode();
3434  $this->object->saveUserAccessCode($ilUser->getId(), $anonymize_key);
3435  }
3436  }
3437  $info->addHiddenElement("anonymous_id", $anonymize_key);
3438  $survey_started = $this->object->isSurveyStarted($ilUser->getId(), $anonymize_key);
3439  if ($survey_started === 1)
3440  {
3441  ilUtil::sendInfo($this->lng->txt("already_completed_survey"));
3442  }
3443  elseif ($survey_started === 0)
3444  {
3445  $info->addFormButton("resume", $this->lng->txt("resume_survey"));
3446  }
3447  elseif ($survey_started === FALSE)
3448  {
3449  $info->addFormButton("start", $this->lng->txt("start_survey"));
3450  }
3451  }
3452  }
3453  else
3454  {
3455  // free access
3456  $survey_started = $this->object->isSurveyStarted($ilUser->getId(), "");
3457  if ($survey_started === 1)
3458  {
3459  ilUtil::sendInfo($this->lng->txt("already_completed_survey"));
3460  }
3461  elseif ($survey_started === 0)
3462  {
3463  $info->addFormButton("resume", $this->lng->txt("resume_survey"));
3464  }
3465  elseif ($survey_started === FALSE)
3466  {
3467  $info->addFormButton("start", $this->lng->txt("start_survey"));
3468  }
3469  }
3470  }
3471 
3472  if (strlen($this->object->getIntroduction()))
3473  {
3474  $introduction = $this->object->getIntroduction();
3475  $info->addSection($this->lng->txt("introduction"));
3476  $info->addProperty("", $this->object->prepareTextareaOutput($introduction));
3477  }
3478 
3479  $info->addSection($this->lng->txt("svy_general_properties"));
3480  if (strlen($this->object->getAuthor()))
3481  {
3482  $info->addProperty($this->lng->txt("author"), $this->object->getAuthor());
3483  }
3484  $info->addProperty($this->lng->txt("title"), $this->object->getTitle());
3485  switch ($this->object->getAnonymize())
3486  {
3487  case ANONYMIZE_OFF:
3488  $info->addProperty($this->lng->txt("anonymization"), $this->lng->txt("anonymize_personalized"));
3489  break;
3490  case ANONYMIZE_ON:
3491  if ($_SESSION["AccountId"] == ANONYMOUS_USER_ID)
3492  {
3493  $info->addProperty($this->lng->txt("anonymization"), $this->lng->txt("info_anonymize_with_code"));
3494  }
3495  else
3496  {
3497  $info->addProperty($this->lng->txt("anonymization"), $this->lng->txt("info_anonymize_registered_user"));
3498  }
3499  break;
3500  case ANONYMIZE_FREEACCESS:
3501  $info->addProperty($this->lng->txt("anonymization"), $this->lng->txt("info_anonymize_without_code"));
3502  break;
3503  }
3504  include_once "./Modules/Survey/classes/class.ilObjSurveyAccess.php";
3505  if ($ilAccess->checkAccess("write", "", $this->ref_id) || ilObjSurveyAccess::_hasEvaluationAccess($this->object->getId(), $ilUser->getId()))
3506  {
3507  $info->addProperty($this->lng->txt("evaluation_access"), $this->lng->txt("evaluation_access_info"));
3508  }
3509  $info->addMetaDataSections($this->object->getId(),0, $this->object->getType());
3510  $this->ctrl->forwardCommand($info);
3511  }
3512 
3518  function printViewObject()
3519  {
3520  global $ilias;
3521 
3522  $this->questionsSubtabs("printview");
3523  $template = new ilTemplate("tpl.il_svy_svy_printview.html", TRUE, TRUE, "Modules/Survey");
3524 
3525  include_once './Services/PDF/classes/class.ilHTMLToPDFTransformer.php';
3527  {
3528  $this->ctrl->setParameter($this, "pdf", "1");
3529  $template->setCurrentBlock("pdf_export");
3530  $template->setVariable("PDF_URL", $this->ctrl->getLinkTarget($this, "printView"));
3531  $this->ctrl->setParameter($this, "pdf", "");
3532  $template->setVariable("PDF_TEXT", $this->lng->txt("pdf_export"));
3533  $template->setVariable("PDF_IMG_ALT", $this->lng->txt("pdf_export"));
3534  $template->setVariable("PDF_IMG_URL", ilUtil::getHtmlPath(ilUtil::getImagePath("application-pdf.png")));
3535  $template->parseCurrentBlock();
3536  }
3537  $template->setVariable("PRINT_TEXT", $this->lng->txt("print"));
3538  $template->setVariable("PRINT_URL", "javascript:window.print();");
3539 
3540  $pages =& $this->object->getSurveyPages();
3541  foreach ($pages as $page)
3542  {
3543  if (count($page) > 0)
3544  {
3545  foreach ($page as $question)
3546  {
3547  $questionGUI = $this->object->getQuestionGUI($question["type_tag"], $question["question_id"]);
3548  if (is_object($questionGUI))
3549  {
3550  if (strlen($question["heading"]))
3551  {
3552  $template->setCurrentBlock("textblock");
3553  $template->setVariable("TEXTBLOCK", $question["heading"]);
3554  $template->parseCurrentBlock();
3555  }
3556  $template->setCurrentBlock("question");
3557  $template->setVariable("QUESTION_DATA", $questionGUI->getPrintView($this->object->getShowQuestionTitles(), $question["questionblock_show_questiontext"], $this->object->getSurveyId()));
3558  $template->parseCurrentBlock();
3559  }
3560  }
3561  if (count($page) > 1)
3562  {
3563  $template->setCurrentBlock("page");
3564  $template->setVariable("BLOCKTITLE", $page[0]["questionblock_title"]);
3565  $template->parseCurrentBlock();
3566  }
3567  else
3568  {
3569  $template->setCurrentBlock("page");
3570  $template->parseCurrentBlock();
3571  }
3572  }
3573  }
3574  $this->tpl->addCss("./Modules/Survey/templates/default/survey_print.css", "print");
3575  if (array_key_exists("pdf", $_GET) && ($_GET["pdf"] == 1))
3576  {
3577  $printbody = new ilTemplate("tpl.il_as_tst_print_body.html", TRUE, TRUE, "Modules/Test");
3578  $printbody->setVariable("TITLE", sprintf($this->lng->txt("tst_result_user_name"), $uname));
3579  $printbody->setVariable("ADM_CONTENT", $template->get());
3580  $printoutput = $printbody->get();
3581  $printoutput = preg_replace("/href=\".*?\"/", "", $printoutput);
3582 
3583  $pdfSetting = new ilSetting("pdf");
3584  include_once "./Services/PDF/classes/class.ilHTMLtoPDF.php";
3585  $transformer = null;
3586  switch ($pdfSetting->get('html_to_pdf_method'))
3587  {
3588  case 'fop':
3589  include_once "./Services/PDF/classes/class.ilHTMLtoPDFTransformerUsingFOP.php";
3590  $transformer = new ilHTMLtoPDFTransformerUsingFOP(ilUtil::getASCIIFilename($this->object->getTitle()) . ".pdf");
3591  $transformer->xsl = "./Modules/Survey/xml/question2fo.xsl";
3592  break;
3593  case 'webkit':
3594  include_once "./Services/PDF/classes/class.ilHTMLtoPDFTransformerUsingWebkit.php";
3595  $transformer = new ilHTMLtoPDFTransformerUsingWebkit(ilUtil::getASCIIFilename($this->object->getTitle()) . ".pdf");
3596  break;
3597  }
3598  if (is_object($transformer))
3599  {
3600  $generator = new ilHTMLtoPDF($transformer);
3601  $generator->deliverPDFFromHTMLString($printoutput);
3602  }
3603  }
3604  else
3605  {
3606  $this->tpl->setVariable("ADM_CONTENT", $template->get());
3607  }
3608  }
3609 
3610  function addLocatorItems()
3611  {
3612  global $ilLocator;
3613  switch ($this->ctrl->getCmd())
3614  {
3615  case "next":
3616  case "previous":
3617  case "start":
3618  case "resume":
3619  case "redirectQuestion":
3620  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "infoScreen"), "", $_GET["ref_id"]);
3621  break;
3622  case "evaluation":
3623  case "checkEvaluationAccess":
3624  case "evaluationdetails":
3625  case "evaluationuser":
3626  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "evaluation"), "", $_GET["ref_id"]);
3627  break;
3628  case "create":
3629  case "save":
3630  case "cancel":
3631  case "importFile":
3632  case "cloneAll":
3633  break;
3634  case "infoScreen":
3635  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "infoScreen"), "", $_GET["ref_id"]);
3636  break;
3637  default:
3638  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, ""), "", $_GET["ref_id"]);
3639  break;
3640  }
3641  }
3642 
3650  function questionsSubtabs($a_cmd)
3651  {
3652  $questions = ($a_cmd == 'questions') ? true : false;
3653  $printview = ($a_cmd == 'printview') ? true : false;
3654 
3655  $this->tabs_gui->addSubTabTarget("survey_question_editor", $this->ctrl->getLinkTarget($this, "questions"),
3656  "", "", "", $questions);
3657  $this->tabs_gui->addSubTabTarget("print_view", $this->ctrl->getLinkTarget($this, "printView"),
3658  "", "", "", $printview);
3659  }
3660 
3666  function setCodesSubtabs()
3667  {
3668  global $ilTabs;
3669  global $ilAccess;
3670 
3671  $ilTabs->addSubTabTarget
3672  (
3673  "codes",
3674  $this->ctrl->getLinkTarget($this,'codes'),
3675  array("codes", "createSurveyCodes", "setCodeLanguage", "deleteCodes", "exportCodes"),
3676  ""
3677  );
3678 
3679  $ilTabs->addSubTabTarget
3680  (
3681  "participating_users",
3682  $this->ctrl->getLinkTarget($this, "codesMail"),
3683  array("codesMail", "saveMailTableFields", "importExternalMailRecipients",
3684  'importExternalRecipientsFromFile', 'importExternalRecipientsFromText',
3685  'importExternalRecipientsFromDataset'),
3686  ""
3687  );
3688 
3689  $data = $this->object->getExternalCodeRecipients();
3690  if (count($data))
3691  {
3692  $ilTabs->addSubTabTarget
3693  (
3694  "mail_survey_codes",
3695  $this->ctrl->getLinkTarget($this, "mailCodes"),
3696  array("mailCodes", "sendCodesMail", "insertSavedMessage", "deleteSavedMessage"),
3697  ""
3698  );
3699  }
3700  }
3701 
3707  function setEvalSubtabs()
3708  {
3709  global $ilTabs;
3710  global $ilAccess;
3711  /* Change Sn */
3712  global $rbacreview;
3713  global $ilUser;
3714 
3715  $ilTabs->addSubTabTarget(
3716  "svy_eval_cumulated",
3717  $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "evaluation"),
3718  array("evaluation", "checkEvaluationAccess"),
3719  ""
3720  );
3721 
3722  $ilTabs->addSubTabTarget(
3723  "svy_eval_detail",
3724  $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "evaluationdetails"),
3725  array("evaluationdetails"),
3726  ""
3727  );
3728 
3729  if ($ilAccess->checkAccess("write", "", $this->object->getRefId()))
3730  {
3731  $ilTabs->addSubTabTarget(
3732  "svy_eval_user",
3733  $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "evaluationuser"),
3734  array("evaluationuser"),
3735  ""
3736  );
3737  }
3738  /* Change Sn */
3739  if ($rbacreview->isAssigned($ilUser->getId(),2)) {
3740  if ($ilAccess->checkAccess("write", "", $this->object->getRefId()))
3741  {
3742  $ilTabs->addSubTabTarget(
3743  "svy_eval_participants_state",
3744  $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "evaluationparticipantsstate"),
3745  array("evaluationparticipantsstate"),
3746  ""
3747  );
3748  }
3749  }
3750  /* Change Sn End */
3751  }
3752 
3754  {
3755  global $ilAccess;
3756  global $ilTabs;
3757 
3758  if ($ilAccess->checkAccess("write", "", $this->ref_id))
3759  {
3760  $ilTabs->setBackTarget($this->lng->txt("menubacktosurvey"), $this->ctrl->getLinkTarget($this, "questions"));
3761  $ilTabs->addTarget("browse_for_questions",
3762  $this->ctrl->getLinkTarget($this, "browseForQuestions"),
3763  array("browseForQuestions", "browseForQuestionblocks"),
3764  "", ""
3765  );
3766  }
3767  }
3768 
3774  function getTabs(&$tabs_gui)
3775  {
3776  global $ilAccess, $ilUser;
3777 
3778  if (strcmp($this->ctrl->getNextClass(), 'ilrepositorysearchgui') != 0)
3779  {
3780  switch ($this->ctrl->getCmd())
3781  {
3782  case "browseForQuestions":
3783  case "browseForQuestionblocks":
3784  case "insertQuestions":
3785  case "filterQuestions":
3786  case "resetFilterQuestions":
3787  case "changeDatatype":
3788 
3789  case "start":
3790  case "resume":
3791  case "next":
3792  case "previous":
3793  case "redirectQuestion":
3794  return;
3795  break;
3796  case "evaluation":
3797  case "checkEvaluationAccess":
3798  case "evaluationdetails":
3799  case "evaluationuser":
3800  case "evaluationparticipantsstate": //Change Sn
3801  $this->setEvalSubtabs();
3802  break;
3803  case "start":
3804  case "resume":
3805  case "next":
3806  case "previous":
3807  case "redirectQuestion":
3808  return;
3809  break;
3810  case "evaluation":
3811  case "checkEvaluationAccess":
3812  case "evaluationdetails":
3813  case "evaluationuser":
3814  $this->setEvalSubtabs();
3815  break;
3816  }
3817  }
3818 
3819  // questions
3820  if ($ilAccess->checkAccess("write", "", $this->ref_id))
3821  {
3822  $force_active = ($_GET["up"] != "" || $_GET["down"] != "")
3823  ? true
3824  : false;
3825 
3826  $tabs_gui->addTarget("survey_questions",
3827  $this->ctrl->getLinkTarget($this,'questions'),
3828  array("questions", "browseForQuestions", "createQuestion",
3829  "filterQuestions", "resetFilterQuestions", "changeDatatype", "insertQuestions",
3830  "removeQuestions", "cancelRemoveQuestions", "confirmRemoveQuestions",
3831  "defineQuestionblock", "saveDefineQuestionblock", "cancelDefineQuestionblock",
3832  "unfoldQuestionblock", "moveQuestions",
3833  "insertQuestionsBefore", "insertQuestionsAfter", "saveObligatory",
3834  "addHeading", "saveHeading", "cancelHeading", "editHeading",
3835  "confirmRemoveHeading", "cancelRemoveHeading", "printView"),
3836  "", "", $force_active);
3837  }
3838 
3839  if ($ilAccess->checkAccess("visible", "", $this->ref_id))
3840  {
3841  $tabs_gui->addTarget("info_short",
3842  $this->ctrl->getLinkTarget($this,'infoScreen'),
3843  array("infoScreen", "showSummary"));
3844  }
3845 
3846  // properties
3847  if ($ilAccess->checkAccess("write", "", $this->ref_id))
3848  {
3849  $force_active = ($this->ctrl->getCmd() == "")
3850  ? true
3851  : false;
3852  $tabs_gui->addTarget("settings",
3853  $this->ctrl->getLinkTarget($this,'properties'),
3854  array("properties", "save", "cancel", 'saveProperties'), "",
3855  "", $force_active);
3856  }
3857 
3858  // questions
3859  if ($ilAccess->checkAccess("write", "", $this->ref_id))
3860  {
3861  // constraints
3862  $tabs_gui->addTarget("constraints",
3863  $this->ctrl->getLinkTarget($this, "constraints"),
3864  array("constraints", "constraintStep1", "constraintStep2",
3865  "constraintStep3", "constraintsAdd", "createConstraints",
3866  "editPrecondition"),
3867  "");
3868  }
3869 
3870  if (($ilAccess->checkAccess("write", "", $this->ref_id)) || ($ilAccess->checkAccess("invite", "", $this->ref_id)))
3871  {
3872  // invite
3873  $tabs_gui->addTarget("invitation",
3874  $this->ctrl->getLinkTarget($this, 'invite'),
3875  array("invite", "saveInvitationStatus",
3876  "inviteUserGroup", "disinviteUserGroup"),
3877  "");
3878  }
3879 
3880  if ($ilAccess->checkAccess("write", "", $this->ref_id))
3881  {
3882  // maintenance
3883  $tabs_gui->addTarget("maintenance",
3884  $this->ctrl->getLinkTarget($this,'maintenance'),
3885  array("maintenance", "deleteAllUserData"),
3886  "");
3887 
3888  if ($this->object->getAnonymize() == 1)
3889  {
3890  // code
3891  $tabs_gui->addTarget("codes",
3892  $this->ctrl->getLinkTarget($this,'codes'),
3893  array("codes", "exportCodes", 'codesMail', 'saveMailTableFields', 'importExternalMailRecipients',
3894  'mailCodes', 'sendCodesMail', 'importExternalRecipientsFromFile', 'importExternalRecipientsFromText',
3895  'importExternalRecipientsFromDataset', 'insertSavedMessage', 'deleteSavedMessage'),
3896  "");
3897  }
3898  }
3899 
3900  include_once "./Modules/Survey/classes/class.ilObjSurveyAccess.php";
3901  if ($ilAccess->checkAccess("write", "", $this->ref_id) || ilObjSurveyAccess::_hasEvaluationAccess($this->object->getId(), $ilUser->getId()))
3902  {
3903  // evaluation
3904  $tabs_gui->addTarget("svy_evaluation",
3905  $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "evaluation"),
3906  array("evaluation", "checkEvaluationAccess", "evaluationdetails",
3907  "evaluationuser", "evaluationparticipantsstate"), // Change Sn
3908  "");
3909  }
3910 
3911  if ($ilAccess->checkAccess("write", "", $this->ref_id))
3912  {
3913  // meta data
3914  $tabs_gui->addTarget("meta_data",
3915  $this->ctrl->getLinkTargetByClass('ilmdeditorgui','listSection'),
3916  "", "ilmdeditorgui");
3917 
3918  // export
3919  $tabs_gui->addTarget("export",
3920  $this->ctrl->getLinkTarget($this,'export'),
3921  array("export", "createExportFile", "confirmDeleteExportFile",
3922  "downloadExportFile"),
3923  ""
3924  );
3925  }
3926 
3927  if ($ilAccess->checkAccess("edit_permission", "", $this->ref_id))
3928  {
3929  // permissions
3930  $tabs_gui->addTarget("perm_settings",
3931  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), array("perm","info","owner"), 'ilpermissiongui');
3932  }
3933  }
3934 
3940  function _goto($a_target, $a_access_code = "")
3941  {
3942  global $ilAccess, $ilErr, $lng;
3943  if ($ilAccess->checkAccess("read", "", $a_target))
3944  {
3945  include_once "./Services/Utilities/classes/class.ilUtil.php";
3946  if (strlen($a_access_code))
3947  {
3948  $_SESSION["anonymous_id"][ilObject::_lookupObjId($a_target)] = $a_access_code;
3949  $_GET["baseClass"] = "ilObjSurveyGUI";
3950  $_GET["cmd"] = "infoScreen";
3951  $_GET["ref_id"] = $a_target;
3952  include("ilias.php");
3953  exit;
3954  }
3955  else
3956  {
3957  $_GET["baseClass"] = "ilObjSurveyGUI";
3958  $_GET["cmd"] = "infoScreen";
3959  $_GET["ref_id"] = $a_target;
3960  include("ilias.php");
3961  exit;
3962  }
3963  }
3964  else if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
3965  {
3966  $_GET["cmd"] = "frameset";
3967  $_GET["target"] = "";
3968  $_GET["ref_id"] = ROOT_FOLDER_ID;
3969  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
3970  ilObject::_lookupTitle(ilObject::_lookupObjId($a_target))), true);
3971  include("repository.php");
3972  exit;
3973  }
3974 
3975  $ilErr->raiseError($lng->txt("msg_no_perm_read_lm"), $ilErr->FATAL);
3976  }
3977 
3978 } // END class.ilObjSurveyGUI
3979 ?>