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

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

Generated on Fri Dec 13 2013 13:52:05 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1