• 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                                 $extension = "jpg";
00120                                 if (preg_match("/.*\.(png|jpg|gif|jpeg)$/", $filename, $matches))
00121                                 {
00122                                         $extension = $matches[1];
00123                                 }
00124                                 if ($filename)
00125                                 {
00126                                         $imagepath = $this->object->getImagePathWeb() . $thisanswer->get_answertext();
00127                                         $this->tpl->setVariable("UPLOADED_IMAGE", "<img src=\"$imagepath.thumb.jpg\" alt=\"" . $thisanswer->get_answertext() . "\" border=\"\" />");
00128                                         $this->tpl->setVariable("IMAGE_FILENAME", htmlspecialchars($thisanswer->get_answertext()));
00129                                         $this->tpl->setVariable("VALUE_ANSWER", "");
00130                                         //$thisanswer->get_answertext()
00131                                 }
00132                                 $this->tpl->setVariable("UPLOAD", $this->lng->txt("upload"));
00133                         }
00134                         elseif ($this->object->get_ordering_type() == OQ_TERMS)
00135                         {
00136                                 $this->tpl->setCurrentBlock("order_terms");
00137                                 $this->tpl->setVariable("VALUE_ANSWER_COUNTER", $thisanswer->get_order() + 1);
00138                                 $this->tpl->setVariable("TEXT_ANSWER_TEXT", $this->lng->txt("answer_text"));
00139                                 $this->tpl->setVariable("ANSWER_ORDER", $i);
00140                                 $this->tpl->setVariable("VALUE_ANSWER", htmlspecialchars($thisanswer->get_answertext()));
00141                         }
00142                         $this->tpl->parseCurrentBlock();
00143 
00144                         $this->tpl->setCurrentBlock("answers");
00145                         $anchor = "#answer_" . ($thisanswer->get_order() + 1);
00146                         $this->tpl->setVariable("TEXT_SOLUTION_ORDER", $this->lng->txt("solution_order"));
00147                         $this->tpl->setVariable("ANSWER_ORDER", $thisanswer->get_order());
00148                         $this->tpl->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
00149                         $this->tpl->setVariable("VALUE_ORDER", $thisanswer->get_solution_order());
00150                         $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
00151                         $this->tpl->setVariable("VALUE_ORDERING_POINTS", sprintf("%d", $thisanswer->get_points()));
00152                         $this->tpl->parseCurrentBlock();
00153                 }
00154 
00155                 if (($this->ctrl->getCmd() == "addItem") and ($ok))
00156                 {
00157                         if ($this->object->get_ordering_type() == OQ_PICTURES)
00158                         {
00159                                 $this->tpl->setCurrentBlock("order_pictures");
00160                                 $this->tpl->setVariable("ANSWER_ORDER", $this->object->get_answer_count());
00161                                 $this->tpl->setVariable("VALUE_ANSWER_COUNTER", $this->object->get_answer_count() + 1);
00162                                 $this->tpl->setVariable("VALUE_ANSWER", "");
00163                                 $this->tpl->setVariable("UPLOAD", $this->lng->txt("upload"));
00164                                 $this->tpl->setVariable("TEXT_ANSWER_PICTURE", $this->lng->txt("answer_picture"));
00165                         }
00166                         elseif ($this->object->get_ordering_type() == OQ_TERMS)
00167                         {
00168                                 $this->tpl->setCurrentBlock("order_terms");
00169                                 $this->tpl->setVariable("TEXT_ANSWER_TEXT", $this->lng->txt("answer_text"));
00170                                 $this->tpl->setVariable("VALUE_ANSWER_COUNTER", $this->object->get_answer_count() + 1);
00171                                 $this->tpl->setVariable("ANSWER_ORDER", $this->object->get_answer_count());
00172                                 $this->tpl->setVariable("VALUE_ASNWER", "");
00173                         }
00174                         $this->tpl->parseCurrentBlock();
00175 
00176                         // Create an empty answer
00177                         $this->tpl->setCurrentBlock("answers");
00178                         //$this->tpl->setVariable("TEXT_ANSWER_TEXT", $this->lng->txt("answer_text"));
00179                         $this->tpl->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
00180                         $anchor = "#answer_" . ($this->object->get_answer_count() + 1);
00181                         $this->tpl->setVariable("TEXT_SOLUTION_ORDER", $this->lng->txt("solution_order"));
00182                         $this->tpl->setVariable("ANSWER_ORDER", $this->object->get_answer_count());
00183                         $this->tpl->setVariable("VALUE_ORDER", $this->object->get_max_solution_order() + 1);
00184                         $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("points"));
00185                         $this->tpl->setVariable("VALUE_ORDERING_POINTS", sprintf("%d", 0));
00186                         $this->tpl->parseCurrentBlock();
00187                 }
00188                 // call to other question data i.e. estimated working time block
00189                 $this->outOtherQuestionData();
00190                 
00191                 $internallinks = array(
00192                         "lm" => $this->lng->txt("obj_lm"),
00193                         "st" => $this->lng->txt("obj_st"),
00194                         "pg" => $this->lng->txt("obj_pg"),
00195                         "glo" => $this->lng->txt("glossary_term")
00196                 );
00197                 foreach ($internallinks as $key => $value)
00198                 {
00199                         $this->tpl->setCurrentBlock("internallink");
00200                         $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00201                         $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00202                         $this->tpl->parseCurrentBlock();
00203                 }
00204                 
00205                 $this->tpl->setCurrentBlock("HeadContent");
00206                 $javascript = "<script type=\"text/javascript\">function initialSelect() {\n%s\n}</script>";
00207                 switch ($this->ctrl->getCmd())
00208                 {
00209                         case "addItem":
00210                                 $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\");"));
00211                                 break;
00212                         default:
00213                                 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_ordering.title.focus();"));
00214                                 break;
00215                 }
00216                 $this->tpl->parseCurrentBlock();
00217                 $this->tpl->setCurrentBlock("question_data");
00218                 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00219                 $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
00220                 $this->tpl->setVariable("TEXT_COMMENT", $this->lng->txt("description"));
00221                 $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
00222                 $this->tpl->setVariable("TEXT_SHUFFLE_ANSWERS", $this->lng->txt("shuffle_answers"));
00223                 $this->tpl->setVariable("TXT_YES", $this->lng->txt("yes"));
00224                 $this->tpl->setVariable("TXT_NO", $this->lng->txt("no"));
00225                 if ($this->object->getShuffle())
00226                 {
00227                         $this->tpl->setVariable("SELECTED_YES", " selected=\"selected\"");
00228                 }
00229                 else
00230                 {
00231                         $this->tpl->setVariable("SELECTED_NO", " selected=\"selected\"");
00232                 }
00233                 $this->tpl->setVariable("ORDERING_ID", $this->object->getId());
00234                 $this->tpl->setVariable("VALUE_ORDERING_TITLE", htmlspecialchars($this->object->getTitle()));
00235                 $this->tpl->setVariable("VALUE_ORDERING_COMMENT", htmlspecialchars($this->object->getComment()));
00236                 $this->tpl->setVariable("VALUE_ORDERING_AUTHOR", htmlspecialchars($this->object->getAuthor()));
00237                 $questiontext = $this->object->get_question();
00238                 $questiontext = preg_replace("/<br \/>/", "\n", $questiontext);
00239                 $this->tpl->setVariable("VALUE_QUESTION", htmlspecialchars($questiontext));
00240                 $this->tpl->setVariable("VALUE_ADD_ANSWER", $this->lng->txt("add_answer"));
00241                 $this->tpl->setVariable("TEXT_TYPE", $this->lng->txt("type"));
00242                 $this->tpl->setVariable("TEXT_TYPE_PICTURES", $this->lng->txt("order_pictures"));
00243                 $this->tpl->setVariable("TEXT_TYPE_TERMS", $this->lng->txt("order_terms"));
00244                 if ($this->object->get_ordering_type() == OQ_TERMS)
00245                 {
00246                         $this->tpl->setVariable("SELECTED_TERMS", " selected=\"selected\"");
00247                 }
00248                 elseif ($this->object->get_ordering_type() == OQ_PICTURES)
00249                 {
00250                         $this->tpl->setVariable("SELECTED_PICTURES", " selected=\"selected\"");
00251                 }
00252 
00253                 $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
00254                 if (count($this->object->suggested_solutions))
00255                 {
00256                         $solution_array = $this->object->getSuggestedSolution(0);
00257                         $href = ASS_Question::_getInternalLinkHref($solution_array["internal_link"]);
00258                         $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
00259                         $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
00260                         $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
00261                         $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
00262                 }
00263                 else
00264                 {
00265                         $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
00266                 }
00267 
00268                 $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
00269                 $this->tpl->setVariable("SAVE_EDIT", $this->lng->txt("save_edit"));
00270                 $this->tpl->setVariable("CANCEL", $this->lng->txt("cancel"));
00271                 $this->ctrl->setParameter($this, "sel_question_types", "qt_ordering");
00272                 $this->tpl->setVariable("ACTION_ORDERING_QUESTION",     $this->ctrl->getFormAction($this));
00273                 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00274                 $this->tpl->parseCurrentBlock();
00275 
00276                 if ($this->error)
00277                 {
00278                         sendInfo($this->error);
00279                 }
00280                 
00281                 $this->tpl->setCurrentBlock("adm_content");
00282                 $this->tpl->setVariable("BODY_ATTRIBUTES", " onload=\"initialSelect();\""); 
00283                 $this->tpl->parseCurrentBlock();
00284         }
00285 
00286 
00287         function addItem()
00288         {
00289                 $ok = true;
00290                 if (!$this->checkInput())
00291                 {
00292                         // You cannot add answers before you enter the required data
00293                         $this->error .= $this->lng->txt("fill_out_all_required_fields_add_answer") . "<br />";
00294                         $ok = false;
00295                 }
00296                 else
00297                 {
00298                         foreach ($_POST as $key => $value)
00299                         {
00300                                 if (preg_match("/answer_(\d+)/", $key, $matches))
00301                                 {
00302                                         if (!$value)
00303                                         {
00304                                                 $ok = false;
00305                                         }
00306                                 }
00307                         }
00308                 }
00309                 if (!$ok)
00310                 {
00311                         $this->error .= $this->lng->txt("fill_out_all_answer_fields") . "<br />";
00312                 }
00313 
00314                 $this->writePostData();
00315                 $this->editQuestion($ok);
00316         }
00317 
00321         function delete()
00322         {
00323                 $this->writePostData();
00324 
00325                 // Delete an answer if the delete button was pressed
00326                 foreach ($_POST[cmd] as $key => $value)
00327                 {
00328                         if (preg_match("/delete_(\d+)/", $key, $matches))
00329                         {
00330                                 $this->object->delete_answer($matches[1]);
00331                         }
00332                 }
00333                 $this->editQuestion();
00334         }
00335 
00339         function upload()
00340         {
00341                 $this->writePostData();
00342                 $this->editQuestion();
00343         }
00344 
00352         function outOtherQuestionData()
00353         {
00354                 $this->tpl->setCurrentBlock("other_question_data");
00355                 $est_working_time = $this->object->getEstimatedWorkingTime();
00356                 $this->tpl->setVariable("TEXT_WORKING_TIME", $this->lng->txt("working_time"));
00357                 $this->tpl->setVariable("TIME_FORMAT", $this->lng->txt("time_format"));
00358                 $this->tpl->setVariable("VALUE_WORKING_TIME", ilUtil::makeTimeSelect("Estimated", false, $est_working_time[h], $est_working_time[m], $est_working_time[s]));
00359                 $this->tpl->parseCurrentBlock();
00360         }
00361 
00370         function writePostData()
00371         {
00372                 $result = 0;
00373                 $saved = false;
00374 
00375                 // Delete all existing answers and create new answers from the form data
00376                 $this->object->flush_answers();
00377 
00378                 $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
00379                 $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
00380                 $this->object->setComment(ilUtil::stripSlashes($_POST["comment"]));
00381                 $questiontext = ilUtil::stripSlashes($_POST["question"], true, "<strong><em><code><cite>");
00382                 $questiontext = preg_replace("/\n/", "<br />", $questiontext);
00383                 $this->object->set_question($questiontext);
00384                 $this->object->setSuggestedSolution($_POST["solution_hint"], 0);
00385                 $this->object->setShuffle($_POST["shuffle"]);
00386 
00387                 // adding estimated working time
00388                 $saved = $saved | $this->writeOtherPostData($result);
00389                 $this->object->set_ordering_type($_POST["ordering_type"]);
00390 
00391                 // Add answers from the form
00392                 foreach ($_POST as $key => $value)
00393                 {
00394                         if (preg_match("/answer_(\d+)/", $key, $matches))
00395                         {
00396                                 if ($this->object->get_ordering_type() == OQ_PICTURES)
00397                                 {
00398                                         if ($_FILES[$key]["tmp_name"])
00399                                         {
00400                                                 // upload the ordering picture
00401                                                 if ($this->object->getId() <= 0)
00402                                                 {
00403                                                         $this->object->saveToDb();
00404                                                         $saved = true;
00405                                                         $this->error .= $this->lng->txt("question_saved_for_upload") . "<br />";
00406                                                 }
00407                                                 $image_file = $_FILES[$key]["name"];
00408                                                 $image_file = str_replace(" ", "_", $image_file);
00409                                                 $upload_result = $this->object->set_image_file($image_file, $_FILES[$key]['tmp_name']);
00410                                                 switch ($upload_result)
00411                                                 {
00412                                                         case 0:
00413                                                                 $_POST[$key] = $image_file;
00414                                                                 break;
00415                                                         case 1:
00416                                                                 $this->error .= $this->lng->txt("error_image_upload_wrong_format") . "<br />";
00417                                                                 break;
00418                                                         case 2:
00419                                                                 $this->error .= $this->lng->txt("error_image_upload_copy_file") . "<br />";
00420                                                                 break;
00421                                                 }
00422                                         }
00423                                 }
00424                                 $points = $_POST["points_$matches[1]"];
00425                                 if (preg_match("/\d+/", $points))
00426                                 {
00427                                         if ($points < 0)
00428                                         {
00429                                                 $points = 0.0;
00430                                                 $this->error .= $this->lng->txt("negative_points_not_allowed") . "<br />";
00431                                         }
00432                                 }
00433                                 else
00434                                 {
00435                                         $points = 0.0;
00436                                 }
00437                                 $this->object->add_answer(
00438                                         ilUtil::stripSlashes($_POST["$key"]),
00439                                         ilUtil::stripSlashes($points),
00440                                         ilUtil::stripSlashes($matches[1]),
00441                                         ilUtil::stripSlashes($_POST["order_$matches[1]"])
00442                                 );
00443                         }
00444                 }
00445 
00446                 if ($saved)
00447                 {
00448                         // If the question was saved automatically before an upload, we have to make
00449                         // sure, that the state after the upload is saved. Otherwise the user could be
00450                         // irritated, if he presses cancel, because he only has the question state before
00451                         // the upload process.
00452                         $this->object->saveToDb();
00453                         $_GET["q_id"] = $this->object->getId();
00454                 }
00455                 return $result;
00456         }
00457 
00465         function outWorkingForm($test_id = "", $is_postponed = false, $showsolution = 0, $show_question_page=true, $show_solution_only = false, $ilUser = null)
00466         {
00467                 if (!is_object($ilUser)) 
00468                 {
00469                         global $ilUser;
00470                 }
00471                 
00472                 $output = $this->outQuestionPage(($show_solution_only)?"":"ORDERING_QUESTION", $is_postponed,"", !$show_question_page);
00473                 $output = preg_replace("/&#123;/", "{", $output);
00474                 $output = preg_replace("/&#125;/", "}", $output);
00475 
00476                 if ($showsolution)
00477                 {
00478                         $solutionintroduction = "<p>" . $this->lng->txt("tst_your_answer_was") . "</p>";
00479                         $output = preg_replace("/(<div[^<]*?ilc_PageTitle.*?<\/div>)/", "\\1" . $solutionintroduction, $output);
00480                 }
00481                 $solutionoutput = preg_replace("/.*?(<div[^<]*?ilc_Question.*?<\/div>).*/", "\\1", $output);
00482                 $solutionoutput = preg_replace("/\"ord/", "\"solution_ord", $solutionoutput);
00483                 $solutionoutput = preg_replace("/name\=\"order_/", "name=\"solution_order_", $solutionoutput);
00484                 
00485                 
00486                 if (!$show_question_page)
00487                         $output = preg_replace("/.*?(<div[^<]*?ilc_Question.*?<\/div>).*/", "\\1", $output);
00488                         
00489                 // if wants solution only then strip the question element from output
00490                 if ($show_solution_only) 
00491                 {
00492                         $output = preg_replace("/(<div[^<]*?ilc_Question[^>]*>.*?<\/div>)/", "", $output);
00493                 }
00494                 
00495                         
00496                 // set solutions
00497                 $solution_script = "";
00498                 if ($test_id)
00499                 {
00500                         $solutions =& $this->object->getSolutionValues($test_id, $ilUser);
00501                         $solution_script .= "";//"resetValues();\n";
00502                         $jssolutions = array();
00503                         if (count($solutions))
00504                         {
00505                                 foreach ($solutions as $idx => $solution_value)
00506                                 {
00507                                         if ($this->object->getOutputType() == OUTPUT_HTML || !$show_question_page)
00508                                         {
00509                                                 $repl_str = "dummy=\"ord".$solution_value->value1."\"";
00510                 //echo "<br>".$repl_str;
00511                                                 if (!$show_question_page)
00512                                                         $output = $this->replaceInputElements($repl_str, $solution_value->value2, $output, "[","]"); 
00513                                                         /*$output = preg_replace ("/(<input[^>]*?$repl_str.*?>)/" ,"[".$solution_value->value2."] ", $output);*/
00514                                                 else 
00515                                                         $output = str_replace($repl_str, $repl_str." value=\"".$solution_value->value2."\"", $output);
00516                                         }
00517                                         else
00518                                         {
00519                                                 $output = str_replace("initial_value_" . $solution_value->value1, $solution_value->value2, $output);
00520                                                 if ((strcmp($solution_value->value2, "") != 0) && (strcmp($solution_value->value1, "") != 0))
00521                                                 {
00522                                                         $jssolutions[$solution_value->value2] = $solution_value->value1;
00523                                                 }
00524                                         }
00525                                 }
00526                         }
00527                         else
00528                         {
00529                                 // generate values for javascript output in the initial state to
00530                                 // prevent setting the question as not answered when the correct answer
00531                                 // is the initial state and the user just clicks previous or next
00532                                 // shuffle
00533                                 if ($this->object->getOutputType() == OUTPUT_JAVASCRIPT)
00534                                 {
00535                                         $akeys = array_keys($this->object->answers);
00536                                         $okeys = $akeys;
00537                                         if ($this->object->getshuffle())
00538                                         {
00539                                                 $akeys = $this->object->pcArrayShuffle($akeys);
00540                                         }
00541                                         foreach ($okeys as $idx => $value)
00542                                         {
00543                                                 $output = str_replace("initial_value_" . $value, $akeys[$idx], $output);
00544                                                 $jssolutions[$akeys[$idx]] = $value;
00545                                         }
00546                                 }
00547                         }
00548                         if (!$show_question_page) 
00549                         {
00550                                 //echo htmlentities ($output);
00551                                 $output = $this->removeFormElements($output);
00552                         }
00553                         if ($this->object->getOutputType() == OUTPUT_JAVASCRIPT)
00554                         {
00555                                 if (count($jssolutions))
00556                                 {
00557                                         ksort($jssolutions, SORT_NUMERIC);
00558                                         $s = array();
00559                                         foreach ($jssolutions as $key => $value)
00560                                         {
00561                                                 array_push($s, $value);
00562                                         }
00563                                         $solution_script .= "setSolution(new Array(" . join(",", $s). "));\n";
00564                                 }
00565                         }
00566                 }
00567 
00568                 if ($this->object->getOutputType() == OUTPUT_JAVASCRIPT)
00569                 {
00570                         if ($this->object->get_ordering_type() == OQ_PICTURES)
00571                         {
00572                                 foreach ($this->object->answers as $key => $answer)
00573                                 {
00574                                         $extension = "jpg";
00575                                         if (preg_match("/.*\.(png|jpg|gif|jpeg)$/", $answer->get_answertext(), $matches))
00576                                         {
00577                                                 $extension = $matches[1];
00578                                         }
00579                                         $sizethumb = GetImageSize ($this->object->getImagePath() . $answer->get_answertext() . ".thumb.jpg");
00580                                         $sizeorig = GetImageSize ($this->object->getImagePath() . $answer->get_answertext());
00581                                         if ($sizethumb[0] >= $sizeorig[0])
00582                                         {
00583                                                 // thumbnail is larger than original -> remove enlarge image
00584                                                 $output = preg_replace("/<a[^>]*?>\s*<img[^>]*?enlarge[^>]*?>\s*<\/a>/", "", $output);
00585                                         }
00586                                         // add the image size to the thumbnails
00587                                         $output = preg_replace("/(<img[^>]*?".$answer->get_answertext()."[^>]*?)(\/{0,1}\s*)?>/", "\\1 " . $sizethumb[3] . "\\2", $output);
00588                                 }
00589                         }
00590                         $output = str_replace("// solution_script", "", $output);
00591                         $this->tpl->setVariable("JS_INITIALIZE", "<script type=\"text/javascript\">\nfunction show_solution() {\n$solution_script\n}\n</script>\n");
00592                         $this->tpl->setVariable("BODY_ATTRIBUTES", " onload=\"show_solution();\"");
00593                 }
00594                 
00595                 foreach ($this->object->answers as $idx => $answer)
00596                 {
00597                         $repl_str = "dummy=\"solution_ord$idx\"";
00598                         $solutionoutput = str_replace($repl_str, $repl_str." value=\"" . $answer->get_solution_order() . "\"", $solutionoutput);
00599                         $solutionoutput = preg_replace("/(<tr.*?dummy=\"solution_ord$idx" . "[^\d].*?)<\/tr>/", "\\1<td>" . "<em>(" . $answer->get_points() . " " . $this->lng->txt("points") . ")</em>" . "</td></tr>", $solutionoutput);
00600                         if ($show_solution_only)
00601                                 $solutionoutput = $this->replaceInputElements($repl_str, $answer->get_solution_order(), $solutionoutput , "[" , "]");
00602                 }
00603 
00604                 $solutionoutput = "<p>" . $this->lng->txt("correct_solution_is") . ":</p><p>$solutionoutput</p>";
00605                 if ($test_id) 
00606                 {
00607                         $reached_points = $this->object->getReachedPoints($ilUser->id, $test_id);
00608                         $received_points = "<p>" . sprintf($this->lng->txt("you_received_a_of_b_points"), $reached_points, $this->object->getMaximumPoints());
00609                         $count_comment = "";
00610                         if ($reached_points == 0)
00611                         {
00612                                 $count_comment = $this->object->getSolutionCommentCountSystem($test_id);
00613                                 if (strlen($count_comment))
00614                                 {
00615                                         if (strlen($mc_comment) == 0)
00616                                         {
00617                                                 $count_comment = "<span class=\"asterisk\">*</span><br /><br /><span class=\"asterisk\">*</span>$count_comment";
00618                                         }
00619                                         else
00620                                         {
00621                                                 $count_comment = "<br /><span class=\"asterisk\">*</span>$count_comment";
00622                                         }
00623                                 }
00624                         }
00625                         $received_points .= $count_comment;
00626                         $received_points .= "</p>";
00627                 }
00628                 if (!$showsolution)
00629                 {
00630                         $solutionoutput = "";
00631                         $received_points = "";
00632                 }
00633                 $this->tpl->setVariable("ORDERING_QUESTION", $output.$solutionoutput.$received_points);
00634         }
00635 
00643         function outUserSolution($user_id, $test_id)
00644         {
00645                 $results = $this->object->getReachedInformation($user_id, $test_id);
00646                 $user_order = array();
00647                 foreach ($results as $key => $value)
00648                 {
00649                         $user_order[$value["order"]] = $value["answer_id"];
00650                 }
00651                 ksort($user_order);
00652                 $user_order = array_values($user_order);
00653                 
00654                 $answer_order = array();
00655                 foreach ($this->answers as $key => $answer)
00656                 {
00657                         $answer_order[$answer->get_solution_order()] = $key;
00658                 }
00659                 ksort($answer_order);
00660                 $answer_order = array_values($answer_order);
00661                 foreach ($this->object->answers as $key => $answer)
00662                 {
00663                         $this->tpl->setCurrentBlock("tablerow");
00664                         $array_key = array_search($key);
00665                         if ($user_order[$array_key] == $answer_order[$array_key])
00666                         {
00667                                 $this->tpl->setVariable("ANSWER_IMAGE", ilUtil::getImagePath("right.png", true));
00668                                 $this->tpl->setVariable("ANSWER_IMAGE_TITLE", $this->lng->txt("answer_is_right"));
00669                         }
00670                         else
00671                         {
00672                                 $this->tpl->setVariable("ANSWER_IMAGE", ilUtil::getImagePath("wrong.png", true));
00673                                 $this->tpl->setVariable("ANSWER_IMAGE_TITLE", $this->lng->txt("answer_is_wrong"));
00674                         }
00675                         if ($this->object->get_ordering_type() == OQ_PICTURES)
00676                         {
00677                                 $extension = "jpg";
00678                                 if (preg_match("/.*\.(png|jpg|gif|jpeg)$/", $answer->get_answertext(), $matches))
00679                                 {
00680                                         $extension = $matches[1];
00681                                 }
00682                                 $answertext = "<img src=\"" . $this->object->getImagePathWeb() . $answer->get_answertext() . ".thumb.jpg\" alt=\"" . $this->lng->txt("selected_image") . "\" />";
00683                         }
00684                         else
00685                         {
00686                                 $answertext = "&quot;<em>" . $answer->get_answertext() . "</em>&quot;";
00687                         }
00688                         $this->tpl->setVariable("ANSWER_DESCRIPTION", $answertext);
00689                         $this->tpl->setVariable("ANSWER_DESCRIPTION_CONNECTOR", $this->lng->txt("with_order") . " &quot;<em>" . $results[$key]["order"] . "</em>&quot;");
00690                         $this->tpl->parseCurrentBlock();
00691                 }
00692         }
00693 
00697         function checkInput()
00698         {
00699                 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
00700                 {
00701                         return false;
00702                 }
00703                 return true;
00704         }
00705 
00706         function addSuggestedSolution()
00707         {
00708                 $_SESSION["subquestion_index"] = 0;
00709                 if ($_POST["cmd"]["addSuggestedSolution"])
00710                 {
00711                         $this->writePostData();
00712                         if (!$this->checkInput())
00713                         {
00714                                 sendInfo($this->lng->txt("fill_out_all_required_fields_add_answer"));
00715                                 $this->editQuestion();
00716                                 return;
00717                         }
00718                 }
00719                 $this->object->saveToDb();
00720                 $_GET["q_id"] = $this->object->getId();
00721                 $this->tpl->setVariable("HEADER", $this->object->getTitle());
00722                 $this->getQuestionTemplate("qt_ordering");
00723                 parent::addSuggestedSolution();
00724         }
00725 }
00726 ?>

Generated on Fri Dec 13 2013 10:18:25 for ILIAS Release_3_5_x_branch .rev 46805 by  doxygen 1.7.1