ILIAS  Release_4_0_x_branch Revision 61816
 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  $qplSetting = new ilSetting("spl");
196  $tablecols = new ilCustomInputGUI($this->lng->txt('spl_browsercolumns'), 'browsercolumn');
197  $tablecols->setInfo($this->lng->txt("spl_browsercolumns_description"));
198  $description = new ilCheckboxInputGUI($this->lng->txt("description"), "description");
199  $description->setChecked($qplSetting->get("description", 1) ? true : false);
200  $type = new ilCheckboxInputGUI($this->lng->txt("question_type"), "type");
201  $type->setChecked($qplSetting->get("type", 1) ? true : false);
202  $author = new ilCheckboxInputGUI($this->lng->txt("author"), "author");
203  $author->setChecked($qplSetting->get("author", 1) ? true : false);
204  $created = new ilCheckboxInputGUI($this->lng->txt("create_date"), "created");
205  $created->setChecked($qplSetting->get("created", 1) ? true : false);
206  $updated = new ilCheckboxInputGUI($this->lng->txt("last_update"), "updated");
207  $updated->setChecked($qplSetting->get("updated", 1) ? true : false);
208  $tablecols->addSubitem($description);
209  $tablecols->addSubitem($type);
210  $tablecols->addSubitem($author);
211  $tablecols->addSubitem($created);
212  $tablecols->addSubitem($updated);
213  $form->addItem($tablecols);
214 
215  $form->addCommandButton("saveProperties", $this->lng->txt("save"));
216 
217  if ($save)
218  {
219  $form->checkInput();
220  }
221  $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
222  }
223 
227  public function savePropertiesObject()
228  {
229  $qpl_online = $_POST["online"];
230  if (strlen($qpl_online) == 0) $qpl_online = "0";
231  $this->object->setOnline($qpl_online);
232  $this->object->saveToDb();
233 
234  $qplSetting = new ilSetting("spl");
235  $qplSetting->set('description', ($_POST["description"]) ? 1 : 0);
236  $qplSetting->set('type', ($_POST["type"]) ? 1 : 0);
237  $qplSetting->set('author', ($_POST["author"]) ? 1 : 0);
238  $qplSetting->set('created', ($_POST["created"]) ? 1 : 0);
239  $qplSetting->set('updated', ($_POST["updated"]) ? 1 : 0);
240  ilUtil::sendSuccess($this->lng->txt("saved_successfully"), true);
241  $this->ctrl->redirect($this, "properties");
242  }
243 
244 
248  public function copyObject()
249  {
250  if (count($_POST["q_id"]) > 0)
251  {
252  foreach ($_POST["q_id"] as $key => $value)
253  {
254  $this->object->copyToClipboard($value);
255  }
256  ilUtil::sendInfo($this->lng->txt("spl_copy_insert_clipboard"), true);
257  }
258  else
259  {
260  ilUtil::sendInfo($this->lng->txt("spl_copy_select_none"), true);
261  }
262  $this->ctrl->redirect($this, "questions");
263  }
264 
268  public function moveObject()
269  {
270  if (count($_POST["q_id"]) > 0)
271  {
272  foreach ($_POST["q_id"] as $key => $value)
273  {
274  $this->object->moveToClipboard($value);
275  }
276  ilUtil::sendInfo($this->lng->txt("spl_move_insert_clipboard"), true);
277  }
278  else
279  {
280  ilUtil::sendInfo($this->lng->txt("spl_move_select_none"), true);
281  }
282  $this->ctrl->redirect($this, "questions");
283  }
284 
288  public function exportQuestionObject()
289  {
290  if (is_array($_POST['q_id']) && count($_POST['q_id']) > 0)
291  {
292  $this->createExportFileObject($_POST['q_id']);
293  }
294  else
295  {
296  ilUtil::sendInfo($this->lng->txt("qpl_export_select_none"));
297  $this->questionsObject();
298  }
299  }
300 
304  public function deleteQuestionsObject()
305  {
306  global $rbacsystem;
307 
309  // create an array of all checked checkboxes
310  $checked_questions = $_POST['q_id'];
311  if (count($checked_questions) > 0)
312  {
313  if ($rbacsystem->checkAccess('write', $this->ref_id))
314  {
315  ilUtil::sendQuestion($this->lng->txt("qpl_confirm_delete_questions"));
316  }
317  else
318  {
319  ilUtil::sendFailure($this->lng->txt("qpl_delete_rbac_error"));
320  $this->questionsObject();
321  return;
322  }
323  }
324  elseif (count($checked_questions) == 0)
325  {
326  ilUtil::sendInfo($this->lng->txt("qpl_delete_select_none"));
327  $this->questionsObject();
328  return;
329  }
330  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_confirm_delete_questions.html", "Modules/SurveyQuestionPool");
331  $infos = $this->object->getQuestionInfos($checked_questions);
332  $colors = array("tblrow1", "tblrow2");
333  $counter = 0;
334  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
335  foreach ($infos as $data)
336  {
337  $this->tpl->setCurrentBlock("row");
338  $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
339  $this->tpl->setVariable("TXT_TITLE", $data["title"]);
340  $this->tpl->setVariable("TXT_DESCRIPTION", $data["description"]);
341  $this->tpl->setVariable("TXT_TYPE", SurveyQuestion::_getQuestionTypeName($data["type_tag"]));
342  $this->tpl->parseCurrentBlock();
343  $counter++;
344  }
345  foreach ($checked_questions as $id)
346  {
347  $this->tpl->setCurrentBlock("hidden");
348  $this->tpl->setVariable("HIDDEN_NAME", "q_id[]");
349  $this->tpl->setVariable("HIDDEN_VALUE", $id);
350  $this->tpl->parseCurrentBlock();
351  }
352 
353  $this->tpl->setCurrentBlock("adm_content");
354  $this->tpl->setVariable("TXT_TITLE", $this->lng->txt("title"));
355  $this->tpl->setVariable("TXT_DESCRIPTION", $this->lng->txt("description"));
356  $this->tpl->setVariable("TXT_TYPE", $this->lng->txt("question_type"));
357  $this->tpl->setVariable("BTN_CONFIRM", $this->lng->txt("confirm"));
358  $this->tpl->setVariable("BTN_CANCEL", $this->lng->txt("cancel"));
359  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
360  $this->tpl->parseCurrentBlock();
361  }
362 
367  {
368  // delete questions after confirmation
369  ilUtil::sendSuccess($this->lng->txt("qpl_questions_deleted"), true);
370  foreach ($_POST['q_id'] as $q_id)
371  {
372  $this->object->removeQuestion($q_id);
373  }
374  $this->ctrl->redirect($this, "questions");
375  }
376 
380  public function cancelDeleteQuestionsObject()
381  {
382  // delete questions after confirmation
383  $this->ctrl->redirect($this, "questions");
384  }
385 
389  public function pasteObject()
390  {
391  if (array_key_exists("spl_clipboard", $_SESSION))
392  {
393  $this->object->pasteFromClipboard();
394  }
395  else
396  {
397  ilUtil::sendInfo($this->lng->txt("spl_paste_no_objects"), true);
398  }
399  $this->ctrl->redirect($this, "questions");
400  }
401 
405  public function importQuestionsObject()
406  {
407  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_import_question.html", "Modules/SurveyQuestionPool");
408  $this->tpl->setCurrentBlock("adm_content");
409  $this->tpl->setVariable("TEXT_IMPORT_QUESTION", $this->lng->txt("import_question"));
410  $this->tpl->setVariable("TEXT_SELECT_FILE", $this->lng->txt("select_file"));
411  $this->tpl->setVariable("TEXT_UPLOAD", $this->lng->txt("upload"));
412  $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
413  $this->tpl->parseCurrentBlock();
414  }
415 
419  public function uploadQuestionsObject()
420  {
421  // check if file was uploaded
422  $source = $_FILES["qtidoc"]["tmp_name"];
423  $error = 0;
424  if (($source == 'none') || (!$source) || $_FILES["qtidoc"]["error"] > UPLOAD_ERR_OK)
425  {
426  $error = 1;
427  }
428  // check correct file type
429  if (strpos("xml", $_FILES["qtidoc"]["type"]) !== FALSE)
430  {
431  $error = 1;
432  }
433  if (!$error)
434  {
435  // import file into questionpool
436  // create import directory
437  $this->object->createImportDirectory();
438 
439  // copy uploaded file to import directory
440  $full_path = $this->object->getImportDirectory()."/".$_FILES["qtidoc"]["name"];
441 
442  include_once "./Services/Utilities/classes/class.ilUtil.php";
443  ilUtil::moveUploadedFile($_FILES["qtidoc"]["tmp_name"],
444  $_FILES["qtidoc"]["name"], $full_path);
445  $source = $full_path;
446  $this->object->importObject($source, TRUE);
447  unlink($source);
448  }
449  $this->ctrl->redirect($this, "questions");
450  }
451 
452  public function filterQuestionBrowserObject()
453  {
454  include_once "./Modules/SurveyQuestionPool/classes/tables/class.ilSurveyQuestionsTableGUI.php";
455  $table_gui = new ilSurveyQuestionsTableGUI($this, 'questions');
456  $table_gui->writeFilterToSession();
457  $this->ctrl->redirect($this, 'questions');
458  }
459 
461  {
462  include_once "./Modules/SurveyQuestionPool/classes/tables/class.ilSurveyQuestionsTableGUI.php";
463  $table_gui = new ilSurveyQuestionsTableGUI($this, 'questions');
464  $table_gui->resetFilter();
465  $this->ctrl->redirect($this, 'questions');
466  }
467 
471  public function questionsObject($arrFilter = null)
472  {
473  global $rbacsystem;
474  global $ilUser;
475 
476  $this->object->purgeQuestions();
477 
478  $_SESSION['q_id_table_nav'] = $_GET['q_id_table_nav'];
479  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_questionbrowser.html", "Modules/SurveyQuestionPool");
480  include_once "./Modules/SurveyQuestionPool/classes/tables/class.ilSurveyQuestionsTableGUI.php";
481  $table_gui = new ilSurveyQuestionsTableGUI($this, 'questions', (($rbacsystem->checkAccess('write', $_GET['ref_id']) ? true : false)));
482  $table_gui->setEditable($rbacsystem->checkAccess('write', $_GET['ref_id']));
483  $arrFilter = array();
484  foreach ($table_gui->getFilterItems() as $item)
485  {
486  if ($item->getValue() !== false)
487  {
488  $arrFilter[$item->getPostVar()] = $item->getValue();
489  }
490  }
491  $data = $this->object->getQuestionsData($arrFilter);
492  $table_gui->setData($data);
493  $this->tpl->setVariable('TABLE', $table_gui->getHTML());
494 
495  if ($rbacsystem->checkAccess('write', $_GET['ref_id']))
496  {
497  $this->tpl->setCurrentBlock("QTypes");
498  $types =& ilObjSurveyQuestionPool::_getQuestionTypes();
499  $lastquestiontype = $ilUser->getPref("svy_lastquestiontype");
500  foreach ($types as $translation => $data)
501  {
502  if ($data["type_tag"] == $lastquestiontype)
503  {
504  $this->tpl->setVariable("QUESTION_TYPE_SELECTED", " selected=\"selected\"");
505  }
506  $this->tpl->setVariable("QUESTION_TYPE_ID", $data["type_tag"]);
507  $this->tpl->setVariable("QUESTION_TYPE", $translation);
508  $this->tpl->parseCurrentBlock();
509  }
510  $this->tpl->setVariable("QUESTION_ADD", $this->lng->txt("create"));
511  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this, 'questions'));
512  $this->tpl->parseCurrentBlock();
513  }
514  }
515 
516  public function updateObject()
517  {
518  $this->update = $this->object->update();
519  ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
520  }
521 
522  /*
523  * list all export files
524  */
525  public function exportObject()
526  {
527  include_once "./Modules/SurveyQuestionPool/classes/tables/class.ilSurveyQuestionPoolExportTableGUI.php";
528  $table_gui = new ilSurveyQuestionPoolExportTableGUI($this, 'export');
529  $export_dir = $this->object->getExportDirectory();
530  $export_files = $this->object->getExportFiles($export_dir);
531  $data = array();
532  foreach ($export_files as $exp_file)
533  {
534  $file_arr = explode("__", $exp_file);
535  array_push($data, array('file' => $exp_file, 'date' => ilDatePresentation::formatDate(new ilDateTime($file_arr[0], IL_CAL_UNIX)), 'size' => filesize($export_dir."/".$exp_file)));
536  }
537  $table_gui->setData($data);
538  $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
539  }
540 
544  public function createExportFileObject($questions = null)
545  {
546  global $rbacsystem;
547 
548  if ($rbacsystem->checkAccess("write", $this->ref_id))
549  {
550  include_once("./Modules/SurveyQuestionPool/classes/class.ilSurveyQuestionpoolExport.php");
551  $survey_exp = new ilSurveyQuestionpoolExport($this->object);
552  $survey_exp->buildExportFile($questions);
553  $this->ctrl->redirect($this, "export");
554  }
555  else
556  {
557  ilUtil::sendInfo("cannot_export_questionpool");
558  }
559  }
560 
564  public function downloadExportFileObject()
565  {
566  if(!isset($_POST["file"]))
567  {
568  ilUtil::sendInfo($this->lng->txt("no_checkbox"), true);
569  $this->ctrl->redirect($this, "export");
570  }
571 
572  if (count($_POST["file"]) > 1)
573  {
574  ilUtil::sendInfo($this->lng->txt("select_max_one_item"),true);
575  $this->ctrl->redirect($this, "export");
576  }
577 
578 
579  $export_dir = $this->object->getExportDirectory();
580  include_once "./Services/Utilities/classes/class.ilUtil.php";
581  ilUtil::deliverFile($export_dir."/".$_POST["file"][0],
582  $_POST["file"][0]);
583  }
584 
589  {
590  if(!isset($_POST["file"]))
591  {
592  ilUtil::sendInfo($this->lng->txt("no_checkbox"),true);
593  $this->ctrl->redirect($this, "export");
594  }
595 
596  ilUtil::sendQuestion($this->lng->txt("info_delete_sure"));
597  include_once "./Modules/SurveyQuestionPool/classes/tables/class.ilSurveyQuestionPoolExportTableGUI.php";
598  $table_gui = new ilSurveyQuestionPoolExportTableGUI($this, 'export', true);
599  $export_dir = $this->object->getExportDirectory();
600  $data = array();
601  foreach ($_POST['file'] as $exp_file)
602  {
603  $file_arr = explode("__", $exp_file);
604  array_push($data, array('file' => $exp_file, 'date' => ilDatePresentation::formatDate(new ilDateTime($file_arr[0], IL_CAL_UNIX)), 'size' => filesize($export_dir."/".$exp_file)));
605  }
606  $table_gui->setData($data);
607  $this->tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
608  }
609 
610 
615  {
616  session_unregister("ilExportFiles");
617  $this->ctrl->redirect($this, "export");
618  }
619 
623  public function deleteExportFileObject()
624  {
625  $export_dir = $this->object->getExportDirectory();
626  foreach($_POST['file'] as $file)
627  {
628  $exp_file = $export_dir."/".$file;
629  $exp_dir = $export_dir."/".substr($file, 0, strlen($file) - 4);
630  if (@is_file($exp_file))
631  {
632  unlink($exp_file);
633  }
634  if (@is_dir($exp_dir))
635  {
636  include_once "./Services/Utilities/classes/class.ilUtil.php";
637  ilUtil::delDir($exp_dir);
638  }
639  }
640  $this->ctrl->redirect($this, "export");
641  }
642 
648  public function importObject()
649  {
650  global $rbacsystem;
651  if (!$rbacsystem->checkAccess("create", $_GET["ref_id"]))
652  {
653  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
654  }
655  $this->getTemplateFile("import", "spl");
656  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
657  $this->tpl->setVariable("BTN_NAME", "uploadSpl");
658  $this->tpl->setVariable("TXT_UPLOAD", $this->lng->txt("upload"));
659  $this->tpl->setVariable("TXT_IMPORT_SPL", $this->lng->txt("import_spl"));
660  $this->tpl->setVariable("TXT_SELECT_MODE", $this->lng->txt("select_mode"));
661  $this->tpl->setVariable("TXT_SELECT_FILE", $this->lng->txt("select_file"));
662  }
663 
667  public function uploadSplObject($redirect = true)
668  {
669  if ($_FILES["xmldoc"]["error"] > UPLOAD_ERR_OK)
670  {
671  ilUtil::sendInfo($this->lng->txt("spl_select_file_for_import"));
672  $this->importObject();
673  return;
674  }
675  include_once "./Modules/SurveyQuestionPool/classes/class.ilObjSurveyQuestionPool.php";
676  // create new questionpool object
677  $newObj = new ilObjSurveyQuestionPool();
678  // set type of questionpool object
679  $newObj->setType($_GET["new_type"]);
680  // set title of questionpool object to "dummy"
681  $newObj->setTitle("dummy");
682  // create the questionpool class in the ILIAS database (object_data table)
683  $newObj->create(true);
684  // create a reference for the questionpool object in the ILIAS database (object_reference table)
685  $newObj->createReference();
686  // put the questionpool object in the administration tree
687  $newObj->putInTree($_GET["ref_id"]);
688  // get default permissions and set the permissions for the questionpool object
689  $newObj->setPermissions($_GET["ref_id"]);
690  // notify the questionpool object and all its parent objects that a "new" object was created
691  $newObj->notify("new",$_GET["ref_id"],$_GET["parent_non_rbac_id"],$_GET["ref_id"],$newObj->getRefId());
692 
693  // create import directory
694  $newObj->createImportDirectory();
695 
696  // copy uploaded file to import directory
697  $file = pathinfo($_FILES["xmldoc"]["name"]);
698  $full_path = $newObj->getImportDirectory()."/".$_FILES["xmldoc"]["name"];
699  include_once "./Services/Utilities/classes/class.ilUtil.php";
700  ilUtil::moveUploadedFile($_FILES["xmldoc"]["tmp_name"],
701  $_FILES["xmldoc"]["name"], $full_path);
702 
703  // import qti data
704  $qtiresult = $newObj->importObject($full_path);
705 
706  if ($redirect)
707  {
708  $this->ctrl->redirect($this, "cancel");
709  }
710  return $newObj->getRefId();
711  }
712 
716  public function createObject()
717  {
718  global $rbacsystem;
719  $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
720  if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], $new_type))
721  {
722  $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
723  }
724  else
725  {
726  $this->getTemplateFile("create", $new_type);
727 
728  include_once("./Modules/Survey/classes/class.ilObjSurvey.php");
729  $this->fillCloneTemplate('DUPLICATE','spl');
730  $this->tpl->setCurrentBlock("adm_content");
731 
732  // fill in saved values in case of error
733  $data = array();
734  $data["fields"] = array();
735  include_once "./Services/Utilities/classes/class.ilUtil.php";
736  $data["fields"]["title"] = ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["title"],true);
737  $data["fields"]["desc"] = ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["desc"]);
738 
739  foreach ($data["fields"] as $key => $val)
740  {
741  $this->tpl->setVariable("TXT_".strtoupper($key), $this->lng->txt($key));
742  $this->tpl->setVariable(strtoupper($key), $val);
743 
744  if ($this->prepare_output)
745  {
746  $this->tpl->parseCurrentBlock();
747  }
748  }
749 
750  $this->ctrl->setParameter($this, "new_type", $this->type);
751  $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
752  $this->tpl->setVariable("TXT_HEADER", $this->lng->txt($new_type."_new"));
753  $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
754  $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt($new_type."_add"));
755  $this->tpl->setVariable("CMD_SUBMIT", "save");
756  $this->tpl->setVariable("TARGET", ' target="'.
757  ilFrameTargetInfo::_getFrame("MainContent").'" ');
758  $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
759 
760  $this->tpl->setVariable("TXT_IMPORT_SPL", $this->lng->txt("import_spl"));
761  $this->tpl->setVariable("TXT_SPL_FILE", $this->lng->txt("spl_upload_file"));
762  $this->tpl->setVariable("NEW_TYPE", $this->type);
763  $this->tpl->setVariable("TXT_IMPORT", $this->lng->txt("import"));
764 
765  $this->tpl->setVariable("TYPE_IMG", ilUtil::getImagePath('icon_spl.gif'));
766  $this->tpl->setVariable("ALT_IMG",$this->lng->txt("obj_spl"));
767  $this->tpl->setVariable("TYPE_IMG2", ilUtil::getImagePath('icon_spl.gif'));
768  $this->tpl->setVariable("ALT_IMG2",$this->lng->txt("obj_spl"));
769 
770  $this->tpl->parseCurrentBlock();
771  }
772  }
773 
777  public function importFileObject()
778  {
779  if (strcmp($_FILES["xmldoc"]["tmp_name"], "") == 0)
780  {
781  ilUtil::sendInfo($this->lng->txt("spl_select_file_for_import"));
782  $this->createObject();
783  return;
784  }
785  $this->ctrl->setParameter($this, "new_type", $this->type);
786  $ref_id = $this->uploadSplObject(false);
787  // always send a message
788  ilUtil::sendSuccess($this->lng->txt("object_imported"),true);
789 
790  ilUtil::redirect("ilias.php?ref_id=".$ref_id.
791  "&baseClass=ilObjSurveyQuestionPoolGUI");
792  }
793 
797  public function &createQuestionObject()
798  {
799  global $ilUser;
800  $ilUser->writePref("svy_lastquestiontype", $_POST["sel_question_types"]);
801  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestionGUI.php";
802  $q_gui =& SurveyQuestionGUI::_getQuestionGUI($_POST["sel_question_types"]);
803  $q_gui->object->setObjId($this->object->getId());
804  $q_gui->object->createNewQuestion();
805  $this->ctrl->setParameterByClass(get_class($q_gui), "q_id", $q_gui->object->getId());
806  $this->ctrl->setParameterByClass(get_class($q_gui), "sel_question_types", $_POST["sel_question_types"]);
807  $this->ctrl->redirectByClass(get_class($q_gui), "editQuestion");
808  }
809 
813  public function &editQuestionForSurveyObject()
814  {
815  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestionGUI.php";
816  $q_gui =& SurveyQuestionGUI::_getQuestionGUI("", $_GET["q_id"]);
817  $this->ctrl->setParameterByClass(get_class($q_gui), "sel_question_types", $q_gui->getQuestionType());
818  $this->ctrl->setParameterByClass(get_class($q_gui), "q_id", $_GET["q_id"]);
819  $this->ctrl->redirectByClass(get_class($q_gui), "editQuestion");
820  }
821 
825  public function &createQuestionForSurveyObject()
826  {
827  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestionGUI.php";
828  $q_gui =& SurveyQuestionGUI::_getQuestionGUI($_GET["sel_question_types"]);
829  $q_gui->object->createNewQuestion();
830  $this->ctrl->setParameterByClass(get_class($q_gui), "q_id", $q_gui->object->getId());
831  $this->ctrl->setParameterByClass(get_class($q_gui), "sel_question_types", $q_gui->getQuestionType());
832  $this->ctrl->redirectByClass(get_class($q_gui), "editQuestion");
833  }
834 
838  public function &previewObject()
839  {
840  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestionGUI.php";
841  $q_gui =& SurveyQuestionGUI::_getQuestionGUI("", $_GET["preview"]);
842  $this->ctrl->setParameterByClass(get_class($q_gui), "sel_question_types", $q_gui->getQuestionType());
843  $this->ctrl->setParameterByClass(get_class($q_gui), "q_id", $_GET["preview"]);
844  $this->ctrl->redirectByClass(get_class($q_gui), "preview");
845  }
846 
847  public function addLocatorItems()
848  {
849  global $ilLocator;
850  switch ($this->ctrl->getCmd())
851  {
852  case "create":
853  case "importFile":
854  case "cancel":
855  break;
856  default:
857  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, ""), "", $_GET["ref_id"]);
858  break;
859  }
860  if ($_GET["q_id"] > 0)
861  {
862  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
863  $q_type = SurveyQuestion::_getQuestionType($_GET["q_id"]) . "GUI";
864  $this->ctrl->setParameterByClass($q_type, "q_id", $_GET["q_id"]);
865  $ilLocator->addItem(SurveyQuestion::_getTitle($_GET["q_id"]), $this->ctrl->getLinkTargetByClass($q_type, "editQuestion"));
866  }
867  }
868 
874  public function getTabs(&$tabs_gui)
875  {
876  $next_class = $this->ctrl->getNextClass($this);
877  switch ($next_class)
878  {
879  case "":
880  case "ilpermissiongui":
881  case "ilmdeditorgui":
882  case "ilsurveyphrasesgui":
883  break;
884  default:
885  return;
886  break;
887  }
888  if (($_GET["calling_survey"] > 0) || ($_GET["new_for_survey"] > 0)) return;
889  // questions
890  $force_active = ($this->ctrl->getCmdClass() == "" ||
891  $this->ctrl->getCmd() == "")
892  ? true
893  : false;
894  if (!$force_active)
895  {
896  if (is_array($_GET["sort"]))
897  {
898  $force_active = true;
899  }
900  }
901  $tabs_gui->addTarget("survey_questions",
902  $this->ctrl->getLinkTarget($this,'questions'),
903  array("questions", "filterQuestionBrowser", "filter", "reset", "createQuestion",
904  "importQuestions", "deleteQuestions", "copy", "paste",
905  "exportQuestions", "confirmDeleteQuestions", "cancelDeleteQuestions",
906  "confirmPasteQuestions", "cancelPasteQuestions", "uploadQuestions",
907  "editQuestion", "addMaterial", "removeMaterial", "save", "cancel",
908  "cancelExplorer", "linkChilds", "addGIT", "addST", "addPG", "preview",
909  "moveCategory", "deleteCategory", "addPhrase", "addCategory", "savePhrase",
910  "addSelectedPhrase", "cancelViewPhrase", "confirmSavePhrase", "cancelSavePhrase",
911  "insertBeforeCategory", "insertAfterCategory", "confirmDeleteCategory",
912  "cancelDeleteCategory", "categories", "saveCategories",
913  "savePhrase", "addPhrase"
914  ),
915  array("ilobjsurveyquestionpoolgui", "ilsurveyphrasesgui"), "", $force_active);
916 
917  global $rbacsystem;
918  global $ilAccess;
919  // properties
920  $tabs_gui->addTarget("properties",
921  $this->ctrl->getLinkTarget($this,'properties'),
922  "properties",
923  "", "");
924  if ($rbacsystem->checkAccess('write', $this->ref_id))
925  {
926  // meta data
927  $tabs_gui->addTarget("meta_data",
928  $this->ctrl->getLinkTargetByClass('ilmdeditorgui','listSection'),
929  "", "ilmdeditorgui");
930 
931  // manage phrases
932  $tabs_gui->addTarget("manage_phrases",
933  $this->ctrl->getLinkTargetByClass("ilsurveyphrasesgui", "phrases"),
934  array("phrases", "deletePhrase", "confirmDeletePhrase", "cancelDeletePhrase"),
935  "ilsurveyphrasesgui", "");
936  }
937 
938  // export
939  $tabs_gui->addTarget("export",
940  $this->ctrl->getLinkTarget($this,'export'),
941  array("export", "createExportFile", "confirmDeleteExportFile",
942  "downloadExportFile", "cancelDeleteExportFile", "deleteExportFile"),
943  "", "");
944 
945  if ($ilAccess->checkAccess("edit_permission", "", $this->ref_id))
946  {
947  $tabs_gui->addTarget("perm_settings",
948  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), array("perm","info","owner"), 'ilpermissiongui');
949  }
950  }
951 
958  public static function _goto($a_target)
959  {
960  global $ilAccess, $ilErr, $lng;
961  if ($ilAccess->checkAccess("write", "", $a_target))
962  {
963  $_GET["baseClass"] = "ilObjSurveyQuestionPoolGUI";
964  $_GET["cmd"] = "questions";
965  $_GET["ref_id"] = $a_target;
966  include_once("ilias.php");
967  exit;
968  }
969  else if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
970  {
971  $_GET["cmd"] = "frameset";
972  $_GET["target"] = "";
973  $_GET["ref_id"] = ROOT_FOLDER_ID;
974  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
976  include("repository.php");
977  exit;
978  }
979  $ilErr->raiseError($lng->txt("msg_no_perm_read_lm"), $ilErr->FATAL);
980  }
981 } // END class.ilObjSurveyQuestionPoolGUI
982 ?>