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

assessment/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 require_once "./assessment/classes/class.assQuestionGUI.php";
00025 require_once "./assessment/classes/class.assJavaApplet.php";
00026 
00038 class ASS_JavaAppletGUI extends ASS_QuestionGUI
00039 {
00048         function ASS_JavaAppletGUI(
00049                 $id = -1
00050         )
00051         {
00052                 $this->ASS_QuestionGUI();
00053                 $this->object = new ASS_JavaApplet();
00054                 if ($id >= 0)
00055                 {
00056                         $this->object->loadFromDb($id);
00057                 }
00058         }
00059 
00068         function getQuestionType()
00069         {
00070                 return "qt_javaapplet";
00071         }
00072 
00073         function getCommand($cmd)
00074         {
00075                 if (substr($cmd, 0, 6) == "delete")
00076                 {
00077                         $cmd = "delete";
00078                 }
00079                 return $cmd;
00080         }
00081 
00089         function editQuestion()
00090         {
00091                 $this->tpl->setVariable("HEADER", $this->object->getTitle());
00092                 $this->getQuestionTemplate("qt_javaapplet");
00093                 $this->tpl->addBlockFile("QUESTION_DATA", "question_data", "tpl.il_as_qpl_javaapplet_question.html", true);
00094                 if ($this->error)
00095                 {
00096                         sendInfo($this->error);
00097                 }
00098                 // call to other question data i.e. estimated working time block
00099                 $this->outOtherQuestionData();
00100                 // image block
00101                 $this->tpl->setCurrentBlock("post_save");
00102 
00103                 $internallinks = array(
00104                         "lm" => $this->lng->txt("obj_lm"),
00105                         "st" => $this->lng->txt("obj_st"),
00106                         "pg" => $this->lng->txt("obj_pg"),
00107                         "glo" => $this->lng->txt("glossary_term")
00108                 );
00109                 foreach ($internallinks as $key => $value)
00110                 {
00111                         $this->tpl->setCurrentBlock("internallink");
00112                         $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00113                         $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00114                         $this->tpl->parseCurrentBlock();
00115                 }
00116                 
00117                 $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
00118                 if (count($this->object->suggested_solutions))
00119                 {
00120                         $solution_array = $this->object->getSuggestedSolution(0);
00121                         $href = ASS_Question::_getInternalLinkHref($solution_array["internal_link"]);
00122                         $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
00123                         $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
00124                         $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
00125                         $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
00126                 }
00127                 else
00128                 {
00129                         $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
00130                 }
00131                 
00132                 // java applet block
00133                 $javaapplet = $this->object->getJavaAppletFilename();
00134                 $this->tpl->setVariable("TEXT_JAVAAPPLET", $this->lng->txt("javaapplet"));
00135                 if (!empty($javaapplet))
00136                 {
00137                         $this->tpl->setVariable("JAVAAPPLET_FILENAME", $javaapplet);
00138                         $this->tpl->setVariable("VALUE_JAVAAPPLET_UPLOAD", $this->lng->txt("change"));
00139                         $this->tpl->setCurrentBlock("javaappletupload");
00140                         $this->tpl->setVariable("UPLOADED_JAVAAPPLET", $javaapplet);
00141                         $this->tpl->parse("javaappletupload");
00142                 }
00143                 else
00144                 {
00145                         $this->tpl->setVariable("VALUE_JAVAAPPLET_UPLOAD", $this->lng->txt("upload"));
00146                 }
00147                 $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("available_points"));
00148                 $this->tpl->setVariable("VALUE_APPLET_POINTS", sprintf("%d", $this->object->getPoints()));
00149                 $this->tpl->parseCurrentBlock();
00150 
00151                 if ($javaapplet)
00152                 {
00153                         $emptyname = 0;
00154                         for ($i = 0; $i < $this->object->getParameterCount(); $i++)
00155                         {
00156                                 // create template for existing applet parameters
00157                                 $this->tpl->setCurrentBlock("delete_parameter");
00158                                 $this->tpl->setVariable("VALUE_DELETE_PARAMETER", $this->lng->txt("delete"));
00159                                 $this->tpl->setVariable("DELETE_PARAMETER_COUNT", $i);
00160                                 $this->tpl->parseCurrentBlock();
00161                                 $this->tpl->setCurrentBlock("applet_parameter");
00162                                 $this->tpl->setVariable("PARAM_PARAM", $this->lng->txt("applet_parameter") . " " . ($i+1));
00163                                 $this->tpl->setVariable("PARAM_NAME", $this->lng->txt("name"));
00164                                 $this->tpl->setVariable("PARAM_VALUE", $this->lng->txt("value"));
00165                                 $param = $this->object->getParameter($i);
00166                                 $this->tpl->setVariable("PARAM_NAME_VALUE", $param["name"]);
00167                                 $this->tpl->setVariable("PARAM_VALUE_VALUE", $param["value"]);
00168                                 $this->tpl->setVariable("PARAM_COUNTER", $i);
00169                                 $this->tpl->parseCurrentBlock();
00170                                 if (!$param["name"])
00171                                 {
00172                                         $emptyname = 1;
00173                                 }
00174                         }
00175                         if ($this->ctrl->getCmd() == "addParameter")
00176                         {
00177                                 if ($emptyname == 0)
00178                                 {
00179                                         // create template for new applet parameter
00180                                         $this->tpl->setCurrentBlock("applet_parameter");
00181                                         $this->tpl->setVariable("PARAM_PARAM", $this->lng->txt("applet_new_parameter"));
00182                                         $this->tpl->setVariable("PARAM_NAME", $this->lng->txt("name"));
00183                                         $this->tpl->setVariable("PARAM_VALUE", $this->lng->txt("value"));
00184                                         $this->tpl->setVariable("PARAM_COUNTER", $this->object->getParameterCount());
00185                                         $this->tpl->parseCurrentBlock();
00186                                 }
00187                                 else
00188                                 {
00189                                         sendInfo($this->lng->txt("too_many_empty_parameters"));
00190                                 }
00191                         }
00192                         $this->tpl->setCurrentBlock("appletcode");
00193                         $this->tpl->setVariable("APPLET_ATTRIBUTES", $this->lng->txt("applet_attributes"));
00194                         $this->tpl->setVariable("TEXT_ARCHIVE", $this->lng->txt("archive"));
00195                         $this->tpl->setVariable("TEXT_CODE", $this->lng->txt("code"));
00196                         $this->tpl->setVariable("TEXT_WIDTH", $this->lng->txt("width"));
00197                         $this->tpl->setVariable("TEXT_HEIGHT", $this->lng->txt("height"));
00198                         $this->tpl->setVariable("VALUE_CODE", $this->object->getJavaCode());
00199                         $this->tpl->setVariable("VALUE_WIDTH", $this->object->getJavaWidth());
00200                         $this->tpl->setVariable("VALUE_HEIGHT", $this->object->getJavaHeight());
00201                         $this->tpl->setVariable("APPLET_PARAMETERS", $this->lng->txt("applet_parameters"));
00202                         $this->tpl->setVariable("VALUE_ADD_PARAMETER", $this->lng->txt("add_applet_parameter"));
00203                         $this->tpl->parseCurrentBlock();
00204                 }
00205 
00206                 $this->tpl->setCurrentBlock("HeadContent");
00207                 $javascript = "<script type=\"text/javascript\">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", htmlspecialchars($this->object->getTitle()));
00213                 $this->tpl->setVariable("VALUE_JAVAAPPLET_COMMENT", htmlspecialchars($this->object->getComment()));
00214                 $this->tpl->setVariable("VALUE_JAVAAPPLET_AUTHOR", htmlspecialchars($this->object->getAuthor()));
00215                 $questiontext = $this->object->getQuestion();
00216                 $questiontext = preg_replace("/<br \/>/", "\n", $questiontext);
00217                 $this->tpl->setVariable("VALUE_QUESTION", htmlspecialchars($questiontext));
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("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00223 
00224                 $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
00225                 $this->tpl->setVariable("SAVE_EDIT", $this->lng->txt("save_edit"));
00226                 $this->tpl->setVariable("CANCEL",$this->lng->txt("cancel"));
00227                 $this->ctrl->setParameter($this, "sel_question_types", "qt_javaapplet");
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 
00239                 $this->tpl->setCurrentBlock("adm_content");
00240                 $this->tpl->setVariable("BODY_ATTRIBUTES", " onload=\"initialSelect();\""); 
00241                 $this->tpl->parseCurrentBlock();
00242 
00243         }
00244 
00245 
00249         function uploadingJavaApplet()
00250         {
00251                 $result = $this->writePostData();
00252                 if ($result == 0)
00253                 {
00254                         $this->object->saveToDb();
00255                 }
00256                 $this->editQuestion();
00257         }
00258 
00262         function addParameter()
00263         {
00264                 $this->writePostData();
00265                 $this->editQuestion();
00266         }
00267 
00271         function delete()
00272         {
00273                 $this->writePostData();
00274                 $this->editQuestion();
00275         }
00276 
00285         function outOtherQuestionData()
00286         {
00287                 $this->tpl->setCurrentBlock("other_question_data");
00288                 $est_working_time = $this->object->getEstimatedWorkingTime();
00289                 $this->tpl->setVariable("TEXT_WORKING_TIME", $this->lng->txt("working_time"));
00290                 $this->tpl->setVariable("TIME_FORMAT", $this->lng->txt("time_format"));
00291                 $this->tpl->setVariable("VALUE_WORKING_TIME", ilUtil::makeTimeSelect("Estimated", false, $est_working_time[h], $est_working_time[m], $est_working_time[s]));
00292                 $this->tpl->parseCurrentBlock();
00293         }
00294 
00303         function writePostData()
00304         {
00305                 $result = 0;
00306                 $saved = false;
00307                 if (!$this->checkInput())
00308                 {
00309                         $result = 1;
00310                 }
00311 
00312                 $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
00313                 $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
00314                 $this->object->setComment(ilUtil::stripSlashes($_POST["comment"]));
00315                 $questiontext = ilUtil::stripSlashes($_POST["question"], true, "<strong><em><code><cite>");
00316                 $questiontext = preg_replace("/\n/", "<br />", $questiontext);
00317                 $this->object->setQuestion($questiontext);
00318                 $this->object->setSuggestedSolution($_POST["solution_hint"], 0);
00319                 $this->object->setShuffle($_POST["shuffle"]);
00320                 $this->object->setPoints($_POST["applet_points"]);
00321                 // adding estimated working time
00322                 $saved = $saved | $this->writeOtherPostData($result);
00323 
00324                 if ($result == 0)
00325                 {
00326                         //setting java applet
00327                         if (empty($_FILES['javaappletName']['tmp_name']))
00328                         {
00329                                 $this->object->setJavaAppletFilename(ilUtil::stripSlashes($_POST['uploaded_javaapplet']));
00330                         }
00331                         else
00332                         {
00333                                 if ($this->object->getId() < 1)
00334                                 {
00335                                         $saved = 1;
00336                                         $this->object->saveToDb();
00337                                 }
00338                                 $this->object->setJavaAppletFilename($_FILES['javaappletName']['name'], $_FILES['javaappletName']['tmp_name']);
00339                         }
00340                         if ($this->object->getJavaAppletFilename())
00341                         {
00342                                 $this->object->setJavaCode($_POST["java_code"]);
00343                                 $this->object->setJavaWidth($_POST["java_width"]);
00344                                 $this->object->setJavaHeight($_POST["java_height"]);
00345                                 if ((!$_POST["java_width"]) or (!$_POST["java_height"])) $result = 1;
00346                                 $this->object->flushParams();
00347                                 foreach ($_POST as $key => $value)
00348                                 {
00349                                         if (preg_match("/param_name_(\d+)/", $key, $matches))
00350                                         {
00351                                                 $this->object->addParameterAtIndex($matches[1], $value, $_POST["param_value_$matches[1]"]);
00352                                         }
00353                                 }
00354                                 if (preg_match("/delete_(\d+)/", $this->ctrl->getCmd(), $matches))
00355                                 {
00356                                         $this->object->removeParameter($_POST["param_name_$matches[1]"]);
00357                                 }
00358                         }
00359                 }
00360                 if ($saved)
00361                 {
00362                         $this->object->saveToDb();
00363                         $this->error .= $this->lng->txt("question_saved_for_upload");
00364                 }
00365                 return $result;
00366         }
00367 
00375         function outWorkingForm($test_id = "", $is_postponed = false, $showsolution = 0)
00376         {
00377                 global $ilUser;
00378                 
00379                 $output = $this->outQuestionPage("JAVA_QUESTION", $is_postponed, $test_id);
00380                 $solutionoutput = preg_replace("/.*?(<div[^<]*?ilc_Question.*?<\/div>).*/", "\\1", $output);
00381                 $solutionoutput = preg_replace("/(<\/applet>)/", "<param name=\"solution\" value=\"1\">\n\\1", $solutionoutput);
00382 
00383                 $solutionoutput = "<p>" . $this->lng->txt("correct_solution_is") . ":</p><p>$solutionoutput</p>";
00384                 if ($test_id) 
00385                 {
00386                         $received_points = "<p>" . sprintf($this->lng->txt("you_received_a_of_b_points"), $this->object->getReachedPoints($ilUser->id, $test_id), $this->object->getMaximumPoints()) . "</p>";
00387                 }
00388                 if (!$showsolution)
00389                 {
00390                         $solutionoutput = "";
00391                         $received_points = "";
00392                 }
00393                 $this->tpl->setVariable("JAVA_QUESTION", $output.$solutionoutput.$received_points);
00394         }
00395 
00403         function outUserSolution($user_id, $test_id)
00404         {
00405         }
00406         
00410         function checkInput()
00411         {
00412                 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
00413                 {
00414                         $this->error .= $this->lng->txt("fill_out_all_required_fields");
00415                         return false;
00416                 }
00417                 return true;
00418         }
00419 
00420 
00421         function addSuggestedSolution()
00422         {
00423                 $_SESSION["subquestion_index"] = 0;
00424                 if ($_POST["cmd"]["addSuggestedSolution"])
00425                 {
00426                         $result = $this->writePostData();
00427                         if ($result != 0)
00428                         {
00429                                 $this->editQuestion();
00430                                 return;
00431                         }
00432                 }
00433                 $this->object->saveToDb();
00434                 $_GET["q_id"] = $this->object->getId();
00435                 $this->tpl->setVariable("HEADER", $this->object->getTitle());
00436                 $this->getQuestionTemplate("qt_javaapplet");
00437                 parent::addSuggestedSolution();
00438         }
00439 }
00440 ?>

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