ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjSurveyQuestionPoolGUI.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 include_once "./classes/class.ilObjectGUI.php";
25 include_once "./Modules/Survey/classes/inc.SurveyConstants.php";
26 
43 {
45 
50  public function ilObjSurveyQuestionPoolGUI()
51  {
52  global $lng, $ilCtrl;
53 
54  $this->type = "spl";
55  $lng->loadLanguageModule("survey");
56  $this->ctrl =& $ilCtrl;
57  $this->ctrl->saveParameter($this, array("ref_id", "calling_survey", "new_for_survey"));
58 
59  $this->ilObjectGUI("",$_GET["ref_id"], true, false);
60  }
61 
65  public function executeCommand()
66  {
67  global $ilAccess, $ilNavigationHistory;
68 
69  if ((!$ilAccess->checkAccess("read", "", $_GET["ref_id"])) && (!$ilAccess->checkAccess("visible", "", $_GET["ref_id"])))
70  {
71  global $ilias;
72  $ilias->raiseError($this->lng->txt("permission_denied"), $ilias->error_obj->MESSAGE);
73  }
74  // add entry to navigation history
75  if (!$this->getCreationMode() &&
76  $ilAccess->checkAccess("read", "", $_GET["ref_id"]))
77  {
78  $ilNavigationHistory->addItem($_GET["ref_id"],
79  "ilias.php?baseClass=ilObjSurveyQuestionPoolGUI&cmd=questions&ref_id=".$_GET["ref_id"], "spl");
80  }
81 
82  $this->tpl->addCss(ilUtil::getStyleSheetLocation("output", "survey.css", "Modules/Survey"), "screen");
83  $this->prepareOutput();
84  $cmd = $this->ctrl->getCmd("questions");
85  $next_class = $this->ctrl->getNextClass($this);
86  $this->ctrl->setReturn($this, "questions");
87  if ($_GET["q_id"] < 1)
88  {
89  $q_type = ($_POST["sel_question_types"] != "")
90  ? $_POST["sel_question_types"]
91  : $_GET["sel_question_types"];
92  }
93  switch($next_class)
94  {
95  case 'ilmdeditorgui':
96  include_once "./Services/MetaData/classes/class.ilMDEditorGUI.php";
97  $md_gui =& new ilMDEditorGUI($this->object->getId(), 0, $this->object->getType());
98  $md_gui->addObserver($this->object,'MDUpdateListener','General');
99 
100  $this->ctrl->forwardCommand($md_gui);
101  break;
102 
103  case 'ilpermissiongui':
104  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
105  $perm_gui =& new ilPermissionGUI($this);
106  $ret =& $this->ctrl->forwardCommand($perm_gui);
107  break;
108 
109  case "ilsurveyphrasesgui":
110  include_once("./Modules/SurveyQuestionPool/classes/class.ilSurveyPhrasesGUI.php");
111  $phrases_gui =& new ilSurveyPhrasesGUI($this);
112  $ret =& $this->ctrl->forwardCommand($phrases_gui);
113  break;
114 
115  case 'ilobjectcopygui':
116  include_once './Services/Object/classes/class.ilObjectCopyGUI.php';
117  $cp = new ilObjectCopyGUI($this);
118  $cp->setType('spl');
119  $this->ctrl->forwardCommand($cp);
120  break;
121 
122  case "":
123  $cmd.= "Object";
124  $ret =& $this->$cmd();
125  break;
126 
127  default:
128  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestionGUI.php";
129  $q_gui = SurveyQuestionGUI::_getQuestionGUI($q_type, $_GET["q_id"]);
130  $q_gui->object->setObjId($this->object->getId());
131  $q_gui->setQuestionTabs();
132  $ret =& $this->ctrl->forwardCommand($q_gui);
133  break;
134  }
135  if (strtolower($_GET["baseClass"]) != "iladministrationgui" &&
136  $this->getCreationMode() != true)
137  {
138  $this->tpl->show();
139  }
140  }
141 
145  public function cancelObject()
146  {
147  ilUtil::redirect("repository.php?cmd=frameset&ref_id=".$_GET["ref_id"]);
148  }
149 
150 
154  public function saveObject()
155  {
156  global $rbacadmin;
157 
158  if (!strlen($_POST['Fobject']['title']))
159  {
160  ilUtil::sendFailure($this->lng->txt('title_required'), true);
161  $this->ctrl->setParameter($this, 'new_type', $_GET['new_type']);
162  $this->ctrl->redirect($this, 'create');
163  }
164 
165  // create and insert forum in objecttree
166  $newObj = parent::saveObject();
167 
168  // always send a message
169  ilUtil::sendSuccess($this->lng->txt("object_added"),true);
170 
171  ilUtil::redirect("ilias.php?ref_id=".$newObj->getRefId().
172  "&baseClass=ilObjSurveyQuestionPoolGUI");
173  }
174 
178  public function propertiesObject()
179  {
180  $save = ((strcmp($this->ctrl->getCmd(), "save") == 0)) ? true : false;
181 
182  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
183  $form = new ilPropertyFormGUI();
184  $form->setFormAction($this->ctrl->getFormAction($this, 'properties'));
185  $form->setTitle($this->lng->txt("properties"));
186  $form->setMultipart(false);
187  $form->setId("properties");
188 
189  // online
190  $online = new ilCheckboxInputGUI($this->lng->txt("spl_online_property"), "online");
191  $online->setInfo($this->lng->txt("spl_online_property_description"));
192  $online->setChecked($this->object->getOnline());
193  $form->addItem($online);
194 
195  $form->addCommandButton("saveProperties", $this->lng->txt("save"));
196 
197  if ($save)
198  {
199  $form->checkInput();
200  }
201  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
202  }
203 
207  public function savePropertiesObject()
208  {
209  $qpl_online = $_POST["online"];
210  if (strlen($qpl_online) == 0) $qpl_online = "0";
211  $this->object->setOnline($qpl_online);
212  $this->object->saveToDb();
213  ilUtil::sendSuccess($this->lng->txt("saved_successfully"), true);
214  $this->ctrl->redirect($this, "properties");
215  }
216 
217 
221  public function copyObject()
222  {
223  if (count($_POST["q_id"]) > 0)
224  {
225  foreach ($_POST["q_id"] as $key => $value)
226  {
227  $this->object->copyToClipboard($value);
228  }
229  ilUtil::sendInfo($this->lng->txt("spl_copy_insert_clipboard"), true);
230  }
231  else
232  {
233  ilUtil::sendInfo($this->lng->txt("spl_copy_select_none"), true);
234  }
235  $this->ctrl->redirect($this, "questions");
236  }
237 
241  public function moveObject()
242  {
243  if (count($_POST["q_id"]) > 0)
244  {
245  foreach ($_POST["q_id"] as $key => $value)
246  {
247  $this->object->moveToClipboard($value);
248  }
249  ilUtil::sendInfo($this->lng->txt("spl_move_insert_clipboard"), true);
250  }
251  else
252  {
253  ilUtil::sendInfo($this->lng->txt("spl_move_select_none"), true);
254  }
255  $this->ctrl->redirect($this, "questions");
256  }
257 
261  public function exportQuestionObject()
262  {
263  if (is_array($_POST['q_id']) && count($_POST['q_id']) > 0)
264  {
265  $this->createExportFileObject($_POST['q_id']);
266  }
267  else
268  {
269  ilUtil::sendInfo($this->lng->txt("qpl_export_select_none"));
270  $this->questionsObject();
271  }
272  }
273 
277  public function deleteQuestionsObject()
278  {
279  global $rbacsystem;
280 
282  // create an array of all checked checkboxes
283  $checked_questions = $_POST['q_id'];
284  if (count($checked_questions) > 0)
285  {
286  if ($rbacsystem->checkAccess('write', $this->ref_id))
287  {
288  ilUtil::sendQuestion($this->lng->txt("qpl_confirm_delete_questions"));
289  }
290  else
291  {
292  ilUtil::sendFailure($this->lng->txt("qpl_delete_rbac_error"));
293  $this->questionsObject();
294  return;
295  }
296  }
297  elseif (count($checked_questions) == 0)
298  {
299  ilUtil::sendInfo($this->lng->txt("qpl_delete_select_none"));
300  $this->questionsObject();
301  return;
302  }
303  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_confirm_delete_questions.html", "Modules/SurveyQuestionPool");
304  $infos = $this->object->getQuestionInfos($checked_questions);
305  $colors = array("tblrow1", "tblrow2");
306  $counter = 0;
307  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
308  foreach ($infos as $data)
309  {
310  $this->tpl->setCurrentBlock("row");
311  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
312  $this->tpl->setVariable("TXT_TITLE", $data["title"]);
313  $this->tpl->setVariable("TXT_DESCRIPTION", $data["description"]);
314  $this->tpl->setVariable("TXT_TYPE", SurveyQuestion::_getQuestionTypeName($data["type_tag"]));
315  $this->tpl->parseCurrentBlock();
316  $counter++;
317  }
318  foreach ($checked_questions as $id)
319  {
320  $this->tpl->setCurrentBlock("hidden");
321  $this->tpl->setVariable("HIDDEN_NAME", "q_id[]");
322  $this->tpl->setVariable("HIDDEN_VALUE", $id);
323  $this->tpl->parseCurrentBlock();
324  }
325 
326  $this->tpl->setCurrentBlock("adm_content");
327  $this->tpl->setVariable("TXT_TITLE", $this->lng->txt("title"));
328  $this->tpl->setVariable("TXT_DESCRIPTION", $this->lng->txt("description"));
329  $this->tpl->setVariable("TXT_TYPE", $this->lng->txt("question_type"));
330  $this->tpl->setVariable("BTN_CONFIRM", $this->lng->txt("confirm"));
331  $this->tpl->setVariable("BTN_CANCEL", $this->lng->txt("cancel"));
332  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
333  $this->tpl->parseCurrentBlock();
334  }
335 
340  {
341  // delete questions after confirmation
342  ilUtil::sendSuccess($this->lng->txt("qpl_questions_deleted"), true);
343  foreach ($_POST['q_id'] as $q_id)
344  {
345  $this->object->removeQuestion($q_id);
346  }
347  $this->ctrl->redirect($this, "questions");
348  }
349 
353  public function cancelDeleteQuestionsObject()
354  {
355  // delete questions after confirmation
356  $this->ctrl->redirect($this, "questions");
357  }
358 
362  public function pasteObject()
363  {
364  if (array_key_exists("spl_clipboard", $_SESSION))
365  {
366  $this->object->pasteFromClipboard();
367  }
368  else
369  {
370  ilUtil::sendInfo($this->lng->txt("spl_paste_no_objects"), true);
371  }
372  $this->ctrl->redirect($this, "questions");
373  }
374 
378  public function importQuestionsObject()
379  {
380  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_import_question.html", "Modules/SurveyQuestionPool");
381  $this->tpl->setCurrentBlock("adm_content");
382  $this->tpl->setVariable("TEXT_IMPORT_QUESTION", $this->lng->txt("import_question"));
383  $this->tpl->setVariable("TEXT_SELECT_FILE", $this->lng->txt("select_file"));
384  $this->tpl->setVariable("TEXT_UPLOAD", $this->lng->txt("upload"));
385  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
386  $this->tpl->parseCurrentBlock();
387  }
388 
392  public function uploadQuestionsObject()
393  {
394  // check if file was uploaded
395  $source = $_FILES["qtidoc"]["tmp_name"];
396  $error = 0;
397  if (($source == 'none') || (!$source) || $_FILES["qtidoc"]["error"] > UPLOAD_ERR_OK)
398  {
399  $error = 1;
400  }
401  // check correct file type
402  if (strpos("xml", $_FILES["qtidoc"]["type"]) !== FALSE)
403  {
404  $error = 1;
405  }
406  if (!$error)
407  {
408  // import file into questionpool
409  // create import directory
410  $this->object->createImportDirectory();
411 
412  // copy uploaded file to import directory
413  $full_path = $this->object->getImportDirectory()."/".$_FILES["qtidoc"]["name"];
414 
415  include_once "./Services/Utilities/classes/class.ilUtil.php";
416  ilUtil::moveUploadedFile($_FILES["qtidoc"]["tmp_name"],
417  $_FILES["qtidoc"]["name"], $full_path);
418  $source = $full_path;
419  $this->object->importObject($source, TRUE);
420  unlink($source);
421  }
422  $this->ctrl->redirect($this, "questions");
423  }
424 
425  public function filterQuestionBrowserObject()
426  {
427  include_once "./Modules/SurveyQuestionPool/classes/tables/class.ilSurveyQuestionsTableGUI.php";
428  $table_gui = new ilSurveyQuestionsTableGUI($this, 'questions');
429  $table_gui->writeFilterToSession();
430  $this->ctrl->redirect($this, 'questions');
431  }
432 
434  {
435  include_once "./Modules/SurveyQuestionPool/classes/tables/class.ilSurveyQuestionsTableGUI.php";
436  $table_gui = new ilSurveyQuestionsTableGUI($this, 'questions');
437  $table_gui->resetFilter();
438  $this->ctrl->redirect($this, 'questions');
439  }
440 
444  public function questionsObject($arrFilter = null)
445  {
446  global $rbacsystem;
447  global $ilUser;
448 
449  $this->object->purgeQuestions();
450 
451  $_SESSION['q_id_table_nav'] = $_GET['q_id_table_nav'];
452  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_questionbrowser.html", "Modules/SurveyQuestionPool");
453  include_once "./Modules/SurveyQuestionPool/classes/tables/class.ilSurveyQuestionsTableGUI.php";
454  $table_gui = new ilSurveyQuestionsTableGUI($this, 'questions', (($rbacsystem->checkAccess('write', $_GET['ref_id']) ? true : false)));
455  $table_gui->setEditable($rbacsystem->checkAccess('write', $_GET['ref_id']));
456  $arrFilter = array();
457  foreach ($table_gui->getFilterItems() as $item)
458  {
459  if ($item->getValue() !== false)
460  {
461  $arrFilter[$item->getPostVar()] = $item->getValue();
462  }
463  }
464  $data = $this->object->getQuestionsData($arrFilter);
465  $table_gui->setData($data);
466  $this->tpl->setVariable('TABLE', $table_gui->getHTML());
467 
468  if ($rbacsystem->checkAccess('write', $_GET['ref_id']))
469  {
470  $this->tpl->setCurrentBlock("QTypes");
471  $types =& ilObjSurveyQuestionPool::_getQuestionTypes();
472  $lastquestiontype = $ilUser->getPref("svy_lastquestiontype");
473  foreach ($types as $translation => $data)
474  {
475  if ($data["type_tag"] == $lastquestiontype)
476  {
477  $this->tpl->setVariable("QUESTION_TYPE_SELECTED", " selected=\"selected\"");
478  }
479  $this->tpl->setVariable("QUESTION_TYPE_ID", $data["type_tag"]);
480  $this->tpl->setVariable("QUESTION_TYPE", $translation);
481  $this->tpl->parseCurrentBlock();
482  }
483  $this->tpl->setVariable("QUESTION_ADD", $this->lng->txt("create"));
484  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, 'questions'));
485  $this->tpl->parseCurrentBlock();
486  }
487  }
488 
489  public function updateObject()
490  {
491  $this->update = $this->object->update();
492  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
493  }
494 
495  /*
496  * list all export files
497  */
498  public function exportObject()
499  {
500  include_once "./Modules/SurveyQuestionPool/classes/tables/class.ilSurveyQuestionPoolExportTableGUI.php";
501  $table_gui = new ilSurveyQuestionPoolExportTableGUI($this, 'export');
502  $export_dir = $this->object->getExportDirectory();
503  $export_files = $this->object->getExportFiles($export_dir);
504  $data = array();
505  foreach ($export_files as $exp_file)
506  {
507  $file_arr = explode("__", $exp_file);
508  array_push($data, array('file' => $exp_file, 'date' => ilDatePresentation::formatDate(new ilDateTime($file_arr[0], IL_CAL_UNIX)), 'size' => filesize($export_dir."/".$exp_file)));
509  }
510  $table_gui->setData($data);
511  $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
512  }
513 
517  public function createExportFileObject($questions = null)
518  {
519  global $rbacsystem;
520 
521  if ($rbacsystem->checkAccess("write", $this->ref_id))
522  {
523  include_once("./Modules/SurveyQuestionPool/classes/class.ilSurveyQuestionpoolExport.php");
524  $survey_exp = new ilSurveyQuestionpoolExport($this->object);
525  $survey_exp->buildExportFile($questions);
526  $this->ctrl->redirect($this, "export");
527  }
528  else
529  {
530  ilUtil::sendInfo("cannot_export_questionpool");
531  }
532  }
533 
537  public function downloadExportFileObject()
538  {
539  if(!isset($_POST["file"]))
540  {
541  ilUtil::sendInfo($this->lng->txt("no_checkbox"), true);
542  $this->ctrl->redirect($this, "export");
543  }
544 
545  if (count($_POST["file"]) > 1)
546  {
547  ilUtil::sendInfo($this->lng->txt("select_max_one_item"),true);
548  $this->ctrl->redirect($this, "export");
549  }
550 
551 
552  $export_dir = $this->object->getExportDirectory();
553  include_once "./Services/Utilities/classes/class.ilUtil.php";
554  ilUtil::deliverFile($export_dir."/".$_POST["file"][0],
555  $_POST["file"][0]);
556  }
557 
562  {
563  if(!isset($_POST["file"]))
564  {
565  ilUtil::sendInfo($this->lng->txt("no_checkbox"),true);
566  $this->ctrl->redirect($this, "export");
567  }
568 
569  ilUtil::sendQuestion($this->lng->txt("info_delete_sure"));
570  include_once "./Modules/SurveyQuestionPool/classes/tables/class.ilSurveyQuestionPoolExportTableGUI.php";
571  $table_gui = new ilSurveyQuestionPoolExportTableGUI($this, 'export', true);
572  $export_dir = $this->object->getExportDirectory();
573  $data = array();
574  foreach ($_POST['file'] as $exp_file)
575  {
576  $file_arr = explode("__", $exp_file);
577  array_push($data, array('file' => $exp_file, 'date' => ilDatePresentation::formatDate(new ilDateTime($file_arr[0], IL_CAL_UNIX)), 'size' => filesize($export_dir."/".$exp_file)));
578  }
579  $table_gui->setData($data);
580  $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
581  }
582 
583 
588  {
589  session_unregister("ilExportFiles");
590  $this->ctrl->redirect($this, "export");
591  }
592 
596  public function deleteExportFileObject()
597  {
598  $export_dir = $this->object->getExportDirectory();
599  foreach($_POST['file'] as $file)
600  {
601  $exp_file = $export_dir."/".$file;
602  $exp_dir = $export_dir."/".substr($file, 0, strlen($file) - 4);
603  if (@is_file($exp_file))
604  {
605  unlink($exp_file);
606  }
607  if (@is_dir($exp_dir))
608  {
609  include_once "./Services/Utilities/classes/class.ilUtil.php";
610  ilUtil::delDir($exp_dir);
611  }
612  }
613  $this->ctrl->redirect($this, "export");
614  }
615 
621  public function importObject()
622  {
623  global $rbacsystem;
624  if (!$rbacsystem->checkAccess("create", $_GET["ref_id"]))
625  {
626  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
627  }
628  $this->getTemplateFile("import", "spl");
629  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
630  $this->tpl->setVariable("BTN_NAME", "uploadSpl");
631  $this->tpl->setVariable("TXT_UPLOAD", $this->lng->txt("upload"));
632  $this->tpl->setVariable("TXT_IMPORT_SPL", $this->lng->txt("import_spl"));
633  $this->tpl->setVariable("TXT_SELECT_MODE", $this->lng->txt("select_mode"));
634  $this->tpl->setVariable("TXT_SELECT_FILE", $this->lng->txt("select_file"));
635  }
636 
640  public function uploadSplObject($redirect = true)
641  {
642  if ($_FILES["xmldoc"]["error"] > UPLOAD_ERR_OK)
643  {
644  ilUtil::sendInfo($this->lng->txt("spl_select_file_for_import"));
645  $this->importObject();
646  return;
647  }
648  include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
649  // create new questionpool object
650  $newObj = new ilObjSurveyQuestionPool();
651  // set type of questionpool object
652  $newObj->setType($_GET["new_type"]);
653  // set title of questionpool object to "dummy"
654  $newObj->setTitle("dummy");
655  // create the questionpool class in the ILIAS database (object_data table)
656  $newObj->create(true);
657  // create a reference for the questionpool object in the ILIAS database (object_reference table)
658  $newObj->createReference();
659  // put the questionpool object in the administration tree
660  $newObj->putInTree($_GET["ref_id"]);
661  // get default permissions and set the permissions for the questionpool object
662  $newObj->setPermissions($_GET["ref_id"]);
663  // notify the questionpool object and all its parent objects that a "new" object was created
664  $newObj->notify("new",$_GET["ref_id"],$_GET["parent_non_rbac_id"],$_GET["ref_id"],$newObj->getRefId());
665 
666  // create import directory
667  $newObj->createImportDirectory();
668 
669  // copy uploaded file to import directory
670  $file = pathinfo($_FILES["xmldoc"]["name"]);
671  $full_path = $newObj->getImportDirectory()."/".$_FILES["xmldoc"]["name"];
672  include_once "./Services/Utilities/classes/class.ilUtil.php";
673  ilUtil::moveUploadedFile($_FILES["xmldoc"]["tmp_name"],
674  $_FILES["xmldoc"]["name"], $full_path);
675 
676  // import qti data
677  $qtiresult = $newObj->importObject($full_path);
678 
679  if ($redirect)
680  {
681  $this->ctrl->redirect($this, "cancel");
682  }
683  return $newObj->getRefId();
684  }
685 
689  public function createObject()
690  {
691  global $rbacsystem;
692  $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
693  if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], $new_type))
694  {
695  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
696  }
697  else
698  {
699  $this->getTemplateFile("create", $new_type);
700 
701  include_once("./Modules/Survey/classes/class.ilObjSurvey.php");
702  $this->fillCloneTemplate('DUPLICATE','spl');
703  $this->tpl->setCurrentBlock("adm_content");
704 
705  // fill in saved values in case of error
706  $data = array();
707  $data["fields"] = array();
708  include_once "./Services/Utilities/classes/class.ilUtil.php";
709  $data["fields"]["title"] = ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["title"],true);
710  $data["fields"]["desc"] = ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["desc"]);
711 
712  foreach ($data["fields"] as $key => $val)
713  {
714  $this->tpl->setVariable("TXT_".strtoupper($key), $this->lng->txt($key));
715  $this->tpl->setVariable(strtoupper($key), $val);
716 
717  if ($this->prepare_output)
718  {
719  $this->tpl->parseCurrentBlock();
720  }
721  }
722 
723  $this->ctrl->setParameter($this, "new_type", $this->type);
724  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
725  $this->tpl->setVariable("TXT_HEADER", $this->lng->txt($new_type."_new"));
726  $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
727  $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt($new_type."_add"));
728  $this->tpl->setVariable("CMD_SUBMIT", "save");
729  $this->tpl->setVariable("TARGET", ' target="'.
730  ilFrameTargetInfo::_getFrame("MainContent").'" ');
731  $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
732 
733  $this->tpl->setVariable("TXT_IMPORT_SPL", $this->lng->txt("import_spl"));
734  $this->tpl->setVariable("TXT_SPL_FILE", $this->lng->txt("spl_upload_file"));
735  $this->tpl->setVariable("NEW_TYPE", $this->type);
736  $this->tpl->setVariable("TXT_IMPORT", $this->lng->txt("import"));
737 
738  $this->tpl->setVariable("TYPE_IMG", ilUtil::getImagePath('icon_spl.gif'));
739  $this->tpl->setVariable("ALT_IMG",$this->lng->txt("obj_spl"));
740  $this->tpl->setVariable("TYPE_IMG2", ilUtil::getImagePath('icon_spl.gif'));
741  $this->tpl->setVariable("ALT_IMG2",$this->lng->txt("obj_spl"));
742 
743  $this->tpl->parseCurrentBlock();
744  }
745  }
746 
750  public function importFileObject()
751  {
752  if (strcmp($_FILES["xmldoc"]["tmp_name"], "") == 0)
753  {
754  ilUtil::sendInfo($this->lng->txt("spl_select_file_for_import"));
755  $this->createObject();
756  return;
757  }
758  $this->ctrl->setParameter($this, "new_type", $this->type);
759  $ref_id = $this->uploadSplObject(false);
760  // always send a message
761  ilUtil::sendSuccess($this->lng->txt("object_imported"),true);
762 
763  ilUtil::redirect("ilias.php?ref_id=".$ref_id.
764  "&baseClass=ilObjSurveyQuestionPoolGUI");
765  }
766 
770  public function &createQuestionObject()
771  {
772  global $ilUser;
773  $ilUser->writePref("svy_lastquestiontype", $_POST["sel_question_types"]);
774  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestionGUI.php";
775  $q_gui =& SurveyQuestionGUI::_getQuestionGUI($_POST["sel_question_types"]);
776  $q_gui->object->setObjId($this->object->getId());
777  $q_gui->object->createNewQuestion();
778  $this->ctrl->setParameterByClass(get_class($q_gui), "q_id", $q_gui->object->getId());
779  $this->ctrl->setParameterByClass(get_class($q_gui), "sel_question_types", $_POST["sel_question_types"]);
780  $this->ctrl->redirectByClass(get_class($q_gui), "editQuestion");
781  }
782 
786  public function &editQuestionForSurveyObject()
787  {
788  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestionGUI.php";
789  $q_gui =& SurveyQuestionGUI::_getQuestionGUI("", $_GET["q_id"]);
790  $this->ctrl->setParameterByClass(get_class($q_gui), "sel_question_types", $q_gui->getQuestionType());
791  $this->ctrl->setParameterByClass(get_class($q_gui), "q_id", $_GET["q_id"]);
792  $this->ctrl->redirectByClass(get_class($q_gui), "editQuestion");
793  }
794 
798  public function &createQuestionForSurveyObject()
799  {
800  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestionGUI.php";
801  $q_gui =& SurveyQuestionGUI::_getQuestionGUI($_GET["sel_question_types"]);
802  $q_gui->object->createNewQuestion();
803  $this->ctrl->setParameterByClass(get_class($q_gui), "q_id", $q_gui->object->getId());
804  $this->ctrl->setParameterByClass(get_class($q_gui), "sel_question_types", $q_gui->getQuestionType());
805  $this->ctrl->redirectByClass(get_class($q_gui), "editQuestion");
806  }
807 
811  public function &previewObject()
812  {
813  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestionGUI.php";
814  $q_gui =& SurveyQuestionGUI::_getQuestionGUI("", $_GET["preview"]);
815  $this->ctrl->setParameterByClass(get_class($q_gui), "sel_question_types", $q_gui->getQuestionType());
816  $this->ctrl->setParameterByClass(get_class($q_gui), "q_id", $_GET["preview"]);
817  $this->ctrl->redirectByClass(get_class($q_gui), "preview");
818  }
819 
820  public function addLocatorItems()
821  {
822  global $ilLocator;
823  switch ($this->ctrl->getCmd())
824  {
825  case "create":
826  case "importFile":
827  case "cancel":
828  break;
829  default:
830  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, ""), "", $_GET["ref_id"]);
831  break;
832  }
833  if ($_GET["q_id"] > 0)
834  {
835  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
836  $q_type = SurveyQuestion::_getQuestionType($_GET["q_id"]) . "GUI";
837  $this->ctrl->setParameterByClass($q_type, "q_id", $_GET["q_id"]);
838  $ilLocator->addItem(SurveyQuestion::_getTitle($_GET["q_id"]), $this->ctrl->getLinkTargetByClass($q_type, "editQuestion"));
839  }
840  }
841 
847  public function getTabs(&$tabs_gui)
848  {
849  global $ilAccess;
850 
851  $next_class = $this->ctrl->getNextClass($this);
852  switch ($next_class)
853  {
854  case "":
855  case "ilpermissiongui":
856  case "ilmdeditorgui":
857  case "ilsurveyphrasesgui":
858  break;
859  default:
860  return;
861  break;
862  }
863  if (($_GET["calling_survey"] > 0) || ($_GET["new_for_survey"] > 0)) return;
864  // questions
865  $force_active = ($this->ctrl->getCmdClass() == "" ||
866  $this->ctrl->getCmd() == "")
867  ? true
868  : false;
869  if (!$force_active)
870  {
871  if (is_array($_GET["sort"]))
872  {
873  $force_active = true;
874  }
875  }
876  $tabs_gui->addTarget("survey_questions",
877  $this->ctrl->getLinkTarget($this,'questions'),
878  array("questions", "filterQuestionBrowser", "filter", "reset", "createQuestion",
879  "importQuestions", "deleteQuestions", "copy", "paste",
880  "exportQuestions", "confirmDeleteQuestions", "cancelDeleteQuestions",
881  "confirmPasteQuestions", "cancelPasteQuestions", "uploadQuestions",
882  "editQuestion", "addMaterial", "removeMaterial", "save", "cancel",
883  "cancelExplorer", "linkChilds", "addGIT", "addST", "addPG", "preview",
884  "moveCategory", "deleteCategory", "addPhrase", "addCategory", "savePhrase",
885  "addSelectedPhrase", "cancelViewPhrase", "confirmSavePhrase", "cancelSavePhrase",
886  "insertBeforeCategory", "insertAfterCategory", "confirmDeleteCategory",
887  "cancelDeleteCategory", "categories", "saveCategories",
888  "savePhrase", "addPhrase"
889  ),
890  array("ilobjsurveyquestionpoolgui", "ilsurveyphrasesgui"), "", $force_active);
891 
892  if ($ilAccess->checkAccess('write', '', $this->ref_id))
893  {
894  // properties
895  $tabs_gui->addTarget("settings",
896  $this->ctrl->getLinkTarget($this,'properties'),
897  "properties",
898  "", "");
899 
900  // manage phrases
901  $tabs_gui->addTarget("manage_phrases",
902  $this->ctrl->getLinkTargetByClass("ilsurveyphrasesgui", "phrases"),
903  array("phrases", "deletePhrase", "confirmDeletePhrase", "cancelDeletePhrase", "editPhrase", "newPhrase", "saveEditPhrase", "phraseEditor"),
904  "ilsurveyphrasesgui", "");
905 
906  // meta data
907  $tabs_gui->addTarget("meta_data",
908  $this->ctrl->getLinkTargetByClass('ilmdeditorgui','listSection'),
909  "", "ilmdeditorgui");
910 
911  // export
912  $tabs_gui->addTarget("export",
913  $this->ctrl->getLinkTarget($this,'export'),
914  array("export", "createExportFile", "confirmDeleteExportFile",
915  "downloadExportFile", "cancelDeleteExportFile", "deleteExportFile"),
916  "", "");
917  }
918 
919  if ($ilAccess->checkAccess("edit_permission", "", $this->ref_id))
920  {
921  $tabs_gui->addTarget("perm_settings",
922  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), array("perm","info","owner"), 'ilpermissiongui');
923  }
924  }
925 
932  public static function _goto($a_target)
933  {
934  global $ilAccess, $ilErr, $lng;
935  if ($ilAccess->checkAccess("write", "", $a_target))
936  {
937  $_GET["baseClass"] = "ilObjSurveyQuestionPoolGUI";
938  $_GET["cmd"] = "questions";
939  $_GET["ref_id"] = $a_target;
940  include_once("ilias.php");
941  exit;
942  }
943  else if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
944  {
945  $_GET["cmd"] = "frameset";
946  $_GET["target"] = "";
947  $_GET["ref_id"] = ROOT_FOLDER_ID;
948  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
950  include("repository.php");
951  exit;
952  }
953  $ilErr->raiseError($lng->txt("msg_no_perm_read_lm"), $ilErr->FATAL);
954  }
955 } // END class.ilObjSurveyQuestionPoolGUI
956 ?>