• Main Page
  • Related Pages
  • 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 require_once "./assessment/classes/class.assQuestionGUI.php";
00025 require_once "./assessment/classes/class.assOrderingQuestion.php";
00026 
00038 class ASS_OrderingQuestionGUI extends ASS_QuestionGUI
00039 {
00040 
00049         function ASS_OrderingQuestionGUI(
00050                         $id = -1
00051         )
00052         {
00053                 $this->ASS_QuestionGUI();
00054                 $this->object = new ASS_OrderingQuestion();
00055                 if ($id >= 0)
00056                 {
00057                         $this->object->loadFromDb($id);
00058                 }
00059         }
00060 
00069         function getQuestionType()
00070         {
00071                 return "qt_ordering";
00072         }
00073 
00074         function getCommand($cmd)
00075         {
00076                 if (substr($cmd, 0, 6) == "delete")
00077                 {
00078                         $cmd = "delete";
00079                 }
00080                 if (substr($cmd, 0, 6) == "upload")
00081                 {
00082                         $cmd = "upload";
00083                 }
00084 
00085                 return $cmd;
00086         }
00087 
00088 
00096         function editQuestion($ok = true)
00097         {
00098                 $this->tpl->setVariable("HEADER", $this->object->getTitle());
00099                 $this->getQuestionTemplate("qt_ordering");
00100                 $this->tpl->addBlockFile("QUESTION_DATA", "question_data", "tpl.il_as_qpl_ordering.html", true);
00101 
00102                 // Output of existing answers
00103                 for ($i = 0; $i < $this->object->get_answer_count(); $i++)
00104                 {
00105                         $this->tpl->setCurrentBlock("deletebutton");
00106                         $this->tpl->setVariable("DELETE", $this->lng->txt("delete"));
00107                         $this->tpl->setVariable("ANSWER_ORDER", $i);
00108                         $this->tpl->parseCurrentBlock();
00109 
00110                         $thisanswer = $this->object->get_answer($i);
00111                         if ($this->object->get_ordering_type() == OQ_PICTURES)
00112                         {
00113                                 $this->tpl->setCurrentBlock("order_pictures");
00114                                 $this->tpl->setVariable("ANSWER_ORDER", $i);
00115                                 $this->tpl->setVariable("VALUE_ANSWER_COUNTER", $thisanswer->get_order() + 1);
00116                                 $this->tpl->setVariable("TEXT_ANSWER_PICTURE", $this->lng->txt("answer_picture"));
00117 
00118                                 $filename = $thisanswer->get_answertext();
00119                                 if ($filename)
00120                                 {
00121                                         $imagepath = $this->object->getImagePathWeb() . $thisanswer->get_answertext();
00122                                         $this->tpl->setVariable("UPLOADED_IMAGE", "<img src=\"$imagepath.thumb.jpg\" alt=\"" . $thisanswer->get_answertext() . "\" border=\"\" />");
00123                                         $this->tpl->setVariable("IMAGE_FILENAME", htmlspecialchars($thisanswer->get_answertext()));
00124                                         $this->tpl->setVariable("VALUE_ANSWER", "");
00125                                         //$thisanswer->get_answertext()
00126                                 }
00127                                 $this->tpl->setVariable("UPLOAD", $this->lng->txt("upload"));
00128                         }
00129                         elseif ($this->object->get_ordering_type() == OQ_TERMS)
00130                         {
00131                                 $this->tpl->setCurrentBlock("order_terms");
00132                                 $this->tpl->setVariable("VALUE_ANSWER_COUNTER", $thisanswer->get_order() + 1);
00133                                 $this->tpl->setVariable("TEXT_ANSWER_TEXT", $this->lng->txt("answer_text"));
00134                                 $this->tpl->setVariable("ANSWER_ORDER", $i);
00135                                 $this->tpl->setVariable("VALUE_ANSWER", htmlspecialchars($thisanswer->get_answertext()));
00136                         }
00137                         $this->tpl->parseCurrentBlock();
00138 
00139                         $this->tpl->setCurrentBlock("answers");
00140                         $anchor = "#answer_" . ($thisanswer->get_order() + 1);
00141                         $this->tpl->setVariable("TEXT_SOLUTION_ORDER", $this->lng->txt("solution_order"));
00142                         $this->tpl->setVariable("ANSWER_ORDER", $thisanswer->get_order());
00143                         $this->tpl->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
00144                         $this->tpl->setVariable("VALUE_ORDER", $thisanswer->get_solution_order());
00145                         $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
00146                         $this->tpl->setVariable("VALUE_ORDERING_POINTS", sprintf("%d", $thisanswer->get_points()));
00147                         $this->tpl->parseCurrentBlock();
00148                 }
00149 
00150                 if (($this->ctrl->getCmd() == "addItem") and ($ok))
00151                 {
00152                         if ($this->object->get_ordering_type() == OQ_PICTURES)
00153                         {
00154                                 $this->tpl->setCurrentBlock("order_pictures");
00155                                 $this->tpl->setVariable("ANSWER_ORDER", $this->object->get_answer_count());
00156                                 $this->tpl->setVariable("VALUE_ANSWER_COUNTER", $this->object->get_answer_count() + 1);
00157                                 $this->tpl->setVariable("VALUE_ANSWER", "");
00158                                 $this->tpl->setVariable("UPLOAD", $this->lng->txt("upload"));
00159                                 $this->tpl->setVariable("TEXT_ANSWER_PICTURE", $this->lng->txt("answer_picture"));
00160                         }
00161                         elseif ($this->object->get_ordering_type() == OQ_TERMS)
00162                         {
00163                                 $this->tpl->setCurrentBlock("order_terms");
00164                                 $this->tpl->setVariable("TEXT_ANSWER_TEXT", $this->lng->txt("answer_text"));
00165                                 $this->tpl->setVariable("VALUE_ANSWER_COUNTER", $this->object->get_answer_count() + 1);
00166                                 $this->tpl->setVariable("ANSWER_ORDER", $this->object->get_answer_count());
00167                                 $this->tpl->setVariable("VALUE_ASNWER", "");
00168                         }
00169                         $this->tpl->parseCurrentBlock();
00170 
00171                         // Create an empty answer
00172                         $this->tpl->setCurrentBlock("answers");
00173                         //$this->tpl->setVariable("TEXT_ANSWER_TEXT", $this->lng->txt("answer_text"));
00174                         $this->tpl->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
00175                         $anchor = "#answer_" . ($this->object->get_answer_count() + 1);
00176                         $this->tpl->setVariable("TEXT_SOLUTION_ORDER", $this->lng->txt("solution_order"));
00177                         $this->tpl->setVariable("ANSWER_ORDER", $this->object->get_answer_count());
00178                         $this->tpl->setVariable("VALUE_ORDER", $this->object->get_max_solution_order() + 1);
00179                         $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
00180                         $this->tpl->setVariable("VALUE_ORDERING_POINTS", sprintf("%d", 0));
00181                         $this->tpl->parseCurrentBlock();
00182                 }
00183                 // call to other question data i.e. estimated working time block
00184                 $this->outOtherQuestionData();
00185                 
00186                 $internallinks = array(
00187                         "lm" => $this->lng->txt("obj_lm"),
00188                         "st" => $this->lng->txt("obj_st"),
00189                         "pg" => $this->lng->txt("obj_pg"),
00190                         "glo" => $this->lng->txt("glossary_term")
00191                 );
00192                 foreach ($internallinks as $key => $value)
00193                 {
00194                         $this->tpl->setCurrentBlock("internallink");
00195                         $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00196                         $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00197                         $this->tpl->parseCurrentBlock();
00198                 }
00199                 
00200                 $this->tpl->setCurrentBlock("HeadContent");
00201                 $javascript = "<script type=\"text/javascript\">function initialSelect() {\n%s\n}</script>";
00202                 switch ($this->ctrl->getCmd())
00203                 {
00204                         case "addItem":
00205                                 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_ordering.answer_".($this->object->get_answer_count()).".focus(); document.frm_ordering.answer_".($this->object->get_answer_count()).".scrollIntoView(\"true\");"));
00206                                 break;
00207                         default:
00208                                 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_ordering.title.focus();"));
00209                                 break;
00210                 }
00211                 $this->tpl->parseCurrentBlock();
00212                 $this->tpl->setCurrentBlock("question_data");
00213                 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00214                 $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
00215                 $this->tpl->setVariable("TEXT_COMMENT", $this->lng->txt("description"));
00216                 $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
00217                 $this->tpl->setVariable("TEXT_SHUFFLE_ANSWERS", $this->lng->txt("shuffle_answers"));
00218                 $this->tpl->setVariable("TXT_YES", $this->lng->txt("yes"));
00219                 $this->tpl->setVariable("TXT_NO", $this->lng->txt("no"));
00220                 if ($this->object->getShuffle())
00221                 {
00222                         $this->tpl->setVariable("SELECTED_YES", " selected=\"selected\"");
00223                 }
00224                 else
00225                 {
00226                         $this->tpl->setVariable("SELECTED_NO", " selected=\"selected\"");
00227                 }
00228                 $this->tpl->setVariable("ORDERING_ID", $this->object->getId());
00229                 $this->tpl->setVariable("VALUE_ORDERING_TITLE", htmlspecialchars($this->object->getTitle()));
00230                 $this->tpl->setVariable("VALUE_ORDERING_COMMENT", htmlspecialchars($this->object->getComment()));
00231                 $this->tpl->setVariable("VALUE_ORDERING_AUTHOR", htmlspecialchars($this->object->getAuthor()));
00232                 $questiontext = $this->object->get_question();
00233                 $questiontext = preg_replace("/<br \/>/", "\n", $questiontext);
00234                 $this->tpl->setVariable("VALUE_QUESTION", htmlspecialchars($questiontext));
00235                 $this->tpl->setVariable("VALUE_ADD_ANSWER", $this->lng->txt("add_answer"));
00236                 $this->tpl->setVariable("TEXT_TYPE", $this->lng->txt("type"));
00237                 $this->tpl->setVariable("TEXT_TYPE_PICTURES", $this->lng->txt("order_pictures"));
00238                 $this->tpl->setVariable("TEXT_TYPE_TERMS", $this->lng->txt("order_terms"));
00239                 if ($this->object->get_ordering_type() == OQ_TERMS)
00240                 {
00241                         $this->tpl->setVariable("SELECTED_TERMS", " selected=\"selected\"");
00242                 }
00243                 elseif ($this->object->get_ordering_type() == OQ_PICTURES)
00244                 {
00245                         $this->tpl->setVariable("SELECTED_PICTURES", " selected=\"selected\"");
00246                 }
00247 
00248                 $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
00249                 if (count($this->object->suggested_solutions))
00250                 {
00251                         $solution_array = $this->object->getSuggestedSolution(0);
00252                         $href = ASS_Question::_getInternalLinkHref($solution_array["internal_link"]);
00253                         $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
00254                         $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
00255                         $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
00256                         $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
00257                 }
00258                 else
00259                 {
00260                         $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
00261                 }
00262 
00263                 $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
00264                 $this->tpl->setVariable("SAVE_EDIT", $this->lng->txt("save_edit"));
00265                 $this->tpl->setVariable("CANCEL", $this->lng->txt("cancel"));
00266                 $this->ctrl->setParameter($this, "sel_question_types", "qt_ordering");
00267                 $this->tpl->setVariable("ACTION_ORDERING_QUESTION",     $this->ctrl->getFormAction($this));
00268                 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00269                 $this->tpl->parseCurrentBlock();
00270 
00271                 if ($this->error)
00272                 {
00273                         sendInfo($this->error);
00274                 }
00275                 
00276                 $this->tpl->setCurrentBlock("adm_content");
00277                 $this->tpl->setVariable("BODY_ATTRIBUTES", " onload=\"initialSelect();\""); 
00278                 $this->tpl->parseCurrentBlock();
00279         }
00280 
00281 
00282         function addItem()
00283         {
00284                 $ok = true;
00285                 if (!$this->checkInput())
00286                 {
00287                         // You cannot add answers before you enter the required data
00288                         $this->error .= $this->lng->txt("fill_out_all_required_fields_add_answer") . "<br />";
00289                         $ok = false;
00290                 }
00291                 else
00292                 {
00293                         foreach ($_POST as $key => $value)
00294                         {
00295                                 if (preg_match("/answer_(\d+)/", $key, $matches))
00296                                 {
00297                                         if (!$value)
00298                                         {
00299                                                 $ok = false;
00300                                         }
00301                                 }
00302                         }
00303                 }
00304                 if (!$ok)
00305                 {
00306                         $this->error .= $this->lng->txt("fill_out_all_answer_fields") . "<br />";
00307                 }
00308 
00309                 $this->writePostData();
00310                 $this->editQuestion($ok);
00311         }
00312 
00316         function delete()
00317         {
00318                 $this->writePostData();
00319 
00320                 // Delete an answer if the delete button was pressed
00321                 foreach ($_POST[cmd] as $key => $value)
00322                 {
00323                         if (preg_match("/delete_(\d+)/", $key, $matches))
00324                         {
00325                                 $this->object->delete_answer($matches[1]);
00326                         }
00327                 }
00328                 $this->editQuestion();
00329         }
00330 
00334         function upload()
00335         {
00336                 $this->writePostData();
00337                 $this->editQuestion();
00338         }
00339 
00347         function outOtherQuestionData()
00348         {
00349                 $this->tpl->setCurrentBlock("other_question_data");
00350                 $est_working_time = $this->object->getEstimatedWorkingTime();
00351                 $this->tpl->setVariable("TEXT_WORKING_TIME", $this->lng->txt("working_time"));
00352                 $this->tpl->setVariable("TIME_FORMAT", $this->lng->txt("time_format"));
00353                 $this->tpl->setVariable("VALUE_WORKING_TIME", ilUtil::makeTimeSelect("Estimated", false, $est_working_time[h], $est_working_time[m], $est_working_time[s]));
00354                 $this->tpl->parseCurrentBlock();
00355         }
00356 
00365         function writePostData()
00366         {
00367                 $result = 0;
00368                 $saved = false;
00369 
00370                 // Delete all existing answers and create new answers from the form data
00371                 $this->object->flush_answers();
00372 
00373                 $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
00374                 $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
00375                 $this->object->setComment(ilUtil::stripSlashes($_POST["comment"]));
00376                 $questiontext = ilUtil::stripSlashes($_POST["question"], true, "<strong><em><code><cite>");
00377                 $questiontext = preg_replace("/\n/", "<br />", $questiontext);
00378                 $this->object->set_question($questiontext);
00379                 $this->object->setSuggestedSolution($_POST["solution_hint"], 0);
00380                 $this->object->setShuffle($_POST["shuffle"]);
00381 
00382                 // adding estimated working time
00383                 $saved = $saved | $this->writeOtherPostData($result);
00384                 $this->object->set_ordering_type($_POST["ordering_type"]);
00385 
00386                 // Add answers from the form
00387                 foreach ($_POST as $key => $value)
00388                 {
00389                         if (preg_match("/answer_(\d+)/", $key, $matches))
00390                         {
00391                                 if ($this->object->get_ordering_type() == OQ_PICTURES)
00392                                 {
00393                                         if ($_FILES[$key]["tmp_name"])
00394                                         {
00395                                                 // upload the ordering picture
00396                                                 if ($this->object->getId() <= 0)
00397                                                 {
00398                                                         $this->object->saveToDb();
00399                                                         $saved = true;
00400                                                         $this->error .= $this->lng->txt("question_saved_for_upload") . "<br />";
00401                                                 }
00402                                                 $upload_result = $this->object->set_image_file($_FILES[$key]['name'], $_FILES[$key]['tmp_name']);
00403                                                 switch ($upload_result)
00404                                                 {
00405                                                         case 0:
00406                                                                 $_POST[$key] = $_FILES[$key]['name'];
00407                                                                 break;
00408                                                         case 1:
00409                                                                 $this->error .= $this->lng->txt("error_image_upload_wrong_format") . "<br />";
00410                                                                 break;
00411                                                         case 2:
00412                                                                 $this->error .= $this->lng->txt("error_image_upload_copy_file") . "<br />";
00413                                                                 break;
00414                                                 }
00415                                         }
00416                                 }
00417                                 $points = $_POST["points_$matches[1]"];
00418                                 if (preg_match("/\d+/", $points))
00419                                 {
00420                                         if ($points < 0)
00421                                         {
00422                                                 $points = 0.0;
00423                                                 $this->error .= $this->lng->txt("negative_points_not_allowed") . "<br />";
00424                                         }
00425                                 }
00426                                 else
00427                                 {
00428                                         $points = 0.0;
00429                                 }
00430                                 $this->object->add_answer(
00431                                         ilUtil::stripSlashes($_POST["$key"]),
00432                                         ilUtil::stripSlashes($points),
00433                                         ilUtil::stripSlashes($matches[1]),
00434                                         ilUtil::stripSlashes($_POST["order_$matches[1]"])
00435                                 );
00436                         }
00437                 }
00438 
00439                 if ($saved)
00440                 {
00441                         // If the question was saved automatically before an upload, we have to make
00442                         // sure, that the state after the upload is saved. Otherwise the user could be
00443                         // irritated, if he presses cancel, because he only has the question state before
00444                         // the upload process.
00445                         $this->object->saveToDb();
00446                         $_GET["q_id"] = $this->object->getId();
00447                 }
00448                 return $result;
00449         }
00450 
00458         function outWorkingForm($test_id = "", $is_postponed = false, $showsolution = 0)
00459         {
00460                 global $ilUser;
00461                 
00462                 $output = $this->outQuestionPage("ORDERING_QUESTION", $is_postponed);
00463                 $output = preg_replace("/&#123;/", "{", $output);
00464                 $output = preg_replace("/&#125;/", "}", $output);
00465                 $solutionoutput = preg_replace("/.*?(<div[^<]*?ilc_Question.*?<\/div>).*/", "\\1", $output);
00466                 $solutionoutput = preg_replace("/\"ord/", "\"solution_ord", $solutionoutput);
00467                 $solutionoutput = preg_replace("/name\=\"order_/", "name=\"solution_order_", $solutionoutput);
00468                 // set solutions
00469                 $solution_script = "";
00470                 if ($test_id)
00471                 {
00472                         $solutions =& $this->object->getSolutionValues($test_id);
00473                         $solution_script .= "";//"resetValues();\n";
00474                         $jssolutions = array();
00475                         foreach ($solutions as $idx => $solution_value)
00476                         {
00477                                 if ($this->object->getOutputType() == OUTPUT_HTML)
00478                                 {
00479                                         $repl_str = "dummy=\"ord".$solution_value->value1."\"";
00480         //echo "<br>".$repl_str;
00481                                         $output = str_replace($repl_str, $repl_str." value=\"".$solution_value->value2."\"", $output);
00482                                 }
00483                                 else
00484                                 {
00485                                         $output = str_replace("initial_value_" . $solution_value->value1, $solution_value->value2, $output);
00486                                         if ((strcmp($solution_value->value2, "") != 0) && (strcmp($solution_value->value1, "") != 0))
00487                                         {
00488                                                 $jssolutions[$solution_value->value2] = $solution_value;
00489                                         }
00490                                 }
00491                         }
00492                         if ($this->object->getOutputType() == OUTPUT_JAVASCRIPT)
00493                         {
00494                                 if (count($jssolutions))
00495                                 {
00496                                         ksort($jssolutions, SORT_NUMERIC);
00497                                         $s = array();
00498                                         foreach ($jssolutions as $key => $value)
00499                                         {
00500                                                 array_push($s, $value->value1);
00501                                         }
00502                                         $solution_script .= "setSolution(new Array(" . join(",", $s). "));\n";
00503                                 }
00504                         }
00505                 }
00506 
00507                 if ($this->object->getOutputType() == OUTPUT_JAVASCRIPT)
00508                 {
00509                         if ($this->object->get_ordering_type() == OQ_PICTURES)
00510                         {
00511                                 foreach ($this->object->answers as $key => $answer)
00512                                 {
00513                                         $sizethumb = GetImageSize ($this->object->getImagePath() . $answer->get_answertext() . ".thumb.jpg");
00514                                         $sizeorig = GetImageSize ($this->object->getImagePath() . $answer->get_answertext());
00515                                         if ($sizethumb[0] >= $sizeorig[0])
00516                                         {
00517                                                 // thumbnail is larger than original -> remove enlarge image
00518                                                 $output = preg_replace("/<a[^>]*?>\s*<img[^>]*?enlarge[^>]*?>\s*<\/a>/", "", $output);
00519                                         }
00520                                         // add the image size to the thumbnails
00521                                         $output = preg_replace("/(<img[^>]*?".$answer->get_answertext()."[^>]*?)(\/{0,1}\s*)?>/", "\\1 " . $sizethumb[3] . "\\2", $output);
00522                                 }
00523                         }
00524                         $output = str_replace("// solution_script", "", $output);
00525                         $this->tpl->setVariable("JS_INITIALIZE", "<script type=\"text/javascript\">\nfunction show_solution() {\n$solution_script\n}\n</script>\n");
00526                         $this->tpl->setVariable("BODY_ATTRIBUTES", " onload=\"show_solution();\"");
00527                 }
00528                 
00529                 foreach ($this->object->answers as $idx => $answer)
00530                 {
00531                         $repl_str = "dummy=\"solution_ord$idx\"";
00532                         $solutionoutput = str_replace($repl_str, $repl_str." value=\"" . $answer->get_solution_order() . "\"", $solutionoutput);
00533                         $solutionoutput = preg_replace("/(<tr.*?dummy=\"solution_ord$idx.*?)<\/tr>/", "\\1<td>" . "<em>(" . $answer->get_points() . " " . $this->lng->txt("points") . ")</em>" . "</td></tr>", $solutionoutput);
00534                 }
00535 
00536                 $solutionoutput = "<p>" . $this->lng->txt("correct_solution_is") . ":</p><p>$solutionoutput</p>";
00537                 if ($test_id) 
00538                 {
00539                         $received_points = "<p>" . sprintf($this->lng->txt("you_received_a_of_b_points"), $this->object->getReachedPoints($ilUser->id, $test_id), $this->object->getMaximumPoints()) . "</p>";
00540                 }
00541                 if (!$showsolution)
00542                 {
00543                         $solutionoutput = "";
00544                         $received_points = "";
00545                 }
00546                 $this->tpl->setVariable("ORDERING_QUESTION", $output.$solutionoutput.$received_points);
00547         }
00548 
00556         function outUserSolution($user_id, $test_id)
00557         {
00558                 $results = $this->object->getReachedInformation($user_id, $test_id);
00559                 $user_order = array();
00560                 foreach ($results as $key => $value)
00561                 {
00562                         $user_order[$value["order"]] = $value["answer_id"];
00563                 }
00564                 ksort($user_order);
00565                 $user_order = array_values($user_order);
00566                 
00567                 $answer_order = array();
00568                 foreach ($this->answers as $key => $answer)
00569                 {
00570                         $answer_order[$answer->get_solution_order()] = $key;
00571                 }
00572                 ksort($answer_order);
00573                 $answer_order = array_values($answer_order);
00574                 foreach ($this->object->answers as $key => $answer)
00575                 {
00576                         $this->tpl->setCurrentBlock("tablerow");
00577                         $array_key = array_search($key);
00578                         if ($user_order[$array_key] == $answer_order[$array_key])
00579                         {
00580                                 $this->tpl->setVariable("ANSWER_IMAGE", ilUtil::getImagePath("right.png", true));
00581                                 $this->tpl->setVariable("ANSWER_IMAGE_TITLE", $this->lng->txt("answer_is_right"));
00582                         }
00583                         else
00584                         {
00585                                 $this->tpl->setVariable("ANSWER_IMAGE", ilUtil::getImagePath("wrong.png", true));
00586                                 $this->tpl->setVariable("ANSWER_IMAGE_TITLE", $this->lng->txt("answer_is_wrong"));
00587                         }
00588                         if ($this->object->get_ordering_type() == OQ_PICTURES)
00589                         {
00590                                 $answertext = "<img src=\"" . $this->object->getImagePathWeb() . $answer->get_answertext() . ".thumb.jpg\" alt=\"" . $this->lng->txt("selected_image") . "\" />";
00591                         }
00592                         else
00593                         {
00594                                 $answertext = "&quot;<em>" . $answer->get_answertext() . "</em>&quot;";
00595                         }
00596                         $this->tpl->setVariable("ANSWER_DESCRIPTION", $answertext);
00597                         $this->tpl->setVariable("ANSWER_DESCRIPTION_CONNECTOR", $this->lng->txt("with_order") . " &quot;<em>" . $results[$key]["order"] . "</em>&quot;");
00598                         $this->tpl->parseCurrentBlock();
00599                 }
00600         }
00601 
00605         function checkInput()
00606         {
00607                 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
00608                 {
00609                         return false;
00610                 }
00611                 return true;
00612         }
00613 
00614         function addSuggestedSolution()
00615         {
00616                 $_SESSION["subquestion_index"] = 0;
00617                 if ($_POST["cmd"]["addSuggestedSolution"])
00618                 {
00619                         $this->writePostData();
00620                         if (!$this->checkInput())
00621                         {
00622                                 sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
00623                                 $this->editQuestion();
00624                                 return;
00625                         }
00626                 }
00627                 $this->object->saveToDb();
00628                 $_GET["q_id"] = $this->object->getId();
00629                 $this->tpl->setVariable("HEADER", $this->object->getTitle());
00630                 $this->getQuestionTemplate("qt_ordering");
00631                 parent::addSuggestedSolution();
00632         }
00633 }
00634 ?>

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