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

Generated on Fri Dec 13 2013 09:06:38 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1