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

Modules/TestQuestionPool/classes/class.assOrderingQuestionGUI.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 include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
00025 include_once "./Modules/Test/classes/inc.AssessmentConstants.php";
00026 
00037 class assOrderingQuestionGUI extends assQuestionGUI
00038 {
00039 
00048         function assOrderingQuestionGUI(
00049                         $id = -1
00050         )
00051         {
00052                 $this->assQuestionGUI();
00053                 include_once "./Modules/TestQuestionPool/classes/class.assOrderingQuestion.php";
00054                 $this->object = new assOrderingQuestion();
00055                 if ($id >= 0)
00056                 {
00057                         $this->object->loadFromDb($id);
00058                 }
00059         }
00060 
00061         function getCommand($cmd)
00062         {
00063                 if (substr($cmd, 0, 6) == "delete")
00064                 {
00065                         $cmd = "delete";
00066                 }
00067                 if (substr($cmd, 0, 6) == "upload")
00068                 {
00069                         $cmd = "upload";
00070                 }
00071 
00072                 return $cmd;
00073         }
00074 
00075 
00083         function editQuestion($ok = true)
00084         {
00085                 $multiline_answers = $this->object->getMultilineAnswerSetting();
00086                 $this->getQuestionTemplate();
00087                 $this->tpl->addBlockFile("QUESTION_DATA", "question_data", "tpl.il_as_qpl_ordering.html", "Modules/TestQuestionPool");
00088 
00089                 // Output of existing answers
00090                 for ($i = 0; $i < $this->object->getAnswerCount(); $i++)
00091                 {
00092                         $this->tpl->setCurrentBlock("deletebutton");
00093                         $this->tpl->setVariable("DELETE", $this->lng->txt("delete"));
00094                         $this->tpl->setVariable("ANSWER_ORDER", $i);
00095                         $this->tpl->parseCurrentBlock();
00096 
00097                         $thisanswer = $this->object->getAnswer($i);
00098                         if ($this->object->getOrderingType() == OQ_PICTURES)
00099                         {
00100                                 $this->tpl->setCurrentBlock("order_pictures");
00101                                 $this->tpl->setVariable("ANSWER_ORDER", $i);
00102                                 $this->tpl->setVariable("VALUE_ANSWER_COUNTER", $thisanswer->getOrder() + 1);
00103                                 $this->tpl->setVariable("TEXT_ANSWER_PICTURE", $this->lng->txt("answer_picture"));
00104 
00105                                 $filename = $thisanswer->getAnswertext();
00106                                 $extension = "jpg";
00107                                 if (preg_match("/.*\.(png|jpg|gif|jpeg)$/", $filename, $matches))
00108                                 {
00109                                         $extension = $matches[1];
00110                                 }
00111                                 if ($filename)
00112                                 {
00113                                         $imagepath = $this->object->getImagePathWeb() . $thisanswer->getAnswertext();
00114                                         $this->tpl->setVariable("UPLOADED_IMAGE", "<img src=\"$imagepath.thumb.jpg\" alt=\"" . $thisanswer->getAnswertext() . "\" border=\"\" />");
00115                                         $this->tpl->setVariable("IMAGE_FILENAME", ilUtil::prepareFormOutput($thisanswer->getAnswertext()));
00116                                         $this->tpl->setVariable("VALUE_ANSWER", "");
00117                                         //$thisanswer->getAnswertext()
00118                                 }
00119                                 $this->tpl->setVariable("UPLOAD", $this->lng->txt("upload"));
00120                         }
00121                         elseif ($this->object->getOrderingType() == OQ_TERMS)
00122                         {
00123                                 if ($multiline_answers)
00124                                 {
00125                                         $this->tpl->setCurrentBlock("show_textarea");
00126                                         $this->tpl->setVariable("ANSWER_ORDER", $i);
00127                                         $this->tpl->setVariable("VALUE_ANSWER", ilUtil::prepareFormOutput($thisanswer->getAnswertext()));
00128                                         $this->tpl->parseCurrentBlock();
00129                                 }
00130                                 else
00131                                 {
00132                                         $this->tpl->setCurrentBlock("show_textinput");
00133                                         $this->tpl->setVariable("ANSWER_ORDER", $i);
00134                                         $this->tpl->setVariable("VALUE_ANSWER", ilUtil::prepareFormOutput($thisanswer->getAnswertext()));
00135                                         $this->tpl->parseCurrentBlock();
00136                                 }
00137                         }
00138                         $this->tpl->parseCurrentBlock();
00139 
00140                         $this->tpl->setCurrentBlock("answers");
00141                         $anchor = "#answer_" . ($thisanswer->getOrder() + 1);
00142                         $this->tpl->setVariable("ANSWER_ORDER", $thisanswer->getOrder());
00143                         $this->tpl->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
00144                         $this->tpl->setVariable("VALUE_ORDER", $thisanswer->getSolutionOrder());
00145                         $this->tpl->setVariable("VALUE_ORDERING_POINTS", $thisanswer->getPoints());
00146                         $this->tpl->parseCurrentBlock();
00147                 }
00148 
00149                 if (($this->ctrl->getCmd() == "addItem") and ($ok))
00150                 {
00151                         if ($this->object->getOrderingType() == OQ_PICTURES)
00152                         {
00153                                 $this->tpl->setCurrentBlock("order_pictures");
00154                                 $this->tpl->setVariable("ANSWER_ORDER", $this->object->getAnswerCount());
00155                                 $this->tpl->setVariable("VALUE_ANSWER", "");
00156                                 $this->tpl->setVariable("UPLOAD", $this->lng->txt("upload"));
00157                         }
00158                         elseif ($this->object->getOrderingType() == OQ_TERMS)
00159                         {
00160                                 if ($multiline_answers)
00161                                 {
00162                                         $this->tpl->setCurrentBlock("show_textarea");
00163                                         $this->tpl->setVariable("ANSWER_ORDER", $i);
00164                                         $this->tpl->parseCurrentBlock();
00165                                 }
00166                                 else
00167                                 {
00168                                         $this->tpl->setCurrentBlock("show_textinput");
00169                                         $this->tpl->setVariable("ANSWER_ORDER", $i);
00170                                         $this->tpl->parseCurrentBlock();
00171                                 }
00172                         }
00173                         $this->tpl->parseCurrentBlock();
00174 
00175                         // Create an empty answer
00176                         $this->tpl->setCurrentBlock("answers");
00177                         //$this->tpl->setVariable("TEXT_ANSWER_TEXT", $this->lng->txt("answer_text"));
00178                         $this->tpl->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
00179                         $anchor = "#answer_" . ($this->object->getAnswerCount() + 1);
00180                         $this->tpl->setVariable("TEXT_SOLUTION_ORDER", $this->lng->txt("solution_order"));
00181                         $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
00182                         if ($this->object->getOrderingType() == OQ_PICTURES)
00183                         {
00184                                 $this->tpl->setVariable("TEXT_ANSWER_PICTURE", $this->lng->txt("answer_picture"));
00185                         }
00186                         else
00187                         {
00188                                 $this->tpl->setVariable("TEXT_ANSWER_TEXT", $this->lng->txt("answer_text"));
00189                         }
00190                         $this->tpl->setVariable("ANSWER_ORDER", $this->object->getAnswerCount());
00191                         $this->tpl->setVariable("VALUE_ORDER", $this->object->getMaxSolutionOrder() + 1);
00192                         $this->tpl->setVariable("VALUE_ORDERING_POINTS", sprintf("%s", 0));
00193                         $this->tpl->parseCurrentBlock();
00194                 }
00195                 // call to other question data i.e. estimated working time block
00196                 if ($this->object->getAnswerCount())
00197                 {
00198                         $this->tpl->setCurrentBlock("answerheader");
00199                         $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
00200                         if ($this->object->getOrderingType() == OQ_PICTURES)
00201                         {
00202                                 $this->tpl->setVariable("TEXT_ANSWER_PICTURE", $this->lng->txt("answer_picture"));
00203                         }
00204                         else
00205                         {
00206                                 $this->tpl->setVariable("TEXT_ANSWER_TEXT", $this->lng->txt("answer_text"));
00207                         }
00208                         $this->tpl->setVariable("TEXT_SOLUTION_ORDER", $this->lng->txt("solution_order"));
00209                         $this->tpl->parseCurrentBlock();
00210                 }
00211 
00212                 if ($this->object->getOrderingType() == OQ_TERMS)
00213                 {
00214                         if ($multiline_answers)
00215                         {
00216                                 $this->tpl->setVariable("SELECTED_SHOW_MULTILINE_ANSWERS", " selected=\"selected\"");
00217                         }
00218                         $this->tpl->setVariable("TEXT_HIDE_MULTILINE_ANSWERS", $this->lng->txt("multiline_terms_hide"));
00219                         $this->tpl->setVariable("TEXT_SHOW_MULTILINE_ANSWERS", $this->lng->txt("multiline_terms_show"));
00220                 }
00221                 
00222                 $this->outOtherQuestionData();
00223                 
00224                 $internallinks = array(
00225                         "lm" => $this->lng->txt("obj_lm"),
00226                         "st" => $this->lng->txt("obj_st"),
00227                         "pg" => $this->lng->txt("obj_pg"),
00228                         "glo" => $this->lng->txt("glossary_term")
00229                 );
00230                 foreach ($internallinks as $key => $value)
00231                 {
00232                         $this->tpl->setCurrentBlock("internallink");
00233                         $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00234                         $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00235                         $this->tpl->parseCurrentBlock();
00236                 }
00237                 
00238                 $this->tpl->setCurrentBlock("HeadContent");
00239                 $this->tpl->addJavascript("./Services/JavaScript/js/Basic.js");
00240                 $javascript = "<script type=\"text/javascript\">ilAddOnLoad(initialSelect);\n".
00241                         "function initialSelect() {\n%s\n}</script>";
00242                 switch ($this->ctrl->getCmd())
00243                 {
00244                         case "addItem":
00245                                 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_ordering.answer_".($this->object->getAnswerCount()).".focus(); document.frm_ordering.answer_".($this->object->getAnswerCount()).".scrollIntoView(\"true\");"));
00246                                 break;
00247                         default:
00248                                 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_ordering.title.focus();"));
00249                                 break;
00250                 }
00251                 $this->tpl->parseCurrentBlock();
00252                 $this->tpl->setCurrentBlock("question_data");
00253                 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00254                 $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
00255                 $this->tpl->setVariable("TEXT_COMMENT", $this->lng->txt("description"));
00256                 $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
00257                 $this->tpl->setVariable("TEXT_SHUFFLE_ANSWERS", $this->lng->txt("shuffle_answers"));
00258                 $this->tpl->setVariable("TXT_YES", $this->lng->txt("yes"));
00259                 $this->tpl->setVariable("TXT_NO", $this->lng->txt("no"));
00260                 if ($this->object->getShuffle())
00261                 {
00262                         $this->tpl->setVariable("SELECTED_YES", " selected=\"selected\"");
00263                 }
00264                 else
00265                 {
00266                         $this->tpl->setVariable("SELECTED_NO", " selected=\"selected\"");
00267                 }
00268                 $this->tpl->setVariable("ORDERING_ID", $this->object->getId());
00269                 $this->tpl->setVariable("VALUE_ORDERING_TITLE", ilUtil::prepareFormOutput($this->object->getTitle()));
00270                 $this->tpl->setVariable("VALUE_ORDERING_COMMENT", ilUtil::prepareFormOutput($this->object->getComment()));
00271                 $this->tpl->setVariable("VALUE_ORDERING_AUTHOR", ilUtil::prepareFormOutput($this->object->getAuthor()));
00272                 $questiontext = $this->object->getQuestion();
00273                 $this->tpl->setVariable("VALUE_QUESTION", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($questiontext)));
00274                 $this->tpl->setVariable("VALUE_ADD_ANSWER", $this->lng->txt("add_answer"));
00275                 $this->tpl->setVariable("TEXT_TYPE", $this->lng->txt("type"));
00276                 $this->tpl->setVariable("TEXT_TYPE_PICTURES", $this->lng->txt("order_pictures"));
00277                 $this->tpl->setVariable("TEXT_TYPE_TERMS", $this->lng->txt("order_terms"));
00278                 if ($this->object->getOrderingType() == OQ_TERMS)
00279                 {
00280                         $this->tpl->setVariable("SELECTED_TERMS", " selected=\"selected\"");
00281                 }
00282                 elseif ($this->object->getOrderingType() == OQ_PICTURES)
00283                 {
00284                         $this->tpl->setVariable("SELECTED_PICTURES", " selected=\"selected\"");
00285                 }
00286 
00287                 $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
00288                 if (count($this->object->suggested_solutions))
00289                 {
00290                         $solution_array = $this->object->getSuggestedSolution(0);
00291                         include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
00292                         $href = assQuestion::_getInternalLinkHref($solution_array["internal_link"]);
00293                         $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
00294                         $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
00295                         $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
00296                         $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
00297                 }
00298                 else
00299                 {
00300                         $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
00301                 }
00302 
00303                 $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
00304                 $this->tpl->setVariable("SAVE_EDIT", $this->lng->txt("save_edit"));
00305                 $this->tpl->setVariable("CANCEL", $this->lng->txt("cancel"));
00306                 $this->tpl->setVariable("SET_EDIT_MODE", $this->lng->txt("set_edit_mode"));
00307                 $this->ctrl->setParameter($this, "sel_question_types", "assOrderingQuestion");
00308                 $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt("assOrderingQuestion"));
00309                 $this->tpl->setVariable("ACTION_ORDERING_QUESTION",     $this->ctrl->getFormAction($this));
00310                 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00311                 $this->tpl->parseCurrentBlock();
00312 
00313                 if ($this->error)
00314                 {
00315                         ilUtil::sendInfo($this->error);
00316                 }
00317                 include_once "./Services/RTE/classes/class.ilRTE.php";
00318                 $rtestring = ilRTE::_getRTEClassname();
00319                 include_once "./Services/RTE/classes/class.$rtestring.php";
00320                 $rte = new $rtestring();
00321                 $rte->addPlugin("latex");
00322                 $rte->addButton("latex"); $rte->addButton("pastelatex");
00323                 include_once "./classes/class.ilObject.php";
00324                 $obj_id = $_GET["q_id"];
00325                 $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
00326                 $rte->addRTESupport($obj_id, $obj_type, "assessment");
00327                 
00328                 $this->tpl->setCurrentBlock("adm_content");
00329                 //$this->tpl->setVariable("BODY_ATTRIBUTES", " onload=\"initialSelect();\""); 
00330                 $this->tpl->parseCurrentBlock();
00331         }
00332 
00333 
00334         function addItem()
00335         {
00336                 $ok = true;
00337                 if (!$this->checkInput())
00338                 {
00339                         // You cannot add answers before you enter the required data
00340                         $this->error .= $this->lng->txt("fill_out_all_required_fields_add_answer") . "<br />";
00341                         $ok = false;
00342                 }
00343                 else
00344                 {
00345                         foreach ($_POST as $key => $value)
00346                         {
00347                                 if (preg_match("/answer_(\d+)/", $key, $matches))
00348                                 {
00349                                         if ((!$value) && ($this->object->getOrderingType() == OQ_TERMS))
00350                                         {
00351                                                 $ok = false;
00352                                         }
00353                                         if ($this->object->getOrderingType() == OQ_PICTURES)
00354                                         {
00355                                                 if ((!$_FILES[$key]["tmp_name"]) && (!$value))
00356                                                 {
00357                                                         $ok = false;
00358                                                 }
00359                                         }
00360                                 }
00361                         }
00362                 }
00363                 if (!$ok)
00364                 {
00365                         $this->error .= $this->lng->txt("fill_out_all_answer_fields") . "<br />";
00366                 }
00367 
00368                 $this->writePostData();
00369                 $this->editQuestion($ok);
00370         }
00371 
00375         function delete()
00376         {
00377                 $this->writePostData();
00378 
00379                 // Delete an answer if the delete button was pressed
00380                 foreach ($_POST[cmd] as $key => $value)
00381                 {
00382                         if (preg_match("/delete_(\d+)/", $key, $matches))
00383                         {
00384                                 $this->object->deleteAnswer($matches[1]);
00385                         }
00386                 }
00387                 //$this->ctrl->redirect($this, "editQuestion"); works only on save
00388                 $this->editQuestion();
00389         }
00390 
00394         function upload()
00395         {
00396                 $this->writePostData();
00397                 $this->editQuestion();
00398         }
00399 
00408         function writePostData()
00409         {
00410                 $result = 0;
00411                 $saved = false;
00412 
00413                 // Delete all existing answers and create new answers from the form data
00414                 $this->object->flushAnswers();
00415 
00416                 $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
00417                 $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
00418                 $this->object->setComment(ilUtil::stripSlashes($_POST["comment"]));
00419                 include_once "./classes/class.ilObjAdvancedEditing.php";
00420                 $questiontext = ilUtil::stripSlashes($_POST["question"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment"));
00421                 $this->object->setQuestion($questiontext);
00422                 $this->object->setSuggestedSolution($_POST["solution_hint"], 0);
00423                 $this->object->setShuffle($_POST["shuffle"]);
00424 
00425                 // adding estimated working time
00426                 $saved = $saved | $this->writeOtherPostData($result);
00427                 $this->object->setOrderingType($_POST["ordering_type"]);
00428                 if ($this->object->getOrderingType() == OQ_TERMS)
00429                 {
00430                         $this->object->setMultilineAnswerSetting($_POST["multilineAnswers"]);
00431                 }
00432 
00433                 // Add answers from the form
00434                 foreach ($_POST as $key => $value)
00435                 {
00436                         if (preg_match("/answer_(\d+)/", $key, $matches))
00437                         {
00438                                 if ($this->object->getOrderingType() == OQ_PICTURES)
00439                                 {
00440                                         if ($_FILES[$key]["tmp_name"])
00441                                         {
00442                                                 // upload the ordering picture
00443                                                 if ($this->object->getId() <= 0)
00444                                                 {
00445                                                         $this->object->saveToDb();
00446                                                         $saved = true;
00447                                                         $this->error .= $this->lng->txt("question_saved_for_upload") . "<br />";
00448                                                 }
00449                                                 $image_file = $this->object->createNewImageFileName($_FILES[$key]["name"]);
00450                                                 $upload_result = $this->object->setImageFile($image_file, $_FILES[$key]['tmp_name']);
00451                                                 switch ($upload_result)
00452                                                 {
00453                                                         case 0:
00454                                                                 $_POST[$key] = $image_file;
00455                                                                 break;
00456                                                         case 1:
00457                                                                 $this->error .= $this->lng->txt("error_image_upload_wrong_format") . "<br />";
00458                                                                 break;
00459                                                         case 2:
00460                                                                 $this->error .= $this->lng->txt("error_image_upload_copy_file") . "<br />";
00461                                                                 break;
00462                                                 }
00463                                         }
00464                                 }
00465                                 $points = $_POST["points_$matches[1]"];
00466                                 if ($points < 0)
00467                                 {
00468                                         $result = 1;
00469                                         $this->setErrorMessage($this->lng->txt("negative_points_not_allowed"));
00470                                 }
00471                                 $answer = $_POST["$key"];
00472                                 include_once "./classes/class.ilObjAdvancedEditing.php";
00473                                 $answer = ilUtil::stripSlashes($answer, false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment"));
00474                                 $this->object->addAnswer(
00475                                         $answer,
00476                                         ilUtil::stripSlashes($points),
00477                                         ilUtil::stripSlashes($matches[1]),
00478                                         ilUtil::stripSlashes($_POST["order_$matches[1]"])
00479                                 );
00480                         }
00481                 }
00482                 if ($saved)
00483                 {
00484                         // If the question was saved automatically before an upload, we have to make
00485                         // sure, that the state after the upload is saved. Otherwise the user could be
00486                         // irritated, if he presses cancel, because he only has the question state before
00487                         // the upload process.
00488                         $this->object->saveToDb();
00489                         $this->ctrl->setParameter($this, "q_id", $this->object->getId());
00490                 }
00491                 return $result;
00492         }
00493 
00494         function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $user_post_solution = FALSE)
00495         {
00496                 $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $user_post_solution);
00497                 $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
00498                 $this->tpl->setVariable("FORMACTION", $formaction);
00499         }
00500 
00501         function getSolutionOutput($active_id, $pass = NULL, $graphicalOutput = FALSE, $result_output = FALSE, $show_question_only = TRUE, $show_feedback = FALSE)
00502         {
00503                 // shuffle output
00504                 $keys = array_keys($this->object->answers);
00505 
00506                 // generate the question output
00507                 include_once "./classes/class.ilTemplate.php";
00508                 $template = new ilTemplate("tpl.il_as_qpl_ordering_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
00509                 $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
00510 
00511                 // get the solution of the user for the active pass or from the last pass if allowed
00512                 $solutions = array();
00513                 if ($active_id)
00514                 {
00515                         $solutions =& $this->object->getSolutionValues($active_id, $pass);
00516                 }
00517                 else
00518                 {
00519                         foreach ($this->object->answers as $index => $answer)
00520                         {
00521                                 array_push($solutions, array("value1" => $index, "value2" => $answer->getSolutionOrder()));
00522                         }
00523                 }
00524                 foreach ($keys as $idx)
00525                 {
00526                         $answer = $this->object->answers[$idx];
00527                         if ($active_id)
00528                         {
00529                                 if ($graphicalOutput)
00530                                 {
00531                                         $sol = array();
00532                                         foreach ($solutions as $solution)
00533                                         {
00534                                                 $sol[$solution["value1"]] = $solution["value2"];
00535                                         }
00536                                         asort($sol);
00537                                         $sol = array_keys($sol);
00538                                         $ans = array();
00539                                         foreach ($this->object->answers as $k => $a)
00540                                         {
00541                                                 $ans[$k] = $a->getSolutionOrder();
00542                                         }
00543                                         asort($ans);
00544                                         $ans = array_keys($ans);
00545                                         $ok = FALSE;
00546                                         foreach ($ans as $arr_idx => $ans_idx)
00547                                         {
00548                                                 if ($ans_idx == $idx)
00549                                                 {
00550                                                         if ($ans_idx == $sol[$arr_idx])
00551                                                         {
00552                                                                 $ok = TRUE;
00553                                                         }
00554                                                 }
00555                                         }
00556                                         // output of ok/not ok icons for user entered solutions
00557                                         if ($ok)
00558                                         {
00559                                                 $template->setCurrentBlock("icon_ok");
00560                                                 $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.gif"));
00561                                                 $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
00562                                                 $template->parseCurrentBlock();
00563                                         }
00564                                         else
00565                                         {
00566                                                 $template->setCurrentBlock("icon_ok");
00567                                                 $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
00568                                                 $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
00569                                                 $template->parseCurrentBlock();
00570                                         }
00571                                 }
00572                         }
00573                         if ($this->object->getOrderingType() == OQ_PICTURES)
00574                         {
00575                                 $template->setCurrentBlock("ordering_row_standard_pictures");
00576                                 $template->setVariable("THUMB_HREF", $this->object->getImagePathWeb() . $answer->getAnswertext() . ".thumb.jpg");
00577                                 $template->setVariable("THUMB_ALT", $this->lng->txt("thumbnail"));
00578                                 $template->setVariable("THUMB_TITLE", $this->lng->txt("enlarge"));
00579                                 $template->parseCurrentBlock();
00580                         }
00581                         else
00582                         {
00583                                 $template->setCurrentBlock("ordering_row_standard_text");
00584                                 $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
00585                                 $template->parseCurrentBlock();
00586                         }
00587                         $template->setCurrentBlock("ordering_row_standard");
00588                         if ($result_output)
00589                         {
00590                                 $answer = $this->object->answers[$idx];
00591                                 $points = $answer->getPoints();
00592                                 $resulttext = ($points == 1) ? "(%s " . $this->lng->txt("point") . ")" : "(%s " . $this->lng->txt("points") . ")"; 
00593                                 $template->setVariable("RESULT_OUTPUT", sprintf($resulttext, $points));
00594                         }
00595                         foreach ($solutions as $solution)
00596                         {
00597                                 if (strcmp($solution["value1"], $idx) == 0)
00598                                 {
00599                                         $template->setVariable("ANSWER_ORDER", $solution["value2"]);
00600                                 }
00601                         }
00602                         $template->parseCurrentBlock();
00603                 }
00604                 $questiontext = $this->object->getQuestion();
00605                 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00606                 $questionoutput = $template->get();
00607                 $feedback = ($show_feedback) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
00608                 if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $feedback);
00609                 $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
00610 
00611                 $solutionoutput = $solutiontemplate->get(); 
00612                 if (!$show_question_only)
00613                 {
00614                         // get page object output
00615                         $pageoutput = $this->getILIASPage();
00616                         $solutionoutput = "<div class=\"ilias_content\">" . preg_replace("/(<div( xmlns:xhtml\=\"http:\/\/www.w3.org\/1999\/xhtml\"){0,1} class\=\"ilc_Question\"><\/div>)/ims", "</div><div class=\"ilc_Question\">" . $solutionoutput . "</div><div class=\"ilias_content\">", $pageoutput) . "</div>";
00617                 }
00618                 return $solutionoutput;
00619         }
00620         
00621         function getPreview($show_question_only = FALSE)
00622         {
00623                 // shuffle output
00624                 $keys = array_keys($this->object->answers);
00625                 if ($this->object->getShuffle())
00626                 {
00627                         $keys = $this->object->pcArrayShuffle($keys);
00628                 }
00629 
00630                 // generate the question output
00631                 include_once "./classes/class.ilTemplate.php";
00632                 $template = new ilTemplate("tpl.il_as_qpl_ordering_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
00633 
00634                 foreach ($keys as $idx)
00635                 {
00636                         $answer = $this->object->answers[$idx];
00637                         if ($this->object->getOrderingType() == OQ_PICTURES)
00638                         {
00639                                 $template->setCurrentBlock("ordering_row_standard_pictures");
00640                                 $template->setVariable("PICTURE_HREF", $this->object->getImagePathWeb() . $answer->getAnswertext());
00641                                 $template->setVariable("THUMB_HREF", $this->object->getImagePathWeb() . $answer->getAnswertext() . ".thumb.jpg");
00642                                 $template->setVariable("THUMB_ALT", $this->lng->txt("thumbnail"));
00643                                 $template->setVariable("THUMB_TITLE", $this->lng->txt("enlarge"));
00644                                 $template->setVariable("ANSWER_ID", $idx);
00645                                 $template->parseCurrentBlock();
00646                         }
00647                         else
00648                         {
00649                                 $template->setCurrentBlock("ordering_row_standard_text");
00650                                 $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
00651                                 $template->setVariable("ANSWER_ID", $idx);
00652                                 $template->parseCurrentBlock();
00653                         }
00654                         $template->setCurrentBlock("ordering_row_standard");
00655                         $template->setVariable("ANSWER_ID", $idx);
00656                         $template->parseCurrentBlock();
00657                 }
00658 
00659                 $questiontext = $this->object->getQuestion();
00660                 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00661                 $questionoutput = $template->get();
00662                 if (!$show_question_only)
00663                 {
00664                         // get page object output
00665                         $pageoutput = $this->getILIASPage();
00666                         $questionoutput = preg_replace("/(<div( xmlns:xhtml\=\"http:\/\/www.w3.org\/1999\/xhtml\"){0,1} class\=\"ilc_Question\"><\/div>)/ims", $questionoutput, $pageoutput);
00667                 }
00668                 else
00669                 {
00670                         $questionoutput = preg_replace("/<div[^>]*?>(.*)<\/div>/is", "\\1", $questionoutput);
00671                 }
00672 
00673                 return $questionoutput;
00674         }
00675 
00676         function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $user_post_solution = FALSE)
00677         {
00678                 // shuffle output
00679                 $keys = array();
00680                 if (is_array($user_post_solution))
00681                 {
00682                         $keys = $_SESSION["ordering_keys"];
00683                 }
00684                 else
00685                 {
00686                         $keys = array_keys($this->object->answers);
00687                         if ($this->object->getShuffle())
00688                         {
00689                                 $keys = $this->object->pcArrayShuffle($keys);
00690                         }
00691                 }
00692                 $_SESSION["ordering_keys"] = $keys;
00693 
00694                 // get page object output
00695                 $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id);
00696                 // generate the question output
00697                 include_once "./classes/class.ilTemplate.php";
00698 
00699                 $template = new ilTemplate("tpl.il_as_qpl_ordering_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
00700                 if ($this->object->getOutputType() == OUTPUT_JAVASCRIPT)
00701                 {
00702                         // BEGIN: add javascript code for javascript enabled ordering questions
00703                         $this->tpl->addBlockFile("CONTENT_BLOCK", "head_content", "tpl.il_as_qpl_ordering_output_javascript.html", "Modules/TestQuestionPool");
00704                         $this->tpl->setCurrentBlock("head_content");
00705                         $this->tpl->setVariable("JS_LOCATION", "./Modules/TestQuestionPool/js/toolman/");
00706                         $this->tpl->parseCurrentBlock();
00707                         // END: add javascript code for javascript enabled ordering questions
00708                         
00709                         // BEGIN: add additional stylesheet for javascript enabled ordering questions
00710                         $this->tpl->setCurrentBlock("AdditionalStyle");
00711                         $this->tpl->setVariable("LOCATION_ADDITIONAL_STYLESHEET", ilUtil::getStyleSheetLocation("output", "test_javascript.css", "Modules/TestQuestionPool"));
00712                         $this->tpl->parseCurrentBlock();
00713                         // END: add additional stylesheet for javascript enabled ordering questions
00714                         
00715                         // BEGIN: onsubmit form action for javascript enabled ordering questions
00716                         $this->tpl->setVariable("ON_SUBMIT", "return saveOrder('orderlist');");
00717                         // END: onsubmit form action for javascript enabled ordering questions
00718                 }
00719 
00720                 // get the solution of the user for the active pass or from the last pass if allowed
00721                 if ($active_id)
00722                 {
00723                         $solutions = NULL;
00724                         include_once "./Modules/Test/classes/class.ilObjTest.php";
00725                         if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
00726                         {
00727                                 if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
00728                         }
00729                         if (is_array($user_post_solution)) 
00730                         {
00731                                 $solutions = array();
00732                                 foreach ($user_post_solution as $key => $value)
00733                                 {
00734                                         if (preg_match("/order_(\d+)/", $key, $matches))
00735                                         {
00736                                                 array_push($solutions, array("value1" => $matches[1], "value2" => $value));
00737                                         }
00738                                 }
00739                         }
00740                         else
00741                         {
00742                                 $solutions =& $this->object->getSolutionValues($active_id, $pass);
00743                         }
00744 
00745                         if ($this->object->getOutputType() == OUTPUT_JAVASCRIPT)
00746                         {
00747                                 $solution_script .= "";
00748                                 $jssolutions = array();
00749                                 foreach ($solutions as $idx => $solution_value)
00750                                 {
00751                                         if ((strcmp($solution_value["value2"], "") != 0) && (strcmp($solution_value["value1"], "") != 0))
00752                                         {
00753                                                 $jssolutions[$solution_value["value2"]] = $solution_value["value1"];
00754                                         }
00755                                 }
00756                                 if (count($jssolutions))
00757                                 {
00758                                         ksort($jssolutions);
00759                                         $js = "";
00760                                         foreach ($jssolutions as $key => $value)
00761                                         {
00762                                                 $js .= "initialorder.push($value);";
00763                                         }
00764                                         $js .= "restoreInitialOrder();";
00765                                 }
00766                                 if (strlen($js))
00767                                 {
00768                                         $template->setCurrentBlock("javascript_restore_order");
00769                                         $template->setVariable("RESTORE_ORDER", $js);
00770                                         $template->parseCurrentBlock();
00771                                 }
00772                         }
00773                 }
00774                 
00775                 if ($this->object->getOutputType() != OUTPUT_JAVASCRIPT)
00776                 {
00777                         foreach ($keys as $idx)
00778                         {
00779                                 $answer = $this->object->answers[$idx];
00780                                 if ($this->object->getOrderingType() == OQ_PICTURES)
00781                                 {
00782                                         $template->setCurrentBlock("ordering_row_standard_pictures");
00783                                         $template->setVariable("PICTURE_HREF", $this->object->getImagePathWeb() . $answer->getAnswertext());
00784                                         $template->setVariable("THUMB_HREF", $this->object->getImagePathWeb() . $answer->getAnswertext() . ".thumb.jpg");
00785                                         $template->setVariable("THUMB_ALT", $this->lng->txt("thumbnail"));
00786                                         $template->setVariable("THUMB_TITLE", $this->lng->txt("enlarge"));
00787                                         $template->setVariable("ANSWER_ID", $idx);
00788                                         $template->parseCurrentBlock();
00789                                 }
00790                                 else
00791                                 {
00792                                         $template->setCurrentBlock("ordering_row_standard_text");
00793                                         $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
00794                                         $template->setVariable("ANSWER_ID", $idx);
00795                                         $template->parseCurrentBlock();
00796                                 }
00797                                 $template->setCurrentBlock("ordering_row_standard");
00798                                 $template->setVariable("ANSWER_ID", $idx);
00799                                 if (is_array($solutions))
00800                                 {
00801                                         foreach ($solutions as $solution)
00802                                         {
00803                                                 if (($solution["value1"] == $idx) && (strlen($solution["value2"])))
00804                                                 {
00805                                                         $template->setVariable("ANSWER_ORDER", " value=\"" . $solution["value2"] . "\"");
00806                                                 }
00807                                         }
00808                                 }
00809                                 $template->parseCurrentBlock();
00810                         }
00811                 }
00812                 else
00813                 {
00814                         foreach ($keys as $idx)
00815                         {
00816                                 $answer = $this->object->answers[$idx];
00817                                 if ($this->object->getOrderingType() == OQ_PICTURES)
00818                                 {
00819                                         $template->setCurrentBlock("ordering_row_javascript_pictures");
00820                                         $template->setVariable("PICTURE_HREF", $this->object->getImagePathWeb() . $answer->getAnswertext());
00821                                         $template->setVariable("THUMB_HREF", $this->object->getImagePathWeb() . $answer->getAnswertext() . ".thumb.jpg");
00822                                         $template->setVariable("THUMB_ALT", $this->lng->txt("thumbnail"));
00823                                         $template->setVariable("THUMB_TITLE", $this->lng->txt("thumbnail"));
00824                                         $template->setVariable("ENLARGE_HREF", ilUtil::getImagePath("enlarge.gif", FALSE));
00825                                         $template->setVariable("ENLARGE_ALT", $this->lng->txt("enlarge"));
00826                                         $template->setVariable("ENLARGE_TITLE", $this->lng->txt("enlarge"));
00827                                         $template->setVariable("ANSWER_ID", $idx);
00828                                         $template->parseCurrentBlock();
00829                                 }
00830                                 else
00831                                 {
00832                                         $template->setCurrentBlock("ordering_row_javascript_text");
00833                                         $template->setVariable("ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
00834                                         $template->setVariable("ANSWER_ID", $idx);
00835                                         $template->parseCurrentBlock();
00836                                 }
00837                         }
00838                         $template->setCurrentBlock("ordering_with_javascript");
00839                         if ($this->object->getOrderingType() == OQ_PICTURES)
00840                         {
00841                                 $template->setVariable("RESET_POSITIONS", $this->lng->txt("reset_pictures"));
00842                         }
00843                         else
00844                         {
00845                                 $template->setVariable("RESET_POSITIONS", $this->lng->txt("reset_definitions"));
00846                         }
00847                         $template->parseCurrentBlock();
00848                 }
00849                 $questiontext = $this->object->getQuestion();
00850                 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00851                 $questionoutput = $template->get();
00852                 $questionoutput = preg_replace("/(<div( xmlns:xhtml\=\"http:\/\/www.w3.org\/1999\/xhtml\"){0,1} class\=\"ilc_Question\"><\/div>)/ims", $questionoutput, $pageoutput);
00853                 return $questionoutput;
00854         }
00855 
00859         function checkInput()
00860         {
00861                 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
00862                 {
00863                         return false;
00864                 }
00865                 return true;
00866         }
00867 
00868         function addSuggestedSolution()
00869         {
00870                 $_SESSION["subquestion_index"] = 0;
00871                 if ($_POST["cmd"]["addSuggestedSolution"])
00872                 {
00873                         if ($this->writePostData())
00874                         {
00875                                 ilUtil::sendInfo($this->getErrorMessage());
00876                                 $this->editQuestion();
00877                                 return;
00878                         }
00879                         if (!$this->checkInput())
00880                         {
00881                                 ilUtil::sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
00882                                 $this->editQuestion();
00883                                 return;
00884                         }
00885                 }
00886                 $this->object->saveToDb();
00887                 $this->ctrl->setParameter($this, "q_id", $this->object->getId());
00888                 $this->tpl->setVariable("HEADER", $this->object->getTitle());
00889                 $this->getQuestionTemplate();
00890                 parent::addSuggestedSolution();
00891         }
00892 
00893         function editMode()
00894         {
00895                 global $ilUser;
00896                 
00897                 if ($this->object->getOrderingType() == OQ_TERMS)
00898                 {
00899                         $this->object->setMultilineAnswerSetting($_POST["multilineAnswers"]);
00900                 }
00901                 $this->object->setOrderingType($_POST["ordering_type"]);
00902                 $this->writePostData();
00903                 $this->editQuestion();
00904         }
00905 
00913         function saveFeedback()
00914         {
00915                 include_once "./classes/class.ilObjAdvancedEditing.php";
00916                 $this->object->saveFeedbackGeneric(0, ilUtil::stripSlashes($_POST["feedback_incomplete"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment")));
00917                 $this->object->saveFeedbackGeneric(1, ilUtil::stripSlashes($_POST["feedback_complete"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment")));
00918                 $this->object->cleanupMediaObjectUsage();
00919                 parent::saveFeedback();
00920         }
00921 
00929         function feedback()
00930         {
00931                 $this->tpl->addBlockFile("ADM_CONTENT", "feedback", "tpl.il_as_qpl_ordering_feedback.html", "Modules/TestQuestionPool");
00932                 $this->tpl->setVariable("FEEDBACK_TEXT", $this->lng->txt("feedback"));
00933                 $this->tpl->setVariable("FEEDBACK_COMPLETE", $this->lng->txt("feedback_complete_solution"));
00934                 $this->tpl->setVariable("VALUE_FEEDBACK_COMPLETE", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(1)), FALSE));
00935                 $this->tpl->setVariable("FEEDBACK_INCOMPLETE", $this->lng->txt("feedback_incomplete_solution"));
00936                 $this->tpl->setVariable("VALUE_FEEDBACK_INCOMPLETE", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(0)), FALSE));
00937                 $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
00938                 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
00939 
00940                 include_once "./Services/RTE/classes/class.ilRTE.php";
00941                 $rtestring = ilRTE::_getRTEClassname();
00942                 include_once "./Services/RTE/classes/class.$rtestring.php";
00943                 $rte = new $rtestring();
00944                 $rte->addPlugin("latex");
00945                 $rte->addButton("latex"); $rte->addButton("pastelatex");
00946                 include_once "./classes/class.ilObject.php";
00947                 $obj_id = $_GET["q_id"];
00948                 $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
00949                 $rte->addRTESupport($obj_id, $obj_type, "assessment");
00950         }
00951 
00959         function setQuestionTabs()
00960         {
00961                 global $rbacsystem, $ilTabs;
00962                 
00963                 $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
00964                 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
00965                 $q_type = $this->object->getQuestionType();
00966 
00967                 if (strlen($q_type))
00968                 {
00969                         $classname = $q_type . "GUI";
00970                         $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
00971                         $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
00972                 }
00973 
00974                 if ($_GET["q_id"])
00975                 {
00976                         if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
00977                         {
00978                                 // edit page
00979                                 $ilTabs->addTarget("edit_content",
00980                                         $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "view"),
00981                                         array("view", "insert", "exec_pg"),
00982                                         "", "", $force_active);
00983                         }
00984         
00985                         // edit page
00986                         $ilTabs->addTarget("preview",
00987                                 $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
00988                                 array("preview"),
00989                                 "ilPageObjectGUI", "", $force_active);
00990                 }
00991 
00992                 $force_active = false;
00993                 if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
00994                 {
00995                         $url = "";
00996                         if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
00997                         $commands = $_POST["cmd"];
00998                         if (is_array($commands))
00999                         {
01000                                 foreach ($commands as $key => $value)
01001                                 {
01002                                         if (preg_match("/^delete_.*/", $key, $matches))
01003                                         {
01004                                                 $force_active = true;
01005                                         }
01006                                 }
01007                         }
01008                         // edit question properties
01009                         $ilTabs->addTarget("edit_properties",
01010                                 $url,
01011                                 array("editQuestion", "save", "cancel", "addSuggestedSolution",
01012                                         "cancelExplorer", "linkChilds", "removeSuggestedSolution", "editMode", "addItem", "upload", 
01013                                         "saveEdit"),
01014                                 $classname, "", $force_active);
01015                 }
01016 
01017                 if ($_GET["q_id"])
01018                 {
01019                         $ilTabs->addTarget("feedback",
01020                                 $this->ctrl->getLinkTargetByClass($classname, "feedback"),
01021                                 array("feedback", "saveFeedback"),
01022                                 $classname, "");
01023                 }
01024                 
01025                 // Assessment of questions sub menu entry
01026                 if ($_GET["q_id"])
01027                 {
01028                         $ilTabs->addTarget("statistics",
01029                                 $this->ctrl->getLinkTargetByClass($classname, "assessment"),
01030                                 array("assessment"),
01031                                 $classname, "");
01032                 }
01033                 
01034                 if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
01035                 {
01036                         $ref_id = $_GET["calling_test"];
01037                         if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
01038                         $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
01039                 }
01040                 else
01041                 {
01042                         $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
01043                 }
01044         }
01045 }
01046 ?>

Generated on Fri Dec 13 2013 17:56:54 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1