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

assessment/classes/class.assMultipleChoiceGUI.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 "./assessment/classes/class.assQuestionGUI.php";
00025 require_once "./assessment/classes/class.assMultipleChoice.php";
00026 
00038 class ASS_MultipleChoiceGUI extends ASS_QuestionGUI
00039 {
00048         function ASS_MultipleChoiceGUI(
00049                         $id = -1
00050         )
00051         {
00052                 $this->ASS_QuestionGUI();
00053                 $this->object = new ASS_MultipleChoice();
00054                 if ($id >= 0)
00055                 {
00056                         $this->object->loadFromDb($id);
00057                 }
00058         }
00059 
00060         function getCommand($cmd)
00061         {
00062                 if (substr($cmd, 0, 6) == "delete")
00063                 {
00064                         $cmd = "delete";
00065                 }
00066 
00067                 return $cmd;
00068         }
00069 
00070 
00079         function getQuestionType()
00080         {
00081                 if ($this->object->get_response() == RESPONSE_SINGLE)
00082                 {
00083                         return "qt_multiple_choice_sr";
00084                 }
00085                 else
00086                 {
00087                         return "qt_multiple_choice_mr";
00088                 }
00089         }
00090 
00098         function editQuestion()
00099         {
00100                 $this->tpl->setVariable("HEADER", $this->object->getTitle());
00101                 $javascript = "<script type=\"text/javascript\">function initialSelect() {\n%s\n}</script>";
00102                 // single response
00103                 if ($this->object->get_response() == RESPONSE_SINGLE)
00104                 {
00105                         $this->getQuestionTemplate("qt_multiple_choice_sr");
00106                         $this->tpl->addBlockFile("QUESTION_DATA", "question_data", "tpl.il_as_qpl_mc_sr.html", true);
00107                         // output of existing single response answers
00108                         for ($i = 0; $i < $this->object->get_answer_count(); $i++)
00109                         {
00110                                 $this->tpl->setCurrentBlock("deletebutton");
00111                                 $this->tpl->setVariable("DELETE", $this->lng->txt("delete"));
00112                                 $this->tpl->setVariable("ANSWER_ORDER", $i);
00113                                 $this->tpl->parseCurrentBlock();
00114                                 $this->tpl->setCurrentBlock("answers");
00115                                 $answer = $this->object->get_answer($i);
00116                                 $this->tpl->setVariable("VALUE_ANSWER_COUNTER", $answer->get_order() + 1);
00117                                 $this->tpl->setVariable("ANSWER_ORDER", $answer->get_order());
00118                                 $this->tpl->setVariable("VALUE_ANSWER", htmlspecialchars($answer->get_answertext()));
00119                                 $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
00120                                 $this->tpl->setVariable("TEXT_ANSWER_TEXT", $this->lng->txt("answer_text"));
00121                                 $this->tpl->setVariable("VALUE_MULTIPLE_CHOICE_POINTS", sprintf("%d", $answer->get_points()));
00122                                 $this->tpl->setVariable("VALUE_TRUE", $this->lng->txt("true"));
00123                                 $this->tpl->parseCurrentBlock();
00124                         }
00125                         // call to other question data i.e. estimated working time block
00126                         $this->outOtherQuestionData();
00127 
00128                         $internallinks = array(
00129                                 "lm" => $this->lng->txt("obj_lm"),
00130                                 "st" => $this->lng->txt("obj_st"),
00131                                 "pg" => $this->lng->txt("obj_pg"),
00132                                 "glo" => $this->lng->txt("glossary_term")
00133                         );
00134                         foreach ($internallinks as $key => $value)
00135                         {
00136                                 $this->tpl->setCurrentBlock("internallink");
00137                                 $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00138                                 $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00139                                 $this->tpl->parseCurrentBlock();
00140                         }
00141                         
00142                         $this->tpl->setCurrentBlock("HeadContent");
00143                         if ($this->object->get_answer_count() == 0)
00144                         {
00145                                 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_multiple_choice.title.focus();"));
00146                         }
00147                         else
00148                         {
00149                                 switch ($this->ctrl->getCmd())
00150                                 {
00151                                         case "add":
00152                                         case "addTrueFalse":
00153                                         case "addYesNo":
00154                                                 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_multiple_choice.answer_".($this->object->get_answer_count() - 1).".focus(); document.getElementById('answer_".($this->object->get_answer_count() - 1)."').scrollIntoView(\"true\");"));
00155                                                 break;
00156                                         case "":
00157                                                 if ($this->object->get_answer_count() == 0)
00158                                                 {
00159                                                         $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_multiple_choice.title.focus();"));
00160                                                 }
00161                                                 else
00162                                                 {
00163                                                         $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_multiple_choice.answer_".($this->object->get_answer_count() - 1).".focus(); document.getElementById('answer_".($this->object->get_answer_count() - 1)."').scrollIntoView(\"true\");"));
00164                                                 }
00165                                                 break;
00166                                         default:
00167                                                 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_multiple_choice.title.focus();"));
00168                                                 break;
00169                                 }
00170                         }
00171                         $this->tpl->parseCurrentBlock();
00172                         $this->tpl->setCurrentBlock("question_data");
00173                         $this->tpl->setVariable("MULTIPLE_CHOICE_ID", $this->object->getId());
00174                         $this->tpl->setVariable("VALUE_MULTIPLE_CHOICE_TITLE", htmlspecialchars($this->object->getTitle()));
00175                         $this->tpl->setVariable("VALUE_MULTIPLE_CHOICE_COMMENT", htmlspecialchars($this->object->getComment()));
00176                         $this->tpl->setVariable("VALUE_MULTIPLE_CHOICE_AUTHOR", htmlspecialchars($this->object->getAuthor()));
00177                         $questiontext = $this->object->get_question();
00178                         $questiontext = preg_replace("/<br \/>/", "\n", $questiontext);
00179                         $this->tpl->setVariable("VALUE_QUESTION", htmlspecialchars($questiontext));
00180                         $this->tpl->setVariable("VALUE_ADD_ANSWER", $this->lng->txt("add_answer"));
00181                         $this->tpl->setVariable("VALUE_ADD_ANSWER_YN", $this->lng->txt("add_answer_yn"));
00182                         $this->tpl->setVariable("VALUE_ADD_ANSWER_TF", $this->lng->txt("add_answer_tf"));
00183                         $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00184                         $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
00185                         $this->tpl->setVariable("TEXT_COMMENT", $this->lng->txt("description"));
00186                         $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
00187                         $this->tpl->setVariable("TEXT_SHUFFLE_ANSWERS", $this->lng->txt("shuffle_answers"));
00188                         $this->tpl->setVariable("TXT_YES", $this->lng->txt("yes"));
00189                         $this->tpl->setVariable("TXT_NO", $this->lng->txt("no"));
00190                         if ($this->object->getShuffle())
00191                         {
00192                                 $this->tpl->setVariable("SELECTED_YES", " selected=\"selected\"");
00193                         }
00194                         else
00195                         {
00196                                 $this->tpl->setVariable("SELECTED_NO", " selected=\"selected\"");
00197                         }
00198                         $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
00199                         if (count($this->object->suggested_solutions))
00200                         {
00201                                 $solution_array = $this->object->getSuggestedSolution(0);
00202                                 $href = ASS_Question::_getInternalLinkHref($solution_array["internal_link"]);
00203                                 $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
00204                                 $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
00205                                 $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
00206                                 $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
00207                         }
00208                         else
00209                         {
00210                                 $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
00211                         }
00212                         $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
00213                         $this->tpl->setVariable("SAVE_EDIT", $this->lng->txt("save_edit"));
00214                         $this->tpl->setVariable("CANCEL",$this->lng->txt("cancel"));
00215                         $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00216                         $this->ctrl->setParameter($this, "sel_question_types", "qt_multiple_choice_sr");
00217                         $this->tpl->setVariable("ACTION_MULTIPLE_CHOICE_TEST", $this->ctrl->getFormAction($this));
00218 
00219                         $this->tpl->parseCurrentBlock();
00220                 }
00221                 else    // multiple response
00222                 {
00223                         $this->getQuestionTemplate("qt_multiple_choice_mr");
00224                         $this->tpl->addBlockFile("QUESTION_DATA", "question_data", "tpl.il_as_qpl_mc_mr.html", true);
00225 
00226                         // output of existing multiple response answers
00227                         for ($i = 0; $i < $this->object->get_answer_count(); $i++)
00228                         {
00229                                 $this->tpl->setCurrentBlock("deletebutton");
00230                                 $this->tpl->setVariable("DELETE", $this->lng->txt("delete"));
00231                                 $this->tpl->setVariable("ANSWER_ORDER", $i);
00232                                 $this->tpl->parseCurrentBlock();
00233                                 $this->tpl->setCurrentBlock("answers");
00234                                 $answer = $this->object->get_answer($i);
00235                                 $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
00236                                 $this->tpl->setVariable("VALUE_ANSWER_COUNTER", $answer->get_order() + 1);
00237                                 $this->tpl->setVariable("VALUE_MULTIPLE_CHOICE_POINTS", sprintf("%d", $answer->get_points()));
00238                                 $this->tpl->setVariable("TEXT_WHEN", $this->lng->txt("when"));
00239                                 $this->tpl->setVariable("TEXT_UNCHECKED", $this->lng->txt("checkbox_unchecked"));
00240                                 $this->tpl->setVariable("TEXT_CHECKED", $this->lng->txt("checkbox_checked"));
00241                                 $this->tpl->setVariable("ANSWER_ORDER", $answer->get_order());
00242                                 $this->tpl->setVariable("VALUE_ANSWER", htmlspecialchars($answer->get_answertext()));
00243                                 $this->tpl->setVariable("TEXT_ANSWER_TEXT", $this->lng->txt("answer_text"));
00244                                 $this->tpl->setVariable("VALUE_TRUE", $this->lng->txt("true"));
00245                                 if ($answer->isStateChecked())
00246                                 {
00247                                         $this->tpl->setVariable("CHECKED_SELECTED", " selected=\"selected\"");
00248                                 }
00249                                 $this->tpl->parseCurrentBlock();
00250                         }
00251 
00252                         // call to other question data i.e. estimated working time block
00253                         $this->outOtherQuestionData();
00254 
00255                         $internallinks = array(
00256                                 "lm" => $this->lng->txt("obj_lm"),
00257                                 "st" => $this->lng->txt("obj_st"),
00258                                 "pg" => $this->lng->txt("obj_pg"),
00259                                 "glo" => $this->lng->txt("glossary_term")
00260                         );
00261                         foreach ($internallinks as $key => $value)
00262                         {
00263                                 $this->tpl->setCurrentBlock("internallink");
00264                                 $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00265                                 $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00266                                 $this->tpl->parseCurrentBlock();
00267                         }
00268                         
00269                         $this->tpl->setCurrentBlock("HeadContent");
00270 
00271                         if ($this->object->get_answer_count() == 0)
00272                         {
00273                                 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_multiple_choice.title.focus();"));
00274                         }
00275                         else
00276                         {
00277                                 switch ($this->ctrl->getCmd())
00278                                 {
00279                                         case "add":
00280                                         case "addTrueFalse":
00281                                         case "addYesNo":
00282                                                 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_multiple_choice.answer_".($this->object->get_answer_count() - 1).".focus(); document.getElementById('answer_".($this->object->get_answer_count() - 1)."').scrollIntoView(\"true\");"));
00283                                                 break;
00284                                         case "":
00285                                                 if ($this->object->get_answer_count() == 0)
00286                                                 {
00287                                                         $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_multiple_choice.title.focus();"));
00288                                                 }
00289                                                 else
00290                                                 {
00291                                                         $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_multiple_choice.answer_".($this->object->get_answer_count() - 1).".focus(); document.getElementById('answer_".($this->object->get_answer_count() - 1)."').scrollIntoView(\"true\");"));
00292                                                 }
00293                                                 break;
00294                                         default:
00295                                                 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_multiple_choice.title.focus();"));
00296                                                 break;
00297                                 }
00298                         }
00299                         $this->tpl->parseCurrentBlock();
00300                         $this->tpl->setCurrentBlock("question_data");
00301                         $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00302                         $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
00303                         $this->tpl->setVariable("TEXT_COMMENT", $this->lng->txt("description"));
00304                         $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
00305                         $this->tpl->setVariable("MULTIPLE_CHOICE_ID", $this->object->getId());
00306                         $this->tpl->setVariable("VALUE_MULTIPLE_CHOICE_TITLE", htmlspecialchars($this->object->getTitle()));
00307                         $this->tpl->setVariable("VALUE_MULTIPLE_CHOICE_COMMENT", htmlspecialchars($this->object->getComment()));
00308                         $this->tpl->setVariable("VALUE_MULTIPLE_CHOICE_AUTHOR", htmlspecialchars($this->object->getAuthor()));
00309                         $questiontext = $this->object->get_question();
00310                         $questiontext = preg_replace("/<br \/>/", "\n", $questiontext);
00311                         $this->tpl->setVariable("VALUE_QUESTION", htmlspecialchars($questiontext));
00312                         $this->tpl->setVariable("VALUE_ADD_ANSWER", $this->lng->txt("add_answer"));
00313                         $this->tpl->setVariable("TEXT_SHUFFLE_ANSWERS", $this->lng->txt("shuffle_answers"));
00314                         $this->tpl->setVariable("TXT_YES", $this->lng->txt("yes"));
00315                         $this->tpl->setVariable("TXT_NO", $this->lng->txt("no"));
00316                         if ($this->object->getShuffle())
00317                         {
00318                                 $this->tpl->setVariable("SELECTED_YES", " selected=\"selected\"");
00319                         }
00320                         else
00321                         {
00322                                 $this->tpl->setVariable("SELECTED_NO", " selected=\"selected\"");
00323                         }
00324                         $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
00325                         if (count($this->object->suggested_solutions))
00326                         {
00327                                 $solution_array = $this->object->getSuggestedSolution(0);
00328                                 $href = ASS_Question::_getInternalLinkHref($solution_array["internal_link"]);
00329                                 $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
00330                                 $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
00331                                 $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
00332                                 $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
00333                         }
00334                         else
00335                         {
00336                                 $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
00337                         }
00338                         $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
00339                         $this->tpl->setVariable("SAVE_EDIT", $this->lng->txt("save_edit"));
00340                         $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00341                         $this->tpl->setVariable("CANCEL", $this->lng->txt("cancel"));
00342                         $this->ctrl->setParameter($this, "sel_question_types", "qt_multiple_choice_mr");
00343                         $this->tpl->setVariable("ACTION_MULTIPLE_CHOICE_TEST", $this->ctrl->getFormAction($this));
00344                         $this->tpl->parseCurrentBlock();
00345                 }
00346 
00347                 $this->tpl->setCurrentBlock("adm_content");
00348                 $this->tpl->setVariable("BODY_ATTRIBUTES", " onload=\"initialSelect();\""); 
00349                 $this->tpl->parseCurrentBlock();
00350         }
00351 
00359         function outOtherQuestionData()
00360         {
00361 //echo "<br>ASS_MultipleChoiceGUI->outOtherQuestionData()";
00362                 $this->tpl->setCurrentBlock("other_question_data");
00363                 $est_working_time = $this->object->getEstimatedWorkingTime();
00364                 $this->tpl->setVariable("TEXT_WORKING_TIME", $this->lng->txt("working_time"));
00365                 $this->tpl->setVariable("TIME_FORMAT", $this->lng->txt("time_format"));
00366                 $this->tpl->setVariable("VALUE_WORKING_TIME", ilUtil::makeTimeSelect("Estimated", false, $est_working_time[h], $est_working_time[m], $est_working_time[s]));
00367                 $this->tpl->parseCurrentBlock();
00368         }
00369 
00373         function addYesNo()
00374         {
00375                 $this->writePostData();
00376                 //$this->setObjectData();
00377 
00378                 if (!$this->checkInput())
00379                 {
00380                         sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
00381                 }
00382                 else
00383                 {
00384                         // add a yes/no answer template
00385                         $this->object->add_answer(
00386                                 $this->lng->txt("yes"),
00387                                 0,
00388                                 0,
00389                                 count($this->object->answers)
00390                         );
00391                         $this->object->add_answer(
00392                                 $this->lng->txt("no"),
00393                                 0,
00394                                 0,
00395                                 count($this->object->answers)
00396                         );
00397                 }
00398 
00399                 $this->editQuestion();
00400         }
00401 
00405         function addTrueFalse()
00406         {
00407                 //$this->setObjectData();
00408                 $this->writePostData();
00409 
00410                 if (!$this->checkInput())
00411                 {
00412                         sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
00413                 }
00414                 else
00415                 {
00416                         // add a true/false answer template
00417                         $this->object->add_answer(
00418                                 $this->lng->txt("true"),
00419                                 0,
00420                                 0,
00421                                 count($this->object->answers)
00422                         );
00423                         $this->object->add_answer(
00424                                 $this->lng->txt("false"),
00425                                 0,
00426                                 0,
00427                                 count($this->object->answers)
00428                         );
00429                 }
00430 
00431                 $this->editQuestion();
00432         }
00433 
00437         function add()
00438         {
00439                 //$this->setObjectData();
00440                 $this->writePostData();
00441 
00442                 if (!$this->checkInput())
00443                 {
00444                         sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
00445                 }
00446                 else
00447                 {
00448                         // add an answer template
00449                         $this->object->add_answer(
00450                                 $this->lng->txt(""),
00451                                 0,
00452                                 0,
00453                                 count($this->object->answers)
00454                         );
00455                 }
00456 
00457                 $this->editQuestion();
00458         }
00459 
00463         function delete()
00464         {
00465                 //$this->setObjectData();
00466                 $this->writePostData();
00467 
00468                 foreach ($_POST["cmd"] as $key => $value)
00469                 {
00470                         // was one of the answers deleted
00471                         if (preg_match("/delete_(\d+)/", $key, $matches))
00472                         {
00473                                 $this->object->delete_answer($matches[1]);
00474                         }
00475                 }
00476 
00477                 $this->editQuestion();
00478         }
00479 
00483         function checkInput()
00484         {
00485                 $cmd = $this->ctrl->getCmd();
00486 
00487                 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
00488                 {
00489 //echo "<br>checkInput1:FALSE";
00490                         return false;
00491                 }
00492                 foreach ($_POST as $key => $value)
00493                 {
00494                         if (preg_match("/answer_(\d+)/", $key, $matches))
00495                         {
00496                                 if (!$value)
00497                                 {
00498 //echo "<br>checkInput2:FALSE";
00499                                         return false;
00500                                 }
00501                         }
00502                 }
00503 
00504                 return true;
00505         }
00506 
00515         function writePostData()
00516         {
00517 //echo "here!"; exit;
00518 //echo "<br>ASS_MultipleChoiceGUI->writePostData()";
00519                 $result = 0;
00520                 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
00521                 {
00522                         $result = 1;
00523                 }
00524 
00525                 if (($result) and (($_POST["cmd"]["add"]) or ($_POST["cmd"]["add_tf"]) or ($_POST["cmd"]["add_yn"])))
00526                 {
00527                         // You cannot add answers before you enter the required data
00528                         sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
00529                         $_POST["cmd"]["add"] = "";
00530                         $_POST["cmd"]["add_yn"] = "";
00531                         $_POST["cmd"]["add_tf"] = "";
00532                 }
00533 
00534                 // Check the creation of new answer text fields
00535                 if ($_POST["cmd"]["add"] or $_POST["cmd"]["add_yn"] or $_POST["cmd"]["add_tf"])
00536                 {
00537                         foreach ($_POST as $key => $value)
00538                         {
00539                                 if (preg_match("/answer_(\d+)/", $key, $matches))
00540                                 {
00541                                         if (!$value)
00542                                         {
00543                                                 $_POST["cmd"]["add"] = "";
00544                                                 $_POST["cmd"]["add_yn"] = "";
00545                                                 $_POST["cmd"]["add_tf"] = "";
00546                                                 sendInfo($this->lng->txt("fill_out_all_answer_fields"));
00547                                         }
00548                                 }
00549                         }
00550                 }
00551 
00552                 $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
00553                 $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
00554                 $this->object->setComment(ilUtil::stripSlashes($_POST["comment"]));
00555                 $questiontext = ilUtil::stripSlashes($_POST["question"], true, "<strong><em><code><cite>");
00556                 $questiontext = preg_replace("/\n/", "<br />", $questiontext);
00557                 $this->object->set_question($questiontext);
00558                 $this->object->setSuggestedSolution($_POST["solution_hint"], 0);
00559                 $this->object->setShuffle($_POST["shuffle"]);
00560 
00561                 $saved = $this->writeOtherPostData($result);
00562 
00563                 // Delete all existing answers and create new answers from the form data
00564                 $this->object->flush_answers();
00565 
00566                 // Add all answers from the form into the object
00567                 if ($this->object->get_response() == RESPONSE_SINGLE)
00568                 {
00569                         // ...for multiple choice with single response
00570                         foreach ($_POST as $key => $value)
00571                         {
00572                                 if (preg_match("/answer_(\d+)/", $key, $matches))
00573                                 {
00574                                         $points = $_POST["points_$matches[1]"];
00575                                         if (preg_match("/\d+/", $points))
00576                                         {
00577                                                 if ($points < 0)
00578                                                 {
00579                                                         $points = 0.0;
00580                                                         sendInfo($this->lng->txt("negative_points_not_allowed"), true);
00581                                                 }
00582                                         }
00583                                         else
00584                                         {
00585                                                 $points = 0.0;
00586                                         }
00587                                         $this->object->add_answer(
00588                                                 ilUtil::stripSlashes($_POST["$key"]),
00589                                                 ilUtil::stripSlashes($points),
00590                                                 ilUtil::stripSlashes(1),
00591                                                 ilUtil::stripSlashes($matches[1])
00592                                                 );
00593                                 }
00594                         }
00595                 }
00596                 else
00597                 {
00598                         // ...for multiple choice with multiple response
00599                         foreach ($_POST as $key => $value)
00600                         {
00601                                 if (preg_match("/answer_(\d+)/", $key, $matches))
00602                                 {
00603                                         $points = $_POST["points_$matches[1]"];
00604                                         if (preg_match("/\d+/", $points))
00605                                         {
00606                                                 if ($points < 0)
00607                                                 {
00608                                                         $points = 0.0;
00609                                                         sendInfo($this->lng->txt("negative_points_not_allowed"), true);
00610                                                 }
00611                                         }
00612                                         else
00613                                         {
00614                                                 $points = 0.0;
00615                                         }
00616                                         $this->object->add_answer(
00617                                                 ilUtil::stripSlashes($_POST["$key"]),
00618                                                 ilUtil::stripSlashes($points),
00619                                                 ilUtil::stripSlashes($_POST["status_$matches[1]"]),
00620                                                 ilUtil::stripSlashes($matches[1])
00621                                                 );
00622                                 }
00623                         }
00624                 }
00625 
00626                 // After adding all questions from the form we have to check if the learner pressed a delete button
00627                 foreach ($_POST as $key => $value)
00628                 {
00629                         // was one of the answers deleted
00630                         if (preg_match("/delete_(\d+)/", $key, $matches))
00631                         {
00632                                 $this->object->delete_answer($matches[1]);
00633                         }
00634                 }
00635 
00636                 // Set the question id from a hidden form parameter
00637                 if ($_POST["multiple_choice_id"] > 0)
00638                 {
00639                         $this->object->setId($_POST["multiple_choice_id"]);
00640                 }
00641                 
00642                 if ($saved)
00643                 {
00644                         // If the question was saved automatically before an upload, we have to make
00645                         // sure, that the state after the upload is saved. Otherwise the user could be
00646                         // irritated, if he presses cancel, because he only has the question state before
00647                         // the upload process.
00648                         $this->object->saveToDb();
00649                         $_GET["q_id"] = $this->object->getId();
00650                 }
00651 
00652                 return $result;
00653         }
00654 
00662         function outWorkingForm($test_id = "", $is_postponed = false, $showsolution = 0)
00663         {
00664                 global $ilUser;
00665                 $output = $this->outQuestionPage("MULTIPLE_CHOICE_QUESTION", $is_postponed);
00666 //              preg_match("/(<div[^<]*?ilc_Question.*?<\/div>)/is", $output, $matches);
00667 //              $solutionoutput = $matches[1];
00668                 $solutionoutput = preg_replace("/.*?(<div[^<]*?ilc_Question.*?<\/div>).*/", "\\1", $output);
00669                 $solutionoutput = preg_replace("/\"mc/", "\"solution_mc", $solutionoutput);
00670                 $solutionoutput = preg_replace("/multiple_choice_result/", "solution_multiple_choice_result", $solutionoutput);
00671                 // set solutions
00672                 if ($test_id)
00673                 {
00674                         $solutions =& $this->object->getSolutionValues($test_id);
00675                         foreach ($solutions as $idx => $solution_value)
00676                         {
00677                                 $repl_str = "dummy=\"mc".$solution_value->value1."\"";
00678 //echo "<br>".htmlentities($repl_str);
00679                                 $output = str_replace($repl_str, $repl_str." checked=\"checked\"", $output);
00680                         }
00681                 }
00682                 
00683                 $maxpoints = 0;
00684                 $maxindex = -1;
00685                 foreach ($this->object->answers as $idx => $answer)
00686                 {
00687                         if ($answer->get_points() > $maxpoints)
00688                         {
00689                                 $maxpoints = $answer->get_points();
00690                                 $maxindex = $idx;
00691                         }
00692                 }
00693                 foreach ($this->object->answers as $idx => $answer)
00694                 {
00695                         if ($this->object->get_response() == RESPONSE_MULTIPLE)
00696                         {
00697                                 if ($answer->isStateChecked() && ($answer->get_points() > 0))
00698                                 {
00699                                         $repl_str = "dummy=\"solution_mc$idx\"";
00700                                         $solutionoutput = str_replace($repl_str, $repl_str." checked=\"checked\"", $solutionoutput);
00701                                 }
00702                                 $sol = '(<em>';
00703                                 $sol .= '<input name="checkbox' . time() . $idx . '" type="checkbox" readonly="readonly" checked="checked" /> = ';
00704                                 if ($answer->isStateChecked())
00705                                 {
00706                                         $sol .= $answer->get_points();
00707                                 }
00708                                 else
00709                                 {
00710                                         $sol .= "0";
00711                                 }
00712                                 $sol .= ' ' . $this->lng->txt("points") . ', ';
00713                                 $sol .= '<input name="checkbox' . time() . $idx . '" type="checkbox" readonly="readonly" /> = ';
00714                                 if (!$answer->isStateChecked())
00715                                 {
00716                                         $sol .= $answer->get_points();
00717                                 }
00718                                 else
00719                                 {
00720                                         $sol .= "0";
00721                                 }
00722                                 $sol .= ' ' . $this->lng->txt("points");
00723                                 $sol .= '</em>)';
00724                                 $solutionoutput = preg_replace("/(<tr.*?dummy=\"solution_mc$idx.*?)<\/tr>/", "\\1<td>" . $sol . "</td></tr>", $solutionoutput);
00725                         }
00726                         else
00727                         {
00728                                 $sol = '(<em>';
00729                                 $sol .= '<input name="radio' . time() . $idx . '" type="radio" readonly="readonly" checked="checked" /> = ';
00730                                 if ($answer->isStateChecked())
00731                                 {
00732                                         $sol .= $answer->get_points();
00733                                 }
00734                                 else
00735                                 {
00736                                         $sol .= "0";
00737                                 }
00738                                 $sol .= ' ' . $this->lng->txt("points") . ', ';
00739                                 $sol .= '<input name="radio' . time() . $idx . '" type="radio" readonly="readonly" /> = ';
00740                                 if (!$answer->isStateChecked())
00741                                 {
00742                                         $sol .= $answer->get_points();
00743                                 }
00744                                 else
00745                                 {
00746                                         $sol .= "0";
00747                                 }
00748                                 $sol .= ' ' . $this->lng->txt("points");
00749                                 $sol .= '</em>)';
00750                                 $solutionoutput = preg_replace("/(<tr.*?dummy=\"solution_mc$idx.*?)<\/tr>/", "\\1<td>" . $sol . "</td></tr>", $solutionoutput);
00751                         }
00752                 }
00753                 if (($maxindex > -1) && ($this->object->get_response() == RESPONSE_SINGLE))
00754                 {
00755                         $repl_str = "dummy=\"solution_mc$maxindex\"";
00756                         $solutionoutput = str_replace($repl_str, $repl_str." checked=\"checked\"", $solutionoutput);
00757                 }
00758 
00759                 $solutionoutput = "<p>" . $this->lng->txt("correct_solution_is") . ":</p><p>$solutionoutput</p>";
00760                 if ($test_id) 
00761                 {
00762                         $received_points = "<p>" . sprintf($this->lng->txt("you_received_a_of_b_points"), $this->object->getReachedPoints($ilUser->id, $test_id), $this->object->getMaximumPoints()) . "</p>";
00763                 }
00764                 if (!$showsolution)
00765                 {
00766                         $solutionoutput = "";
00767                         $received_points = "";
00768                 }
00769                 $this->tpl->setVariable("MULTIPLE_CHOICE_QUESTION", $output.$solutionoutput.$received_points);
00770         }
00771 
00779         function outUserSolution($user_id, $test_id)
00780         {
00781                 $results = $this->object->getReachedInformation($user_id, $test_id);
00782                 foreach ($this->object->answers as $key => $answer)
00783                 {
00784                         $selected = 0;
00785                         $this->tpl->setCurrentBlock("tablerow");
00786                         if ($answer->isStateChecked())
00787                         {
00788                                 $right = 0;
00789                                 foreach ($results as $reskey => $resvalue)
00790                                 {
00791                                         if ($resvalue["value"] == $key)
00792                                         {
00793                                                 $right = 1;
00794                                                 $selected = 1;
00795                                         }
00796                                 }
00797                         }
00798                         elseif ($answer->isStateUnchecked())
00799                         {
00800                                 $right = 1;
00801                                 foreach ($results as $reskey => $resvalue)
00802                                 {
00803                                         if ($resvalue["value"] == $key)
00804                                         {
00805                                                 $right = 0;
00806                                                 $selected = 1;
00807                                         }
00808                                 }
00809                         }
00810                         if ($right)
00811                         {
00812                                 $this->tpl->setVariable("ANSWER_IMAGE", ilUtil::getImagePath("right.png", true));
00813                                 $this->tpl->setVariable("ANSWER_IMAGE_TITLE", $this->lng->txt("answer_is_right"));
00814                         }
00815                         else
00816                         {
00817                                 $this->tpl->setVariable("ANSWER_IMAGE", ilUtil::getImagePath("wrong.png", true));
00818                                 $this->tpl->setVariable("ANSWER_IMAGE_TITLE", $this->lng->txt("answer_is_wrong"));
00819                         }
00820                         if ($this->object->get_response() == RESPONSE_SINGLE)
00821                         {
00822                                 $state = $this->lng->txt("unselected");
00823                         }
00824                         else
00825                         {
00826                                 $state = $this->lng->txt("checkbox_unchecked");
00827                         }
00828                         if ($selected)
00829                         {
00830                                 if ($this->object->get_response() == RESPONSE_SINGLE)
00831                                 {
00832                                         $state = $this->lng->txt("selected");
00833                                 }
00834                                 else
00835                                 {
00836                                         $state = $this->lng->txt("checkbox_checked");
00837                                 }
00838                         }
00839                         $this->tpl->setVariable("ANSWER_DESCRIPTION", "$state: " . "&quot;<em>" . $answer->get_answertext() . "</em>&quot;");
00840                         $this->tpl->parseCurrentBlock();
00841                 }
00842         }
00843         
00844         function addSuggestedSolution()
00845         {
00846                 $_SESSION["subquestion_index"] = 0;
00847                 if ($_POST["cmd"]["addSuggestedSolution"])
00848                 {
00849                         $this->writePostData();
00850                         if (!$this->checkInput())
00851                         {
00852                                 sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
00853                                 $this->editQuestion();
00854                                 return;
00855                         }
00856                 }
00857                 $this->object->saveToDb();
00858                 $_GET["q_id"] = $this->object->getId();
00859                 $this->tpl->setVariable("HEADER", $this->object->getTitle());
00860                 if ($this->object->get_response() == RESPONSE_SINGLE)
00861                 {
00862                         $this->getQuestionTemplate("qt_multiple_choice_sr");
00863                 }
00864                 else
00865                 {
00866                         $this->getQuestionTemplate("qt_multiple_choice_mr");
00867                 }
00868                 parent::addSuggestedSolution();
00869         }
00870 }
00871 ?>

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