00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 include_once "./assessment/classes/class.assQuestion.php";
00024 include_once "./assessment/classes/inc.AssessmentConstants.php";
00025
00036 class assJavaApplet extends assQuestion
00037 {
00045 var $question;
00046
00054 var $javaapplet_filename;
00055
00063 var $java_code;
00064
00072 var $java_codebase;
00073
00081 var $java_archive;
00082
00090 var $java_width;
00091
00099 var $java_height;
00100
00108 var $parameters;
00109
00125 function assJavaApplet(
00126 $title = "",
00127 $comment = "",
00128 $author = "",
00129 $owner = -1,
00130 $question = "",
00131 $javaapplet_filename = ""
00132 )
00133 {
00134 $this->assQuestion($title, $comment, $author, $owner);
00135 $this->question = $question;
00136 $this->javaapplet_filename = $javaapplet_filename;
00137 $this->parameters = array();
00138 }
00139
00140
00154 function fromXML(&$item, &$questionpool_id, &$tst_id, &$tst_object, &$question_counter, &$import_mapping)
00155 {
00156 global $ilUser;
00157
00158
00159 unset($_SESSION["import_mob_xhtml"]);
00160 $presentation = $item->getPresentation();
00161 $duration = $item->getDuration();
00162 $now = getdate();
00163 $applet = NULL;
00164 $maxpoints = 0;
00165 $javacode = "";
00166 $javacodebase = "";
00167 $javaarchive = "";
00168 $params = array();
00169 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
00170 $answers = array();
00171 foreach ($presentation->order as $entry)
00172 {
00173 switch ($entry["type"])
00174 {
00175 case "material":
00176 $material = $presentation->material[$entry["index"]];
00177 for ($i = 0; $i < $material->getMaterialCount(); $i++)
00178 {
00179 $mat = $material->getMaterial($i);
00180 if (strcmp($mat["type"], "mattext") == 0)
00181 {
00182 $mattext = $mat["material"];
00183 if ((strlen($mattext->getLabel()) == 0) && (strlen($this->QTIMaterialToString($item->getQuestiontext())) == 0))
00184 {
00185 $item->setQuestiontext($mattext->getContent());
00186 }
00187 if (strcmp($mattext->getLabel(), "points") == 0)
00188 {
00189 $maxpoints = $mattext->getContent();
00190 }
00191 else if (strcmp($mattext->getLabel(), "java_code") == 0)
00192 {
00193 $javacode = $mattext->getContent();
00194 }
00195 else if (strcmp($mattext->getLabel(), "java_codebase") == 0)
00196 {
00197 $javacodebase = $mattext->getContent();
00198 }
00199 else if (strcmp($mattext->getLabel(), "java_archive") == 0)
00200 {
00201 $javaarchive = $mattext->getContent();
00202 }
00203 else if (strlen($mattext->getLabel()) > 0)
00204 {
00205 array_push($params, array("key" => $mattext->getLabel(), "value" => $mattext->getContent()));
00206 }
00207 }
00208 elseif (strcmp($mat["type"], "matapplet") == 0)
00209 {
00210 $applet = $mat["material"];
00211 }
00212 }
00213 break;
00214 }
00215 }
00216
00217 $this->setTitle($item->getTitle());
00218 $this->setComment($item->getComment());
00219 $this->setAuthor($item->getAuthor());
00220 $this->setOwner($ilUser->getId());
00221 $this->setQuestion($this->QTIMaterialToString($item->getQuestiontext()));
00222 $this->setObjId($questionpool_id);
00223 $this->setEstimatedWorkingTime($duration["h"], $duration["m"], $duration["s"]);
00224 $this->javaapplet_filename = $applet->getUri();
00225 $this->setJavaWidth($applet->getWidth());
00226 $this->setJavaHeight($applet->getHeight());
00227 $this->setJavaCode($javacode);
00228 $this->setJavaCodebase($javacodebase);
00229 $this->setJavaArchive($javaarchive);
00230 $this->setPoints($maxpoints);
00231 foreach ($params as $pair)
00232 {
00233 $this->addParameter($pair["key"], $pair["value"]);
00234 }
00235 $this->saveToDb();
00236 if (count($item->suggested_solutions))
00237 {
00238 foreach ($item->suggested_solutions as $suggested_solution)
00239 {
00240 $this->setSuggestedSolution($suggested_solution["solution"]->getContent(), $suggested_solution["gap_index"], true);
00241 }
00242 $this->saveToDb();
00243 }
00244 $javaapplet =& base64_decode($applet->getContent());
00245 $javapath = $this->getJavaPath();
00246 if (!file_exists($javapath))
00247 {
00248 include_once "./classes/class.ilUtil.php";
00249 ilUtil::makeDirParents($javapath);
00250 }
00251 $javapath .= $this->javaapplet_filename;
00252 $fh = fopen($javapath, "wb");
00253 if ($fh == false)
00254 {
00255
00256
00257
00258 }
00259 else
00260 {
00261 $javafile = fwrite($fh, $javaapplet);
00262 fclose($fh);
00263 }
00264
00265 if (is_array($_SESSION["import_mob_xhtml"]))
00266 {
00267 include_once "./content/classes/Media/class.ilObjMediaObject.php";
00268 include_once "./Services/RTE/classes/class.ilRTE.php";
00269 foreach ($_SESSION["import_mob_xhtml"] as $mob)
00270 {
00271 if ($tst_id > 0)
00272 {
00273 include_once "./assessment/classes/class.ilObjTest.php";
00274 $importfile = ilObjTest::_getImportDirectory() . "/" . $_SESSION["tst_import_subdir"] . "/" . $mob["uri"];
00275 }
00276 else
00277 {
00278 include_once "./assessment/classes/class.ilObjQuestionPool.php";
00279 $importfile = ilObjQuestionPool::_getImportDirectory() . "/" . $_SESSION["qpl_import_subdir"] . "/" . $mob["uri"];
00280 }
00281 $media_object =& ilObjMediaObject::_saveTempFileAsMediaObject(basename($importfile), $importfile, FALSE);
00282 ilObjMediaObject::_saveUsage($media_object->getId(), "qpl:html", $this->getId());
00283 $this->setQuestion(ilRTE::_replaceMediaObjectImageSrc(str_replace("src=\"" . $mob["mob"] . "\"", "src=\"" . "il_" . IL_INST_ID . "_mob_" . $media_object->getId() . "\"", $this->getQuestion()), 1));
00284 }
00285 $this->saveToDb();
00286 }
00287 if ($tst_id > 0)
00288 {
00289 $q_1_id = $this->getId();
00290 $question_id = $this->duplicate(true);
00291 $tst_object->questions[$question_counter++] = $question_id;
00292 $import_mapping[$item->getIdent()] = array("pool" => $q_1_id, "test" => $question_id);
00293 }
00294 else
00295 {
00296 $import_mapping[$item->getIdent()] = array("pool" => $this->getId(), "test" => 0);
00297 }
00298
00299 }
00300
00310 function to_xml($a_include_header = true, $a_include_binary = true, $a_shuffle = false, $test_output = false, $force_image_references = false)
00311 {
00312 include_once("./classes/class.ilXmlWriter.php");
00313 $a_xml_writer = new ilXmlWriter;
00314
00315 $a_xml_writer->xmlHeader();
00316 $a_xml_writer->xmlStartTag("questestinterop");
00317 $attrs = array(
00318 "ident" => "il_".IL_INST_ID."_qst_".$this->getId(),
00319 "title" => $this->getTitle()
00320 );
00321 $a_xml_writer->xmlStartTag("item", $attrs);
00322
00323 $a_xml_writer->xmlElement("qticomment", NULL, $this->getComment());
00324
00325 $workingtime = $this->getEstimatedWorkingTime();
00326 $duration = sprintf("P0Y0M0DT%dH%dM%dS", $workingtime["h"], $workingtime["m"], $workingtime["s"]);
00327 $a_xml_writer->xmlElement("duration", NULL, $duration);
00328
00329 $a_xml_writer->xmlStartTag("itemmetadata");
00330 $a_xml_writer->xmlStartTag("qtimetadata");
00331 $a_xml_writer->xmlStartTag("qtimetadatafield");
00332 $a_xml_writer->xmlElement("fieldlabel", NULL, "ILIAS_VERSION");
00333 $a_xml_writer->xmlElement("fieldentry", NULL, $this->ilias->getSetting("ilias_version"));
00334 $a_xml_writer->xmlEndTag("qtimetadatafield");
00335 $a_xml_writer->xmlStartTag("qtimetadatafield");
00336 $a_xml_writer->xmlElement("fieldlabel", NULL, "QUESTIONTYPE");
00337 $a_xml_writer->xmlElement("fieldentry", NULL, JAVAAPPLET_QUESTION_IDENTIFIER);
00338 $a_xml_writer->xmlEndTag("qtimetadatafield");
00339 $a_xml_writer->xmlStartTag("qtimetadatafield");
00340 $a_xml_writer->xmlElement("fieldlabel", NULL, "AUTHOR");
00341 $a_xml_writer->xmlElement("fieldentry", NULL, $this->getAuthor());
00342 $a_xml_writer->xmlEndTag("qtimetadatafield");
00343 $a_xml_writer->xmlEndTag("qtimetadata");
00344 $a_xml_writer->xmlEndTag("itemmetadata");
00345
00346
00347 $attrs = array(
00348 "label" => $this->getTitle()
00349 );
00350 $a_xml_writer->xmlStartTag("presentation", $attrs);
00351
00352 $a_xml_writer->xmlStartTag("flow");
00353
00354 $this->addQTIMaterial($a_xml_writer, $this->getQuestion());
00355 $solution = $this->getSuggestedSolution(0);
00356 if (count($solution))
00357 {
00358 if (preg_match("/il_(\d*?)_(\w+)_(\d+)/", $solution["internal_link"], $matches))
00359 {
00360 $a_xml_writer->xmlStartTag("material");
00361 $intlink = "il_" . IL_INST_ID . "_" . $matches[2] . "_" . $matches[3];
00362 if (strcmp($matches[1], "") != 0)
00363 {
00364 $intlink = $solution["internal_link"];
00365 }
00366 $attrs = array(
00367 "label" => "suggested_solution"
00368 );
00369 $a_xml_writer->xmlElement("mattext", $attrs, $intlink);
00370 $a_xml_writer->xmlEndTag("material");
00371 }
00372 }
00373
00374 $a_xml_writer->xmlStartTag("material");
00375 $attrs = array(
00376 "label" => "applet data",
00377 "uri" => $this->getJavaAppletFilename(),
00378 "height" => $this->getJavaHeight(),
00379 "width" => $this->getJavaWidth(),
00380 "embedded" => "base64"
00381 );
00382 $javapath = $this->getJavaPath() . $this->getJavaAppletFilename();
00383 $fh = @fopen($javapath, "rb");
00384 if ($fh == false)
00385 {
00386 return;
00387 }
00388 $javafile = fread($fh, filesize($javapath));
00389 fclose($fh);
00390 $base64 = base64_encode($javafile);
00391 $a_xml_writer->xmlElement("matapplet", $attrs, $base64);
00392
00393 if ($this->buildParamsOnly())
00394 {
00395 if ($this->java_code)
00396 {
00397 $attrs = array(
00398 "label" => "java_code"
00399 );
00400 $a_xml_writer->xmlElement("mattext", $attrs, $this->java_code);
00401 }
00402 if ($this->java_codebase)
00403 {
00404 $attrs = array(
00405 "label" => "java_codebase"
00406 );
00407 $a_xml_writer->xmlElement("mattext", $attrs, $this->java_codebase);
00408 }
00409 if ($this->java_archive)
00410 {
00411 $attrs = array(
00412 "label" => "java_archive"
00413 );
00414 $a_xml_writer->xmlElement("mattext", $attrs, $this->java_archive);
00415 }
00416 foreach ($this->parameters as $key => $value)
00417 {
00418 $attrs = array(
00419 "label" => $value["name"]
00420 );
00421 $a_xml_writer->xmlElement("mattext", $attrs, $value["value"]);
00422 }
00423 }
00424 $a_xml_writer->xmlEndTag("material");
00425 $a_xml_writer->xmlStartTag("material");
00426 $attrs = array(
00427 "label" => "points"
00428 );
00429 $a_xml_writer->xmlElement("mattext", $attrs, $this->getPoints());
00430 $a_xml_writer->xmlEndTag("material");
00431
00432 $a_xml_writer->xmlEndTag("flow");
00433 $a_xml_writer->xmlEndTag("presentation");
00434
00435 $a_xml_writer->xmlEndTag("item");
00436 $a_xml_writer->xmlEndTag("questestinterop");
00437
00438 $xml = $a_xml_writer->xmlDumpMem(FALSE);
00439 if (!$a_include_header)
00440 {
00441 $pos = strpos($xml, "?>");
00442 $xml = substr($xml, $pos + 2);
00443 }
00444 return $xml;
00445 }
00446
00455 function splitParams($params = "")
00456 {
00457 $params_array = split("<separator>", $params);
00458 foreach ($params_array as $pair)
00459 {
00460 if (preg_match("/(.*?)\=(.*)/", $pair, $matches))
00461 {
00462 switch ($matches[1])
00463 {
00464 case "java_code" :
00465 $this->java_code = $matches[2];
00466 break;
00467 case "java_codebase" :
00468 $this->java_codebase = $matches[2];
00469 break;
00470 case "java_archive" :
00471 $this->java_archive = $matches[2];
00472 break;
00473 case "java_width" :
00474 $this->java_width = $matches[2];
00475 break;
00476 case "java_height" :
00477 $this->java_height = $matches[2];
00478 break;
00479 }
00480 if (preg_match("/param_name_(\d+)/", $matches[1], $found_key))
00481 {
00482 $this->parameters[$found_key[1]]["name"] = $matches[2];
00483 }
00484 if (preg_match("/param_value_(\d+)/", $matches[1], $found_key))
00485 {
00486 $this->parameters[$found_key[1]]["value"] = $matches[2];
00487 }
00488 }
00489 }
00490 }
00491
00500 function buildParams()
00501 {
00502 $params_array = array();
00503 if ($this->java_code)
00504 {
00505 array_push($params_array, "java_code=$this->java_code");
00506 }
00507 if ($this->java_codebase)
00508 {
00509 array_push($params_array, "java_codebase=$this->java_codebase");
00510 }
00511 if ($this->java_archive)
00512 {
00513 array_push($params_array, "java_archive=$this->java_archive");
00514 }
00515 if ($this->java_width)
00516 {
00517 array_push($params_array, "java_width=$this->java_width");
00518 }
00519 if ($this->java_height)
00520 {
00521 array_push($params_array, "java_height=$this->java_height");
00522 }
00523 foreach ($this->parameters as $key => $value)
00524 {
00525 array_push($params_array, "param_name_$key=" . $value["name"]);
00526 array_push($params_array, "param_value_$key=" . $value["value"]);
00527 }
00528 return join($params_array, "<separator>");
00529 }
00530
00539 function buildParamsOnly()
00540 {
00541 $params_array = array();
00542 if ($this->java_code)
00543 {
00544 array_push($params_array, "java_code=$this->java_code");
00545 array_push($params_array, "java_codebase=$this->java_codebase");
00546 array_push($params_array, "java_archive=$this->java_archive");
00547 }
00548 foreach ($this->parameters as $key => $value)
00549 {
00550 array_push($params_array, "param_name_$key=" . $value["name"]);
00551 array_push($params_array, "param_value_$key=" . $value["value"]);
00552 }
00553 return join($params_array, "<separator>");
00554 }
00555
00564 function isComplete()
00565 {
00566 if (($this->title) and ($this->author) and ($this->question) and ($this->javaapplet_filename) and ($this->java_width) and ($this->java_height) and ($this->getMaximumPoints() > 0))
00567 {
00568 return true;
00569 }
00570 else if (($this->title) and ($this->author) and ($this->question) and ($this->getJavaArchive()) and ($this->getJavaCodebase()) and ($this->java_width) and ($this->java_height) and ($this->getMaximumPoints() > 0))
00571 {
00572 return true;
00573 }
00574 else
00575 {
00576 return false;
00577 }
00578 }
00579
00580
00589 function saveToDb($original_id = "")
00590 {
00591 global $ilDB;
00592
00593 $complete = 0;
00594 if ($this->isComplete())
00595 {
00596 $complete = 1;
00597 }
00598
00599 $params = $this->buildParams();
00600 $estw_time = $this->getEstimatedWorkingTime();
00601 $estw_time = sprintf("%02d:%02d:%02d", $estw_time['h'], $estw_time['m'], $estw_time['s']);
00602
00603 if ($original_id)
00604 {
00605 $original_id = $ilDB->quote($original_id);
00606 }
00607 else
00608 {
00609 $original_id = "NULL";
00610 }
00611
00612
00613 include_once("./Services/RTE/classes/class.ilRTE.php");
00614 ilRTE::_cleanupMediaObjectUsage($this->question, "qpl:html",
00615 $this->getId());
00616
00617 if ($this->id == -1)
00618 {
00619
00620 $now = getdate();
00621 $question_type = $this->getQuestionType();
00622 $created = sprintf("%04d%02d%02d%02d%02d%02d", $now['year'], $now['mon'], $now['mday'], $now['hours'], $now['minutes'], $now['seconds']);
00623 $query = sprintf("INSERT INTO qpl_questions (question_id, question_type_fi, obj_fi, title, comment, author, owner, question_text, points, working_time, complete, created, original_id, TIMESTAMP) VALUES (NULL, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NULL)",
00624 $ilDB->quote($question_type . ""),
00625 $ilDB->quote($this->obj_id . ""),
00626 $ilDB->quote($this->title . ""),
00627 $ilDB->quote($this->comment . ""),
00628 $ilDB->quote($this->author . ""),
00629 $ilDB->quote($this->owner . ""),
00630 $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->question, 0)),
00631 $ilDB->quote($this->points . ""),
00632 $ilDB->quote($estw_time . ""),
00633 $ilDB->quote($complete . ""),
00634 $ilDB->quote($created . ""),
00635 $original_id
00636 );
00637
00638 $result = $ilDB->query($query);
00639 if ($result == DB_OK)
00640 {
00641 $this->id = $ilDB->getLastInsertId();
00642 $query = sprintf("INSERT INTO qpl_question_javaapplet (question_fi, image_file, params) VALUES (%s, %s, %s)",
00643 $ilDB->quote($this->id . ""),
00644 $ilDB->quote($this->javaapplet_filename . ""),
00645 $ilDB->quote($params . "")
00646 );
00647 $ilDB->query($query);
00648
00649
00650 $this->createPageObject();
00651
00652 if ($this->getTestId() > 0)
00653 {
00654 $this->insertIntoTest($this->getTestId());
00655 }
00656 }
00657 }
00658 else
00659 {
00660
00661 $query = sprintf("UPDATE qpl_questions SET obj_fi = %s, title = %s, comment = %s, author = %s, question_text = %s, points = %s, working_time=%s, complete = %s WHERE question_id = %s",
00662 $ilDB->quote($this->obj_id. ""),
00663 $ilDB->quote($this->title . ""),
00664 $ilDB->quote($this->comment . ""),
00665 $ilDB->quote($this->author . ""),
00666 $ilDB->quote(ilRTE::_replaceMediaObjectImageSrc($this->question, 0)),
00667 $ilDB->quote($this->points . ""),
00668 $ilDB->quote($estw_time . ""),
00669 $ilDB->quote($complete . ""),
00670 $ilDB->quote($this->id . "")
00671 );
00672 $result = $ilDB->query($query);
00673 $query = sprintf("UPDATE qpl_question_javaapplet SET image_file = %s, params = %s WHERE question_fi = %s",
00674 $ilDB->quote($this->javaapplet_filename . ""),
00675 $ilDB->quote($params . ""),
00676 $ilDB->quote($this->id . "")
00677 );
00678 $result = $ilDB->query($query);
00679 }
00680 parent::saveToDb($original_id);
00681 }
00682
00692 function loadFromDb($question_id)
00693 {
00694 global $ilDB;
00695
00696 $query = sprintf("SELECT qpl_questions.*, qpl_question_javaapplet.* FROM qpl_questions, qpl_question_javaapplet WHERE question_id = %s AND qpl_questions.question_id = qpl_question_javaapplet.question_fi",
00697 $ilDB->quote($question_id)
00698 );
00699 $result = $ilDB->query($query);
00700
00701 if (strcmp(strtolower(get_class($result)), db_result) == 0)
00702 {
00703 if ($result->numRows() == 1)
00704 {
00705 $data = $result->fetchRow(DB_FETCHMODE_OBJECT);
00706 $this->id = $question_id;
00707 $this->title = $data->title;
00708 $this->comment = $data->comment;
00709 $this->obj_id = $data->obj_fi;
00710 $this->author = $data->author;
00711 $this->points = $data->points;
00712 $this->owner = $data->owner;
00713 $this->original_id = $data->original_id;
00714 $this->javaapplet_filename = $data->image_file;
00715 include_once("./Services/RTE/classes/class.ilRTE.php");
00716 $this->question = ilRTE::_replaceMediaObjectImageSrc($data->question_text, 1);
00717 $this->solution_hint = $data->solution_hint;
00718 $this->splitParams($data->params);
00719 $this->setEstimatedWorkingTime(substr($data->working_time, 0, 2), substr($data->working_time, 3, 2), substr($data->working_time, 6, 2));
00720 }
00721 }
00722 parent::loadFromDb($question_id);
00723 }
00724
00732 function duplicate($for_test = true, $title = "", $author = "", $owner = "")
00733 {
00734 if ($this->id <= 0)
00735 {
00736
00737 return;
00738 }
00739
00740 $this_id = $this->getId();
00741 $clone = $this;
00742 include_once ("./assessment/classes/class.assQuestion.php");
00743 $original_id = assQuestion::_getOriginalId($this->id);
00744 $clone->id = -1;
00745 if ($title)
00746 {
00747 $clone->setTitle($title);
00748 }
00749 if ($author)
00750 {
00751 $clone->setAuthor($author);
00752 }
00753 if ($owner)
00754 {
00755 $clone->setOwner($owner);
00756 }
00757 if ($for_test)
00758 {
00759 $clone->saveToDb($original_id);
00760 }
00761 else
00762 {
00763 $clone->saveToDb();
00764 }
00765
00766
00767 $clone->copyPageOfQuestion($this_id);
00768
00769 $clone->copyXHTMLMediaObjectsOfQuestion($this_id);
00770
00771
00772 $clone->duplicateApplet($this_id);
00773 return $clone->id;
00774 }
00775
00783 function copyObject($target_questionpool, $title = "")
00784 {
00785 if ($this->id <= 0)
00786 {
00787
00788 return;
00789 }
00790
00791 $clone = $this;
00792 include_once ("./assessment/classes/class.assQuestion.php");
00793 $original_id = assQuestion::_getOriginalId($this->id);
00794 $clone->id = -1;
00795 $source_questionpool = $this->getObjId();
00796 $clone->setObjId($target_questionpool);
00797 if ($title)
00798 {
00799 $clone->setTitle($title);
00800 }
00801 $clone->saveToDb();
00802
00803
00804 $clone->copyPageOfQuestion($original_id);
00805
00806 $clone->copyXHTMLMediaObjectsOfQuestion($original_id);
00807
00808
00809 $clone->copyApplet($original_id, $source_questionpool);
00810 return $clone->id;
00811 }
00812
00813 function duplicateApplet($question_id)
00814 {
00815 $javapath = $this->getJavaPath();
00816 $javapath_original = preg_replace("/([^\d])$this->id([^\d])/", "\${1}$question_id\${2}", $javapath);
00817 if (!file_exists($javapath))
00818 {
00819 ilUtil::makeDirParents($javapath);
00820 }
00821 $filename = $this->getJavaAppletFilename();
00822 if (!copy($javapath_original . $filename, $javapath . $filename)) {
00823 print "java applet could not be duplicated!!!! ";
00824 }
00825 }
00826
00827 function copyApplet($question_id, $source_questionpool)
00828 {
00829 $javapath = $this->getJavaPath();
00830 $javapath_original = preg_replace("/([^\d])$this->id([^\d])/", "\${1}$question_id\${2}", $javapath);
00831 $javapath_original = str_replace("/$this->obj_id/", "/$source_questionpool/", $javapath_original);
00832 if (!file_exists($javapath))
00833 {
00834 ilUtil::makeDirParents($javapath);
00835 }
00836 $filename = $this->getJavaAppletFilename();
00837 if (!copy($javapath_original . $filename, $javapath . $filename)) {
00838 print "java applet could not be copied!!!! ";
00839 }
00840 }
00841
00851 function getQuestion()
00852 {
00853 return $this->question;
00854 }
00855
00865 function setQuestion($question = "")
00866 {
00867 $this->question = $question;
00868 }
00869
00878 function getMaximumPoints()
00879 {
00880 return $this->points;
00881 }
00882
00891 function getJavaCode()
00892 {
00893 return $this->java_code;
00894 }
00895
00904 function getJavaCodebase()
00905 {
00906 return $this->java_codebase;
00907 }
00908
00917 function getJavaArchive()
00918 {
00919 return $this->java_archive;
00920 }
00921
00930 function setJavaCode($java_code = "")
00931 {
00932 $this->java_code = $java_code;
00933 }
00934
00943 function setJavaCodebase($java_codebase = "")
00944 {
00945 $this->java_codebase = $java_codebase;
00946 }
00947
00956 function setJavaArchive($java_archive = "")
00957 {
00958 $this->java_archive = $java_archive;
00959 }
00960
00969 function getJavaWidth()
00970 {
00971 return $this->java_width;
00972 }
00973
00982 function setJavaWidth($java_width = "")
00983 {
00984 $this->java_width = $java_width;
00985 }
00986
00995 function getJavaHeight()
00996 {
00997 return $this->java_height;
00998 }
00999
01008 function setJavaHeight($java_height = "")
01009 {
01010 $this->java_height = $java_height;
01011 }
01012
01024 function calculateReachedPoints($active_id, $pass = NULL)
01025 {
01026 global $ilDB;
01027
01028 $found_values = array();
01029 if (is_null($pass))
01030 {
01031 $pass = $this->getSolutionMaxPass($active_id);
01032 }
01033 $query = sprintf("SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
01034 $ilDB->quote($active_id . ""),
01035 $ilDB->quote($this->getId() . ""),
01036 $ilDB->quote($pass . "")
01037 );
01038 $result = $ilDB->query($query);
01039 $points = 0;
01040 while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
01041 {
01042 $points += $data->points;
01043 }
01044
01045 $points = parent::calculateReachedPoints($active_id, $pass = NULL, $points);
01046 return $points;
01047 }
01048
01058 function getReachedInformation($active_id, $pass = NULL)
01059 {
01060 global $ilDB;
01061
01062 $found_values = array();
01063 if (is_null($pass))
01064 {
01065 $pass = $this->getSolutionMaxPass($active_id);
01066 }
01067 $query = sprintf("SELECT * FROM tst_solutions WHERE active_fi = %s AND question_fi = %s AND pass = %s",
01068 $ilDB->quote($active_id . ""),
01069 $ilDB->quote($this->getId() . ""),
01070 $ilDB->quote($pass . "")
01071 );
01072 $result = $ilDB->query($query);
01073 $counter = 1;
01074 $user_result = array();
01075 while ($data = $result->fetchRow(DB_FETCHMODE_OBJECT))
01076 {
01077 $true = 0;
01078 if ($data->points > 0)
01079 {
01080 $true = 1;
01081 }
01082 $solution = array(
01083 "order" => "$counter",
01084 "points" => "$data->points",
01085 "true" => "$true",
01086 "value1" => "$data->value1",
01087 "value2" => "$data->value2",
01088 );
01089 $counter++;
01090 array_push($user_result, $solution);
01091 }
01092 return $user_result;
01093 }
01094
01105 function addParameter($name = "", $value = "")
01106 {
01107 $index = $this->getParameterIndex($name);
01108 if ($index > -1)
01109 {
01110 $this->parameters[$index] = array("name" => $name, "value" => $value);
01111 }
01112 else
01113 {
01114 array_push($this->parameters, array("name" => $name, "value" => $value));
01115 }
01116 }
01117
01129 function addParameterAtIndex($index = 0, $name = "", $value = "")
01130 {
01131 $this->parameters[$index] = array("name" => $name, "value" => $value);
01132 }
01133
01143 function removeParameter($name)
01144 {
01145 foreach ($this->parameters as $key => $value)
01146 {
01147 if (strcmp($name, $value["name"]) == 0)
01148 {
01149 array_splice($this->parameters, $key, 1);
01150 return;
01151 }
01152 }
01153 }
01154
01165 function getParameter($index)
01166 {
01167 if (($index < 0) or ($index >= count($this->parameters)))
01168 {
01169 return undef;
01170 }
01171 return $this->parameters[$index];
01172 }
01173
01184 function getParameterIndex($name)
01185 {
01186 foreach ($this->parameters as $key => $value)
01187 {
01188 if (array_key_exists($name, $value))
01189 {
01190 return $key;
01191 }
01192 }
01193 return -1;
01194 }
01195
01205 function getParameterCount()
01206 {
01207 return count($this->parameters);
01208 }
01209
01218 function flushParams()
01219 {
01220 $this->parameters = array();
01221 }
01222
01233 function saveWorkingData($active_id, $pass = NULL)
01234 {
01235 parent::saveWorkingData($active_id, $pass);
01236 return true;
01237 }
01238
01248 function getJavaAppletFilename()
01249 {
01250 return $this->javaapplet_filename;
01251 }
01252
01262 function setJavaAppletFilename($javaapplet_filename, $javaapplet_tempfilename = "")
01263 {
01264 if (!empty($javaapplet_filename))
01265 {
01266 $this->javaapplet_filename = $javaapplet_filename;
01267 }
01268 if (!empty($javaapplet_tempfilename))
01269 {
01270 $javapath = $this->getJavaPath();
01271 if (!file_exists($javapath))
01272 {
01273 ilUtil::makeDirParents($javapath);
01274 }
01275
01276
01277 if (!ilUtil::moveUploadedFile($javaapplet_tempfilename, $javaapplet_filename, $javapath.$javaapplet_filename))
01278 {
01279 print "java applet not uploaded!!!! ";
01280 }
01281 else
01282 {
01283 $this->setJavaCodebase();
01284 $this->setJavaArchive();
01285 }
01286 }
01287 }
01288
01289 function deleteJavaAppletFilename()
01290 {
01291 unlink($this->getJavaPath() . $this->getJavaAppletFilename());
01292 $this->javaapplet_filename = "";
01293 }
01294
01295 function syncWithOriginal()
01296 {
01297 global $ilDB;
01298
01299 if ($this->original_id)
01300 {
01301 $complete = 0;
01302 if ($this->isComplete())
01303 {
01304 $complete = 1;
01305 }
01306
01307 $estw_time = $this->getEstimatedWorkingTime();
01308 $estw_time = sprintf("%02d:%02d:%02d", $estw_time['h'], $estw_time['m'], $estw_time['s']);
01309
01310 $query = sprintf("UPDATE qpl_questions SET obj_fi = %s, title = %s, comment = %s, author = %s, question_text = %s, points = %s, working_time=%s, complete = %s WHERE question_id = %s",
01311 $ilDB->quote($this->obj_id. ""),
01312 $ilDB->quote($this->title . ""),
01313 $ilDB->quote($this->comment . ""),
01314 $ilDB->quote($this->author . ""),
01315 $ilDB->quote($this->question . ""),
01316 $ilDB->quote($this->points . ""),
01317 $ilDB->quote($estw_time . ""),
01318 $ilDB->quote($complete . ""),
01319 $ilDB->quote($this->original_id . "")
01320 );
01321 $result = $ilDB->query($query);
01322 $params = $this->buildParams();
01323 $query = sprintf("UPDATE qpl_question_javaapplet SET image_file = %s, params = %s WHERE question_fi = %s",
01324 $ilDB->quote($this->javaapplet_filename . ""),
01325 $ilDB->quote($params . ""),
01326 $ilDB->quote($this->original_id . "")
01327 );
01328 $result = $ilDB->query($query);
01329
01330 parent::syncWithOriginal();
01331 }
01332 }
01333
01342 function getQuestionType()
01343 {
01344 return 7;
01345 }
01346
01355 function getAdditionalTableName()
01356 {
01357 return "qpl_question_javaapplet";
01358 }
01359 }
01360
01361 ?>