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

Modules/TestQuestionPool/classes/class.assJavaAppletGUI.php

Go to the documentation of this file.
00001 <?php
00002  /*
00003    +----------------------------------------------------------------------------+
00004    | ILIAS open source                                                          |
00005    +----------------------------------------------------------------------------+
00006    | Copyright (c) 1998-2001 ILIAS open source, University of Cologne           |
00007    |                                                                            |
00008    | This program is free software; you can redistribute it and/or              |
00009    | modify it under the terms of the GNU General Public License                |
00010    | as published by the Free Software Foundation; either version 2             |
00011    | of the License, or (at your option) any later version.                     |
00012    |                                                                            |
00013    | This program is distributed in the hope that it will be useful,            |
00014    | but WITHOUT ANY WARRANTY; without even the implied warranty of             |
00015    | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              |
00016    | GNU General Public License for more details.                               |
00017    |                                                                            |
00018    | You should have received a copy of the GNU General Public License          |
00019    | along with this program; if not, write to the Free Software                |
00020    | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
00021    +----------------------------------------------------------------------------+
00022 */
00023 
00024 include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
00025 include_once "./Modules/Test/classes/inc.AssessmentConstants.php";
00026 
00037 class assJavaAppletGUI extends assQuestionGUI
00038 {
00047         function assJavaAppletGUI(
00048                 $id = -1
00049         )
00050         {
00051                 $this->assQuestionGUI();
00052                 include_once "./Modules/TestQuestionPool/classes/class.assJavaApplet.php";
00053                 $this->object = new assJavaApplet();
00054                 if ($id >= 0)
00055                 {
00056                         $this->object->loadFromDb($id);
00057                 }
00058         }
00059 
00060         function getCommand($cmd)
00061         {
00062                 if (substr($cmd, 0, 6) == "delete")
00063                 {
00064                         $cmd = "delete";
00065                 }
00066                 return $cmd;
00067         }
00068 
00076         function editQuestion()
00077         {
00078                 $this->getQuestionTemplate();
00079                 $this->tpl->addBlockFile("QUESTION_DATA", "question_data", "tpl.il_as_qpl_javaapplet_question.html", "Modules/TestQuestionPool");
00080                 if ($this->error)
00081                 {
00082                         ilUtil::sendInfo($this->error);
00083                 }
00084                 // call to other question data i.e. estimated working time block
00085                 $this->outOtherQuestionData();
00086                 // image block
00087                 $this->tpl->setCurrentBlock("post_save");
00088 
00089                 $internallinks = array(
00090                         "lm" => $this->lng->txt("obj_lm"),
00091                         "st" => $this->lng->txt("obj_st"),
00092                         "pg" => $this->lng->txt("obj_pg"),
00093                         "glo" => $this->lng->txt("glossary_term")
00094                 );
00095                 foreach ($internallinks as $key => $value)
00096                 {
00097                         $this->tpl->setCurrentBlock("internallink");
00098                         $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00099                         $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00100                         $this->tpl->parseCurrentBlock();
00101                 }
00102                 
00103                 $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
00104                 if (count($this->object->suggested_solutions))
00105                 {
00106                         $solution_array = $this->object->getSuggestedSolution(0);
00107                         include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
00108                         $href = assQuestion::_getInternalLinkHref($solution_array["internal_link"]);
00109                         $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
00110                         $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
00111                         $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
00112                         $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
00113                 }
00114                 else
00115                 {
00116                         $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
00117                 }
00118                 
00119                 // java applet block
00120                 $javaapplet = $this->object->getJavaAppletFilename();
00121                 $this->tpl->setVariable("TEXT_JAVAAPPLET", $this->lng->txt("javaapplet"));
00122                 if (!empty($javaapplet))
00123                 {
00124                         $this->tpl->setVariable("JAVAAPPLET_FILENAME", $javaapplet);
00125                         $this->tpl->setVariable("VALUE_JAVAAPPLET_UPLOAD", $this->lng->txt("change"));
00126                         $this->tpl->setCurrentBlock("javaappletupload");
00127                         $this->tpl->setVariable("UPLOADED_JAVAAPPLET", $javaapplet);
00128                         $this->tpl->parse("javaappletupload");
00129                         $this->tpl->setCurrentBlock("delete_applet");
00130                         $this->tpl->setVariable("VALUE_JAVAAPPLET_DELETE", $this->lng->txt("delete"));
00131                         $this->tpl->parseCurrentBlock();
00132                 }
00133                 else
00134                 {
00135                         $this->tpl->setVariable("VALUE_JAVAAPPLET_UPLOAD", $this->lng->txt("upload"));
00136                 }
00137                 $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("available_points"));
00138                 $this->tpl->setVariable("VALUE_APPLET_POINTS", $this->object->getPoints());
00139                 $this->tpl->parseCurrentBlock();
00140 
00141                 
00142                 if ((strlen($this->object->getTitle()) > 0) && (strlen($this->object->getAuthor()) > 0) && (strlen($this->object->getQuestion()) > 0) && ($this->object->getPoints() > 0))
00143                 {
00144                         $emptyname = 0;
00145                         for ($i = 0; $i < $this->object->getParameterCount(); $i++)
00146                         {
00147                                 // create template for existing applet parameters
00148                                 $this->tpl->setCurrentBlock("delete_parameter");
00149                                 $this->tpl->setVariable("VALUE_DELETE_PARAMETER", $this->lng->txt("delete"));
00150                                 $this->tpl->setVariable("DELETE_PARAMETER_COUNT", $i);
00151                                 $this->tpl->parseCurrentBlock();
00152                                 $this->tpl->setCurrentBlock("applet_parameter");
00153                                 $this->tpl->setVariable("PARAM_PARAM", $this->lng->txt("applet_parameter") . " " . ($i+1));
00154                                 $this->tpl->setVariable("PARAM_NAME", $this->lng->txt("name"));
00155                                 $this->tpl->setVariable("PARAM_VALUE", $this->lng->txt("value"));
00156                                 $param = $this->object->getParameter($i);
00157                                 $this->tpl->setVariable("PARAM_NAME_VALUE", $param["name"]);
00158                                 $this->tpl->setVariable("PARAM_VALUE_VALUE", $param["value"]);
00159                                 $this->tpl->setVariable("PARAM_COUNTER", $i);
00160                                 $this->tpl->parseCurrentBlock();
00161                                 if (!$param["name"])
00162                                 {
00163                                         $emptyname = 1;
00164                                 }
00165                         }
00166                         if ($this->ctrl->getCmd() == "addParameter")
00167                         {
00168                                 if ($emptyname == 0)
00169                                 {
00170                                         // create template for new applet parameter
00171                                         $this->tpl->setCurrentBlock("applet_parameter");
00172                                         $this->tpl->setVariable("PARAM_PARAM", $this->lng->txt("applet_new_parameter"));
00173                                         $this->tpl->setVariable("PARAM_NAME", $this->lng->txt("name"));
00174                                         $this->tpl->setVariable("PARAM_VALUE", $this->lng->txt("value"));
00175                                         $this->tpl->setVariable("PARAM_COUNTER", $this->object->getParameterCount());
00176                                         $this->tpl->parseCurrentBlock();
00177                                 }
00178                                 else
00179                                 {
00180                                         ilUtil::sendInfo($this->lng->txt("too_many_empty_parameters"));
00181                                 }
00182                         }
00183                         if (!strlen($javaapplet))
00184                         {
00185                                 $this->tpl->setVariable("TEXT_ARCHIVE", $this->lng->txt("archive"));
00186                                 $this->tpl->setVariable("VALUE_ARCHIVE", $this->object->getJavaArchive());
00187                                 $this->tpl->setVariable("TEXT_CODEBASE", $this->lng->txt("codebase"));
00188                                 $this->tpl->setVariable("VALUE_CODEBASE", $this->object->getJavaCodebase());
00189                         }
00190 
00191                         $this->tpl->setCurrentBlock("appletcode");
00192                         $this->tpl->setVariable("APPLET_ATTRIBUTES", $this->lng->txt("applet_attributes"));
00193                         $this->tpl->setVariable("TEXT_CODE", $this->lng->txt("code"));
00194                         $this->tpl->setVariable("TEXT_WIDTH", $this->lng->txt("width"));
00195                         $this->tpl->setVariable("TEXT_HEIGHT", $this->lng->txt("height"));
00196                         $this->tpl->setVariable("VALUE_CODE", $this->object->getJavaCode());
00197                         $this->tpl->setVariable("VALUE_WIDTH", $this->object->getJavaWidth());
00198                         $this->tpl->setVariable("VALUE_HEIGHT", $this->object->getJavaHeight());
00199                         $this->tpl->setVariable("APPLET_PARAMETERS", $this->lng->txt("applet_parameters"));
00200                         $this->tpl->setVariable("VALUE_ADD_PARAMETER", $this->lng->txt("add_applet_parameter"));
00201                         $this->tpl->parseCurrentBlock();
00202                 }
00203 
00204                 $this->tpl->setCurrentBlock("HeadContent");
00205                 $this->tpl->addJavascript("./Services/JavaScript/js/Basic.js");
00206                 $javascript = "<script type=\"text/javascript\">ilAddOnLoad(initialSelect);\n".
00207                         "function initialSelect() {\n%s\n}</script>";
00208                 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_javaapplet.title.focus();"));
00209                 $this->tpl->parseCurrentBlock();
00210                 $this->tpl->setCurrentBlock("question_data");
00211                 $this->tpl->setVariable("JAVAAPPLET_ID", $this->object->getId());
00212                 $this->tpl->setVariable("VALUE_JAVAAPPLET_TITLE", ilUtil::prepareFormOutput($this->object->getTitle()));
00213                 $this->tpl->setVariable("VALUE_JAVAAPPLET_COMMENT", ilUtil::prepareFormOutput($this->object->getComment()));
00214                 $this->tpl->setVariable("VALUE_JAVAAPPLET_AUTHOR", ilUtil::prepareFormOutput($this->object->getAuthor()));
00215                 $questiontext = $this->object->getQuestion();
00216                 $this->tpl->setVariable("VALUE_QUESTION", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($questiontext)));
00217                 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00218                 $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
00219                 $this->tpl->setVariable("TEXT_COMMENT", $this->lng->txt("description"));
00220                 $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
00221                 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00222 
00223                 $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
00224                 $this->tpl->setVariable("SAVE_EDIT", $this->lng->txt("save_edit"));
00225                 $this->tpl->setVariable("CANCEL",$this->lng->txt("cancel"));
00226                 $this->ctrl->setParameter($this, "sel_question_types", "assJavaApplet");
00227                 $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt("assJavaApplet"));
00228                 $formaction = $this->ctrl->getFormaction($this);
00229                 if ($this->object->getId() > 0)
00230                 {
00231                         if (!preg_match("/q_id\=\d+/", $formaction))
00232                         {
00233                                 $formaction = str_replace("q_id=", "q_id=" . $this->object->getId(), $formaction);
00234                         }
00235                 }
00236                 $this->tpl->setVariable("ACTION_JAVAAPPLET_QUESTION", $formaction);
00237                 $this->tpl->parseCurrentBlock();
00238                 include_once "./Services/RTE/classes/class.ilRTE.php";
00239                 $rtestring = ilRTE::_getRTEClassname();
00240                 include_once "./Services/RTE/classes/class.$rtestring.php";
00241                 $rte = new $rtestring();
00242                 $rte->addPlugin("latex");
00243                 $rte->addButton("latex"); $rte->addButton("pastelatex");
00244                 include_once "./classes/class.ilObject.php";
00245                 $obj_id = $_GET["q_id"];
00246                 $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
00247                 $rte->addRTESupport($obj_id, $obj_type, "assessment");
00248 
00249                 $this->tpl->setCurrentBlock("adm_content");
00250                 //$this->tpl->setVariable("BODY_ATTRIBUTES", " onload=\"initialSelect();\""); 
00251                 $this->tpl->parseCurrentBlock();
00252 
00253         }
00254 
00255 
00259         function uploadingJavaApplet()
00260         {
00261                 $result = $this->writePostData();
00262                 if ($result == 0)
00263                 {
00264                         $this->object->saveToDb();
00265                         $this->ctrl->setParameter($this, "q_id", $this->object->getId());
00266                 }
00267                 $this->editQuestion();
00268         }
00269 
00270 
00274         function removeJavaapplet()
00275         {
00276                 $this->object->deleteJavaAppletFilename();
00277                 $this->object->saveToDb();
00278                 $this->editQuestion();
00279         }
00280 
00284         function addParameter()
00285         {
00286                 $this->writePostData();
00287                 $this->editQuestion();
00288         }
00289 
00293         function delete()
00294         {
00295                 $this->writePostData();
00296                 $this->editQuestion();
00297         }
00298 
00307         function writePostData()
00308         {
00309                 $result = 0;
00310                 $saved = false;
00311                 if (!$this->checkInput())
00312                 {
00313                         $result = 1;
00314                 }
00315 
00316                 $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
00317                 $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
00318                 $this->object->setComment(ilUtil::stripSlashes($_POST["comment"]));
00319                 include_once "./classes/class.ilObjAdvancedEditing.php";
00320                 $questiontext = ilUtil::stripSlashes($_POST["question"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment"));
00321                 $this->object->setQuestion($questiontext);
00322                 $this->object->setSuggestedSolution($_POST["solution_hint"], 0);
00323                 $this->object->setShuffle($_POST["shuffle"]);
00324                 $this->object->setPoints($_POST["applet_points"]);
00325                 if ($_POST["applet_points"] < 0)
00326                 {
00327                         $result = 1;
00328                         $this->setErrorMessage($this->lng->txt("negative_points_not_allowed"));
00329                 }
00330                 // adding estimated working time
00331                 $saved = $saved | $this->writeOtherPostData($result);
00332 
00333                 if ($result == 0)
00334                 {
00335                         //setting java applet
00336                         if (empty($_FILES['javaappletName']['tmp_name']))
00337                         {
00338                                 $this->object->setJavaAppletFilename(ilUtil::stripSlashes($_POST['uploaded_javaapplet']));
00339                         }
00340                         else
00341                         {
00342                                 if ($this->object->getId() < 1)
00343                                 {
00344                                         $saved = 1;
00345                                         $this->object->saveToDb();
00346                                 }
00347                                 $this->object->setJavaAppletFilename($_FILES['javaappletName']['name'], $_FILES['javaappletName']['tmp_name']);
00348                         }
00349                         if ((strlen($this->object->getTitle()) > 0) && (strlen($this->object->getAuthor()) > 0) && (strlen($this->object->getQuestion()) > 0) && ($this->object->getPoints() > 0) && array_key_exists("java_height", $_POST))
00350                         {
00351                                 $this->object->setJavaCode($_POST["java_code"]);
00352                                 $this->object->setJavaCodebase($_POST["java_codebase"]);
00353                                 $this->object->setJavaArchive($_POST["java_archive"]);
00354                                 $this->object->setJavaWidth($_POST["java_width"]);
00355                                 $this->object->setJavaHeight($_POST["java_height"]);
00356                                 if ((!$_POST["java_width"]) or (!$_POST["java_height"])) $result = 1;
00357                                 $this->object->flushParams();
00358                                 foreach ($_POST as $key => $value)
00359                                 {
00360                                         if (preg_match("/param_name_(\d+)/", $key, $matches))
00361                                         {
00362                                                 $this->object->addParameterAtIndex($matches[1], $value, $_POST["param_value_$matches[1]"]);
00363                                         }
00364                                 }
00365                                 if (preg_match("/delete_(\d+)/", $this->ctrl->getCmd(), $matches))
00366                                 {
00367                                         $this->object->removeParameter($_POST["param_name_$matches[1]"]);
00368                                 }
00369                         }
00370                 }
00371                 if ($saved)
00372                 {
00373                         $this->object->saveToDb();
00374                         $this->ctrl->setParameter($this, "q_id", $this->object->getId());
00375                         $this->error .= $this->lng->txt("question_saved_for_upload");
00376                 }
00377                 return $result;
00378         }
00379 
00380         function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE)
00381         {
00382                 $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $use_post_solutions); 
00383                 $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
00384                 $this->tpl->setVariable("FORMACTION", $formaction);
00385         }
00386 
00387         function getSolutionOutput($active_id, $pass = NULL, $graphicalOutput = FALSE, $result_output = FALSE, $show_question_only = TRUE, $show_feedback = FALSE)
00388         {
00389                 $userdata = $this->object->getActiveUserData($active_id);
00390 
00391                 // generate the question output
00392                 include_once "./classes/class.ilTemplate.php";
00393                 include_once "./Modules/Test/classes/class.ilObjTest.php";
00394                 $template = new ilTemplate("tpl.il_as_qpl_javaapplet_question_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
00395                 $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
00396                 if (strlen($userdata["test_id"]))
00397                 {
00398                         $template->setCurrentBlock("appletparam");
00399                         $template->setVariable("PARAM_NAME", "test_type");
00400                         if (ilObjTest::_lookupAnonymity(ilObjTest::_getObjectIDFromTestID($userdata["test_id"])))
00401                         {
00402                                 $template->setVariable("PARAM_VALUE", "0");
00403                         }
00404                         else
00405                         {
00406                                 $template->setVariable("PARAM_VALUE", "1");
00407                         }
00408                         $template->parseCurrentBlock();
00409                 }
00410                 if (strlen($userdata["test_id"]))
00411                 {
00412                         $template->setCurrentBlock("appletparam");
00413                         $template->setVariable("PARAM_NAME", "test_id");
00414                         $template->setVariable("PARAM_VALUE", $userdata["test_id"]);
00415                         $template->parseCurrentBlock();
00416                 }
00417                 $template->setCurrentBlock("appletparam");
00418                 $template->setVariable("PARAM_NAME", "active_id");
00419                 $template->setVariable("PARAM_VALUE", $active_id);
00420                 $template->parseCurrentBlock();
00421                 $template->setCurrentBlock("appletparam");
00422                 $template->setVariable("PARAM_NAME", "question_id");
00423                 $template->setVariable("PARAM_VALUE", $this->object->getId());
00424                 $template->parseCurrentBlock();
00425                 if (strlen($userdata["user_id"]))
00426                 {
00427                         $template->setCurrentBlock("appletparam");
00428                         $template->setVariable("PARAM_NAME", "user_id");
00429                         $template->setVariable("PARAM_VALUE", $userdata["user_id"]);
00430                         $template->parseCurrentBlock();
00431                 }
00432                 $template->setCurrentBlock("appletparam");
00433                 $template->setVariable("PARAM_NAME", "points_max");
00434                 $template->setVariable("PARAM_VALUE", $this->object->getPoints());
00435                 $template->parseCurrentBlock();
00436                 $template->setCurrentBlock("appletparam");
00437                 $template->setVariable("PARAM_NAME", "session_id");
00438                 $template->setVariable("PARAM_VALUE", $_COOKIE["PHPSESSID"]);
00439                 $template->parseCurrentBlock();
00440                 $template->setCurrentBlock("appletparam");
00441                 $template->setVariable("PARAM_NAME", "client");
00442                 $template->setVariable("PARAM_VALUE", CLIENT_ID);
00443                 $template->parseCurrentBlock();
00444                 $template->setCurrentBlock("appletparam");
00445                 $template->setVariable("PARAM_NAME", "pass");
00446                 $actualpass = ilObjTest::_getPass($active_id);
00447                 $template->setVariable("PARAM_VALUE", $actualpass);
00448                 $template->parseCurrentBlock();
00449                 // additional parameters
00450                 for ($i = 0; $i < $this->object->getParameterCount(); $i++)
00451                 {
00452                         $parameter = $this->object->getParameter($i);
00453                         $template->setCurrentBlock("appletparam");
00454                         $template->setVariable("PARAM_NAME", $parameter["name"]);
00455                         $template->setVariable("PARAM_VALUE", $parameter["value"]);
00456                         $template->parseCurrentBlock();
00457                 }
00458 
00459                 if ($active_id)
00460                 {
00461                         $solutions = NULL;
00462                         include_once "./Modules/Test/classes/class.ilObjTest.php";
00463                         $info = $this->object->getReachedInformation($active_id, $pass);
00464                         foreach ($info as $kk => $infodata)
00465                         {
00466                                 $template->setCurrentBlock("appletparam");
00467                                 $template->setVariable("PARAM_NAME", "value_" . $infodata["order"] . "_1");
00468                                 $template->setVariable("PARAM_VALUE", $infodata["value1"]);
00469                                 $template->parseCurrentBlock();
00470                                 $template->setCurrentBlock("appletparam");
00471                                 $template->setVariable("PARAM_NAME", "value_" . $infodata["order"] . "_2");
00472                                 $template->setVariable("PARAM_VALUE", $infodata["value2"]);
00473                                 $template->parseCurrentBlock();
00474                         }
00475                 }
00476                 
00477                 $questiontext = $this->object->getQuestion();
00478                 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00479                 $template->setVariable("APPLET_WIDTH", $this->object->getJavaWidth());
00480                 $template->setVariable("APPLET_HEIGHT", $this->object->getJavaHeight());
00481                 $template->setVariable("APPLET_CODE", $this->object->getJavaCode());
00482                 if (strlen($this->object->getJavaArchive()) > 0)
00483                 {
00484                         $template->setVariable("APPLET_ARCHIVE", " archive=\"".$this->object->getJavaArchive()."\"");
00485                 }
00486                 else
00487                 {
00488                         if (strpos($this->object->getJavaAppletFilename(), ".jar") !== FALSE)
00489                         {
00490                                 $template->setVariable("APPLET_ARCHIVE", " archive=\"".$this->object->getJavaPathWeb().$this->object->getJavaAppletFilename()."\"");
00491                         }
00492                 }
00493                 if (strlen($this->object->getJavaCodebase()) > 0)
00494                 {
00495                         $template->setVariable("APPLET_CODEBASE", " codebase=\"".$this->object->getJavaCodebase()."\"");
00496                 }
00497                 else
00498                 {
00499                         if (strpos($this->object->getJavaAppletFilename(), ".class") !== FALSE)
00500                         {
00501                                 $template->setVariable("APPLET_CODEBASE", " codebase=\"".$this->object->getJavaPathWeb()."\"");
00502                         }
00503                 }
00504                 if ($active_id)
00505                 {
00506                         if ($graphicalOutput)
00507                         {
00508                                 // output of ok/not ok icons for user entered solutions
00509                                 $reached_points = $this->object->getReachedPoints($active_id, $pass);
00510                                 if ($reached_points == $this->object->getMaximumPoints())
00511                                 {
00512                                         $template->setCurrentBlock("icon_ok");
00513                                         $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.gif"));
00514                                         $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
00515                                         $template->parseCurrentBlock();
00516                                 }
00517                                 else
00518                                 {
00519                                         $template->setCurrentBlock("icon_ok");
00520                                         if ($reached_points > 0)
00521                                         {
00522                                                 $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.gif"));
00523                                                 $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
00524                                         }
00525                                         else
00526                                         {
00527                                                 $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
00528                                                 $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
00529                                         }
00530                                         $template->parseCurrentBlock();
00531                                 }
00532                         }
00533                 }
00534                 $questionoutput = $template->get();
00535                 $feedback = ($show_feedback) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
00536                 if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $feedback);
00537                 $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
00538 
00539                 $solutionoutput = $solutiontemplate->get(); 
00540                 if (!$show_question_only)
00541                 {
00542                         // get page object output
00543                         $pageoutput = $this->getILIASPage();
00544                         $solutionoutput = "<div class=\"ilias_content\">" . preg_replace("/(<div( xmlns:xhtml\=\"http:\/\/www.w3.org\/1999\/xhtml\"){0,1} class\=\"ilc_Question\"><\/div>)/ims", "</div><div class=\"ilc_Question\">" . $solutionoutput . "</div><div class=\"ilias_content\">", $pageoutput) . "</div>";
00545                 }
00546                 return $solutionoutput;
00547         }
00548         
00549         function getPreview($show_question_only = FALSE)
00550         {
00551                 // generate the question output
00552                 include_once "./classes/class.ilTemplate.php";
00553                 $template = new ilTemplate("tpl.il_as_qpl_javaapplet_question_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
00554                 $template->setCurrentBlock("appletparam");
00555                 $template->setVariable("PARAM_NAME", "question_id");
00556                 $template->setVariable("PARAM_VALUE", $this->object->getId());
00557                 $template->parseCurrentBlock();
00558                 $template->setCurrentBlock("appletparam");
00559                 $template->setVariable("PARAM_NAME", "points_max");
00560                 $template->setVariable("PARAM_VALUE", $this->object->getPoints());
00561                 $template->parseCurrentBlock();
00562                 $template->setCurrentBlock("appletparam");
00563                 $template->setVariable("PARAM_NAME", "session_id");
00564                 $template->setVariable("PARAM_VALUE", $_COOKIE["PHPSESSID"]);
00565                 $template->parseCurrentBlock();
00566                 $template->setCurrentBlock("appletparam");
00567                 $template->setVariable("PARAM_NAME", "client");
00568                 $template->setVariable("PARAM_VALUE", CLIENT_ID);
00569                 $template->parseCurrentBlock();
00570                 // additional parameters
00571                 for ($i = 0; $i < $this->object->getParameterCount(); $i++)
00572                 {
00573                         $parameter = $this->object->getParameter($i);
00574                         $template->setCurrentBlock("appletparam");
00575                         $template->setVariable("PARAM_NAME", $parameter["name"]);
00576                         $template->setVariable("PARAM_VALUE", $parameter["value"]);
00577                         $template->parseCurrentBlock();
00578                 }
00579 
00580                 $questiontext = $this->object->getQuestion();
00581                 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00582                 $template->setVariable("APPLET_WIDTH", $this->object->getJavaWidth());
00583                 $template->setVariable("APPLET_HEIGHT", $this->object->getJavaHeight());
00584                 $template->setVariable("APPLET_CODE", $this->object->getJavaCode());
00585                 if (strlen($this->object->getJavaArchive()) > 0)
00586                 {
00587                         $template->setVariable("APPLET_ARCHIVE", " archive=\"".$this->object->getJavaArchive()."\"");
00588                 }
00589                 else
00590                 {
00591                         if (strpos($this->object->getJavaAppletFilename(), ".jar") !== FALSE)
00592                         {
00593                                 $template->setVariable("APPLET_ARCHIVE", " archive=\"".$this->object->getJavaPathWeb().$this->object->getJavaAppletFilename()."\"");
00594                         }
00595                 }
00596                 if (strlen($this->object->getJavaCodebase()) > 0)
00597                 {
00598                         $template->setVariable("APPLET_CODEBASE", " codebase=\"".$this->object->getJavaCodebase()."\"");
00599                 }
00600                 else
00601                 {
00602                         if (strpos($this->object->getJavaAppletFilename(), ".class") !== FALSE)
00603                         {
00604                                 $template->setVariable("APPLET_CODEBASE", " codebase=\"".$this->object->getJavaPathWeb()."\"");
00605                         }
00606                 }
00607                 $questionoutput = $template->get();
00608                 if (!$show_question_only)
00609                 {
00610                         // get page object output
00611                         $pageoutput = $this->getILIASPage();
00612                         $questionoutput = preg_replace("/(<div( xmlns:xhtml\=\"http:\/\/www.w3.org\/1999\/xhtml\"){0,1} class\=\"ilc_Question\"><\/div>)/ims", $questionoutput, $pageoutput);
00613                 }
00614                 else
00615                 {
00616                         $questionoutput = preg_replace("/<div[^>]*?>(.*)<\/div>/is", "\\1", $questionoutput);
00617                 }
00618 
00619                 return $questionoutput;
00620         }
00621         
00622         function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE)
00623         {
00624                 // get page object output
00625                 $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id);
00626                 $userdata = $this->object->getActiveUserData($active_id);
00627                 // generate the question output
00628                 include_once "./classes/class.ilTemplate.php";
00629                 $template = new ilTemplate("tpl.il_as_qpl_javaapplet_question_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
00630                 $template->setCurrentBlock("appletparam");
00631                 $template->setVariable("PARAM_NAME", "test_type");
00632                 include_once "./Modules/Test/classes/class.ilObjTest.php";
00633                 if (ilObjTest::_lookupAnonymity(ilObjTest::_getObjectIDFromTestID($userdata["test_id"])))
00634                 {
00635                         $template->setVariable("PARAM_VALUE", "0");
00636                 }
00637                 else
00638                 {
00639                         $template->setVariable("PARAM_VALUE", "1");
00640                 }
00641                 $template->parseCurrentBlock();
00642                 $template->setCurrentBlock("appletparam");
00643                 $template->setVariable("PARAM_NAME", "active_id");
00644                 $template->setVariable("PARAM_VALUE", $active_id);
00645                 $template->parseCurrentBlock();
00646                 $template->setCurrentBlock("appletparam");
00647                 $template->setVariable("PARAM_NAME", "test_id");
00648                 $template->setVariable("PARAM_VALUE", $userdata["test_id"]);
00649                 $template->parseCurrentBlock();
00650                 $template->setCurrentBlock("appletparam");
00651                 $template->setVariable("PARAM_NAME", "question_id");
00652                 $template->setVariable("PARAM_VALUE", $this->object->getId());
00653                 $template->parseCurrentBlock();
00654                 $template->setCurrentBlock("appletparam");
00655                 $template->setVariable("PARAM_NAME", "user_id");
00656                 $template->setVariable("PARAM_VALUE", $userdata["user_id"]);
00657                 $template->parseCurrentBlock();
00658                 $template->setCurrentBlock("appletparam");
00659                 $template->setVariable("PARAM_NAME", "points_max");
00660                 $template->setVariable("PARAM_VALUE", $this->object->getPoints());
00661                 $template->parseCurrentBlock();
00662                 $template->setCurrentBlock("appletparam");
00663                 $template->setVariable("PARAM_NAME", "session_id");
00664                 $template->setVariable("PARAM_VALUE", $_COOKIE["PHPSESSID"]);
00665                 $template->parseCurrentBlock();
00666                 $template->setCurrentBlock("appletparam");
00667                 $template->setVariable("PARAM_NAME", "client");
00668                 $template->setVariable("PARAM_VALUE", CLIENT_ID);
00669                 $template->parseCurrentBlock();
00670                 $template->setCurrentBlock("appletparam");
00671                 $template->setVariable("PARAM_NAME", "pass");
00672                 $actualpass = ilObjTest::_getPass($active_id);
00673                 $template->setVariable("PARAM_VALUE", $actualpass);
00674                 $template->parseCurrentBlock();
00675                 $template->setCurrentBlock("appletparam");
00676                 $template->setVariable("PARAM_NAME", "post_url");
00677                 $template->setVariable("PARAM_VALUE", ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/Modules/TestQuestionPool/save_question_post_data.php");
00678                 $template->parseCurrentBlock();
00679                 // additional parameters
00680                 for ($i = 0; $i < $this->object->getParameterCount(); $i++)
00681                 {
00682                         $parameter = $this->object->getParameter($i);
00683                         $template->setCurrentBlock("appletparam");
00684                         $template->setVariable("PARAM_NAME", $parameter["name"]);
00685                         $template->setVariable("PARAM_VALUE", $parameter["value"]);
00686                         $template->parseCurrentBlock();
00687                 }
00688 
00689                 if ($active_id)
00690                 {
00691                         $solutions = NULL;
00692                         include_once "./Modules/Test/classes/class.ilObjTest.php";
00693                         if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
00694                         {
00695                                 if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
00696                         }
00697                         $info = $this->object->getReachedInformation($active_id, $pass);
00698                         foreach ($info as $kk => $infodata)
00699                         {
00700                                 $template->setCurrentBlock("appletparam");
00701                                 $template->setVariable("PARAM_NAME", "value_" . $infodata["order"] . "_1");
00702                                 $template->setVariable("PARAM_VALUE", $infodata["value1"]);
00703                                 $template->parseCurrentBlock();
00704                                 $template->setCurrentBlock("appletparam");
00705                                 $template->setVariable("PARAM_NAME", "value_" . $infodata["order"] . "_2");
00706                                 $template->setVariable("PARAM_VALUE", $infodata["value2"]);
00707                                 $template->parseCurrentBlock();
00708                         }
00709                         include_once './Services/Administration/classes/class.ilSetting.php';
00710                         $soapSetting = new ilSetting();
00711                         if ($soapSetting->get("soap_user_administration") == 1)
00712                         {
00713                                 $template->setCurrentBlock("appletparam");
00714                                 $template->setVariable("PARAM_NAME", "server");
00715                                 $template->setVariable("PARAM_VALUE", ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/webservice/soap/server.php");
00716                         }
00717                 }
00718                 
00719                 $questiontext = $this->object->getQuestion();
00720                 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
00721                 $template->setVariable("APPLET_WIDTH", $this->object->getJavaWidth());
00722                 $template->setVariable("APPLET_HEIGHT", $this->object->getJavaHeight());
00723                 $template->setVariable("APPLET_CODE", $this->object->getJavaCode());
00724                 if (strlen($this->object->getJavaArchive()) > 0)
00725                 {
00726                         $template->setVariable("APPLET_ARCHIVE", " archive=\"".$this->object->getJavaArchive()."\"");
00727                 }
00728                 else
00729                 {
00730                         if (strpos($this->object->getJavaAppletFilename(), ".jar") !== FALSE)
00731                         {
00732                                 $template->setVariable("APPLET_ARCHIVE", " archive=\"".$this->object->getJavaPathWeb().$this->object->getJavaAppletFilename()."\"");
00733                         }
00734                 }
00735                 if (strlen($this->object->getJavaCodebase()) > 0)
00736                 {
00737                         $template->setVariable("APPLET_CODEBASE", " codebase=\"".$this->object->getJavaCodebase()."\"");
00738                 }
00739                 else
00740                 {
00741                         if (strpos($this->object->getJavaAppletFilename(), ".class") !== FALSE)
00742                         {
00743                                 $template->setVariable("APPLET_CODEBASE", " codebase=\"".$this->object->getJavaPathWeb()."\"");
00744                         }
00745                 }
00746                 $questionoutput = $template->get();
00747                 $questionoutput = str_replace("<div xmlns:xhtml=\"http://www.w3.org/1999/xhtml\" class=\"ilc_Question\"></div>", $questionoutput, $pageoutput);
00748                 return $questionoutput;
00749         }
00750         
00754         function checkInput()
00755         {
00756                 if ((strlen($_POST["title"]) == 0) or (strlen($_POST["author"]) == 0) or (strlen($_POST["question"]) == 0) or (strlen($_POST["applet_points"]) == 0))
00757                 {
00758                         $this->error .= $this->lng->txt("fill_out_all_required_fields");
00759                         return false;
00760                 }
00761                 return true;
00762         }
00763 
00764 
00765         function addSuggestedSolution()
00766         {
00767                 $_SESSION["subquestion_index"] = 0;
00768                 if ($_POST["cmd"]["addSuggestedSolution"])
00769                 {
00770                         if ($this->writePostData())
00771                         {
00772                                 ilUtil::sendInfo($this->getErrorMessage());
00773                                 $this->editQuestion();
00774                                 return;
00775                         }
00776                         if ($result != 0)
00777                         {
00778                                 $this->editQuestion();
00779                                 return;
00780                         }
00781                 }
00782                 $this->object->saveToDb();
00783                 $this->ctrl->setParameter($this, "q_id", $this->object->getId());
00784                 $this->tpl->setVariable("HEADER", $this->object->getTitle());
00785                 $this->getQuestionTemplate();
00786                 parent::addSuggestedSolution();
00787         }
00788 
00796         function saveFeedback()
00797         {
00798                 include_once "./classes/class.ilObjAdvancedEditing.php";
00799                 $this->object->saveFeedbackGeneric(0, ilUtil::stripSlashes($_POST["feedback_incomplete"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment")));
00800                 $this->object->saveFeedbackGeneric(1, ilUtil::stripSlashes($_POST["feedback_complete"], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment")));
00801                 $this->object->cleanupMediaObjectUsage();
00802                 parent::saveFeedback();
00803         }
00804 
00812         function feedback()
00813         {
00814                 $this->tpl->addBlockFile("ADM_CONTENT", "feedback", "tpl.il_as_qpl_javaapplet_question_feedback.html", "Modules/TestQuestionPool");
00815                 $this->tpl->setVariable("FEEDBACK_TEXT", $this->lng->txt("feedback"));
00816                 $this->tpl->setVariable("FEEDBACK_COMPLETE", $this->lng->txt("feedback_complete_solution"));
00817                 $this->tpl->setVariable("VALUE_FEEDBACK_COMPLETE", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(1)), FALSE));
00818                 $this->tpl->setVariable("FEEDBACK_INCOMPLETE", $this->lng->txt("feedback_incomplete_solution"));
00819                 $this->tpl->setVariable("VALUE_FEEDBACK_INCOMPLETE", ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(0)), FALSE));
00820                 $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
00821                 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
00822 
00823                 include_once "./Services/RTE/classes/class.ilRTE.php";
00824                 $rtestring = ilRTE::_getRTEClassname();
00825                 include_once "./Services/RTE/classes/class.$rtestring.php";
00826                 $rte = new $rtestring();
00827                 $rte->addPlugin("latex");
00828                 $rte->addButton("latex"); $rte->addButton("pastelatex");
00829                 include_once "./classes/class.ilObject.php";
00830                 $obj_id = $_GET["q_id"];
00831                 $obj_type = ilObject::_lookupType($_GET["ref_id"], TRUE);
00832                 $rte->addRTESupport($obj_id, $obj_type, "assessment");
00833         }
00834 
00842         function setQuestionTabs()
00843         {
00844                 global $rbacsystem, $ilTabs;
00845                 
00846                 $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
00847                 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
00848                 $q_type = $this->object->getQuestionType();
00849 
00850                 if (strlen($q_type))
00851                 {
00852                         $classname = $q_type . "GUI";
00853                         $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
00854                         $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
00855                 }
00856 
00857                 if ($_GET["q_id"])
00858                 {
00859                         if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
00860                         {
00861                                 // edit page
00862                                 $ilTabs->addTarget("edit_content",
00863                                         $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "view"),
00864                                         array("view", "insert", "exec_pg"),
00865                                         "", "", $force_active);
00866                         }
00867         
00868                         // edit page
00869                         $ilTabs->addTarget("preview",
00870                                 $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
00871                                 array("preview"),
00872                                 "ilPageObjectGUI", "", $force_active);
00873                 }
00874 
00875                 $force_active = false;
00876                 if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
00877                 {
00878                         $url = "";
00879                         if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
00880                         $commands = $_POST["cmd"];
00881                         if (is_array($commands))
00882                         {
00883                                 foreach ($commands as $key => $value)
00884                                 {
00885                                         if (preg_match("/^delete_.*/", $key, $matches))
00886                                         {
00887                                                 $force_active = true;
00888                                         }
00889                                 }
00890                         }
00891                         // edit question properties
00892                         $ilTabs->addTarget("edit_properties",
00893                                 $url,
00894                                 array("editQuestion", "save", "cancel", "addSuggestedSolution",
00895                                         "cancelExplorer", "linkChilds", "removeSuggestedSolution",
00896                                         "uploadingJavaapplet", "addParameter",
00897                                         "saveEdit"),
00898                                 $classname, "", $force_active);
00899                 }
00900 
00901                 if ($_GET["q_id"])
00902                 {
00903                         $ilTabs->addTarget("feedback",
00904                                 $this->ctrl->getLinkTargetByClass($classname, "feedback"),
00905                                 array("feedback", "saveFeedback"),
00906                                 $classname, "");
00907                 }
00908                 
00909                 // Assessment of questions sub menu entry
00910                 if ($_GET["q_id"])
00911                 {
00912                         $ilTabs->addTarget("statistics",
00913                                 $this->ctrl->getLinkTargetByClass($classname, "assessment"),
00914                                 array("assessment"),
00915                                 $classname, "");
00916                 }
00917                 
00918                 if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
00919                 {
00920                         $ref_id = $_GET["calling_test"];
00921                         if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
00922                         $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
00923                 }
00924                 else
00925                 {
00926                         $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
00927                 }
00928         }
00929 }
00930 ?>

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