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

survey/classes/class.SurveyQuestionGUI.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 require_once "./survey/classes/class.SurveyNominalQuestionGUI.php";
00025 require_once "./survey/classes/class.SurveyTextQuestionGUI.php";
00026 require_once "./survey/classes/class.SurveyMetricQuestionGUI.php";
00027 require_once "./survey/classes/class.SurveyOrdinalQuestionGUI.php";
00028 
00040 class SurveyQuestionGUI {
00048   var $object;
00049         var $tpl;
00050         var $lng;
00062   function SurveyQuestionGUI()
00063 
00064   {
00065                 global $lng, $tpl, $ilCtrl;
00066 
00067     $this->lng =& $lng;
00068     $this->tpl =& $tpl;
00069                 $this->ctrl =& $ilCtrl;
00070                 $this->ctrl->saveParameter($this, "q_id");
00071         }
00072 
00076         function &executeCommand()
00077         {
00078                 $cmd = $this->ctrl->getCmd();
00079                 $next_class = $this->ctrl->getNextClass($this);
00080 
00081                 $cmd = $this->getCommand($cmd);
00082                 switch($next_class)
00083                 {
00084                         default:
00085                                 $ret =& $this->$cmd();
00086                                 break;
00087                 }
00088                 return $ret;
00089         }
00090 
00091         function getCommand($cmd)
00092         {
00093                 return $cmd;
00094         }
00095 
00107         function &_getQuestionGUI($questiontype, $question_id = -1)
00108         {
00109                 if (!$questiontype)
00110                 {
00111                         $questiontype = SurveyQuestion::_getQuestiontype($question_id);
00112                 }
00113                 switch ($questiontype)
00114                 {
00115                         case "qt_nominal":
00116                                 $question = new SurveyNominalQuestionGUI();
00117                                 break;
00118                         case "qt_ordinal":
00119                                 $question = new SurveyOrdinalQuestionGUI();
00120                                 break;
00121                         case "qt_metric":
00122                                 $question = new SurveyMetricQuestionGUI();
00123                                 break;
00124                         case "qt_text":
00125                                 $question = new SurveyTextQuestionGUI();
00126                                 break;
00127                 }
00128                 if ($question_id > 0)
00129                 {
00130                         $question->object->loadFromDb($question_id);
00131                 }
00132 
00133                 return $question;
00134         }
00135         
00136         function _getGUIClassNameForId($a_q_id)
00137         {
00138                 $q_type = SurveyQuestion::_getQuestiontype($a_q_id);
00139                 $class_name = SurveyQuestionGUI::_getClassNameForQType($q_type);
00140                 return $class_name;
00141         }
00142 
00143         function _getClassNameForQType($q_type)
00144         {
00145                 switch ($q_type)
00146                 {
00147                         case "qt_nominal":
00148                                 return "SurveyNominalQuestionGUI";
00149                                 break;
00150 
00151                         case "qt_ordinal":
00152                                 return "SurveyOrdinalQuestionGUI";
00153                                 break;
00154 
00155                         case "qt_metric":
00156                                 return "SurveyMetricQuestionGUI";
00157                                 break;
00158 
00159                         case "qt_text":
00160                                 return "SurveyTextQuestionGUI";
00161                                 break;
00162                 }
00163         }
00164         
00165         function originalSyncForm()
00166         {
00167 //              $this->tpl->setVariable("HEADER", $this->object->getTitle());
00168                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_sync_original.html", true);
00169                 $this->tpl->setCurrentBlock("adm_content");
00170                 $this->tpl->setVariable("BUTTON_YES", $this->lng->txt("yes"));
00171                 $this->tpl->setVariable("BUTTON_NO", $this->lng->txt("no"));
00172                 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
00173                 $this->tpl->setVariable("TEXT_SYNC", $this->lng->txt("confirm_sync_questions"));
00174                 $this->tpl->parseCurrentBlock();
00175         }
00176         
00177         function sync()
00178         {
00179                 $original_id = $this->object->original_id;
00180                 if ($original_id)
00181                 {
00182                         $this->object->syncWithOriginal();
00183                 }
00184                 $_GET["ref_id"] = $_GET["calling_survey"];
00185                 ilUtil::redirect("survey.php?ref_id=" . $_GET["calling_survey"] . "&cmd=questions");
00186         }
00187 
00188         function cancelSync()
00189         {
00190                 $_GET["ref_id"] = $_GET["calling_survey"];
00191                 ilUtil::redirect("survey.php?ref_id=" . $_GET["calling_survey"] . "&cmd=questions");
00192         }
00193                 
00197         function save()
00198         {
00199                 global $ilUser;
00200                 $old_id = $_GET["q_id"];
00201                 $result = $this->writePostData();
00202                 if ($result == 0)
00203                 {
00204                         $this->object->saveToDb();
00205                         $originalexists = $this->object->_questionExists($this->object->original_id);
00206                         $_GET["q_id"] = $this->object->getId();
00207                         if ($_GET["calling_survey"] && $originalexists && SurveyQuestion::_isWriteable($this->object->original_id, $ilUser->getId()))
00208                         {
00209                                 $this->originalSyncForm();
00210                                 return;
00211                         }
00212                         elseif ($_GET["calling_survey"])
00213                         {
00214                                 $_GET["ref_id"] = $_GET["calling_survey"];
00215                                 ilUtil::redirect("survey.php?ref_id=" . $_GET["calling_survey"] . "&cmd=questions");
00216                                 return;
00217                         }
00218                         else
00219                         {
00220                                 sendInfo($this->lng->txt("msg_obj_modified"), true);
00221                                 $this->ctrl->setParameterByClass($_GET["cmdClass"], "q_id", $this->object->getId());
00222                                 $this->ctrl->setParameterByClass($_GET["cmdClass"], "sel_question_types", $_GET["sel_question_types"]);
00223                                 $this->ctrl->setParameterByClass($_GET["cmdClass"], "new_for_survey", $_GET["new_for_survey"]);
00224                                 $this->ctrl->redirectByClass($_GET["cmdClass"], "editQuestion");
00225                         }
00226                 }
00227                 else
00228                 {
00229       sendInfo($this->lng->txt("fill_out_all_required_fields"));
00230                 }
00231                 $this->editQuestion();
00232         }
00233         
00241         function deleteCategory()
00242         {
00243                 $result = $this->writePostData();
00244                 if ($result == 0)
00245                 {
00246                         $delete_categories = array();
00247                         foreach ($_POST as $key => $value) {
00248                                 if (preg_match("/chb_category_(\d+)/", $key, $matches)) {
00249                                         array_push($delete_categories, $matches[1]);
00250                                 }
00251                         }
00252                         if (count($delete_categories))
00253                         {
00254                                 sendInfo($this->lng->txt("category_delete_confirm"));
00255                                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_confirm_remove_categories.html", true);
00256                                 $rowclass = array("tblrow1", "tblrow2");
00257                                 $counter = 0;
00258                                 foreach ($_POST as $key => $value) {
00259                                         if (preg_match("/chb_category_(\d+)/", $key, $matches)) {
00260                                                 $this->tpl->setCurrentBlock("row");
00261                                                 $this->tpl->setVariable("TXT_TITLE", $_POST["category_$matches[1]"]);
00262                                                 $this->tpl->setVariable("COLOR_CLASS", $rowclass[$counter % 2]);
00263                                                 $this->tpl->parseCurrentBlock();
00264                                                 $this->tpl->setCurrentBlock("hidden");
00265                                                 $this->tpl->setVariable("HIDDEN_NAME", $key);
00266                                                 $this->tpl->setVariable("HIDDEN_VALUE", $value);
00267                                                 $this->tpl->parseCurrentBlock();
00268                                                 $counter++;
00269                                         }
00270                                 }
00271                 
00272                                 // set the id to return to the selected question
00273                                 $this->tpl->setCurrentBlock("hidden");
00274                                 $this->tpl->setVariable("HIDDEN_NAME", "id");
00275                                 $this->tpl->setVariable("HIDDEN_VALUE", $_POST["id"]);
00276                                 $this->tpl->parseCurrentBlock();
00277                                 
00278                                 $this->tpl->setCurrentBlock("adm_content");
00279                                 $this->tpl->setVariable("TXT_TITLE", $this->lng->txt("category"));
00280                                 $this->tpl->setVariable("BTN_CANCEL",$this->lng->txt("cancel"));
00281                                 $this->tpl->setVariable("BTN_CONFIRM",$this->lng->txt("confirm"));
00282                                 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
00283                                 $this->tpl->parseCurrentBlock();
00284                         }
00285                         else
00286                         {
00287                                 sendInfo($this->lng->txt("category_delete_select_none"));
00288                                 $this->editQuestion();
00289                         }
00290                 }
00291                 else
00292                 {
00293                         // You cannot add answers before you enter the required data
00294                         sendInfo($this->lng->txt("fill_out_all_required_fields_delete_category"));
00295                         $this->editQuestion();
00296                 }
00297         }
00298         
00306         function confirmDeleteCategory() {
00307                 $delete_categories = array();
00308                 foreach ($_POST as $key => $value) {
00309                         if (preg_match("/chb_category_(\d+)/", $key, $matches)) {
00310                                 array_push($delete_categories, $matches[1]);
00311                         }
00312                 }
00313                 if (count($delete_categories))
00314                 {
00315                         $this->object->removeCategories($delete_categories);
00316                 }
00317                 $this->object->saveToDb();
00318                 $this->ctrl->redirect($this, "editQuestion");
00319         }
00320 
00321         function moveCategory()
00322         {
00323                 $result = $this->writePostData();
00324                 if ($result == 0)
00325                 {
00326                         $checked_move = 0;
00327                         foreach ($_POST as $key => $value) 
00328                         {
00329                                 if (preg_match("/chb_category_(\d+)/", $key, $matches))
00330                                 {
00331                                         $checked_move++;
00332                                         $this->tpl->setCurrentBlock("move");
00333                                         $this->tpl->setVariable("MOVE_COUNTER", $matches[1]);
00334                                         $this->tpl->setVariable("MOVE_VALUE", $matches[1]);
00335                                         $this->tpl->parseCurrentBlock();
00336                                 }
00337                         }
00338                         if ($checked_move)
00339                         {
00340                                 $this->tpl->setCurrentBlock("move_buttons");
00341                                 $this->tpl->setVariable("INSERT_BEFORE", $this->lng->txt("insert_before"));
00342                                 $this->tpl->setVariable("INSERT_AFTER", $this->lng->txt("insert_after"));
00343                                 $this->tpl->parseCurrentBlock();
00344                                 sendInfo($this->lng->txt("select_target_position_for_move"));
00345                         }
00346                         else
00347                         {
00348                                 sendInfo($this->lng->txt("no_category_selected_for_move"));
00349                         }
00350                 }
00351                 else
00352                 {
00353                         // You cannot add answers before you enter the required data
00354                         sendInfo($this->lng->txt("fill_out_all_required_fields_move_category"));
00355                 }
00356                 $this->editQuestion();
00357         }
00358         
00359         function addCategory()
00360         {
00361                 $result = $this->writePostData();
00362                 if ($result == 0)
00363                 {
00364                         // Check for blank fields before a new category field is inserted
00365                         foreach ($_POST as $key => $value) {
00366                                 if (preg_match("/category_(\d+)/", $key, $matches)) {
00367                                         if (!$value) {
00368                                                 $_POST["cmd"]["addCategory"] = "";
00369                                                 sendInfo($this->lng->txt("fill_out_all_category_fields"));
00370                                         }
00371                                 }
00372                         }
00373                 }
00374                 else
00375                 {
00376                         sendInfo($this->lng->txt("fill_out_all_required_fields_add_category"));
00377                         $_POST["cmd"]["addCategory"] = "";
00378                 }
00379                 $this->editQuestion();
00380         }
00381         
00382         function insertBeforeCategory()
00383         {
00384                 $result = $this->writePostData();
00385                 $array1 = array();
00386                 $array2 = array();
00387         
00388                 // Move selected categories
00389                 $move_categories = array();
00390                 $selected_category = -1;
00391                 foreach ($_POST as $key => $value)
00392                 {
00393                         if (preg_match("/^move_(\d+)$/", $key, $matches))
00394                         {
00395                                 array_push($move_categories, $value);
00396                                 array_push($array2, ilUtil::stripSlashes($_POST["category_$value"]));
00397                         }
00398                         if (preg_match("/^chb_category_(\d+)/", $key, $matches))
00399                         {
00400                                 if ($selected_category < 0)
00401                                 {
00402                                         // take onley the first checked category (if more categories are checked)
00403                                         $selected_category = $matches[1];
00404                                 }
00405                         }
00406                 }
00407 
00408     // Add all categories from the form into the object
00409                 foreach ($_POST as $key => $value) {
00410                         if (preg_match("/^category_(\d+)/", $key, $matches)) {
00411                                 if (!in_array($matches[1], $move_categories) or ($selected_category < 0))
00412                                 {
00413                                         array_push($array1, ilUtil::stripSlashes($value));
00414                                 }
00415                         }
00416                 }
00417 
00418                 if ($selected_category >= 0)
00419                 {
00420                         // Delete all existing categories and create new categories from the form data
00421                         $this->object->flushCategories();
00422                         $array_pos = array_search($_POST["category_$selected_category"], $array1);
00423                         $part1 = array_slice($array1, 0, $array_pos);
00424                         $part2 = array_slice($array1, $array_pos);
00425                         $array1 = array_merge($part1, $array2, $part2);
00426                         $this->object->addCategoryArray($array1);
00427                         $this->object->saveToDb();
00428                 }
00429                 $this->editQuestion();
00430         }
00431         
00432         function insertAfterCategory()
00433         {
00434                 $result = $this->writePostData();
00435                 $array1 = array();
00436                 $array2 = array();
00437         
00438                 // Move selected categories
00439                 $move_categories = array();
00440                 $selected_category = -1;
00441                 foreach ($_POST as $key => $value)
00442                 {
00443                         if (preg_match("/^move_(\d+)$/", $key, $matches))
00444                         {
00445                                 array_push($move_categories, $value);
00446                                 array_push($array2, ilUtil::stripSlashes($_POST["category_$value"]));
00447                         }
00448                         if (preg_match("/^chb_category_(\d+)/", $key, $matches))
00449                         {
00450                                 if ($selected_category < 0)
00451                                 {
00452                                         // take onley the first checked category (if more categories are checked)
00453                                         $selected_category = $matches[1];
00454                                 }
00455                         }
00456                 }
00457 
00458     // Add all categories from the form into the object
00459                 foreach ($_POST as $key => $value) {
00460                         if (preg_match("/^category_(\d+)/", $key, $matches)) {
00461                                 if (!in_array($matches[1], $move_categories) or ($selected_category < 0))
00462                                 {
00463                                         array_push($array1, ilUtil::stripSlashes($value));
00464                                 }
00465                         }
00466                 }
00467 
00468                 if ($selected_category >= 0)
00469                 {
00470                         // Delete all existing categories and create new categories from the form data
00471                         $this->object->flushCategories();
00472                         $array_pos = array_search($_POST["category_$selected_category"], $array1);
00473                         $part1 = array_slice($array1, 0, $array_pos + 1);
00474                         $part2 = array_slice($array1, $array_pos + 1);
00475                         $array1 = array_merge($part1, $array2, $part2);
00476                         $this->object->addCategoryArray($array1);
00477                         $this->object->saveToDb();
00478                 }
00479                 $this->editQuestion();
00480         }
00481         
00482         function cancel()
00483         {
00484                 if ($_GET["calling_survey"])
00485                 {
00486                         $_GET["ref_id"] = $_GET["calling_survey"];
00487                         ilUtil::redirect("survey.php?cmd=questions&ref_id=".$_GET["calling_survey"]);
00488                 }
00489                 elseif ($_GET["new_for_survey"])
00490                 {
00491                         $_GET["ref_id"] = $_GET["new_for_survey"];
00492                         ilUtil::redirect("survey.php?cmd=questions&ref_id=".$_GET["new_for_survey"]);
00493                 }
00494                 else
00495                 {
00496                         $this->ctrl->redirectByClass("ilobjsurveyquestionpoolgui", "questions");
00497                 }
00498         }
00499 
00507   function addPhrase($hasError = false) 
00508         {
00509                 if (!$hasError)
00510                 {
00511                         $result = $this->writePostData();
00512                         if ($result > 0)
00513                         {
00514                                 sendInfo($this->lng->txt("fill_out_all_required_fields"));
00515                                 $this->editQuestion();
00516                                 return;
00517                         }
00518                         $this->object->saveToDb();
00519                         $this->ctrl->setParameterByClass(get_class($this), "q_id", $this->object->getId());
00520                         $this->ctrl->setParameterByClass("ilobjsurveyquestionpoolgui", "q_id", $this->object->getId());
00521                 }
00522                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_addphrase.html", true);
00523 
00524                 // set the id to return to the selected question
00525                 $this->tpl->setCurrentBlock("hidden");
00526                 $this->tpl->setVariable("HIDDEN_NAME", "id");
00527                 $this->tpl->setVariable("HIDDEN_VALUE", $this->object->getId());
00528                 $this->tpl->parseCurrentBlock();
00529 
00530                 $phrases =& $this->object->getAvailablePhrases();
00531                 $colors = array("tblrow1", "tblrow2");
00532                 $counter = 0;
00533                 foreach ($phrases as $phrase_id => $phrase_array)
00534                 {
00535                         $this->tpl->setCurrentBlock("phraserow");
00536                         $this->tpl->setVariable("COLOR_CLASS", $colors[$counter++ % 2]);
00537                         $this->tpl->setVariable("PHRASE_VALUE", $phrase_id);
00538                         $this->tpl->setVariable("PHRASE_NAME", $phrase_array["title"]);
00539                         $categories =& $this->object->getCategoriesForPhrase($phrase_id);
00540                         $this->tpl->setVariable("PHRASE_CONTENT", join($categories, ","));
00541                         $this->tpl->parseCurrentBlock();
00542                 }
00543                 
00544                 $this->tpl->setCurrentBlock("adm_content");
00545                 $this->tpl->setVariable("TEXT_CANCEL", $this->lng->txt("cancel"));
00546                 $this->tpl->setVariable("TEXT_PHRASE", $this->lng->txt("phrase"));
00547                 $this->tpl->setVariable("TEXT_CONTENT", $this->lng->txt("categories"));
00548                 $this->tpl->setVariable("TEXT_ADD_PHRASE", $this->lng->txt("add_phrase"));
00549                 $this->tpl->setVariable("TEXT_INTRODUCTION",$this->lng->txt("add_phrase_introduction"));
00550                 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
00551                 $this->tpl->parseCurrentBlock();
00552         }
00553         
00561         function cancelViewPhrase() {
00562                 $this->ctrl->redirect($this, "editQuestion");
00563         }
00564 
00572         function cancelDeleteCategory() {
00573                 $this->ctrl->redirect($this, "editQuestion");
00574         }
00575 
00583         function addSelectedPhrase() {
00584                 if (strcmp($_POST["phrases"], "") == 0)
00585                 {
00586                         sendInfo($this->lng->txt("select_phrase_to_add"));
00587                         $this->addPhrase(true);
00588                 }
00589                 else
00590                 {
00591                         if (strcmp($this->object->getPhrase($_POST["phrases"]), "dp_standard_numbers") != 0)
00592                         {
00593                                 $this->object->addPhrase($_POST["phrases"]);
00594                         }
00595                         else
00596                         {
00597                                 $this->addStandardNumbers();
00598                                 return;
00599                         }
00600                         $this->editQuestion();
00601                 }
00602         }
00603 
00611   function addStandardNumbers() 
00612         {
00613                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_addphrase_standard_numbers.html", true);
00614 
00615                 // set the id to return to the selected question
00616                 $this->tpl->setCurrentBlock("hidden");
00617                 $this->tpl->setVariable("HIDDEN_NAME", "id");
00618                 $this->tpl->setVariable("HIDDEN_VALUE", $this->object->getId());
00619                 $this->tpl->parseCurrentBlock();
00620 
00621                 $this->tpl->setCurrentBlock("adm_content");
00622                 $this->tpl->setVariable("TEXT_ADD_LIMITS", $this->lng->txt("add_limits_for_standard_numbers"));
00623                 $this->tpl->setVariable("TEXT_LOWER_LIMIT",$this->lng->txt("lower_limit"));
00624                 $this->tpl->setVariable("TEXT_UPPER_LIMIT",$this->lng->txt("upper_limit"));
00625                 $this->tpl->setVariable("VALUE_LOWER_LIMIT", $_POST["lower_limit"]);
00626                 $this->tpl->setVariable("VALUE_UPPER_LIMIT", $_POST["upper_limit"]);
00627                 $this->tpl->setVariable("BTN_ADD",$this->lng->txt("add_phrase"));
00628                 $this->tpl->setVariable("BTN_CANCEL",$this->lng->txt("cancel"));
00629                 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
00630                 $this->tpl->parseCurrentBlock();
00631         }
00632         
00640         function cancelStandardNumbers() {
00641                 $this->ctrl->redirect($this, "editQuestion");
00642         }
00643 
00651         function insertStandardNumbers() {
00652                 if ((strcmp($_POST["lower_limit"], "") == 0) or (strcmp($_POST["upper_limit"], "") == 0))
00653                 {
00654                         sendInfo($this->lng->txt("missing_upper_or_lower_limit"));
00655                         $this->addStandardNumbers();
00656                 }
00657                 else if ((int)$_POST["upper_limit"] <= (int)$_POST["lower_limit"])
00658                 {
00659                         sendInfo($this->lng->txt("upper_limit_must_be_greater"));
00660                         $this->addStandardNumbers();
00661                 }
00662                 else
00663                 {
00664                         $this->object->addStandardNumbers($_POST["lower_limit"], $_POST["upper_limit"]);
00665                         $this->editQuestion();
00666                 }
00667         }
00668 
00676   function savePhrase($hasError = false) 
00677         {
00678                 if (!$hasError)
00679                 {
00680                         $result = $this->writePostData();
00681                 }
00682                 else
00683                 {
00684                         $result = 0;
00685                 }
00686 
00687                 $categories_checked = 0;
00688                 foreach ($_POST as $key => $value) 
00689                 {
00690                         if (preg_match("/chb_category_(\d+)/", $key, $matches)) 
00691                         {
00692                                 $categories_checked++;
00693                         }
00694                 }
00695 
00696                 if ($categories_checked == 0)
00697                 {
00698                         sendInfo($this->lng->txt("check_category_to_save_phrase"));
00699                         $this->editQuestion();
00700                         return;
00701                 }
00702                 
00703                 if ($result == 0)
00704                 {
00705                         $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_savephrase.html", true);
00706                         $rowclass = array("tblrow1", "tblrow2");
00707                         $counter = 0;
00708                         foreach ($_POST as $key => $value) {
00709                                 if (preg_match("/chb_category_(\d+)/", $key, $matches)) {
00710                                         $this->tpl->setCurrentBlock("row");
00711                                         $this->tpl->setVariable("TXT_TITLE", $_POST["category_$matches[1]"]);
00712                                         $this->tpl->setVariable("COLOR_CLASS", $rowclass[$counter % 2]);
00713                                         $this->tpl->parseCurrentBlock();
00714                                         $this->tpl->setCurrentBlock("hidden");
00715                                         $this->tpl->setVariable("HIDDEN_NAME", $key);
00716                                         $this->tpl->setVariable("HIDDEN_VALUE", $value);
00717                                         $this->tpl->parseCurrentBlock();
00718                                         $this->tpl->setCurrentBlock("hidden");
00719                                         $this->tpl->setVariable("HIDDEN_NAME", "category_$matches[1]");
00720                                         $this->tpl->setVariable("HIDDEN_VALUE", $_POST["category_$matches[1]"]);
00721                                         $this->tpl->parseCurrentBlock();
00722                                         $counter++;
00723                                 }
00724                         }
00725         
00726                         // set the id to return to the selected question
00727                         $this->tpl->setCurrentBlock("hidden");
00728                         $this->tpl->setVariable("HIDDEN_NAME", "id");
00729                         $this->tpl->setVariable("HIDDEN_VALUE", $_POST["id"]);
00730                         $this->tpl->parseCurrentBlock();
00731                         
00732                         $this->tpl->setCurrentBlock("adm_content");
00733                         $this->tpl->setVariable("SAVE_PHRASE_INTRODUCTION", $this->lng->txt("save_phrase_introduction"));
00734                         $this->tpl->setVariable("TEXT_PHRASE_TITLE", $this->lng->txt("enter_phrase_title"));
00735                         $this->tpl->setVariable("TXT_TITLE", $this->lng->txt("category"));
00736                         $this->tpl->setVariable("VALUE_PHRASE_TITLE", $_POST["phrase_title"]);
00737                         $this->tpl->setVariable("BTN_CANCEL",$this->lng->txt("cancel"));
00738                         $this->tpl->setVariable("BTN_CONFIRM",$this->lng->txt("confirm"));
00739                         $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
00740                         $this->tpl->parseCurrentBlock();
00741                 }
00742                 else
00743                 {
00744                         sendInfo($this->lng->txt("fill_out_all_required_fields_save_phrase"));
00745                 }
00746         }
00747 
00755         function cancelSavePhrase() {
00756                 $this->ctrl->redirect($this, "editQuestion");
00757         }
00758 
00766         function confirmSavePhrase() {
00767                 if (!$_POST["phrase_title"])
00768                 {
00769                         sendInfo($this->lng->txt("qpl_savephrase_empty"));
00770                         $this->savePhrase(true);
00771                         return;
00772                 }
00773                 if ($this->object->phraseExists($_POST["phrase_title"]))
00774                 {
00775                         sendInfo($this->lng->txt("qpl_savephrase_exists"));
00776                         $this->savePhrase(true);
00777                         return;
00778                 }
00779 
00780                 $save_categories = array();
00781                 foreach ($_POST as $key => $value) {
00782                         if (preg_match("/chb_category_(\d+)/", $key, $matches)) {
00783                                 array_push($save_categories, $matches[1]);
00784                         }
00785                 }
00786                 if (count($save_categories))
00787                 {
00788                         $this->object->savePhrase($save_categories, $_POST["phrase_title"]);
00789                         sendInfo($this->lng->txt("phrase_saved"));
00790                 }
00791                 $this->editQuestion();
00792         }
00793 
00794         function setQuestionTabsForClass($guiclass)
00795         {
00796                 global $rbacsystem;
00797 
00798                 include_once "./classes/class.ilTabsGUI.php";
00799                 $tabs_gui =& new ilTabsGUI();
00800                 
00801                 $this->ctrl->setParameterByClass("$guiclass", "sel_question_types", $this->getQuestionType());
00802                 $this->ctrl->setParameterByClass("$guiclass", "q_id", $_GET["q_id"]);
00803 
00804                 if ($rbacsystem->checkAccess('edit', $_GET["ref_id"])) {
00805                         $tabs_gui->addTarget("properties",
00806                                 $this->ctrl->getLinkTargetByClass("$guiclass", "editQuestion"), "editQuestion",
00807                                 "$guiclass");
00808                 }
00809                 
00810                 if ($_GET["q_id"])
00811                 {
00812                         $tabs_gui->addTarget("preview",
00813                         $this->ctrl->getLinkTargetByClass("$guiclass", "preview"), "preview",
00814                         "$guiclass");
00815                 }
00816 
00817                 if ($_GET["calling_survey"])
00818                 {
00819                         $tabs_gui->addTarget("menubacktosurvey",
00820                                 "survey.php?cmd=questions&ref_id=".$_GET["calling_survey"], "questions",
00821                                 "ilObjSurveyQuestionPoolGUI");
00822                 }
00823                 elseif ($_GET["new_for_survey"])
00824                 {
00825                         $tabs_gui->addTarget("menubacktosurvey",
00826                                 "survey.php?cmd=questions&new_id=".$this->object->getId() . "&ref_id=".$_GET["new_for_survey"], "questions",
00827                                 "ilObjSurveyQuestionPoolGUI");
00828                 }
00829                 else
00830                 {               
00831                         $tabs_gui->addTarget("menuback",
00832                                 $this->ctrl->getLinkTargetByClass("ilobjsurveyquestionpoolgui", "questions"), "questions",
00833                                 "ilObjSurveyQuestionPoolGUI");
00834                 }
00835                 
00836                 $this->tpl->setVariable("TABS", $tabs_gui->getHTML());
00837 
00838     if ($this->object->getId() > 0) {
00839       $title = $this->lng->txt("edit") . " &quot;" . $this->object->getTitle() . "&quot";
00840     } else {
00841       $title = $this->lng->txt("create_new") . " " . $this->lng->txt($this->getQuestionType());
00842     }
00843                 $this->tpl->setVariable("HEADER", $title);
00844 //              echo "<br>end setQuestionTabs<br>";
00845         }
00846 
00847         function addMaterial()
00848         {
00849                 global $tree;
00850 
00851                 require_once("./survey/classes/class.ilMaterialExplorer.php");
00852                 switch ($_POST["internalLinkType"])
00853                 {
00854                         case "lm":
00855                                 $_SESSION["link_new_type"] = "lm";
00856                                 $_SESSION["search_link_type"] = "lm";
00857                                 break;
00858                         case "glo":
00859                                 $_SESSION["link_new_type"] = "glo";
00860                                 $_SESSION["search_link_type"] = "glo";
00861                                 break;
00862                         case "st":
00863                                 $_SESSION["link_new_type"] = "lm";
00864                                 $_SESSION["search_link_type"] = "st";
00865                                 break;
00866                         case "pg":
00867                                 $_SESSION["link_new_type"] = "lm";
00868                                 $_SESSION["search_link_type"] = "pg";
00869                                 break;
00870                         default:
00871                                 if (!$_SESSION["link_new_type"])
00872                                 {
00873                                         $_SESSION["link_new_type"] = "lm";
00874                                 }
00875                                 break;
00876                 }
00877 
00878                 sendInfo($this->lng->txt("select_object_to_link"));
00879                 
00880                 $exp = new ilMaterialExplorer($this->ctrl->getLinkTarget($this,'addMaterial'), get_class($this));
00881 
00882                 $exp->setExpand($_GET["expand"] ? $_GET["expand"] : $tree->readRootId());
00883                 $exp->setExpandTarget($this->ctrl->getLinkTarget($this,'addMaterial'));
00884                 $exp->setTargetGet("ref_id");
00885                 $exp->setRefId($this->cur_ref_id);
00886                 $exp->addFilter($_SESSION["link_new_type"]);
00887                 $exp->setSelectableType($_SESSION["link_new_type"]);
00888 
00889                 // build html-output
00890                 $exp->setOutput(0);
00891 
00892                 $this->tpl->addBlockFile("ADM_CONTENT", "explorer", "tpl.il_svy_qpl_explorer.html", true);
00893                 $this->tpl->setVariable("EXPLORER_TREE",$exp->getOutput());
00894                 $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
00895                 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00896                 $this->tpl->parseCurrentBlock();
00897         }
00898         
00899         function removeMaterial()
00900         {
00901                 $this->object->material = array();
00902                 $this->object->saveToDb();
00903                 $this->editQuestion();
00904         }
00905         
00906         function cancelExplorer()
00907         {
00908                 unset($_SESSION["link_new_type"]);
00909                 $this->editQuestion();
00910         }
00911                 
00912         function addPG()
00913         {
00914                 $this->object->setMaterial("il__pg_" . $_GET["pg"]);
00915                 unset($_SESSION["link_new_type"]);
00916                 unset($_SESSION["search_link_type"]);
00917                 sendInfo($this->lng->txt("material_added_successfully"));
00918                 $this->editQuestion();
00919         }
00920         
00921         function addST()
00922         {
00923                 $this->object->setMaterial("il__st_" . $_GET["st"]);
00924                 unset($_SESSION["link_new_type"]);
00925                 unset($_SESSION["search_link_type"]);
00926                 sendInfo($this->lng->txt("material_added_successfully"));
00927                 $this->editQuestion();
00928         }
00929 
00930         function addGIT()
00931         {
00932                 $this->object->setMaterial("il__git_" . $_GET["git"]);
00933                 unset($_SESSION["link_new_type"]);
00934                 unset($_SESSION["search_link_type"]);
00935                 sendInfo($this->lng->txt("material_added_successfully"));
00936                 $this->editQuestion();
00937         }
00938         
00939         function linkChilds()
00940         {
00941                 switch ($_SESSION["search_link_type"])
00942                 {
00943                         case "pg":
00944                         case "st":
00945                                 $_GET["q_id"] = $this->object->getId();
00946                                 $color_class = array("tblrow1", "tblrow2");
00947                                 $counter = 0;
00948                                 require_once("./content/classes/class.ilObjContentObject.php");
00949                                 $cont_obj =& new ilObjContentObject($_GET["source_id"], true);
00950                                 // get all chapters
00951                                 $ctree =& $cont_obj->getLMTree();
00952                                 $nodes = $ctree->getSubtree($ctree->getNodeData($ctree->getRootId()));
00953                                 $this->tpl->addBlockFile("ADM_CONTENT", "link_selection", "tpl.il_svy_qpl_internallink_selection.html", true);
00954                                 foreach($nodes as $node)
00955                                 {
00956                                         if($node["type"] == $_SESSION["search_link_type"])
00957                                         {
00958                                                 $this->tpl->setCurrentBlock("linktable_row");
00959                                                 $this->tpl->setVariable("TEXT_LINK", $node["title"]);
00960                                                 $this->tpl->setVariable("TEXT_ADD", $this->lng->txt("add"));
00961                                                 $this->tpl->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "add" . strtoupper($node["type"])) . "&" . $node["type"] . "=" . $node["obj_id"]);
00962                                                 $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
00963                                                 $this->tpl->parseCurrentBlock();
00964                                                 $counter++;
00965                                         }
00966                                 }
00967                                 $this->tpl->setCurrentBlock("link_selection");
00968                                 $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
00969                                 $this->tpl->setVariable("TEXT_LINK_TYPE", $this->lng->txt("obj_" . $_SESSION["search_link_type"]));
00970                                 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00971                                 $this->tpl->parseCurrentBlock();
00972                                 break;
00973                         case "glo":
00974                                 $_GET["q_id"] = $this->object->getId();
00975                                 $color_class = array("tblrow1", "tblrow2");
00976                                 $counter = 0;
00977                                 $this->tpl->addBlockFile("ADM_CONTENT", "link_selection", "tpl.il_svy_qpl_internallink_selection.html", true);
00978                                 require_once "./content/classes/class.ilObjGlossary.php";
00979                                 $glossary =& new ilObjGlossary($_GET["source_id"], true);
00980                                 // get all glossary items
00981                                 $terms = $glossary->getTermList();
00982                                 foreach($terms as $term)
00983                                 {
00984                                         $this->tpl->setCurrentBlock("linktable_row");
00985                                         $this->tpl->setVariable("TEXT_LINK", $term["term"]);
00986                                         $this->tpl->setVariable("TEXT_ADD", $this->lng->txt("add"));
00987                                         $this->tpl->setVariable("LINK_HREF", $this->ctrl->getLinkTargetByClass(get_class($this), "addGIT") . "&git=" . $term["id"]);
00988                                         $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
00989                                         $this->tpl->parseCurrentBlock();
00990                                         $counter++;
00991                                 }
00992                                 $this->tpl->setCurrentBlock("link_selection");
00993                                 $this->tpl->setVariable("BUTTON_CANCEL",$this->lng->txt("cancel"));
00994                                 $this->tpl->setVariable("TEXT_LINK_TYPE", $this->lng->txt("glossary_term"));
00995                                 $this->tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00996                                 $this->tpl->parseCurrentBlock();
00997                                 break;
00998                         case "lm":
00999                                 $this->object->setMaterial("il__lm_" . $_GET["source_id"]);
01000                                 unset($_SESSION["link_new_type"]);
01001                                 unset($_SESSION["search_link_type"]);
01002                                 sendInfo($this->lng->txt("material_added_successfully"));
01003                                 $this->editQuestion();
01004                                 break;
01005                 }
01006         }
01007 }
01008 ?>

Generated on Fri Dec 13 2013 10:18:33 for ILIAS Release_3_5_x_branch .rev 46805 by  doxygen 1.7.1