• 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 include_once "./assessment/classes/class.assQuestionGUI.php";
00025 include_once "./assessment/classes/inc.AssessmentConstants.php";
00026 
00038 class ASS_JavaAppletGUI extends ASS_QuestionGUI
00039 {
00048         function ASS_JavaAppletGUI(
00049                 $id = -1
00050         )
00051         {
00052                 $this->ASS_QuestionGUI();
00053                 include_once "./assessment/classes/class.assJavaApplet.php";
00054                 $this->object = new ASS_JavaApplet();
00055                 if ($id >= 0)
00056                 {
00057                         $this->object->loadFromDb($id);
00058                 }
00059         }
00060 
00069         function getQuestionType()
00070         {
00071                 return "qt_javaapplet";
00072         }
00073 
00074         function getCommand($cmd)
00075         {
00076                 if (substr($cmd, 0, 6) == "delete")
00077                 {
00078                         $cmd = "delete";
00079                 }
00080                 return $cmd;
00081         }
00082 
00090         function editQuestion()
00091         {
00092                 //$this->tpl->setVariable("HEADER", $this->object->getTitle());
00093                 $this->getQuestionTemplate("qt_javaapplet");
00094                 $this->tpl->addBlockFile("QUESTION_DATA", "question_data", "tpl.il_as_qpl_javaapplet_question.html", true);
00095                 if ($this->error)
00096                 {
00097                         sendInfo($this->error);
00098                 }
00099                 // call to other question data i.e. estimated working time block
00100                 $this->outOtherQuestionData();
00101                 // image block
00102                 $this->tpl->setCurrentBlock("post_save");
00103 
00104                 $internallinks = array(
00105                         "lm" => $this->lng->txt("obj_lm"),
00106                         "st" => $this->lng->txt("obj_st"),
00107                         "pg" => $this->lng->txt("obj_pg"),
00108                         "glo" => $this->lng->txt("glossary_term")
00109                 );
00110                 foreach ($internallinks as $key => $value)
00111                 {
00112                         $this->tpl->setCurrentBlock("internallink");
00113                         $this->tpl->setVariable("TYPE_INTERNAL_LINK", $key);
00114                         $this->tpl->setVariable("TEXT_INTERNAL_LINK", $value);
00115                         $this->tpl->parseCurrentBlock();
00116                 }
00117                 
00118                 $this->tpl->setVariable("TEXT_SOLUTION_HINT", $this->lng->txt("solution_hint"));
00119                 if (count($this->object->suggested_solutions))
00120                 {
00121                         $solution_array = $this->object->getSuggestedSolution(0);
00122                         include_once "./assessment/classes/class.assQuestion.php";
00123                         $href = ASS_Question::_getInternalLinkHref($solution_array["internal_link"]);
00124                         $this->tpl->setVariable("TEXT_VALUE_SOLUTION_HINT", " <a href=\"$href\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a> ");
00125                         $this->tpl->setVariable("BUTTON_REMOVE_SOLUTION", $this->lng->txt("remove"));
00126                         $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("change"));
00127                         $this->tpl->setVariable("VALUE_SOLUTION_HINT", $solution_array["internal_link"]);
00128                 }
00129                 else
00130                 {
00131                         $this->tpl->setVariable("BUTTON_ADD_SOLUTION", $this->lng->txt("add"));
00132                 }
00133                 
00134                 // java applet block
00135                 $javaapplet = $this->object->getJavaAppletFilename();
00136                 $this->tpl->setVariable("TEXT_JAVAAPPLET", $this->lng->txt("javaapplet"));
00137                 if (!empty($javaapplet))
00138                 {
00139                         $this->tpl->setVariable("JAVAAPPLET_FILENAME", $javaapplet);
00140                         $this->tpl->setVariable("VALUE_JAVAAPPLET_UPLOAD", $this->lng->txt("change"));
00141                         $this->tpl->setCurrentBlock("javaappletupload");
00142                         $this->tpl->setVariable("UPLOADED_JAVAAPPLET", $javaapplet);
00143                         $this->tpl->parse("javaappletupload");
00144                 }
00145                 else
00146                 {
00147                         $this->tpl->setVariable("VALUE_JAVAAPPLET_UPLOAD", $this->lng->txt("upload"));
00148                 }
00149                 $this->tpl->setVariable("TEXT_POINTS", $this->lng->txt("available_points"));
00150                 $this->tpl->setVariable("VALUE_APPLET_POINTS", sprintf("%d", $this->object->getPoints()));
00151                 $this->tpl->parseCurrentBlock();
00152 
00153                 if ($javaapplet)
00154                 {
00155                         $emptyname = 0;
00156                         for ($i = 0; $i < $this->object->getParameterCount(); $i++)
00157                         {
00158                                 // create template for existing applet parameters
00159                                 $this->tpl->setCurrentBlock("delete_parameter");
00160                                 $this->tpl->setVariable("VALUE_DELETE_PARAMETER", $this->lng->txt("delete"));
00161                                 $this->tpl->setVariable("DELETE_PARAMETER_COUNT", $i);
00162                                 $this->tpl->parseCurrentBlock();
00163                                 $this->tpl->setCurrentBlock("applet_parameter");
00164                                 $this->tpl->setVariable("PARAM_PARAM", $this->lng->txt("applet_parameter") . " " . ($i+1));
00165                                 $this->tpl->setVariable("PARAM_NAME", $this->lng->txt("name"));
00166                                 $this->tpl->setVariable("PARAM_VALUE", $this->lng->txt("value"));
00167                                 $param = $this->object->getParameter($i);
00168                                 $this->tpl->setVariable("PARAM_NAME_VALUE", $param["name"]);
00169                                 $this->tpl->setVariable("PARAM_VALUE_VALUE", $param["value"]);
00170                                 $this->tpl->setVariable("PARAM_COUNTER", $i);
00171                                 $this->tpl->parseCurrentBlock();
00172                                 if (!$param["name"])
00173                                 {
00174                                         $emptyname = 1;
00175                                 }
00176                         }
00177                         if ($this->ctrl->getCmd() == "addParameter")
00178                         {
00179                                 if ($emptyname == 0)
00180                                 {
00181                                         // create template for new applet parameter
00182                                         $this->tpl->setCurrentBlock("applet_parameter");
00183                                         $this->tpl->setVariable("PARAM_PARAM", $this->lng->txt("applet_new_parameter"));
00184                                         $this->tpl->setVariable("PARAM_NAME", $this->lng->txt("name"));
00185                                         $this->tpl->setVariable("PARAM_VALUE", $this->lng->txt("value"));
00186                                         $this->tpl->setVariable("PARAM_COUNTER", $this->object->getParameterCount());
00187                                         $this->tpl->parseCurrentBlock();
00188                                 }
00189                                 else
00190                                 {
00191                                         sendInfo($this->lng->txt("too_many_empty_parameters"));
00192                                 }
00193                         }
00194                         $this->tpl->setCurrentBlock("appletcode");
00195                         $this->tpl->setVariable("APPLET_ATTRIBUTES", $this->lng->txt("applet_attributes"));
00196                         $this->tpl->setVariable("TEXT_ARCHIVE", $this->lng->txt("archive"));
00197                         $this->tpl->setVariable("TEXT_CODE", $this->lng->txt("code"));
00198                         $this->tpl->setVariable("TEXT_WIDTH", $this->lng->txt("width"));
00199                         $this->tpl->setVariable("TEXT_HEIGHT", $this->lng->txt("height"));
00200                         $this->tpl->setVariable("VALUE_CODE", $this->object->getJavaCode());
00201                         $this->tpl->setVariable("VALUE_WIDTH", $this->object->getJavaWidth());
00202                         $this->tpl->setVariable("VALUE_HEIGHT", $this->object->getJavaHeight());
00203                         $this->tpl->setVariable("APPLET_PARAMETERS", $this->lng->txt("applet_parameters"));
00204                         $this->tpl->setVariable("VALUE_ADD_PARAMETER", $this->lng->txt("add_applet_parameter"));
00205                         $this->tpl->parseCurrentBlock();
00206                 }
00207 
00208                 $this->tpl->setCurrentBlock("HeadContent");
00209                 $javascript = "<script type=\"text/javascript\">function initialSelect() {\n%s\n}</script>";
00210                 $this->tpl->setVariable("CONTENT_BLOCK", sprintf($javascript, "document.frm_javaapplet.title.focus();"));
00211                 $this->tpl->parseCurrentBlock();
00212                 $this->tpl->setCurrentBlock("question_data");
00213                 $this->tpl->setVariable("JAVAAPPLET_ID", $this->object->getId());
00214                 $this->tpl->setVariable("VALUE_JAVAAPPLET_TITLE", htmlspecialchars($this->object->getTitle()));
00215                 $this->tpl->setVariable("VALUE_JAVAAPPLET_COMMENT", htmlspecialchars($this->object->getComment()));
00216                 $this->tpl->setVariable("VALUE_JAVAAPPLET_AUTHOR", htmlspecialchars($this->object->getAuthor()));
00217                 $questiontext = $this->object->getQuestion();
00218                 $questiontext = preg_replace("/<br \/>/", "\n", $questiontext);
00219                 $this->tpl->setVariable("VALUE_QUESTION", htmlspecialchars($questiontext));
00220                 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
00221                 $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
00222                 $this->tpl->setVariable("TEXT_COMMENT", $this->lng->txt("description"));
00223                 $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
00224                 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
00225 
00226                 $this->tpl->setVariable("SAVE",$this->lng->txt("save"));
00227                 $this->tpl->setVariable("SAVE_EDIT", $this->lng->txt("save_edit"));
00228                 $this->tpl->setVariable("CANCEL",$this->lng->txt("cancel"));
00229                 $this->ctrl->setParameter($this, "sel_question_types", "qt_javaapplet");
00230                 $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt("qt_javaapplet"));
00231                 $formaction = $this->ctrl->getFormaction($this);
00232                 if ($this->object->getId() > 0)
00233                 {
00234                         if (!preg_match("/q_id\=\d+/", $formaction))
00235                         {
00236                                 $formaction = str_replace("q_id=", "q_id=" . $this->object->getId(), $formaction);
00237                         }
00238                 }
00239                 $this->tpl->setVariable("ACTION_JAVAAPPLET_QUESTION", $formaction);
00240                 $this->tpl->parseCurrentBlock();
00241 
00242                 $this->tpl->setCurrentBlock("adm_content");
00243                 $this->tpl->setVariable("BODY_ATTRIBUTES", " onload=\"initialSelect();\""); 
00244                 $this->tpl->parseCurrentBlock();
00245 
00246         }
00247 
00248 
00252         function uploadingJavaApplet()
00253         {
00254                 $result = $this->writePostData();
00255                 if ($result == 0)
00256                 {
00257                         $this->object->saveToDb();
00258                 }
00259                 $this->editQuestion();
00260         }
00261 
00265         function addParameter()
00266         {
00267                 $this->writePostData();
00268                 $this->editQuestion();
00269         }
00270 
00274         function delete()
00275         {
00276                 $this->writePostData();
00277                 $this->editQuestion();
00278         }
00279 
00288         function outOtherQuestionData()
00289         {
00290                 $this->tpl->setCurrentBlock("other_question_data");
00291                 $est_working_time = $this->object->getEstimatedWorkingTime();
00292                 $this->tpl->setVariable("TEXT_WORKING_TIME", $this->lng->txt("working_time"));
00293                 $this->tpl->setVariable("TIME_FORMAT", $this->lng->txt("time_format"));
00294                 $this->tpl->setVariable("VALUE_WORKING_TIME", ilUtil::makeTimeSelect("Estimated", false, $est_working_time[h], $est_working_time[m], $est_working_time[s]));
00295                 $this->tpl->parseCurrentBlock();
00296         }
00297 
00306         function writePostData()
00307         {
00308                 $result = 0;
00309                 $saved = false;
00310                 if (!$this->checkInput())
00311                 {
00312                         $result = 1;
00313                 }
00314 
00315                 $this->object->setTitle(ilUtil::stripSlashes($_POST["title"]));
00316                 $this->object->setAuthor(ilUtil::stripSlashes($_POST["author"]));
00317                 $this->object->setComment(ilUtil::stripSlashes($_POST["comment"]));
00318                 $questiontext = ilUtil::stripSlashes($_POST["question"], true, "<strong><em><code><cite>");
00319                 $questiontext = preg_replace("/\n/", "<br />", $questiontext);
00320                 $this->object->setQuestion($questiontext);
00321                 $this->object->setSuggestedSolution($_POST["solution_hint"], 0);
00322                 $this->object->setShuffle($_POST["shuffle"]);
00323                 $this->object->setPoints($_POST["applet_points"]);
00324                 // adding estimated working time
00325                 $saved = $saved | $this->writeOtherPostData($result);
00326 
00327                 if ($result == 0)
00328                 {
00329                         //setting java applet
00330                         if (empty($_FILES['javaappletName']['tmp_name']))
00331                         {
00332                                 $this->object->setJavaAppletFilename(ilUtil::stripSlashes($_POST['uploaded_javaapplet']));
00333                         }
00334                         else
00335                         {
00336                                 if ($this->object->getId() < 1)
00337                                 {
00338                                         $saved = 1;
00339                                         $this->object->saveToDb();
00340                                 }
00341                                 $this->object->setJavaAppletFilename($_FILES['javaappletName']['name'], $_FILES['javaappletName']['tmp_name']);
00342                         }
00343                         if ($this->object->getJavaAppletFilename())
00344                         {
00345                                 $this->object->setJavaCode($_POST["java_code"]);
00346                                 $this->object->setJavaWidth($_POST["java_width"]);
00347                                 $this->object->setJavaHeight($_POST["java_height"]);
00348                                 if ((!$_POST["java_width"]) or (!$_POST["java_height"])) $result = 1;
00349                                 $this->object->flushParams();
00350                                 foreach ($_POST as $key => $value)
00351                                 {
00352                                         if (preg_match("/param_name_(\d+)/", $key, $matches))
00353                                         {
00354                                                 $this->object->addParameterAtIndex($matches[1], $value, $_POST["param_value_$matches[1]"]);
00355                                         }
00356                                 }
00357                                 if (preg_match("/delete_(\d+)/", $this->ctrl->getCmd(), $matches))
00358                                 {
00359                                         $this->object->removeParameter($_POST["param_name_$matches[1]"]);
00360                                 }
00361                         }
00362                 }
00363                 if ($saved)
00364                 {
00365                         $this->object->saveToDb();
00366                         $this->error .= $this->lng->txt("question_saved_for_upload");
00367                 }
00368                 return $result;
00369         }
00370 
00386         function outWorkingForm(
00387                 $test_id = "", 
00388                 $is_postponed = false, 
00389                 $showsolution = 0, 
00390                 $show_question_page = true, 
00391                 $show_solution_only = false, 
00392                 $ilUser = NULL, 
00393                 $pass = NULL, 
00394                 $mixpass = false
00395         )
00396         {
00397                 if (!is_object($ilUser)) 
00398                 {
00399                         global $ilUser;
00400                 }
00401                 $output = $this->outQuestionPage(($show_solution_only)?"":"JAVA_QUESTION", $is_postponed, $test_id);
00402                 
00403                 if ($showsolution && !$show_solution_only)
00404                 {
00405                         $solutionintroduction = "<p>" . $this->lng->txt("tst_your_answer_was") . "</p>";
00406                         $output = preg_replace("/(<div[^<]*?ilc_PageTitle.*?<\/div>)/", "\\1" . $solutionintroduction, $output);
00407                 }
00408                 $solutionoutput = preg_replace("/.*?(<div[^<]*?ilc_Question.*?<\/div>).*/", "\\1", $output);
00409                 $solutionoutput = preg_replace("/(<\/applet>)/", "<param name=\"solution\" value=\"1\">\n\\1", $solutionoutput);
00410                 
00411                 if ($show_question_page)
00412                         $output = preg_replace("/.*?(<div[^<]*?ilc_Question.*?<\/div>).*/", "\\1", $output);
00413                         
00414                 // if wants solution only then strip the question element from output
00415                 if ($show_solution_only) 
00416                 {
00417                         $output = preg_replace("/(<div[^<]*?ilc_Question[^>]*>.*?<\/div>)/", "", $output);
00418                 }
00419 
00420                 if (!$show_solution_only)
00421                 {
00422                         $solutionoutput = "<p>" . $this->lng->txt("correct_solution_is") . ":</p><p>$solutionoutput</p>";
00423                 }
00424                 
00425                 if ($test_id) 
00426                 {
00427                         $reached_points = $this->object->getReachedPoints($ilUser->id, $test_id);
00428                         $received_points = "<p>" . sprintf($this->lng->txt("you_received_a_of_b_points"), $reached_points, $this->object->getMaximumPoints());
00429                         $count_comment = "";
00430                         if ($reached_points == 0)
00431                         {
00432                                 $count_comment = $this->object->getSolutionCommentCountSystem($test_id);
00433                                 if (strlen($count_comment))
00434                                 {
00435                                         if (strlen($mc_comment) == 0)
00436                                         {
00437                                                 $count_comment = "<span class=\"asterisk\">*</span><br /><br /><span class=\"asterisk\">*</span>$count_comment";
00438                                         }
00439                                         else
00440                                         {
00441                                                 $count_comment = "<br /><span class=\"asterisk\">*</span>$count_comment";
00442                                         }
00443                                 }
00444                         }
00445                         $received_points .= $count_comment;
00446                         $received_points .= "</p>";
00447                 }
00448                 if (!$showsolution)
00449                 {
00450                         $solutionoutput = "";
00451                         $received_points = "";
00452                 }
00453                 $this->tpl->setVariable("JAVA_QUESTION", $output.$solutionoutput.$received_points);
00454         }
00455 
00459         function checkInput()
00460         {
00461                 if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
00462                 {
00463                         $this->error .= $this->lng->txt("fill_out_all_required_fields");
00464                         return false;
00465                 }
00466                 return true;
00467         }
00468 
00469 
00470         function addSuggestedSolution()
00471         {
00472                 $_SESSION["subquestion_index"] = 0;
00473                 if ($_POST["cmd"]["addSuggestedSolution"])
00474                 {
00475                         $result = $this->writePostData();
00476                         if ($result != 0)
00477                         {
00478                                 $this->editQuestion();
00479                                 return;
00480                         }
00481                 }
00482                 $this->object->saveToDb();
00483                 $_GET["q_id"] = $this->object->getId();
00484                 $this->tpl->setVariable("HEADER", $this->object->getTitle());
00485                 $this->getQuestionTemplate("qt_javaapplet");
00486                 parent::addSuggestedSolution();
00487         }
00488 }
00489 ?>

Generated on Fri Dec 13 2013 11:57:52 for ILIAS Release_3_6_x_branch .rev 46809 by  doxygen 1.7.1