• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

survey/classes/class.ilObjSurveyGUI.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 
00040 include_once "./classes/class.ilObjectGUI.php";
00041 include_once "./survey/classes/inc.SurveyConstants.php";
00042 
00043 class ilObjSurveyGUI extends ilObjectGUI
00044 {
00049         function ilObjSurveyGUI()
00050         {
00051     global $lng, $ilCtrl;
00052 
00053                 $this->type = "svy";
00054                 $lng->loadLanguageModule("survey");
00055                 $this->ctrl =& $ilCtrl;
00056                 $this->ctrl->saveParameter($this, "ref_id");
00057 
00058                 $this->ilObjectGUI("",$_GET["ref_id"], true, false);
00059         }
00060         
00061         function backToRepositoryObject()
00062         {
00063                 include_once "./classes/class.ilUtil.php";
00064                 $path = $this->tree->getPathFull($this->object->getRefID());
00065                 ilUtil::redirect($this->getReturnLocation("cancel","./repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
00066         }
00067 
00071         function &executeCommand()
00072         {
00073                 $cmd = $this->ctrl->getCmd("properties");
00074                 $next_class = $this->ctrl->getNextClass($this);
00075                 $this->ctrl->setReturn($this, "properties");
00076                 $this->prepareOutput();
00077 
00078                 //echo "<br>nextclass:$next_class:cmd:$cmd:qtype=$q_type";
00079                 switch($next_class)
00080                 {
00081                         case 'ilmdeditorgui':
00082                                 include_once 'Services/MetaData/classes/class.ilMDEditorGUI.php';
00083                                 $md_gui =& new ilMDEditorGUI($this->object->getId(), 0, $this->object->getType());
00084                                 $md_gui->addObserver($this->object,'MDUpdateListener','General');
00085 
00086                                 $this->ctrl->forwardCommand($md_gui);
00087                                 break;
00088                         
00089                         case "ilsurveyevaluationgui":
00090                                 include_once("./survey/classes/class.ilSurveyEvaluationGUI.php");
00091                                 $eval_gui = new ilSurveyEvaluationGUI($this->object);
00092                                 $ret =& $this->ctrl->forwardCommand($eval_gui);
00093                                 break;
00094 
00095                         case "ilsurveyexecutiongui":
00096                                 include_once("./survey/classes/class.ilSurveyExecutionGUI.php");
00097                                 $exec_gui = new ilSurveyExecutionGUI($this->object);
00098                                 $ret =& $this->ctrl->forwardCommand($exec_gui);
00099                                 break;
00100                                 
00101                         case 'ilpermissiongui':
00102                                 include_once("./classes/class.ilPermissionGUI.php");
00103                                 $perm_gui =& new ilPermissionGUI($this);
00104                                 $ret =& $this->ctrl->forwardCommand($perm_gui);
00105                                 break;
00106 
00107                         default:
00108                                 $cmd.= "Object";
00109                                 $ret =& $this->$cmd();
00110                                 break;
00111                 }
00112                 if (strtolower($_GET["baseClass"]) != "iladministrationgui" &&
00113                         $this->getCreationMode() != true)
00114                 {
00115                         $this->tpl->show();
00116                 }
00117         }
00118 
00123         function saveObject()
00124         {
00125                 global $rbacadmin;
00126 
00127                 // create and insert forum in objecttree
00128                 $newObj = parent::saveObject();
00129                 // always send a message
00130                 sendInfo($this->lng->txt("object_added"),true);
00131                 
00132                 ilUtil::redirect("ilias.php?ref_id=".$newObj->getRefId().
00133                         "&baseClass=ilObjSurveyGUI");
00134         }
00135         
00141         function cancelObject($in_rep = false)
00142         {
00143                 sendInfo($this->lng->txt("msg_cancel"),true);
00144                 ilUtil::redirect("repository.php?cmd=frameset&ref_id=".$_GET["ref_id"]);
00145         }
00146 
00154         function cancelPropertiesObject()
00155         {
00156     sendInfo($this->lng->txt("msg_cancel"), true);
00157                 $this->ctrl->redirect($this, "properties");
00158         }
00159         
00167         function savePropertiesObject()
00168         {
00169                 include_once "./classes/class.ilUtil.php";
00170                 $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
00171                 $this->object->setDescription(ilUtil::stripSlashes($_POST["description"]));
00172                 $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
00173                 $result = $this->object->setStatus($_POST["status"]);
00174                 if ($result)
00175                 {
00176                         sendInfo($result, true);
00177                 }
00178                 $this->object->setEvaluationAccess($_POST["evaluation_access"]);
00179                 $this->object->setStartDate(sprintf("%04d-%02d-%02d", $_POST["start_date"]["y"], $_POST["start_date"]["m"], $_POST["start_date"]["d"]));
00180                 $this->object->setStartDateEnabled($_POST["checked_start_date"]);
00181                 $this->object->setEndDate(sprintf("%04d-%02d-%02d", $_POST["end_date"]["y"], $_POST["end_date"]["m"], $_POST["end_date"]["d"]));
00182                 $this->object->setEndDateEnabled($_POST["checked_end_date"]);
00183                 $this->object->setIntroduction(ilUtil::stripSlashes($_POST["introduction"]));
00184                 $this->object->setAnonymize($_POST["anonymize"]);
00185                 if ($_POST["showQuestionTitles"])
00186                 {
00187                         $this->object->showQuestionTitles();
00188                 }
00189                 else
00190                 {
00191                         $this->object->hideQuestionTitles();
00192                 }
00193                 $this->update = $this->object->update();
00194                 $this->object->saveToDb();
00195                 if (strcmp($_SESSION["info"], "") != 0)
00196                 {
00197                         sendInfo($_SESSION["info"] . "<br />" . $this->lng->txt("msg_obj_modified"), true);
00198                 }
00199                 else
00200                 {
00201                         sendInfo($this->lng->txt("msg_obj_modified"), true);
00202                 }
00203                 $this->ctrl->redirect($this, "properties");
00204         }
00205 
00213   function propertiesObject()
00214   {
00215                 global $rbacsystem;
00216 
00217                 include_once "./classes/class.ilUtil.php";
00218                 $this->lng->loadLanguageModule("jscalendar");
00219                 $this->tpl->addBlockFile("CALENDAR_LANG_JAVASCRIPT", "calendar_javascript", "tpl.calendar.html");
00220                 $this->tpl->setCurrentBlock("calendar_javascript");
00221                 $this->tpl->setVariable("FULL_SUNDAY", $this->lng->txt("l_su"));
00222                 $this->tpl->setVariable("FULL_MONDAY", $this->lng->txt("l_mo"));
00223                 $this->tpl->setVariable("FULL_TUESDAY", $this->lng->txt("l_tu"));
00224                 $this->tpl->setVariable("FULL_WEDNESDAY", $this->lng->txt("l_we"));
00225                 $this->tpl->setVariable("FULL_THURSDAY", $this->lng->txt("l_th"));
00226                 $this->tpl->setVariable("FULL_FRIDAY", $this->lng->txt("l_fr"));
00227                 $this->tpl->setVariable("FULL_SATURDAY", $this->lng->txt("l_sa"));
00228                 $this->tpl->setVariable("SHORT_SUNDAY", $this->lng->txt("s_su"));
00229                 $this->tpl->setVariable("SHORT_MONDAY", $this->lng->txt("s_mo"));
00230                 $this->tpl->setVariable("SHORT_TUESDAY", $this->lng->txt("s_tu"));
00231                 $this->tpl->setVariable("SHORT_WEDNESDAY", $this->lng->txt("s_we"));
00232                 $this->tpl->setVariable("SHORT_THURSDAY", $this->lng->txt("s_th"));
00233                 $this->tpl->setVariable("SHORT_FRIDAY", $this->lng->txt("s_fr"));
00234                 $this->tpl->setVariable("SHORT_SATURDAY", $this->lng->txt("s_sa"));
00235                 $this->tpl->setVariable("FULL_JANUARY", $this->lng->txt("l_01"));
00236                 $this->tpl->setVariable("FULL_FEBRUARY", $this->lng->txt("l_02"));
00237                 $this->tpl->setVariable("FULL_MARCH", $this->lng->txt("l_03"));
00238                 $this->tpl->setVariable("FULL_APRIL", $this->lng->txt("l_04"));
00239                 $this->tpl->setVariable("FULL_MAY", $this->lng->txt("l_05"));
00240                 $this->tpl->setVariable("FULL_JUNE", $this->lng->txt("l_06"));
00241                 $this->tpl->setVariable("FULL_JULY", $this->lng->txt("l_07"));
00242                 $this->tpl->setVariable("FULL_AUGUST", $this->lng->txt("l_08"));
00243                 $this->tpl->setVariable("FULL_SEPTEMBER", $this->lng->txt("l_09"));
00244                 $this->tpl->setVariable("FULL_OCTOBER", $this->lng->txt("l_10"));
00245                 $this->tpl->setVariable("FULL_NOVEMBER", $this->lng->txt("l_11"));
00246                 $this->tpl->setVariable("FULL_DECEMBER", $this->lng->txt("l_12"));
00247                 $this->tpl->setVariable("SHORT_JANUARY", $this->lng->txt("s_01"));
00248                 $this->tpl->setVariable("SHORT_FEBRUARY", $this->lng->txt("s_02"));
00249                 $this->tpl->setVariable("SHORT_MARCH", $this->lng->txt("s_03"));
00250                 $this->tpl->setVariable("SHORT_APRIL", $this->lng->txt("s_04"));
00251                 $this->tpl->setVariable("SHORT_MAY", $this->lng->txt("s_05"));
00252                 $this->tpl->setVariable("SHORT_JUNE", $this->lng->txt("s_06"));
00253                 $this->tpl->setVariable("SHORT_JULY", $this->lng->txt("s_07"));
00254                 $this->tpl->setVariable("SHORT_AUGUST", $this->lng->txt("s_08"));
00255                 $this->tpl->setVariable("SHORT_SEPTEMBER", $this->lng->txt("s_09"));
00256                 $this->tpl->setVariable("SHORT_OCTOBER", $this->lng->txt("s_10"));
00257                 $this->tpl->setVariable("SHORT_NOVEMBER", $this->lng->txt("s_11"));
00258                 $this->tpl->setVariable("SHORT_DECEMBER", $this->lng->txt("s_12"));
00259                 $this->tpl->setVariable("ABOUT_CALENDAR", $this->lng->txt("about_calendar"));
00260                 $this->tpl->setVariable("ABOUT_CALENDAR_LONG", $this->lng->txt("about_calendar_long"));
00261                 $this->tpl->setVariable("ABOUT_TIME_LONG", $this->lng->txt("about_time"));
00262                 $this->tpl->setVariable("PREV_YEAR", $this->lng->txt("prev_year"));
00263                 $this->tpl->setVariable("PREV_MONTH", $this->lng->txt("prev_month"));
00264                 $this->tpl->setVariable("GO_TODAY", $this->lng->txt("go_today"));
00265                 $this->tpl->setVariable("NEXT_MONTH", $this->lng->txt("next_month"));
00266                 $this->tpl->setVariable("NEXT_YEAR", $this->lng->txt("next_year"));
00267                 $this->tpl->setVariable("SEL_DATE", $this->lng->txt("select_date"));
00268                 $this->tpl->setVariable("DRAG_TO_MOVE", $this->lng->txt("drag_to_move"));
00269                 $this->tpl->setVariable("PART_TODAY", $this->lng->txt("part_today"));
00270                 $this->tpl->setVariable("DAY_FIRST", $this->lng->txt("day_first"));
00271                 $this->tpl->setVariable("CLOSE", $this->lng->txt("close"));
00272                 $this->tpl->setVariable("TODAY", $this->lng->txt("today"));
00273                 $this->tpl->setVariable("TIME_PART", $this->lng->txt("time_part"));
00274                 $this->tpl->setVariable("DEF_DATE_FORMAT", $this->lng->txt("def_date_format"));
00275                 $this->tpl->setVariable("TT_DATE_FORMAT", $this->lng->txt("tt_date_format"));
00276                 $this->tpl->setVariable("WK", $this->lng->txt("wk"));
00277                 $this->tpl->setVariable("TIME", $this->lng->txt("time"));
00278                 $this->tpl->parseCurrentBlock();
00279                 $this->tpl->setCurrentBlock("CalendarJS");
00280                 $this->tpl->setVariable("LOCATION_JAVASCRIPT_CALENDAR", "./survey/js/calendar/calendar.js");
00281                 $this->tpl->setVariable("LOCATION_JAVASCRIPT_CALENDAR_SETUP", "./survey/js/calendar/calendar-setup.js");
00282                 $this->tpl->setVariable("LOCATION_JAVASCRIPT_CALENDAR_STYLESHEET", "./survey/js/calendar/calendar.css");
00283                 $this->tpl->parseCurrentBlock();
00284 
00285                 if ((!$rbacsystem->checkAccess("read", $this->ref_id)) && (!$rbacsystem->checkAccess("write", $this->ref_id))) 
00286                 {
00287                         // allow only read and write access
00288                         sendInfo($this->lng->txt("cannot_edit_survey"), true);
00289                         $path = $this->tree->getPathFull($this->object->getRefID());
00290                         ilUtil::redirect($this->getReturnLocation("cancel","./repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
00291                         return;
00292                 }
00293 
00294                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_properties.html", true);
00295                 $this->tpl->setCurrentBlock("adm_content");
00296                 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
00297                 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00298                 $this->tpl->setVariable("VALUE_TITLE", ilUtil::prepareFormOutput($this->object->getTitle()));
00299                 $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
00300                 $this->tpl->setVariable("VALUE_AUTHOR", ilUtil::prepareFormOutput($this->object->getAuthor()));
00301                 $this->tpl->setVariable("TEXT_DESCRIPTION", $this->lng->txt("description"));
00302                 $this->tpl->setVariable("VALUE_DESCRIPTION", ilUtil::prepareFormOutput($this->object->getDescription()));
00303                 $this->tpl->setVariable("TEXT_INTRODUCTION", $this->lng->txt("introduction"));
00304                 $this->tpl->setVariable("VALUE_INTRODUCTION", ilUtil::prepareFormOutput($this->object->getIntroduction()));
00305                 $this->tpl->setVariable("TEXT_STATUS", $this->lng->txt("status"));
00306                 $this->tpl->setVariable("TEXT_START_DATE", $this->lng->txt("start_date"));
00307                 $this->tpl->setVariable("VALUE_START_DATE", ilUtil::makeDateSelect("start_date", $this->object->getStartYear(), $this->object->getStartMonth(), $this->object->getStartDay()));
00308                 $this->tpl->setVariable("IMG_START_DATE_CALENDAR", ilUtil::getImagePath("calendar.png"));
00309                 $this->tpl->setVariable("TXT_START_DATE_CALENDAR", $this->lng->txt("open_calendar"));
00310                 $this->tpl->setVariable("TEXT_END_DATE", $this->lng->txt("end_date"));
00311                 $this->tpl->setVariable("VALUE_END_DATE", ilUtil::makeDateSelect("end_date", $this->object->getEndYear(), $this->object->getEndMonth(), $this->object->getEndDay()));
00312                 $this->tpl->setVariable("IMG_END_DATE_CALENDAR", ilUtil::getImagePath("calendar.png"));
00313                 $this->tpl->setVariable("TXT_END_DATE_CALENDAR", $this->lng->txt("open_calendar"));
00314                 $this->tpl->setVariable("TEXT_EVALUATION_ACCESS", $this->lng->txt("evaluation_access"));
00315                 $this->tpl->setVariable("VALUE_OFFLINE", $this->lng->txt("offline"));
00316                 $this->tpl->setVariable("VALUE_ONLINE", $this->lng->txt("online"));
00317                 $this->tpl->setVariable("TEXT_ENABLED", $this->lng->txt("enabled"));
00318                 $this->tpl->setVariable("VALUE_OFF", $this->lng->txt("off"));
00319                 $this->tpl->setVariable("VALUE_ALL", $this->lng->txt("evaluation_access_all"));
00320                 $this->tpl->setVariable("VALUE_PARTICIPANTS", $this->lng->txt("evaluation_access_participants"));
00321                 $this->tpl->setVariable("TEXT_ANONYMIZATION", $this->lng->txt("anonymize_survey"));
00322                 $this->tpl->setVariable("TEXT_ANONYMIZATION_EXPLANATION", $this->lng->txt("anonymize_survey_explanation"));
00323                 $this->tpl->setVariable("ANON_VALUE_OFF", $this->lng->txt("off"));
00324                 $this->tpl->setVariable("ANON_VALUE_ON", $this->lng->txt("on"));
00325                 
00326                 if ($this->object->getAnonymize())
00327                 {
00328                         $this->tpl->setVariable("ANON_SELECTED_ON", " selected=\"selected\"");
00329                 }
00330                 else
00331                 {
00332                         $this->tpl->setVariable("ANON_SELECTED_OFF", " selected=\"selected\"");
00333                 }
00334                 
00335                 if ($this->object->getEndDateEnabled())
00336                 {
00337                         $this->tpl->setVariable("CHECKED_END_DATE", " checked=\"checked\"");
00338                 }
00339                 if ($this->object->getStartDateEnabled())
00340                 {
00341                         $this->tpl->setVariable("CHECKED_START_DATE", " checked=\"checked\"");
00342                 }
00343                 switch ($this->object->getEvaluationAccess())
00344                 {
00345                         case EVALUATION_ACCESS_OFF:
00346                                 $this->tpl->setVariable("SELECTED_OFF", " selected=\"selected\"");
00347                                 break;
00348                         case EVALUATION_ACCESS_ALL:
00349                                 $this->tpl->setVariable("SELECTED_ALL", " selected=\"selected\"");
00350                                 break;
00351                         case EVALUATION_ACCESS_PARTICIPANTS:
00352                                 $this->tpl->setVariable("SELECTED_PARTICIPANTS", " selected=\"selected\"");
00353                                 break;
00354                 }
00355                 if ($this->object->getStatus() == STATUS_ONLINE)
00356                 {
00357                         $this->tpl->setVariable("SELECTED_ONLINE", " selected=\"selected\"");
00358                 }
00359                 else
00360                 {
00361                         $this->tpl->setVariable("SELECTED_OFFLINE", " selected=\"selected\"");
00362                 }
00363                 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00364     if ($rbacsystem->checkAccess("write", $this->ref_id)) {
00365                         $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
00366                         $this->tpl->setVariable("CANCEL", $this->lng->txt("cancel"));
00367                 }
00368                 $this->tpl->setVariable("TEXT_SHOW_QUESTIONTITLES", $this->lng->txt("svy_show_questiontitles"));
00369                 if ($this->object->getShowQuestionTitles())
00370                 {
00371                         $this->tpl->setVariable("QUESTIONTITLES_CHECKED", " checked=\"checked\"");
00372                 }
00373     $this->tpl->parseCurrentBlock();
00374   }
00375 
00383         function filterQuestionsObject()
00384         {
00385                 $this->browseForQuestionsObject($_POST["sel_questionpool"]);
00386         }
00387         
00395         function resetFilterQuestionsObject()
00396         {
00397                 $this->browseForQuestionsObject("", true);
00398         }
00399         
00407         function changeDatatypeObject()
00408         {
00409                 $this->browseForQuestionsObject("", true, $_POST["datatype"]);
00410         }
00411         
00419         function insertQuestionsObject()
00420         {
00421                 // insert selected questions into test
00422                 $inserted_objects = 0;
00423                 foreach ($_POST as $key => $value) 
00424                 {
00425                         if (preg_match("/cb_(\d+)/", $key, $matches)) 
00426                         {
00427                                 if ($_GET["browsetype"] == 1)
00428                                 {
00429                                         $this->object->insertQuestion($matches[1]);
00430                                 }
00431                                 else
00432                                 {
00433                                         $this->object->insertQuestionBlock($matches[1]);
00434                                 }
00435                                 $inserted_objects++;
00436                         }
00437                 }
00438                 if ($inserted_objects)
00439                 {
00440                         $this->object->saveCompletionStatus();
00441                         sendInfo($this->lng->txt("questions_inserted"), true);
00442                         $this->ctrl->redirect($this, "questions");
00443                 }
00444                 else
00445                 {
00446                         if ($_GET["browsetype"] == 1)
00447                         {
00448                                 sendInfo($this->lng->txt("insert_missing_question"));
00449                         }
00450                         else
00451                         {
00452                                 sendInfo($this->lng->txt("insert_missing_questionblock"));
00453                         }
00454                         $this->browseForQuestionsObject("", false, $_GET["browsetype"]);
00455                 }
00456         }
00457         
00465         function removeQuestionsObject()
00466         {
00467                 $checked_questions = array();
00468                 $checked_questionblocks = array();
00469                 foreach ($_POST as $key => $value) 
00470                 {
00471                         if (preg_match("/cb_(\d+)/", $key, $matches)) 
00472                         {
00473                                 array_push($checked_questions, $matches[1]);
00474                         }
00475                         if (preg_match("/cb_qb_(\d+)/", $key, $matches))
00476                         {
00477                                 array_push($checked_questionblocks, $matches[1]);
00478                         }
00479                 }
00480                 if (count($checked_questions) + count($checked_questionblocks) > 0) 
00481                 {
00482                         sendInfo($this->lng->txt("remove_questions"));
00483                         $this->removeQuestionsForm($checked_questions, $checked_questionblocks);
00484                         return;
00485                 } 
00486                 else 
00487                 {
00488                         sendInfo($this->lng->txt("no_question_selected_for_removal"), true);
00489                         $this->ctrl->redirect($this, "questions");
00490                 }
00491         }
00492         
00500         function browseForQuestionsObject($filter_questionpool = "", $reset_filter = false, $browsequestions = 1) 
00501         {
00502     global $rbacsystem;
00503 
00504                 if (strcmp($this->ctrl->getCmd(), "filterQuestions") != 0)
00505                 {
00506                         if (array_key_exists("sel_questionpool", $_GET)) $filter_questionpool = $_GET["sel_questionpool"];
00507                 }
00508                 if (strcmp($this->ctrl->getCmd(), "changeDatatype") != 0)
00509                 {
00510                         if (array_key_exists("browsetype", $_GET))      $browsequestions = $_GET["browsetype"];
00511                 }
00512                 if ($_POST["cmd"]["back"]) {
00513                         $show_questionbrowser = false;
00514                 }
00515                 
00516     $add_parameter = "&insert_question=1";
00517 
00518                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_questionbrowser.html", true);
00519     $this->tpl->addBlockFile("A_BUTTONS", "a_buttons", "tpl.il_svy_svy_action_buttons.html", true);
00520     $this->tpl->addBlockFile("FILTER_QUESTION_MANAGER", "filter_questions", "tpl.il_svy_svy_filter_questions.html", true);
00521 
00522                 $questionpools =& $this->object->getQuestionpoolTitles();
00523 
00524                 $filter_type = $_GET["sel_filter_type"];
00525                 if (!$filter_type)
00526                 {
00527                         $filter_type = $_POST["sel_filter_type"];
00528                 }
00529                 if ($reset_filter)
00530                 {
00531                         $filter_type = "";
00532                 }
00533                 $add_parameter .= "&sel_filter_type=$filter_type";
00534 
00535                 $filter_text = $_GET["filter_text"];
00536                 if (!$filter_text)
00537                 {
00538                         $filter_text = $_POST["filter_text"];
00539                 }
00540                 if ($reset_filter)
00541                 {
00542                         $filter_text = "";
00543                 }
00544                 $add_parameter .= "&filter_text=$filter_text";
00545 
00546                 $add_parameter .= "&browsetype=$browsequestions";
00547                 $filter_fields = array(
00548                         "title" => $this->lng->txt("title"),
00549                         "comment" => $this->lng->txt("description"),
00550                         "author" => $this->lng->txt("author"),
00551                 );
00552                 $this->tpl->setCurrentBlock("filterrow");
00553                 foreach ($filter_fields as $key => $value) 
00554                 {
00555                         $this->tpl->setVariable("VALUE_FILTER_TYPE", "$key");
00556                         $this->tpl->setVariable("NAME_FILTER_TYPE", "$value");
00557                         if (!$reset_filter) 
00558                         {
00559                                 if (strcmp($filter_type, $key) == 0) 
00560                                 {
00561                                         $this->tpl->setVariable("VALUE_FILTER_SELECTED", " selected=\"selected\"");
00562                                 }
00563                         }
00564                         $this->tpl->parseCurrentBlock();
00565                 }
00566 
00567                 $filter_question_type = $_POST["sel_question_type"];
00568                 if (!$filter_question_type)
00569                 {
00570                         $filter_question_type = $_GET["sel_question_type"];
00571                 }
00572                 if ($reset_filter)
00573                 {
00574                         $filter_question_type = "";
00575                 }
00576                 $add_parameter .= "&sel_question_type=$filter_question_type";
00577 
00578                 if ($browsequestions)
00579                 {
00580                         $questiontypes =& $this->object->_getQuestiontypes();
00581                         foreach ($questiontypes as $key => $value)
00582                         {
00583                                 $this->tpl->setCurrentBlock("questiontype_row");
00584                                 $this->tpl->setVariable("VALUE_QUESTION_TYPE", $value);
00585                                 $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt($value));
00586                                 if (strcmp($filter_question_type, $value) == 0)
00587                                 {
00588                                         $this->tpl->setVariable("SELECTED_QUESTION_TYPE", " selected=\"selected\"");
00589                                 }
00590                                 $this->tpl->parseCurrentBlock();
00591                         }
00592                 }
00593                 
00594                 if ($reset_filter)
00595                 {
00596                         $filter_questionpool = "";
00597                 }
00598                 $add_parameter .= "&sel_questionpool=$filter_questionpool";
00599                 
00600                 if ($browsequestions)
00601                 {
00602                         foreach ($questionpools as $key => $value)
00603                         {
00604                                 $this->tpl->setCurrentBlock("questionpool_row");
00605                                 $this->tpl->setVariable("VALUE_QUESTIONPOOL", $key);
00606                                 $this->tpl->setVariable("TEXT_QUESTIONPOOL", $value);
00607                                 if (strcmp($filter_questionpool, $key) == 0)
00608                                 {
00609                                         $this->tpl->setVariable("SELECTED_QUESTIONPOOL", " selected=\"selected\"");
00610                                 }
00611                                 $this->tpl->parseCurrentBlock();
00612                         }
00613                 }
00614 
00615                 if ($browsequestions)
00616                 {
00617                         $this->tpl->setCurrentBlock("question_filters");
00618                         $this->tpl->setVariable("SHOW_QUESTION_TYPES", $this->lng->txt("filter_show_question_types"));
00619                         $this->tpl->setVariable("TEXT_ALL_QUESTION_TYPES", $this->lng->txt("filter_all_question_types"));
00620                         $this->tpl->setVariable("SHOW_QUESTIONPOOLS", $this->lng->txt("filter_show_questionpools"));
00621                         $this->tpl->setVariable("TEXT_ALL_QUESTIONPOOLS", $this->lng->txt("filter_all_questionpools"));
00622                         $this->tpl->parseCurrentBlock();
00623                 }
00624 
00625                 $this->tpl->setCurrentBlock("filter_questions");
00626     $this->tpl->setVariable("FILTER_TEXT", $this->lng->txt("filter"));
00627     $this->tpl->setVariable("TEXT_FILTER_BY", $this->lng->txt("by"));
00628     if (!$_POST["cmd"]["reset"]) {
00629       $this->tpl->setVariable("VALUE_FILTER_TEXT", $filter_text);
00630     }
00631     $this->tpl->setVariable("VALUE_SUBMIT_FILTER", $this->lng->txt("set_filter"));
00632     $this->tpl->setVariable("VALUE_RESET_FILTER", $this->lng->txt("reset_filter"));
00633     $this->tpl->setVariable("OPTION_QUESTIONS", $this->lng->txt("questions"));
00634     $this->tpl->setVariable("OPTION_QUESTIONBLOCKS", $this->lng->txt("questionblocks"));
00635                 if ($browsequestions)
00636                 {
00637             $this->tpl->setVariable("SELECTED_QUESTIONS", " selected=\"selected\"");
00638                 }
00639                 else
00640                 {
00641             $this->tpl->setVariable("SELECTED_QUESTIONBLOCKS", " selected=\"selected\"");
00642                 }
00643     $this->tpl->setVariable("TEXT_DATATYPE", $this->lng->txt("display_all_available"));
00644                 $this->tpl->setVariable("BTN_CHANGE", $this->lng->txt("change"));
00645     $this->tpl->parseCurrentBlock();
00646 
00647                 if ($_POST["cmd"]["reset"])
00648                 {
00649                         $_POST["filter_text"] = "";
00650                 }
00651                 $startrow = 0;
00652                 if ($_GET["prevrow"])
00653                 {
00654                         $startrow = $_GET["prevrow"];
00655                 }
00656                 if ($_GET["nextrow"])
00657                 {
00658                         $startrow = $_GET["nextrow"];
00659                 }
00660                 if ($_GET["startrow"])
00661                 {
00662                         $startrow = $_GET["startrow"];
00663                 }
00664                 if (!$_GET["sort"])
00665                 {
00666                         // default sort order
00667                         $_GET["sort"] = array("title" => "ASC");
00668                 }
00669                 if ($browsequestions)
00670                 {
00671                         $table = $this->object->getQuestionsTable($_GET["sort"], $filter_text, $filter_type, $startrow, 1, $filter_question_type, $filter_questionpool);
00672                 }
00673                 else
00674                 {
00675                         $table = $this->object->getQuestionblocksTable($_GET["sort"], $filter_text, $filter_type, $startrow);
00676                 }
00677     $colors = array("tblrow1", "tblrow2");
00678     $counter = 0;
00679                 $questionblock_id = 0;
00680                 if ($browsequestions)
00681                 {
00682                         include_once "./classes/class.ilFormat.php";
00683                         foreach ($table["rows"] as $data)
00684                         {
00685                                 if ($rbacsystem->checkAccess("write", $data["ref_id"])) {
00686                                         $this->tpl->setCurrentBlock("QTab");
00687                                         if ($data["complete"]) {
00688                                                 // make only complete questions selectable
00689                                                 $this->tpl->setVariable("QUESTION_ID", $data["question_id"]);
00690                                         }
00691                                         $this->tpl->setVariable("QUESTION_TITLE", "<strong>" . $data["title"] . "</strong>");
00692                                         $this->tpl->setVariable("PREVIEW", "[<a href=\"" . "ilias.php?baseClass=ilObjSurveyQuestionPoolGUI&ref_id=" . $data["ref_id"] . "&cmd=preview&preview=" . $data["question_id"] . " \" target=\"_blank\">" . $this->lng->txt("preview") . "</a>]");
00693                                         $this->tpl->setVariable("QUESTION_COMMENT", $data["description"]);
00694                                         $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt($data["type_tag"]));
00695                                         $this->tpl->setVariable("QUESTION_AUTHOR", $data["author"]);
00696                                         $this->tpl->setVariable("QUESTION_CREATED", ilFormat::formatDate(ilFormat::ftimestamp2dateDB($data["created"]), "date"));
00697                                         $this->tpl->setVariable("QUESTION_UPDATED", ilFormat::formatDate(ilFormat::ftimestamp2dateDB($data["TIMESTAMP14"]), "date"));
00698                                         $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
00699                                         $this->tpl->setVariable("QUESTION_POOL", $questionpools[$data["obj_fi"]]);
00700                                         $this->tpl->parseCurrentBlock();
00701                                         $counter++;
00702                                 }
00703                         }
00704                         if ($table["rowcount"] > count($table["rows"]))
00705                         {
00706                                 $nextstep = $table["nextrow"] + $table["step"];
00707                                 if ($nextstep > $table["rowcount"])
00708                                 {
00709                                         $nextstep = $table["rowcount"];
00710                                 }
00711                                 $sort = "";
00712                                 if (is_array($_GET["sort"]))
00713                                 {
00714                                         $key = key($_GET["sort"]);
00715                                         $sort = "&sort[$key]=" . $_GET["sort"]["$key"];
00716                                 }
00717                                 $counter = 1;
00718                                 for ($i = 0; $i < $table["rowcount"]; $i += $table["step"])
00719                                 {
00720                                         $this->tpl->setCurrentBlock("pages_questions");
00721                                         if ($table["startrow"] == $i)
00722                                         {
00723                                                 $this->tpl->setVariable("PAGE_NUMBER", "<span class=\"inactivepage\">$counter</span>");
00724                                         }
00725                                         else
00726                                         {
00727                                                 $this->tpl->setVariable("PAGE_NUMBER", "<a href=\"" . $this->ctrl->getLinkTarget($this, "browseForQuestions") . $add_parameter . "$sort&nextrow=$i" . "\">$counter</a>");
00728                                         }
00729                                         $this->tpl->parseCurrentBlock();
00730                                         $counter++;
00731                                 }
00732                                 $this->tpl->setCurrentBlock("questions_navigation_bottom");
00733                                 $this->tpl->setVariable("TEXT_ITEM", $this->lng->txt("item"));
00734                                 $this->tpl->setVariable("TEXT_ITEM_START", $table["startrow"] + 1);
00735                                 $end = $table["startrow"] + $table["step"];
00736                                 if ($end > $table["rowcount"])
00737                                 {
00738                                         $end = $table["rowcount"];
00739                                 }
00740                                 $this->tpl->setVariable("TEXT_ITEM_END", $end);
00741                                 $this->tpl->setVariable("TEXT_OF", strtolower($this->lng->txt("of")));
00742                                 $this->tpl->setVariable("TEXT_ITEM_COUNT", $table["rowcount"]);
00743                                 $this->tpl->setVariable("TEXT_PREVIOUS", $this->lng->txt("previous"));
00744                                 $this->tpl->setVariable("TEXT_NEXT", $this->lng->txt("next"));
00745                                 $this->tpl->setVariable("HREF_PREV_ROWS", $this->ctrl->getLinkTarget($this, "browseForQuestions") . $add_parameter . "$sort&prevrow=" . $table["prevrow"]);
00746                                 $this->tpl->setVariable("HREF_NEXT_ROWS", $this->ctrl->getLinkTarget($this, "browseForQuestions") . $add_parameter . "$sort&nextrow=" . $table["nextrow"]);
00747                                 $this->tpl->parseCurrentBlock();
00748                         }
00749                 }
00750                 else
00751                 {
00752                         foreach ($table["rows"] as $data)
00753                         {
00754                                 $this->tpl->setCurrentBlock("questionblock_row");
00755                                 $this->tpl->setVariable("QUESTIONBLOCK_ID", $data["questionblock_id"]);
00756                                 $this->tpl->setVariable("QUESTIONBLOCK_TITLE", "<strong>" . $data["title"] . "</strong>");
00757                                 $this->tpl->setVariable("SURVEY_TITLE", $data["surveytitle"]);
00758                                 $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
00759                                 $this->tpl->setVariable("QUESTIONS_TITLE", $data["questions"]);
00760                                 $this->tpl->parseCurrentBlock();
00761                                 $counter++;
00762                         }
00763                         if ($table["rowcount"] > count($table["rows"]))
00764                         {
00765                                 $nextstep = $table["nextrow"] + $table["step"];
00766                                 if ($nextstep > $table["rowcount"])
00767                                 {
00768                                         $nextstep = $table["rowcount"];
00769                                 }
00770                                 $sort = "";
00771                                 if (is_array($_GET["sort"]))
00772                                 {
00773                                         $key = key($_GET["sort"]);
00774                                         $sort = "&sort[$key]=" . $_GET["sort"]["$key"];
00775                                 }
00776                                 $counter = 1;
00777                                 for ($i = 0; $i < $table["rowcount"]; $i += $table["step"])
00778                                 {
00779                                         $this->tpl->setCurrentBlock("pages_questionblocks");
00780                                         if ($table["startrow"] == $i)
00781                                         {
00782                                                 $this->tpl->setVariable("PAGE_NUMBER", "<strong>$counter</strong>");
00783                                         }
00784                                         else
00785                                         {
00786                                                 $this->tpl->setVariable("PAGE_NUMBER", "<a href=\"" . $this->ctrl->getLinkTarget($this, "browseForQuestions") . $add_parameter . "$sort&nextrow=$i" . "\">$counter</a>");
00787                                         }
00788                                         $this->tpl->parseCurrentBlock();
00789                                         $counter++;
00790                                 }
00791                                 $this->tpl->setCurrentBlock("questionblocks_navigation_bottom");
00792                                 $this->tpl->setVariable("TEXT_ITEM", $this->lng->txt("item"));
00793                                 $this->tpl->setVariable("TEXT_ITEM_START", $table["startrow"] + 1);
00794                                 $end = $table["startrow"] + $table["step"];
00795                                 if ($end > $table["rowcount"])
00796                                 {
00797                                         $end = $table["rowcount"];
00798                                 }
00799                                 $this->tpl->setVariable("TEXT_ITEM_END", $end);
00800                                 $this->tpl->setVariable("TEXT_OF", strtolower($this->lng->txt("of")));
00801                                 $this->tpl->setVariable("TEXT_ITEM_COUNT", $table["rowcount"]);
00802                                 $this->tpl->setVariable("TEXT_PREVIOUS", $this->lng->txt("previous"));
00803                                 $this->tpl->setVariable("TEXT_NEXT", $this->lng->txt("next"));
00804                                 $this->tpl->setVariable("HREF_PREV_ROWS", $this->ctrl->getLinkTarget($this, "browseForQuestions") . $add_parameter . "$sort&prevrow=" . $table["prevrow"]);
00805                                 $this->tpl->setVariable("HREF_NEXT_ROWS", $this->ctrl->getLinkTarget($this, "browseForQuestions") . $add_parameter . "$sort&nextrow=" . $table["nextrow"]);
00806                                 $this->tpl->parseCurrentBlock();
00807                         }
00808                 }
00809 
00810     // if there are no questions, display a message
00811     if ($counter == 0) 
00812                 {
00813       $this->tpl->setCurrentBlock("Emptytable");
00814                         if ($browsequestions)
00815                         {
00816         $this->tpl->setVariable("TEXT_EMPTYTABLE", $this->lng->txt("no_questions_available"));
00817                         }
00818                         else
00819                         {
00820         $this->tpl->setVariable("TEXT_EMPTYTABLE", $this->lng->txt("no_questionblocks_available"));
00821                         }
00822       $this->tpl->parseCurrentBlock();
00823     }
00824                 else
00825                 {
00826                         $this->tpl->setCurrentBlock("selectall");
00827                         $this->tpl->setVariable("SELECT_ALL", $this->lng->txt("select_all"));
00828                         $counter++;
00829                         $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
00830                         $this->tpl->parseCurrentBlock();
00831                         // create edit buttons & table footer
00832                         $this->tpl->setCurrentBlock("selection");
00833                         $this->tpl->setVariable("INSERT", $this->lng->txt("insert"));
00834                         $this->tpl->parseCurrentBlock();
00835 
00836                         $this->tpl->setCurrentBlock("Footer");
00837                         include_once "./classes/class.ilUtil.php";
00838                         $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\">");
00839                         $this->tpl->parseCurrentBlock();
00840                 }
00841     // define the sort column parameters
00842     $sort = array(
00843       "title" => $_GET["sort"]["title"],
00844       "description" => $_GET["sort"]["description"],
00845       "type" => $_GET["sort"]["type"],
00846       "author" => $_GET["sort"]["author"],
00847       "created" => $_GET["sort"]["created"],
00848       "updated" => $_GET["sort"]["updated"],
00849                         "qpl" => $_GET["sort"]["qpl"],
00850                         "svy" => $_GET["sort"]["svy"]
00851     );
00852     foreach ($sort as $key => $value) {
00853       if (strcmp($value, "ASC") == 0) {
00854         $sort[$key] = "DESC";
00855       } else {
00856         $sort[$key] = "ASC";
00857       }
00858     }
00859 
00860                 if ($browsequestions)
00861                 {
00862                         $this->tpl->setCurrentBlock("questions_header");
00863                         $this->tpl->setVariable("QUESTION_TITLE", "<a href=\"" . $this->ctrl->getLinkTargetByClass(get_class($this), "browseForQuestions") . "$add_parameter&startrow=" . $table["startrow"] . "&sort[title]=" . $sort["title"] . "\">" . $this->lng->txt("title") . "</a>" . $table["images"]["title"]);
00864                         $this->tpl->setVariable("QUESTION_COMMENT", "<a href=\"" . $this->ctrl->getLinkTargetByClass(get_class($this), "browseForQuestions") . "$add_parameter&startrow=" . $table["startrow"] . "&sort[description]=" . $sort["description"] . "\">" . $this->lng->txt("description") . "</a>". $table["images"]["description"]);
00865                         $this->tpl->setVariable("QUESTION_TYPE", "<a href=\"" . $this->ctrl->getLinkTargetByClass(get_class($this), "browseForQuestions") . "$add_parameter&startrow=" . $table["startrow"] . "&sort[type]=" . $sort["type"] . "\">" . $this->lng->txt("question_type") . "</a>" . $table["images"]["type"]);
00866                         $this->tpl->setVariable("QUESTION_AUTHOR", "<a href=\"" . $this->ctrl->getLinkTargetByClass(get_class($this), "browseForQuestions") . "$add_parameter&startrow=" . $table["startrow"] . "&sort[author]=" . $sort["author"] . "\">" . $this->lng->txt("author") . "</a>" . $table["images"]["author"]);
00867                         $this->tpl->setVariable("QUESTION_CREATED", "<a href=\"" . $this->ctrl->getLinkTargetByClass(get_class($this), "browseForQuestions") . "$add_parameter&startrow=" . $table["startrow"] . "&sort[created]=" . $sort["created"] . "\">" . $this->lng->txt("create_date") . "</a>" . $table["images"]["created"]);
00868                         $this->tpl->setVariable("QUESTION_UPDATED", "<a href=\"" . $this->ctrl->getLinkTargetByClass(get_class($this), "browseForQuestions") . "$add_parameter&startrow=" . $table["startrow"] . "&sort[updated]=" . $sort["updated"] . "\">" . $this->lng->txt("last_update") . "</a>" . $table["images"]["updated"]);
00869                         $this->tpl->setVariable("QUESTION_POOL", "<a href=\"" . $this->ctrl->getLinkTargetByClass(get_class($this), "browseForQuestions") . "$add_parameter&startrow=" . $table["startrow"] . "&sort[qpl]=" . $sort["qpl"] . "\">" . $this->lng->txt("obj_spl") . "</a>" . $table["images"]["qpl"]);
00870                         $this->tpl->parseCurrentBlock();
00871                 }
00872                 else
00873                 {
00874                         $this->tpl->setCurrentBlock("questionblocks_header");
00875                         $this->tpl->setVariable("QUESTIONBLOCK_TITLE", "<a href=\"" . $this->ctrl->getLinkTargetByClass(get_class($this), "browseForQuestions") . "$add_parameter&startrow=" . $table["startrow"] . "&sort[title]=" . $sort["title"] . "\">" . $this->lng->txt("title") . "</a>" . $table["images"]["title"]);
00876                         $this->tpl->setVariable("SURVEY_TITLE", "<a href=\"" . $this->ctrl->getLinkTargetByClass(get_class($this), "browseForQuestions") . "$add_parameter&startrow=" . $table["startrow"] . "&sort[svy]=" . $sort["svy"] . "\">" . $this->lng->txt("obj_svy") . "</a>" . $table["images"]["svy"]);
00877                         $this->tpl->setVariable("QUESTIONS_TITLE", $this->lng->txt("contains"));
00878                         $this->tpl->parseCurrentBlock();
00879                 }
00880     $this->tpl->setCurrentBlock("adm_content");
00881     // create table header
00882     $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this) . $add_parameter);
00883     $this->tpl->parseCurrentBlock();
00884         }
00885         
00893         function searchQuestionsExecuteObject()
00894         {
00895                 include_once "./survey/classes/class.SurveySearch.php";
00896                 include_once "./classes/class.ilUtil.php";
00897                 $search = new SurveySearch(ilUtil::stripSlashes($_POST["search_term"]), $_POST["concat"], $_POST["search_field"], $_POST["search_type"]);
00898                 $search->search();
00899                 $results =& $search->search_results;
00900                 if (count($results))
00901                 {
00902                         $this->searchQuestionsObject($results);
00903                 }
00904                 else
00905                 {
00906                         sendInfo($this->lng->txt("no_search_results"));
00907                         $this->searchQuestionsObject();
00908                 }
00909         }
00910         
00919         function searchQuestionsObject($search_results = false)
00920         {
00921                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_search_questions.html", true);
00922 
00923                 if (is_array($search_results))
00924                 {
00925                         $classes = array("tblrow1", "tblrow2");
00926                         $counter = 0;
00927                         $titles = $this->object->getQuestionpoolTitles();
00928                         $forbidden_pools =& $this->object->getForbiddenQuestionpools();
00929                         $existing_questions =& $this->object->getExistingQuestions();
00930                         foreach ($search_results as $data)
00931                         {
00932                                 if ((!in_array($data["question_id"], $existing_questions)) && (!in_array($data["obj_fi"], $forbidden_pools)))
00933                                 {
00934                                         $this->tpl->setCurrentBlock("result_row");
00935                                         $this->tpl->setVariable("COLOR_CLASS", $classes[$counter % 2]);
00936                                         $this->tpl->setVariable("QUESTION_ID", $data["question_id"]);
00937                                         $this->tpl->setVariable("QUESTION_TITLE", $data["title"]);
00938                                         $this->tpl->setVariable("QUESTION_DESCRIPTION", $data["description"]);
00939                                         $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt($data["type_tag"]));
00940                                         $this->tpl->setVariable("QUESTION_AUTHOR", $data["author"]);
00941                                         $this->tpl->setVariable("QUESTION_POOL", $titles[$data["obj_fi"]]);
00942                                         $this->tpl->parseCurrentBlock();
00943                                         $counter++;
00944                                 }
00945                         }
00946                         $this->tpl->setCurrentBlock("search_results");
00947                         include_once "./classes/class.ilUtil.php";
00948                         $this->tpl->setVariable("RESULT_IMAGE", ilUtil::getImagePath("icon_spl_b.gif"));
00949                         $this->tpl->setVariable("ALT_IMAGE", $this->lng->txt("found_questions"));
00950                         $this->tpl->setVariable("TEXT_QUESTION_TITLE", $this->lng->txt("title"));
00951                         $this->tpl->setVariable("TEXT_QUESTION_DESCRIPTION", $this->lng->txt("description"));
00952                         $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt("question_type"));
00953                         $this->tpl->setVariable("TEXT_QUESTION_AUTHOR", $this->lng->txt("author"));
00954                         $this->tpl->setVariable("TEXT_QUESTION_POOL", $this->lng->txt("obj_spl"));
00955                         $this->tpl->setVariable("BTN_INSERT", $this->lng->txt("insert"));
00956                         $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\">");
00957                         $this->tpl->setVariable("FOUND_QUESTIONS", $this->lng->txt("found_questions"));
00958                         $this->tpl->parseCurrentBlock();
00959                 }
00960                 
00961                 sendInfo();
00962                 $questiontypes = &$this->object->getQuestiontypes();
00963                 foreach ($questiontypes as $questiontype)
00964                 {
00965                         $this->tpl->setCurrentBlock("questiontypes");
00966                         $this->tpl->setVariable("VALUE_QUESTION_TYPE", $questiontype);
00967                         $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt($questiontype));
00968                         if (strcmp($_POST["search_type"], $questiontype) == 0)
00969                         {
00970                                 $this->tpl->setVariable("SELECTED_SEARCH_TYPE", " selected=\"selected\"");
00971                         }
00972                         $this->tpl->parseCurrentBlock();
00973                 }
00974                 $this->tpl->setCurrentBlock("adm_content");
00975                 switch ($_POST["search_field"])
00976                 {
00977                         case "title":
00978                                 $this->tpl->setVariable("CHECKED_TITLE", " selected=\"selected\"");
00979                                 break;
00980                         case "description":
00981                                 $this->tpl->setVariable("CHECKED_DESCRIPTION", " selected=\"selected\"");
00982                                 break;
00983                         case "author":
00984                                 $this->tpl->setVariable("CHECKED_AUTHOR", " selected=\"selected\"");
00985                                 break;
00986                         case "questiontext":
00987                                 $this->tpl->setVariable("CHECKED_QUESTIONTEXT", " selected=\"selected\"");
00988                                 break;
00989                         case "default":
00990                                 $this->tpl->setVariable("CHECKED_ALL", " selected=\"selected\"");
00991                                 break;
00992                 }
00993                 $this->tpl->setVariable("TEXT_SEARCH_TERM", $this->lng->txt("search_term"));
00994                 $this->tpl->setVariable("VALUE_SEARCH_TERM", $_POST["search_term"]);
00995                 $this->tpl->setVariable("TEXT_CONCATENATION", $this->lng->txt("concatenation"));
00996                 $this->tpl->setVariable("TEXT_AND", $this->lng->txt("and"));
00997                 $this->tpl->setVariable("TEXT_OR", $this->lng->txt("or"));
00998                 if ($_POST["concat"] == 1)
00999                 {
01000                         $this->tpl->setVariable("CHECKED_OR", " checked=\"checked\"");
01001                 }
01002                 else
01003                 {
01004                         $this->tpl->setVariable("CHECKED_AND", " checked=\"checked\"");
01005                 }
01006                 $this->tpl->setVariable("TEXT_SEARCH_FOR", $this->lng->txt("search_for"));
01007                 $this->tpl->setVariable("SEARCH_FIELD_ALL", $this->lng->txt("search_field_all"));
01008                 $this->tpl->setVariable("SEARCH_FIELD_TITLE", $this->lng->txt("title"));
01009                 $this->tpl->setVariable("SEARCH_FIELD_DESCRIPTION", $this->lng->txt("description"));
01010                 $this->tpl->setVariable("SEARCH_FIELD_AUTHOR", $this->lng->txt("author"));
01011                 $this->tpl->setVariable("SEARCH_FIELD_QUESTIONTEXT", $this->lng->txt("question"));
01012                 $this->tpl->setVariable("SEARCH_TYPE_ALL", $this->lng->txt("search_type_all"));
01013                 $this->tpl->setVariable("BTN_SEARCH", $this->lng->txt("search"));
01014                 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this) . "&search_question=1&browsetype=1&insert_question=1");
01015                 $this->tpl->parseCurrentBlock();
01016         }
01017 
01027         function removeQuestionsForm($checked_questions, $checked_questionblocks)
01028         {
01029                 sendInfo();
01030                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_remove_questions.html", true);
01031                 $colors = array("tblrow1", "tblrow2");
01032                 $counter = 0;
01033                 $surveyquestions =& $this->object->getSurveyQuestions();
01034                 foreach ($surveyquestions as $question_id => $data)
01035                 {
01036                         if (in_array($data["question_id"], $checked_questions) or (in_array($data["questionblock_id"], $checked_questionblocks)))
01037                         {
01038                                 $this->tpl->setCurrentBlock("row");
01039                                 $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
01040                                 $this->tpl->setVariable("TEXT_TITLE", $data["title"]);
01041                                 $this->tpl->setVariable("TEXT_DESCRIPTION", $data["description"]);
01042                                 $this->tpl->setVariable("TEXT_TYPE", $this->lng->txt($data["type_tag"]));
01043                                 $this->tpl->setVariable("TEXT_QUESTIONBLOCK", $data["questionblock_title"]);
01044                                 $this->tpl->parseCurrentBlock();
01045                                 $counter++;
01046                         }
01047                 }
01048                 foreach ($checked_questions as $id)
01049                 {
01050                         $this->tpl->setCurrentBlock("hidden");
01051                         $this->tpl->setVariable("HIDDEN_NAME", "id_$id");
01052                         $this->tpl->setVariable("HIDDEN_VALUE", "$id");
01053                         $this->tpl->parseCurrentBlock();
01054                 }
01055                 foreach ($checked_questionblocks as $id)
01056                 {
01057                         $this->tpl->setCurrentBlock("hidden");
01058                         $this->tpl->setVariable("HIDDEN_NAME", "id_qb_$id");
01059                         $this->tpl->setVariable("HIDDEN_VALUE", "$id");
01060                         $this->tpl->parseCurrentBlock();
01061                 }
01062                 $this->tpl->setCurrentBlock("adm_content");
01063                 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
01064                 $this->tpl->setVariable("TEXT_DESCRIPTION", $this->lng->txt("description"));
01065                 $this->tpl->setVariable("TEXT_TYPE", $this->lng->txt("question_type"));
01066                 $this->tpl->setVariable("TEXT_QUESTIONBLOCK", $this->lng->txt("questionblock"));
01067                 $this->tpl->setVariable("BTN_CONFIRM", $this->lng->txt("confirm"));
01068                 $this->tpl->setVariable("BTN_CANCEL", $this->lng->txt("cancel"));
01069                 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
01070                 $this->tpl->parseCurrentBlock();
01071         }
01072 
01073 
01082         function defineQuestionblock($questionblock_id = "")
01083         {
01084                 sendInfo();
01085                 if ($questionblock_id)
01086                 {
01087                         $questionblock = $this->object->getQuestionblock($questionblock_id);
01088                 }
01089                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_define_questionblock.html", true);
01090                 foreach ($_POST as $key => $value)
01091                 {
01092                         if (preg_match("/cb_(\d+)/", $key, $matches))
01093                         {
01094                                 $this->tpl->setCurrentBlock("hidden");
01095                                 $this->tpl->setVariable("HIDDEN_NAME", "cb_$matches[1]");
01096                                 $this->tpl->setVariable("HIDDEN_VALUE", $matches[1]);
01097                                 $this->tpl->parseCurrentBlock();
01098                         }
01099                 }
01100                 if ($questionblock_id)
01101                 {
01102                         $this->tpl->setCurrentBlock("hidden");
01103                         $this->tpl->setVariable("HIDDEN_NAME", "questionblock_id");
01104                         $this->tpl->setVariable("HIDDEN_VALUE", $questionblock_id);
01105                         $this->tpl->parseCurrentBlock();
01106                 }
01107                 $this->tpl->setCurrentBlock("adm_content");
01108                 $this->tpl->setVariable("DEFINE_QUESTIONBLOCK_HEADING", $this->lng->txt("define_questionblock"));
01109                 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
01110                 if ($questionblock_id)
01111                 {
01112                         $this->tpl->setVariable("VALUE_TITLE", $questionblock["title"]);
01113                 }
01114                 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
01115                 $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
01116                 $this->tpl->setVariable("CANCEL", $this->lng->txt("cancel"));
01117                 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
01118                 $this->tpl->parseCurrentBlock();
01119         }
01120 
01128         function createQuestionObject()
01129         {
01130                 global $ilUser;
01131                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_qpl_select.html", true);
01132                 $questionpools =& $this->object->getAvailableQuestionpools();
01133                 foreach ($questionpools as $key => $value)
01134                 {
01135                         $this->tpl->setCurrentBlock("option");
01136                         $this->tpl->setVariable("VALUE_OPTION", $key);
01137                         $this->tpl->setVariable("TEXT_OPTION", $value);
01138                         $this->tpl->parseCurrentBlock();
01139                 }
01140                 $this->tpl->setCurrentBlock("hidden");
01141                 $this->tpl->setVariable("HIDDEN_NAME", "sel_question_types");
01142                 $this->tpl->setVariable("HIDDEN_VALUE", $_POST["sel_question_types"]);
01143                 $this->tpl->parseCurrentBlock();
01144                 $this->tpl->setCurrentBlock("adm_content");
01145                 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
01146                 $this->tpl->setVariable("TXT_QPL_SELECT", $this->lng->txt("select_questionpool"));
01147                 if (count($questionpools))
01148                 {
01149                         $this->tpl->setVariable("BTN_SUBMIT", $this->lng->txt("submit"));
01150                 }
01151                 else
01152                 {
01153                         sendInfo($this->lng->txt("create_questionpool_before_add_question"));
01154                 }
01155                 $this->tpl->setVariable("BTN_CANCEL", $this->lng->txt("cancel"));
01156                 $this->tpl->parseCurrentBlock();
01157         }
01158 
01166         function cancelCreateQuestionObject()
01167         {
01168                 $this->ctrl->redirect($this, "questions");
01169         }
01170         
01178         function executeCreateQuestionObject()
01179         {
01180                 include_once "./classes/class.ilUtil.php";
01181                 ilUtil::redirect("ilias.php?baseClass=ilObjSurveyQuestionPoolGUI&ref_id=" . $_POST["sel_spl"] . "&cmd=createQuestionForSurvey&new_for_survey=".$_GET["ref_id"]."&sel_question_types=".$_POST["sel_question_types"]);
01182         }
01183         
01192         function addHeadingObject($question_id = "")
01193         {
01194                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_heading.html", true);
01195                 $survey_questions =& $this->object->getSurveyQuestions();
01196                 if ($question_id)
01197                 {
01198                         $_POST["insertbefore"] = $question_id;
01199                         $_POST["heading"] = $survey_questions[$question_id]["heading"];
01200                 }
01201                 foreach ($survey_questions as $key => $value)
01202                 {
01203                         $this->tpl->setCurrentBlock("insertbefore_row");
01204                         $this->tpl->setVariable("VALUE_OPTION", $key);
01205                         $option = $this->lng->txt("before") . ": \"" . $value["title"] . "\"";
01206                         if (strlen($option) > 80)
01207                         {
01208                                 $option = preg_replace("/^(.{40}).*(.{40})$/", "\\1 [...] \\2", $option);
01209                         }
01210                         include_once "./classes/class.ilUtil.php";
01211                         $this->tpl->setVariable("TEXT_OPTION", ilUtil::prepareFormOutput($option));
01212                         if ($key == $_POST["insertbefore"])
01213                         {
01214                                 $this->tpl->setVariable("SELECTED_OPTION", " selected=\"selected\"");
01215                         }
01216                         $this->tpl->parseCurrentBlock();
01217                 }
01218                 if ($question_id)
01219                 {
01220                         $this->tpl->setCurrentBlock("hidden");
01221                         $this->tpl->setVariable("INSERTBEFORE_ORIGINAL", $question_id);
01222                         $this->tpl->parseCurrentBlock();
01223                 }
01224                 $this->tpl->setCurrentBlock("adm_content");
01225                 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
01226                 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
01227                 if ($question_id)
01228                 {
01229                         $this->tpl->setVariable("TEXT_ADD_HEADING", $this->lng->txt("edit_heading"));
01230                         $this->tpl->setVariable("SELECT_DISABLED", " disabled=\"disabled\"");
01231                 }
01232                 else
01233                 {
01234                         $this->tpl->setVariable("TEXT_ADD_HEADING", $this->lng->txt("add_heading"));
01235                 }
01236                 $this->tpl->setVariable("TEXT_HEADING", $this->lng->txt("heading"));
01237                 $this->tpl->setVariable("VALUE_HEADING", $_POST["heading"]);
01238                 $this->tpl->setVariable("TEXT_INSERT", $this->lng->txt("insert"));
01239                 $this->tpl->setVariable("CANCEL", $this->lng->txt("cancel"));
01240                 $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
01241                 $this->tpl->parseCurrentBlock();
01242         }
01243 
01251         function confirmInsertQuestionObject()
01252         {
01253                 // insert questions from test after confirmation
01254                 foreach ($_POST as $key => $value) {
01255                         if (preg_match("/id_(\d+)/", $key, $matches)) {
01256                                 if ($_GET["browsetype"] == 1)
01257                                 {
01258                                         $this->object->insertQuestion($matches[1]);
01259                                 }
01260                                 else
01261                                 {
01262                                         $this->object->insertQuestionBlock($matches[1]);
01263                                 }
01264                         }
01265                 }
01266                 $this->object->saveCompletionStatus();
01267                 sendInfo($this->lng->txt("questions_inserted"), true);
01268                 $this->ctrl->redirect($this, "questions");
01269         }
01270         
01278         function cancelInsertQuestionObject()
01279         {
01280                 $this->ctrl->redirect($this, "questions");
01281         }
01282 
01290         function saveHeadingObject()
01291         {
01292                 if ($_POST["heading"])
01293                 {
01294                         $insertbefore = $_POST["insertbefore"];
01295                         if (!$insertbefore)
01296                         {
01297                                 $insertbefore = $_POST["insertbefore_original"];
01298                         }
01299                         $this->object->saveHeading($_POST["heading"], $insertbefore);
01300                         $this->ctrl->redirect($this, "questions");
01301                 }
01302                 else
01303                 {
01304                         sendInfo($this->lng->txt("error_add_heading"));
01305                         $this->addHeadingObject();
01306                         return;
01307                 }
01308         }
01309         
01317         function cancelHeadingObject()
01318         {
01319                 $this->ctrl->redirect($this, "questions");
01320         }
01321 
01329         function confirmRemoveHeadingObject()
01330         {
01331                 $this->object->saveHeading("", $_POST["removeheading"]);
01332                 $this->ctrl->redirect($this, "questions");
01333         }
01334         
01342         function cancelRemoveHeadingObject()
01343         {
01344                 $this->ctrl->redirect($this, "questions");
01345         }
01346         
01354         function confirmRemoveHeadingForm()
01355         {
01356                 sendInfo($this->lng->txt("confirm_remove_heading"));
01357                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_confirm_removeheading.html", true);
01358                 $this->tpl->setCurrentBlock("adm_content");
01359                 $this->tpl->setVariable("BTN_CONFIRM_REMOVE", $this->lng->txt("confirm"));
01360                 $this->tpl->setVariable("BTN_CANCEL_REMOVE", $this->lng->txt("cancel"));
01361                 $this->tpl->setVariable("REMOVE_HEADING", $_GET["removeheading"]);
01362                 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
01363                 $this->tpl->parseCurrentBlock();
01364         }
01365         
01373         function confirmRemoveQuestionsObject()
01374         {
01375                 $checked_questions = array();
01376                 $checked_questionblocks = array();
01377                 foreach ($_POST as $key => $value) 
01378                 {
01379                         if (preg_match("/id_(\d+)/", $key, $matches)) 
01380                         {
01381                                 array_push($checked_questions, $matches[1]);
01382                         }
01383                         if (preg_match("/id_qb_(\d+)/", $key, $matches)) 
01384                         {
01385                                 array_push($checked_questionblocks, $matches[1]);
01386                         }
01387                 }
01388                 $this->object->removeQuestions($checked_questions, $checked_questionblocks);
01389                 $this->object->saveCompletionStatus();
01390                 sendInfo($this->lng->txt("questions_removed"), true);
01391                 $this->ctrl->redirect($this, "questions");
01392         }
01393         
01401         function cancelRemoveQuestionsObject()
01402         {
01403                 $this->ctrl->redirect($this, "questions");
01404         }
01405 
01413         function defineQuestionblockObject()
01414         {
01415                 $questionblock = array();
01416                 foreach ($_POST as $key => $value)
01417                 {
01418                         if (preg_match("/cb_(\d+)/", $key, $matches))
01419                         {
01420                                 array_push($questionblock, $value);
01421                         }
01422                 }
01423                 if (count($questionblock) < 2)
01424                 {
01425                         sendInfo($this->lng->txt("qpl_define_questionblock_select_missing"), true);
01426                         $this->ctrl->redirect($this, "questions");
01427                 }
01428                 else
01429                 {
01430                         $this->defineQuestionblock();
01431                         return;
01432                 }
01433         }
01434         
01442         function saveDefineQuestionblockObject()
01443         {
01444                 if ($_POST["title"])
01445                 {
01446                         if ($_POST["questionblock_id"])
01447                         {
01448                                 include_once "./classes/class.ilUtil.php";
01449                                 $this->object->modifyQuestionblock($_POST["questionblock_id"], ilUtil::stripSlashes($_POST["title"]));
01450                         }
01451                         else
01452                         {
01453                                 $questionblock = array();
01454                                 foreach ($_POST as $key => $value)
01455                                 {
01456                                         if (preg_match("/cb_(\d+)/", $key, $matches))
01457                                         {
01458                                                 array_push($questionblock, $value);
01459                                         }
01460                                 }
01461                                 include_once "./classes/class.ilUtil.php";
01462                                 $this->object->createQuestionblock(ilUtil::stripSlashes($_POST["title"]), $questionblock);
01463                         }
01464                         $this->ctrl->redirect($this, "questions");
01465                 }
01466                 else
01467                 {
01468                         sendInfo($this->lng->txt("enter_questionblock_title"));
01469                         $this->defineQuestionblockObject();
01470                         return;
01471                 }
01472         }
01473 
01481         function unfoldQuestionblockObject()
01482         {
01483                 $unfoldblocks = array();
01484                 foreach ($_POST as $key => $value)
01485                 {
01486                         if (preg_match("/cb_qb_(\d+)/", $key, $matches))
01487                         {
01488                                 array_push($unfoldblocks, $matches[1]);
01489                         }
01490                 }
01491                 if (count($unfoldblocks))
01492                 {
01493                         $this->object->unfoldQuestionblocks($unfoldblocks);
01494                 }
01495                 else
01496                 {
01497                         sendInfo($this->lng->txt("qpl_unfold_select_none"), true);
01498                 }
01499                 $this->ctrl->redirect($this, "questions");
01500         }
01501         
01509         function cancelDefineQuestionblockObject()
01510         {
01511                 $this->ctrl->redirect($this, "questions");
01512         }
01513         
01521         function moveQuestionsObject()
01522         {
01523                 $move_questions = array();
01524                 foreach ($_POST as $key => $value)
01525                 {
01526                         if (preg_match("/cb_(\d+)/", $key, $matches))
01527                         {
01528                                 array_push($move_questions, $matches[1]);
01529                         }
01530                         if (preg_match("/cb_qb_(\d+)/", $key, $matches))
01531                         {
01532                                 $ids = $this->object->getQuestionblockQuestionIds($matches[1]);
01533                                 foreach ($ids as $qkey => $qid)
01534                                 {
01535                                         array_push($move_questions, $qid);
01536                                 }
01537                         }
01538                 }
01539                 if (count($move_questions) == 0)
01540                 {
01541                         sendInfo($this->lng->txt("no_question_selected_for_move"), true);
01542                         $this->ctrl->redirect($this, "questions");
01543                 }
01544                 else
01545                 {
01546                         $_SESSION["move_questions"] = $move_questions;
01547                         sendInfo($this->lng->txt("select_target_position_for_move_question"));
01548                         $this->questionsObject();
01549                 }
01550         }
01551 
01559         function insertQuestions($insert_mode)
01560         {
01561                 // get all questions to move
01562                 $move_questions = $_SESSION["move_questions"];
01563                 // get insert point
01564                 $insert_id = -1;
01565                 foreach ($_POST as $key => $value)
01566                 {
01567                         if (preg_match("/^cb_(\d+)$/", $key, $matches))
01568                         {
01569                                 if ($insert_id < 0)
01570                                 {
01571                                         $insert_id = $matches[1];
01572                                 }
01573                         }
01574                         if (preg_match("/^cb_qb_(\d+)$/", $key, $matches))
01575                         {
01576                                 if ($insert_id < 0)
01577                                 {
01578                                         $ids =& $this->object->getQuestionblockQuestionIds($matches[1]);
01579                                         if (count($ids))
01580                                         {
01581                                                 if ($insert_mode == 0)
01582                                                 {
01583                                                         $insert_id = $ids[0];
01584                                                 }
01585                                                 else if ($insert_mode == 1)
01586                                                 {
01587                                                         $insert_id = $ids[count($ids)-1];
01588                                                 }
01589                                         }
01590                                 }
01591                         }
01592                 }
01593                 if ($insert_id <= 0)
01594                 {
01595                         sendInfo($this->lng->txt("no_target_selected_for_move"), true);
01596                 }
01597                 else
01598                 {
01599                         $this->object->moveQuestions($move_questions, $insert_id, $insert_mode);
01600                 }
01601                 unset($_SESSION["move_questions"]);
01602                 $this->ctrl->redirect($this, "questions");
01603         }
01604 
01612         function insertQuestionsBeforeObject()
01613         {
01614                 $this->insertQuestions(0);
01615         }
01616         
01624         function insertQuestionsAfterObject()
01625         {
01626                 $this->insertQuestions(1);
01627         }
01628 
01636         function saveObligatoryObject()
01637         {
01638                 $obligatory = array();
01639                 foreach ($_POST as $key => $value)
01640                 {
01641                         if (preg_match("/obligatory_(\d+)/", $key, $matches))
01642                         {
01643                                 $obligatory[$matches[1]] = 1;
01644                         }
01645                 }
01646                 $this->object->setObligatoryStates($obligatory);
01647                 $this->ctrl->redirect($this, "questions");
01648         }
01649         
01657         function questionsObject() 
01658         {
01659                 global $rbacsystem;
01660 
01661                 $hasDatasets = $this->object->_hasDatasets($this->object->getSurveyId());
01662                 include_once "./classes/class.ilUtil.php";
01663                 if ((!$rbacsystem->checkAccess("read", $this->ref_id)) && (!$rbacsystem->checkAccess("write", $this->ref_id))) 
01664                 {
01665                         // allow only read and write access
01666                         sendInfo($this->lng->txt("cannot_edit_survey"), true);
01667                         $path = $this->tree->getPathFull($this->object->getRefID());
01668                         ilUtil::redirect($this->getReturnLocation("cancel","./repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
01669                         return;
01670                 }
01671                 
01672                 if ($_GET["new_id"] > 0)
01673                 {
01674                         // add a question to the survey previous created in a questionpool
01675                         $inserted = $this->object->insertQuestion($_GET["new_id"]);
01676                         if (!$inserted)
01677                         {
01678                                 sendInfo($this->lng->txt("survey_error_insert_incomplete_question"));
01679                         }
01680                 }
01681                 
01682                 if ($_GET["eqid"] and $_GET["eqpl"])
01683                 {
01684                         ilUtil::redirect("ilias.php?baseClass=ilObjSurveyQuestionPoolGUI&ref_id=" . $_GET["eqpl"] . "&cmd=editQuestionForSurvey&calling_survey=".$_GET["ref_id"]."&q_id=" . $_GET["eqid"]);
01685                 }
01686 
01687 
01688                 $_SESSION["calling_survey"] = $this->object->getRefId();
01689                 unset($_SESSION["survey_id"]);
01690 
01691                 if ($_GET["editheading"])
01692                 {
01693                         $this->addHeadingObject($_GET["editheading"]);
01694                         return;
01695                 }
01696                 
01697                 if ($_GET["up"] > 0)
01698                 {
01699                         $this->object->moveUpQuestion($_GET["up"]);
01700                 }
01701                 if ($_GET["down"] > 0)
01702                 {
01703                         $this->object->moveDownQuestion($_GET["down"]);
01704                 }
01705                 if ($_GET["qbup"] > 0)
01706                 {
01707                         $this->object->moveUpQuestionblock($_GET["qbup"]);
01708                 }
01709                 if ($_GET["qbdown"] > 0)
01710                 {
01711                         $this->object->moveDownQuestionblock($_GET["qbdown"]);
01712                 }
01713                 
01714                 if ($_GET["removeheading"])
01715                 {
01716                         $this->confirmRemoveHeadingForm();
01717                         return;
01718                 }
01719                 
01720                 if ($_GET["editblock"])
01721                 {
01722                         $this->defineQuestionblock($_GET["editblock"]);
01723                         return;
01724                 }
01725 
01726                 if ($_GET["add"])
01727                 {
01728                         // called after a new question was created from a questionpool
01729                         $selected_array = array();
01730                         array_push($selected_array, $_GET["add"]);
01731                         sendInfo($this->lng->txt("ask_insert_questions"));
01732                         $this->insertQuestionsForm($selected_array);
01733                         return;
01734                 }
01735 
01736                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_questions.html", true);
01737 
01738                 $survey_questions =& $this->object->getSurveyQuestions();
01739                 $questionblock_titles =& $this->object->getQuestionblockTitles();
01740                 $questionpools =& $this->object->getQuestionpoolTitles();
01741                 $colors = array("tblrow1", "tblrow2");
01742                 $counter = 0;
01743                 $title_counter = 0;
01744                 $last_color_class = "";
01745                 $obligatory = "<img src=\"" . ilUtil::getImagePath("obligatory.gif", true) . "\" alt=\"" . $this->lng->txt("question_obligatory") . "\" title=\"" . $this->lng->txt("question_obligatory") . "\" />";
01746                 if (count($survey_questions) > 0)
01747                 {
01748                         foreach ($survey_questions as $question_id => $data)
01749                         {
01750                                 $title_counter++;
01751                                 if (($last_questionblock_id > 0) && ($data["questionblock_id"] == 0))
01752                                 {
01753                                         $counter++;
01754                                 }
01755                                 if (($last_questionblock_id > 0) && ($data["questionblock_id"] > 0) && ($data["questionblock_id"] != $last_questionblock_id))
01756                                 {
01757                                         $counter++;
01758                                 }
01759                                 if (($data["questionblock_id"] > 0) and ($data["questionblock_id"] != $last_questionblock_id))
01760                                 {
01761                                         // add a separator line for the beginning of a question block
01762                                         $this->tpl->setCurrentBlock("separator");
01763                                         $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
01764                                         $this->tpl->parseCurrentBlock();
01765                                         $this->tpl->setCurrentBlock("QTab");
01766                                         $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
01767                                         $this->tpl->parseCurrentBlock();
01768 
01769                                         $this->tpl->setCurrentBlock("block");
01770                                         $this->tpl->setVariable("TYPE_ICON", "<img src=\"" . ilUtil::getImagePath("questionblock.gif", true) . "\" alt=\"".$this->lng->txt("questionblock_icon")."\" />");
01771                                         $this->tpl->setVariable("TEXT_QUESTIONBLOCK", $this->lng->txt("questionblock") . ": " . $data["questionblock_title"]);
01772                                         $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
01773                                         if ($rbacsystem->checkAccess("write", $this->ref_id) and $this->object->isOffline() and !$hasDatasets) 
01774                                         {
01775                                                 if ($data["question_id"] != $this->object->questions[0])
01776                                                 {
01777                                                         $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>");
01778                                                 }
01779                                                 $akeys = array_keys($survey_questions);
01780                                                 if ($data["questionblock_id"] != $survey_questions[$akeys[count($akeys)-1]]["questionblock_id"])
01781                                                 {
01782                                                         $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>");
01783                                                 }
01784                                                 $this->tpl->setVariable("TEXT_EDIT", $this->lng->txt("edit"));
01785                                                 $this->tpl->setVariable("HREF_EDIT", $this->ctrl->getLinkTarget($this, "questions") . "&editblock=" . $data["questionblock_id"]);
01786                                         }
01787                                         $this->tpl->parseCurrentBlock();
01788                                         $this->tpl->setCurrentBlock("QTab");
01789                                         $this->tpl->setVariable("QUESTION_ID", "qb_" . $data["questionblock_id"]);
01790                                         $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
01791                                         $this->tpl->parseCurrentBlock();
01792                                 }
01793                                 if (($last_questionblock_id > 0) && ($data["questionblock_id"] == 0))
01794                                 {
01795                                         // add a separator line for the end of a question block
01796                                         $this->tpl->setCurrentBlock("separator");
01797                                         $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
01798                                         $this->tpl->parseCurrentBlock();
01799                                         $this->tpl->setCurrentBlock("QTab");
01800                                         $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
01801                                         $this->tpl->parseCurrentBlock();
01802                                 }
01803                                 if ($data["heading"])
01804                                 {
01805                                         $this->tpl->setCurrentBlock("heading");
01806                                         $this->tpl->setVariable("TEXT_HEADING", $data["heading"]);
01807                                         $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
01808                                         if ($rbacsystem->checkAccess("write", $this->ref_id) and $this->object->isOffline() and !$hasDatasets) 
01809                                         {
01810                                                 $this->tpl->setVariable("TEXT_EDIT", $this->lng->txt("edit"));
01811                                                 $this->tpl->setVariable("HREF_EDIT", $this->ctrl->getLinkTarget($this, "questions") . "&editheading=" . $data["question_id"]);
01812                                                 $this->tpl->setVariable("TEXT_DELETE", $this->lng->txt("remove"));
01813                                                 $this->tpl->setVariable("HREF_DELETE", $this->ctrl->getLinkTarget($this, "questions") . "&removeheading=" . $data["question_id"]);
01814                                         }
01815                                         $this->tpl->parseCurrentBlock();
01816                                         $this->tpl->setCurrentBlock("QTab");
01817                                         $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
01818                                         $this->tpl->parseCurrentBlock();
01819                                 }
01820                                 if (!$data["questionblock_id"])
01821                                 {
01822                                         $this->tpl->setCurrentBlock("checkable");
01823                                         $this->tpl->setVariable("QUESTION_ID", $data["question_id"]);
01824                                         $this->tpl->parseCurrentBlock();
01825                                 }
01826                                 $this->tpl->setCurrentBlock("QTab");
01827                                 include_once "./survey/classes/class.SurveyQuestion.php";
01828                                 $ref_id = SurveyQuestion::_getRefIdFromObjId($data["obj_fi"]);
01829                                 if ($rbacsystem->checkAccess("write", $this->ref_id) and $this->object->isOffline() and !$hasDatasets) 
01830                                 {
01831                                         $q_id = $data["question_id"];
01832                                         $qpl_ref_id = $this->object->_getRefIdFromObjId($data["obj_fi"]);
01833                                         $this->tpl->setVariable("QUESTION_TITLE", "$title_counter. <a href=\"" . $this->ctrl->getLinkTarget($this, "questions") . "&eqid=$q_id&eqpl=$qpl_ref_id" . "\">" . $data["title"] . "</a>");
01834                                 }
01835                                 else
01836                                 {
01837                                         $this->tpl->setVariable("QUESTION_TITLE", "$title_counter. ". $data["title"]);
01838                                 }
01839                                 $this->tpl->setVariable("TYPE_ICON", "<img src=\"" . ilUtil::getImagePath("question.gif", true) . "\" alt=\"".$this->lng->txt("question_icon")."\" />");
01840                                 if ($rbacsystem->checkAccess("write", $this->ref_id) and $this->object->isOffline() and !$hasDatasets) 
01841                                 {
01842                                         $obligatory_checked = "";
01843                                         if ($data["obligatory"] == 1)
01844                                         {
01845                                                 $obligatory_checked = " checked=\"checked\"";
01846                                         }
01847                                         $this->tpl->setVariable("QUESTION_OBLIGATORY", "<input type=\"checkbox\" name=\"obligatory_" . $data["question_id"] . "\" value=\"1\"$obligatory_checked />");
01848                                 }
01849                                 else
01850                                 {
01851                                         if ($data["obligatory"] == 1)
01852                                         {
01853                                                 $this->tpl->setVariable("QUESTION_OBLIGATORY", $obligatory);
01854                                         }
01855                                 }
01856                                 $this->tpl->setVariable("QUESTION_COMMENT", $data["description"]);
01857                                 if ($rbacsystem->checkAccess("write", $this->ref_id) and $this->object->isOffline() and !$hasDatasets) 
01858                                 {
01859                                         if (!$data["questionblock_id"])
01860                                         {
01861                                                 // up/down buttons for non-questionblock questions
01862                                                 if ($data["question_id"] != $this->object->questions[0])
01863                                                 {
01864                                                         $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>");
01865                                                 }
01866                                                 if ($data["question_id"] != $this->object->questions[count($this->object->questions)-1])
01867                                                 {
01868                                                         $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>");
01869                                                 }
01870                                         }
01871                                         else
01872                                         {
01873                                                 // up/down buttons for questionblock questions
01874                                                 if ($data["questionblock_id"] == $last_questionblock_id)
01875                                                 {
01876                                                         $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>");
01877                                                 }
01878                                                 $tmp_questions = array_keys($survey_questions);
01879                                                 $blockkey = array_search($question_id, $tmp_questions);
01880                                                 if (($blockkey !== FALSE) && ($blockkey < count($tmp_questions)-1))
01881                                                 {
01882                                                         if ($data["questionblock_id"] == $survey_questions[$tmp_questions[$blockkey+1]]["questionblock_id"])
01883                                                         {
01884                                                                 $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>");
01885                                                         }
01886                                                 }
01887                                         }
01888                                 }
01889                                 $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt($data["type_tag"]));
01890                                 $this->tpl->setVariable("QUESTION_AUTHOR", $data["author"]);
01891                                 $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
01892                                 $last_color_class = $colors[$counter % 2];
01893                                 if (!$data["questionblock_id"])
01894                                 {
01895                                         $counter++;
01896                                 }
01897                                 $this->tpl->parseCurrentBlock();
01898                                 $last_questionblock_id = $data["questionblock_id"];
01899                         }
01900 
01901                         if ($rbacsystem->checkAccess("write", $this->ref_id) and $this->object->isOffline() and !$hasDatasets) 
01902                         {
01903                                 $this->tpl->setCurrentBlock("selectall");
01904                                 $this->tpl->setVariable("SELECT_ALL", $this->lng->txt("select_all"));
01905                                 $this->tpl->setVariable("COLOR_CLASS", $last_color_class);
01906                                 $this->tpl->parseCurrentBlock();
01907                                 if (array_key_exists("move_questions", $_SESSION))
01908                                 {
01909                                         $this->tpl->setCurrentBlock("move_buttons");
01910                                         $this->tpl->setVariable("INSERT_BEFORE", $this->lng->txt("insert_before"));
01911                                         $this->tpl->setVariable("INSERT_AFTER", $this->lng->txt("insert_after"));
01912                                         $this->tpl->parseCurrentBlock();
01913                                 }
01914                                 $this->tpl->setCurrentBlock("QFooter");
01915                                 $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\">");
01916                                 $this->tpl->setVariable("REMOVE", $this->lng->txt("remove_question"));
01917                                 $this->tpl->setVariable("MOVE", $this->lng->txt("move"));
01918                                 $this->tpl->setVariable("QUESTIONBLOCK", $this->lng->txt("define_questionblock"));
01919                                 $this->tpl->setVariable("UNFOLD", $this->lng->txt("unfold"));
01920                                 $this->tpl->parseCurrentBlock();
01921                                 $this->tpl->setCurrentBlock("actionbuttons");
01922                                 $this->tpl->setVariable("SAVE", $this->lng->txt("save_obligatory_state"));
01923                                 $this->tpl->setVariable("HEADING", $this->lng->txt("add_heading"));
01924                                 $this->tpl->parseCurrentBlock();
01925                         }
01926                 }
01927                 else
01928                 {
01929                         $this->tpl->setCurrentBlock("Emptytable");
01930                         $this->tpl->setVariable("TEXT_EMPTYTABLE", $this->lng->txt("no_questions_available"));
01931                         $this->tpl->parseCurrentBlock();
01932                 }
01933                 if (($last_questionblock_id > 0))
01934                 {
01935                         // add a separator line for the end of a question block (if the last question is a questionblock question)
01936                         $this->tpl->setCurrentBlock("separator");
01937                         $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
01938                         $this->tpl->parseCurrentBlock();
01939                         $this->tpl->setCurrentBlock("QTab");
01940                         $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
01941                         $this->tpl->parseCurrentBlock();
01942                 }
01943 
01944                 if ($rbacsystem->checkAccess("write", $this->ref_id) and $this->object->isOffline() and !$hasDatasets) 
01945                 {
01946                         $this->tpl->setCurrentBlock("QTypes");
01947                         $query = "SELECT * FROM survey_questiontype";
01948                         $query_result = $this->ilias->db->query($query);
01949                         while ($data = $query_result->fetchRow(DB_FETCHMODE_OBJECT))
01950                         {
01951                                 $this->tpl->setVariable("QUESTION_TYPE_ID", $data->type_tag);
01952                                 $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt($data->type_tag));
01953                                 $this->tpl->parseCurrentBlock();
01954                         }
01955                         $this->tpl->parseCurrentBlock();
01956                 }
01957                 $this->tpl->setCurrentBlock("adm_content");
01958                 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
01959                 $this->tpl->setVariable("QUESTION_TITLE", $this->lng->txt("title"));
01960                 $this->tpl->setVariable("QUESTION_COMMENT", $this->lng->txt("description"));
01961                 $this->tpl->setVariable("QUESTION_OBLIGATORY", $this->lng->txt("obligatory"));
01962                 $this->tpl->setVariable("QUESTION_SEQUENCE", $this->lng->txt("sequence"));
01963                 $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("question_type"));
01964                 $this->tpl->setVariable("QUESTION_AUTHOR", $this->lng->txt("author"));
01965 
01966                 if ($rbacsystem->checkAccess("write", $this->ref_id) and $this->object->isOffline() and !$hasDatasets)
01967                 {
01968                         $this->tpl->setVariable("BUTTON_INSERT_QUESTION", $this->lng->txt("browse_for_questions"));
01969                         $this->tpl->setVariable("BUTTON_SEARCH_QUESTION", $this->lng->txt("search_questions"));
01970                         $this->tpl->setVariable("TEXT_OR", " " . strtolower($this->lng->txt("or")));
01971                         $this->tpl->setVariable("TEXT_CREATE_NEW", " " . strtolower($this->lng->txt("or")) . " " . $this->lng->txt("create_new"));
01972                         $this->tpl->setVariable("BUTTON_CREATE_QUESTION", $this->lng->txt("create"));
01973                 }
01974                 if ($this->object->isOnline())
01975                 {
01976                         sendInfo($this->lng->txt("survey_online_warning"));
01977                 }
01978                 else if ($hasDatasets)
01979                 {
01980                         sendInfo($this->lng->txt("survey_has_datasets_warning"));
01981                 }
01982 
01983                 $this->tpl->parseCurrentBlock();
01984         }
01985 
01993         function evaluationObject()
01994         {
01995                 include_once("./survey/classes/class.ilSurveyEvaluationGUI.php");
01996                 $eval_gui = new ilSurveyEvaluationGUI($this->object);
01997                 $this->ctrl->setCmdClass(get_class($eval_gui));
01998                 $this->ctrl->redirect($eval_gui, "evaluation");
01999         }
02000         
02008         function runObject()
02009         {
02010                 include_once("./survey/classes/class.ilSurveyExecutionGUI.php");
02011                 $exec_gui = new ilSurveyExecutionGUI($this->object);
02012                 $this->ctrl->setCmdClass(get_class($exec_gui));
02013                 $this->ctrl->redirect($exec_gui, "run");
02014         }
02015         
02023         function outUserGroupTable($a_type, $id_array, $block_result, $block_row, $title_text, $buttons)
02024         {
02025                 global $rbacsystem;
02026                 
02027                 $rowclass = array("tblrow1", "tblrow2");
02028                 switch($a_type)
02029                 {
02030                         case "usr":
02031                                 include_once "./classes/class.ilObjUser.php";
02032                                 $counter = 0;
02033                                 foreach ($id_array as $user_id)
02034                                 {
02035                                         $user = new ilObjUser($user_id);
02036                                         $this->tpl->setCurrentBlock($block_row);
02037                                         $this->tpl->setVariable("COLOR_CLASS", $rowclass[$counter % 2]);
02038                                         $this->tpl->setVariable("COUNTER", $user->getId());
02039                                         $this->tpl->setVariable("VALUE_LOGIN", $user->getLogin());
02040                                         $this->tpl->setVariable("VALUE_FIRSTNAME", $user->getFirstname());
02041                                         $this->tpl->setVariable("VALUE_LASTNAME", $user->getLastname());
02042                                         $counter++;
02043                                         $this->tpl->parseCurrentBlock();
02044                                 }
02045                                 if (count($id_array))
02046                                 {
02047                                         $this->tpl->setCurrentBlock("selectall_$block_result");
02048                                         $this->tpl->setVariable("SELECT_ALL", $this->lng->txt("select_all"));
02049                                         $counter++;
02050                                         $this->tpl->setVariable("COLOR_CLASS", $rowclass[$counter % 2]);
02051                                         $this->tpl->parseCurrentBlock();
02052                                 }
02053                                 $this->tpl->setCurrentBlock($block_result);
02054                                 include_once "./classes/class.ilUtil.php";
02055                                 $this->tpl->setVariable("TEXT_USER_TITLE", "<img src=\"" . ilUtil::getImagePath("icon_usr.gif") . "\" alt=\"".$this->lng->txt("obj_usr")."\" /> " . $title_text);
02056                                 $this->tpl->setVariable("TEXT_LOGIN", $this->lng->txt("login"));
02057                                 $this->tpl->setVariable("TEXT_FIRSTNAME", $this->lng->txt("firstname"));
02058                                 $this->tpl->setVariable("TEXT_LASTNAME", $this->lng->txt("lastname"));
02059                                 if ($rbacsystem->checkAccess('invite', $this->object->getRefId()))
02060                                 {
02061                                         foreach ($buttons as $cat)
02062                                         {
02063                                                 $this->tpl->setVariable("VALUE_" . strtoupper($cat), $this->lng->txt($cat));
02064                                         }
02065                                         $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\">");
02066                                 }
02067                                 $this->tpl->parseCurrentBlock();
02068                                 break;
02069                         case "grp":
02070                                 include_once "./classes/class.ilObjGroup.php";
02071                                 $counter = 0;
02072                                 foreach ($id_array as $group_id)
02073                                 {
02074                                         $group = new ilObjGroup($group_id);
02075                                         $this->tpl->setCurrentBlock($block_row);
02076                                         $this->tpl->setVariable("COLOR_CLASS", $rowclass[$counter % 2]);
02077                                         $this->tpl->setVariable("COUNTER", $group->getRefId());
02078                                         $this->tpl->setVariable("VALUE_TITLE", $group->getTitle());
02079                                         $this->tpl->setVariable("VALUE_DESCRIPTION", $group->getDescription());
02080                                         $counter++;
02081                                         $this->tpl->parseCurrentBlock();
02082                                 }
02083                                 if (count($id_array))
02084                                 {
02085                                         $this->tpl->setCurrentBlock("selectall_$block_result");
02086                                         $this->tpl->setVariable("SELECT_ALL", $this->lng->txt("select_all"));
02087                                         $counter++;
02088                                         $this->tpl->setVariable("COLOR_CLASS", $rowclass[$counter % 2]);
02089                                         $this->tpl->parseCurrentBlock();
02090                                 }
02091                                 $this->tpl->setCurrentBlock($block_result);
02092                                 include_once "./classes/class.ilUtil.php";
02093                                 $this->tpl->setVariable("TEXT_GROUP_TITLE", "<img src=\"" . ilUtil::getImagePath("icon_grp.gif") . "\" alt=\"".$this->lng->txt("obj_grp")."\" /> " . $title_text);
02094                                 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
02095                                 $this->tpl->setVariable("TEXT_DESCRIPTION", $this->lng->txt("description"));
02096                                 if ($rbacsystem->checkAccess('invite', $this->object->getRefId()))
02097                                 {
02098                                         foreach ($buttons as $cat)
02099                                         {
02100                                                 $this->tpl->setVariable("VALUE_" . strtoupper($cat), $this->lng->txt($cat));
02101                                         }
02102                                         $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\">");
02103                                 }
02104                                 $this->tpl->parseCurrentBlock();
02105                                 break;
02106                         case "role":
02107                                 include_once "./classes/class.ilObjRole.php";
02108                                 $counter = 0;
02109                                 foreach ($id_array as $role_id)
02110                                 {
02111                                         $role = new ilObjRole($role_id);
02112                                         $this->tpl->setCurrentBlock($block_row);
02113                                         $this->tpl->setVariable("COLOR_CLASS", $rowclass[$counter % 2]);
02114                                         $this->tpl->setVariable("COUNTER", $role->getId());
02115                                         $this->tpl->setVariable("VALUE_TITLE", $role->getTitle());
02116                                         $this->tpl->setVariable("VALUE_DESCRIPTION", $role->getDescription());
02117                                         $counter++;
02118                                         $this->tpl->parseCurrentBlock();
02119                                 }
02120                                 if (count($id_array))
02121                                 {
02122                                         $this->tpl->setCurrentBlock("selectall_$block_result");
02123                                         $this->tpl->setVariable("SELECT_ALL", $this->lng->txt("select_all"));
02124                                         $counter++;
02125                                         $this->tpl->setVariable("COLOR_CLASS", $rowclass[$counter % 2]);
02126                                         $this->tpl->parseCurrentBlock();
02127                                 }
02128                                 $this->tpl->setCurrentBlock($block_result);
02129                                 include_once "./classes/class.ilUtil.php";
02130                                 $this->tpl->setVariable("TEXT_ROLE_TITLE", "<img src=\"" . ilUtil::getImagePath("icon_role.gif") . "\" alt=\"".$this->lng->txt("obj_role")."\" /> " . $title_text);
02131                                 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
02132                                 $this->tpl->setVariable("TEXT_DESCRIPTION", $this->lng->txt("description"));
02133                                 if ($rbacsystem->checkAccess('invite', $this->object->getRefId()))
02134                                 {
02135                                         foreach ($buttons as $cat)
02136                                         {
02137                                                 $this->tpl->setVariable("VALUE_" . strtoupper($cat), $this->lng->txt($cat));
02138                                         }
02139                                         $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\">");
02140                                 }
02141                                 $this->tpl->parseCurrentBlock();
02142                                 break;
02143                 }
02144         }
02145         
02153         function cancelInvitationStatusObject()
02154         {
02155                 $this->ctrl->redirect($this, "invite");
02156         }
02157 
02165         function saveInvitationStatusObject()
02166         {
02167                 $this->object->setInvitationAndMode($_POST["invitation"], $_POST["mode"]);
02168                 $this->object->saveToDb();
02169                 $this->ctrl->redirect($this, "invite");
02170         }
02171         
02179         function searchInvitationObject()
02180         {
02181                 $this->inviteObject();
02182         }
02183 
02191         function disinviteUserGroupObject()
02192         {
02193                 // disinvite users
02194                 if (is_array($_POST["invited_users"]))
02195                 {
02196                         foreach ($_POST["invited_users"] as $user_id)
02197                         {
02198                                 $this->object->disinviteUser($user_id);
02199                         }
02200                 }
02201                 $this->ctrl->redirect($this, "invite");
02202         }
02203         
02211         function inviteUserGroupObject()
02212         {
02213                 // add users to invitation
02214                 if (is_array($_POST["user_select"]))
02215                 {
02216                         foreach ($_POST["user_select"] as $user_id)
02217                         {
02218                                 $this->object->inviteUser($user_id);
02219                         }
02220                 }
02221                 // add groups to invitation
02222                 if (is_array($_POST["group_select"]))
02223                 {
02224                         foreach ($_POST["group_select"] as $group_id)
02225                         {
02226                                 $this->object->inviteGroup($group_id);
02227                         }
02228                 }
02229                 // add roles to invitation
02230                 if (is_array($_POST["role_select"]))
02231                 {
02232                         foreach ($_POST["role_select"] as $role_id)
02233                         {
02234                                 $this->object->inviteRole($role_id);
02235                         }
02236                 }
02237                 $this->ctrl->redirect($this, "invite");
02238         }
02239 
02240         
02248         function inviteObject()
02249         {
02250                 global $rbacsystem;
02251 
02252                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_invite.html", true);
02253 
02254                 if ($this->object->getStatus() == STATUS_OFFLINE)
02255                 {
02256                         $this->tpl->setCurrentBlock("survey_offline");
02257                         $this->tpl->setVariable("SURVEY_OFFLINE_MESSAGE", $this->lng->txt("survey_offline_message"));
02258                         $this->tpl->parseCurrentBlock();
02259                         return;
02260                 }
02261 
02262                 $concat = ($_POST["concatenation"]) ? $_POST["concatenation"] : "or";
02263                 $searchfor = ($_POST["search_for"]) ? $_POST["search_for"] : array("usr");
02264 
02265                 if (strcmp($this->ctrl->getCmd(), "searchInvitation") == 0)
02266                 {
02267                         if (is_array($_POST["search_for"]))
02268                         {
02269                                 if (in_array("usr", $_POST["search_for"]) or in_array("grp", $_POST["search_for"]) or in_array("role", $_POST["search_for"]))
02270                                 {
02271                                         include_once "./classes/class.ilSearch.php";
02272                                         $search =& new ilSearch($ilUser->id);
02273                                         $search->setSearchString($_POST["search_term"]);
02274                                         $search->setCombination($concat);
02275                                         $search->setSearchFor($searchfor);
02276                                         $search->setSearchType("new");
02277                                         if($search->validate($message))
02278                                         {
02279                                                 $search->performSearch();
02280                                         }
02281                                         if ($message)
02282                                         {
02283                                                 sendInfo($message);
02284                                         }
02285                                         if(!$search->getNumberOfResults() && $search->getSearchFor())
02286                                         {
02287                                                 sendInfo($this->lng->txt("search_no_match"));
02288                                         }
02289                                         $buttons = array("add");
02290                                         $invited_users = $this->object->getInvitedUsers();
02291                                         if ($searchresult = $search->getResultByType("usr"))
02292                                         {
02293                                                 $users = array();
02294                                                 foreach ($searchresult as $result_array)
02295                                                 {
02296                                                         if (!in_array($result_array["id"], $invited_users))
02297                                                         {
02298                                                                 array_push($users, $result_array["id"]);
02299                                                         }
02300                                                 }
02301                                                 $this->outUserGroupTable("usr", $users, "user_result", "user_row", $this->lng->txt("search_users"), $buttons);
02302                                         }
02303                                         $searchresult = array();
02304                                         if ($searchresult = $search->getResultByType("grp"))
02305                                         {
02306                                                 $groups = array();
02307                                                 foreach ($searchresult as $result_array)
02308                                                 {
02309                                                         array_push($groups, $result_array["id"]);
02310                                                 }
02311                                                 $this->outUserGroupTable("grp", $groups, "group_result", "group_row", $this->lng->txt("search_groups"), $buttons);
02312                                         }
02313                                         $searchresult = array();
02314                                         if ($searchresult = $search->getResultByType("role"))
02315                                         {
02316                                                 $roles = array();
02317                                                 foreach ($searchresult as $result_array)
02318                                                 {
02319                                                         array_push($roles, $result_array["id"]);
02320                                                 }
02321                                                 $this->outUserGroupTable("role", $roles, "role_result", "role_row", $this->lng->txt("search_roles"), $buttons);
02322                                         }
02323                                 }
02324                         }
02325                         else
02326                         {
02327                                 sendInfo($this->lng->txt("no_user_or_group_selected"));
02328                         }
02329                 }
02330 
02331                 if (($this->object->getInvitationMode() == MODE_PREDEFINED_USERS) and ($this->object->getInvitation() == INVITATION_ON))
02332                 {
02333                         if ($rbacsystem->checkAccess('invite', $this->ref_id))
02334                         {
02335                                 $this->tpl->setCurrentBlock("invitation");
02336                                 $this->tpl->setVariable("SEARCH_INVITATION", $this->lng->txt("search_invitation"));
02337                                 $this->tpl->setVariable("SEARCH_TERM", $this->lng->txt("search_term"));
02338                                 $this->tpl->setVariable("SEARCH_FOR", $this->lng->txt("search_for"));
02339                                 $this->tpl->setVariable("SEARCH_USERS", $this->lng->txt("objs_usr"));
02340                                 $this->tpl->setVariable("SEARCH_GROUPS", $this->lng->txt("objs_grp"));
02341                                 $this->tpl->setVariable("SEARCH_ROLES", $this->lng->txt("objs_role"));
02342                                 $this->tpl->setVariable("TEXT_CONCATENATION", $this->lng->txt("concatenation"));
02343                                 $this->tpl->setVariable("TEXT_AND", $this->lng->txt("and"));
02344                                 $this->tpl->setVariable("TEXT_OR", $this->lng->txt("or"));
02345                                 $this->tpl->setVariable("VALUE_SEARCH_TERM", $_POST["search_term"]);
02346                                 if (is_array($searchfor))
02347                                 {
02348                                         if (in_array("usr", $searchfor))
02349                                         {
02350                                                 $this->tpl->setVariable("CHECKED_USERS", " checked=\"checked\"");
02351                                         }
02352                                         if (in_array("grp", $searchfor))
02353                                         {
02354                                                 $this->tpl->setVariable("CHECKED_GROUPS", " checked=\"checked\"");
02355                                         }
02356                                         if (in_array("role", $searchfor))
02357                                         {
02358                                                 $this->tpl->setVariable("CHECKED_ROLES", " checked=\"checked\"");
02359                                         }
02360                                 }
02361                                 if (strcmp($concat, "and") == 0)
02362                                 {
02363                                         $this->tpl->setVariable("CHECKED_AND", " checked=\"checked\"");
02364                                 }
02365                                 else if (strcmp($concat, "or") == 0)
02366                                 {
02367                                         $this->tpl->setVariable("CHECKED_OR", " checked=\"checked\"");
02368                                 }
02369                                 $this->tpl->setVariable("SEARCH", $this->lng->txt("search"));
02370                                 $this->tpl->parseCurrentBlock();
02371                         }
02372                 }
02373                 if ($this->object->getInvitationMode() == MODE_PREDEFINED_USERS)
02374                 {
02375                         $invited_users = $this->object->getInvitedUsers();
02376                         $buttons = array("disinvite");
02377                         if (count($invited_users))
02378                         {
02379                                 $this->outUserGroupTable("usr", $invited_users, "invited_user_result", "invited_user_row", $this->lng->txt("invited_users"), $buttons);
02380                         }
02381                 }
02382                 if ($this->object->getInvitation() == INVITATION_ON)
02383                 {
02384                         $this->tpl->setCurrentBlock("invitation_mode");
02385                         $this->tpl->setVariable("TEXT_MODE", $this->lng->txt("invitation_mode"));
02386                         $this->tpl->setVariable("VALUE_UNLIMITED", $this->lng->txt("unlimited_users"));
02387                         $this->tpl->setVariable("VALUE_PREDEFINED", $this->lng->txt("predefined_users"));
02388                         if ($this->object->getInvitationMode() == MODE_PREDEFINED_USERS)
02389                         {
02390                                 $this->tpl->setVariable("SELECTED_PREDEFINED", " selected=\"selected\"");
02391                         }
02392                         else
02393                         {
02394                                 $this->tpl->setVariable("SELECTED_UNLIMITED", " selected=\"selected\"");
02395                         }
02396                         $this->tpl->parseCurrentBlock();
02397                 }
02398                 $this->tpl->setCurrentBlock("adm_content");
02399                 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
02400                 $this->tpl->setVariable("TEXT_INVITATION", $this->lng->txt("invitation"));
02401                 $this->tpl->setVariable("VALUE_ON", $this->lng->txt("on"));
02402                 $this->tpl->setVariable("VALUE_OFF", $this->lng->txt("off"));
02403                 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
02404                 if ($this->object->getInvitation() == INVITATION_ON)
02405                 {
02406                         $this->tpl->setVariable("SELECTED_ON", " selected=\"selected\"");
02407                 }
02408                 else
02409                 {
02410                         $this->tpl->setVariable("SELECTED_OFF", " selected=\"selected\"");
02411                 }
02412     if ($rbacsystem->checkAccess("write", $this->ref_id) or $rbacsystem->checkAccess('invite', $this->ref_id)) {
02413                         $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
02414                         $this->tpl->setVariable("CANCEL", $this->lng->txt("cancel"));
02415                 }
02416                 $this->tpl->parseCurrentBlock();
02417         }
02418 
02426         function deleteAllUserDataObject()
02427         {
02428                 sendInfo($this->lng->txt("confirm_delete_all_user_data"));
02429                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_maintenance.html", true);
02430                 $this->tpl->setCurrentBlock("confirm_delete");
02431                 $this->tpl->setVariable("BTN_CONFIRM_DELETE_ALL", $this->lng->txt("confirm"));
02432                 $this->tpl->setVariable("BTN_CANCEL_DELETE_ALL", $this->lng->txt("cancel"));
02433                 $this->tpl->parseCurrentBlock();
02434                 $this->tpl->setCurrentBlock("adm_content");
02435                 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
02436                 $this->tpl->parseCurrentBlock();
02437         }
02438         
02446         function confirmDeleteAllUserDataObject()
02447         {
02448                 $this->object->deleteAllUserData();
02449                 sendInfo($this->lng->txt("svy_all_user_data_deleted"), true);
02450                 $this->ctrl->redirect($this, "maintenance");
02451         }
02452         
02460         function cancelDeleteAllUserDataObject()
02461         {
02462                 $this->ctrl->redirect($this, "maintenance");
02463         }
02464         
02472         function maintenanceObject()
02473         {
02474                 global $rbacsystem;
02475 
02476                 if ((!$rbacsystem->checkAccess("read", $this->ref_id)) && (!$rbacsystem->checkAccess("write", $this->ref_id))) 
02477                 {
02478                         // allow only read and write access
02479                         sendInfo($this->lng->txt("cannot_edit_survey"), true);
02480                         $path = $this->tree->getPathFull($this->object->getRefID());
02481                         include_once "./classes/class.ilUtil.php";
02482                         ilUtil::redirect($this->getReturnLocation("cancel","./repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
02483                         return;
02484                 }
02485 
02486                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_maintenance.html", true);
02487 
02488                 if ($rbacsystem->checkAccess("write", $this->ref_id))
02489                 {
02490                         $this->tpl->setCurrentBlock("delete_button");
02491                         $this->tpl->setVariable("BTN_DELETE_ALL", $this->lng->txt("svy_delete_all_user_data"));
02492                         $this->tpl->parseCurrentBlock();
02493                         $this->tpl->setCurrentBlock("adm_content");
02494                         $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
02495                         $this->tpl->parseCurrentBlock();
02496                 }
02497                 else
02498                 {
02499                         sendInfo($this->lng->txt("cannot_maintain_survey"));
02500                 }
02501         }       
02502 
02510         function statusObject()
02511         {
02512                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_status.html", true);
02513                 if (!$this->object->isComplete())
02514                 {
02515                         if (count($this->object->questions) == 0)
02516                         {
02517                                 $this->tpl->setCurrentBlock("list_element");
02518                                 $this->tpl->setVariable("TEXT_ELEMENT", $this->lng->txt("svy_missing_questions"));
02519                                 $this->tpl->parseCurrentBlock();
02520                         }
02521                         if (strcmp($this->object->author, "") == 0)
02522                         {
02523                                 $this->tpl->setCurrentBlock("list_element");
02524                                 $this->tpl->setVariable("TEXT_ELEMENT", $this->lng->txt("svy_missing_author"));
02525                                 $this->tpl->parseCurrentBlock();
02526                         }
02527                         if (strcmp($this->object->title, "") == 0)
02528                         {
02529                                 $this->tpl->setCurrentBlock("list_element");
02530                                 $this->tpl->setVariable("TEXT_ELEMENT", $this->lng->txt("svy_missing_author"));
02531                                 $this->tpl->parseCurrentBlock();
02532                         }
02533                         $this->tpl->setCurrentBlock("status_list");
02534                         $this->tpl->setVariable("TEXT_MISSING_ELEMENTS", $this->lng->txt("svy_status_missing_elements"));
02535                         $this->tpl->parseCurrentBlock();
02536                 }
02537                 $this->tpl->setCurrentBlock("adm_content");
02538                 if ($this->object->isComplete())
02539                 {
02540                         $this->tpl->setVariable("TEXT_STATUS_MESSAGE", $this->lng->txt("svy_status_ok"));
02541                         $this->tpl->setVariable("STATUS_CLASS", "bold");
02542                 }
02543                 else
02544                 {
02545                         $this->tpl->setVariable("TEXT_STATUS_MESSAGE", $this->lng->txt("svy_status_missing"));
02546                         $this->tpl->setVariable("STATUS_CLASS", "warning");
02547                 }
02548                 $this->tpl->parseCurrentBlock();
02549         }       
02550 
02551         /*
02552         * list all export files
02553         */
02554         function exportObject()
02555         {
02556                 global $tree;
02557                 global $rbacsystem;
02558 
02559                 if ((!$rbacsystem->checkAccess("read", $this->ref_id)) && (!$rbacsystem->checkAccess("write", $this->ref_id))) 
02560                 {
02561                         // allow only read and write access
02562                         sendInfo($this->lng->txt("cannot_edit_survey"), true);
02563                         $path = $this->tree->getPathFull($this->object->getRefID());
02564                         include_once "./classes/class.ilUtil.php";
02565                         ilUtil::redirect($this->getReturnLocation("cancel","./repository.php?ref_id=" . $path[count($path) - 2]["child"]));
02566                         return;
02567                 }
02568 
02569                 //$this->setTabs();
02570 
02571                 //add template for view button
02572                 $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
02573 
02574                 // create export file button
02575                 $this->tpl->setCurrentBlock("btn_cell");
02576                 $this->tpl->setVariable("BTN_LINK", $this->ctrl->getLinkTarget($this, "createExportFile"));
02577                 $this->tpl->setVariable("BTN_TXT", $this->lng->txt("svy_create_export_file"));
02578                 $this->tpl->parseCurrentBlock();
02579 
02580                 $export_dir = $this->object->getExportDirectory();
02581                 $export_files = $this->object->getExportFiles($export_dir);
02582 
02583                 // create table
02584                 include_once("./classes/class.ilTableGUI.php");
02585                 $tbl = new ilTableGUI();
02586 
02587                 // load files templates
02588                 $this->tpl->addBlockfile("ADM_CONTENT", "adm_content", "tpl.table.html");
02589 
02590                 // load template for table content data
02591                 $this->tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.export_file_row.html", true);
02592 
02593                 $num = 0;
02594 
02595                 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
02596 
02597                 $tbl->setTitle($this->lng->txt("svy_export_files"));
02598 
02599                 $tbl->setHeaderNames(array("", $this->lng->txt("svy_file"),
02600                         $this->lng->txt("svy_size"), $this->lng->txt("date") ));
02601 
02602                 $tbl->enabled["sort"] = false;
02603                 $tbl->setColumnWidth(array("1%", "49%", "25%", "25%"));
02604 
02605                 // control
02606                 $tbl->setOrderColumn($_GET["sort_by"]);
02607                 $tbl->setOrderDirection($_GET["sort_order"]);
02608                 $tbl->setLimit($_GET["limit"]);
02609                 $tbl->setOffset($_GET["offset"]);
02610                 $tbl->setMaxCount($this->maxcount);             // ???
02611 
02612                 // footer
02613                 $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
02614                 //$tbl->disable("footer");
02615 
02616                 $tbl->setMaxCount(count($export_files));
02617                 $export_files = array_slice($export_files, $_GET["offset"], $_GET["limit"]);
02618 
02619                 $tbl->render();
02620                 if(count($export_files) > 0)
02621                 {
02622                         $this->tpl->setVariable("COLUMN_COUNTS", 4);
02623                         
02624                         $i=0;
02625                         foreach($export_files as $exp_file)
02626                         {
02627                                 $this->tpl->setCurrentBlock("tbl_content");
02628                                 $this->tpl->setVariable("TXT_FILENAME", $exp_file);
02629 
02630                                 $css_row = ilUtil::switchColor($i++, "tblrow1", "tblrow2");
02631                                 $this->tpl->setVariable("CSS_ROW", $css_row);
02632 
02633                                 $this->tpl->setVariable("TXT_SIZE", filesize($export_dir."/".$exp_file));
02634                                 $this->tpl->setVariable("CHECKBOX_ID", $exp_file);
02635 
02636                                 $file_arr = explode("__", $exp_file);
02637                                 $this->tpl->setVariable("TXT_DATE", date("Y-m-d H:i:s",$file_arr[0]));
02638 
02639                                 $this->tpl->parseCurrentBlock();
02640                         }
02641                         $this->tpl->setCurrentBlock("selectall");
02642                         $this->tpl->setVariable("SELECT_ALL", $this->lng->txt("select_all"));
02643                         $this->tpl->setVariable("CSS_ROW", $css_row);
02644                         $this->tpl->parseCurrentBlock();
02645                         // delete button
02646                         $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
02647                         $this->tpl->setCurrentBlock("tbl_action_btn");
02648                         $this->tpl->setVariable("BTN_NAME", "confirmDeleteExportFile");
02649                         $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("delete"));
02650                         $this->tpl->parseCurrentBlock();
02651         
02652                         $this->tpl->setCurrentBlock("tbl_action_btn");
02653                         $this->tpl->setVariable("BTN_NAME", "downloadExportFile");
02654                         $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("download"));
02655                         $this->tpl->parseCurrentBlock();        
02656                 } //if is_array
02657                 else
02658                 {
02659                         $this->tpl->setCurrentBlock("notfound");
02660                         $this->tpl->setVariable("TXT_OBJECT_NOT_FOUND", $this->lng->txt("obj_not_found"));
02661                         $this->tpl->setVariable("NUM_COLS", 3);
02662                         $this->tpl->parseCurrentBlock();
02663                 }
02664 
02665                 $this->tpl->parseCurrentBlock();
02666         }
02667 
02671         function createExportFileObject()
02672         {
02673                 global $rbacsystem;
02674                 
02675                 if ($rbacsystem->checkAccess("write", $this->ref_id))
02676                 {
02677                         include_once("./survey/classes/class.ilSurveyExport.php");
02678                         $survey_exp = new ilSurveyExport($this->object);
02679                         $survey_exp->buildExportFile();
02680                         $this->ctrl->redirect($this, "export");
02681                 }
02682                 else
02683                 {
02684                         sendInfo("cannot_export_survey");
02685                 }
02686         }
02687 
02693         function importObject()
02694         {
02695                 $this->getTemplateFile("import", "svy");
02696                 $this->tpl->setCurrentBlock("option_qpl");
02697                 include_once("./survey/classes/class.ilObjSurvey.php");
02698                 $svy = new ilObjSurvey();
02699                 $questionpools =& $svy->getAvailableQuestionpools(true);
02700                 if (count($questionpools) == 0)
02701                 {
02702                 }
02703                 else
02704                 {
02705                         foreach ($questionpools as $key => $value)
02706                         {
02707                                 $this->tpl->setCurrentBlock("option_spl");
02708                                 $this->tpl->setVariable("OPTION_VALUE", $key);
02709                                 $this->tpl->setVariable("TXT_OPTION", $value);
02710                                 $this->tpl->parseCurrentBlock();
02711                         }
02712                 }
02713                 $this->tpl->setVariable("TXT_SELECT_QUESTIONPOOL", $this->lng->txt("select_questionpool"));
02714                 $this->tpl->setVariable("OPTION_SELECT_QUESTIONPOOL", $this->lng->txt("select_questionpool_option"));
02715                 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
02716 //              $this->tpl->setVariable("FORMACTION", "adm_object.php?&ref_id=".$_GET["ref_id"]."&cmd=gateway&new_type=".$this->type);
02717                 $this->tpl->setVariable("BTN_NAME", "upload");
02718                 $this->tpl->setVariable("TXT_UPLOAD", $this->lng->txt("upload"));
02719                 $this->tpl->setVariable("TXT_IMPORT_TST", $this->lng->txt("import_tst"));
02720                 $this->tpl->setVariable("TXT_SELECT_MODE", $this->lng->txt("select_mode"));
02721                 $this->tpl->setVariable("TXT_SELECT_FILE", $this->lng->txt("select_file"));
02722 
02723         }
02724 
02731         function uploadObject($redirect = true)
02732         {
02733                 if ($_POST["spl"] < 1)
02734                 {
02735                         sendInfo($this->lng->txt("svy_select_questionpools"));
02736                         $this->importObject();
02737                         return;
02738                 }
02739                 if (strcmp($_FILES["xmldoc"]["tmp_name"], "") == 0)
02740                 {
02741                         sendInfo($this->lng->txt("svy_select_file_for_import"));
02742                         $this->importObject();
02743                         return;
02744                 }
02745                 include_once("./survey/classes/class.ilObjSurvey.php");
02746                 $newObj = new ilObjSurvey();
02747                 $newObj->setType($_GET["new_type"]);
02748                 $newObj->setTitle("dummy");
02749                 $newObj->setDescription("dummy");
02750                 $newObj->create(true);
02751                 $newObj->createReference();
02752                 $newObj->putInTree($_GET["ref_id"]);
02753                 $newObj->setPermissions($_GET["ref_id"]);
02754                 $newObj->notify("new",$_GET["ref_id"],$_GET["parent_non_rbac_id"],$_GET["ref_id"],$newObj->getRefId());
02755 
02756                 // copy uploaded file to import directory
02757                 $newObj->importObject($_FILES["xmldoc"], $_POST["spl"]);
02758 
02759                 $newObj->update();
02760                 $newObj->saveToDb();
02761                 if ($redirect)
02762                 {
02763                         include_once "./classes/class.ilUtil.php";
02764                         ilUtil::redirect($this->getReturnLocation("upload",$this->ctrl->getTargetScript()."?".$this->link_params));
02765                 }
02766                 return $newObj->getRefId();
02767         }
02768 
02772         function createObject()
02773         {
02774                 global $rbacsystem;
02775                 $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
02776                 if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], $new_type))
02777                 {
02778                         $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
02779                 }
02780                 else
02781                 {
02782                         $this->getTemplateFile("create", $new_type);
02783 
02784                         include_once("./survey/classes/class.ilObjSurvey.php");
02785                         $svy = new ilObjSurvey();
02786                         
02787                         $surveys =& ilObjSurvey::_getAvailableSurveys(true);
02788                         if (count($surveys) > 0)
02789                         {
02790                                 foreach ($surveys as $key => $value)
02791                                 {
02792                                         $this->tpl->setCurrentBlock("option_svy");
02793                                         $this->tpl->setVariable("OPTION_VALUE_SVY", $key);
02794                                         $this->tpl->setVariable("TXT_OPTION_SVY", $value);
02795                                         if ($_POST["svy"] == $key)
02796                                         {
02797                                                 $this->tpl->setVariable("OPTION_SELECTED_SVY", " selected=\"selected\"");                               
02798                                         }
02799                                         $this->tpl->parseCurrentBlock();
02800                                 }
02801                         }
02802                         
02803                         $questionpools =& $svy->getAvailableQuestionpools($use_obj_id = true, $could_be_offline = true);
02804                         if (count($questionpools) > 0)
02805                         {
02806                                 foreach ($questionpools as $key => $value)
02807                                 {
02808                                         $this->tpl->setCurrentBlock("option_spl");
02809                                         $this->tpl->setVariable("OPTION_VALUE", $key);
02810                                         $this->tpl->setVariable("TXT_OPTION", $value);
02811                                         if ($_POST["spl"] == $key)
02812                                         {
02813                                                 $this->tpl->setVariable("OPTION_SELECTED", " selected=\"selected\"");                           
02814                                         }
02815                                         $this->tpl->parseCurrentBlock();
02816                                 }
02817                         }
02818                         // fill in saved values in case of error
02819                         $data = array();
02820                         $data["fields"] = array();
02821                         include_once "./classes/class.ilUtil.php";
02822                         $data["fields"]["title"] = ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["title"],true);
02823                         $data["fields"]["desc"] = ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["desc"]);
02824 
02825                         foreach ($data["fields"] as $key => $val)
02826                         {
02827                                 $this->tpl->setVariable("TXT_".strtoupper($key), $this->lng->txt($key));
02828                                 $this->tpl->setVariable(strtoupper($key), $val);
02829 
02830                                 if ($this->prepare_output)
02831                                 {
02832                                         $this->tpl->parseCurrentBlock();
02833                                 }
02834                         }
02835 
02836                         $this->ctrl->setParameter($this, "new_type", $this->type);
02837 //                      $this->tpl->setVariable("FORMACTION", $this->getFormAction("save","adm_object.php?cmd=gateway&ref_id=".
02838 //                                                                                                                                         $_GET["ref_id"]."&new_type=".$new_type));
02839                         $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
02840                         $this->tpl->setVariable("TXT_HEADER", $this->lng->txt($new_type."_new"));
02841                         $this->tpl->setVariable("TXT_SELECT_QUESTIONPOOL", $this->lng->txt("select_questionpool_short"));
02842                         $this->tpl->setVariable("OPTION_SELECT_QUESTIONPOOL", $this->lng->txt("select_questionpool_option"));
02843                         $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
02844                         $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt($new_type."_add"));
02845                         $this->tpl->setVariable("CMD_SUBMIT", "save");
02846                         $this->tpl->setVariable("TARGET", ' target="'.
02847                                 ilFrameTargetInfo::_getFrame("MainContent").'" ');
02848                         $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
02849 
02850                         $this->tpl->setVariable("TXT_IMPORT_SVY", $this->lng->txt("import_svy"));
02851                         $this->tpl->setVariable("TXT_SVY_FILE", $this->lng->txt("svy_upload_file"));
02852                         $this->tpl->setVariable("TXT_IMPORT", $this->lng->txt("import"));
02853 
02854                         $this->tpl->setVariable("TXT_DUPLICATE_SVY", $this->lng->txt("duplicate_svy"));
02855                         $this->tpl->setVariable("TXT_SELECT_SVY", $this->lng->txt("obj_svy"));
02856                         $this->tpl->setVariable("OPTION_SELECT_SVY", $this->lng->txt("select_svy_option"));
02857                         $this->tpl->setVariable("TXT_DUPLICATE", $this->lng->txt("duplicate"));
02858                 }
02859         }
02860         
02864         function cloneAllObject()
02865         {
02866                 if ($_POST["svy"] < 1)
02867                 {
02868                         sendInfo($this->lng->txt("svy_select_surveys"));
02869                         $this->createObject();
02870                         return;
02871                 }
02872                 include_once "./survey/classes/class.ilObjSurvey.php";
02873                 include_once "./classes/class.ilUtil.php";
02874                 $ref_id = ilObjSurvey::_clone($_POST["svy"]);
02875                 // always send a message
02876                 sendInfo($this->lng->txt("object_duplicated"),true);
02877 
02878                 ilUtil::redirect("ilias.php?ref_id=".$ref_id.
02879                         "&baseClass=ilObjSurveyGUI");
02880         }
02881         
02885         function importFileObject()
02886         {
02887                 if ($_POST["spl"] < 1)
02888                 {
02889                         sendInfo($this->lng->txt("svy_select_questionpools"));
02890                         $this->createObject();
02891                         return;
02892                 }
02893                 if (strcmp($_FILES["xmldoc"]["tmp_name"], "") == 0)
02894                 {
02895                         sendInfo($this->lng->txt("svy_select_file_for_import"));
02896                         $this->createObject();
02897                         return;
02898                 }
02899                 $this->ctrl->setParameter($this, "new_type", $this->type);
02900                 $ref_id = $this->uploadObject(false);
02901                 // always send a message
02902                 sendInfo($this->lng->txt("object_imported"),true);
02903 
02904                 ilUtil::redirect("ilias.php?ref_id=".$ref_id.
02905                         "&baseClass=ilObjSurveyGUI");
02906 //              $this->ctrl->redirect($this, "importFile");
02907         }
02908 
02912         function downloadExportFileObject()
02913         {
02914                 if(!isset($_POST["file"]))
02915                 {
02916                         sendInfo($this->lng->txt("no_checkbox"), true);
02917                         $this->ctrl->redirect($this, "export");
02918                 }
02919 
02920                 if (count($_POST["file"]) > 1)
02921                 {
02922                         sendInfo($this->lng->txt("select_max_one_item"), true);
02923                         $this->ctrl->redirect($this, "export");
02924                 }
02925 
02926 
02927                 $export_dir = $this->object->getExportDirectory();
02928                 include_once "./classes/class.ilUtil.php";
02929                 ilUtil::deliverFile($export_dir."/".$_POST["file"][0],
02930                         $_POST["file"][0]);
02931         }
02932 
02936         function confirmDeleteExportFileObject()
02937         {
02938                 if(!isset($_POST["file"]))
02939                 {
02940                         sendInfo($this->lng->txt("no_checkbox"), true);
02941                         $this->ctrl->redirect($this, "export");
02942                 }
02943 
02944                 //$this->setTabs();
02945 
02946                 // SAVE POST VALUES
02947                 $_SESSION["ilExportFiles"] = $_POST["file"];
02948 
02949                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.confirm_deletion.html", true);
02950 
02951                 sendInfo($this->lng->txt("info_delete_sure"));
02952 
02953                 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
02954 
02955                 // BEGIN TABLE HEADER
02956                 $this->tpl->setCurrentBlock("table_header");
02957                 $this->tpl->setVariable("TEXT",$this->lng->txt("objects"));
02958                 $this->tpl->parseCurrentBlock();
02959 
02960                 // BEGIN TABLE DATA
02961                 $counter = 0;
02962                 include_once "./classes/class.ilUtil.php";
02963                 foreach($_POST["file"] as $file)
02964                 {
02965                                 $this->tpl->setCurrentBlock("table_row");
02966                                 $this->tpl->setVariable("IMG_OBJ", ilUtil::getImagePath("icon_file.gif"));
02967                                 $this->tpl->setVariable("TEXT_IMG_OBJ", $this->lng->txt("file_icon"));
02968                                 $this->tpl->setVariable("CSS_ROW",ilUtil::switchColor(++$counter,"tblrow1","tblrow2"));
02969                                 $this->tpl->setVariable("TEXT_CONTENT", $file);
02970                                 $this->tpl->parseCurrentBlock();
02971                 }
02972 
02973                 // cancel/confirm button
02974                 $this->tpl->setVariable("IMG_ARROW",ilUtil::getImagePath("arrow_downright.gif"));
02975                 $buttons = array( "cancelDeleteExportFile"  => $this->lng->txt("cancel"),
02976                         "deleteExportFile"  => $this->lng->txt("confirm"));
02977                 foreach ($buttons as $name => $value)
02978                 {
02979                         $this->tpl->setCurrentBlock("operation_btn");
02980                         $this->tpl->setVariable("BTN_NAME",$name);
02981                         $this->tpl->setVariable("BTN_VALUE",$value);
02982                         $this->tpl->parseCurrentBlock();
02983                 }
02984         }
02985 
02986 
02990         function cancelDeleteExportFileObject()
02991         {
02992                 session_unregister("ilExportFiles");
02993                 $this->ctrl->redirect($this, "export");
02994         }
02995 
02996 
03000         function deleteExportFileObject()
03001         {
03002                 $export_dir = $this->object->getExportDirectory();
03003                 foreach($_SESSION["ilExportFiles"] as $file)
03004                 {
03005                         $exp_file = $export_dir."/".$file;
03006                         $exp_dir = $export_dir."/".substr($file, 0, strlen($file) - 4);
03007                         if (@is_file($exp_file))
03008                         {
03009                                 unlink($exp_file);
03010                         }
03011                         if (@is_dir($exp_dir))
03012                         {
03013                                 include_once "./classes/class.ilUtil.php";
03014                                 ilUtil::delDir($exp_dir);
03015                         }
03016                 }
03017                 $this->ctrl->redirect($this, "export");
03018         }
03019 
03027         function codesObject()
03028         {
03029                 global $rbacsystem;
03030                 global $ilUser;
03031                 
03032                 $default_lang = $ilUser->getPref("survey_code_language");
03033                 
03034                 if ((!$rbacsystem->checkAccess("read", $this->ref_id)) && (!$rbacsystem->checkAccess("write", $this->ref_id))) 
03035                 {
03036                         // allow only read and write access
03037                         sendInfo($this->lng->txt("cannot_edit_survey"), true);
03038                         $path = $this->tree->getPathFull($this->object->getRefID());
03039                         include_once "./classes/class.ilUtil.php";
03040                         ilUtil::redirect($this->getReturnLocation("cancel","./repository.php?ref_id=" . $path[count($path) - 2]["child"]));
03041                         return;
03042                 }
03043                 
03044                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_codes.html", true);
03045                 if ($rbacsystem->checkAccess("write", $this->ref_id))
03046                 {
03047                         $codecount = $this->object->getSurveyCodesCount();
03048                         if ($codecount)
03049                         {
03050                                 $maxentries = $ilUser->getPref("hits_per_page");
03051                                 if ($maxentries < 1)
03052                                 {
03053                                         $maxentries = 9999;
03054                                 }
03055         
03056                                 $survey_codes =& $this->object->getSurveyCodesTableData($default_lang, $_GET["offset"], $maxentries, $_GET["sort_by"], $_GET["sort_order"]);
03057                                 $headervars = array("", "counter", "date", "used", "url");
03058         
03059                                 include_once "./classes/class.ilTableGUI.php";
03060                                 $tbl = new ilTableGUI(0, FALSE);
03061                                 $tbl->setTitle($this->lng->txt("survey_code"));
03062                                 $header_names = array(
03063                                         "",
03064                                         $this->lng->txt("survey_code"),
03065                                         $this->lng->txt("create_date"),
03066                                         $this->lng->txt("survey_code_used"),
03067                                         $this->lng->txt("survey_code_url")
03068                                 );
03069                                 $tbl->setHeaderNames($header_names);
03070         
03071                                 $tbl->disable("sort");
03072                                 $tbl->disable("auto_sort");
03073                                 $tbl->disable("title");
03074                                 $tbl->setLimit($maxentries);
03075                                 $tbl->setOffset($_GET["offset"]);
03076                                 $tbl->setData($survey_codes);
03077                                 $tbl->setMaxCount($codecount);
03078                                 $tbl->setOrderDirection($_GET["sort_order"]);
03079         
03080                                 $header_params = $this->ctrl->getParameterArray($this, "codes");
03081                                 $tbl->setHeaderVars($headervars, $header_params);
03082                                 
03083                                 // footer
03084                                 $tbl->setFooter("tblfooter", $this->lng->txt("previous"), $this->lng->txt("next"));
03085                                 // render table
03086                                 $tableoutput = $tbl->render();
03087                                 $this->tpl->setVariable("CODES_TABLE", $tableoutput);
03088                         }
03089                         else
03090                         {
03091                                 $this->tpl->setCurrentBlock("emptyrow");
03092                                 $this->tpl->setVariable("NO_CODES", $this->lng->txt("survey_code_no_codes"));
03093                                 $this->tpl->parseCurrentBlock();
03094                         }
03095                         
03096                         $languages = $this->lng->getInstalledLanguages();
03097                         foreach ($languages as $lang)
03098                         {
03099                                 $this->tpl->setCurrentBlock("option_lang");
03100                                 $this->tpl->setVariable("VALUE_LANG", $lang);
03101                                 $this->tpl->setVariable("TEXT_LANG", $this->lng->txt("lang_$lang"));
03102                                 if (strcmp($lang, $default_lang) == 0)
03103                                 {
03104                                         $this->tpl->setVariable("SELECTED_LANG", " selected=\"selected\"");
03105                                 }
03106                                 $this->tpl->parseCurrentBlock();
03107                         }
03108                         
03109                         $this->tpl->setCurrentBlock("adm_content");
03110                         $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
03111                         $this->tpl->setVariable("TEXT_CREATE", $this->lng->txt("create"));
03112                         $this->tpl->setVariable("TEXT_SURVEY_CODES", $this->lng->txt("new_survey_codes"));
03113                         $this->tpl->setVariable("TEXT_SURVEY_CODES_LANG", $this->lng->txt("survey_codes_lang"));
03114                         $this->tpl->setVariable("TEXT_NO_LANGUAGE_SELECTED", $this->lng->txt("please_select"));
03115                         $this->tpl->setVariable("VALUE_ACTIVATE", $this->lng->txt("select"));
03116                         $this->tpl->parseCurrentBlock();
03117                 }
03118                 else
03119                 {
03120                         sendInfo($this->lng->txt("cannot_create_survey_codes"));
03121                 }
03122         }
03123 
03131         function codesObject2()
03132         {
03133                 global $rbacsystem;
03134 
03135                 if ((!$rbacsystem->checkAccess("read", $this->ref_id)) && (!$rbacsystem->checkAccess("write", $this->ref_id))) 
03136                 {
03137                         // allow only read and write access
03138                         sendInfo($this->lng->txt("cannot_edit_survey"), true);
03139                         $path = $this->tree->getPathFull($this->object->getRefID());
03140                         include_once "./classes/class.ilUtil.php";
03141                         ilUtil::redirect($this->getReturnLocation("cancel","./repository.php?ref_id=" . $path[count($path) - 2]["child"]));
03142                         return;
03143                 }
03144                 
03145                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_codes.html", true);
03146                 if ($rbacsystem->checkAccess("write", $this->ref_id))
03147                 {
03148                         $color_class = array("tblrow1", "tblrow2");
03149                         $survey_codes =& $this->object->getSurveyCodes();
03150                         if (count($survey_codes) == 0)
03151                         {
03152                                 $this->tpl->setCurrentBlock("emptyrow");
03153                                 $this->tpl->setVariable("COLOR_CLASS", "tblrow1");
03154                                 $this->tpl->setVariable("NO_CODES", $this->lng->txt("survey_code_no_codes"));
03155                                 $this->tpl->parseCurrentBlock();
03156                         }
03157                         else
03158                         {
03159                                 $counter = 1;
03160                                 foreach ($survey_codes as $key => $row)
03161                                 {
03162                                         $this->tpl->setCurrentBlock("coderow");
03163                                         $this->tpl->setVariable("COLOR_CLASS", $color_class[$key % 2]);
03164                                         $this->tpl->setVariable("CODE_SEQUENCE", $counter);
03165                                         $this->tpl->setVariable("SURVEY_CODE", $row["survey_key"]);
03166                                         include_once "./classes/class.ilFormat.php";
03167                                         $this->tpl->setVariable("CODE_CREATED", ilFormat::formatDate(ilFormat::ftimestamp2dateDB($row["TIMESTAMP14"]), "date"));
03168                                         $state = "<span class=\"smallred\">" . $this->lng->txt("not_used") . "</span>";
03169                                         if ($this->object->isSurveyCodeUsed($row["survey_key"]))
03170                                         {
03171                                                 $state = "<span class=\"smallgreen\">" . $this->lng->txt("used") . "</span>";
03172                                         }
03173                                         else
03174                                         {
03175                                                 $this->tpl->setVariable("CODE_URL_NAME", $this->lng->txt("survey_code_url_name"));
03176                                                 $this->tpl->setVariable("CODE_URL", ILIAS_HTTP_PATH."/goto.php?cmd=run&target=svy_".$this->object->getRefId() . "&client_id=" . CLIENT_ID . "&accesscode=".$row["survey_key"]);
03177                                         }
03178                                         $this->tpl->setVariable("CODE_USED", $state);
03179                                         $this->tpl->parseCurrentBlock();
03180                                         $counter++;
03181                                 }
03182                         }
03183                         $this->tpl->setCurrentBlock("adm_content");
03184                         $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
03185                         $this->tpl->setVariable("SURVEY_CODE", $this->lng->txt("survey_code"));
03186                         $this->tpl->setVariable("CODE_CREATED", $this->lng->txt("create_date"));
03187                         $this->tpl->setVariable("CODE_USED", $this->lng->txt("survey_code_used"));
03188                         $this->tpl->setVariable("CODE_URL", $this->lng->txt("survey_code_url"));
03189                         $this->tpl->setVariable("TEXT_CREATE", $this->lng->txt("create"));
03190                         $this->tpl->setVariable("TEXT_SURVEY_CODES", $this->lng->txt("new_survey_codes"));
03191                         $this->tpl->parseCurrentBlock();
03192                 }
03193                 else
03194                 {
03195                         sendInfo($this->lng->txt("cannot_create_survey_codes"));
03196                 }
03197         }
03198         
03206         function createSurveyCodesObject()
03207         {
03208                 if (preg_match("/\d+/", $_POST["nrOfCodes"]))
03209                 {
03210                         $this->object->createSurveyCodes($_POST["nrOfCodes"]);
03211                 }
03212                 else
03213                 {
03214                         sendInfo($this->lng->txt("enter_valid_number_of_codes"), true);
03215                 }
03216                 $this->ctrl->redirect($this, "codes");
03217         }
03218 
03226         function addConstraintForm($step, &$survey_questions, $questions = false)
03227         {
03228                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_add_constraint.html", true);
03229                 if (is_array($questions))
03230                 {
03231                         foreach ($questions as $question)
03232                         {
03233                                 $this->tpl->setCurrentBlock("option_q");
03234                                 $this->tpl->setVariable("OPTION_VALUE", $question["question_id"]);
03235                                 $this->tpl->setVariable("OPTION_TEXT", $question["title"] . " (" . $this->lng->txt($question["type_tag"]) . ")");
03236                                 if ($question["question_id"] == $_POST["q"])
03237                                 {
03238                                         $this->tpl->setVariable("OPTION_CHECKED", " selected=\"selected\"");
03239                                 }
03240                                 $this->tpl->parseCurrentBlock();
03241                         }
03242                 }
03243                 
03244                 if ($step > 1)
03245                 {
03246                         $relations = $this->object->getAllRelations();
03247                         switch ($survey_questions[$_POST["q"]]["type_tag"])
03248                         {
03249                                 case "qt_nominal":
03250                                         foreach ($relations as $rel_id => $relation)
03251                                         {
03252                                                 if ((strcmp($relation["short"], "=") == 0) or (strcmp($relation["short"], "<>") == 0))
03253                                                 {
03254                                                         $this->tpl->setCurrentBlock("option_r");
03255                                                         $this->tpl->setVariable("OPTION_VALUE", $rel_id);
03256                                                         $this->tpl->setVariable("OPTION_TEXT", $relation["short"]);
03257                                                         if ($rel_id == $_POST["r"])
03258                                                         {
03259                                                                 $this->tpl->setVariable("OPTION_CHECKED", " selected=\"selected\"");
03260                                                         }
03261                                                         $this->tpl->parseCurrentBlock();
03262                                                 }
03263                                         }
03264                                         break;
03265                                 case "qt_ordinal":
03266                                 case "qt_metric":
03267                                         foreach ($relations as $rel_id => $relation)
03268                                         {
03269                                                 $this->tpl->setCurrentBlock("option_r");
03270                                                 $this->tpl->setVariable("OPTION_VALUE", $rel_id);
03271                                                 $this->tpl->setVariable("OPTION_TEXT", $relation["short"]);
03272                                                 if ($rel_id == $_POST["r"])
03273                                                 {
03274                                                         $this->tpl->setVariable("OPTION_CHECKED", " selected=\"selected\"");
03275                                                 }
03276                                                 $this->tpl->parseCurrentBlock();
03277                                         }
03278                                         break;
03279                         }
03280                         $this->tpl->setCurrentBlock("select_relation");
03281                         $this->tpl->setVariable("SELECT_RELATION", $this->lng->txt("step") . " 2: " . $this->lng->txt("select_relation"));
03282                         $this->tpl->parseCurrentBlock();
03283                 }
03284                 
03285                 if ($step > 2)
03286                 {
03287                         $variables =& $this->object->getVariables($_POST["q"]);
03288                         switch ($survey_questions[$_POST["q"]]["type_tag"])
03289                         {
03290                                 case "qt_nominal":
03291                                 case "qt_ordinal":
03292                                         foreach ($variables as $sequence => $row)
03293                                         {
03294                                                 $this->tpl->setCurrentBlock("option_v");
03295                                                 $this->tpl->setVariable("OPTION_VALUE", $sequence);
03296                                                 $this->tpl->setVariable("OPTION_TEXT", ($sequence+1) . " - " . $row->title);
03297                                                 $this->tpl->parseCurrentBlock();
03298                                         }
03299                                         break;
03300                                 case "qt_metric":
03301                                                 $this->tpl->setCurrentBlock("textfield");
03302                                                 $this->tpl->setVariable("TEXTFIELD_VALUE", "");
03303                                                 $this->tpl->parseCurrentBlock();
03304                                         break;
03305                         }
03306                         $this->tpl->setCurrentBlock("select_value");
03307                         if (strcmp($survey_questions[$_POST["q"]]["type_tag"], "qt_metric") == 0)
03308                         {
03309                                 $this->tpl->setVariable("SELECT_VALUE", $this->lng->txt("step") . " 3: " . $this->lng->txt("enter_value"));
03310                         }
03311                         else
03312                         {
03313                                 $this->tpl->setVariable("SELECT_VALUE", $this->lng->txt("step") . " 3: " . $this->lng->txt("select_value"));
03314                         }
03315                         $this->tpl->parseCurrentBlock();
03316                 }
03317                 
03318                 $this->tpl->setCurrentBlock("buttons");
03319                 $this->tpl->setVariable("BTN_CONTINUE", $this->lng->txt("continue"));
03320                 switch ($step)
03321                 {
03322                         case 1:
03323                                 $this->tpl->setVariable("COMMAND", "constraintStep2");
03324                                 $this->tpl->setVariable("COMMAND_BACK", "constraints");
03325                                 break;
03326                         case 2:
03327                                 $this->tpl->setVariable("COMMAND", "constraintStep3");
03328                                 $this->tpl->setVariable("COMMAND_BACK", "constraintStep1");
03329                                 break;
03330                         case 3:
03331                                 $this->tpl->setVariable("COMMAND", "constraintsAdd");
03332                                 $this->tpl->setVariable("COMMAND_BACK", "constraintStep2");
03333                                 break;
03334                 }
03335                 $this->tpl->setVariable("BTN_BACK", $this->lng->txt("back"));
03336                 $this->tpl->parseCurrentBlock();
03337                 $this->tpl->setCurrentBlock("adm_content");
03338                 $title = "";
03339                 if ($survey_questions[$_SESSION["constraintstructure"][$_GET["start"]][0]]["questionblock_id"] > 0)
03340                 {
03341                         $title = $this->lng->txt("questionblock") . ": " . $survey_questions[$_SESSION["constraintstructure"][$_GET["start"]][0]]["questionblock_title"];
03342                 }
03343                 else
03344                 {
03345                         $title = $this->lng->txt($survey_questions[$_SESSION["constraintstructure"][$_GET["start"]][0]]["type_tag"]) . ": " . $survey_questions[$_SESSION["constraintstructure"][$_GET["start"]][0]]["title"];
03346                 }
03347                 $this->tpl->setVariable("CONSTRAINT_QUESTION_TEXT", $title);
03348                 $this->tpl->setVariable("SELECT_PRIOR_QUESTION", $this->lng->txt("step") . " 1: " . $this->lng->txt("select_prior_question"));
03349                 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this) . "&start=" . $_GET["start"]);
03350                 $this->tpl->parseCurrentBlock();
03351         }
03352         
03360         function constraintsAddObject()
03361         {
03362                 $survey_questions =& $this->object->getSurveyQuestions();
03363                 $structure =& $_SESSION["constraintstructure"];
03364                 $include_elements = $_SESSION["includeElements"];
03365                 foreach ($include_elements as $elementCounter)
03366                 {
03367                         if (is_array($structure[$elementCounter]))
03368                         {
03369                                 foreach ($structure[$elementCounter] as $key => $question_id)
03370                                 {
03371                                         $this->object->addConstraint($question_id, $_POST["q"], $_POST["r"], $_POST["v"]);
03372                                 }
03373                         }
03374                 }
03375                 unset($_SESSION["includeElements"]);
03376                 unset($_SESSION["constraintstructure"]);
03377                 $this->ctrl->redirect($this, "constraints");
03378         }
03379 
03387         function constraintStep3Object()
03388         {
03389                 $survey_questions =& $this->object->getSurveyQuestions();
03390                 $option_questions = array();
03391                 array_push($option_questions, array("question_id" => $_POST["q"], "title" => $survey_questions[$_POST["q"]]["title"], "type_tag" => $survey_questions[$_POST["q"]]["type_tag"]));
03392                 $this->addConstraintForm(3, $survey_questions, $option_questions);
03393         }
03394         
03402         function constraintStep2Object()
03403         {
03404                 $survey_questions =& $this->object->getSurveyQuestions();
03405                 $option_questions = array();
03406                 array_push($option_questions, array("question_id" => $_POST["q"], "title" => $survey_questions[$_POST["q"]]["title"], "type_tag" => $survey_questions[$_POST["q"]]["type_tag"]));
03407                 $this->addConstraintForm(2, $survey_questions, $option_questions);
03408         }
03409         
03417         function constraintStep1Object()
03418         {
03419                 $survey_questions =& $this->object->getSurveyQuestions();
03420                 $structure =& $_SESSION["constraintstructure"];
03421                 $start = $_GET["start"];
03422                 $option_questions = array();
03423                 for ($i = 1; $i < $start; $i++)
03424                 {
03425                         if (is_array($structure[$i]))
03426                         {
03427                                 foreach ($structure[$i] as $key => $question_id)
03428                                 {
03429                                         if (strcmp($survey_questions[$question_id]["type_tag"], "qt_text") != 0)
03430                                         {
03431                                                 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"]));
03432                                         }
03433                                 }
03434                         }
03435                 }
03436                 if (count($option_questions) == 0)
03437                 {
03438                         unset($_SESSION["includeElements"]);
03439                         unset($_SESSION["constraintstructure"]);
03440                         sendInfo($this->lng->txt("constraints_no_nonessay_available"), true);
03441                         $this->ctrl->redirect($this, "constraints");
03442                 }
03443                 $this->addConstraintForm(1, $survey_questions, $option_questions);
03444         }
03445         
03453         function deleteConstraintsObject()
03454         {
03455                 $survey_questions =& $this->object->getSurveyQuestions();
03456                 $structure =& $_SESSION["constraintstructure"];
03457                 foreach ($_POST as $key => $value)
03458                 {
03459                         if (preg_match("/^constraint_(\d+)_(\d+)/", $key, $matches)) 
03460                         {
03461                                 foreach ($structure[$matches[1]] as $key => $question_id)
03462                                 {
03463                                         $this->object->deleteConstraint($matches[2], $question_id);
03464                                 }
03465                         }
03466                 }
03467 
03468                 $this->ctrl->redirect($this, "constraints");
03469         }
03470         
03471         function createConstraintsObject()
03472         {
03473                 $include_elements = $_POST["includeElements"];
03474                 if ((!is_array($include_elements)) || (count($include_elements) == 0))
03475                 {
03476                         sendInfo($this->lng->txt("constraints_no_questions_or_questionblocks_selected"), true);
03477                         $this->ctrl->redirect($this, "constraints");
03478                 }
03479                 else if (count($include_elements) >= 1)
03480                 {
03481                         $_SESSION["includeElements"] = $include_elements;
03482                         sort($include_elements, SORT_NUMERIC);
03483                         $_GET["start"] = $include_elements[0];
03484                         $this->constraintStep1Object();
03485                 }
03486         }
03487         
03495         function constraintsObject()
03496         {
03497                 global $rbacsystem;
03498                 
03499                 $hasDatasets = $this->object->_hasDatasets($this->object->getSurveyId());
03500                 $step = 0;
03501                 if (array_key_exists("step", $_GET))    $step = $_GET["step"];
03502                 switch ($step)
03503                 {
03504                         case 1:
03505                                 $this->constraintStep1Object();
03506                                 return;
03507                                 break;
03508                         case 2:
03509                                 return;
03510                                 break;
03511                         case 3:
03512                                 return;
03513                                 break;
03514                 }
03515                 
03516                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_svy_constraints_list.html", true);
03517                 $survey_questions =& $this->object->getSurveyQuestions();
03518                 $last_questionblock_title = "";
03519                 $counter = 1;
03520                 $structure = array();
03521                 $colors = array("tblrow1", "tblrow2");
03522                 foreach ($survey_questions as $question_id => $data)
03523                 {
03524                         $title = $data["title"];
03525                         $show = true;
03526                         if ($data["questionblock_id"] > 0)
03527                         {
03528                                 $title = $data["questionblock_title"];
03529                                 $type = $this->lng->txt("questionblock");
03530                                 if (strcmp($title, $last_questionblock_title) != 0) 
03531                                 {
03532                                         $last_questionblock_title = $title;
03533                                         $structure[$counter] = array();
03534                                         array_push($structure[$counter], $data["question_id"]);
03535                                 }
03536                                 else
03537                                 {
03538                                         array_push($structure[$counter-1], $data["question_id"]);
03539                                         $show = false;
03540                                 }
03541                         }
03542                         else
03543                         {
03544                                 $structure[$counter] = array($data["question_id"]);
03545                                 $type = $this->lng->txt("question");
03546                         }
03547                         if ($show)
03548                         {
03549                                 if ($counter == 1)
03550                                 {
03551                                         $this->tpl->setCurrentBlock("description");
03552                                         $this->tpl->setVariable("DESCRIPTION", $this->lng->txt("constraints_first_question_description"));
03553                                         $this->tpl->parseCurrentBlock();
03554                                 }
03555                                 else
03556                                 {
03557                                         $constraints =& $this->object->getConstraints($data["question_id"]);
03558                                         $rowcount = 0;
03559                                         if (count($constraints))
03560                                         {
03561                                                 foreach ($constraints as $constraint)
03562                                                 {
03563                                                         $value = "";
03564                                                         $variables =& $this->object->getVariables($constraint["question"]);
03565                                                         switch ($survey_questions[$constraint["question"]]["type_tag"])
03566                                                         {
03567                                                                 case "qt_metric":
03568                                                                         $value = $constraint["value"];
03569                                                                         break;
03570                                                                 case "qt_nominal":
03571                                                                 case "qt_ordinal":
03572                                                                         $value = sprintf("%d", $constraint["value"]+1) . " - " . $variables[$constraint["value"]]->title;
03573                                                                         break;
03574                                                         }
03575                                                         $this->tpl->setCurrentBlock("constraint");
03576                                                         $this->tpl->setVariable("CONSTRAINT_TEXT", $survey_questions[$constraint["question"]]["title"] . " " . $constraint["short"] . " $value");
03577                                                         $this->tpl->setVariable("SEQUENCE_ID", $counter);
03578                                                         $this->tpl->setVariable("CONSTRAINT_ID", $constraint["id"]);
03579                                                         $this->tpl->setVariable("COLOR_CLASS", $colors[$rowcount % 2]);
03580                                                         $rowcount++;
03581                                                         $this->tpl->parseCurrentBlock();
03582                                                 }
03583                                                 if ($rbacsystem->checkAccess("write", $this->ref_id) and $this->object->isOffline() and !$hasDatasets)
03584                                                 {
03585                                                         $this->tpl->setCurrentBlock("delete_button");
03586                                                         $this->tpl->setVariable("BTN_DELETE", $this->lng->txt("delete"));
03587                                                         include_once "./classes/class.ilUtil.php";
03588                                                         $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\">");
03589                                                         $this->tpl->parseCurrentBlock();
03590                                                 }
03591                                         }
03592                                         else
03593                                         {
03594                                                 $this->tpl->setCurrentBlock("empty_row");
03595                                                 $this->tpl->setVariable("EMPTY_TEXT", $this->lng->txt("no_available_constraints"));
03596                                                 $this->tpl->setVariable("COLOR_CLASS", $colors[$rowcount % 2]);
03597                                                 $this->tpl->parseCurrentBlock();
03598                                         }
03599                                         $this->tpl->setCurrentBlock("question");
03600                                         $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
03601                                         $this->tpl->setVariable("DEFINED_PRECONDITIONS", $this->lng->txt("existing_constraints"));
03602                                         $this->tpl->parseCurrentBlock();
03603                                 }
03604                                 if ($counter != 1)
03605                                 {
03606                                         $this->tpl->setCurrentBlock("include_elements");
03607                                         $this->tpl->setVariable("QUESTION_NR", "$counter");
03608                                         $this->tpl->parseCurrentBlock();
03609                                 }
03610                                 $this->tpl->setCurrentBlock("constraint_section");
03611                                 $this->tpl->setVariable("QUESTION_NR", "$counter");
03612                                 $this->tpl->setVariable("TITLE", "$title");
03613                                 $icontype = "question.gif";
03614                                 if ($data["questionblock_id"] > 0)
03615                                 {
03616                                         $icontype = "questionblock.gif";
03617                                         $this->tpl->setVariable("TYPE", "$type: ");
03618                                 }
03619                                 include_once "./classes/class.ilUtil.php";
03620                                 $this->tpl->setVariable("ICON_HREF", ilUtil::getImagePath($icontype, true));
03621                                 $this->tpl->setVariable("ICON_ALT", $type);
03622                                 $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
03623                                 $this->tpl->parseCurrentBlock();
03624                                 $counter++;
03625                         }
03626                 }
03627                 if ($rbacsystem->checkAccess("write", $this->ref_id) and $this->object->isOffline() and !$hasDatasets)
03628                 {
03629                         $this->tpl->setCurrentBlock("selectall");
03630                         $this->tpl->setVariable("SELECT_ALL", $this->lng->txt("select_all"));
03631                         $counter++;
03632                         $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
03633                         $this->tpl->parseCurrentBlock();
03634 
03635                         $this->tpl->setCurrentBlock("buttons");
03636                         $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"".$this->lng->txt("arrow_downright")."\">");
03637                         $this->tpl->setVariable("BTN_CREATE_CONSTRAINTS", $this->lng->txt("constraint_add"));
03638                         $this->tpl->parseCurrentBlock();
03639                 }
03640                 $this->tpl->setCurrentBlock("adm_content");
03641                 $this->tpl->setVariable("CONSTRAINTS_INTRODUCTION", $this->lng->txt("constraints_introduction"));
03642                 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
03643                 $this->tpl->setVariable("CONSTRAINTS_HEADER", $this->lng->txt("constraints_list_of_entities"));
03644                 $this->tpl->parseCurrentBlock();
03645                 $_SESSION["constraintstructure"] = $structure;
03646                 if ($this->object->isOnline())
03647                 {
03648                         sendInfo($this->lng->txt("survey_online_warning"));
03649                 }
03650                 else if ($hasDatasets)
03651                 {
03652                         sendInfo($this->lng->txt("survey_has_datasets_warning"));
03653                 }
03654         }
03655 
03656         function setCodeLanguageObject()
03657         {
03658                 if (strcmp($_POST["lang"], "-1") != 0)
03659                 {
03660                         global $ilUser;
03661                         $ilUser->writePref("survey_code_language", $_POST["lang"]);
03662                 }
03663                 $this->ctrl->redirect($this, "codes");
03664         }
03665         
03666         function addLocatorItems()
03667         {
03668                 global $ilLocator;
03669                 switch ($this->ctrl->getCmd())
03670                 {
03671                         case "run":
03672                         case "start":
03673                         case "resume":
03674                         case "next":
03675                         case "previous":
03676                                 $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTargetByClass("ilsurveyexecutiongui", "run"));
03677                                 break;
03678                         case "evaluation":
03679                         case "checkEvaluationAccess":
03680                         case "evaluationdetails":
03681                         case "evaluationuser":
03682                                 $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "evaluation"));
03683                                 break;
03684                         case "create":
03685                         case "save":
03686                         case "cancel":
03687                         case "importFile":
03688                         case "cloneAll":
03689                                 break;
03690                 default:
03691                                 $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, ""));
03692                                 break;
03693                 }
03694         }
03695         
03701         function getTabs(&$tabs_gui)
03702         {
03703                 global $rbacsystem;
03704 
03705                 switch ($this->ctrl->getCmd())
03706                 {
03707                         case "run":
03708                         case "start":
03709                         case "resume":
03710                         case "next":
03711                         case "previous":
03712 
03713                         case "evaluation":
03714                         case "checkEvaluationAccess":
03715                         case "evaluationdetails":
03716                         case "evaluationuser":
03717                                 return;
03718                                 break;
03719                 }
03720                 
03721                 if ($rbacsystem->checkAccess("write", $this->ref_id))
03722                 {
03723                         // properties
03724                         $force_active = ($this->ctrl->getCmd() == "")
03725                                 ? true
03726                                 : false;
03727                         $tabs_gui->addTarget("properties",
03728                                  $this->ctrl->getLinkTarget($this,'properties'),
03729                                  array("properties", "save", "cancel"), "",
03730                                  "", $force_active);
03731         
03732                         // questions
03733                         $force_active = ($_GET["up"] != "" || $_GET["down"] != "")
03734                                 ? true
03735                                 : false;
03736         
03737                         $tabs_gui->addTarget("survey_questions",
03738                                  $this->ctrl->getLinkTarget($this,'questions'),
03739                                  array("questions", "browseForQuestions", "searchQuestions", "createQuestion",
03740                                  "searchQuestionsExecute",
03741                                  "filterQuestions", "resetFilterQuestions", "changeDatatype", "insertQuestions",
03742                                  "removeQuestions", "cancelRemoveQuestions", "confirmRemoveQuestions",
03743                                  "defineQuestionblock", "saveDefineQuestionblock", "cancelDefineQuestionblock",
03744                                  "unfoldQuestionblock", "moveQuestions",
03745                                  "insertQuestionsBefore", "insertQuestionsAfter", "saveObligatory",
03746                                  "addHeading", "saveHeading", "cancelHeading", "editHeading",
03747                                  "confirmRemoveHeading", "cancelRemoveHeading"),
03748                                  "", "", $force_active);
03749                                  
03750                         // constraints
03751                         $tabs_gui->addTarget("constraints",
03752                                  $this->ctrl->getLinkTarget($this, "constraints"),
03753                                  array("constraints", "constraintStep1", "constraintStep2",
03754                                  "constraintStep3", "constraintsAdd", "createConstraints"),
03755                                  "");
03756                 }
03757                 if (($rbacsystem->checkAccess("write", $this->ref_id)) || ($rbacsystem->checkAccess("invite", $this->ref_id)))
03758                 {
03759                         // invite
03760                         $tabs_gui->addTarget("invite_participants",
03761                                  $this->ctrl->getLinkTarget($this, "invite"),
03762                                  array("invite", "saveInvitationStatus",
03763                                  "cancelInvitationStatus", "searchInvitation", "inviteUserGroup",
03764                                  "disinviteUserGroup"),
03765                                  "");
03766                 }
03767                 if ($rbacsystem->checkAccess("write", $this->ref_id))
03768                 {
03769                         // export
03770                         $tabs_gui->addTarget("export",
03771                                  $this->ctrl->getLinkTarget($this,'export'),
03772                                  array("export", "createExportFile", "confirmDeleteExportFile",
03773                                  "downloadExportFile"), 
03774                                  ""
03775                                 );
03776         
03777                         // maintenance
03778                         $tabs_gui->addTarget("maintenance",
03779                                  $this->ctrl->getLinkTarget($this,'maintenance'),
03780                                  array("maintenance", "deleteAllUserData"),
03781                                  "");
03782         
03783                         // status
03784                         $tabs_gui->addTarget("status",
03785                                  $this->ctrl->getLinkTarget($this,'status'),
03786                                  array("status"),
03787                                  "");
03788                                 
03789                         // code
03790                         $tabs_gui->addTarget("codes",
03791                                  $this->ctrl->getLinkTarget($this,'codes'),
03792                                  array("codes", "createSurveyCodes", "setCodeLanguage"),
03793                                  "");
03794         
03795                         // permissions
03796                         $tabs_gui->addTarget("perm_settings",
03797                                 $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm"), array("perm","info","owner"), 'ilpermissiongui');
03798                                  
03799                         // meta data
03800                         $tabs_gui->addTarget("meta_data",
03801                                  $this->ctrl->getLinkTargetByClass('ilmdeditorgui','listSection'),
03802                                  "", "ilmdeditorgui");
03803                 }
03804         }
03805         
03806 } // END class.ilObjSurveyGUI
03807 ?>

Generated on Fri Dec 13 2013 11:58:01 for ILIAS Release_3_6_x_branch .rev 46809 by  doxygen 1.7.1