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

assessment/classes/class.ilObjTestGUI.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 
00038 include_once "./assessment/classes/class.ilObjQuestionPool.php";
00039 include_once "./classes/class.ilObjectGUI.php";
00040 //include_once "./classes/class.ilMetaDataGUI.php";
00041 include_once "./assessment/classes/class.assQuestionGUI.php";
00042 require_once "./classes/class.ilSearch.php";
00043 require_once "./classes/class.ilObjUser.php";
00044 require_once "./classes/class.ilObjGroup.php";
00045 
00046 define ("TYPE_XLS_PC", "latin1");
00047 define ("TYPE_XLS_MAC", "macos");
00048 define ("TYPE_SPSS", "csv");
00049 
00050 class ilObjTestGUI extends ilObjectGUI
00051 {
00052         var $sequence;
00053 
00054         var $cmdCtrl;
00055 
00056         var $maxProcessingTimeReached;
00057 
00058         var $endingTimeReached;
00059 
00060         var $saveResult;
00061 
00066         function ilObjTestGUI($a_data,$a_id,$a_call_by_reference = true, $a_prepare_output = true)
00067         {
00068                 global $lng, $ilCtrl;
00069                 $lng->loadLanguageModule("assessment");
00070                 $this->type = "tst";
00071                 $this->ilObjectGUI($a_data,$a_id,$a_call_by_reference, false);
00072                 if (!defined("ILIAS_MODULE"))
00073                 {
00074                         $this->setTabTargetScript("adm_object.php");
00075                 }
00076                 else
00077                 {
00078                         $this->setTabTargetScript("test.php");
00079                 }
00080                 if ($a_prepare_output) {
00081                         $this->prepareOutput();
00082                 }
00083 
00084                 $this->ctrl =& $ilCtrl;
00085                 $this->ctrl->saveParameter($this, "ref_id");
00086 
00087                 // Added parameter if called from crs_objectives
00088                 if((int) $_GET['crs_show_result'])
00089                 {
00090                         $this->ctrl->saveParameter($this,'crs_show_result',(int) $_GET['crs_show_result']);
00091                 }
00092         }
00093         
00094         function createCommandControlObject() {
00095                 global $rbacsystem;
00096                 
00097                 if (!$rbacsystem->checkAccess("read", $this->ref_id)) 
00098                 {
00099                         // only with read access it is possible to run the test
00100                         $this->ilias->raiseError($this->lng->txt("cannot_execute_test"),$this->ilias->error_obj->MESSAGE);
00101                 }
00102                 
00103                 include_once "./assessment/classes/class.ilCommandControl.php";;
00104                 if ($this->object->isOnlineTest()) {
00105                         include_once "./assessment/classes/class.ilOnlineTestCommandControl.php";;
00106                         $this->cmdCtrl = new OnlineTestCommandControl ($this, $this->object);
00107                 } else 
00108                         $this->cmdCtrl = new DefaultTestCommandControl ($this, $this->object);
00109         }
00110 
00114         function &executeCommand()
00115         {
00116                 $cmd = $this->ctrl->getCmd("properties");
00117                 $next_class = $this->ctrl->getNextClass($this);
00118                 $this->ctrl->setReturn($this, "properties");
00119 
00120                 #echo "<br>nextclass:$next_class:cmd:$cmd:qtype=$q_type";
00121                 switch($next_class)
00122                 {
00123                         case 'ilmdeditorgui':
00124                                 $this->setAdminTabs();
00125                                 include_once 'Services/MetaData/classes/class.ilMDEditorGUI.php';
00126 
00127                                 $md_gui =& new ilMDEditorGUI($this->object->getId(), 0, $this->object->getType());
00128                                 $md_gui->addObserver($this->object,'MDUpdateListener','General');
00129 
00130                                 $this->ctrl->forwardCommand($md_gui);
00131                                 break;
00132 
00133                         default:
00134                                 switch ($cmd)
00135                                 {
00136                                         case "run":
00137                                         case "eval_a":
00138                                         case "eval_stat":
00139                                         case "evalStatSelected":
00140                                         case "searchForEvaluation":
00141                                         case "outTestResults":
00142                                         case "outIntroductionPage":
00143                                         case "addFoundGroupsToEval":
00144                                         case "removeSelectedGroup":
00145                                         case "removeSelectedUser":
00146                                         case "addFoundUsersToEval":
00147                                         case "evalSelectedUsers":
00148                                         case "evalAllUsers":
00149                                         case "printAnswers":
00150                                                 break;
00151                                         default:
00152                                                 $this->setAdminTabs();
00153                                 }
00154                                 if ((strcmp($cmd, "properties") == 0) && ($_GET["browse"]))
00155                                 {
00156                                         $this->questionBrowser();
00157                                         return;
00158                                 }
00159                                 if ((strcmp($cmd, "properties") == 0) && ($_GET["up"] || $_GET["down"]))
00160                                 {
00161                                         $this->questionsObject();
00162                                         return;
00163                                 }
00164                                 $cmd.= "Object";
00165                                 $ret =& $this->$cmd();
00166                                 break;
00167                 }
00168         }
00169 
00175         function getCallingScript()
00176         {
00177                 return "test.php";
00178         }
00179 
00183         function importFileObject()
00184         {
00185                 if ($_POST["qpl"] < 1)
00186                 {
00187                         sendInfo($this->lng->txt("tst_select_questionpools"));
00188                         $this->createObject();
00189                         return;
00190                 }
00191                 if (strcmp($_FILES["xmldoc"]["tmp_name"], "") == 0)
00192                 {
00193                         sendInfo($this->lng->txt("tst_select_file_for_import"));
00194                         $this->createObject();
00195                         return;
00196                 }
00197                 $this->uploadTstObject();
00198         }
00199         
00203         function cloneAllObject()
00204         {
00205                 if ($_POST["tst"] < 1)
00206                 {
00207                         sendInfo($this->lng->txt("tst_select_tsts"));
00208                         $this->createObject();
00209                         return;
00210                 }
00211                 include_once "./assessment/classes/class.ilObjTest.php";
00212                 ilObjTest::_clone($_POST["tst"]);
00213                 ilUtil::redirect($this->getReturnLocation("save", "adm_object.php?ref_id=" . $_GET["ref_id"]));
00214         }
00215         
00220         function saveObject()
00221         {
00222                 global $rbacadmin;
00223 
00224                 // create and insert forum in objecttree
00225                 $newObj = parent::saveObject();
00226 
00227                 // setup rolefolder & default local roles
00228                 //$roles = $newObj->initDefaultRoles();
00229 
00230                 // ...finally assign role to creator of object
00231                 //$rbacadmin->assignUser($roles[0], $newObj->getOwner(), "y");
00232 
00233                 // put here object specific stuff
00234 
00235                 // always send a message
00236                 sendInfo($this->lng->txt("object_added"),true);
00237 
00238                 $returnlocation = "test.php";
00239                 if (!defined("ILIAS_MODULE"))
00240                 {
00241                         $returnlocation = "adm_object.php";
00242                 }
00243                 ilUtil::redirect($this->getReturnLocation("save","$returnlocation?".$this->link_params));
00244                 exit();
00245         }
00246 
00247         function getAddParameter()
00248         {
00249                 return "?ref_id=" . $_GET["ref_id"] . "&cmd=" . $_GET["cmd"] . '&crs_show_result='. (int) $_GET['crs_show_result'];
00250         }
00251 
00252         /*
00253         * list all export files
00254         */
00255         function exportObject()
00256         {
00257                 global $tree;
00258                 global $rbacsystem;
00259 
00260                 if ((!$rbacsystem->checkAccess("read", $this->ref_id)) && (!$rbacsystem->checkAccess("write", $this->ref_id))) 
00261                 {
00262                         // allow only read and write access
00263                         sendInfo($this->lng->txt("cannot_edit_test"), true);
00264                         $path = $this->tree->getPathFull($this->object->getRefID());
00265                         ilUtil::redirect($this->getReturnLocation("cancel","../repository.php?ref_id=" . $path[count($path) - 2]["child"]));
00266                         return;
00267                 }
00268 
00269                 //$this->setTabs();
00270 
00271                 //add template for view button
00272                 $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
00273 
00274                 // create export file button
00275                 $this->tpl->setCurrentBlock("btn_cell");
00276                 $this->tpl->setVariable("BTN_LINK", "test.php?ref_id=".$_GET["ref_id"]."&cmd=createExportFile&mode=xml");
00277                 $this->tpl->setVariable("BTN_TXT", $this->lng->txt("ass_create_export_file"));
00278                 $this->tpl->parseCurrentBlock();
00279                 
00280                 // create export file button
00281                 if ($this->object->isOnlineTest()) {
00282                         $this->tpl->setCurrentBlock("btn_cell");
00283                         $this->tpl->setVariable("BTN_LINK", "test.php?ref_id=".$_GET["ref_id"]."&cmd=createExportFile&mode=results");
00284                         $this->tpl->setVariable("BTN_TXT", $this->lng->txt("ass_create_export_test_results"));
00285                         $this->tpl->parseCurrentBlock();
00286                 }
00287                 
00288 
00289                 // view last export log button
00290                 /*
00291                 if (is_file($this->object->getExportDirectory()."/export.log"))
00292                 {
00293                         $this->tpl->setCurrentBlock("btn_cell");
00294                         $this->tpl->setVariable("BTN_LINK", $this->ctrl->getLinkTarget($this, "viewExportLog"));
00295                         $this->tpl->setVariable("BTN_TXT", $this->lng->txt("cont_view_last_export_log"));
00296                         $this->tpl->parseCurrentBlock();
00297                 }*/
00298 
00299                 $export_dir = $this->object->getExportDirectory();
00300 
00301                 $export_files = $this->object->getExportFiles($export_dir);
00302 
00303                 // create table
00304                 include_once("classes/class.ilTableGUI.php");
00305                 $tbl = new ilTableGUI();
00306 
00307                 // load files templates
00308                 $this->tpl->addBlockfile("ADM_CONTENT", "adm_content", "tpl.table.html");
00309 
00310                 // load template for table content data
00311                 $this->tpl->addBlockfile("TBL_CONTENT", "tbl_content", "tpl.export_file_row.html", true);
00312 
00313                 $num = 0;
00314 
00315                 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
00316 
00317                 $tbl->setTitle($this->lng->txt("ass_export_files"));
00318 
00319                 $tbl->setHeaderNames(array("<input type=\"checkbox\" name=\"chb_check_all\" value=\"1\" onclick=\"setCheckboxes('ObjectItems', 'file', document.ObjectItems.chb_check_all.checked);\" />", $this->lng->txt("ass_file"),
00320                         $this->lng->txt("ass_size"), $this->lng->txt("date") ));
00321 
00322                 $tbl->enabled["sort"] = false;
00323                 $tbl->setColumnWidth(array("1%", "49%", "25%", "25%"));
00324 
00325                 // control
00326                 $tbl->setOrderColumn($_GET["sort_by"]);
00327                 $tbl->setOrderDirection($_GET["sort_order"]);
00328                 $tbl->setLimit($_GET["limit"]);
00329                 $tbl->setOffset($_GET["offset"]);
00330                 $tbl->setMaxCount($this->maxcount);             // ???
00331 
00332 
00333                 $this->tpl->setVariable("COLUMN_COUNTS", 4);
00334 
00335                 // delete button
00336                 $this->tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.gif"));
00337                 $this->tpl->setCurrentBlock("tbl_action_btn");
00338                 $this->tpl->setVariable("BTN_NAME", "confirmDeleteExportFile");
00339                 $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("delete"));
00340                 $this->tpl->parseCurrentBlock();
00341 
00342                 $this->tpl->setCurrentBlock("tbl_action_btn");
00343                 $this->tpl->setVariable("BTN_NAME", "downloadExportFile");
00344                 $this->tpl->setVariable("BTN_VALUE", $this->lng->txt("download"));
00345                 $this->tpl->parseCurrentBlock();
00346 
00347                 // footer
00348                 $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
00349                 //$tbl->disable("footer");
00350 
00351                 $tbl->setMaxCount(count($export_files));
00352                 $export_files = array_slice($export_files, $_GET["offset"], $_GET["limit"]);
00353 
00354                 $tbl->render();
00355                 if(count($export_files) > 0)
00356                 {
00357                         $i=0;
00358                         foreach($export_files as $exp_file)
00359                         {
00360                                 $this->tpl->setCurrentBlock("tbl_content");
00361                                 $this->tpl->setVariable("TXT_FILENAME", $exp_file);
00362 
00363                                 $css_row = ilUtil::switchColor($i++, "tblrow1", "tblrow2");
00364                                 $this->tpl->setVariable("CSS_ROW", $css_row);
00365 
00366                                 $this->tpl->setVariable("TXT_SIZE", filesize($export_dir."/".$exp_file));
00367                                 $this->tpl->setVariable("CHECKBOX_ID", $exp_file);
00368 
00369                                 $file_arr = explode("__", $exp_file);
00370                                 $this->tpl->setVariable("TXT_DATE", date("Y-m-d H:i:s",$file_arr[0]));
00371 
00372                                 $this->tpl->parseCurrentBlock();
00373                         }
00374                 } //if is_array
00375                 else
00376                 {
00377                         $this->tpl->setCurrentBlock("notfound");
00378                         $this->tpl->setVariable("TXT_OBJECT_NOT_FOUND", $this->lng->txt("obj_not_found"));
00379                         $this->tpl->setVariable("NUM_COLS", 3);
00380                         $this->tpl->parseCurrentBlock();
00381                 }
00382 
00383                 $this->tpl->parseCurrentBlock();
00384         }
00385 
00386         
00390         function createExportFileObject()
00391         {
00392                 global $rbacsystem;
00393                 
00394                 if ($rbacsystem->checkAccess("write", $this->ref_id))
00395                 {
00396                         include_once("assessment/classes/class.ilTestExport.php");
00397                         $test_exp = new ilTestExport($this->object, $_GET["mode"]);
00398                         $test_exp->buildExportFile();
00399                 }
00400                 else
00401                 {
00402                         sendInfo("cannot_export_test");
00403                 }
00404                 $this->exportObject();
00405         }
00406         
00407         
00411         function downloadExportFileObject()
00412         {
00413                 if(!isset($_POST["file"]))
00414                 {
00415                         $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
00416                 }
00417 
00418                 if (count($_POST["file"]) > 1)
00419                 {
00420                         $this->ilias->raiseError($this->lng->txt("select_max_one_item"),$this->ilias->error_obj->MESSAGE);
00421                 }
00422 
00423 
00424                 $export_dir = $this->object->getExportDirectory();
00425                 ilUtil::deliverFile($export_dir."/".$_POST["file"][0],
00426                         $_POST["file"][0]);
00427         }
00428 
00432         function confirmDeleteExportFileObject()
00433         {
00434                 if(!isset($_POST["file"]))
00435                 {
00436                         $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
00437                 }
00438 
00439                 //$this->setTabs();
00440 
00441                 // SAVE POST VALUES
00442                 $_SESSION["ilExportFiles"] = $_POST["file"];
00443 
00444                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.confirm_deletion.html", true);
00445 
00446                 sendInfo($this->lng->txt("info_delete_sure"));
00447 
00448                 $this->tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
00449 
00450                 // BEGIN TABLE HEADER
00451                 $this->tpl->setCurrentBlock("table_header");
00452                 $this->tpl->setVariable("TEXT",$this->lng->txt("objects"));
00453                 $this->tpl->parseCurrentBlock();
00454 
00455                 // BEGIN TABLE DATA
00456                 $counter = 0;
00457                 foreach($_POST["file"] as $file)
00458                 {
00459                                 $this->tpl->setCurrentBlock("table_row");
00460                                 $this->tpl->setVariable("CSS_ROW",ilUtil::switchColor(++$counter,"tblrow1","tblrow2"));
00461                                 $this->tpl->setVariable("TEXT_CONTENT", $file);
00462                                 $this->tpl->parseCurrentBlock();
00463                 }
00464 
00465                 // cancel/confirm button
00466                 $this->tpl->setVariable("IMG_ARROW",ilUtil::getImagePath("arrow_downright.gif"));
00467                 $buttons = array( "cancelDeleteExportFile"  => $this->lng->txt("cancel"),
00468                         "deleteExportFile"  => $this->lng->txt("confirm"));
00469                 foreach ($buttons as $name => $value)
00470                 {
00471                         $this->tpl->setCurrentBlock("operation_btn");
00472                         $this->tpl->setVariable("BTN_NAME",$name);
00473                         $this->tpl->setVariable("BTN_VALUE",$value);
00474                         $this->tpl->parseCurrentBlock();
00475                 }
00476         }
00477 
00478 
00482         function cancelDeleteExportFileObject()
00483         {
00484                 session_unregister("ilExportFiles");
00485                 ilUtil::redirect("test.php?cmd=export&ref_id=".$_GET["ref_id"]);
00486         }
00487 
00488 
00492         function deleteExportFileObject()
00493         {
00494                 $export_dir = $this->object->getExportDirectory();
00495                 foreach($_SESSION["ilExportFiles"] as $file)
00496                 {
00497                         $exp_file = $export_dir."/".$file;
00498                         $exp_dir = $export_dir."/".substr($file, 0, strlen($file) - 4);
00499                         if (@is_file($exp_file))
00500                         {
00501                                 unlink($exp_file);
00502                         }
00503                         if (@is_dir($exp_dir))
00504                         {
00505                                 ilUtil::delDir($exp_dir);
00506                         }
00507                 }
00508                 ilUtil::redirect("test.php?cmd=export&ref_id=".$_GET["ref_id"]);
00509         }
00510 
00516         function importObject()
00517         {
00518                 $this->getTemplateFile("import", "tst");
00519                 $this->tpl->setCurrentBlock("option_qpl");
00520                 include_once("./assessment/classes/class.ilObjTest.php");
00521                 $tst = new ilObjTest();
00522                 $questionpools =& $tst->getAvailableQuestionpools(true);
00523                 if (count($questionpools) == 0)
00524                 {
00525                 }
00526                 else
00527                 {
00528                         foreach ($questionpools as $key => $value)
00529                         {
00530                                 $this->tpl->setCurrentBlock("option_qpl");
00531                                 $this->tpl->setVariable("OPTION_VALUE", $key);
00532                                 $this->tpl->setVariable("TXT_OPTION", $value);
00533                                 $this->tpl->parseCurrentBlock();
00534                         }
00535                 }
00536                 $this->tpl->setVariable("TXT_SELECT_QUESTIONPOOL", $this->lng->txt("select_questionpool"));
00537                 $this->tpl->setVariable("OPTION_SELECT_QUESTIONPOOL", $this->lng->txt("select_questionpool_option"));
00538                 $this->tpl->setVariable("FORMACTION", "adm_object.php?&ref_id=".$_GET["ref_id"]."&cmd=gateway&new_type=".$this->type);
00539                 $this->tpl->setVariable("BTN_NAME", "uploadTst");
00540                 $this->tpl->setVariable("TXT_UPLOAD", $this->lng->txt("upload"));
00541                 $this->tpl->setVariable("NEW_TYPE", $this->type);
00542                 $this->tpl->setVariable("TXT_IMPORT_TST", $this->lng->txt("import_tst"));
00543                 $this->tpl->setVariable("TXT_SELECT_MODE", $this->lng->txt("select_mode"));
00544                 $this->tpl->setVariable("TXT_SELECT_FILE", $this->lng->txt("select_file"));
00545 
00546         }
00547 
00551         function uploadTstObject()
00552         {
00553                 if ($_POST["qpl"] < 1)
00554                 {
00555                         sendInfo($this->lng->txt("tst_select_questionpools"));
00556                         $this->importObject();
00557                         return;
00558                 }
00559 
00560                 if ($_FILES["xmldoc"]["error"] > UPLOAD_ERR_OK)
00561                 {
00562                         sendInfo($this->lng->txt("error_upload"));
00563                         $this->importObject();
00564                         return;
00565                 }
00566                 include_once("./assessment/classes/class.ilObjTest.php");
00567                 // create import directory
00568                 ilObjTest::_createImportDirectory();
00569 
00570                 // copy uploaded file to import directory
00571                 $file = pathinfo($_FILES["xmldoc"]["name"]);
00572                 $full_path = ilObjTest::_getImportDirectory()."/".$_FILES["xmldoc"]["name"];
00573                 ilUtil::moveUploadedFile($_FILES["xmldoc"]["tmp_name"], $_FILES["xmldoc"]["name"], $full_path);
00574 
00575                 // unzip file
00576                 ilUtil::unzip($full_path);
00577 
00578                 // determine filenames of xml files
00579                 $subdir = basename($file["basename"],".".$file["extension"]);
00580                 $xml_file = ilObjTest::_getImportDirectory()."/".$subdir."/".$subdir.".xml";
00581                 $qti_file = ilObjTest::_getImportDirectory()."/".$subdir."/". str_replace("test", "qti", $subdir).".xml";
00582                 // start verification of QTI files
00583                 include_once "./assessment/classes/class.ilQTIParser.php";
00584                 $qtiParser = new ilQTIParser($qti_file, IL_MO_VERIFY_QTI, 0, "");
00585                 $result = $qtiParser->startParsing();
00586                 $founditems =& $qtiParser->getFoundItems();
00587                 
00588                 if (count($founditems) == 0)
00589                 {
00590                         // nothing found
00591 
00592                         // delete import directory
00593                         ilUtil::delDir(ilObjTest::_getImportDirectory());
00594 
00595                         sendInfo($this->lng->txt("tst_import_no_items"));
00596                         $this->importObject();
00597                         return;
00598                 }
00599                 
00600                 $complete = 0;
00601                 $incomplete = 0;
00602                 foreach ($founditems as $item)
00603                 {
00604                         if (strlen($item["type"]))
00605                         {
00606                                 $complete++;
00607                         }
00608                         else
00609                         {
00610                                 $incomplete++;
00611                         }
00612                 }
00613                 
00614                 if ($complete == 0)
00615                 {
00616                         // delete import directory
00617                         ilUtil::delDir(ilObjTest::_getImportDirectory());
00618 
00619                         sendInfo($this->lng->txt("qpl_import_non_ilias_files"));
00620                         $this->importObject();
00621                         return;
00622                 }
00623                 
00624                 $_SESSION["tst_import_xml_file"] = $xml_file;
00625                 $_SESSION["tst_import_qti_file"] = $qti_file;
00626                 $_SESSION["tst_import_subdir"] = $subdir;
00627                 // display of found questions
00628                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.tst_import_verification.html");
00629                 $row_class = array("tblrow1", "tblrow2");
00630                 $counter = 0;
00631                 foreach ($founditems as $item)
00632                 {
00633                         $this->tpl->setCurrentBlock("verification_row");
00634                         $this->tpl->setVariable("ROW_CLASS", $row_class[$counter++ % 2]);
00635                         $this->tpl->setVariable("QUESTION_TITLE", $item["title"]);
00636                         $this->tpl->setVariable("QUESTION_IDENT", $item["ident"]);
00637                         switch ($item["type"])
00638                         {
00639                                 case "MULTIPLE CHOICE QUESTION":
00640                                         $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("qt_multiple_choice"));
00641                                         break;
00642                                 case "CLOZE QUESTION":
00643                                         $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("qt_cloze"));
00644                                         break;
00645                                 case "IMAGE MAP QUESTION":
00646                                         $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("qt_imagemap"));
00647                                         break;
00648                                 case "JAVA APPLET QUESTION":
00649                                         $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("qt_javaapplet"));
00650                                         break;
00651                                 case "MATCHING QUESTION":
00652                                         $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("qt_matching"));
00653                                         break;
00654                                 case "ORDERING QUESTION":
00655                                         $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("qt_ordering"));
00656                                         break;
00657                                 case "TEXT QUESTION":
00658                                         $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("qt_text"));
00659                                         break;
00660                         }
00661                         $this->tpl->parseCurrentBlock();
00662                 }
00663                 $this->tpl->setCurrentBlock("adm_content");
00664                 $this->tpl->setVariable("TEXT_TYPE", $this->lng->txt("question_type"));
00665                 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("question_title"));
00666                 $this->tpl->setVariable("FOUND_QUESTIONS_INTRODUCTION", $this->lng->txt("tst_import_verify_found_questions"));
00667                 $this->tpl->setVariable("VERIFICATION_HEADING", $this->lng->txt("import_tst"));
00668                 $this->tpl->setVariable("FORMACTION", $this->getFormAction("save","adm_object.php?cmd=gateway&ref_id=".$_GET["ref_id"]."&new_type=".$this->type));
00669                 $this->tpl->setVariable("ARROW", ilUtil::getImagePath("arrow_downright.gif"));
00670                 $this->tpl->setVariable("QUESTIONPOOL_ID", $_POST["qpl"]);
00671                 $this->tpl->setVariable("VALUE_IMPORT", $this->lng->txt("import"));
00672                 $this->tpl->setVariable("VALUE_CANCEL", $this->lng->txt("cancel"));
00673                 $this->tpl->parseCurrentBlock();
00674         }
00675         
00679         function importVerifiedFileObject()
00680         {
00681                 include_once "./assessment/classes/class.ilObjTest.php";
00682                 // create new questionpool object
00683                 $newObj = new ilObjTest(true);
00684                 // set type of questionpool object
00685                 $newObj->setType($_GET["new_type"]);
00686                 // set title of questionpool object to "dummy"
00687                 $newObj->setTitle("dummy");
00688                 // set description of questionpool object
00689                 $newObj->setDescription("test import");
00690                 // create the questionpool class in the ILIAS database (object_data table)
00691                 $newObj->create(true);
00692                 // create a reference for the questionpool object in the ILIAS database (object_reference table)
00693                 $newObj->createReference();
00694                 // put the questionpool object in the administration tree
00695                 $newObj->putInTree($_GET["ref_id"]);
00696                 // get default permissions and set the permissions for the questionpool object
00697                 $newObj->setPermissions($_GET["ref_id"]);
00698                 // notify the questionpool object and all its parent objects that a "new" object was created
00699                 $newObj->notify("new",$_GET["ref_id"],$_GET["parent_non_rbac_id"],$_GET["ref_id"],$newObj->getRefId());
00700                 // empty mark schema
00701                 $newObj->mark_schema->flush();
00702 
00703                 // start parsing of QTI files
00704                 include_once "./assessment/classes/class.ilQTIParser.php";
00705                 $qtiParser = new ilQTIParser($_SESSION["tst_import_qti_file"], IL_MO_PARSE_QTI, $_POST["qpl_id"], $_POST["ident"]);
00706                 $qtiParser->setTestObject($newObj);
00707                 $result = $qtiParser->startParsing();
00708                 $newObj->saveToDb();
00709                 
00710                 // import page data
00711                 include_once ("content/classes/class.ilContObjParser.php");
00712                 $contParser = new ilContObjParser($newObj, $_SESSION["tst_import_xml_file"], $_SESSION["tst_import_subdir"]);
00713                 $contParser->setQuestionMapping($qtiParser->getImportMapping());
00714                 $contParser->startParsing();
00715 
00716                 // delete import directory
00717                 ilUtil::delDir(ilObjTest::_getImportDirectory());
00718                 
00719                 ilUtil::redirect($this->getReturnLocation("save", "adm_object.php?ref_id=" . $_GET["ref_id"]));
00720         }
00721         
00722         function cancelImportObject()
00723         {
00724                 ilUtil::redirect($this->getReturnLocation("cancel", "adm_object.php?ref_id=" . $_GET["ref_id"]));
00725         }
00726         
00727         
00734         function uploadObject($redirect = true)
00735         {
00736                 $this->uploadTstObject();
00737         }
00738 
00746         function savePropertiesObject()
00747         {
00748                 $total = $this->object->evalTotalPersons();
00749                 $deleteuserdata = false;
00750                 $randomtest_switch = false;
00751                 // Check the values the user entered in the form
00752                 if (!$total)
00753                 {
00754                         $data["count_system"] = $_POST["count_system"];
00755                         $data["mc_scoring"] = $_POST["mc_scoring"];
00756                         $data["sel_test_types"] = ilUtil::stripSlashes($_POST["sel_test_types"]);
00757                         if (!strlen($_POST["chb_random"]))
00758                         {
00759                                 $data["random_test"] = 0;
00760                         }
00761                         else
00762                         {
00763                                 $data["random_test"] = ilUtil::stripSlashes($_POST["chb_random"]);
00764                         }
00765                 }
00766                 else
00767                 {
00768                         $data["sel_test_types"] = $this->object->getTestType();
00769                         $data["random_test"] = $this->object->random_test;
00770                         $data["count_system"] = $this->object->getCountSystem();
00771                         $data["mc_scoring"] = $this->object->getMCScoring();
00772                 }
00773                 if ($data["sel_test_types"] != $this->object->getTestType())
00774                 {
00775                         $deleteuserdata = true;
00776                 }
00777                 if ($data["random_test"] != $this->object->random_test)
00778                 {
00779                         $randomtest_switch = true;
00780                 }
00781                 $data["title"] = ilUtil::stripSlashes($_POST["title"]);
00782                 $data["description"] = ilUtil::stripSlashes($_POST["description"]);
00783                 $data["author"] = ilUtil::stripSlashes($_POST["author"]);
00784                 $data["introduction"] = ilUtil::stripSlashes($_POST["introduction"]);
00785                 $data["sequence_settings"] = ilUtil::stripSlashes($_POST["sequence_settings"]);
00786                 if ($this->object->getTestType() == TYPE_ASSESSMENT || $this->object->getTestType() == TYPE_ONLINE_TEST)
00787                 {
00788                         $data["score_reporting"] = REPORT_AFTER_TEST;
00789                 }
00790                 else
00791                 {
00792                         $data["score_reporting"] = ilUtil::stripSlashes($_POST["score_reporting"]);
00793                 }
00794                 $data["nr_of_tries"] = ilUtil::stripSlashes($_POST["nr_of_tries"]);
00795                 $data["processing_time"] = ilUtil::stripSlashes($_POST["processing_time"]);
00796                 if (!$_POST["chb_starting_time"])
00797                 {
00798                         $data["starting_time"] = "";
00799                 }
00800                 else
00801                 {
00802                         $data["starting_time"] = sprintf("%04d%02d%02d%02d%02d%02d",
00803                                 $_POST["starting_date"]["y"],
00804                                 $_POST["starting_date"]["m"],
00805                                 $_POST["starting_date"]["d"],
00806                                 $_POST["starting_time"]["h"],
00807                                 $_POST["starting_time"]["m"],
00808                                 0
00809                         );
00810                 }
00811                 if (!$_POST["chb_ending_time"])
00812                 {
00813                         $data["ending_time"] = "";
00814                 }
00815                 else
00816                 {
00817                         $data["ending_time"] = sprintf("%04d%02d%02d%02d%02d%02d",
00818                                 $_POST["ending_date"]["y"],
00819                                 $_POST["ending_date"]["m"],
00820                                 $_POST["ending_date"]["d"],
00821                                 $_POST["ending_time"]["h"],
00822                                 $_POST["ending_time"]["m"],
00823                                 0
00824                         );
00825                 }
00826 
00827                 if ($_POST["chb_processing_time"])
00828                 {
00829                         $data["enable_processing_time"] = "1";
00830                 }
00831                 else
00832                 {
00833                         $data["enable_processing_time"] = "0";
00834                 }
00835 
00836                 if ($data["enable_processing_time"])
00837                 {
00838                         $data["processing_time"] = sprintf("%02d:%02d:%02d",
00839                                 $_POST["processing_time"]["h"],
00840                                 $_POST["processing_time"]["m"],
00841                                 $_POST["processing_time"]["s"]
00842                         );
00843                 }
00844                 else
00845                 {
00846                         $proc_time = $this->object->getEstimatedWorkingTime();
00847                         $data["processing_time"] = sprintf("%02d:%02d:%02d",
00848                                 $proc_time["h"],
00849                                 $proc_time["m"],
00850                                 $proc_time["s"]
00851                         );
00852                 }
00853 
00854                 if (!$_POST["chb_reporting_date"] && !$this->object->isOnlineTest())
00855                 {
00856                         $data["reporting_date"] = "";
00857                 }
00858                 else
00859                 {
00860                         $data["reporting_date"] = sprintf("%04d%02d%02d%02d%02d%02d",
00861                                 $_POST["reporting_date"]["y"],
00862                                 $_POST["reporting_date"]["m"],
00863                                 $_POST["reporting_date"]["d"],
00864                                 $_POST["reporting_time"]["h"],
00865                                 $_POST["reporting_time"]["m"],
00866                                 0
00867                         );
00868                 }
00869                 $this->object->setTestType($data["sel_test_types"]);
00870                 $this->object->setTitle($data["title"]);
00871                 $this->object->setDescription($data["description"]);
00872                 $this->object->setAuthor($data["author"]);
00873                 $this->object->setIntroduction($data["introduction"]);
00874                 $this->object->setSequenceSettings($data["sequence_settings"]);
00875                 $this->object->setCountSystem($data["count_system"]);
00876                 $this->object->setMCScoring($data["mc_scoring"]);
00877                 if ($this->object->getTestType() == TYPE_ASSESSMENT || $this->object->getTestType() == TYPE_ONLINE_TEST )
00878                 {
00879                         $this->object->setScoreReporting(REPORT_AFTER_TEST);
00880                 }
00881                 else
00882                 {
00883                         $this->object->setScoreReporting($data["score_reporting"]);
00884                 }
00885                 
00886                 $this->object->setReportingDate($data["reporting_date"]);
00887                 $this->object->setNrOfTries($data["nr_of_tries"]);
00888                 $this->object->setStartingTime($data["starting_time"]);
00889                 $this->object->setEndingTime($data["ending_time"]);
00890                 $this->object->setProcessingTime($data["processing_time"]);
00891                 $this->object->setRandomTest($data["random_test"]);
00892                 $this->object->setEnableProcessingTime($data["enable_processing_time"]);
00893                 
00894                 if ($this->object->getTestType() == TYPE_ONLINE_TEST) 
00895                 {
00896                         $this->object->setScoreReporting(1);
00897                 $this->object->setSequenceSettings(0);
00898                 $this->object->setNrOfTries(1);
00899                 $this->object->setRandomTest(0);
00900                 }
00901 
00902 //              $this->object->updateTitleAndDescription();
00903                 $this->update = $this->object->update();
00904                 $this->object->saveToDb(true);
00905 
00906                 if ($deleteuserdata)
00907                 {
00908                         $this->object->removeAllTestEditings();
00909                 }
00910                 sendInfo($this->lng->txt("msg_obj_modified"));
00911                 if ($randomtest_switch)
00912                 {
00913                         if ($this->object->isRandomTest())
00914                         {
00915                                 $this->object->removeNonRandomTestData();
00916                         }
00917                         else
00918                         {
00919                                 $this->object->removeRandomTestData();
00920                         }
00921                 }
00922                 $this->ctrl->redirect($this, "properties");
00923         }
00924         
00932         function cancelPropertiesObject()
00933         {
00934                 sendInfo($this->lng->txt("msg_cancel"), true);
00935                 $path = $this->tree->getPathFull($this->object->getRefID());
00936                 ilUtil::redirect($this->getReturnLocation("cancel","../repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
00937         }
00938         
00946         function propertiesObject()
00947         {
00948                 global $rbacsystem;
00949                 $total = $this->object->evalTotalPersons();
00950                 if ($this->object->getTestType() == TYPE_ONLINE_TEST  || $data["sel_test_types"] == TYPE_ONLINE_TEST)
00951                 {
00952                 // fixed settings
00953                 $this->object->setScoreReporting(1);
00954                 $this->object->setSequenceSettings(0);
00955                 $this->object->setNrOfTries(1);
00956                 $this->object->setRandomTest(0);
00957         }
00958                 
00959                 if (($data["sel_test_types"] == TYPE_ONLINE_TEST) || ($data["sel_test_types"] == TYPE_ASSESSMENT) || (($this->object->getTestType() == TYPE_ASSESSMENT || $this->object->getTestType() == TYPE_ONLINE_TEST) && strlen($data["sel_test_types"]) == 0)) 
00960                 {
00961                         $this->lng->loadLanguageModule("jscalendar");
00962                         $this->tpl->addBlockFile("CALENDAR_LANG_JAVASCRIPT", "calendar_javascript", "tpl.calendar.html");
00963                         $this->tpl->setCurrentBlock("calendar_javascript");
00964                         $this->tpl->setVariable("FULL_SUNDAY", $this->lng->txt("l_su"));
00965                         $this->tpl->setVariable("FULL_MONDAY", $this->lng->txt("l_mo"));
00966                         $this->tpl->setVariable("FULL_TUESDAY", $this->lng->txt("l_tu"));
00967                         $this->tpl->setVariable("FULL_WEDNESDAY", $this->lng->txt("l_we"));
00968                         $this->tpl->setVariable("FULL_THURSDAY", $this->lng->txt("l_th"));
00969                         $this->tpl->setVariable("FULL_FRIDAY", $this->lng->txt("l_fr"));
00970                         $this->tpl->setVariable("FULL_SATURDAY", $this->lng->txt("l_sa"));
00971                         $this->tpl->setVariable("SHORT_SUNDAY", $this->lng->txt("s_su"));
00972                         $this->tpl->setVariable("SHORT_MONDAY", $this->lng->txt("s_mo"));
00973                         $this->tpl->setVariable("SHORT_TUESDAY", $this->lng->txt("s_tu"));
00974                         $this->tpl->setVariable("SHORT_WEDNESDAY", $this->lng->txt("s_we"));
00975                         $this->tpl->setVariable("SHORT_THURSDAY", $this->lng->txt("s_th"));
00976                         $this->tpl->setVariable("SHORT_FRIDAY", $this->lng->txt("s_fr"));
00977                         $this->tpl->setVariable("SHORT_SATURDAY", $this->lng->txt("s_sa"));
00978                         $this->tpl->setVariable("FULL_JANUARY", $this->lng->txt("l_01"));
00979                         $this->tpl->setVariable("FULL_FEBRUARY", $this->lng->txt("l_02"));
00980                         $this->tpl->setVariable("FULL_MARCH", $this->lng->txt("l_03"));
00981                         $this->tpl->setVariable("FULL_APRIL", $this->lng->txt("l_04"));
00982                         $this->tpl->setVariable("FULL_MAY", $this->lng->txt("l_05"));
00983                         $this->tpl->setVariable("FULL_JUNE", $this->lng->txt("l_06"));
00984                         $this->tpl->setVariable("FULL_JULY", $this->lng->txt("l_07"));
00985                         $this->tpl->setVariable("FULL_AUGUST", $this->lng->txt("l_08"));
00986                         $this->tpl->setVariable("FULL_SEPTEMBER", $this->lng->txt("l_09"));
00987                         $this->tpl->setVariable("FULL_OCTOBER", $this->lng->txt("l_10"));
00988                         $this->tpl->setVariable("FULL_NOVEMBER", $this->lng->txt("l_11"));
00989                         $this->tpl->setVariable("FULL_DECEMBER", $this->lng->txt("l_12"));
00990                         $this->tpl->setVariable("SHORT_JANUARY", $this->lng->txt("s_01"));
00991                         $this->tpl->setVariable("SHORT_FEBRUARY", $this->lng->txt("s_02"));
00992                         $this->tpl->setVariable("SHORT_MARCH", $this->lng->txt("s_03"));
00993                         $this->tpl->setVariable("SHORT_APRIL", $this->lng->txt("s_04"));
00994                         $this->tpl->setVariable("SHORT_MAY", $this->lng->txt("s_05"));
00995                         $this->tpl->setVariable("SHORT_JUNE", $this->lng->txt("s_06"));
00996                         $this->tpl->setVariable("SHORT_JULY", $this->lng->txt("s_07"));
00997                         $this->tpl->setVariable("SHORT_AUGUST", $this->lng->txt("s_08"));
00998                         $this->tpl->setVariable("SHORT_SEPTEMBER", $this->lng->txt("s_09"));
00999                         $this->tpl->setVariable("SHORT_OCTOBER", $this->lng->txt("s_10"));
01000                         $this->tpl->setVariable("SHORT_NOVEMBER", $this->lng->txt("s_11"));
01001                         $this->tpl->setVariable("SHORT_DECEMBER", $this->lng->txt("s_12"));
01002                         $this->tpl->setVariable("ABOUT_CALENDAR", $this->lng->txt("about_calendar"));
01003                         $this->tpl->setVariable("ABOUT_CALENDAR_LONG", $this->lng->txt("about_calendar_long"));
01004                         $this->tpl->setVariable("ABOUT_TIME_LONG", $this->lng->txt("about_time"));
01005                         $this->tpl->setVariable("PREV_YEAR", $this->lng->txt("prev_year"));
01006                         $this->tpl->setVariable("PREV_MONTH", $this->lng->txt("prev_month"));
01007                         $this->tpl->setVariable("GO_TODAY", $this->lng->txt("go_today"));
01008                         $this->tpl->setVariable("NEXT_MONTH", $this->lng->txt("next_month"));
01009                         $this->tpl->setVariable("NEXT_YEAR", $this->lng->txt("next_year"));
01010                         $this->tpl->setVariable("SEL_DATE", $this->lng->txt("select_date"));
01011                         $this->tpl->setVariable("DRAG_TO_MOVE", $this->lng->txt("drag_to_move"));
01012                         $this->tpl->setVariable("PART_TODAY", $this->lng->txt("part_today"));
01013                         $this->tpl->setVariable("DAY_FIRST", $this->lng->txt("day_first"));
01014                         $this->tpl->setVariable("CLOSE", $this->lng->txt("close"));
01015                         $this->tpl->setVariable("TODAY", $this->lng->txt("today"));
01016                         $this->tpl->setVariable("TIME_PART", $this->lng->txt("time_part"));
01017                         $this->tpl->setVariable("DEF_DATE_FORMAT", $this->lng->txt("def_date_format"));
01018                         $this->tpl->setVariable("TT_DATE_FORMAT", $this->lng->txt("tt_date_format"));
01019                         $this->tpl->setVariable("WK", $this->lng->txt("wk"));
01020                         $this->tpl->setVariable("TIME", $this->lng->txt("time"));
01021                         $this->tpl->parseCurrentBlock();
01022                         $this->tpl->setCurrentBlock("CalendarJS");
01023                         $this->tpl->setVariable("LOCATION_JAVASCRIPT_CALENDAR", ilUtil::getJSPath("calendar.js"));
01024                         $this->tpl->setVariable("LOCATION_JAVASCRIPT_CALENDAR_SETUP", ilUtil::getJSPath("calendar-setup.js"));
01025                         $this->tpl->setVariable("LOCATION_JAVASCRIPT_CALENDAR_STYLESHEET", ilUtil::getJSPath("calendar.css"));
01026                         $this->tpl->parseCurrentBlock();
01027                         $this->tpl->setCurrentBlock("javascript_call_calendar");
01028                         $this->tpl->setVariable("INPUT_FIELDS_STARTING_DATE", "starting_date");
01029                         $this->tpl->setVariable("INPUT_FIELDS_ENDING_DATE", "ending_date");
01030                         $this->tpl->setVariable("INPUT_FIELDS_REPORTING_DATE", "reporting_date");
01031                         $this->tpl->parseCurrentBlock();
01032                 }
01033                 if ((!$rbacsystem->checkAccess("read", $this->ref_id)) && (!$rbacsystem->checkAccess("write", $this->ref_id))) 
01034                 {
01035                         // allow only read and write access
01036                         sendInfo($this->lng->txt("cannot_edit_test"), true);
01037                         $path = $this->tree->getPathFull($this->object->getRefID());
01038                         ilUtil::redirect($this->getReturnLocation("cancel","../repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
01039                         return;
01040                 }
01041                 
01042                 $data["sel_test_types"] = $this->object->getTestType();
01043                 $data["author"] = $this->object->getAuthor();
01044                 $data["introduction"] = $this->object->getIntroduction();
01045                 $data["sequence_settings"] = $this->object->getSequenceSettings();
01046                 $data["score_reporting"] = $this->object->getScoreReporting();
01047                 $data["reporting_date"] = $this->object->getReportingDate();
01048                 $data["nr_of_tries"] = $this->object->getNrOfTries();
01049 
01050                 $data["enable_processing_time"] = $this->object->getEnableProcessingTime();
01051                 $data["processing_time"] = $this->object->getProcessingTime();
01052                 $data["random_test"] = $this->object->isRandomTest();
01053                 $data["count_system"] = $this->object->getCountSystem();
01054                 $data["mc_scoring"] = $this->object->getMCScoring();
01055                 if ((int)substr($data["processing_time"], 0, 2) + (int)substr($data["processing_time"], 3, 2) + (int)substr($data["processing_time"], 6, 2) == 0)
01056                 {
01057                         $proc_time = $this->object->getEstimatedWorkingTime();
01058                         $data["processing_time"] = sprintf("%02d:%02d:%02d",
01059                                 $proc_time["h"],
01060                                 $proc_time["m"],
01061                                 $proc_time["s"]
01062                         );
01063                 }
01064                 $data["starting_time"] = $this->object->getStartingTime();
01065                 $data["ending_time"] = $this->object->getEndingTime();
01066                 $data["title"] = $this->object->getTitle();
01067                 $data["description"] = $this->object->getDescription();
01068                 
01069                 if ($data["sel_test_types"] == TYPE_ASSESSMENT || ($data["sel_test_types"] == TYPE_ONLINE_TEST))
01070                 {
01071                         $this->tpl->setCurrentBlock("starting_time");
01072                         $this->tpl->setVariable("TEXT_STARTING_TIME", $this->lng->txt("tst_starting_time"));
01073                         if (!$data["starting_time"])
01074                         {
01075                                 $date_input = ilUtil::makeDateSelect("starting_date");
01076                                 $time_input = ilUtil::makeTimeSelect("starting_time");
01077                         }
01078                         else
01079                         {
01080                                 preg_match("/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/", $data["starting_time"], $matches);
01081                                 $date_input = ilUtil::makeDateSelect("starting_date", $matches[1], sprintf("%d", $matches[2]), sprintf("%d", $matches[3]));
01082                                 $time_input = ilUtil::makeTimeSelect("starting_time", true, sprintf("%d", $matches[4]), sprintf("%d", $matches[5]), sprintf("%d", $matches[6]));
01083                         }
01084                         $this->tpl->setVariable("IMG_STARTING_TIME_CALENDAR", ilUtil::getImagePath("calendar.png"));
01085                         $this->tpl->setVariable("TXT_STARTING_TIME_CALENDAR", $this->lng->txt("open_calendar"));
01086                         $this->tpl->setVariable("TXT_ENABLED", $this->lng->txt("enabled"));
01087                         if ($data["starting_time"])
01088                         {
01089                                 $this->tpl->setVariable("CHECKED_STARTING_TIME", " checked=\"checked\"");
01090                         }
01091                         $this->tpl->setVariable("INPUT_STARTING_TIME", $this->lng->txt("date") . ": " . $date_input . $this->lng->txt("time") . ": " . $time_input);
01092                         $this->tpl->parseCurrentBlock();
01093 
01094                         $this->tpl->setCurrentBlock("ending_time");
01095                         $this->tpl->setVariable("TEXT_ENDING_TIME", $this->lng->txt("tst_ending_time"));
01096                         if (!$data["ending_time"])
01097                         {
01098                                 $date_input = ilUtil::makeDateSelect("ending_date");
01099                                 $time_input = ilUtil::makeTimeSelect("ending_time");
01100                         }
01101                         else
01102                         {
01103                                 preg_match("/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/", $data["ending_time"], $matches);
01104                                 $date_input = ilUtil::makeDateSelect("ending_date", $matches[1], sprintf("%d", $matches[2]), sprintf("%d", $matches[3]));
01105                                 $time_input = ilUtil::makeTimeSelect("ending_time", true, sprintf("%d", $matches[4]), sprintf("%d", $matches[5]), sprintf("%d", $matches[6]));
01106                         }
01107                         $this->tpl->setVariable("IMG_ENDING_TIME_CALENDAR", ilUtil::getImagePath("calendar.png"));
01108                         $this->tpl->setVariable("TXT_ENDING_TIME_CALENDAR", $this->lng->txt("open_calendar"));
01109                         $this->tpl->setVariable("TXT_ENABLED", $this->lng->txt("enabled"));
01110                         if ($data["ending_time"])
01111                         {
01112                                 $this->tpl->setVariable("CHECKED_ENDING_TIME", " checked=\"checked\"");
01113                         }
01114                         $this->tpl->setVariable("INPUT_ENDING_TIME", $this->lng->txt("date") . ": " . $date_input . $this->lng->txt("time") . ": " . $time_input);
01115                         $this->tpl->parseCurrentBlock();
01116 
01117                         $this->tpl->setCurrentBlock("reporting_date");
01118                         $this->tpl->setVariable("TEXT_SCORE_DATE", $this->lng->txt("tst_score_reporting_date"));
01119                         if (!$data["reporting_date"])
01120                         {
01121                                 $date_input = ilUtil::makeDateSelect("reporting_date");
01122                                 $time_input = ilUtil::makeTimeSelect("reporting_time");
01123                         } else {
01124                                 preg_match("/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/", $data["reporting_date"], $matches);
01125                                 $date_input = ilUtil::makeDateSelect("reporting_date", $matches[1], sprintf("%d", $matches[2]), sprintf("%d", $matches[3]));
01126                                 $time_input = ilUtil::makeTimeSelect("reporting_time", true, sprintf("%d", $matches[4]), sprintf("%d", $matches[5]), sprintf("%d", $matches[6]));
01127                         }
01128                         $this->tpl->setVariable("IMG_REPORTING_DATE_CALENDAR", ilUtil::getImagePath("calendar.png"));
01129                         $this->tpl->setVariable("TXT_REPORTING_DATE_CALENDAR", $this->lng->txt("open_calendar"));
01130                         $this->tpl->setVariable("TXT_ENABLED", $this->lng->txt("enabled"));
01131                         if ($data["reporting_date"] || ($data["sel_test_types"] == TYPE_ONLINE_TEST)) {
01132                                 $this->tpl->setVariable("CHECKED_REPORTING_DATE", " checked=\"checked\"");
01133                         }
01134                         $this->tpl->setVariable("INPUT_REPORTING_DATE", $this->lng->txt("date") . ": " . $date_input . $this->lng->txt("time") . ": " . $time_input);
01135                         $this->tpl->parseCurrentBlock();
01136                 }
01137 
01138                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_properties.html", true);
01139                 $this->tpl->setCurrentBlock("test_types");
01140                 foreach ($this->object->test_types as $key => $value) {
01141                         $this->tpl->setVariable("VALUE_TEST_TYPE", $key);
01142                         $this->tpl->setVariable("TEXT_TEST_TYPE", $this->lng->txt($value));
01143                         if ($data["sel_test_types"] == $key) {
01144                                 $this->tpl->setVariable("SELECTED_TEST_TYPE", " selected=\"selected\"");
01145                         }
01146                         $this->tpl->parseCurrentBlock();
01147                 }
01148                 $this->tpl->setCurrentBlock("adm_content");
01149                 $this->tpl->setVariable("ACTION_PROPERTIES", $this->ctrl->getFormAction($this));
01150                 if ($rbacsystem->checkAccess("write", $this->ref_id)) {
01151                         $this->tpl->setVariable("SUBMIT_TYPE", $this->lng->txt("change"));
01152                 }
01153                 $this->tpl->setVariable("HEADING_GENERAL", $this->lng->txt("tst_general_properties"));
01154                 $this->tpl->setVariable("TEXT_TEST_TYPES", $this->lng->txt("tst_types"));
01155                 $this->tpl->setVariable("TEST_TYPE_COMMENT", $this->lng->txt("tst_type_comment"));
01156                 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
01157                 $this->tpl->setVariable("VALUE_TITLE", ilUtil::prepareFormOutput($data["title"]));
01158                 $this->tpl->setVariable("TEXT_AUTHOR", $this->lng->txt("author"));
01159                 $this->tpl->setVariable("VALUE_AUTHOR", ilUtil::prepareFormOutput($data["author"]));
01160                 $this->tpl->setVariable("TEXT_DESCRIPTION", $this->lng->txt("description"));
01161                 $this->tpl->setVariable("VALUE_DESCRIPTION", ilUtil::prepareFormOutput($data["description"]));
01162                 $this->tpl->setVariable("TEXT_INTRODUCTION", $this->lng->txt("tst_introduction"));
01163                 $this->tpl->setVariable("VALUE_INTRODUCTION", $data["introduction"]);
01164                 $this->tpl->setVariable("HEADING_SEQUENCE", $this->lng->txt("tst_sequence_properties"));
01165                 $this->tpl->setVariable("TEXT_SEQUENCE", $this->lng->txt("tst_sequence"));
01166                 $this->tpl->setVariable("SEQUENCE_FIXED", $this->lng->txt("tst_sequence_fixed"));
01167                 $this->tpl->setVariable("SEQUENCE_POSTPONE", $this->lng->txt("tst_sequence_postpone"));
01168                 if ($data["sequence_settings"] == 0) {
01169                         $this->tpl->setVariable("SELECTED_FIXED", " selected=\"selected\"");
01170                 } elseif ($data["sequence_settings"] == 1) {
01171                         $this->tpl->setVariable("SELECTED_POSTPONE", " selected=\"selected\"");
01172                 }
01173                 $this->tpl->setVariable("HEADING_SCORE", $this->lng->txt("tst_score_reporting"));
01174                 $this->tpl->setVariable("TEXT_SCORE_TYPE", $this->lng->txt("tst_score_type"));
01175                 $this->tpl->setVariable("REPORT_AFTER_QUESTION", $this->lng->txt("tst_report_after_question"));
01176                 $this->tpl->setVariable("REPORT_AFTER_TEST", $this->lng->txt("tst_report_after_test"));
01177                 if ($data["sel_test_types"] == TYPE_ASSESSMENT || ($data["sel_test_types"] == TYPE_ONLINE_TEST || $this->object->getTestType() == TYPE_ONLINE_TEST)) 
01178                 {
01179                         $this->tpl->setVariable("SELECTED_TEST", " selected=\"selected\"");
01180                         $this->tpl->setVariable("DISABLE_SCORE_REPORTING", " disabled=\"disabled\"");
01181                         if ($this->object->getTestType() == TYPE_ONLINE_TEST || $data["sel_test_types"] == TYPE_ONLINE_TEST) 
01182                         {
01183                                 $this->tpl->setVariable("DISABLE_SCORE_REPORTING_DATE_CHECKBOX", " disabled=\"disabled\"");
01184                                 $this->tpl->setVariable("DISABLE_SEQUENCE", " disabled=\"disabled\"");
01185                                 $this->tpl->setVariable("DISABLE_NR_OF_TRIES", " disabled=\"disabled\"");
01186                                 $this->tpl->setVariable("ENABLED_RANDOM_TEST", " disabled=\"disabled\"");
01187                         }
01188                 } 
01189                 else 
01190                 {
01191                         if ($data["score_reporting"] == 0) 
01192                         {
01193                                 $this->tpl->setVariable("SELECTED_QUESTION", " selected=\"selected\"");
01194                         } 
01195                         elseif ($data["score_reporting"] == 1) 
01196                         {
01197                                 $this->tpl->setVariable("SELECTED_TEST", " selected=\"selected\"");
01198                         }
01199                 }
01200                 $this->tpl->setVariable("HEADING_SESSION", $this->lng->txt("tst_session_settings"));
01201                 $this->tpl->setVariable("TEXT_NR_OF_TRIES", $this->lng->txt("tst_nr_of_tries"));
01202                 $this->tpl->setVariable("VALUE_NR_OF_TRIES", $data["nr_of_tries"]);
01203                 $this->tpl->setVariable("COMMENT_NR_OF_TRIES", $this->lng->txt("0_unlimited"));
01204                 $this->tpl->setVariable("TEXT_PROCESSING_TIME", $this->lng->txt("tst_processing_time"));
01205                 $time_input = ilUtil::makeTimeSelect("processing_time", false, substr($data["processing_time"], 0, 2), substr($data["processing_time"], 3, 2), substr($data["processing_time"], 6, 2));
01206                 $this->tpl->setVariable("MAX_PROCESSING_TIME", $time_input . " (hh:mm:ss)");
01207                 if ($data["enable_processing_time"]) {
01208                         $this->tpl->setVariable("CHECKED_PROCESSING_TIME", " checked=\"checked\"");
01209                 }
01210                 $this->tpl->setVariable("TEXT_RANDOM_TEST", $this->lng->txt("tst_random_test"));
01211                 $this->tpl->setVariable("TEXT_RANDOM_TEST_DESCRIPTION", $this->lng->txt("tst_random_test_description"));
01212                 if ($data["random_test"]) {
01213                         $this->tpl->setVariable("CHECKED_RANDOM_TEST", " checked=\"checked\"");
01214                 }
01215 
01216                 $this->tpl->setVariable("HEADING_SCORING", $this->lng->txt("tst_heading_scoring"));
01217                 $this->tpl->setVariable("TEXT_COUNT_SYSTEM", $this->lng->txt("tst_text_count_system"));
01218                 $this->tpl->setVariable("COUNT_PARTIAL_SOLUTIONS", $this->lng->txt("tst_count_partial_solutions"));
01219                 if ($data["count_system"] == COUNT_PARTIAL_SOLUTIONS)
01220                 {
01221                         $this->tpl->setVariable("SELECTED_PARTIAL", " selected=\"selected\"");
01222                 }
01223                 $this->tpl->setVariable("COUNT_CORRECT_SOLUTIONS", $this->lng->txt("tst_count_correct_solutions"));
01224                 if ($data["count_system"] == COUNT_CORRECT_SOLUTIONS)
01225                 {
01226                         $this->tpl->setVariable("SELECTED_CORRECT", " selected=\"selected\"");
01227                 }
01228                 $this->tpl->setVariable("TEXT_SCORE_MCMR", $this->lng->txt("tst_score_mcmr_questions"));
01229                 $this->tpl->setVariable("ZERO_POINTS_WHEN_UNANSWERED", $this->lng->txt("tst_score_mcmr_zero_points_when_unanswered"));
01230                 $this->tpl->setVariable("USE_SCORING_SYSTEM", $this->lng->txt("tst_score_mcmr_use_scoring_system"));
01231                 if ($data["mc_scoring"] == SCORE_ZERO_POINTS_WHEN_UNANSWERED)
01232                 {
01233                         $this->tpl->setVariable("SELECTED_ANTICHEAT", " selected=\"selected\"");
01234                 }
01235                 else
01236                 {
01237                         $this->tpl->setVariable("SELECTED_STANDARD", " selected=\"selected\"");
01238                 }
01239 
01240                 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
01241                 if ($rbacsystem->checkAccess("write", $this->ref_id)) {
01242                         $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
01243                         $this->tpl->setVariable("CANCEL", $this->lng->txt("cancel"));
01244                 }
01245                 if ($total > 0)
01246                 {
01247                         $this->tpl->setVariable("DISABLE_COUNT_SYSTEM", " disabled=\"disabled\"");
01248                         $this->tpl->setVariable("DISABLE_MC_SCORING", " disabled=\"disabled\"");
01249                         $this->tpl->setVariable("ENABLED_TEST_TYPES", " disabled=\"disabled\"");
01250                         $this->tpl->setVariable("ENABLED_RANDOM_TEST", " disabled=\"disabled\"");
01251                 }
01252                 $this->tpl->parseCurrentBlock();
01253         }
01254 
01258         function downloadFileObject()
01259         {
01260                 $file = explode("_", $_GET["file_id"]);
01261                 include_once("classes/class.ilObjFile.php");
01262                 $fileObj =& new ilObjFile($file[count($file) - 1], false);
01263                 $fileObj->sendFile();
01264                 exit;
01265         }
01266         
01270         function fullscreenObject()
01271         {
01272                 include_once("content/classes/Pages/class.ilPageObjectGUI.php");
01273                 $page =& new ilPageObject("qpl", $_GET["pg_id"]);
01274                 $page_gui =& new ilPageObjectGUI($page);
01275                 $page_gui->showMediaFullscreen();
01276                 
01277         }
01278 
01282         function download_paragraphObject()
01283         {
01284                 include_once("content/classes/Pages/class.ilPageObject.php");
01285                 $pg_obj =& new ilPageObject("qpl", $_GET["pg_id"]);
01286                 $pg_obj->send_paragraph ($_GET["par_id"], $_GET["downloadtitle"]);
01287                 exit;
01288         }
01289 
01290         
01291         function filterObject()
01292         {
01293                 $filter_type = $_POST["sel_filter_type"];
01294                 if (!$filter_type)
01295                 {
01296                         $filter_type = $_GET["sel_filter_type"];
01297                 }
01298                 $filter_question_type = $_POST["sel_question_type"];
01299                 if (!$filter_question_type)
01300                 {
01301                         $filter_question_type = $_GET["sel_question_type"];
01302                 }
01303                 $filter_questionpool = $_POST["sel_questionpool"];
01304                 if (!$filter_questionpool)
01305                 {
01306                         $filter_questionpool = $_GET["sel_questionpool"];
01307                 }
01308                 $filter_text = $_POST["filter_text"];
01309                 if (!$filter_text)
01310                 {
01311                         $filter_text = $_GET["filter_text"];
01312                 }
01313                 $this->questionBrowser($filter_type, $filter_question_type, $filter_questionpool, $filter_text);
01314         }
01315 
01323         function resetFilterObject()
01324         {
01325                 $_GET["sel_filter_type"] = "";
01326                 $_GET["sel_question_type"] = "";
01327                 $_GET["sel_questionpool"] = "";
01328                 $_GET["filter_text"] = "";
01329                 $this->questionBrowser();
01330         }
01331 
01339         function backObject()
01340         {
01341                 $this->ctrl->redirect($this, "questions");
01342         }
01343         
01351         function insertQuestionsObject()
01352         {
01353                 // insert selected questions into test
01354                 $selected_array = array();
01355                 foreach ($_POST as $key => $value)
01356                 {
01357                         if (preg_match("/cb_(\d+)/", $key, $matches))
01358                         {
01359                                 array_push($selected_array, $matches[1]);
01360                         }
01361                 }
01362                 if (!count($selected_array))
01363                 {
01364                         sendInfo($this->lng->txt("tst_insert_missing_question"), true);
01365                         $this->ctrl->redirect($this, "browseForQuestions");
01366                 }
01367                 else
01368                 {
01369 
01370                         foreach ($selected_array as $key => $value) 
01371                         {
01372                                 $this->object->insertQuestion($value);
01373                         }
01374                         $this->object->saveCompleteStatus();
01375                         sendInfo($this->lng->txt("tst_questions_inserted"), true);
01376                         $this->ctrl->redirect($this, "questions");
01377                         return;
01378                 }
01379         }
01380 
01388         function questionBrowser($filter_type = "", $filter_question_type = "", $filter_questionpool = "", $filter_text = "")
01389         {
01390                 global $rbacsystem;
01391 
01392                 $this->ctrl->setParameterByClass(get_class($this), "browse", "1");
01393                 if (!$filter_type)
01394                 {
01395                         $filter_type = $_GET["sel_filter_type"];
01396                 }
01397                 $this->ctrl->setParameterByClass(get_class($this), "sel_filter_type", $filter_type);
01398                 if (!$filter_question_type)
01399                 {
01400                         $filter_question_type = $_GET["sel_question_type"];
01401                 }
01402                 $this->ctrl->setParameterByClass(get_class($this), "sel_question_type", $filter_question_type);
01403                 if (!$filter_questionpool)
01404                 {
01405                         $filter_questionpool = $_GET["sel_questionpool"];
01406                 }
01407                 $this->ctrl->setParameterByClass(get_class($this), "sel_questionpool", $filter_questionpool);
01408                 if (!$filter_text)
01409                 {
01410                         $filter_text = $_GET["filter_text"];
01411                 }
01412                 $this->ctrl->setParameterByClass(get_class($this), "filter_text", $filter_text);
01413                 
01414                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_questionbrowser.html", true);
01415                 $this->tpl->addBlockFile("A_BUTTONS", "a_buttons", "tpl.il_as_qpl_action_buttons.html", true);
01416                 $this->tpl->addBlockFile("FILTER_QUESTION_MANAGER", "filter_questions", "tpl.il_as_tst_filter_questions.html", true);
01417 
01418                 $questionpools =& $this->object->get_qpl_titles();
01419 
01420                 $filter_fields = array(
01421                         "title" => $this->lng->txt("title"),
01422                         "comment" => $this->lng->txt("description"),
01423                         "author" => $this->lng->txt("author"),
01424                 );
01425                 $this->tpl->setCurrentBlock("filterrow");
01426                 foreach ($filter_fields as $key => $value) {
01427                         $this->tpl->setVariable("VALUE_FILTER_TYPE", "$key");
01428                         $this->tpl->setVariable("NAME_FILTER_TYPE", "$value");
01429                         if (strcmp($_POST["cmd"]["resetFilter"], "") == 0) {
01430                                 if (strcmp($filter_type, $key) == 0) {
01431                                         $this->tpl->setVariable("VALUE_FILTER_SELECTED", " selected=\"selected\"");
01432                                 }
01433                         }
01434                         $this->tpl->parseCurrentBlock();
01435                 }
01436 
01437                 $questiontypes =& $this->object->_getQuestiontypes();
01438                 foreach ($questiontypes as $key => $value)
01439                 {
01440                         $this->tpl->setCurrentBlock("questiontype_row");
01441                         $this->tpl->setVariable("VALUE_QUESTION_TYPE", $value);
01442                         $this->tpl->setVariable("TEXT_QUESTION_TYPE", $this->lng->txt($value));
01443                         if (strcmp($filter_question_type, $value) == 0)
01444                         {
01445                                 $this->tpl->setVariable("SELECTED_QUESTION_TYPE", " selected=\"selected\"");
01446                         }
01447                         $this->tpl->parseCurrentBlock();
01448                 }
01449                 
01450                 foreach ($questionpools as $key => $value)
01451                 {
01452                         $this->tpl->setCurrentBlock("questionpool_row");
01453                         $this->tpl->setVariable("VALUE_QUESTIONPOOL", $key);
01454                         $this->tpl->setVariable("TEXT_QUESTIONPOOL", $value);
01455                         if (strcmp($filter_questionpool, $key) == 0)
01456                         {
01457                                 $this->tpl->setVariable("SELECTED_QUESTIONPOOL", " selected=\"selected\"");
01458                         }
01459                         $this->tpl->parseCurrentBlock();
01460                 }
01461 
01462                 $this->tpl->setCurrentBlock("filter_questions");
01463                 $this->tpl->setVariable("SHOW_QUESTION_TYPES", $this->lng->txt("filter_show_question_types"));
01464                 $this->tpl->setVariable("TEXT_ALL_QUESTION_TYPES", $this->lng->txt("filter_all_question_types"));
01465                 $this->tpl->setVariable("SHOW_QUESTIONPOOLS", $this->lng->txt("filter_show_questionpools"));
01466                 $this->tpl->setVariable("TEXT_ALL_QUESTIONPOOLS", $this->lng->txt("filter_all_questionpools"));
01467                 $this->tpl->setVariable("FILTER_TEXT", $this->lng->txt("filter"));
01468                 $this->tpl->setVariable("TEXT_FILTER_BY", $this->lng->txt("by"));
01469                 if (strcmp($_POST["cmd"]["resetFilter"], "") == 0) 
01470                 {
01471                         $this->tpl->setVariable("VALUE_FILTER_TEXT", $filter_text);
01472                 }
01473                 $this->tpl->setVariable("VALUE_SUBMIT_FILTER", $this->lng->txt("set_filter"));
01474                 $this->tpl->setVariable("VALUE_RESET_FILTER", $this->lng->txt("reset_filter"));
01475                 $this->tpl->parseCurrentBlock();
01476 
01477                 // create edit buttons & table footer
01478                 $this->tpl->setCurrentBlock("selection");
01479                 $this->tpl->setVariable("INSERT", $this->lng->txt("insert"));
01480                 $this->tpl->parseCurrentBlock();
01481 
01482                 $this->tpl->setCurrentBlock("Footer");
01483                 $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"\">");
01484                 $this->tpl->parseCurrentBlock();
01485 
01486                 $this->tpl->setCurrentBlock("QTab");
01487 
01488                 $startrow = 0;
01489                 if ($_GET["prevrow"])
01490                 {
01491                         $startrow = $_GET["prevrow"];
01492                 }
01493                 if ($_GET["nextrow"])
01494                 {
01495                         $startrow = $_GET["nextrow"];
01496                 }
01497                 if ($_GET["startrow"])
01498                 {
01499                         $startrow = $_GET["startrow"];
01500                 }
01501                 if (!$_GET["sort"])
01502                 {
01503                         // default sort order
01504                         $_GET["sort"] = array("title" => "ASC");
01505                 }
01506                 $table = $this->object->getQuestionsTable($_GET["sort"], $filter_text, $filter_type, $startrow, 1, $filter_question_type, $filter_questionpool);
01507                 // display all questions in accessable question pools
01508                 $colors = array("tblrow1", "tblrow2");
01509                 $counter = 0;
01510                 $existing_questions =& $this->object->getExistingQuestions();
01511                 foreach ($table["rows"] as $data)
01512                 {
01513                         if (!in_array($data["question_id"], $existing_questions))
01514                         {
01515                                 if ($data["complete"])
01516                                 {
01517                                         // make only complete questions selectable
01518                                         $this->tpl->setVariable("QUESTION_ID", $data["question_id"]);
01519                                 }
01520                                 $this->tpl->setVariable("QUESTION_TITLE", "<strong>" . $data["title"] . "</strong>");
01521                                 $this->tpl->setVariable("PREVIEW", "[<a href=\"" . $this->getCallingScript() . "$add_parameter&preview=" . $data["question_id"] . "\">" . $this->lng->txt("preview") . "</a>]");
01522                                 $this->tpl->setVariable("QUESTION_COMMENT", $data["comment"]);
01523                                 $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt($data["type_tag"]));
01524                                 $this->tpl->setVariable("QUESTION_AUTHOR", $data["author"]);
01525                                 $this->tpl->setVariable("QUESTION_CREATED", ilFormat::formatDate(ilFormat::ftimestamp2dateDB($data["created"]), "date"));
01526                                 $this->tpl->setVariable("QUESTION_UPDATED", ilFormat::formatDate(ilFormat::ftimestamp2dateDB($data["TIMESTAMP14"]), "date"));
01527                                 $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
01528                                 $this->tpl->setVariable("QUESTION_POOL", $questionpools[$data["obj_fi"]]);
01529                                 $this->tpl->parseCurrentBlock();
01530                                 $counter++;
01531                         }
01532                 }
01533 
01534                 if ($table["rowcount"] > count($table["rows"]))
01535                 {
01536                         $nextstep = $table["nextrow"] + $table["step"];
01537                         if ($nextstep > $table["rowcount"])
01538                         {
01539                                 $nextstep = $table["rowcount"];
01540                         }
01541                         $sort = "";
01542                         if (is_array($_GET["sort"]))
01543                         {
01544                                 $key = key($_GET["sort"]);
01545                                 $sort = "&sort[$key]=" . $_GET["sort"]["$key"];
01546                         }
01547                         $counter = 1;
01548                         for ($i = 0; $i < $table["rowcount"]; $i += $table["step"])
01549                         {
01550                                 $this->tpl->setCurrentBlock("pages");
01551                                 if ($table["startrow"] == $i)
01552                                 {
01553                                         $this->tpl->setVariable("PAGE_NUMBER", "<span class=\"inactivepage\">$counter</span>");
01554                                 }
01555                                 else
01556                                 {
01557                                         $this->tpl->setVariable("PAGE_NUMBER", "<a href=\"" . $this->ctrl->getFormAction($this) . "$sort&nextrow=$i" . "\">$counter</a>");
01558                                 }
01559                                 $this->tpl->parseCurrentBlock();
01560                                 $counter++;
01561                         }
01562                         $this->tpl->setCurrentBlock("navigation_bottom");
01563                         $this->tpl->setVariable("TEXT_ITEM", $this->lng->txt("item"));
01564                         $this->tpl->setVariable("TEXT_ITEM_START", $table["startrow"] + 1);
01565                         $end = $table["startrow"] + $table["step"];
01566                         if ($end > $table["rowcount"])
01567                         {
01568                                 $end = $table["rowcount"];
01569                         }
01570                         $this->tpl->setVariable("TEXT_ITEM_END", $end);
01571                         $this->tpl->setVariable("TEXT_OF", strtolower($this->lng->txt("of")));
01572                         $this->tpl->setVariable("TEXT_ITEM_COUNT", $table["rowcount"]);
01573                         $this->tpl->setVariable("TEXT_PREVIOUS", $this->lng->txt("previous"));
01574                         $this->tpl->setVariable("TEXT_NEXT", $this->lng->txt("next"));
01575                         $this->tpl->setVariable("HREF_PREV_ROWS", $this->ctrl->getFormAction($this) . "$sort&prevrow=" . $table["prevrow"]);
01576                         $this->tpl->setVariable("HREF_NEXT_ROWS", $this->ctrl->getFormAction($this) . "$sort&nextrow=" . $table["nextrow"]);
01577                         $this->tpl->parseCurrentBlock();
01578                 }
01579 
01580                 // if there are no questions, display a message
01581                 if ($counter == 0) {
01582                         $this->tpl->setCurrentBlock("Emptytable");
01583                         $this->tpl->setVariable("TEXT_EMPTYTABLE", $this->lng->txt("no_questions_available"));
01584                         $this->tpl->parseCurrentBlock();
01585                 }
01586 
01587                 // define the sort column parameters
01588                 $sort = array(
01589                         "title" => $_GET["sort"]["title"],
01590                         "comment" => $_GET["sort"]["comment"],
01591                         "type" => $_GET["sort"]["type"],
01592                         "author" => $_GET["sort"]["author"],
01593                         "created" => $_GET["sort"]["created"],
01594                         "updated" => $_GET["sort"]["updated"],
01595                         "qpl" => $_GET["sort"]["qpl"]
01596                 );
01597                 foreach ($sort as $key => $value) {
01598                         if (strcmp($value, "ASC") == 0) {
01599                                 $sort[$key] = "DESC";
01600                         } else {
01601                                 $sort[$key] = "ASC";
01602                         }
01603                 }
01604 
01605                 $this->tpl->setCurrentBlock("adm_content");
01606                 // create table header
01607                 $this->ctrl->setCmd("questionBrowser");
01608                 $this->ctrl->setParameterByClass(get_class($this), "startrow", $table["startrow"]);
01609                 $this->tpl->setVariable("QUESTION_TITLE", "<a href=\"" . $this->ctrl->getFormAction($this) . "&sort[title]=" . $sort["title"] . "\">" . $this->lng->txt("title") . "</a>" . $table["images"]["title"]);
01610                 $this->tpl->setVariable("QUESTION_COMMENT", "<a href=\"" . $this->ctrl->getFormAction($this) . "&sort[comment]=" . $sort["comment"] . "\">" . $this->lng->txt("description") . "</a>". $table["images"]["comment"]);
01611                 $this->tpl->setVariable("QUESTION_TYPE", "<a href=\"" . $this->ctrl->getFormAction($this) . "&sort[type]=" . $sort["type"] . "\">" . $this->lng->txt("question_type") . "</a>" . $table["images"]["type"]);
01612                 $this->tpl->setVariable("QUESTION_AUTHOR", "<a href=\"" . $this->ctrl->getFormAction($this) . "&sort[author]=" . $sort["author"] . "\">" . $this->lng->txt("author") . "</a>" . $table["images"]["author"]);
01613                 $this->tpl->setVariable("QUESTION_CREATED", "<a href=\"" . $this->ctrl->getFormAction($this) . "&sort[created]=" . $sort["created"] . "\">" . $this->lng->txt("create_date") . "</a>" . $table["images"]["created"]);
01614                 $this->tpl->setVariable("QUESTION_UPDATED", "<a href=\"" . $this->ctrl->getFormAction($this) . "&sort[updated]=" . $sort["updated"] . "\">" . $this->lng->txt("last_update") . "</a>" . $table["images"]["updated"]);
01615                 $this->tpl->setVariable("QUESTION_POOL", "<a href=\"" . $this->ctrl->getFormAction($this) . "&sort[qpl]=" . $sort["qpl"] . "\">" . $this->lng->txt("obj_qpl") . "</a>" . $table["images"]["qpl"]);
01616                 $this->tpl->setVariable("BUTTON_BACK", $this->lng->txt("back"));
01617                 $this->tpl->setVariable("ACTION_QUESTION_FORM", $this->ctrl->getFormAction($this));
01618                 $this->tpl->parseCurrentBlock();
01619         }
01620 
01629         function createQuestionPool($name = "dummy")
01630         {
01631                 global $tree;
01632                 $parent_ref = $tree->getParentId($this->object->getRefId());
01633                 $qpl = new ilObjQuestionPool();
01634                 $qpl->setType("qpl");
01635                 $qpl->setTitle($name);
01636                 $qpl->setDescription("");
01637                 $qpl->create();
01638                 $qpl->createReference();
01639                 $qpl->putInTree($parent_ref);
01640                 $qpl->setPermissions($parent_ref);
01641                 return $qpl->getRefId();
01642         }
01643 
01651         function randomselectObject()
01652         {
01653                 global $ilUser;
01654                 $add_parameter = $this->getAddParameter();
01655                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_random_select.html", true);
01656                 $questionpools =& $this->object->getAvailableQuestionpools();
01657                 $this->tpl->setCurrentBlock("option");
01658                 $this->tpl->setVariable("VALUE_OPTION", "0");
01659                 $this->tpl->setVariable("TEXT_OPTION", $this->lng->txt("all_available_question_pools"));
01660                 $this->tpl->parseCurrentBlock();
01661                 foreach ($questionpools as $key => $value)
01662                 {
01663                         $this->tpl->setCurrentBlock("option");
01664                         $this->tpl->setVariable("VALUE_OPTION", $key);
01665                         $this->tpl->setVariable("TEXT_OPTION", $value);
01666                         $this->tpl->parseCurrentBlock();
01667                 }
01668                 $this->tpl->setCurrentBlock("hidden");
01669                 $this->tpl->setVariable("HIDDEN_NAME", "sel_question_types");
01670                 $this->tpl->setVariable("HIDDEN_VALUE", $_POST["sel_question_types"]);
01671                 $this->tpl->parseCurrentBlock();
01672                 $this->tpl->setCurrentBlock("adm_content");
01673                 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
01674                 $this->tpl->setVariable("TXT_QPL_SELECT", $this->lng->txt("tst_random_select_questionpool"));
01675                 $this->tpl->setVariable("TXT_NR_OF_QUESTIONS", $this->lng->txt("tst_random_nr_of_questions"));
01676                 $this->tpl->setVariable("BTN_SUBMIT", $this->lng->txt("submit"));
01677                 $this->tpl->setVariable("BTN_CANCEL", $this->lng->txt("cancel"));
01678                 $this->tpl->parseCurrentBlock();
01679         }
01680         
01688         function cancelRandomSelectObject()
01689         {
01690                 $this->ctrl->redirect($this, "questions");
01691         }
01692         
01700         function createRandomSelectionObject()
01701         {
01702                 $question_array = $this->object->randomSelectQuestions($_POST["nr_of_questions"], $_POST["sel_qpl"]);
01703                 $add_parameter = $this->getAddParameter();
01704                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_random_question_offer.html", true);
01705                 $color_class = array("tblrow1", "tblrow2");
01706                 $counter = 0;
01707                 $questionpools =& $this->object->get_qpl_titles();
01708                 foreach ($question_array as $question_id)
01709                 {
01710                         $dataset = $this->object->getQuestionDataset($question_id);
01711                         $this->tpl->setCurrentBlock("QTab");
01712                         $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
01713                         $this->tpl->setVariable("QUESTION_TITLE", $dataset->title);
01714                         $this->tpl->setVariable("QUESTION_COMMENT", $dataset->comment);
01715                         $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt($dataset->type_tag));
01716                         $this->tpl->setVariable("QUESTION_AUTHOR", $dataset->author);
01717                         $this->tpl->setVariable("QUESTION_POOL", $questionpools[$dataset->obj_fi]);
01718                         $this->tpl->parseCurrentBlock();
01719                         $counter++;
01720                 }
01721                 if (count($question_array) == 0)
01722                 {
01723                         $this->tpl->setCurrentBlock("Emptytable");
01724                         $this->tpl->setVariable("TEXT_NO_QUESTIONS_AVAILABLE", $this->lng->txt("no_questions_available"));
01725                         $this->tpl->parseCurrentBlock();
01726                 }
01727                         else
01728                 {
01729                         $this->tpl->setCurrentBlock("Selectionbuttons");
01730                         $this->tpl->setVariable("BTN_YES", $this->lng->txt("random_accept_sample"));
01731                         $this->tpl->setVariable("BTN_NO", $this->lng->txt("random_another_sample"));
01732                         $this->tpl->parseCurrentBlock();
01733                 }
01734                 $chosen_questions = join($question_array, ",");
01735                 $this->tpl->setCurrentBlock("adm_content");
01736                 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
01737                 $this->tpl->setVariable("QUESTION_TITLE", $this->lng->txt("tst_question_title"));
01738                 $this->tpl->setVariable("QUESTION_COMMENT", $this->lng->txt("description"));
01739                 $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("tst_question_type"));
01740                 $this->tpl->setVariable("QUESTION_AUTHOR", $this->lng->txt("author"));
01741                 $this->tpl->setVariable("QUESTION_POOL", $this->lng->txt("qpl"));
01742                 $this->tpl->setVariable("VALUE_CHOSEN_QUESTIONS", $chosen_questions);
01743                 $this->tpl->setVariable("VALUE_QUESTIONPOOL_SELECTION", $_POST["sel_qpl"]);
01744                 $this->tpl->setVariable("VALUE_NR_OF_QUESTIONS", $_POST["nr_of_questions"]);
01745                 $this->tpl->setVariable("TEXT_QUESTION_OFFER", $this->lng->txt("tst_question_offer"));
01746                 $this->tpl->setVariable("BTN_CANCEL", $this->lng->txt("cancel"));
01747                 $this->tpl->parseCurrentBlock();
01748         }
01749         
01757         function insertRandomSelectionObject()
01758         {
01759                 $selected_array = split(",", $_POST["chosen_questions"]);
01760                 if (!count($selected_array))
01761                 {
01762                         sendInfo($this->lng->txt("tst_insert_missing_question"));
01763                 }
01764                 else
01765                 {
01766                         $total = $this->object->evalTotalPersons();
01767                         if ($total)
01768                         {
01769                                 // the test was executed previously
01770                                 sendInfo(sprintf($this->lng->txt("tst_insert_questions_and_results"), $total));
01771                         }
01772                         else
01773                         {
01774                                 sendInfo($this->lng->txt("tst_insert_questions"));
01775                         }
01776                         foreach ($selected_array as $key => $value) 
01777                         {
01778                                 $this->object->insertQuestion($value);
01779                         }
01780                         $this->object->saveCompleteStatus();
01781                         sendInfo($this->lng->txt("tst_questions_inserted"), true);
01782                         $this->ctrl->redirect($this, "questions");
01783                         return;
01784                 }
01785         }
01786 
01787         function randomQuestionsObject()
01788         {
01789                 $total = $this->object->evalTotalPersons();
01790                 $add_parameter = $this->getAddParameter();
01791                 $available_qpl =& $this->object->getAvailableQuestionpools(true);
01792                 $qpl_question_count = array();
01793                 foreach ($available_qpl as $key => $value)
01794                 {
01795                         $count = ilObjQuestionPool::_getQuestionCount($key);
01796                         $qpl_question_count[$key] = $count;
01797                         if ($count == 1)
01798                         {
01799                                 $available_qpl[$key] = $value . " ($count " . $this->lng->txt("ass_question") . ")";
01800                         }
01801                         else
01802                         {
01803                                 $available_qpl[$key] = $value . " ($count " . $this->lng->txt("ass_questions") . ")";
01804                         }
01805                 }
01806                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_random_questions.html", true);
01807                 $found_qpls = array();
01808                 if (count($_POST) == 0)
01809                 {
01810                         $found_qpls = $this->object->getRandomQuestionpools();
01811                 }
01812                 if (count($found_qpls) == 0)
01813                 {
01814                         if (!array_key_exists("countqpl_0", $_POST))
01815                         {
01816                                 // create first questionpool row automatically
01817                                 foreach ($available_qpl as $key => $value)
01818                                 {
01819                                         $this->tpl->setCurrentBlock("qpl_value");
01820                                         $this->tpl->setVariable("QPL_ID", $key);
01821                                         $this->tpl->setVariable("QPL_TEXT", $value);
01822                                         $this->tpl->parseCurrentBlock();
01823                                 }
01824                                 $this->tpl->setCurrentBlock("questionpool_row");
01825                                 $this->tpl->setVariable("COUNTQPL", "0");
01826                                 $this->tpl->setVariable("VALUE_COUNTQPL", $_POST["countqpl_0"]);
01827                                 $this->tpl->setVariable("TEXT_SELECT_QUESTIONPOOL", $this->lng->txt("select_questionpool_option"));
01828                                 $this->tpl->setVariable("TEXT_QUESTIONS_FROM", $this->lng->txt("questions_from"));
01829                                 $this->tpl->parseCurrentBlock();
01830                         }
01831                 }
01832                 $qpl_unselected = 0;
01833                 foreach ($_POST as $key => $value)
01834                 {
01835                         if (preg_match("/countqpl_(\d+)/", $key, $matches))
01836                         {
01837                                 if ($value > $qpl_question_count[$_POST["qpl_" . $matches[1]]])
01838                                 {
01839                                         $value = $qpl_question_count[$_POST["qpl_" . $matches[1]]];
01840                                         sendInfo($this->lng->txt("tst_random_selection_question_count_too_high"));
01841                                 }
01842                                 $found_qpls[$matches[1]] = array(
01843                                         "index" => $matches[1],
01844                                         "count" => sprintf("%d", $value),
01845                                         "qpl"   => $_POST["qpl_" . $matches[1]]
01846                                 );
01847                                 if ($_POST["qpl_" . $matches[1]] == -1)
01848                                 {
01849                                         $qpl_unselected = 1;
01850                                 }
01851                         }
01852                 }
01853                 foreach ($_POST as $key => $value)
01854                 {
01855                         if (preg_match("/deleteqpl_(\d+)/", $key, $matches))
01856                         {
01857                                 unset($found_qpls[$matches[1]]);
01858                         }
01859                 }
01860                 sort($found_qpls);
01861                 $found_qpls = array_values($found_qpls);
01862                 $counter = 0;
01863                 foreach ($found_qpls as $key => $value)
01864                 {
01865                         $pools = $available_qpl;
01866                         foreach ($found_qpls as $pkey => $pvalue)
01867                         {
01868                                 if ($pvalue["qpl"] != $value["qpl"])
01869                                 {
01870                                         unset($pools[$pvalue["qpl"]]);
01871                                 }
01872                         }
01873                         // create first questionpool row automatically
01874                         foreach ($pools as $pkey => $pvalue)
01875                         {
01876                                 $this->tpl->setCurrentBlock("qpl_value");
01877                                 $this->tpl->setVariable("QPL_ID", $pkey);
01878                                 $this->tpl->setVariable("QPL_TEXT", $pvalue);
01879                                 if ($pkey == $value["qpl"])
01880                                 {
01881                                         $this->tpl->setVariable("SELECTED_QPL", " selected=\"selected\"");
01882                                 }
01883                                 $this->tpl->parseCurrentBlock();
01884                         }
01885                         $this->tpl->setCurrentBlock("questionpool_row");
01886                         $this->tpl->setVariable("COUNTQPL", $counter);
01887                         $this->tpl->setVariable("VALUE_COUNTQPL", $value["count"]);
01888                         $this->tpl->setVariable("TEXT_SELECT_QUESTIONPOOL", $this->lng->txt("select_questionpool_option"));
01889                         $this->tpl->setVariable("TEXT_QUESTIONS_FROM", $this->lng->txt("questions_from"));
01890                         if (!$total)
01891                         {
01892                                 if ($counter > 0)
01893                                 {
01894                                         $this->tpl->setVariable("BTNCOUNTQPL", $counter);
01895                                         $this->tpl->setVariable("BTN_DELETE", $this->lng->txt("delete"));
01896                                 }
01897                         }
01898                         $this->tpl->parseCurrentBlock();
01899                         $counter++;
01900                 }
01901                 if ($_POST["cmd"]["addQuestionpool"])
01902                 {
01903                         if ($qpl_unselected)
01904                         {
01905                                 sendInfo($this->lng->txt("tst_random_qpl_unselected"));
01906                         }
01907                         else
01908                         {
01909                                 $pools = $available_qpl;
01910                                 foreach ($found_qpls as $pkey => $pvalue)
01911                                 {
01912                                         unset($pools[$pvalue["qpl"]]);
01913                                 }
01914                                 if (count($pools) == 0)
01915                                 {
01916                                         sendInfo($this->lng->txt("tst_no_more_available_questionpools"));
01917                                 }
01918                                 else
01919                                 {
01920                                         foreach ($pools as $key => $value)
01921                                         {
01922                                                 $this->tpl->setCurrentBlock("qpl_value");
01923                                                 $this->tpl->setVariable("QPL_ID", $key);
01924                                                 $this->tpl->setVariable("QPL_TEXT", $value);
01925                                                 $this->tpl->parseCurrentBlock();
01926                                         }
01927                                         $this->tpl->setCurrentBlock("questionpool_row");
01928                                         $this->tpl->setVariable("COUNTQPL", "$counter");
01929                                         $this->tpl->setVariable("TEXT_SELECT_QUESTIONPOOL", $this->lng->txt("select_questionpool_option"));
01930                                         $this->tpl->setVariable("TEXT_QUESTIONS_FROM", $this->lng->txt("questions_from"));
01931                                         $this->tpl->parseCurrentBlock();
01932                                 }
01933                         }
01934                 }
01935                 if ($_POST["cmd"]["save"])
01936                 {
01937                         $this->object->saveRandomQuestionCount($_POST["total_questions"]);
01938                         $this->object->saveRandomQuestionpools($found_qpls);
01939                         $this->object->saveCompleteStatus();
01940                 }
01941                 $this->tpl->setCurrentBlock("adm_content");
01942                 $this->tpl->setVariable("TEXT_SELECT_RANDOM_QUESTIONS", $this->lng->txt("tst_select_random_questions"));
01943                 $this->tpl->setVariable("TEXT_TOTAL_QUESTIONS", $this->lng->txt("tst_total_questions"));
01944                 $this->tpl->setVariable("TEXT_TOTAL_QUESTIONS_DESCRIPTION", $this->lng->txt("tst_total_questions_description"));
01945                 $total_questions = $this->object->getRandomQuestionCount();
01946                 if (array_key_exists("total_questions", $_POST))
01947                 {
01948                         $total_questions = $_POST["total_questions"];
01949                 }
01950                 if ($total_questions > 0)
01951                 {
01952                         $sum = 0;
01953                         foreach ($found_qpls as $key => $value)
01954                         {
01955                                 $sum += $qpl_question_count[$value["qpl"]];
01956                         }
01957                         if ($total_questions > $sum)
01958                         {
01959                                 $total_questions = $sum;
01960                                 if ($_POST["cmd"]["saveRandomQuestions"])
01961                                 {
01962                                         $this->object->saveRandomQuestionCount($total_questions);
01963                                 }
01964                                 sendInfo($this->lng->txt("tst_random_selection_question_total_count_too_high"));
01965                         }
01966                 }
01967                 $this->tpl->setVariable("VALUE_TOTAL_QUESTIONS", $total_questions);
01968                 $this->tpl->setVariable("TEXT_QUESTIONPOOLS", $this->lng->txt("tst_random_questionpools"));
01969                 if (!$total)
01970                 {
01971                         $this->tpl->setVariable("BTN_SAVE", $this->lng->txt("save"));
01972                         $this->tpl->setVariable("BTN_ADD_QUESTIONPOOL", $this->lng->txt("add_questionpool"));
01973                 }
01974                 $this->tpl->setVariable("FORM_ACTION", $this->getCallingScript() . $add_parameter);
01975                 $this->tpl->parseCurrentBlock();
01976         }
01977 
01978         function browseForQuestionsObject()
01979         {
01980                 $this->questionBrowser();
01981         }
01982         
01990         function executeCreateQuestionObject()
01991         {
01992                 $qpl_ref_id = $_POST["sel_qpl"];
01993                 if ((strcmp($_POST["txt_qpl"], "") == 0) && (strcmp($qpl_ref_id, "") == 0))
01994                 {
01995                         sendInfo($this->lng->txt("questionpool_not_entered"));
01996                         $this->createQuestionObject();
01997                         return;
01998                 }
01999                 else
02000                 {
02001                         $_SESSION["test_id"] = $this->object->getRefId();
02002                         if (strcmp($_POST["txt_qpl"], "") != 0)
02003                         {
02004                                 // create a new question pool and return the reference id
02005                                 $qpl_ref_id = $this->createQuestionPool($_POST["txt_qpl"]);
02006                         }
02007                         ilUtil::redirect("questionpool.php?ref_id=" . $qpl_ref_id . "&cmd=createQuestionForTest&test_ref_id=".$_GET["ref_id"]."&sel_question_types=" . $_POST["sel_question_types"]);
02008                         exit();
02009                 }
02010         }
02011 
02019         function cancelCreateQuestionObject()
02020         {
02021                 $this->ctrl->redirect($this, "questions");
02022         }
02023 
02031         function createQuestionObject()
02032         {
02033                 global $ilUser;
02034                 $add_parameter = $this->getAddParameter();
02035                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_qpl_select.html", true);
02036                 $questionpools =& $this->object->getAvailableQuestionpools();
02037                 if (count($questionpools) == 0)
02038                 {
02039                         $this->tpl->setCurrentBlock("option");
02040                         $this->tpl->setVariable("VALUE_QPL", "");
02041                         $this->tpl->parseCurrentBlock();
02042                 }
02043                 else
02044                 {
02045                         foreach ($questionpools as $key => $value)
02046                         {
02047                                 $this->tpl->setCurrentBlock("option");
02048                                 $this->tpl->setVariable("VALUE_OPTION", $key);
02049                                 $this->tpl->setVariable("TEXT_OPTION", $value);
02050                                 $this->tpl->parseCurrentBlock();
02051                         }
02052                 }
02053                 $this->tpl->setCurrentBlock("hidden");
02054                 $this->tpl->setVariable("HIDDEN_NAME", "sel_question_types");
02055                 $this->tpl->setVariable("HIDDEN_VALUE", $_POST["sel_question_types"]);
02056                 $this->tpl->parseCurrentBlock();
02057                 $this->tpl->setCurrentBlock("adm_content");
02058                 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
02059 
02060                 if (count($questionpools) == 0)
02061                 {
02062                         $this->tpl->setVariable("TXT_QPL_SELECT", $this->lng->txt("tst_enter_questionpool"));
02063                 }
02064                 else
02065                 {
02066                         $this->tpl->setVariable("TXT_QPL_SELECT", $this->lng->txt("tst_select_questionpool"));
02067                 }
02068                 $this->tpl->setVariable("BTN_SUBMIT", $this->lng->txt("submit"));
02069                 $this->tpl->setVariable("BTN_CANCEL", $this->lng->txt("cancel"));
02070                 $this->tpl->parseCurrentBlock();
02071         }
02072 
02080         function confirmRemoveQuestionsObject()
02081         {
02082                 sendInfo($this->lng->txt("tst_questions_removed"));
02083                 $checked_questions = array();
02084                 foreach ($_POST as $key => $value) {
02085                         if (preg_match("/id_(\d+)/", $key, $matches)) {
02086                                 array_push($checked_questions, $matches[1]);
02087                         }
02088                 }
02089                 foreach ($checked_questions as $key => $value) {
02090                         $this->object->removeQuestion($value);
02091                 }
02092                 $this->object->saveCompleteStatus();
02093                 $this->ctrl->redirect($this, "questions");
02094         }
02095         
02103         function cancelRemoveQuestionsObject()
02104         {
02105                 $this->ctrl->redirect($this, "questions");
02106         }
02107         
02115         function removeQuestionsForm($checked_questions)
02116         {
02117                 sendInfo();
02118                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_remove_questions.html", true);
02119                 $query = sprintf("SELECT qpl_questions.*, qpl_question_type.type_tag FROM qpl_questions, qpl_question_type, tst_test_question WHERE qpl_questions.question_type_fi = qpl_question_type.question_type_id AND tst_test_question.test_fi = %s AND tst_test_question.question_fi = qpl_questions.question_id ORDER BY sequence",
02120                         $this->ilias->db->quote($this->object->getTestId())
02121                 );
02122                 $query_result = $this->ilias->db->query($query);
02123                 $colors = array("tblrow1", "tblrow2");
02124                 $counter = 0;
02125                 if ($query_result->numRows() > 0)
02126                 {
02127                         while ($data = $query_result->fetchRow(DB_FETCHMODE_OBJECT))
02128                         {
02129                                 if (in_array($data->question_id, $checked_questions))
02130                                 {
02131                                         $this->tpl->setCurrentBlock("row");
02132                                         $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
02133                                         $this->tpl->setVariable("TXT_TITLE", $data->title);
02134                                         $this->tpl->setVariable("TXT_DESCRIPTION", $data->comment);
02135                                         $this->tpl->setVariable("TXT_TYPE", $this->lng->txt($data->type_tag));
02136                                         $this->tpl->parseCurrentBlock();
02137                                         $counter++;
02138                                 }
02139                         }
02140                 }
02141                 foreach ($checked_questions as $id)
02142                 {
02143                         $this->tpl->setCurrentBlock("hidden");
02144                         $this->tpl->setVariable("HIDDEN_NAME", "id_$id");
02145                         $this->tpl->setVariable("HIDDEN_VALUE", "1");
02146                         $this->tpl->parseCurrentBlock();
02147                 }
02148 
02149                 $this->tpl->setCurrentBlock("adm_content");
02150                 $this->tpl->setVariable("TXT_TITLE", $this->lng->txt("tst_question_title"));
02151                 $this->tpl->setVariable("TXT_DESCRIPTION", $this->lng->txt("description"));
02152                 $this->tpl->setVariable("TXT_TYPE", $this->lng->txt("tst_question_type"));
02153                 $this->tpl->setVariable("BTN_CONFIRM", $this->lng->txt("confirm"));
02154                 $this->tpl->setVariable("BTN_CANCEL", $this->lng->txt("cancel"));
02155                 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
02156                 $this->tpl->parseCurrentBlock();
02157         }
02158 
02166         function removeQuestionsObject()
02167         {
02168                 $checked_questions = array();
02169                 foreach ($_POST as $key => $value) {
02170                         if (preg_match("/cb_(\d+)/", $key, $matches)) {
02171                                 array_push($checked_questions, $matches[1]);
02172                         }
02173                 }
02174                 if (count($checked_questions) > 0) {
02175                         $total = $this->object->evalTotalPersons();
02176                         if ($total) {
02177                                 // the test was executed previously
02178                                 sendInfo(sprintf($this->lng->txt("tst_remove_questions_and_results"), $total));
02179                         } else {
02180                                 sendInfo($this->lng->txt("tst_remove_questions"));
02181                         }
02182                         $this->removeQuestionsForm($checked_questions);
02183                         return;
02184                 } elseif (count($checked_questions) == 0) {
02185                         sendInfo($this->lng->txt("tst_no_question_selected_for_removal"), true);
02186                         $this->ctrl->redirect($this, "questions");
02187                 }
02188         }
02189         
02197         function moveQuestionsObject()
02198         {
02199                 $this->questionsObject();
02200         }
02201         
02209         function insertQuestionsBeforeObject()
02210         {
02211                 // get all questions to move
02212                 $move_questions = array();
02213                 foreach ($_POST as $key => $value)
02214                 {
02215                         if (preg_match("/^move_(\d+)$/", $key, $matches))
02216                         {
02217                                 array_push($move_questions, $value);
02218                         }
02219                 }
02220                 // get insert point
02221                 $insert_id = -1;
02222                 foreach ($_POST as $key => $value)
02223                 {
02224                         if (preg_match("/^cb_(\d+)$/", $key, $matches))
02225                         {
02226                                 if ($insert_id < 0)
02227                                 {
02228                                         $insert_id = $matches[1];
02229                                 }
02230                         }
02231                 }
02232                 if ($insert_id <= 0)
02233                 {
02234                         sendInfo($this->lng->txt("no_target_selected_for_move"), true);
02235                 }
02236                 else
02237                 {
02238                         $insert_mode = 0;
02239                         $this->object->moveQuestions($move_questions, $insert_id, $insert_mode);
02240                 }
02241                 $this->ctrl->redirect($this, "questions");
02242         }
02243         
02251         function insertQuestionsAfterObject()
02252         {
02253                 // get all questions to move
02254                 $move_questions = array();
02255                 foreach ($_POST as $key => $value)
02256                 {
02257                         if (preg_match("/^move_(\d+)$/", $key, $matches))
02258                         {
02259                                 array_push($move_questions, $value);
02260                         }
02261                 }
02262                 // get insert point
02263                 $insert_id = -1;
02264                 foreach ($_POST as $key => $value)
02265                 {
02266                         if (preg_match("/^cb_(\d+)$/", $key, $matches))
02267                         {
02268                                 if ($insert_id < 0)
02269                                 {
02270                                         $insert_id = $matches[1];
02271                                 }
02272                         }
02273                 }
02274                 if ($insert_id <= 0)
02275                 {
02276                         sendInfo($this->lng->txt("no_target_selected_for_move"), true);
02277                 }
02278                 else
02279                 {
02280                         $insert_mode = 1;
02281                         $this->object->moveQuestions($move_questions, $insert_id, $insert_mode);
02282                 }
02283                 $this->ctrl->redirect($this, "questions");
02284         }
02285         
02286         function questionsObject()
02287         {
02288                 global $rbacsystem;
02289 
02290                 if ((!$rbacsystem->checkAccess("read", $this->ref_id)) && (!$rbacsystem->checkAccess("write", $this->ref_id))) 
02291                 {
02292                         // allow only read and write access
02293                         sendInfo($this->lng->txt("cannot_edit_test"), true);
02294                         $path = $this->tree->getPathFull($this->object->getRefID());
02295                         ilUtil::redirect($this->getReturnLocation("cancel","../repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
02296                         return;
02297                 }
02298 
02299                 if ($this->object->isRandomTest())
02300                 {
02301                         $this->randomQuestionsObject();
02302                         return;
02303                 }
02304                 
02305                 $add_parameter = $this->getAddParameter();
02306 
02307                 if ($_GET["eqid"] and $_GET["eqpl"])
02308                 {
02309                         ilUtil::redirect("questionpool.php?ref_id=" . $_GET["eqpl"] . "&cmd=editQuestionForTest&calling_test=".$_GET["ref_id"]."&q_id=" . $_GET["eqid"]);
02310                 }
02311                 
02312                 if ($_GET["up"] > 0)
02313                 {
02314                         $this->object->questionMoveUp($_GET["up"]);
02315                 }
02316                 if ($_GET["down"] > 0)
02317                 {
02318                         $this->object->questionMoveDown($_GET["down"]);
02319                 }
02320 
02321                 if ($_GET["add"])
02322                 {
02323                         $selected_array = array();
02324                         array_push($selected_array, $_GET["add"]);
02325                         $total = $this->object->evalTotalPersons();
02326                         if ($total)
02327                         {
02328                                 // the test was executed previously
02329                                 sendInfo(sprintf($this->lng->txt("tst_insert_questions_and_results"), $total));
02330                         }
02331                         else
02332                         {
02333                                 sendInfo($this->lng->txt("tst_insert_questions"));
02334                         }
02335                         $this->insertQuestions($selected_array);
02336                         return;
02337                 }
02338 
02339                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_questions.html", true);
02340                 $this->tpl->addBlockFile("A_BUTTONS", "question_buttons", "tpl.il_as_tst_question_buttons.html", true);
02341 
02342                 if (strcmp($this->ctrl->getCmd(), "moveQuestions") == 0)
02343                 {
02344                         $checked_move = 0;
02345                         foreach ($_POST as $key => $value)
02346                         {
02347                                 if (preg_match("/cb_(\d+)/", $key, $matches))
02348                                 {
02349                                         $checked_move++;
02350                                         $this->tpl->setCurrentBlock("move");
02351                                         $this->tpl->setVariable("MOVE_COUNTER", $matches[1]);
02352                                         $this->tpl->setVariable("MOVE_VALUE", $matches[1]);
02353                                         $this->tpl->parseCurrentBlock();
02354                                 }
02355                         }
02356                         if ($checked_move)
02357                         {
02358                                 sendInfo($this->lng->txt("select_target_position_for_move_question"));
02359                                 $this->tpl->setCurrentBlock("move_buttons");
02360                                 $this->tpl->setVariable("INSERT_BEFORE", $this->lng->txt("insert_before"));
02361                                 $this->tpl->setVariable("INSERT_AFTER", $this->lng->txt("insert_after"));
02362                                 $this->tpl->parseCurrentBlock();
02363                         }
02364                         else
02365                         {
02366                                 sendInfo($this->lng->txt("no_question_selected_for_move"));
02367                         }
02368                 }
02369                 
02370                 $query = sprintf("SELECT qpl_questions.*, qpl_question_type.type_tag FROM qpl_questions, qpl_question_type, tst_test_question WHERE qpl_questions.question_type_fi = qpl_question_type.question_type_id AND tst_test_question.test_fi = %s AND tst_test_question.question_fi = qpl_questions.question_id ORDER BY sequence",
02371                         $this->ilias->db->quote($this->object->getTestId())
02372                 );
02373                 $query_result = $this->ilias->db->query($query);
02374                 $colors = array("tblrow1", "tblrow2");
02375                 $counter = 0;
02376                 $questionpools =& $this->object->get_qpl_titles();
02377                 $total = $this->object->evalTotalPersons();
02378                 if ($query_result->numRows() > 0)
02379                 {
02380                         while ($data = $query_result->fetchRow(DB_FETCHMODE_OBJECT))
02381                         {
02382                                 $this->tpl->setCurrentBlock("QTab");
02383                                 $this->tpl->setVariable("QUESTION_ID", $data->question_id);
02384                                 if (($rbacsystem->checkAccess("write", $this->ref_id) and ($total == 0))) {
02385                                         $q_id = $data->question_id;
02386                                         $qpl_ref_id = $this->object->_getRefIdFromObjId($data->obj_fi);
02387                                         $this->tpl->setVariable("QUESTION_TITLE", "<a href=\"" . $this->getCallingScript() . $add_parameter . "&eqid=$q_id&eqpl=$qpl_ref_id" . "\">" . $data->title . "</a>");
02388                                 } else {
02389                                         $this->tpl->setVariable("QUESTION_TITLE", $data->title);
02390                                 }
02391                                 $this->tpl->setVariable("QUESTION_SEQUENCE", $this->lng->txt("tst_sequence"));
02392 
02393                                 if (($rbacsystem->checkAccess("write", $this->ref_id) and ($total == 0))) {
02394                                         if ($data->question_id != $this->object->questions[1])
02395                                         {
02396                                                 $this->tpl->setVariable("BUTTON_UP", "<a href=\"" . $this->ctrl->getFormAction($this) . "&up=$data->question_id\"><img src=\"" . ilUtil::getImagePath("a_up.gif") . "\" alt=\"" . $this->lng->txt("up") . "\" border=\"0\" /></a>");
02397                                         }
02398                                         if ($data->question_id != $this->object->questions[count($this->object->questions)])
02399                                         {
02400                                                 $this->tpl->setVariable("BUTTON_DOWN", "<a href=\"" . $this->ctrl->getFormAction($this) . "&down=$data->question_id\"><img src=\"" . ilUtil::getImagePath("a_down.gif") . "\" alt=\"" . $this->lng->txt("down") . "\" border=\"0\" /></a>");
02401                                         }
02402                                 }
02403                                 $this->tpl->setVariable("QUESTION_COMMENT", $data->comment);
02404                                 $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt($data->type_tag));
02405                                 $this->tpl->setVariable("QUESTION_AUTHOR", $data->author);
02406                                 $this->tpl->setVariable("QUESTION_POOL", $questionpools[$data->obj_fi]);
02407                                 $this->tpl->setVariable("COLOR_CLASS", $colors[$counter % 2]);
02408                                 $this->tpl->parseCurrentBlock();
02409                                 $counter++;
02410                         }
02411                 }
02412                 if ($counter == 0) {
02413                         $this->tpl->setCurrentBlock("Emptytable");
02414                         $this->tpl->setVariable("TEXT_EMPTYTABLE", $this->lng->txt("tst_no_questions_available"));
02415                         $this->tpl->parseCurrentBlock();
02416                 } else {
02417                         if (($rbacsystem->checkAccess("write", $this->ref_id) and ($total == 0))) {
02418                                 $this->tpl->setCurrentBlock("QFooter");
02419                                 $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"\">");
02420                                 $this->tpl->setVariable("REMOVE", $this->lng->txt("remove_question"));
02421                                 $this->tpl->setVariable("MOVE", $this->lng->txt("move"));
02422                                 $this->tpl->parseCurrentBlock();
02423                         }
02424                 }
02425 
02426                 if (($rbacsystem->checkAccess("write", $this->ref_id) and ($total == 0))) {
02427                         $this->tpl->setCurrentBlock("QTypes");
02428                         $query = "SELECT * FROM qpl_question_type";
02429                         $query_result = $this->ilias->db->query($query);
02430                         while ($data = $query_result->fetchRow(DB_FETCHMODE_OBJECT))
02431                         {
02432                                 $this->tpl->setVariable("QUESTION_TYPE_ID", $data->type_tag);
02433                                 $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt($data->type_tag));
02434                                 $this->tpl->parseCurrentBlock();
02435                         }
02436                         $this->tpl->parseCurrentBlock();
02437                 }
02438                 $this->tpl->setCurrentBlock("adm_content");
02439                 $this->tpl->setVariable("ACTION_QUESTION_FORM", $this->ctrl->getFormAction($this));
02440                 $this->tpl->setVariable("QUESTION_TITLE", $this->lng->txt("tst_question_title"));
02441                 $this->tpl->setVariable("QUESTION_COMMENT", $this->lng->txt("description"));
02442                 $this->tpl->setVariable("QUESTION_TYPE", $this->lng->txt("tst_question_type"));
02443                 $this->tpl->setVariable("QUESTION_AUTHOR", $this->lng->txt("author"));
02444                 $this->tpl->setVariable("QUESTION_POOL", $this->lng->txt("qpl"));
02445 
02446                 if (($rbacsystem->checkAccess("write", $this->ref_id) and ($total == 0))) {
02447                         $this->tpl->setVariable("BUTTON_INSERT_QUESTION", $this->lng->txt("tst_browse_for_questions"));
02448                         $this->tpl->setVariable("TEXT_CREATE_NEW", " " . strtolower($this->lng->txt("or")) . " " . $this->lng->txt("create_new"));
02449                         $this->tpl->setVariable("BUTTON_CREATE_QUESTION", $this->lng->txt("create"));
02450                         $this->tpl->setVariable("TXT_OR", $this->lng->txt("or"));
02451                         $this->tpl->setVariable("TEXT_RANDOM_SELECT", $this->lng->txt("random_selection"));
02452                 }
02453 
02454                 $this->tpl->parseCurrentBlock();
02455         }
02456 
02457         function takenObject() {
02458         }
02459         
02467         function addMarkStepObject()
02468         {
02469                 $this->saveMarkSchemaFormData();
02470                 $this->object->mark_schema->add_mark_step();
02471                 $this->marksObject();
02472         }
02473 
02481         function saveMarkSchemaFormData()
02482         {
02483                 $this->object->mark_schema->flush();
02484                 foreach ($_POST as $key => $value) {
02485                         if (preg_match("/mark_short_(\d+)/", $key, $matches)) {
02486                                 $this->object->mark_schema->add_mark_step($_POST["mark_short_$matches[1]"], $_POST["mark_official_$matches[1]"], $_POST["mark_percentage_$matches[1]"], $_POST["passed_$matches[1]"]);
02487                         }
02488                 }
02489                 $this->object->ects_grades["A"] = $_POST["ects_grade_a"];
02490                 $this->object->ects_grades["B"] = $_POST["ects_grade_b"];
02491                 $this->object->ects_grades["C"] = $_POST["ects_grade_c"];
02492                 $this->object->ects_grades["D"] = $_POST["ects_grade_d"];
02493                 $this->object->ects_grades["E"] = $_POST["ects_grade_e"];
02494                 if ($_POST["chbUseFX"])
02495                 {
02496                         $this->object->ects_fx = $_POST["percentFX"];
02497                 }
02498                 else
02499                 {
02500                         $this->object->ects_fx = "";
02501                 }
02502                 $this->object->ects_output = $_POST["chbECTS"];
02503         }
02504         
02512         function addSimpleMarkSchemaObject()
02513         {
02514                 $this->object->mark_schema->create_simple_schema($this->lng->txt("failed_short"), $this->lng->txt("failed_official"), 0, 0, $this->lng->txt("passed_short"), $this->lng->txt("passed_official"), 50, 1);
02515                 $this->marksObject();
02516         }
02517         
02525         function deleteMarkStepsObject()
02526         {
02527                 $this->saveMarkSchemaFormData();
02528                 $delete_mark_steps = array();
02529                 foreach ($_POST as $key => $value) {
02530                         if (preg_match("/cb_(\d+)/", $key, $matches)) {
02531                                 array_push($delete_mark_steps, $matches[1]);
02532                         }
02533                 }
02534                 if (count($delete_mark_steps)) {
02535                         $this->object->mark_schema->delete_mark_steps($delete_mark_steps);
02536                 } else {
02537                         sendInfo($this->lng->txt("tst_delete_missing_mark"));
02538                 }
02539                 $this->marksObject();
02540         }
02541 
02549         function cancelMarksObject()
02550         {
02551                 sendInfo($this->lng->txt("msg_cancel"), true);
02552                 $this->ctrl->redirect($this, "properties");
02553         }
02554         
02562         function saveMarksObject()
02563         {
02564                 $this->saveMarkSchemaFormData();
02565                 
02566                 $mark_check = $this->object->checkMarks();
02567                 if ($mark_check !== true)
02568                 {
02569                         sendInfo($this->lng->txt($mark_check));
02570                 }
02571                 elseif ($_POST["chbECTS"] && ((strcmp($_POST["ects_grade_a"], "") == 0) or (strcmp($_POST["ects_grade_b"], "") == 0) or (strcmp($_POST["ects_grade_c"], "") == 0) or (strcmp($_POST["ects_grade_d"], "") == 0) or (strcmp($_POST["ects_grade_e"], "") == 0)))
02572                 {
02573                         sendInfo($this->lng->txt("ects_fill_out_all_values"), true);
02574                 }
02575                 elseif (($_POST["ects_grade_a"] > 100) or ($_POST["ects_grade_a"] < 0))
02576                 {
02577                         sendInfo($this->lng->txt("ects_range_error_a"), true);
02578                 }
02579                 elseif (($_POST["ects_grade_b"] > 100) or ($_POST["ects_grade_b"] < 0))
02580                 {
02581                         sendInfo($this->lng->txt("ects_range_error_b"), true);
02582                 }
02583                 elseif (($_POST["ects_grade_c"] > 100) or ($_POST["ects_grade_c"] < 0))
02584                 {
02585                         sendInfo($this->lng->txt("ects_range_error_c"), true);
02586                 }
02587                 elseif (($_POST["ects_grade_d"] > 100) or ($_POST["ects_grade_d"] < 0))
02588                 {
02589                         sendInfo($this->lng->txt("ects_range_error_d"), true);
02590                 }
02591                 elseif (($_POST["ects_grade_e"] > 100) or ($_POST["ects_grade_e"] < 0))
02592                 {
02593                         sendInfo($this->lng->txt("ects_range_error_e"), true);
02594                 }
02595                 else 
02596                 {
02597                         $this->object->mark_schema->saveToDb($this->object->getTestId());
02598                         $this->object->saveCompleteStatus();
02599                         if ($this->object->getReportingDate())
02600                         {
02601                                 $fxpercent = "";
02602                                 if ($_POST["chbUseFX"])
02603                                 {
02604                                         $fxpercent = ilUtil::stripSlashes($_POST["percentFX"]);
02605                                 }
02606                                 $this->object->saveECTSStatus($_POST["chbECTS"], $fxpercent, $this->object->ects_grades["A"], $this->object->ects_grades["B"], $this->object->ects_grades["C"], $this->object->ects_grades["D"], $this->object->ects_grades["E"]);
02607                         }
02608                         sendInfo($this->lng->txt("msg_obj_modified"), true);
02609                 }
02610                 $this->marksObject();
02611         }
02612         
02613         function marksObject() {
02614                 global $rbacsystem;
02615 
02616                 if ((!$rbacsystem->checkAccess("read", $this->ref_id)) && (!$rbacsystem->checkAccess("write", $this->ref_id))) 
02617                 {
02618                         // allow only read and write access
02619                         sendInfo($this->lng->txt("cannot_edit_test"), true);
02620                         $path = $this->tree->getPathFull($this->object->getRefID());
02621                         ilUtil::redirect($this->getReturnLocation("cancel","../repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
02622                         return;
02623                 }
02624 
02625                 $this->object->mark_schema->sort();
02626         
02627                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_marks.html", true);
02628                 $marks = $this->object->mark_schema->mark_steps;
02629                 $rows = array("tblrow1", "tblrow2");
02630                 $counter = 0;
02631                 foreach ($marks as $key => $value) {
02632                         $this->tpl->setCurrentBlock("markrow");
02633                         $this->tpl->setVariable("MARK_SHORT", $value->get_short_name());
02634                         $this->tpl->setVariable("MARK_OFFICIAL", $value->get_official_name());
02635                         $this->tpl->setVariable("MARK_PERCENTAGE", sprintf("%.2f", $value->get_minimum_level()));
02636                         $this->tpl->setVariable("MARK_PASSED", strtolower($this->lng->txt("tst_mark_passed")));
02637                         $this->tpl->setVariable("MARK_ID", "$key");
02638                         $this->tpl->setVariable("ROW_CLASS", $rows[$counter % 2]);
02639                         if ($value->get_passed()) {
02640                                 $this->tpl->setVariable("MARK_PASSED_CHECKED", " checked=\"checked\"");
02641                         }
02642                         $this->tpl->parseCurrentBlock();
02643                         $counter++;
02644                 }
02645                 if (count($marks) == 0) {
02646                         $this->tpl->setCurrentBlock("Emptyrow");
02647                         $this->tpl->setVariable("EMPTY_ROW", $this->lng->txt("tst_no_marks_defined"));
02648                         $this->tpl->setVariable("ROW_CLASS", $rows[$counter % 2]);
02649                         $this->tpl->parseCurrentBlock();
02650                 } else {
02651                         if ($rbacsystem->checkAccess("write", $this->ref_id)) {
02652                                 $this->tpl->setCurrentBlock("Footer");
02653                                 $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"\">");
02654                                 $this->tpl->setVariable("BUTTON_EDIT", $this->lng->txt("edit"));
02655                                 $this->tpl->setVariable("BUTTON_DELETE", $this->lng->txt("delete"));
02656                                 $this->tpl->parseCurrentBlock();
02657                         }
02658                 }
02659                 
02660                 if ($this->object->getReportingDate())
02661                 {
02662                         $this->tpl->setCurrentBlock("ects");
02663                         if ($this->object->ects_output)
02664                         {
02665                                 $this->tpl->setVariable("CHECKED_ECTS", " checked=\"checked\"");
02666                         }
02667                         $this->tpl->setVariable("TEXT_OUTPUT_ECTS_GRADES", $this->lng->txt("ects_output_of_ects_grades"));
02668                         $this->tpl->setVariable("TEXT_ALLOW_ECTS_GRADES", $this->lng->txt("ects_allow_ects_grades"));
02669                         $this->tpl->setVariable("TEXT_USE_FX", $this->lng->txt("ects_use_fx_grade"));
02670                         if (preg_match("/\d+/", $this->object->ects_fx))
02671                         {
02672                                 $this->tpl->setVariable("CHECKED_FX", " checked=\"checked\"");
02673                                 $this->tpl->setVariable("VALUE_PERCENT_FX", sprintf("value=\"%s\" ", $this->object->ects_fx));
02674                         }
02675                         $this->tpl->setVariable("TEXT_PERCENT", $this->lng->txt("ects_use_fx_grade_part2"));
02676                         $this->tpl->setVariable("ECTS_GRADE", $this->lng->txt("ects_grade"));
02677                         $this->tpl->setVariable("PERCENTILE", $this->lng->txt("percentile"));
02678                         $this->tpl->setVariable("ECTS_GRADE_A", "A - " . $this->lng->txt("ects_grade_a_short"));
02679                         $this->tpl->setVariable("VALUE_GRADE_A", $this->object->ects_grades["A"]);
02680                         $this->tpl->setVariable("ECTS_GRADE_B", "B - " . $this->lng->txt("ects_grade_b_short"));
02681                         $this->tpl->setVariable("VALUE_GRADE_B", $this->object->ects_grades["B"]);
02682                         $this->tpl->setVariable("ECTS_GRADE_C", "C - " . $this->lng->txt("ects_grade_c_short"));
02683                         $this->tpl->setVariable("VALUE_GRADE_C", $this->object->ects_grades["C"]);
02684                         $this->tpl->setVariable("ECTS_GRADE_D", "D - " . $this->lng->txt("ects_grade_d_short"));
02685                         $this->tpl->setVariable("VALUE_GRADE_D", $this->object->ects_grades["D"]);
02686                         $this->tpl->setVariable("ECTS_GRADE_E", "E - " . $this->lng->txt("ects_grade_e_short"));
02687                         $this->tpl->setVariable("VALUE_GRADE_E", $this->object->ects_grades["E"]);
02688                         
02689                         $this->tpl->parseCurrentBlock();
02690                 }
02691 
02692                 $this->tpl->setCurrentBlock("adm_content");
02693                 $this->tpl->setVariable("ACTION_MARKS", $this->ctrl->getFormAction($this));
02694                 $this->tpl->setVariable("HEADER_SHORT", $this->lng->txt("tst_mark_short_form"));
02695                 $this->tpl->setVariable("HEADER_OFFICIAL", $this->lng->txt("tst_mark_official_form"));
02696                 $this->tpl->setVariable("HEADER_PERCENTAGE", $this->lng->txt("tst_mark_minimum_level"));
02697                 $this->tpl->setVariable("HEADER_PASSED", $this->lng->txt("tst_mark_passed"));
02698                 if ($rbacsystem->checkAccess("write", $this->ref_id)) {
02699                         $this->tpl->setVariable("BUTTON_NEW", $this->lng->txt("tst_mark_create_new_mark_step"));
02700                         $this->tpl->setVariable("BUTTON_NEW_SIMPLE", $this->lng->txt("tst_mark_create_simple_mark_schema"));
02701                         $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
02702                         $this->tpl->setVariable("CANCEL", $this->lng->txt("cancel"));
02703                 }
02704                 $this->tpl->parseCurrentBlock();
02705         }
02706 
02707         function runObject()
02708         {
02709                 global $ilUser;
02710                 global $rbacsystem;
02711                 $this->tpl->addBlockFile("CONTENT", "content", "tpl.il_as_tst_content.html", true);
02712                 $this->tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");            
02713                 $title = $this->object->getTitle();
02714                 
02715                 $this->createCommandControlObject();
02716                 
02717                 $this->cmdCtrl->prepareRequestVariables();
02718                 
02719                 $this->cmdCtrl->onRunObjectEnter();
02720                 
02721                 // update working time and set saveResult state
02722                 $this->updateWorkingTime();
02723                                         
02724                 
02725                 if (!empty($title))
02726                 {
02727                         $this->tpl->setVariable("HEADER", $title);
02728                 }
02729                 
02730                 if ($_POST["cmd"]["start"] or $_POST["cmd"]["resume"])
02731                         $this->cmdCtrl->handleStartCommands ();
02732                                 
02733 
02734                 $this->setLocator();
02735                                 
02736                 // catch feedback message
02737                 sendInfo();
02738                 
02739                 $this->sequence = $this->cmdCtrl->getSequence();        
02740                 if ($this->cmdCtrl->handleCommands())
02741                         return;
02742 
02743                 // sequence not defined
02744                 if (!$this->sequence)
02745                 {
02746                         // show introduction page
02747                         $this->outIntroductionPage();
02748                         return;
02749                 }
02750                                                         
02751                 if ($this->isMaxProcessingTimeReached())
02752                 {
02753                         $this->maxProcessingTimeReached();
02754                         return;
02755                 }
02756                 
02757                 if ($this->isEndingTimeReached())
02758                 {
02759                         $this->endingTimeReached();
02760                         return;
02761                 }
02762                         
02763                 $user_question_order =& $this->object->getAllQuestionsForActiveUser();
02764                         
02765                 if ($this->sequence <= $this->object->getQuestionCount())
02766                 {
02767                         if ($this->object->getScoreReporting() == REPORT_AFTER_QUESTION)
02768                         {
02769                                 $this->tpl->setCurrentBlock("direct_feedback");
02770                                 $this->tpl->setVariable("TEXT_DIRECT_FEEDBACK", $this->lng->txt("direct_feedback"));
02771                                 $this->tpl->parseCurrentBlock();
02772                         }
02773                         
02774                         // show next/previous question
02775                         $postpone = "";
02776                         if ($_POST["cmd"]["postpone"])
02777                         {
02778                                 $postpone = $this->sequence;
02779                         }
02780 
02781                         $this->object->setActiveTestUser($this->sequence, $postpone);
02782                 
02783                         if ($this->sequence == $this->object->getQuestionCount())
02784                         {
02785                                 $finish = true;
02786                         }
02787                         else
02788                         {
02789                                 $finish = false;
02790                         }
02791 
02792                         $postpone = false;
02793 
02794                         if ($this->object->getSequenceSettings() == TEST_POSTPONE)
02795                         {
02796                                 $postpone = true;
02797                         }
02798 
02799                         $active = $this->object->getActiveTestUser();
02800 
02801                         if(!$_GET['crs_show_result'])
02802                         {
02803                                 $this->outShortResult($user_question_order);
02804                         }
02805                                 
02806                         if ($this->object->getEnableProcessingTime())
02807                         {
02808                                 $this->outProcessingTime();
02809                         }
02810 
02811                         $this->outWorkingForm($this->sequence, $finish, $this->object->getTestId(), $active, $postpone, $user_question_order, $_POST["cmd"]["directfeedback"], $show_summary);
02812 
02813                 }
02814                 else
02815                 {
02816                         $this->finishTest();
02817                 }
02818         }
02819         
02820         function finishTest()
02821         {
02822                 global $ilUser;
02823                 
02824                 // finish test
02825                 if ($_SESSION["tst_next"] != 1)
02826                 {
02827                         $_SESSION["tst_next"] = 1;
02828                         if ($this->object->isOnlineTest() && !$this->object->isActiveTestSubmitted($ilUser->getId())) 
02829                         {
02830                                 $this->outTestSummary();
02831                                 unset($_SESSION["tst_next"]);
02832                                 return;
02833                         }
02834                                 
02835                         $this->object->setActiveTestUser(1, "", true);
02836 
02837                         // Update objectives
02838                         include_once './course/classes/class.ilCourseObjectiveResult.php';
02839 
02840                         $tmp_obj_res =& new ilCourseObjectiveResult($ilUser->getId());
02841                         $tmp_obj_res->updateResults($this->object->getTestResult($ilUser->getId()));
02842                         if($_GET['crs_show_result'])
02843                         {
02844                                 unset($_SESSION["tst_next"]);
02845                                 ilUtil::redirect($this->getReturnLocation("cancel","../repository.php?ref_id=".(int) $_GET['crs_show_result']));
02846                         }
02847                         
02848                         if (!$this->object->canViewResults()) 
02849                         {
02850                                 unset($_SESSION["tst_next"]);
02851                                 $this->ctrl->redirect($this, "run");
02852                                 //$this->outIntroductionPage($maxprocessingtimereached);
02853                         }
02854                         else
02855                         {                                       
02856                                 unset($_SESSION["tst_next"]);
02857                                 $this->ctrl->redirect($this, "outTestResults");
02858                                 //$this->outTestResults();
02859                         }
02860                         unset($_SESSION["tst_next"]);
02861                 }
02862         }
02863 
02864         function outTestResultsObject()
02865         {
02866                 $this->outTestResults();
02867         }
02868         
02869         function outIntroductionPageObject()
02870         {
02871                 $this->outIntroductionPage();
02872         }
02873         
02881         function outIntroductionPage()
02882         {
02883                 global $ilUser;
02884                 // todo: max_processing_reached
02885                 
02886                 unset($_SESSION["tst_next"]);
02887                 $maxprocessingtimereached = $this->isMaxProcessingTimeReached();
02888 
02889                 $add_parameter = $this->getAddParameter();
02890                 $active = $this->object->getActiveTestUser();
02891                 
02892                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_introduction.html", true);
02893                 $this->tpl->setCurrentBlock("info_row");
02894                 $this->tpl->setVariable("TEXT_INFO_COL1", $this->lng->txt("tst_type") . ":");
02895                 $this->tpl->setVariable("TEXT_INFO_COL2", $this->lng->txt($this->object->test_types[$this->object->getTestType()]));
02896                 $this->tpl->parseCurrentBlock();
02897                 $this->tpl->setVariable("TEXT_INFO_COL1", $this->lng->txt("description") . ":");
02898                 $this->tpl->setVariable("TEXT_INFO_COL2", $this->object->getDescription());
02899                 $this->tpl->parseCurrentBlock();
02900                 $this->tpl->setVariable("TEXT_INFO_COL1", $this->lng->txt("tst_sequence") . ":");
02901                 $this->tpl->setVariable("TEXT_INFO_COL2", $this->lng->txt(($this->object->getSequenceSettings() == TEST_FIXED_SEQUENCE)? "tst_sequence_fixed":"tst_sequence_postpone"));
02902                 $this->tpl->parseCurrentBlock();
02903                 $this->tpl->setVariable("TEXT_INFO_COL1", $this->lng->txt("tst_score_reporting") . ":");
02904                 $this->tpl->setVariable("TEXT_INFO_COL2", $this->lng->txt(($this->object->getScoreReporting() == REPORT_AFTER_QUESTION)?"tst_report_after_question":"tst_report_after_test"));
02905                 $this->tpl->parseCurrentBlock();
02906                 $this->tpl->setVariable("TEXT_INFO_COL1", $this->lng->txt("tst_count_partial_solutions") . ":");
02907                 if ($this->object->getCountSystem() == COUNT_PARTIAL_SOLUTIONS)
02908                 {
02909                         $this->tpl->setVariable("TEXT_INFO_COL2", $this->lng->txt("tst_count_partial_solutions"));
02910                 }
02911                 else
02912                 {
02913                         $this->tpl->setVariable("TEXT_INFO_COL2", $this->lng->txt("tst_count_correct_solutions"));
02914                 }
02915                 $this->tpl->parseCurrentBlock();
02916                 $this->tpl->setVariable("TEXT_INFO_COL1", $this->lng->txt("tst_score_mcmr_questions") . ":");
02917                 if ($this->object->getMCScoring() == SCORE_ZERO_POINTS_WHEN_UNANSWERED)
02918                 {
02919                         $this->tpl->setVariable("TEXT_INFO_COL2", $this->lng->txt("tst_score_mcmr_zero_points_when_unanswered"));
02920                 }
02921                 else
02922                 {
02923                         $this->tpl->setVariable("TEXT_INFO_COL2", $this->lng->txt("tst_score_mcmr_use_scoring_system"));
02924                 }
02925                 $this->tpl->parseCurrentBlock();
02926                 $this->tpl->setVariable("TEXT_INFO_COL1", $this->lng->txt("tst_nr_of_tries") . ":");
02927 
02928                 $num_of = $this->object->getNrOfTries();
02929                 if (!$num_of) {
02930                         $num_of = $this->lng->txt("unlimited");
02931                 }
02932                 $this->tpl->setVariable("TEXT_INFO_COL2", $num_of);
02933                 $this->tpl->parseCurrentBlock();
02934 
02935                 if ($num_of != 1)
02936                 {
02937                         // display number of tries of the user
02938                         $this->tpl->setVariable("TEXT_INFO_COL1", $this->lng->txt("tst_nr_of_tries_of_user") . ":");
02939                         $tries = $active->tries;
02940                         if (!$tries)
02941                         {
02942                                 $tries = $this->lng->txt("tst_no_tries");
02943                         }
02944                         $this->tpl->setVariable("TEXT_INFO_COL2", $tries);
02945                         $this->tpl->parseCurrentBlock();
02946                 }
02947 
02948                 if ($this->object->getEnableProcessingTime())
02949                 {
02950                         $working_time = $this->object->getCompleteWorkingTime($ilUser->id);
02951                         $processing_time = $this->object->getProcessingTimeInSeconds();
02952                         $this->tpl->setVariable("TEXT_INFO_COL1", $this->lng->txt("tst_processing_time") . ":");
02953                         $time_seconds = $processing_time;
02954                         $time_hours    = floor($time_seconds/3600);
02955                         $time_seconds -= $time_hours   * 3600;
02956                         $time_minutes  = floor($time_seconds/60);
02957                         $time_seconds -= $time_minutes * 60;
02958                         $this->tpl->setVariable("TEXT_INFO_COL2", sprintf("%02d:%02d:%02d", $time_hours, $time_minutes, $time_seconds));
02959                         $this->tpl->parseCurrentBlock();
02960                 }
02961 
02962                 if ($this->object->getStartingTime())
02963                 {
02964                         $this->tpl->setVariable("TEXT_INFO_COL1", $this->lng->txt("tst_starting_time") . ":");
02965                         $this->tpl->setVariable("TEXT_INFO_COL2", ilFormat::formatDate(ilFormat::ftimestamp2datetimeDB($this->object->getStartingTime())));
02966                         $this->tpl->parseCurrentBlock();
02967                 }
02968                 if ($this->object->getEndingTime())
02969                 {
02970                         $this->tpl->setVariable("TEXT_INFO_COL1", $this->lng->txt("tst_ending_time") . ":");
02971                         $this->tpl->setVariable("TEXT_INFO_COL2", ilFormat::formatDate(ilFormat::ftimestamp2datetimeDB($this->object->getEndingTime())));
02972                         $this->tpl->parseCurrentBlock();
02973                 }
02974 
02975                 $this->tpl->setCurrentBlock("info");
02976                 $this->tpl->setVariable("TEXT_USE_JAVASCRIPT", $this->lng->txt("tst_use_javascript"));
02977                 if ($ilUser->prefs["tst_javascript"])
02978                 {
02979                         $this->tpl->setVariable("CHECKED_JAVASCRIPT", "checked=\"checked\" ");
02980                 }
02981                 $this->tpl->parseCurrentBlock();
02982                 $seq = 1;
02983                 if ($active) {
02984                         $seq = $active->lastindex;
02985                 }
02986                 $add_sequence = "&sequence=$seq";
02987 
02988                 if($this->cmdCtrl->showTestResults())
02989                 {
02990                         $first_seq = $this->object->getFirstSequence();
02991                         $add_sequence = "&sequence=".$first_seq;
02992 
02993                         if(!$first_seq)
02994                         {
02995                                 sendInfo($this->lng->txt('crs_all_questions_answered_successfully'));
02996                         }
02997                 }
02998                                 
02999                 // from here we have test type specific handling
03000                 
03001                 $test_disabled = !$this->cmdCtrl->isTestAccessible();
03002                 
03003                 if ($test_disabled) {
03004                         $add_sequence = "";
03005                 }
03006                 
03007                 if ($this->cmdCtrl->isTestResumable() && $this->cmdCtrl->isTestAccessible()){
03008                         // RESUME BLOCK 
03009                         $this->tpl->setCurrentBlock("resume");
03010                         if ($seq == 1)
03011                         {
03012                                 if(!$this->cmdCtrl->showTestResults() or $first_seq)
03013                                 {
03014                                         $this->tpl->setVariable("BTN_RESUME", $this->lng->txt("tst_start_test"));
03015                                 }
03016                         }
03017                         else
03018                         {
03019                                 $this->tpl->setVariable("BTN_RESUME", $this->lng->txt("tst_resume_test"));
03020                         }
03021                         
03022                         // disable resume button
03023                         if ($test_disabled) {
03024                                 $this->tpl->setVariable("DISABLED", " disabled");
03025                         }
03026                         $this->tpl->parseCurrentBlock();
03027                 } else {
03028                 // Start a new Test
03029                         if ($this->cmdCtrl->isTestAccessible()// ($this->object->startingTimeReached() and !$this->object->endingTimeReached()) 
03030                                                 //or ($this->object->getTestType() != TYPE_ASSESSMENT and !$this->object->isOnlineTest())
03031                                         )
03032                         {
03033                                 $this->tpl->setCurrentBlock("start");
03034                                 $this->tpl->setVariable("BTN_START", $this->lng->txt("tst_start_test"));
03035                                 if (!$this->object->isComplete())
03036                                 {
03037                                         $this->tpl->setVariable("DISABLED", " disabled=\"disabled\"");
03038                                         $test_disabled = true;
03039                                 }
03040                                 $this->tpl->parseCurrentBlock();
03041                         }                                                       
03042                 }
03043                                                 
03044                 // we have results
03045                 if ($active && $active->tries > 0) {
03046                         // DELETE RESULTS only available for non Online Exams
03047                         if (!$this->object->isOnlineTest())
03048                         {
03049                                 // if resume is active it is possible to reset the test
03050                                 $this->tpl->setCurrentBlock("delete_results");
03051                                 $this->tpl->setVariable("BTN_DELETERESULTS", $this->lng->txt("tst_delete_results"));
03052                                 $this->tpl->parseCurrentBlock();
03053                         }                       
03054                                                 
03055                         // RESULT BLOCK if we can show result because we have data
03056                         if ($this->cmdCtrl->canShowTestResults()) {
03057                                 $this->tpl->setCurrentBlock("results");
03058                                 $this->tpl->setVariable("BTN_RESULTS", $this->lng->txt("tst_show_results"));                            
03059                                 $this->tpl->parseCurrentBlock();
03060                         }
03061                         
03062                         // Show results in a new print frame
03063                         if ($this->object->isActiveTestSubmitted()) {
03064                                 $add_parameter2 = "?ref_id=" . $_GET["ref_id"];
03065                                 $this->tpl->setCurrentBlock("show_printview");
03066                                 $this->tpl->setVariable("BTN_ANSWERS", $this->lng->txt("tst_show_answer_print_sheet")); 
03067                                 $this->tpl->setVariable("PRINT_VIEW_HREF", $this->getCallingScript (). $add_parameter2. "&cmd=answersheet");                            
03068                                 $this->tpl->parseCurrentBlock();                                
03069                         }                       
03070                                                 
03071                         // Result Date not reached
03072                         if (!$this->cmdCtrl->canShowTestResults()) {
03073                                         $this->tpl->setCurrentBlock("report_date_not_reached");
03074                                         preg_match("/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/", $this->object->getReportingDate(), $matches);
03075                                         $reporting_date = date($this->lng->text["lang_dateformat"] . " " . $this->lng->text["lang_timeformat"], mktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]));
03076                                         $this->tpl->setVariable("RESULT_DATE_NOT_REACHED", sprintf($this->lng->txt("report_date_not_reached"), $reporting_date));
03077                                         $this->tpl->parseCurrentBlock();
03078                                 }
03079                         
03083                         if ($this->object->isOnlineTest() and $test_disabled) {
03084                                 if (!$this->object->isActiveTestSubmitted($ilUser->getId())) {
03085                                         $this->tpl->setCurrentBlock("show_summary");                            
03086                                         $this->tpl->setVariable("BTN_SUMMARY", $this->lng->txt("save_finish"));
03087                                         $this->tpl->parseCurrentBlock();
03088                                 } else {
03089                                         sendInfo($this->lng->txt("tst_already_submitted"));                                     
03090                                 }
03091                         }                       
03092                 }
03093                 
03094 
03095                 $this->tpl->setCurrentBlock("adm_content");
03096 
03097                 // test is disabled
03098                 if ($test_disabled)
03099                 {
03100                         if (!$this->object->startingTimeReached() or $this->object->endingTimeReached())
03101                         {
03102                                 $this->tpl->setCurrentBlock("startingtime");
03103                                 $this->tpl->setVariable("IMAGE_STARTING_TIME", ilUtil::getImagePath("time.gif", true));
03104                         
03105                                 if (!$this->object->startingTimeReached())
03106                                 {
03107                                         $this->tpl->setVariable("ALT_STARTING_TIME_NOT_REACHED", $this->lng->txt("starting_time_not_reached"));
03108                                         $this->tpl->setVariable("TEXT_STARTING_TIME_NOT_REACHED", sprintf($this->lng->txt("detail_starting_time_not_reached"), ilFormat::ftimestamp2datetimeDB($this->object->getStartingTime())));
03109                                 }
03110                                 else
03111                                 {
03112                                         $this->tpl->setVariable("ALT_STARTING_TIME_NOT_REACHED", $this->lng->txt("ending_time_reached"));
03113                                         $this->tpl->setVariable("TEXT_STARTING_TIME_NOT_REACHED", sprintf($this->lng->txt("detail_ending_time_reached"), ilFormat::ftimestamp2datetimeDB($this->object->getEndingTime())));
03114                                 }
03115                                 $this->tpl->parseCurrentBlock();
03116                         }
03117                         
03118                         if ($this->cmdCtrl->isNrOfTriesReached())                               
03119                         {
03120                                 $this->tpl->setVariable("MAXIMUM_NUMBER_OF_TRIES_REACHED", $this->lng->txt("maximum_nr_of_tries_reached"));
03121                         }
03122                         if ($this->isMaxProcessingTimeReached())
03123                         {
03124                                 sendInfo($this->lng->txt("detail_max_processing_time_reached"));                                        
03125                         }                               
03126                         if (!$this->object->isComplete())
03127                         {
03128                                 sendInfo($this->lng->txt("warning_test_not_complete"));
03129                         }
03130                 }               
03131                 $introduction = $this->object->getIntroduction();
03132                 $introduction = preg_replace("/\n/i", "<br />", $introduction);
03133                 $this->tpl->setVariable("TEXT_INTRODUCTION", $introduction);
03134                 $this->tpl->setVariable("FORMACTION", $this->getCallingScript() . "$add_parameter$add_sequence");
03135                 $this->tpl->parseCurrentBlock();
03136         }
03137         
03145         function outWorkingForm($sequence = 1, $finish = false, $test_id, $active, $postpone_allowed, $user_question_order, $directfeedback = 0)
03146         {
03147                 global $ilUser;
03148                 
03149                 include_once("classes/class.ilObjStyleSheet.php");
03150                 $this->tpl->setCurrentBlock("ContentStyle");
03151                 $this->tpl->setVariable("LOCATION_CONTENT_STYLESHEET",
03152                 ilObjStyleSheet::getContentStylePath(0));
03153                 $this->tpl->parseCurrentBlock();
03154 
03155                 // syntax style
03156                 $this->tpl->setCurrentBlock("SyntaxStyle");
03157                 $this->tpl->setVariable("LOCATION_SYNTAX_STYLESHEET",
03158                 ilObjStyleSheet::getSyntaxStylePath());
03159                 $this->tpl->parseCurrentBlock();
03160                 
03161                 $question_gui = $this->object->createQuestionGUI("", $this->object->getQuestionIdFromActiveUserSequence($sequence));
03162                 if (is_null($question_gui))
03163                 {
03164                         $questioncount = $this->object->getQuestionCount();
03165                         while ((($sequence + 1) < $questioncount) && (is_null($question_gui)))
03166                         {
03167                                 $sequence += 1;
03168                                 $question_gui = $this->object->createQuestionGUI("", $this->object->getQuestionIdFromActiveUserSequence($sequence));
03169                         }
03170                         if (is_null($question_gui))
03171                         {
03172                                 // no more questions found -> finish the test
03173                                 $this->object->setActiveTestUser($questioncount);
03174                                 return $this->finishTest();
03175                         }
03176                 }
03177                 if ($ilUser->prefs["tst_javascript"])
03178                 {
03179                         $question_gui->object->setOutputType(OUTPUT_JAVASCRIPT);
03180                 }
03181                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_preview.html", true);
03182 
03183                 $is_postponed = false;
03184                 if (is_object($active))
03185                 {                       
03186                         if (!preg_match("/(^|\D)" . $question_gui->object->getId() . "($|\D)/", $active->postponed) and 
03187                                 !($active->postponed == $question_gui->object->getId()))
03188                         {
03189                                 $is_postponed = false;
03190                         }
03191                         else
03192                         {
03193                                 $is_postponed = true;
03194                         }
03195                 }
03196 
03197                 $formaction = $this->getCallingScript() . $this->getAddParameter() . "&sequence=$sequence";
03198                 $question_gui->setSequenceNumber ($sequence);
03199                                 
03200                 // output question
03201                 switch ($question_gui->getQuestionType())
03202                 {
03203                         case "qt_imagemap":
03204                                 $question_gui->outWorkingForm($test_id, $is_postponed, $directfeedback, $formaction, true);
03205                                 $info =& $question_gui->object->getReachedInformation($ilUser->id, $test_id);
03206                                 if (strcmp($info[0]["value"], "") != 0)
03207                                 {
03208                                         $formaction .= "&selImage=" . $info[0]["value"];
03209                                 }
03210                                 break;
03211 
03212                         default:
03213                                 $question_gui->outWorkingForm($test_id, $is_postponed, $directfeedback);
03214                                 break;
03215                 }
03216 
03217                 if(!$_GET['crs_show_result'])
03218                 {
03219                         if ($sequence == 1)
03220                         {
03221                                 $this->tpl->setCurrentBlock("prev");
03222                                 $this->tpl->setVariable("BTN_PREV", "&lt;&lt; " . $this->lng->txt("save_introduction"));
03223                                 $this->tpl->parseCurrentBlock();
03224                                 $this->tpl->setCurrentBlock("prev_bottom");
03225                                 $this->tpl->setVariable("BTN_PREV", "&lt;&lt; " . $this->lng->txt("save_introduction"));
03226                                 $this->tpl->parseCurrentBlock();
03227                         }
03228                         else
03229                         {
03230                                 $this->tpl->setCurrentBlock("prev");
03231                                 $this->tpl->setVariable("BTN_PREV", "&lt;&lt; " . $this->lng->txt("save_previous"));
03232                                 $this->tpl->parseCurrentBlock();
03233                                 $this->tpl->setCurrentBlock("prev_bottom");
03234                                 $this->tpl->setVariable("BTN_PREV", "&lt;&lt; " . $this->lng->txt("save_previous"));
03235                                 $this->tpl->parseCurrentBlock();
03236                         }
03237                 }
03238 
03239                 if ($postpone_allowed)
03240                 {
03241                         if (!$is_postponed)
03242                         {
03243                                 $this->tpl->setCurrentBlock("postpone");
03244                                 $this->tpl->setVariable("BTN_POSTPONE", $this->lng->txt("postpone"));
03245                                 $this->tpl->parseCurrentBlock();
03246                                 $this->tpl->setCurrentBlock("postpone_bottom");
03247                                 $this->tpl->setVariable("BTN_POSTPONE", $this->lng->txt("postpone"));
03248                                 $this->tpl->parseCurrentBlock();
03249                         }
03250                 }
03251                 
03252                 if ($this->object->isOnlineTest() && !$finish) {
03253                         $this->tpl->setCurrentBlock("summary");
03254                         $this->tpl->setVariable("BTN_SUMMARY", $this->lng->txt("summary"));
03255                         $this->tpl->parseCurrentBlock();
03256                         $this->tpl->setCurrentBlock("summary_bottom");
03257                         $this->tpl->setVariable("BTN_SUMMARY", $this->lng->txt("summary"));
03258                         $this->tpl->parseCurrentBlock();
03259                 }
03260 
03261                 if (!$this->object->isOnlineTest()) {
03262                         $this->tpl->setCurrentBlock("cancel_test");
03263                         $this->tpl->setVariable("TEXT_CANCELTEST", $this->lng->txt("cancel_test"));
03264                         $this->tpl->setVariable("TEXT_ALTCANCELTEXT", $this->lng->txt("cancel_test"));
03265                         $this->tpl->setVariable("TEXT_TITLECANCELTEXT", $this->lng->txt("cancel_test"));
03266                         $this->tpl->setVariable("HREF_IMGCANCELTEST", $this->ctrl->getLinkTargetByClass(get_class($this), "run") . "&cancelTest=true");
03267                         $this->tpl->setVariable("HREF_CANCELTEXT", $this->ctrl->getLinkTargetByClass(get_class($this), "run") . "&cancelTest=true");
03268                         $this->tpl->setVariable("IMAGE_CANCEL", ilUtil::getImagePath("cancel.png"));
03269                         $this->tpl->parseCurrentBlock();
03270                         $this->tpl->setCurrentBlock("cancel_test_bottom");
03271                         $this->tpl->setVariable("TEXT_CANCELTEST", $this->lng->txt("cancel_test"));
03272                         $this->tpl->setVariable("TEXT_ALTCANCELTEXT", $this->lng->txt("cancel_test"));
03273                         $this->tpl->setVariable("TEXT_TITLECANCELTEXT", $this->lng->txt("cancel_test"));
03274                         $this->tpl->setVariable("HREF_IMGCANCELTEST", $this->ctrl->getLinkTargetByClass(get_class($this), "run") . "&cancelTest=true");
03275                         $this->tpl->setVariable("HREF_CANCELTEXT", $this->ctrl->getLinkTargetByClass(get_class($this), "run") . "&cancelTest=true");
03276                         $this->tpl->setVariable("IMAGE_CANCEL", ilUtil::getImagePath("cancel.png"));
03277                         $this->tpl->parseCurrentBlock();                        
03278                 }               
03279 
03280                 if ($finish)
03281                 {
03282                         if (!$this->object->isOnlineTest()) {
03283                                 $this->tpl->setCurrentBlock("next");
03284                                 $this->tpl->setVariable("BTN_NEXT", $this->lng->txt("save_finish") . " &gt;&gt;");
03285                                 $this->tpl->parseCurrentBlock();
03286                                 $this->tpl->setCurrentBlock("next_bottom");
03287                                 $this->tpl->setVariable("BTN_NEXT", $this->lng->txt("save_finish") . " &gt;&gt;");
03288                                 $this->tpl->parseCurrentBlock();
03289                         } else {
03290                                 $this->tpl->setCurrentBlock("next");
03291                                 $this->tpl->setVariable("BTN_NEXT", $this->lng->txt("summary") . " &gt;&gt;");
03292                                 $this->tpl->parseCurrentBlock();
03293                                 $this->tpl->setCurrentBlock("next_bottom");
03294                                 $this->tpl->setVariable("BTN_NEXT", $this->lng->txt("summary") . " &gt;&gt;");
03295                                 $this->tpl->parseCurrentBlock();                                
03296                         }
03297                 }
03298                 else
03299                 {
03300                         $this->tpl->setCurrentBlock("next");
03301                         $this->tpl->setVariable("BTN_NEXT", $this->lng->txt("save_next") . " &gt;&gt;");
03302                         $this->tpl->parseCurrentBlock();
03303                         $this->tpl->setCurrentBlock("next_bottom");
03304                         $this->tpl->setVariable("BTN_NEXT", $this->lng->txt("save_next") . " &gt;&gt;");
03305                         $this->tpl->parseCurrentBlock();
03306                 }
03307 
03308                 
03309                 
03310                 if ($this->object->isOnlineTest()) {
03311                         $solved_array = ilObjTest::_getSolvedQuestions($this->object->test_id, $ilUser->getId(), $question_gui->object->getId());
03312                         $solved = 0;
03313                         
03314                         if (count ($solved_array) > 0) {
03315                                 $solved = array_pop($solved_array);
03316                                 $solved = $solved->solved;
03317                         }                       
03318                         
03319                         if ($solved==1) 
03320                         {
03321                                 $solved = ilUtil::getImagePath("solved.png", true);
03322                                 $solved_cmd = "resetsolved";
03323                                 $solved_txt = $this->lng->txt("tst_qst_resetsolved");
03324                         } else 
03325                         {                                
03326                                 $solved = ilUtil::getImagePath("not_solved.png", true);
03327                                 $solved_cmd = "setsolved";
03328                                 $solved_txt = $this->lng->txt("tst_qst_setsolved");
03329                         }                       
03330                         $solved = "<input align=\"middle\" border=\"0\" alt=\"".$this->lng->txt("tst_qst_solved_state_click_to_change")."\" name=\"cmd[$solved_cmd]\" type=\"image\" src=\"$solved\">&nbsp;<small>$solved_txt</small>";
03331                         
03332                         $this->tpl->setCurrentBlock("question_status");
03333                         $this->tpl->setVariable("TEXT_QUESTION_STATUS_LABEL", $this->lng->txt("tst_question_solved_state").":");
03334                         $this->tpl->setVariable("TEXT_QUESTION_STATUS", $solved);
03335                         $this->tpl->parseCurrentBlock();                        
03336                 }
03337 
03338                 $this->tpl->setCurrentBlock("adm_content");
03339                 $this->tpl->setVariable("FORMACTION", $formaction);
03340 
03341                 $this->tpl->parseCurrentBlock();
03342         }
03343 
03344         function outEvaluationForm()
03345         {
03346                 global $ilUser;
03347 
03348                 include_once("classes/class.ilObjStyleSheet.php");
03349                 $this->tpl->setCurrentBlock("ContentStyle");
03350                 $this->tpl->setVariable("LOCATION_CONTENT_STYLESHEET", ilObjStyleSheet::getContentStylePath(0));
03351                 $this->tpl->parseCurrentBlock();
03352 
03353                 // syntax style
03354                 $this->tpl->setCurrentBlock("SyntaxStyle");
03355                 $this->tpl->setVariable("LOCATION_SYNTAX_STYLESHEET",
03356                         ilObjStyleSheet::getSyntaxStylePath());
03357                 $this->tpl->parseCurrentBlock();
03358 
03359                 $test_id = $this->object->getTestId();
03360                 $question_gui = $this->object->createQuestionGUI("", $_GET["evaluation"]);
03361 //              $this->tpl->addBlockFile("RESULT_DESCRIPTION", "result_description", "tpl.il_as_tst_result_table.html", true);
03362                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_evaluation.html", true);
03363                 $formaction = $this->getCallingScript() . $this->getAddParameter() . "&sequence=$sequence";
03364                 
03365                 switch ($question_gui->getQuestionType())
03366                 {
03367                         case "qt_imagemap":
03368                                 $question_gui->outWorkingForm($test_id, "", 1, $formaction);
03369                                 break;
03370                         case "qt_javaapplet":
03371                                 $question_gui->outWorkingForm("", "", 0);
03372                                 break;
03373                         default:
03374                                 $question_gui->outWorkingForm($test_id, "", 1);
03375                 }
03376 //              $this->tpl->setCurrentBlock("result_description");
03377 //              $question_gui->outUserSolution($ilUser->id, $this->object->getTestId());
03378                 $this->tpl->setCurrentBlock("adm_content");
03379                 $this->tpl->setVariable("FORMACTION", $this->getCallingScript() . $this->getAddParameter());
03380                 $this->tpl->setVariable("BACKLINK_TEXT", "&lt;&lt; " . $this->lng->txt("back"));
03381                 $this->tpl->parseCurrentBlock();
03382         }
03383 
03391         function outStatSelectedSearchResults()
03392         {
03393                 include_once ("./classes/class.ilSearch.php");
03394                 global $ilUser;
03395                 
03396                 if (is_array($_POST["search_for"]))
03397                 {
03398                         if (in_array("usr", $_POST["search_for"]) or in_array("grp", $_POST["search_for"]))
03399                         {
03400                                 $search =& new ilSearch($ilUser->id);
03401                                 $search->setSearchString($_POST["search_term"]);
03402                                 $search->setCombination($_POST["concatenation"]);
03403                                 $search->setSearchFor($_POST["search_for"]);
03404                                 $search->setSearchType("new");
03405                                 if($search->validate($message))
03406                                 {
03407                                         $search->performSearch();
03408                                 }
03409                                 if ($message)
03410                                 {
03411                                         //sendInfo($message);
03412                                 }
03413                                 if(!$search->getNumberOfResults() && $search->getSearchFor())
03414                                 {
03415                                         sendInfo($this->lng->txt("search_no_match"));
03416                                         return;
03417                                 }
03418                                 $buttons = array("add");
03419                                 $participants =& $this->object->evalTotalPersonsArray();
03420                                 $eval_users = $this->object->getEvaluationUsers($ilUser->id);
03421                                 if ($searchresult = $search->getResultByType("usr"))
03422                                 {
03423                                         $users = array();
03424                                         foreach ($searchresult as $result_array)
03425                                         {
03426                                                 if (!array_key_exists($result_array["id"], $eval_users))
03427                                                 {
03428                                                         if (array_key_exists($result_array["id"], $participants))
03429                                                         {
03430                                                                 $users[$result_array["id"]] = $eval_users[$result_array["id"]];
03431                                                         }
03432                                                 }
03433                                         }
03434                                         $this->outEvalSearchResultTable("usr", $users, "user_result", "user_row", $this->lng->txt("search_found_users"), $buttons);
03435                                 }
03436                                 $searchresult = array();
03437                                 $eval_groups = $this->object->getEvaluationGroups($ilUser->id);
03438                                 if ($searchresult = $search->getResultByType("grp"))
03439                                 {
03440                                         $groups = array();
03441                                         foreach ($searchresult as $result_array)
03442                                         {
03443                                                 if (!in_array($result_array["id"], $eval_groups))
03444                                                 {
03445                                                         include_once("./classes/class.ilObjGroup.php");
03446                                                         $grp = new ilObjGroup($result_array["id"], true);
03447                                                         $members = $grp->getGroupMemberIds();
03448                                                         $found_member = 0;
03449                                                         foreach ($members as $member_id)
03450                                                         {
03451                                                                 if (array_key_exists($member_id, $participants))
03452                                                                 {
03453                                                                         $found_member = 1;
03454                                                                 }
03455                                                         }
03456                                                         if ($found_member)
03457                                                         {
03458                                                                 array_push($groups, $result_array["id"]);
03459                                                         }
03460                                                 }
03461                                         }
03462                                         $this->outEvalSearchResultTable("grp", $groups, "group_result", "group_row", $this->lng->txt("search_found_groups"), $buttons);
03463                                 }
03464                         }
03465                 }
03466                 else
03467                 {
03468                         sendInfo($this->lng->txt("no_user_or_group_selected"));
03469                 }
03470         }
03471         
03479         function addFoundUsersToEvalObject()
03480         {
03481                 global $ilUser;
03482                 if (is_array($_POST["user_select"]))
03483                 {
03484                         foreach ($_POST["user_select"] as $user_id)
03485                         {
03486                                 $this->object->addSelectedUser($user_id, $ilUser->id);
03487                         }
03488                 }
03489                 $this->evalStatSelectedObject();
03490         }
03491         
03499         function removeSelectedUserObject()
03500         {
03501                 global $ilUser;
03502                 if (is_array($_POST["selected_users"]))
03503                 {
03504                         foreach ($_POST["selected_users"] as $user_id)
03505                         {
03506                                 $this->object->removeSelectedUser($user_id, $ilUser->id);
03507                         }
03508                 }
03509                 $this->evalStatSelectedObject();
03510         }
03511         
03519         function removeSelectedGroupObject()
03520         {
03521                 global $ilUser;
03522                 if (is_array($_POST["selected_groups"]))
03523                 {
03524                         foreach ($_POST["selected_groups"] as $group_id)
03525                         {
03526                                 $this->object->removeSelectedGroup($group_id, $ilUser->id);
03527                         }
03528                 }
03529                 $this->evalStatSelectedObject();
03530         }
03531         
03539         function addFoundGroupsToEvalObject()
03540         {
03541                 global $ilUser;
03542                 if (is_array($_POST["group_select"]))
03543                 {
03544                         foreach ($_POST["group_select"] as $group_id)
03545                         {
03546                                 $this->object->addSelectedGroup($group_id, $ilUser->id);
03547                         }
03548                 }
03549                 $this->evalStatSelectedObject();
03550         }
03551         
03559         function searchForEvaluationObject()
03560         {
03561                 $this->evalStatSelectedObject(1);
03562         }
03563         
03571         function evalStatSelectedObject($search = 0)
03572         {
03573                 global $ilUser;
03574                 
03575                 $this->ctrl->setCmd("evalStatSelected");
03576                 $this->setEvaluationSettingsTabs();
03577                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_eval_statistical_evaluation_selection.html", true);
03578                 if ($search)
03579                 {
03580                         $this->outStatSelectedSearchResults();
03581                 }
03582                 $this->tpl->setCurrentBlock("userselection");
03583                 $this->tpl->setVariable("SEARCH_USERSELECTION", $this->lng->txt("eval_search_userselection"));
03584                 $this->tpl->setVariable("SEARCH_TERM", $this->lng->txt("eval_search_term"));
03585                 $this->tpl->setVariable("SEARCH_FOR", $this->lng->txt("search_for"));
03586                 $this->tpl->setVariable("SEARCH_USERS", $this->lng->txt("eval_search_users"));
03587                 $this->tpl->setVariable("SEARCH_GROUPS", $this->lng->txt("eval_search_groups"));
03588                 $this->tpl->setVariable("TEXT_CONCATENATION", $this->lng->txt("eval_concatenation"));
03589                 $this->tpl->setVariable("TEXT_AND", $this->lng->txt("and"));
03590                 $this->tpl->setVariable("TEXT_OR", $this->lng->txt("or"));
03591                 $this->tpl->setVariable("VALUE_SEARCH_TERM", $_POST["search_term"]);
03592                 if (is_array($_POST["search_for"]))
03593                 {
03594                         if (in_array("usr", $_POST["search_for"]))
03595                         {
03596                                 $this->tpl->setVariable("CHECKED_USERS", " checked=\"checked\"");
03597                         }
03598                         if (in_array("grp", $_POST["search_for"]))
03599                         {
03600                                 $this->tpl->setVariable("CHECKED_GROUPS", " checked=\"checked\"");
03601                         }
03602                 }
03603                 if (strcmp($_POST["concatenation"], "and") == 0)
03604                 {
03605                         $this->tpl->setVariable("CHECKED_AND", " checked=\"checked\"");
03606                 }
03607                 else if (strcmp($_POST["concatenation"], "or") == 0)
03608                 {
03609                         $this->tpl->setVariable("CHECKED_OR", " checked=\"checked\"");
03610                 }
03611                 $this->tpl->setVariable("SEARCH", $this->lng->txt("search"));
03612                 $this->tpl->parseCurrentBlock();
03613 
03614                 // output of alread found users and groups
03615                 $eval_users = $this->object->getEvaluationUsers($ilUser->id);
03616                 $eval_groups = $this->object->getEvaluationGroups($ilUser->id);
03617                 $buttons = array("remove");
03618                 if (count($eval_users))
03619                 {
03620                         $this->outEvalSearchResultTable("usr", $eval_users, "selected_user_result", "selected_user_row", $this->lng->txt("eval_found_selected_users"), $buttons);
03621                 }
03622                 if (count($eval_groups))
03623                 {
03624                         $this->outEvalSearchResultTable("grp", $eval_groups, "selected_group_result", "selected_group_row", $this->lng->txt("eval_found_selected_groups"), $buttons);
03625                 }
03626 
03627                 $this->tpl->setCurrentBlock("adm_content");
03628                 $this->tpl->setVariable("CMD_EVAL", "evalSelectedUsers");
03629                 $this->tpl->setVariable("TXT_STAT_USERS_INTRO", $this->lng->txt("tst_stat_users_intro"));
03630                 $this->tpl->setVariable("TXT_STAT_ALL_USERS", $this->lng->txt("tst_stat_selected_users"));
03631                 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
03632                 $this->tpl->setVariable("TXT_QWORKEDTHROUGH", $this->lng->txt("tst_stat_result_qworkedthrough"));
03633                 $this->tpl->setVariable("TXT_PWORKEDTHROUGH", $this->lng->txt("tst_stat_result_pworkedthrough"));
03634                 $this->tpl->setVariable("TXT_TIMEOFWORK", $this->lng->txt("tst_stat_result_timeofwork"));
03635                 $this->tpl->setVariable("TXT_ATIMEOFWORK", $this->lng->txt("tst_stat_result_atimeofwork"));
03636                 $this->tpl->setVariable("TXT_FIRSTVISIT", $this->lng->txt("tst_stat_result_firstvisit"));
03637                 $this->tpl->setVariable("TXT_LASTVISIT", $this->lng->txt("tst_stat_result_lastvisit"));
03638                 $this->tpl->setVariable("TXT_RESULTSPOINTS", $this->lng->txt("tst_stat_result_resultspoints"));
03639                 $this->tpl->setVariable("TXT_RESULTSMARKS", $this->lng->txt("tst_stat_result_resultsmarks"));
03640                 $this->tpl->setVariable("TXT_DISTANCEMEDIAN", $this->lng->txt("tst_stat_result_distancemedian"));
03641                 $this->tpl->setVariable("TXT_SPECIFICATION", $this->lng->txt("tst_stat_result_specification"));
03642                 $user_settings = $this->object->evalLoadStatisticalSettings($ilUser->id);
03643                 foreach ($user_settings as $key => $value) {
03644                         if ($value == 1) {
03645                                 $user_settings[$key] = " checked=\"checked\"";
03646                         } else {
03647                                 $user_settings[$key] = "";
03648                         }
03649                 }
03650                 $this->tpl->setVariable("CHECKED_QWORKEDTHROUGH", $user_settings["qworkedthrough"]);
03651                 $this->tpl->setVariable("CHECKED_PWORKEDTHROUGH", $user_settings["pworkedthrough"]);
03652                 $this->tpl->setVariable("CHECKED_TIMEOFWORK", $user_settings["timeofwork"]);
03653                 $this->tpl->setVariable("CHECKED_ATIMEOFWORK", $user_settings["atimeofwork"]);
03654                 $this->tpl->setVariable("CHECKED_FIRSTVISIT", $user_settings["firstvisit"]);
03655                 $this->tpl->setVariable("CHECKED_LASTVISIT", $user_settings["lastvisit"]);
03656                 $this->tpl->setVariable("CHECKED_RESULTSPOINTS", $user_settings["resultspoints"]);
03657                 $this->tpl->setVariable("CHECKED_RESULTSMARKS", $user_settings["resultsmarks"]);
03658                 $this->tpl->setVariable("CHECKED_DISTANCEMEDIAN", $user_settings["distancemedian"]);
03659                 $this->tpl->setVariable("TXT_STATISTICAL_EVALUATION", $this->lng->txt("tst_statistical_evaluation"));
03660                 $this->tpl->parseCurrentBlock();
03661         }
03662         
03670         function outEvalSearchResultTable($a_type, $id_array, $block_result, $block_row, $title_text, $buttons)
03671         {
03672                 include_once("./classes/class.ilObjGroup.php");
03673                 global $rbacsystem;
03674                 
03675                 $rowclass = array("tblrow1", "tblrow2");
03676                 switch($a_type)
03677                 {
03678                         case "usr":
03679                                 foreach ($id_array as $user_id => $username)
03680                                 {
03681                                         $counter = 0;
03682                                         $user = new ilObjUser($user_id);
03683                                         $this->tpl->setCurrentBlock($block_row);
03684                                         $this->tpl->setVariable("COLOR_CLASS", $rowclass[$counter % 2]);
03685                                         $this->tpl->setVariable("COUNTER", $user->getId());
03686                                         $this->tpl->setVariable("VALUE_LOGIN", $user->getLogin());
03687                                         $this->tpl->setVariable("VALUE_FIRSTNAME", $user->getFirstname());
03688                                         $this->tpl->setVariable("VALUE_LASTNAME", $user->getLastname());
03689                                         $counter++;
03690                                         $this->tpl->parseCurrentBlock();
03691                                 }
03692                                 $this->tpl->setCurrentBlock($block_result);
03693                                 $this->tpl->setVariable("TEXT_USER_TITLE", "<img src=\"" . ilUtil::getImagePath("icon_usr_b.gif") . "\" alt=\"\" /> " . $title_text);
03694                                 $this->tpl->setVariable("TEXT_LOGIN", $this->lng->txt("login"));
03695                                 $this->tpl->setVariable("TEXT_FIRSTNAME", $this->lng->txt("firstname"));
03696                                 $this->tpl->setVariable("TEXT_LASTNAME", $this->lng->txt("lastname"));
03697                                 if ($rbacsystem->checkAccess("write", $this->object->getRefId()))
03698                                 {
03699                                         foreach ($buttons as $cat)
03700                                         {
03701                                                 $this->tpl->setVariable("VALUE_" . strtoupper($cat), $this->lng->txt($cat));
03702                                         }
03703                                         $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"\">");
03704                                 }
03705                                 $this->tpl->parseCurrentBlock();
03706                                 break;
03707                         case "grp":
03708                                 foreach ($id_array as $group_id)
03709                                 {
03710                                         $counter = 0;
03711                                         $group = new ilObjGroup($group_id);
03712                                         $this->tpl->setCurrentBlock($block_row);
03713                                         $this->tpl->setVariable("COLOR_CLASS", $rowclass[$counter % 2]);
03714                                         $this->tpl->setVariable("COUNTER", $group->getRefId());
03715                                         $this->tpl->setVariable("VALUE_TITLE", $group->getTitle());
03716                                         $this->tpl->setVariable("VALUE_DESCRIPTION", $group->getDescription());
03717                                         $counter++;
03718                                         $this->tpl->parseCurrentBlock();
03719                                 }
03720                                 $this->tpl->setCurrentBlock($block_result);
03721                                 $this->tpl->setVariable("TEXT_GROUP_TITLE", "<img src=\"" . ilUtil::getImagePath("icon_grp_b.gif") . "\" alt=\"\" /> " . $title_text);
03722                                 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
03723                                 $this->tpl->setVariable("TEXT_DESCRIPTION", $this->lng->txt("description"));
03724                                 if ($rbacsystem->checkAccess("write", $this->object->getRefId()))
03725                                 {
03726                                         foreach ($buttons as $cat)
03727                                         {
03728                                                 $this->tpl->setVariable("VALUE_" . strtoupper($cat), $this->lng->txt($cat));
03729                                         }
03730                                         $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"\">");
03731                                 }
03732                                 $this->tpl->parseCurrentBlock();
03733                                 break;
03734                 }
03735         }
03736 
03744         function evaluationDetailObject()
03745         {
03746                 $answertext = $this->object->getTextAnswer($_GET["userdetail"], $_GET["answer"]);
03747                 $questiontext = $this->object->getQuestiontext($_GET["answer"]);
03748                 $this->tpl = new ilTemplate("./assessment/templates/default/tpl.il_as_tst_eval_user_answer.html", true, true);
03749                 $this->tpl->setVariable("TITLE_USER_ANSWER", $this->lng->txt("tst_eval_user_answer"));
03750                 $this->tpl->setVariable("TEXT_USER", $this->lng->txt("user"));
03751                 $user = new ilObjUser($_GET["userdetail"]);
03752                 $this->tpl->setVariable("TEXT_USERNAME", trim($user->getFirstname() . " " . $user->getLastname()));
03753                 $this->tpl->setVariable("TEXT_QUESTION", $this->lng->txt("question"));
03754                 $this->tpl->setVariable("TEXT_QUESTIONTEXT", $questiontext);
03755                 $this->tpl->setVariable("TEXT_ANSWER", $this->lng->txt("answer"));
03756                 $this->tpl->setVariable("TEXT_USER_ANSWER", str_replace("\n", "<br />", ilUtil::prepareFormOutput($answertext)));
03757         }
03758         
03759         function eval_statObject()
03760         {
03761                 $this->ctrl->setCmdClass(get_class($this));
03762                 $this->ctrl->setCmd("eval_stat");
03763                 $this->setEvaluationSettingsTabs();
03764                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_eval_statistical_evaluation_selection.html", true);
03765                 $this->tpl->setCurrentBlock("adm_content");
03766                 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
03767                 $this->tpl->setVariable("CMD_EVAL", "evalAllUsers");
03768                 $this->tpl->setVariable("TXT_STAT_USERS_INTRO", $this->lng->txt("tst_stat_users_intro"));
03769                 $this->tpl->setVariable("TXT_STAT_ALL_USERS", $this->lng->txt("tst_stat_all_users"));
03770                 $this->tpl->setVariable("TXT_QWORKEDTHROUGH", $this->lng->txt("tst_stat_result_qworkedthrough"));
03771                 $this->tpl->setVariable("TXT_PWORKEDTHROUGH", $this->lng->txt("tst_stat_result_pworkedthrough"));
03772                 $this->tpl->setVariable("TXT_TIMEOFWORK", $this->lng->txt("tst_stat_result_timeofwork"));
03773                 $this->tpl->setVariable("TXT_ATIMEOFWORK", $this->lng->txt("tst_stat_result_atimeofwork"));
03774                 $this->tpl->setVariable("TXT_FIRSTVISIT", $this->lng->txt("tst_stat_result_firstvisit"));
03775                 $this->tpl->setVariable("TXT_LASTVISIT", $this->lng->txt("tst_stat_result_lastvisit"));
03776                 $this->tpl->setVariable("TXT_RESULTSPOINTS", $this->lng->txt("tst_stat_result_resultspoints"));
03777                 $this->tpl->setVariable("TXT_RESULTSMARKS", $this->lng->txt("tst_stat_result_resultsmarks"));
03778                 $this->tpl->setVariable("TXT_DISTANCEMEDIAN", $this->lng->txt("tst_stat_result_distancemedian"));
03779                 $this->tpl->setVariable("TXT_SPECIFICATION", $this->lng->txt("tst_stat_result_specification"));
03780                 $user_settings = $this->object->evalLoadStatisticalSettings($ilUser->id);
03781                 foreach ($user_settings as $key => $value) {
03782                         if ($value == 1) {
03783                                 $user_settings[$key] = " checked=\"checked\"";
03784                         } else {
03785                                 $user_settings[$key] = "";
03786                         }
03787                 }
03788                 $this->tpl->setVariable("CHECKED_QWORKEDTHROUGH", $user_settings["qworkedthrough"]);
03789                 $this->tpl->setVariable("CHECKED_PWORKEDTHROUGH", $user_settings["pworkedthrough"]);
03790                 $this->tpl->setVariable("CHECKED_TIMEOFWORK", $user_settings["timeofwork"]);
03791                 $this->tpl->setVariable("CHECKED_ATIMEOFWORK", $user_settings["atimeofwork"]);
03792                 $this->tpl->setVariable("CHECKED_FIRSTVISIT", $user_settings["firstvisit"]);
03793                 $this->tpl->setVariable("CHECKED_LASTVISIT", $user_settings["lastvisit"]);
03794                 $this->tpl->setVariable("CHECKED_RESULTSPOINTS", $user_settings["resultspoints"]);
03795                 $this->tpl->setVariable("CHECKED_RESULTSMARKS", $user_settings["resultsmarks"]);
03796                 $this->tpl->setVariable("CHECKED_DISTANCEMEDIAN", $user_settings["distancemedian"]);
03797                 $this->tpl->setVariable("TXT_STATISTICAL_EVALUATION", $this->lng->txt("tst_statistical_evaluation"));
03798                 $this->tpl->parseCurrentBlock();
03799         }
03800 
03801         function saveEvaluationSettings()
03802         {
03803                 $eval_statistical_settings = array(
03804                         "qworkedthrough" => $_POST["chb_result_qworkedthrough"],
03805                         "pworkedthrough" => $_POST["chb_result_pworkedthrough"],
03806                         "timeofwork" => $_POST["chb_result_timeofwork"],
03807                         "atimeofwork" => $_POST["chb_result_atimeofwork"],
03808                         "firstvisit" => $_POST["chb_result_firstvisit"],
03809                         "lastvisit" => $_POST["chb_result_lastvisit"],
03810                         "resultspoints" => $_POST["chb_result_resultspoints"],
03811                         "resultsmarks" => $_POST["chb_result_resultsmarks"],
03812                         "distancemedian" => $_POST["chb_result_distancemedian"]
03813                 );
03814                 $this->object->evalSaveStatisticalSettings($eval_statistical_settings, $ilUser->id);
03815                 return $eval_statistical_settings;
03816         }
03817         
03818         function evalSelectedUsersObject($all_users = 0)
03819         {
03820                 global $ilUser;
03821 
03822                 $savetextanswers = 0;
03823                 $textanswers = 0;
03824                 $print = 0;
03825                 $export = 0;
03826                 if (strcmp($_POST["cmd"][$this->ctrl->getCmd()], $this->lng->txt("print")) == 0)
03827                 {
03828                         $print = 1;
03829                 }
03830                 if (strcmp($_POST["cmd"][$this->ctrl->getCmd()], $this->lng->txt("export")) == 0)
03831                 {
03832                         $export = 1;
03833                 }
03834                 if (strcmp($_POST["cmd"][$this->ctrl->getCmd()], $this->lng->txt("save_text_answer_points")) == 0)
03835                 {
03836 
03837                         $savetextanswers = 1;
03838                         foreach ($_POST as $key => $value)
03839                         {
03840                                 if (preg_match("/(\d+)_(\d+)_(\d+)/", $key, $matches))
03841                                 {
03842                                         ASS_TextQuestion::_setReachedPoints($matches[1], $this->object->getTestId(), $matches[2], $value, $matches[3]);
03843                                 }
03844                         }
03845                         sendInfo($this->lng->txt("text_answers_saved"));
03846                 }
03847                 if ((count($_POST) == 0) || ($print) || ($export) || ($savetextanswers))
03848                 {
03849                         $user_settings = $this->object->evalLoadStatisticalSettings($ilUser->id);
03850                         $eval_statistical_settings = array(
03851                                 "qworkedthrough" => $user_settings["qworkedthrough"],
03852                                 "pworkedthrough" => $user_settings["pworkedthrough"],
03853                                 "timeofwork" => $user_settings["timeofwork"],
03854                                 "atimeofwork" => $user_settings["atimeofwork"],
03855                                 "firstvisit" => $user_settings["firstvisit"],
03856                                 "lastvisit" => $user_settings["lastvisit"],
03857                                 "resultspoints" => $user_settings["resultspoints"],
03858                                 "resultsmarks" => $user_settings["resultsmarks"],
03859                                 "distancemedian" => $user_settings["distancemedian"]
03860                         );
03861                 }
03862                 else
03863                 {
03864                         $eval_statistical_settings = $this->saveEvaluationSettings();
03865                 }
03866 //              $this->ctrl->setCmd("evalSelectedUsers");
03867                 $this->setEvaluationTabs($all_users);
03868                 $legend = array();
03869                 $legendquestions = array();
03870                 $titlerow = array();
03871                 // build title columns
03872                 $name_column = $this->lng->txt("name");
03873                 if ($this->object->getTestType() == TYPE_SELF_ASSESSMENT)
03874                 {
03875                         $name_column = $this->lng->txt("counter");
03876                 }
03877                 array_push($titlerow, $name_column);
03878                 
03879                 $char = "A";
03880                 if ($eval_statistical_settings["qworkedthrough"]) {
03881                         array_push($titlerow, $char);
03882                         $legend[$char] = $this->lng->txt("tst_stat_result_qworkedthrough");
03883                         $char++;
03884                 }
03885                 if ($eval_statistical_settings["pworkedthrough"]) {
03886                         array_push($titlerow, $char);
03887                         $legend[$char] = $this->lng->txt("tst_stat_result_pworkedthrough");
03888                         $char++;
03889                 }
03890                 if ($eval_statistical_settings["timeofwork"]) {
03891                         array_push($titlerow, $char);
03892                         $legend[$char] = $this->lng->txt("tst_stat_result_timeofwork");
03893                         $char++;
03894                 }
03895                 if ($eval_statistical_settings["atimeofwork"]) {
03896                         array_push($titlerow, $char);
03897                         $legend[$char] = $this->lng->txt("tst_stat_result_atimeofwork");
03898                         $char++;
03899                 }
03900                 if ($eval_statistical_settings["firstvisit"]) {
03901                         array_push($titlerow, $char);
03902                         $legend[$char] = $this->lng->txt("tst_stat_result_firstvisit");
03903                         $char++;
03904                 }
03905                 if ($eval_statistical_settings["lastvisit"]) {
03906                         array_push($titlerow, $char);
03907                         $legend[$char] = $this->lng->txt("tst_stat_result_lastvisit");
03908                         $char++;
03909                 }
03910                 if ($eval_statistical_settings["resultspoints"]) {
03911                         array_push($titlerow, $char);
03912                         $legend[$char] = $this->lng->txt("tst_stat_result_resultspoints");
03913                         $char++;
03914                 }
03915                 if ($eval_statistical_settings["resultsmarks"]) {
03916                         array_push($titlerow, $char);
03917                         $legend[$char] = $this->lng->txt("tst_stat_result_resultsmarks");
03918                         $char++;
03919                         
03920                         if ($this->object->ects_output)
03921                         {
03922                                 array_push($titlerow, $char);
03923                                 $legend[$char] = $this->lng->txt("ects_grade");
03924                                 $char++;
03925                         }
03926                 }
03927                 if ($eval_statistical_settings["distancemedian"]) {
03928                         array_push($titlerow, $char);
03929                         $legend[$char] = $this->lng->txt("tst_stat_result_mark_median");
03930                         $char++;
03931                         array_push($titlerow, $char);
03932                         $legend[$char] = $this->lng->txt("tst_stat_result_rank_participant");
03933                         $char++;
03934                         array_push($titlerow, $char);
03935                         $legend[$char] = $this->lng->txt("tst_stat_result_rank_median");
03936                         $char++;
03937                         array_push($titlerow, $char);
03938                         $legend[$char] = $this->lng->txt("tst_stat_result_total_participants");
03939                         $char++;
03940                         array_push($titlerow, $char);
03941                         $legend[$char] = $this->lng->txt("tst_stat_result_median");
03942                         $char++;
03943                 }
03944                 
03945                 $titlerow_without_questions = $titlerow;
03946                 if (!$this->object->isRandomTest())
03947                 {
03948                         $qtitles =& $this->object->getQuestionTitles();
03949                         $i = 1;
03950                         foreach ($qtitles as $title)
03951                         {
03952                                 array_push($titlerow, $this->lng->txt("question_short") . " " . $i);
03953                                 $legendquestions[$i] = $title;
03954                                 $legend[$this->lng->txt("question_short") . " " . $i] = $i;
03955                                 $i++;
03956                         }
03957                 }
03958                 else
03959                 {
03960                         for ($i = 1; $i <= $this->object->getQuestionCount(); $i++)
03961                         {
03962                                 array_push($titlerow, "&nbsp;");
03963                         }
03964                 }
03965                 $total_users =& $this->object->evalTotalPersonsArray();
03966                 $selected_users = array();
03967                 if ($all_users == 1) {
03968                         $selected_users = $total_users;
03969                 } else {
03970                         $selected_users =& $this->object->getEvaluationUsers($ilUser->id);
03971                         $selected_groups =& $this->object->getEvaluationGroups($ilUser->id);
03972                         include_once("./classes/class.ilObjGroup.php");
03973                         foreach ($selected_groups as $group_id)
03974                         {
03975                                 $grp = new ilObjGroup($group_id, true);
03976                                 $members = $grp->getGroupMemberIds();
03977                                 foreach ($members as $member_id)
03978                                 {
03979                                         if (array_key_exists($member_id, $total_users))
03980                                         {
03981                                                 $usr = new ilObjUser($member_id); 
03982                                                 $selected_users[$member_id] = trim($usr->firstname . " " . $usr->lastname);
03983                                         }
03984                                 }
03985                         }
03986                 }
03987 //                      $ilBench->stop("Test_Statistical_evaluation", "getAllParticipants");
03988                 $row = 0;
03989                 $question_legend = false;
03990                 $question_stat = array();
03991                 $evaluation_array = array();
03992                 foreach ($total_users as $key => $value) {
03993                         // receive array with statistical information on the test for a specific user
03994 //                              $ilBench->start("Test_Statistical_evaluation", "this->object->evalStatistical($key)");
03995                         $stat_eval =& $this->object->evalStatistical($key);
03996                         foreach ($stat_eval as $sindex => $sarray)
03997                         {
03998                                 if (preg_match("/\d+/", $sindex))
03999                                 {
04000                                         $qt = $sarray["title"];
04001                                         $qt = preg_replace("/<.*?>/", "", $qt);
04002                                         if (!array_key_exists($sarray["qid"], $question_stat))
04003                                         {
04004                                                 $question_stat[$sarray["qid"]] = array("max" => 0, "reached" => 0, "title" => $qt);
04005                                         }
04006                                         $question_stat[$sarray["qid"]]["single_max"] = $sarray["max"];
04007                                         $question_stat[$sarray["qid"]]["max"] += $sarray["max"];
04008                                         $question_stat[$sarray["qid"]]["reached"] += $sarray["reached"];
04009                                 }
04010                         }
04011 //                              $ilBench->stop("Test_Statistical_evaluation", "this->object->evalStatistical($key)");
04012                         $evaluation_array[$key] = $stat_eval;
04013                 }
04014 
04015                 include_once "./classes/class.ilStatistics.php";
04016                 // calculate the median
04017                 $median_array = array();
04018                 foreach ($evaluation_array as $key => $value)
04019                 {
04020                         array_push($median_array, $value["resultspoints"]);
04021                 }
04022                 //$median_array =& $this->object->getTotalPointsArray();
04023                 $statistics = new ilStatistics();
04024                 $statistics->setData($median_array);
04025                 $median = $statistics->median();
04026 //                      $ilBench->stop("Test_Statistical_evaluation", "calculate all statistical data");
04027 //                      $ilBench->save();
04028                 $evalcounter = 1;
04029                 $question_titles = array();
04030                 $question_title_counter = 1;
04031                 $eval_complete = array();
04032                 foreach ($selected_users as $key => $name)
04033                 {
04034                         $stat_eval = $evaluation_array[$key];
04035                         
04036                         $titlerow_user = array();
04037                         if ($this->object->isRandomTest())
04038                         {
04039                                 $this->object->loadQuestions($key);
04040                                 $titlerow_user = $titlerow_without_questions;
04041                                 $i = 1;
04042                                 foreach ($stat_eval as $key1 => $value1)
04043                                 {
04044                                         if (preg_match("/\d+/", $key1))
04045                                         {
04046                                                 $qt = $value1["title"];
04047                                                 $qt = preg_replace("/<.*?>/", "", $qt);
04048 /*                                              $arraykey = array_search($qt, $legend);
04049                                                 if (!$arraykey)
04050                                                 {
04051                                                         array_push($titlerow_user, $this->lng->txt("question_short") . " " . $question_title_counter);
04052                                                         $legend[$this->lng->txt("question_short") . " " . $question_title_counter] = $qt;
04053                                                         $question_title_counter++;
04054                                                 }
04055                                                 else
04056                                                 {
04057                                                         array_push($titlerow_user, $arraykey);
04058                                                 }*/
04059                                                 if (!array_key_exists($value1["qid"], $legendquestions))
04060                                                 {
04061                                                         array_push($titlerow_user, $this->lng->txt("question_short") . " " . $question_title_counter);
04062                                                         $legend[$this->lng->txt("question_short") . " " . $question_title_counter] = $value1["qid"];
04063                                                         $legendquestions[$value1["qid"]] = $qt;
04064                                                         $question_title_counter++;
04065                                                 }
04066                                                 else
04067                                                 {
04068                                                         $arraykey = array_search($value1["qid"], $legend);
04069                                                         array_push($titlerow_user, $arraykey);
04070                                                 }
04071                                         }
04072                                 }
04073                         }
04074 
04075                         $evalrow = array();
04076                         $username = $evalcounter++; 
04077                         if ($this->object->getTestType() != TYPE_SELF_ASSESSMENT)
04078                         {
04079                                 $username = $selected_users[$key];
04080                         }
04081                         array_push($evalrow, array(
04082                                 "html" => $username,
04083                                 "xls"  => $username,
04084                                 "csv"  => $username
04085                         ));
04086                         if ($eval_statistical_settings["qworkedthrough"]) {
04087                                 array_push($evalrow, array(
04088                                         "html" => $stat_eval["qworkedthrough"],
04089                                         "xls"  => $stat_eval["qworkedthrough"],
04090                                         "csv"  => $stat_eval["qworkedthrough"]
04091                                 ));
04092                         }
04093                         if ($eval_statistical_settings["pworkedthrough"]) {
04094                                 array_push($evalrow, array(
04095                                         "html" => sprintf("%2.2f", $stat_eval["pworkedthrough"] * 100.0) . " %",
04096                                         "xls"  => $stat_eval["pworkedthrough"],
04097                                         "csv"  => $stat_eval["pworkedthrough"],
04098                                         "format" => "%"
04099                                 ));
04100                         }
04101                         if ($eval_statistical_settings["timeofwork"]) 
04102                         {
04103                                 $time = $stat_eval["timeofwork"];
04104                                 $time_seconds = $time;
04105                                 $time_hours    = floor($time_seconds/3600);
04106                                 $time_seconds -= $time_hours   * 3600;
04107                                 $time_minutes  = floor($time_seconds/60);
04108                                 $time_seconds -= $time_minutes * 60;
04109                                 array_push($evalrow, array(
04110                                         "html" => sprintf("%02d:%02d:%02d", $time_hours, $time_minutes, $time_seconds),
04111                                         "xls"  => sprintf("%02d:%02d:%02d", $time_hours, $time_minutes, $time_seconds),
04112                                         "csv"  => sprintf("%02d:%02d:%02d", $time_hours, $time_minutes, $time_seconds)
04113                                 ));
04114                         }
04115                         if ($eval_statistical_settings["atimeofwork"]) {
04116                                 $time = $stat_eval["atimeofwork"];
04117                                 $time_seconds = $time;
04118                                 $time_hours    = floor($time_seconds/3600);
04119                                 $time_seconds -= $time_hours   * 3600;
04120                                 $time_minutes  = floor($time_seconds/60);
04121                                 $time_seconds -= $time_minutes * 60;
04122                                 array_push($evalrow, array(
04123                                         "html" => sprintf("%02d:%02d:%02d", $time_hours, $time_minutes, $time_seconds),
04124                                         "xls"  => sprintf("%02d:%02d:%02d", $time_hours, $time_minutes, $time_seconds),
04125                                         "csv"  => sprintf("%02d:%02d:%02d", $time_hours, $time_minutes, $time_seconds)
04126                                 ));
04127                         }
04128                         if ($eval_statistical_settings["firstvisit"]) {
04129                                 array_push($evalrow, array(
04130                                         "html" => date($this->lng->text["lang_dateformat"] . " " . $this->lng->text["lang_timeformat"], mktime($stat_eval["firstvisit"]["hours"], $stat_eval["firstvisit"]["minutes"], $stat_eval["firstvisit"]["seconds"], $stat_eval["firstvisit"]["mon"], $stat_eval["firstvisit"]["mday"], $stat_eval["firstvisit"]["year"])),
04131                                         "xls"  => ilUtil::excelTime($stat_eval["firstvisit"]["year"],$stat_eval["firstvisit"]["mon"],$stat_eval["firstvisit"]["mday"],$stat_eval["firstvisit"]["hours"],$stat_eval["firstvisit"]["minutes"],$stat_eval["firstvisit"]["seconds"]),
04132                                         "csv"  => date($this->lng->text["lang_dateformat"] . " " . $this->lng->text["lang_timeformat"], mktime($stat_eval["firstvisit"]["hours"], $stat_eval["firstvisit"]["minutes"], $stat_eval["firstvisit"]["seconds"], $stat_eval["firstvisit"]["mon"], $stat_eval["firstvisit"]["mday"], $stat_eval["firstvisit"]["year"])),
04133                                         "format" => "t"
04134                                 ));
04135                         }
04136                         if ($eval_statistical_settings["lastvisit"]) {
04137                                 array_push($evalrow, array(
04138                                         "html" => date($this->lng->text["lang_dateformat"] . " " . $this->lng->text["lang_timeformat"], mktime($stat_eval["lastvisit"]["hours"], $stat_eval["lastvisit"]["minutes"], $stat_eval["lastvisit"]["seconds"], $stat_eval["lastvisit"]["mon"], $stat_eval["lastvisit"]["mday"], $stat_eval["lastvisit"]["year"])),
04139                                         "xls"  => ilUtil::excelTime($stat_eval["lastvisit"]["year"],$stat_eval["lastvisit"]["mon"],$stat_eval["lastvisit"]["mday"],$stat_eval["lastvisit"]["hours"],$stat_eval["lastvisit"]["minutes"],$stat_eval["lastvisit"]["seconds"]),
04140                                         "csv"  => date($this->lng->text["lang_dateformat"] . " " . $this->lng->text["lang_timeformat"], mktime($stat_eval["lastvisit"]["hours"], $stat_eval["lastvisit"]["minutes"], $stat_eval["lastvisit"]["seconds"], $stat_eval["lastvisit"]["mon"], $stat_eval["lastvisit"]["mday"], $stat_eval["lastvisit"]["year"])),
04141                                         "format" => "t"
04142                                 ));
04143                         }
04144                         if ($eval_statistical_settings["resultspoints"]) {
04145                                 array_push($evalrow, array(
04146                                         "html" => $stat_eval["resultspoints"]." ".strtolower($this->lng->txt("of"))." ". $stat_eval["maxpoints"],
04147                                         "xls"  => $stat_eval["resultspoints"],
04148                                         "csv"  => $stat_eval["resultspoints"]
04149                                 ));
04150                         }
04151                         if ($eval_statistical_settings["resultsmarks"]) {
04152                                 array_push($evalrow, array(
04153                                         "html" => $stat_eval["resultsmarks"],
04154                                         "xls"  => $stat_eval["resultsmarks"],
04155                                         "csv"  => $stat_eval["resultsmarks"]
04156                                 ));
04157 
04158                                 if ($this->object->ects_output)
04159                                 {
04160                                         $mark_ects = $this->object->getECTSGrade($stat_eval["resultspoints"],$stat_eval["maxpoints"]);
04161                                         array_push($evalrow, array(
04162                                                 "html" => $mark_ects,
04163                                                 "xls"  => $mark_ects,
04164                                                 "csv"  => $mark_ects
04165                                         ));
04166                                 }
04167                         }
04168                         
04169                         if ($eval_statistical_settings["distancemedian"]) {
04170                                 if ($stat_eval["maxpoints"] == 0)
04171                                 {
04172                                         $pct = 0;
04173                                 }
04174                                 else
04175                                 {
04176                                         $pct = ($median / $stat_eval["maxpoints"]) * 100.0;
04177                                 }
04178                                 $mark = $this->object->mark_schema->get_matching_mark($pct);
04179                                 $mark_short_name = "";
04180                                 if ($mark)
04181                                 {
04182                                         $mark_short_name = $mark->get_short_name();
04183                                 }
04184                                 array_push($evalrow, array(
04185                                         "html" => $mark_short_name,
04186                                         "xls"  => $mark_short_name,
04187                                         "csv"  => $mark_short_name
04188                                 ));
04189                                 $rank_participant = $statistics->rank($stat_eval["resultspoints"]);
04190                                 array_push($evalrow, array(
04191                                         "html" => $rank_participant,
04192                                         "xls"  => $rank_participant,
04193                                         "csv"  => $rank_participant
04194                                 ));
04195                                 $rank_median = $statistics->rank_median();
04196                                 array_push($evalrow, array(
04197                                         "html" => $rank_median,
04198                                         "xls"  => $rank_median,
04199                                         "csv"  => $rank_median
04200                                 ));
04201                                 $total_participants = count($median_array);
04202                                 array_push($evalrow, array(
04203                                         "html" => $total_participants,
04204                                         "xls"  => $total_participants,
04205                                         "csv"  => $total_participants
04206                                 ));
04207                                 array_push($evalrow, array(
04208                                         "html" => $median,
04209                                         "xls"  => $median,
04210                                         "csv"  => $median
04211                                 ));
04212                         }
04213                         
04214                         for ($i = 1; $i <= $this->object->getQuestionCount(); $i++)
04215                         {
04216                                 $qshort = "";
04217                                 $qt = "";
04218                                 if ($this->object->isRandomTest())
04219                                 {
04220                                         $qt = $stat_eval[$i-1]["title"];
04221                                         $qt = preg_replace("/<.*?>/", "", $qt);
04222                                         $arrkey = array_search($stat_eval[$i-1]["qid"], $legend);
04223                                         if ($arrkey)
04224                                         {
04225                                                 $qshort = "<span title=\"" . ilUtil::prepareFormOutput($qt) . "\">" . $arrkey . "</span>: ";
04226                                         }
04227                                 }
04228 
04229                                 $htmloutput = "";
04230                                 if ($stat_eval[$i-1]["type"] == "qt_text")
04231                                 {
04232                                         // Text question
04233                                         $name = $key."_".$stat_eval[$i-1]["qid"]."_".$stat_eval[$i-1]["max"];
04234                                         $htmloutput = $qshort . "<input type=\"text\" name=\"".$name."\" size=\"3\" value=\"".$stat_eval[$i-1]["reached"]."\" />".strtolower($this->lng->txt("of"))." ". $stat_eval[$i-1]["max"];
04235                                         // Solution
04236                                         $htmloutput .= " [<a href=\"".$this->ctrl->getLinkTargetByClass(get_class($this), "evaluationDetail") . "&userdetail=$key&answer=".$stat_eval[$i-1]["qid"]."\" target=\"popup\" onclick=\"";
04237                                         $htmloutput .= "window.open('', 'popup', 'width=600, height=200, scrollbars=yes, toolbar=no, status=no, resizable=yes, menubar=no, location=no, directories=no')";
04238                                         $htmloutput .= "\">".$this->lng->txt("tst_eval_show_answer")."</a>]";
04239                                         $textanswers++;
04240                                 }
04241                                         else
04242                                 {
04243                                         $htmloutput = $qshort . $stat_eval[$i-1]["reached"] . " " . strtolower($this->lng->txt("of")) . " " .  $stat_eval[$i-1]["max"];
04244                                 }
04245 
04246                                 array_push($evalrow, array(
04247                                         "html" => $htmloutput,
04248                                         "xls"  => $stat_eval[$i-1]["reached"],
04249                                         "csv"  => $stat_eval[$i-1]["reached"]
04250                                 ));
04251                         }
04252                         array_push($eval_complete, array("title" => $titlerow_user, "data" => $evalrow));
04253                 }
04254 
04255                 $noqcount = count($titlerow_without_questions);
04256                 if ($export)
04257                 {
04258                         $testname = preg_replace("/\s/", "_", $this->object->getTitle());
04259                         switch ($_POST["export_type"])
04260                         {
04261                                 case TYPE_XLS_PC:
04262                                 case TYPE_XLS_MAC:
04263                                         // Creating a workbook
04264                                         $result = @include_once 'Spreadsheet/Excel/Writer.php';
04265                                         if (!$result)
04266                                         {
04267                                                 include_once './classes/Spreadsheet/Excel/Writer.php';
04268                                         }
04269                                         $workbook = new Spreadsheet_Excel_Writer();
04270         
04271                                         // sending HTTP headers
04272                                         $workbook->send("$testname.xls");
04273         
04274                                         // Creating a worksheet
04275                                         $format_bold =& $workbook->addFormat();
04276                                         $format_bold->setBold();
04277                                         $format_percent =& $workbook->addFormat();
04278                                         $format_percent->setNumFormat("0.00%");
04279                                         $format_datetime =& $workbook->addFormat();
04280                                         $format_datetime->setNumFormat("DD/MM/YYYY hh:mm:ss");
04281                                         $format_title =& $workbook->addFormat();
04282                                         $format_title->setBold();
04283                                         $format_title->setColor('black');
04284                                         $format_title->setPattern(1);
04285                                         $format_title->setFgColor('silver');
04286                                         $worksheet =& $workbook->addWorksheet();
04287                                         $row = 0;
04288                                         $col = 0;
04289                                         include_once ("./classes/class.ilExcelUtils.php");
04290                                         if (!$this->object->isRandomTest())
04291                                         {
04292                                                 foreach ($titlerow as $title)
04293                                                 {
04294                                                         if (preg_match("/\d+/", $title))
04295                                                         {
04296                                                                 $worksheet->write($row, $col, ilExcelUtils::_convert_text($legendquestions[$legend[$title]], $_POST["export_type"]), $format_title);
04297                                                         }
04298                                                         else if (strlen($title) == 1)
04299                                                         {
04300                                                                 $worksheet->write($row, $col, ilExcelUtils::_convert_text($legend[$title], $_POST["export_type"]), $format_title);
04301                                                         }
04302                                                         else
04303                                                         {
04304                                                                 $worksheet->write($row, $col, ilExcelUtils::_convert_text($title, $_POST["export_type"]), $format_title);
04305                                                         }
04306                                                         $col++;
04307                                                 }
04308                                                 $row++;
04309                                         }
04310                                         foreach ($eval_complete as $evalrow)
04311                                         {
04312                                                 $col = 0;
04313                                                 if ($this->object->isRandomTest())
04314                                                 {
04315                                                         foreach ($evalrow["title"] as $key => $value)
04316                                                         {
04317                                                                 if ($key == 0)
04318                                                                 {
04319                                                                         $worksheet->write($row, $col, ilExcelUtils::_convert_text($value, $_POST["export_type"]), $format_title);
04320                                                                 }
04321                                                                 else
04322                                                                 {
04323                                                                         if (preg_match("/\d+/", $value))
04324                                                                         {
04325                                                                                 $worksheet->write($row, $col, ilExcelUtils::_convert_text($legendquestions[$legend[$value]], $_POST["export_type"]), $format_title);
04326                                                                         }
04327                                                                         else
04328                                                                         {
04329                                                                                 $worksheet->write($row, $col, ilExcelUtils::_convert_text($legend[$value], $_POST["export_type"]), $format_title);
04330                                                                         }
04331                                                                 }
04332                                                                 $col++;
04333                                                         }
04334                                                         $row++;
04335                                                 }
04336                                                 $col = 0;
04337                                                 foreach ($evalrow["data"] as $key => $value)
04338                                                 {
04339                                                         switch ($value["format"])
04340                                                         {
04341                                                                 case "%":
04342                                                                         $worksheet->write($row, $col, $value["xls"], $format_percent);
04343                                                                         break;
04344                                                                 case "t":
04345                                                                         $worksheet->write($row, $col, $value["xls"], $format_datetime);
04346                                                                         break;
04347                                                                 default:
04348                                                                         $worksheet->write($row, $col, ilExcelUtils::_convert_text($value["xls"], $_POST["export_type"]));
04349                                                                         break;
04350                                                         }
04351                                                         $col++;
04352                                                 }
04353                                                 $row++;
04354                                         }
04355                                         $workbook->close();
04356                                         exit;
04357                                 case TYPE_SPSS:
04358                                         $csv = "";
04359                                         $separator = ";";
04360                                         if (!$this->object->isRandomTest())
04361                                         {
04362                                                 $titlerow =& $this->object->processCSVRow($titlerow, TRUE, $separator);
04363                                                 $csv .= join($titlerow, $separator) . "\n";
04364                                         }
04365                                         foreach ($eval_complete as $evalrow)
04366                                         {
04367                                                 $csvrow = array();
04368                                                 foreach ($evalrow["data"] as $dataarray)
04369                                                 {
04370                                                         array_push($csvrow, $dataarray["csv"]);
04371                                                 }
04372                                                 if ($this->object->isRandomTest())
04373                                                 {
04374                                                         $evalrow["title"] =& $this->object->processCSVRow($evalrow["title"], TRUE, $separator);
04375                                                         $csv .= join($evalrow["title"], $separator) . "\n";
04376                                                 }
04377                                                 $csvarr = array();
04378                                                 $evalrow["data"] =& $this->object->processCSVRow($csvrow, TRUE, $separator);
04379                                                 $csv .= join($evalrow["data"], $separator) . "\n";
04380                                         }
04381                                         ilUtil::deliverData($csv, "$testname.csv");
04382                                         break;
04383                         }
04384                         exit;
04385                 }
04386                 if ($print)
04387                 {
04388                         $this->tpl = new ilTemplate("./assessment/templates/default/tpl.il_as_tst_eval_statistical_evaluation_preview.html", true, true);
04389                 }
04390                 else
04391                 {
04392                         $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_eval_statistical_evaluation.html", true);
04393                 }
04394                 $color_class = array("tblrow1", "tblrow2");
04395                 foreach ($legend as $short => $long)
04396                 {
04397                         $this->tpl->setCurrentBlock("legendrow");
04398                         $this->tpl->setVariable("TXT_SYMBOL", $short);
04399                         if (preg_match("/\d+/", $short))
04400                         {
04401                                 $this->tpl->setVariable("TXT_MEANING", $legendquestions[$long]);
04402                         }
04403                         else
04404                         {
04405                                 $this->tpl->setVariable("TXT_MEANING", $long);
04406                         }
04407                         $this->tpl->parseCurrentBlock();
04408                 }
04409                 $this->tpl->setCurrentBlock("legend");
04410                 $this->tpl->setVariable("TXT_LEGEND", $this->lng->txt("legend"));
04411                 $this->tpl->setVariable("TXT_LEGEND_LINK", $this->lng->txt("eval_legend_link"));
04412                 $this->tpl->setVariable("TXT_SYMBOL", $this->lng->txt("symbol"));
04413                 $this->tpl->setVariable("TXT_MEANING", $this->lng->txt("meaning"));
04414                 $this->tpl->parseCurrentBlock();
04415 
04416                 $counter = 0;
04417                 foreach ($question_stat as $title => $values)
04418                 {
04419                         $this->tpl->setCurrentBlock("meanrow");
04420                         $this->tpl->setVariable("TXT_QUESTION", ilUtil::prepareFormOutput($values["title"]));
04421                         $percent = 0;
04422                         if ($values["max"] > 0)
04423                         {
04424                                 $percent = $values["reached"] / $values["max"];
04425                         }
04426                         $this->tpl->setVariable("TXT_MEAN", sprintf("%.2f", $values["single_max"]*$percent) . " " . strtolower($this->lng->txt("of")) . " " . sprintf("%.2f", $values["single_max"]) . " (" . sprintf("%.2f", $percent*100) . " %)");
04427                         $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
04428                         $counter++;
04429                         $this->tpl->parseCurrentBlock();
04430                 }
04431                 $this->tpl->setCurrentBlock("question_mean_points");
04432                 $this->tpl->setVariable("TXT_AVERAGE_POINTS", $this->lng->txt("average_reached_points"));
04433                 $this->tpl->setVariable("TXT_QUESTION", $this->lng->txt("question_title"));
04434                 $this->tpl->setVariable("TXT_MEAN", $this->lng->txt("average_reached_points"));
04435                 $this->tpl->parseCurrentBlock();
04436                 
04437                 $noq = $noqcount;               
04438                 foreach ($titlerow as $title)
04439                 {
04440                         if ($noq > 0)
04441                         {
04442                                 $this->tpl->setCurrentBlock("titlecol");
04443                                 $this->tpl->setVariable("TXT_TITLE", "<div title=\"" . ilUtil::prepareFormOutput($legendquestions[$legend[$title]]) . "\">" . $title . "</div>");
04444                                 $this->tpl->parseCurrentBlock();
04445                                 if ($noq == $noqcount)
04446                                 {
04447                                         $this->tpl->setCurrentBlock("questions_titlecol");
04448                                         $this->tpl->setVariable("TXT_TITLE", $title);
04449                                         $this->tpl->parseCurrentBlock();
04450                                 }
04451                                 $noq--;
04452                         }
04453                         else
04454                         {
04455                                 $this->tpl->setCurrentBlock("questions_titlecol");
04456                                 $this->tpl->setVariable("TXT_TITLE", "<div title=\"" . $legendquestions[$legend[$title]] . "\">" . $title . "</div>");
04457                                 $this->tpl->parseCurrentBlock();
04458                         }
04459                 }
04460                 $counter = 0;
04461                 foreach ($eval_complete as $row)
04462                 {
04463                         $noq = $noqcount;
04464                         foreach ($row["data"] as $key => $value)
04465                         {
04466                                 if ($noq > 0)
04467                                 {
04468                                         $this->tpl->setCurrentBlock("datacol");
04469                                         $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
04470                                         $this->tpl->setVariable("TXT_DATA", $value["html"]);
04471                                         $this->tpl->parseCurrentBlock();
04472                                         if ($noq == $noqcount)
04473                                         {
04474                                                 $this->tpl->setCurrentBlock("questions_datacol");
04475                                                 $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
04476                                                 $this->tpl->setVariable("TXT_DATA", $value["html"]);
04477                                                 $this->tpl->parseCurrentBlock();
04478                                         }
04479                                         $noq--;
04480                                 }
04481                                 else
04482                                 {
04483                                         $this->tpl->setCurrentBlock("questions_datacol");
04484                                         $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
04485                                         $this->tpl->setVariable("TXT_DATA", $value["html"]);
04486                                         $this->tpl->parseCurrentBlock();
04487                                 }
04488                         }
04489                         $this->tpl->setCurrentBlock("row");
04490                         $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
04491                         $this->tpl->parseCurrentBlock();
04492                         $this->tpl->setCurrentBlock("questions_row");
04493                         $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
04494                         $this->tpl->parseCurrentBlock();
04495                         $counter++;
04496                 }
04497 
04498                 if ($textanswers)
04499                 {
04500                         $this->tpl->setCurrentBlock("questions_output_button");
04501                         $this->tpl->setVariable("BUTTON_SAVE", $this->lng->txt("save_text_answer_points"));
04502                         $this->tpl->setVariable("BTN_COMMAND", $this->ctrl->getCmd());
04503                         $this->tpl->parseCurrentBlock();
04504                 }
04505                 
04506                 $this->tpl->setCurrentBlock("questions_output");
04507                 $this->tpl->setVariable("TXT_QUESTIONS",  $this->lng->txt("ass_questions"));
04508                 $this->tpl->setVariable("FORM_ACTION_RESULTS", $this->ctrl->getFormAction($this));
04509                 $this->tpl->parseCurrentBlock();
04510 
04511                 $this->tpl->setCurrentBlock("export_btn");
04512                 $this->tpl->setVariable("EXPORT_DATA", $this->lng->txt("exp_eval_data"));
04513                 $this->tpl->setVariable("TEXT_EXCEL", $this->lng->txt("exp_type_excel"));
04514                 $this->tpl->setVariable("TEXT_EXCEL_MAC", $this->lng->txt("exp_type_excel_mac"));
04515                 $this->tpl->setVariable("TEXT_CSV", $this->lng->txt("exp_type_spss"));
04516                 $this->tpl->setVariable("BTN_EXPORT", $this->lng->txt("export"));
04517                 $this->tpl->setVariable("BTN_PRINT", $this->lng->txt("print"));
04518                 $this->tpl->setVariable("BTN_COMMAND", $this->ctrl->getCmd());
04519                 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
04520                 $this->tpl->parseCurrentBlock();
04521                 
04522                 $this->tpl->setCurrentBlock("adm_content");
04523                 $this->tpl->setVariable("TXT_STATISTICAL_DATA", $this->lng->txt("statistical_data"));
04524                 $this->tpl->parseCurrentBlock();
04525                 if ($print)
04526                 {
04527                         $this->tpl->setCurrentBlock("__global__");
04528                         $this->tpl->setVariable("TXT_STATISTICAL_EVALUATION", $this->lng->txt("tst_statistical_evaluation") . " " . strtolower($this->lng->txt("of")) . " &quot;" . ilUtil::prepareFormOutput($this->object->getTitle()) . "&quot;");
04529                         $this->tpl->setVariable("PRINT_CSS", "./templates/default/print.css");
04530                         $this->tpl->setVariable("PRINT_TYPE", "summary");
04531                         $this->tpl->show();
04532                         exit;
04533                 }
04534         }
04535         
04536         function evalAllUsersObject()
04537         {
04538                 $this->evalSelectedUsersObject(1);
04539         }
04540         
04541         function eval_aObject()
04542         {
04543                 $this->setAggregatedResultsTabs();
04544                 $color_class = array("tblrow1", "tblrow2");
04545                 $counter = 0;
04546                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_eval_anonymous_aggregation.html", true);
04547                 $total_persons = $this->object->evalTotalPersons();
04548                 if ($total_persons) {
04549                         $this->tpl->setCurrentBlock("row");
04550                         $this->tpl->setVariable("TXT_RESULT", $this->lng->txt("tst_eval_total_persons"));
04551                         $this->tpl->setVariable("TXT_VALUE", $total_persons);
04552                         $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
04553                         $counter++;
04554                         $this->tpl->parseCurrentBlock();
04555                         $this->tpl->setCurrentBlock("row");
04556                         $this->tpl->setVariable("TXT_RESULT", $this->lng->txt("tst_eval_total_finished"));
04557                         $total_finished = $this->object->evalTotalFinished();
04558                         $this->tpl->setVariable("TXT_VALUE", $total_finished);
04559                         $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
04560                         $counter++;
04561                         $this->tpl->parseCurrentBlock();
04562                         $this->tpl->setCurrentBlock("row");
04563                         $average_time = $this->object->evalTotalFinishedAverageTime();
04564                         $diff_seconds = $average_time;
04565                         $diff_hours    = floor($diff_seconds/3600);
04566                         $diff_seconds -= $diff_hours   * 3600;
04567                         $diff_minutes  = floor($diff_seconds/60);
04568                         $diff_seconds -= $diff_minutes * 60;
04569                         $this->tpl->setVariable("TXT_RESULT", $this->lng->txt("tst_eval_total_finished_average_time"));
04570                         $this->tpl->setVariable("TXT_VALUE", sprintf("%02d:%02d:%02d", $diff_hours, $diff_minutes, $diff_seconds));
04571                         $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
04572                         $counter++;
04573                         $passed_tests = $this->object->evalTotalFinishedPassed();
04574                         $this->tpl->parseCurrentBlock();
04575                         $this->tpl->setCurrentBlock("row");
04576                         $this->tpl->setVariable("TXT_RESULT", $this->lng->txt("tst_eval_total_passed"));
04577                         $this->tpl->setVariable("TXT_VALUE", $passed_tests["total_passed"]);
04578                         $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
04579                         $counter++;
04580                         $this->tpl->parseCurrentBlock();
04581                         $this->tpl->setCurrentBlock("row");
04582                         $this->tpl->setVariable("TXT_RESULT", $this->lng->txt("tst_eval_total_passed_average_points"));
04583                         $this->tpl->setVariable("TXT_VALUE", sprintf("%2.2f", $passed_tests["average_points"]) . " " . strtolower($this->lng->txt("of")) . " " . sprintf("%2.2f", $passed_tests["maximum_points"]));
04584                         $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
04585                         $counter++;
04586                         $this->tpl->parseCurrentBlock();
04587                 } else {
04588                         $this->tpl->setCurrentBlock("emptyrow");
04589                         $this->tpl->setVariable("TXT_NO_ANONYMOUS_AGGREGATION", $this->lng->txt("tst_eval_no_anonymous_aggregation"));
04590                         $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
04591                         $this->tpl->parseCurrentBlock();
04592                 }
04593                 $this->tpl->setCurrentBlock("adm_content");
04594                 $this->tpl->setVariable("TXT_ANON_EVAL", $this->lng->txt("tst_anon_eval"));
04595                 $this->tpl->setVariable("TXT_RESULT", $this->lng->txt("result"));
04596                 $this->tpl->setVariable("TXT_VALUE", $this->lng->txt("value"));
04597                 $this->tpl->parseCurrentBlock();
04598         }
04599 
04607         function confirmDeleteResults() 
04608         {
04609                 $add_parameter = $this->getAddParameter();
04610                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_delete_results_confirm.html", true);
04611                 $this->tpl->setCurrentBlock("adm_content");
04612                 $this->tpl->setVariable("TEXT_CONFIRM_DELETE_RESULTS", $this->lng->txt("tst_confirm_delete_results"));
04613                 $this->tpl->setVariable("BTN_CANCEL", $this->lng->txt("cancel"));
04614                 $this->tpl->setVariable("BTN_OK", $this->lng->txt("tst_delete_results"));
04615                 $this->tpl->setVariable("FORM_ACTION", $this->getCallingScript() . $add_parameter);
04616                 $this->tpl->parseCurrentBlock();
04617         }
04618 
04626         function outTestResults($print = false) {
04627                 global $ilUser;
04628 
04629                 function sort_percent($a, $b) {
04630                         if (strcmp($_GET["order"], "ASC")) {
04631                                 $smaller = 1;
04632                                 $greater = -1;
04633                         } else {
04634                                 $smaller = -1;
04635                                 $greater = 1;
04636                         }
04637                         if ($a["percent"] == $b["percent"]) {
04638                                 if ($a["nr"] == $b["nr"]) return 0;
04639                                 return ($a["nr"] < $b["nr"]) ? -1 : 1;
04640                         }
04641                         return ($a["percent"] < $b["percent"]) ? $smaller : $greater;
04642                 }
04643 
04644                 function sort_nr($a, $b) {
04645                         if (strcmp($_GET["order"], "ASC")) {
04646                                 $smaller = 1;
04647                                 $greater = -1;
04648                         } else {
04649                                 $smaller = -1;
04650                                 $greater = 1;
04651                         }
04652                         if ($a["nr"] == $b["nr"]) return 0;
04653                         return ($a["nr"] < $b["nr"]) ? $smaller : $greater;
04654                 }
04655 
04656                 $add_parameter = $this->getAddParameter();
04657                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_finish.html", true);
04658                 $user_id = $ilUser->id;
04659                 $color_class = array("tblrow1", "tblrow2");
04660                 $counter = 0;
04661                 $this->tpl->addBlockFile("TEST_RESULTS", "results", "tpl.il_as_tst_results.html", true);
04662                 $result_array =& $this->object->getTestResult($user_id);
04663 
04664                 if (!$result_array["test"]["total_max_points"])
04665                 {
04666                         $percentage = 0;
04667                 }
04668                 else
04669                 {
04670                         $percentage = ($result_array["test"]["total_reached_points"]/$result_array["test"]["total_max_points"])*100;
04671                 }
04672                 $total_max = $result_array["test"]["total_max_points"];
04673                 $total_reached = $result_array["test"]["total_reached_points"];
04674                 $img_title_percent = "";
04675                 $img_title_nr = "";
04676                 switch ($_GET["sortres"]) {
04677                         case "percent":
04678                                 usort($result_array, "sort_percent");
04679                                 $img_title_percent = " <img src=\"" . ilUtil::getImagePath(strtolower($_GET["order"]) . "_order.png", true) . "\" alt=\"\" />";
04680                                 if (strcmp($_GET["order"], "ASC") == 0) {
04681                                         $sortpercent = "DESC";
04682                                 } else {
04683                                         $sortpercent = "ASC";
04684                                 }
04685                                 break;
04686                         case "nr":
04687                                 usort($result_array, "sort_nr");
04688                                 $img_title_nr = " <img src=\"" . ilUtil::getImagePath(strtolower($_GET["order"]) . "_order.png", true) . "\" alt=\"\" />";
04689                                 if (strcmp($_GET["order"], "ASC") == 0) {
04690                                         $sortnr = "DESC";
04691                                 } else {
04692                                         $sortnr = "ASC";
04693                                 }
04694                                 break;
04695                 }
04696                 if (!$sortpercent) {
04697                         $sortpercent = "ASC";
04698                 }
04699                 if (!$sortnr) {
04700                         $sortnr = "ASC";
04701                 }
04702 
04703                 foreach ($result_array as $key => $value) {
04704                         if (preg_match("/\d+/", $key)) {
04705                                 $this->tpl->setCurrentBlock("question");
04706                                 $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
04707                                 $this->tpl->setVariable("VALUE_QUESTION_COUNTER", $value["nr"]);
04708                                 if ($this->object->isOnlineTest())
04709                                         $this->tpl->setVariable("VALUE_QUESTION_TITLE", preg_replace("/<a[^>]*>(.*?)<\/a>/i","\\1", $value["title"]));
04710                                 else
04711                                         $this->tpl->setVariable("VALUE_QUESTION_TITLE", $value["title"]);
04712                                 $this->tpl->setVariable("VALUE_MAX_POINTS", $value["max"]);
04713                                 $this->tpl->setVariable("VALUE_REACHED_POINTS", $value["reached"]);
04714                                 if (preg_match("/http/", $value["solution"]))
04715                                 {
04716                                         $this->tpl->setVariable("SOLUTION_HINT", "<a href=\"".$value["solution"]."\" target=\"content\">" . $this->lng->txt("solution_hint"). "</a>");
04717                                 }
04718                                 else
04719                                 {
04720                                         if ($value["solution"])
04721                                         {
04722                                                 $this->tpl->setVariable("SOLUTION_HINT", $this->lng->txt($value["solution"]));
04723                                         }
04724                                         else
04725                                         {
04726                                                 $this->tpl->setVariable("SOLUTION_HINT", "");
04727                                         }
04728                                 }
04729                                 $this->tpl->setVariable("VALUE_PERCENT_SOLVED", $value["percent"]);
04730                                 $this->tpl->parseCurrentBlock();
04731                                 $counter++;
04732                         }
04733                 }
04734 
04735                 $this->tpl->setCurrentBlock("question");
04736                 $this->tpl->setVariable("COLOR_CLASS", "std");
04737                 $this->tpl->setVariable("VALUE_QUESTION_COUNTER", "<strong>" . $this->lng->txt("total") . "</strong>");
04738                 $this->tpl->setVariable("VALUE_QUESTION_TITLE", "");
04739                 $this->tpl->setVariable("SOLUTION_HINT", "");
04740                 $this->tpl->setVariable("VALUE_MAX_POINTS", "<strong>" . sprintf("%d", $total_max) . "</strong>");
04741                 $this->tpl->setVariable("VALUE_REACHED_POINTS", "<strong>" . sprintf("%d", $total_reached) . "</strong>");
04742                 $this->tpl->setVariable("VALUE_PERCENT_SOLVED", "<strong>" . sprintf("%2.2f", $percentage) . " %" . "</strong>");
04743                 $this->tpl->parseCurrentBlock();
04744 
04745                 $this->tpl->setCurrentBlock("results");
04746                 $this->tpl->setVariable("QUESTION_COUNTER", "<a href=\"" . $this->getCallingScript() . "$add_parameter&sortres=nr&order=$sortnr\">" . $this->lng->txt("tst_question_no") . "</a>$img_title_nr");
04747                 $this->tpl->setVariable("QUESTION_TITLE", $this->lng->txt("tst_question_title"));
04748                 $this->tpl->setVariable("SOLUTION_HINT_HEADER", $this->lng->txt("solution_hint"));
04749                 $this->tpl->setVariable("MAX_POINTS", $this->lng->txt("tst_maximum_points"));
04750                 $this->tpl->setVariable("REACHED_POINTS", $this->lng->txt("tst_reached_points"));
04751                 $this->tpl->setVariable("PERCENT_SOLVED", "<a href=\"" . $this->getCallingScript() . "$add_parameter&sortres=percent&order=$sortpercent\">" . $this->lng->txt("tst_percent_solved") . "</a>$img_title_percent");
04752                 $mark_obj = $this->object->mark_schema->get_matching_mark($percentage);
04753                 if ($mark_obj)
04754                 {
04755                         if ($mark_obj->get_passed()) {
04756                                 $mark = $this->lng->txt("tst_result_congratulations");
04757                         } else {
04758                                 $mark = $this->lng->txt("tst_result_sorry");
04759                         }
04760                         $mark .= "<br />" . $this->lng->txt("tst_your_mark_is") . ": &quot;" . $mark_obj->get_official_name() . "&quot;";
04761                 }
04762                 if ($this->object->ects_output)
04763                 {
04764                         $ects_mark = $this->object->getECTSGrade($total_reached, $total_max);
04765                         $mark .= "<br />" . $this->lng->txt("tst_your_ects_mark_is") . ": &quot;" . $ects_mark . "&quot; (" . $this->lng->txt("ects_grade_". strtolower($ects_mark) . "_short") . ": " . $this->lng->txt("ects_grade_". strtolower($ects_mark)) . ")";
04766                 }
04767                 $this->tpl->setVariable("USER_FEEDBACK", $mark);
04768                 $this->tpl->parseCurrentBlock();
04769                 $this->tpl->setCurrentBlock("test_user_name");
04770                 $this->tpl->setVariable("USER_NAME", sprintf($this->lng->txt("tst_result_user_name"), $ilUser->getFullname()));
04771                 $this->tpl->parseCurrentBlock();
04772                 
04773                 $this->tpl->setCurrentBlock("adm_content");
04774                 $this->tpl->setVariable("TEXT_RESULTS", $this->lng->txt("tst_results"));
04775                 $this->tpl->parseCurrentBlock();
04776         }
04777 
04785         function deleteAllUserDataObject()
04786         {
04787                 sendInfo($this->lng->txt("confirm_delete_all_user_data"));
04788                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_maintenance.html", true);
04789 
04790                 $this->tpl->setCurrentBlock("confirm_delete");
04791                 $this->tpl->setVariable("BTN_CONFIRM_DELETE_ALL", $this->lng->txt("confirm"));
04792                 $this->tpl->setVariable("BTN_CANCEL_DELETE_ALL", $this->lng->txt("cancel"));
04793                 $this->tpl->parseCurrentBlock();
04794 
04795                 $this->tpl->setCurrentBlock("adm_content");
04796                 $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
04797                 $this->tpl->parseCurrentBlock();
04798         }
04799         
04807         function confirmDeleteAllUserDataObject()
04808         {
04809                 $this->object->removeAllTestEditings();
04810                 sendInfo($this->lng->txt("tst_all_user_data_deleted"), true);
04811                 $this->ctrl->redirect($this, "maintenance");
04812         }
04813         
04821         function cancelDeleteAllUserDataObject()
04822         {
04823                 $this->ctrl->redirect($this, "maintenance");
04824         }
04825         
04835         function createSolutionsObject()
04836         {
04837                 $this->object->createRandomSolutionsForAllUsers();
04838                 $this->ctrl->redirect($this, "maintenance");
04839         }
04840 
04848         function maintenanceObject()
04849         {
04850                 global $rbacsystem;
04851 
04852                 if ((!$rbacsystem->checkAccess("read", $this->ref_id)) && (!$rbacsystem->checkAccess("write", $this->ref_id))) 
04853                 {
04854                         // allow only read and write access
04855                         sendInfo($this->lng->txt("cannot_edit_test"), true);
04856                         $path = $this->tree->getPathFull($this->object->getRefID());
04857                         ilUtil::redirect($this->getReturnLocation("cancel","../repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
04858                         return;
04859                 }
04860                 
04861                 if ($rbacsystem->checkAccess("write", $this->ref_id)) {
04862                         $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_maintenance.html", true);
04863                         $this->tpl->setCurrentBlock("adm_content");
04864                         $this->tpl->setVariable("BTN_DELETE_ALL", $this->lng->txt("tst_delete_all_user_data"));
04865 //                      $this->tpl->setVariable("BTN_CREATE_SOLUTIONS", $this->lng->txt("tst_create_solutions"));
04866                         $this->tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
04867                         $this->tpl->parseCurrentBlock();
04868                 }
04869                 else
04870                 {
04871                         sendInfo($this->lng->txt("cannot_maintain_test"));
04872                 }
04873         }       
04874 
04882         function statusObject()
04883         {
04884                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_status.html", true);
04885                 if (!$this->object->isComplete())
04886                 {
04887                         if (!$this->object->isRandomTest())
04888                         {
04889                                 if (count($this->object->questions) == 0)
04890                                 {
04891                                         $this->tpl->setCurrentBlock("list_element");
04892                                         $this->tpl->setVariable("TEXT_ELEMENT", $this->lng->txt("tst_missing_questions"));
04893                                         $this->tpl->parseCurrentBlock();
04894                                 }
04895                         }
04896                         if (count($this->object->mark_schema->mark_steps) == 0)
04897                         {
04898                                 $this->tpl->setCurrentBlock("list_element");
04899                                 $this->tpl->setVariable("TEXT_ELEMENT", $this->lng->txt("tst_missing_marks"));
04900                                 $this->tpl->parseCurrentBlock();
04901                         }
04902                         if (strcmp($this->object->author, "") == 0)
04903                         {
04904                                 $this->tpl->setCurrentBlock("list_element");
04905                                 $this->tpl->setVariable("TEXT_ELEMENT", $this->lng->txt("tst_missing_author"));
04906                                 $this->tpl->parseCurrentBlock();
04907                         }
04908                         if (strcmp($this->object->title, "") == 0)
04909                         {
04910                                 $this->tpl->setCurrentBlock("list_element");
04911                                 $this->tpl->setVariable("TEXT_ELEMENT", $this->lng->txt("tst_missing_author"));
04912                                 $this->tpl->parseCurrentBlock();
04913                         }
04914                         
04915                         if ($this->object->isRandomTest())
04916                         {
04917                                 $arr = $this->object->getRandomQuestionpools();
04918                                 if (count($arr) == 0)
04919                                 {
04920                                         $this->tpl->setCurrentBlock("list_element");
04921                                         $this->tpl->setVariable("TEXT_ELEMENT", $this->lng->txt("tst_no_questionpools_for_random_test"));
04922                                         $this->tpl->parseCurrentBlock();
04923                                 }
04924                                 $count = 0;
04925                                 foreach ($arr as $array)
04926                                 {
04927                                         $count += $array["count"];
04928                                 }
04929                                 if (($count == 0) && ($this->object->getRandomQuestionCount() == 0))
04930                                 {
04931                                         $this->tpl->setCurrentBlock("list_element");
04932                                         $this->tpl->setVariable("TEXT_ELEMENT", $this->lng->txt("tst_no_questions_for_random_test"));
04933                                         $this->tpl->parseCurrentBlock();
04934                                 }
04935                         }
04936                         
04937                         $this->tpl->setCurrentBlock("status_list");
04938                         $this->tpl->setVariable("TEXT_MISSING_ELEMENTS", $this->lng->txt("tst_status_missing_elements"));
04939                         $this->tpl->parseCurrentBlock();
04940                 }
04941                 $total = $this->object->evalTotalPersons();
04942                 if ($total > 0)
04943                 {
04944                         $this->tpl->setCurrentBlock("list_element");
04945                         $this->tpl->setVariable("TEXT_ELEMENT", sprintf($this->lng->txt("tst_in_use_edit_questions_disabled"), $total));
04946                         $this->tpl->parseCurrentBlock();
04947                 }
04948                 $this->tpl->setCurrentBlock("adm_content");
04949                 if ($this->object->isComplete())
04950                 {
04951                         $this->tpl->setVariable("TEXT_STATUS_MESSAGE", $this->lng->txt("tst_status_ok"));
04952                         $this->tpl->setVariable("STATUS_CLASS", "bold");
04953                 }
04954                 else
04955                 {
04956                         $this->tpl->setVariable("TEXT_STATUS_MESSAGE", $this->lng->txt("tst_status_missing"));
04957                         $this->tpl->setVariable("STATUS_CLASS", "warning");
04958                 }
04959                 $this->tpl->parseCurrentBlock();
04960         }       
04961 
04970         function setLocator($a_tree = "", $a_id = "", $scriptname="repository.php")
04971         {
04972 //              global $ilias_locator;
04973                 $ilias_locator = new ilLocatorGUI(false);
04974                 if (!is_object($a_tree))
04975                 {
04976                         $a_tree =& $this->tree;
04977                 }
04978                 if (!($a_id))
04979                 {
04980                         $a_id = $_GET["ref_id"];
04981                 }
04982 
04983                 //$this->tpl->addBlockFile("LOCATOR", "locator", "tpl.locator.html");
04984 
04985                 $path = $a_tree->getPathFull($a_id);
04986                 //check if object isn't in tree, this is the case if parent_parent is set
04987                 // TODO: parent_parent no longer exist. need another marker
04988                 if ($a_parent_parent)
04989                 {
04990                         //$subObj = getObject($a_ref_id);
04991                         $subObj =& $this->ilias->obj_factory->getInstanceByRefId($a_ref_id);
04992 
04993                         $path[] = array(
04994                                 "id"     => $a_ref_id,
04995                                 "title"  => $this->lng->txt($subObj->getTitle())
04996                                 );
04997                 }
04998 
04999                 // this is a stupid workaround for a bug in PEAR:IT
05000                 $modifier = 1;
05001 
05002                 if (isset($_GET["obj_id"]))
05003                 {
05004                         $modifier = 0;
05005                 }
05006 
05007                 // ### AA 03.11.10 added new locator GUI class ###
05008                 $i = 1;
05009                 if (!defined("ILIAS_MODULE")) {
05010                         foreach ($path as $key => $row)
05011                         {
05012                                 $ilias_locator->navigate($i++, $row["title"], 
05013                                                                                  ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH).
05014                                                                                  "/adm_object.php?ref_id=".$row["child"],"");
05015                         }
05016                 } else {
05017                         
05018                         // Workaround for crs_objectives
05019                         $frameset = $_GET['crs_show_result'] ? '' : 'cmd=frameset&';
05020 
05021                         foreach ($path as $key => $row)
05022                         {
05023                                 if (strcmp($row["title"], "ILIAS") == 0) {
05024                                         $row["title"] = $this->lng->txt("repository");
05025                                 }
05026                                 if ($this->ref_id == $row["child"]) {
05027                                         if ($_GET["cmd"]) {
05028                                                 $param = "&cmd=" . $_GET["cmd"];
05029                                         } else {
05030                                                 $param = "";
05031                                         }
05032                                         $ilias_locator->navigate($i++, $row["title"], 
05033                                                                                          ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . 
05034                                                                                          "/assessment/test.php" . "?crs_show_result=".$_GET['crs_show_result'].
05035                                                                                          "&ref_id=".$row["child"] . $param,"");
05036 
05037                                         if ($this->sequence) {
05038                                                 if (($this->sequence <= $this->object->getQuestionCount()) and (!$_POST["cmd"]["showresults"])) {
05039                                                         $ilias_locator->navigate($i++, $this->object->getQuestionTitle($this->sequence), 
05040                                                                                                          ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . 
05041                                                                                                          "/assessment/test.php" . "?crs_show_result=".$_GET['crs_show_result'].
05042                                                                                                          "&ref_id=".$row["child"] . $param . 
05043                                                                                                          "&sequence=" . $this->sequence,"");
05044                                                 } else {
05045                                                 }
05046                                                 /*if ($_POST["cmd"]["summary"] or isset($_GET["sort_summary"]))
05047                                                 {
05048                                                 $ilias_locator->navigate($i++, $this->lng->txt("summary"), 
05049                                                                                                          ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . 
05050                                                                                                          "/assessment/test.php" . "?crs_show_result=0".
05051                                                                                                          "&ref_id=".$row["child"] . $param . 
05052                                                                                                  "&sequence=" . $_GET["sequence"]."&order=".$_GET["order"]."&sort_summary=".$_GET["sort_summary"],"");
05053                                                 }*/
05054                                         } else {
05055                                                 if ($_POST["cmd"]["summary"] or isset($_GET["sort_summary"]))
05056                                                 {
05057                                                         $ilias_locator->navigate($i++, $this->lng->txt("summary"), 
05058                                                                                                          ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . 
05059                                                                                                          "/assessment/test.php" . "?crs_show_result=0".
05060                                                                                                          "&ref_id=".$row["child"] . $param . 
05061                                                                                                  "&sequence=" . $_GET["sequence"]."&order=".$_GET["order"]."&sort_summary=".$_GET["sort_summary"],"");
05062                                                 }/* elseif ($_POST["cmd"]["show_answers"])
05063                                                 {
05064                                                         $ilias_locator->navigate($i++, $this->lng->txt("preview"), 
05065                                                                                                          ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . 
05066                                                                                                          "/assessment/test.php" . "?crs_show_result=0".
05067                                                                                                          "&ref_id=".$row["child"] . $param . 
05068                                                                                                  "&sequence=" . $_GET["sequence"]."&order=".$_GET["order"]."&sort_summary=".$_GET["sort_summary"],"");
05069                                                         
05070                                                 }                                               
05071                                                 elseif ($_POST["cmd"]["submit_answers"])
05072                                                 {
05073                                                         $ilias_locator->navigate($i++, $this->lng->txt("submit"), 
05074                                                                                                          ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . 
05075                                                                                                          "/assessment/test.php" . "?crs_show_result=0".
05076                                                                                                          "&ref_id=".$row["child"] . $param . 
05077                                                                                                  "&sequence=" . $_GET["sequence"]."&order=".$_GET["order"]."&sort_summary=".$_GET["sort_summary"],"");
05078                                                         
05079                                                 }*/
05080                                         }
05081                                 } else {
05082                                         $ilias_locator->navigate($i++, $row["title"], 
05083                                                                                          ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH) . "/" . 
05084                                                                                          $scriptname."?".$frameset."ref_id=".$row["child"],"");
05085                                 }
05086                         }
05087 
05088                         if (isset($_GET["obj_id"]))
05089                         {
05090                                 $obj_data =& $this->ilias->obj_factory->getInstanceByObjId($_GET["obj_id"]);
05091                                 $ilias_locator->navigate($i++,$obj_data->getTitle(),
05092                                                                                  $scriptname."?".$frameset."ref_id=".$_GET["ref_id"]."&obj_id=".$_GET["obj_id"],"");
05093                         }
05094                 }
05095                 $ilias_locator->output();
05096         }
05097 
05098 /*
05099         function editMetaObject()
05100         {
05101                 $meta_gui =& new ilMetaDataGUI();
05102                 $meta_gui->setObject($this->object);
05103                 $meta_gui->edit("ADM_CONTENT", "adm_content",
05104                         $this->getTabTargetScript()."?ref_id=".$_GET["ref_id"]."&cmd=saveMeta");
05105         }
05106 
05107         function saveMetaObject()
05108         {
05109                 $meta_gui =& new ilMetaDataGUI();
05110                 $meta_gui->setObject($this->object);
05111                 $meta_gui->save($_POST["meta_section"]);
05112                 if (!strcmp($_POST["meta_section"], "General")) {
05113                         $meta = $_POST["meta"];
05114                         $this->object->setTitle(ilUtil::stripSlashes($meta["Title"]["Value"]));
05115                         $this->object->setDescription(ilUtil::stripSlashes($meta["Description"][0]["Value"]));
05116                         $this->object->update();
05117                 }
05118                 ilUtil::redirect($this->getTabTargetScript()."?ref_id=".$_GET["ref_id"]."&cmd=editMeta");
05119         }
05120 
05121         // called by administration
05122         function chooseMetaSectionObject($a_script = "",
05123                 $a_templ_var = "ADM_CONTENT", $a_templ_block = "adm_content")
05124         {
05125                 if ($a_script == "")
05126                 {
05127                         $a_script = $this->getTabTargetScript()."?ref_id=".$_GET["ref_id"];
05128                 }
05129                 $meta_gui =& new ilMetaDataGUI();
05130                 $meta_gui->setObject($this->object);
05131                 $meta_gui->edit($a_templ_var, $a_templ_block, $a_script, $_REQUEST["meta_section"]);
05132         }
05133 
05134         // called by editor
05135         function chooseMetaSection()
05136         {
05137                 $this->chooseMetaSectionObject($this->getTabTargetScript()."?ref_id=".
05138                         $this->object->getRefId());
05139         }
05140 
05141         function addMetaObject($a_script = "",
05142                 $a_templ_var = "ADM_CONTENT", $a_templ_block = "adm_content")
05143         {
05144                 if ($a_script == "")
05145                 {
05146                         $a_script = $this->getTabTargetScript()."?ref_id=".$_GET["ref_id"];
05147                 }
05148                 $meta_gui =& new ilMetaDataGUI();
05149                 $meta_gui->setObject($this->object);
05150                 $meta_name = $_POST["meta_name"] ? $_POST["meta_name"] : $_GET["meta_name"];
05151                 $meta_index = $_POST["meta_index"] ? $_POST["meta_index"] : $_GET["meta_index"];
05152                 if ($meta_index == "")
05153                         $meta_index = 0;
05154                 $meta_path = $_POST["meta_path"] ? $_POST["meta_path"] : $_GET["meta_path"];
05155                 $meta_section = $_POST["meta_section"] ? $_POST["meta_section"] : $_GET["meta_section"];
05156                 if ($meta_name != "")
05157                 {
05158                         $meta_gui->meta_obj->add($meta_name, $meta_path, $meta_index);
05159                 }
05160                 else
05161                 {
05162                         sendInfo($this->lng->txt("meta_choose_element"), true);
05163                 }
05164                 $meta_gui->edit($a_templ_var, $a_templ_block, $a_script, $meta_section);
05165         }
05166 
05167         function addMeta()
05168         {
05169                 $this->addMetaObject($this->getTabTargetScript()."?ref_id=".
05170                         $this->object->getRefId());
05171         }
05172 
05173         function deleteMetaObject($a_script = "",
05174                 $a_templ_var = "ADM_CONTENT", $a_templ_block = "adm_content")
05175         {
05176                 if ($a_script == "")
05177                 {
05178                         $a_script = $this->getTabTargetScript()."?ref_id=".$_GET["ref_id"];
05179                 }
05180                 $meta_gui =& new ilMetaDataGUI();
05181                 $meta_gui->setObject($this->object);
05182                 $meta_index = $_POST["meta_index"] ? $_POST["meta_index"] : $_GET["meta_index"];
05183                 $meta_gui->meta_obj->delete($_GET["meta_name"], $_GET["meta_path"], $meta_index);
05184                 $meta_gui->edit($a_templ_var, $a_templ_block, $a_script, $_GET["meta_section"]);
05185         }
05186 
05187         function deleteMeta()
05188         {
05189                 $this->deleteMetaObject($this->getTabTargetScript()."?ref_id=".
05190                         $this->object->getRefId());
05191         }
05192 */
05196         function createObject()
05197         {
05198                 global $rbacsystem;
05199                 $new_type = $_POST["new_type"] ? $_POST["new_type"] : $_GET["new_type"];
05200                 if (!$rbacsystem->checkAccess("create", $_GET["ref_id"], $new_type))
05201                 {
05202                         $this->ilias->raiseError($this->lng->txt("permission_denied"),$this->ilias->error_obj->MESSAGE);
05203                 }
05204                 else
05205                 {
05206                         $this->getTemplateFile("create", $new_type);
05207 
05208                         include_once("./assessment/classes/class.ilObjTest.php");
05209                         $tst = new ilObjTest();
05210                         
05211                         $tests =& ilObjTest::_getAvailableTests(true);
05212                         if (count($tests) > 0)
05213                         {
05214                                 foreach ($tests as $key => $value)
05215                                 {
05216                                         $this->tpl->setCurrentBlock("option_tst");
05217                                         $this->tpl->setVariable("OPTION_VALUE_TST", $key);
05218                                         $this->tpl->setVariable("TXT_OPTION_TST", $value);
05219                                         if ($_POST["tst"] == $key)
05220                                         {
05221                                                 $this->tpl->setVariable("OPTION_SELECTED_TST", " selected=\"selected\"");                               
05222                                         }
05223                                         $this->tpl->parseCurrentBlock();
05224                                 }
05225                         }
05226                         
05227                         $questionpools =& $tst->getAvailableQuestionpools(true);
05228                         if (count($questionpools) == 0)
05229                         {
05230                         }
05231                         else
05232                         {
05233                                 foreach ($questionpools as $key => $value)
05234                                 {
05235                                         $this->tpl->setCurrentBlock("option_qpl");
05236                                         $this->tpl->setVariable("OPTION_VALUE", $key);
05237                                         $this->tpl->setVariable("TXT_OPTION", $value);
05238                                         if ($_POST["qpl"] == $key)
05239                                         {
05240                                                 $this->tpl->setVariable("OPTION_SELECTED", " selected=\"selected\"");                           
05241                                         }
05242                                         $this->tpl->parseCurrentBlock();
05243                                 }
05244                         }
05245                         // fill in saved values in case of error
05246                         $data = array();
05247                         $data["fields"] = array();
05248                         $data["fields"]["title"] = ilUtil::prepareFormOutput($_SESSION["error_post_vars"]["Fobject"]["title"],true);
05249                         $data["fields"]["desc"] = ilUtil::stripSlashes($_SESSION["error_post_vars"]["Fobject"]["desc"]);
05250 
05251                         foreach ($data["fields"] as $key => $val)
05252                         {
05253                                 $this->tpl->setVariable("TXT_".strtoupper($key), $this->lng->txt($key));
05254                                 $this->tpl->setVariable(strtoupper($key), $val);
05255 
05256                                 if ($this->prepare_output)
05257                                 {
05258                                         $this->tpl->parseCurrentBlock();
05259                                 }
05260                         }
05261 
05262                         $this->tpl->setVariable("FORMACTION", $this->getFormAction("save","adm_object.php?cmd=gateway&ref_id=".
05263                                                                                                                                            $_GET["ref_id"]."&new_type=".$new_type));
05264                         $this->tpl->setVariable("TXT_HEADER", $this->lng->txt($new_type."_new"));
05265                         $this->tpl->setVariable("TXT_SELECT_QUESTIONPOOL", $this->lng->txt("select_questionpool"));
05266                         $this->tpl->setVariable("OPTION_SELECT_QUESTIONPOOL", $this->lng->txt("select_questionpool_option"));
05267                         $this->tpl->setVariable("TXT_CANCEL", $this->lng->txt("cancel"));
05268                         $this->tpl->setVariable("TXT_SUBMIT", $this->lng->txt($new_type."_add"));
05269                         $this->tpl->setVariable("CMD_SUBMIT", "save");
05270                         $this->tpl->setVariable("TARGET", $this->getTargetFrame("save"));
05271                         $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
05272 
05273                         $this->tpl->setVariable("TXT_IMPORT_TST", $this->lng->txt("import_tst"));
05274                         $this->tpl->setVariable("TXT_TST_FILE", $this->lng->txt("tst_upload_file"));
05275                         $this->tpl->setVariable("TXT_IMPORT", $this->lng->txt("import"));
05276 
05277                         $this->tpl->setVariable("TXT_DUPLICATE_TST", $this->lng->txt("duplicate_tst"));
05278                         $this->tpl->setVariable("TXT_SELECT_TST", $this->lng->txt("obj_tst"));
05279                         $this->tpl->setVariable("OPTION_SELECT_TST", $this->lng->txt("select_tst_option"));
05280                         $this->tpl->setVariable("TXT_DUPLICATE", $this->lng->txt("duplicate"));
05281                         $this->tpl->setVariable("NEW_TYPE", $this->type);
05282                         $this->tpl->parseCurrentBlock();
05283                 }
05284         }
05285 
05286         function prepareOutput()
05287         {
05288                 $this->tpl->addBlockFile("CONTENT", "content", "tpl.adm_content.html");
05289                 $this->tpl->addBlockFile("STATUSLINE", "statusline", "tpl.statusline.html");
05290                 $title = $this->object->getTitle();
05291                 // catch feedback message
05292                 sendInfo();
05293 
05294                 if (!empty($title))
05295                 {
05296                         $this->tpl->setVariable("HEADER", $title);
05297                 }
05298                 if (!defined("ILIAS_MODULE"))
05299                 {
05300                         $this->setAdminTabs($_POST["new_type"]);
05301                 }
05302                 $this->setLocator();
05303 
05304         }
05305         
05306         function setAggregatedResultsTabs()
05307         {
05308                 global $rbacsystem;
05309 
05310                 include_once "./classes/class.ilTabsGUI.php";
05311                 $tabs_gui =& new ilTabsGUI();
05312                 
05313                 $path = $this->tree->getPathFull($this->object->getRefID());
05314                 $addcmd = "";
05315                 if (strcmp($_SESSION["il_rep_mode"], "tree") == 0)
05316                 {
05317                         $addcmd = "&cmd=frameset";
05318                 }
05319                 $tabs_gui->addTarget("back", $this->getReturnLocation("cancel","../repository.php?ref_id=" . $path[count($path) - 2]["child"]) . $addcmd, "",   "");
05320                 $this->tpl->setVariable("TABS", $tabs_gui->getHTML());
05321         }
05322         
05323         function setEvaluationSettingsTabs()
05324         {
05325                 global $rbacsystem;
05326 
05327                 include_once "./classes/class.ilTabsGUI.php";
05328                 $tabs_gui =& new ilTabsGUI();
05329                 
05330                 $path = $this->tree->getPathFull($this->object->getRefID());
05331                 $tabs_gui->addTarget("eval_all_users", $this->ctrl->getLinkTargetByClass(get_class($this), "eval_stat"), "eval_stat",   "ilobjtestgui");
05332                 $tabs_gui->addTarget("eval_selected_users", $this->ctrl->getLinkTargetByClass(get_class($this), "evalStatSelected"), "evalStatSelected",        "ilobjtestgui");
05333                 $this->tpl->setVariable("TABS", $tabs_gui->getHTML());
05334         }
05335         
05336         function setEvaluationTabs($all_users = 0)
05337         {
05338                 global $rbacsystem;
05339 
05340                 include_once "./classes/class.ilTabsGUI.php";
05341                 $tabs_gui =& new ilTabsGUI();
05342                 
05343                 $cmd = "evalAllUsers";
05344                 if ($all_users == 0)
05345                 {
05346                         $cmd = "evalSelectedUsers";
05347                 }
05348                 $path = $this->tree->getPathFull($this->object->getRefID());
05349                 $tabs_gui->addTarget("tst_statistical_evaluation", $this->ctrl->getLinkTargetByClass(get_class($this), "$cmd"), "$cmd", "ilobjtestgui");
05350                 $this->tpl->setVariable("TABS", $tabs_gui->getHTML());
05351         }
05352         
05360         function participantsObject()
05361         {
05362                 global $rbacsystem;
05363 
05364                 if ((!$rbacsystem->checkAccess("read", $this->ref_id)) && (!$rbacsystem->checkAccess("write", $this->ref_id))) 
05365                 {
05366                         // allow only read and write access
05367                         sendInfo($this->lng->txt("cannot_edit_test"), true);
05368                         $path = $this->tree->getPathFull($this->object->getRefID());
05369                         ilUtil::redirect($this->getReturnLocation("cancel","../repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
05370                         return;
05371                 }
05372                 
05373                 if ($this->object->getTestType() != TYPE_ONLINE_TEST) 
05374                 {
05375                         // allow only read and write access
05376                         sendInfo($this->lng->txt("tst_must_be_online_exam"), false);
05377                         return;
05378                 }
05379                 
05380                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_invite.html", true);
05381 
05382                 if ($_POST["cmd"]["cancel"])
05383                 {
05384                         $path = $this->tree->getPathFull($this->object->getRefID());
05385                         ilUtil::redirect($this->getReturnLocation("cancel",ilUtil::removeTrailingPathSeparators(ILIAS_HTTP_PATH)."/repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
05386                         exit();
05387                 }
05388 
05389                 if (count($_POST))
05390                 {
05391                         $this->handleCommands();
05392                         //return;
05393                 }
05394                 
05395                 if ($_POST["cmd"]["save"])
05396                 {
05397                         $this->object->saveToDb();
05398                 }
05399                 
05400                 {
05401                         if ($rbacsystem->checkAccess('write', $this->ref_id))
05402                         {
05403                                 $this->tpl->setCurrentBlock("invitation");
05404                                 $this->tpl->setVariable("SEARCH_INVITATION", $this->lng->txt("search"));
05405                                 $this->tpl->setVariable("SEARCH_TERM", $this->lng->txt("search_term"));
05406                                 $this->tpl->setVariable("SEARCH_FOR", $this->lng->txt("search_for"));
05407                                 $this->tpl->setVariable("SEARCH_USERS", $this->lng->txt("search_users"));
05408                                 $this->tpl->setVariable("SEARCH_GROUPS", $this->lng->txt("search_groups"));
05409                                 $this->tpl->setVariable("SEARCH_ROLES", $this->lng->txt("search_roles"));
05410                                 $this->tpl->setVariable("TEXT_CONCATENATION", $this->lng->txt("concatenation"));
05411                                 $this->tpl->setVariable("TEXT_AND", $this->lng->txt("and"));
05412                                 $this->tpl->setVariable("TEXT_OR", $this->lng->txt("or"));
05413                                 $this->tpl->setVariable("VALUE_SEARCH_TERM", $_POST["search_term"]);
05414                                 if (is_array($_POST["search_for"]))
05415                                 {
05416                                         if (in_array("usr", $_POST["search_for"]))
05417                                         {
05418                                                 $this->tpl->setVariable("CHECKED_USERS", " checked=\"checked\"");
05419                                         }
05420                                         if (in_array("grp", $_POST["search_for"]))
05421                                         {
05422                                                 $this->tpl->setVariable("CHECKED_GROUPS", " checked=\"checked\"");
05423                                         }
05424                                         if (in_array("role", $_POST["search_for"]))
05425                                         {
05426                                                 $this->tpl->setVariable("CHECKED_ROLES", " checked=\"checked\"");
05427                                         }
05428                                         
05429                                 }
05430                                 if (strcmp($_POST["concatenation"], "and") == 0)
05431                                 {
05432                                         $this->tpl->setVariable("CHECKED_AND", " checked=\"checked\"");
05433                                 }
05434                                 else if (strcmp($_POST["concatenation"], "or") == 0)
05435                                 {
05436                                         $this->tpl->setVariable("CHECKED_OR", " checked=\"checked\"");
05437                                 }
05438                                 $this->tpl->setVariable("SEARCH", $this->lng->txt("search"));
05439                                 $this->tpl->parseCurrentBlock();
05440                         }
05441                 }
05442                 $invited_users = $this->object->getInvitedUsers();
05443 
05444                 $buttons = array("save","remove","print_answers","print_results");
05445                 
05446                 if (count($invited_users))
05447                 {
05448                         $this->outUserGroupTable("iv_usr", $invited_users, "invited_user_result", "invited_user_row", $this->lng->txt("tst_participating_users"), "TEXT_INVITED_USER_TITLE",$buttons);
05449                 }
05450                 
05451                 $this->tpl->setCurrentBlock("adm_content");
05452                 $this->tpl->setVariable("TEXT_INVITATION", $this->lng->txt("invitation"));
05453                 $this->tpl->setVariable("VALUE_ON", $this->lng->txt("on"));
05454                 $this->tpl->setVariable("VALUE_OFF", $this->lng->txt("off"));
05455                 $this->tpl->setVariable("TXT_REQUIRED_FLD", $this->lng->txt("required_field"));
05456 
05457         if ($rbacsystem->checkAccess("write", $this->ref_id)) {
05458                         $this->tpl->setVariable("SAVE", $this->lng->txt("save"));
05459                         $this->tpl->setVariable("CANCEL", $this->lng->txt("cancel"));
05460                 }
05461                 $this->tpl->parseCurrentBlock();
05462         }
05463 
05471         function handleCommands()
05472         {
05473                 global $ilUser;
05474 
05475                 $message = "";
05476                 
05477                 if (is_array($_POST["invited_users"]))
05478                 {                       
05479                         if ($_POST["cmd"]["print_answers"]) {
05480                                 $this->_printAnswerSheets($_POST["invited_users"]);
05481                                 return;
05482                         } elseif ($_POST["cmd"]["print_results"]) {
05483                                 $this->_printResultSheets($_POST["invited_users"]);
05484                                 return;                                 
05485                         }
05486                         
05487                         for ($i = 0; $i < count($_POST["invited_users"]); $i++)
05488                         {
05489                                 $user_id = $_POST["invited_users"][$i]; 
05490                                 if ($_POST["cmd"]["remove"])
05491                                         $this->object->disinviteUser($user_id);                         
05492                         }
05493                 }
05494                 if (is_array($_POST["clientip"])) {
05495                         foreach ($_POST["clientip"] as $user_id => $client_ip)
05496                         {
05497                                 if ($_POST["cmd"]["save_client_ip"])
05498                                         $this->object->setClientIP($user_id, $client_ip);
05499                         }                       
05500                 }
05501                 
05502                 if ($_POST["cmd"]["add"])
05503                 {
05504                         // add users 
05505                         if (is_array($_POST["user_select"]))
05506                         {
05507                                 $i = 0;
05508                                 foreach ($_POST["user_select"] as $user_id)
05509                                 {                                       
05510                                         $client_ip = $_POST["client_ip"][$i];
05511                                         $this->object->inviteUser($user_id, $client_ip);
05512                                         $i++;                           
05513                                 }
05514                         }
05515                         // add groups members
05516                         if (is_array($_POST["group_select"]))
05517                         {
05518                                 foreach ($_POST["group_select"] as $group_id)
05519                                 {
05520                                         $this->object->inviteGroup($group_id);
05521                                 }
05522                         }
05523                         // add role members
05524                         if (is_array($_POST["role_select"]))
05525                         {
05526                                 foreach ($_POST["role_select"] as $role_id)
05527                                 {                                       
05528                                         $this->object->inviteRole($role_id);
05529                                 }
05530                         }
05531                         
05532                 }
05533 
05534                 if ($_POST["cmd"]["search"])
05535                 {
05536                         if (is_array($_POST["search_for"]))
05537                         {
05538                                 if (in_array("usr", $_POST["search_for"]) or in_array("grp", $_POST["search_for"]) or in_array("role", $_POST["search_for"]))
05539                                 {                                       
05540                                         
05541                                         $search =& new ilSearch($ilUser->id);
05542                                         $search->setSearchString($_POST["search_term"]);
05543                                         $search->setCombination($_POST["concatenation"]);
05544                                         $search->setSearchFor($_POST["search_for"]);
05545                                         $search->setSearchType("new");
05546                                         if($search->validate($message))
05547                                         {
05548                                                 $search->performSearch();
05549                                         }
05550                                         if ($message)
05551                                         {
05552                                                 sendInfo($message);
05553                                         }
05554                                         
05555                                         if(!$search->getNumberOfResults() && $search->getSearchFor())
05556                                         {
05557                                                 sendInfo($this->lng->txt("search_no_match"));
05558                                                 return;
05559                                         }
05560                                         $buttons = array("add");
05561 
05562                                         $invited_users = $this->object->getInvitedUsers();
05563                                 
05564                                         if ($searchresult = $search->getResultByType("usr"))
05565                                         {                                                                                               
05566                                                 $users = array();
05567                                                 foreach ($searchresult as $result_array)
05568                                                 {
05569                                                         if (!array_key_exists($result_array["id"], $invited_users))
05570                                                         {                                                               
05571                                                                 array_push($users, $result_array["id"]);
05572                                                         }
05573                                                 }
05574                                                 
05575                                                 $users = $this->object->getUserData($users);
05576                                                 
05577                                                 if (count ($users))
05578                                                         $this->outUserGroupTable("usr", $users, "user_result", "user_row", $this->lng->txt("search_user"),"TEXT_USER_TITLE", $buttons);
05579                                         }
05580 
05581                                         $searchresult = array();
05582                                         
05583                                         if ($searchresult = $search->getResultByType("grp"))
05584                                         {
05585                                                 $groups = array();
05586                                                 
05587                                                 foreach ($searchresult as $result_array)
05588                                                 {                                                       
05589                                                         array_push($groups, $result_array["id"]);
05590                                                 }
05591                                                 $groups = $this->object->getGroupData ($groups);
05592                                                 
05593                                                 if (count ($groups))
05594                                                         $this->outUserGroupTable("grp", $groups, "group_result", "group_row", $this->lng->txt("search_group"), "TEXT_GROUP_TITLE", $buttons);
05595                                         }
05596                                         
05597                                         $searchresult = array();
05598                                         
05599                                         if ($searchresult = $search->getResultByType("role"))
05600                                         {
05601                                                 $roles = array();
05602                                                 
05603                                                 foreach ($searchresult as $result_array)
05604                                                 {                                                       
05605                                                         array_push($roles, $result_array["id"]);
05606                                                 }
05607                                                 
05608                                                 $roles = $this->object->getRoleData ($roles);                   
05609                                                                 
05610                                                 if (count ($roles))
05611                                                         $this->outUserGroupTable("role", $roles, "role_result", "role_row", $this->lng->txt("role"), "TEXT_ROLE_TITLE", $buttons);
05612                                         }
05613                                         
05614                                 }
05615                                 
05616                         }
05617                         else
05618                         {
05619                                 sendInfo($this->lng->txt("no_user_or_group_selected"));
05620                         }
05621                 }
05622         }
05623         
05624         
05625         
05626 function outUserGroupTable($a_type, $data_array, $block_result, $block_row, $title_text, $title_label, $buttons)
05627         {
05628                 global $rbacsystem;
05629                 $rowclass = array("tblrow1", "tblrow2");
05630                 
05631                 switch($a_type)
05632                 {
05633                         case "iv_usr":
05634                                 $add_parameter = "?ref_id=" . $_GET["ref_id"];
05635                                 $finished = "<a target=\"_BLANK\" href=\"".$this->getCallingScript().$add_parameter."&cmd=resultsheet&user_id=\"><img border=\"0\" align=\"middle\" src=\"".ilUtil::getImagePath("right.png", true) . "\" alt=\"\" />&nbsp;".$this->lng->txt("tst_qst_result_sheet")."</a>" ;
05636                                 $finished .= "&nbsp;<a target=\"_BLANK\" href=\"".$this->getCallingScript().$add_parameter."&cmd=answersheet&user_id=\">&nbsp;".$this->lng->txt("tst_show_answer_sheet")."</a>" ;
05637                                 $started   = "<img border=\"0\" align=\"middle\" src=\"".ilUtil::getImagePath("right.png", true) . "\" alt=\"\" />" ;
05638                                 
05639                                 foreach ($data_array as $data)
05640                                 {
05641                                         $finished_line = str_replace ("&user_id=","&user_id=".$data->usr_id,$finished);
05642                                         $started_line = str_replace ("&user_id=","&user_id=".$data->usr_id,$started); 
05643                                         $counter = 0;
05644                                         $this->tpl->setCurrentBlock($block_row);
05645                                         $this->tpl->setVariable("COLOR_CLASS", $rowclass[$counter % 2]);
05646                                         $this->tpl->setVariable("COUNTER", $data->usr_id);
05647                                         $this->tpl->setVariable("VALUE_IV_USR_ID", $data->usr_id);
05648                                         $this->tpl->setVariable("VALUE_IV_LOGIN", $data->login);
05649                                         $this->tpl->setVariable("VALUE_IV_FIRSTNAME", $data->firstname);
05650                                         $this->tpl->setVariable("VALUE_IV_LASTNAME", $data->lastname);
05651                                         $this->tpl->setVariable("VALUE_IV_CLIENT_IP", $data->clientip);
05652                                         $this->tpl->setVariable("VALUE_IV_TEST_FINISHED", ($data->test_finished==1)?$finished_line:"&nbsp;");
05653                                         $this->tpl->setVariable("VALUE_IV_TEST_STARTED", ($data->test_started==1)?$started_line:"&nbsp;");
05654                                         $counter++;
05655                                         $this->tpl->parseCurrentBlock();
05656                                 }
05657                                 $this->tpl->setCurrentBlock($block_result);
05658                                 $this->tpl->setVariable("$title_label", "<img src=\"" . ilUtil::getImagePath("icon_usr_b.gif") . "\" alt=\"\" /> " . $title_text);
05659                                 $this->tpl->setVariable("TEXT_IV_LOGIN", $this->lng->txt("login"));
05660                                 $this->tpl->setVariable("TEXT_IV_FIRSTNAME", $this->lng->txt("firstname"));
05661                                 $this->tpl->setVariable("TEXT_IV_LASTNAME", $this->lng->txt("lastname"));
05662                                 $this->tpl->setVariable("TEXT_IV_CLIENT_IP", $this->lng->txt("clientip"));
05663                                 $this->tpl->setVariable("TEXT_IV_TEST_FINISHED", $this->lng->txt("tst_finished"));
05664                                 $this->tpl->setVariable("TEXT_IV_TEST_STARTED", $this->lng->txt("tst_started"));
05665                                         
05666                                 if ($rbacsystem->checkAccess('write', $this->object->getRefId()))
05667                                 {
05668                                         foreach ($buttons as $cat)
05669                                         {
05670                                                 $this->tpl->setVariable("VALUE_" . strtoupper($cat), $this->lng->txt($cat));
05671                                         }
05672                                         $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"\">");
05673                                 }
05674                                 $this->tpl->parseCurrentBlock();
05675                                 break;
05676                         case "usr":
05677                                 $add_parameter = "?ref_id=" . $_GET["ref_id"] . "&cmd=resultsheet";
05678                                 $finished = "<a target=\"_BLANK\" href=\"".$this->getCallingScript().$add_parameter."\"><img border=\"0\" align=\"middle\" src=\"".ilUtil::getImagePath("right.png", true) . "\" alt=\"\" />&nbsp;".$this->lng->txt("tst_qst_result_sheet")."</a>" ;
05679                                 foreach ($data_array as $data)
05680                                 {
05681                                         $counter = 0;
05682                                         $this->tpl->setCurrentBlock($block_row);
05683                                         $this->tpl->setVariable("COLOR_CLASS", $rowclass[$counter % 2]);
05684                                         $this->tpl->setVariable("COUNTER", $data->usr_id);
05685                                         $this->tpl->setVariable("VALUE_LOGIN", $data->login);
05686                                         $this->tpl->setVariable("VALUE_FIRSTNAME", $data->firstname);
05687                                         $this->tpl->setVariable("VALUE_LASTNAME", $data->lastname);
05688                                         $this->tpl->setVariable("VALUE_CLIENT_IP", $data->clientip);
05689                                         $counter++;
05690                                         $this->tpl->parseCurrentBlock();
05691                                 }
05692                                 $this->tpl->setCurrentBlock($block_result);
05693                                 $this->tpl->setVariable("$title_label", "<img src=\"" . ilUtil::getImagePath("icon_usr_b.gif") . "\" alt=\"\" /> " . $title_text);
05694                                 $this->tpl->setVariable("TEXT_LOGIN", $this->lng->txt("login"));
05695                                 $this->tpl->setVariable("TEXT_FIRSTNAME", $this->lng->txt("firstname"));
05696                                 $this->tpl->setVariable("TEXT_LASTNAME", $this->lng->txt("lastname"));
05697                                 $this->tpl->setVariable("TEXT_CLIENT_IP", $this->lng->txt("clientip"));
05698                                         
05699                                 if ($rbacsystem->checkAccess('write', $this->object->getRefId()))
05700                                 {
05701                                         foreach ($buttons as $cat)
05702                                         {
05703                                                 $this->tpl->setVariable("VALUE_" . strtoupper($cat), $this->lng->txt($cat));
05704                                         }
05705                                         $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"\">");
05706                                 }
05707                                 $this->tpl->parseCurrentBlock();
05708                                 break;
05709                                 
05710                         case "role":
05711                                 
05712                         case "grp":
05713                                 foreach ($data_array as $key => $data)
05714                                 {
05715                                         $counter = 0;
05716                                         $this->tpl->setCurrentBlock($block_row);
05717                                         $this->tpl->setVariable("COLOR_CLASS", $rowclass[$counter % 2]);
05718                                         $this->tpl->setVariable("COUNTER", $key);
05719                                         $this->tpl->setVariable("VALUE_TITLE", $data->title);
05720                                         $this->tpl->setVariable("VALUE_DESCRIPTION", $data->description);
05721                                         $counter++;
05722                                         $this->tpl->parseCurrentBlock();
05723                                 }
05724                                 $this->tpl->setCurrentBlock($block_result);
05725                                 $this->tpl->setVariable("$title_label", "<img src=\"" . ilUtil::getImagePath("icon_".$a_type."_b.gif") . "\" alt=\"\" /> " . $title_text);
05726                                 $this->tpl->setVariable("TEXT_TITLE", $this->lng->txt("title"));
05727                                 $this->tpl->setVariable("TEXT_DESCRIPTION", $this->lng->txt("description"));
05728                                 if ($rbacsystem->checkAccess('write', $this->object->getRefId()))
05729                                 {
05730                                         foreach ($buttons as $cat)
05731                                         {
05732                                                 $this->tpl->setVariable("VALUE_" . strtoupper($cat), $this->lng->txt($cat));
05733                                         }
05734                                         $this->tpl->setVariable("ARROW", "<img src=\"" . ilUtil::getImagePath("arrow_downright.gif") . "\" alt=\"\">");
05735                                 }
05736                                 $this->tpl->parseCurrentBlock();
05737                                 break;
05738                 }
05739         }
05740                 
05741                 
05747         function outTestSummary() 
05748         {
05749                 global $ilUser;
05750 
05751                 function sort_title($a, $b) {
05752                         if (strcmp($_GET["order"], "ASC")) {
05753                                 $smaller = 1;
05754                                 $greater = -1;
05755                         } else {
05756                                 $smaller = -1;
05757                                 $greater = 1;
05758                         }
05759                         if ($a["nr"] == $b["nr"]) return 0;
05760                         if (strcmp($a["title"],$b["title"])< 0)
05761                                 return $smaller;
05762                         else if (strcmp($a["title"],$b["title"])> 0)
05763                                 return $greater;
05764                         return 0;
05765                 }
05766                 
05767                 
05768                 function sort_nr($a, $b) {
05769                         if (strcmp($_GET["order"], "ASC")) {
05770                                 $smaller = 1;
05771                                 $greater = -1;
05772                         } else {
05773                                 $smaller = -1;
05774                                 $greater = 1;
05775                         }
05776                         if ($a["nr"] == $b["nr"]) return 0;
05777                         return ($a["nr"] < $b["nr"]) ? $smaller : $greater;
05778                 }
05779                 
05780                 function sort_visited($a, $b) {
05781                         if (strcmp($_GET["order"], "ASC")) {
05782                                 $smaller = 1;
05783                                 $greater = -1;
05784                         } else {
05785                                 $smaller = -1;
05786                                 $greater = 1;
05787                         }
05788                         if ($a["nr"] == $b["nr"]) 
05789                                 return 0;
05790                         return ($a["visited"] < $b["visited"]) ? $smaller : $greater;
05791                 }
05792 
05793                 
05794                 function sort_solved($a, $b) {
05795                         if (strcmp($_GET["order"], "ASC")) {
05796                                 $smaller = 1;
05797                                 $greater = -1;
05798                         } else {
05799                                 $smaller = -1;
05800                                 $greater = 1;
05801                         }
05802                         if ($a["nr"] == $b["nr"]) return 0;
05803                         return ($a["solved"] < $b["solved"]) ? $smaller : $greater;
05804                 }
05805 
05806                 $add_parameter = $this->getAddParameter()."&"."sequence=".$_GET["sequence"];
05807                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_summary.html", true);
05808                 $user_id = $ilUser->id;
05809                 $color_class = array ("tblrow1", "tblrow2");
05810                 $counter = 0;
05811                 
05812                 $result_array = & $this->object->getTestSummary($user_id);
05813                 
05814                 $img_title_nr = "";
05815                 $img_title_title = "";
05816                 $img_title_solved = "";
05817                 
05818                 if (!$_GET["sort_summary"] )
05819                 {
05820                         $_GET["sort_summary"]  = "nr";
05821                         $_GET["order"] = "ASC";
05822                 } 
05823                 
05824                 switch ($_GET["sort_summary"]) {
05825                         case nr:
05826                                 usort($result_array, "sort_nr");
05827                                 $img_title_nr = " <img src=\"" . ilUtil::getImagePath(strtolower($_GET["order"]) . "_order.png", true) . "\" alt=\"\" />";
05828                                 if (strcmp($_GET["order"], "ASC") == 0) {
05829                                         $sortnr = "DESC";
05830                                 } else {
05831                                         $sortnr = "ASC";
05832                                 }
05833                                 break;                  
05834                         
05835                         case "title":
05836                                 usort($result_array, "sort_title");
05837                                 $img_title_title = " <img src=\"" . ilUtil::getImagePath(strtolower($_GET["order"]) . "_order.png", true) . "\" alt=\"\" />";
05838                                 if (strcmp($_GET["order"], "ASC") == 0) {
05839                                         $sorttitle = "DESC";
05840                                 } else {
05841                                         $sorttitle = "ASC";
05842                                 }
05843                                 break;
05844                         case "solved":
05845                                 usort($result_array, "sort_solved");
05846                                 $img_title_solved = " <img src=\"" . ilUtil::getImagePath(strtolower($_GET["order"]) . "_order.png", true) . "\" alt=\"\" />";
05847                                 if (strcmp($_GET["order"], "ASC") == 0) {
05848                                         $sortsolved = "DESC";
05849                                 } else {
05850                                         $sortsolved = "ASC";
05851                                 }
05852                                 break;                  
05853                 }
05854                 if (!$sorttitle) {
05855                         $sorttitle = "ASC";
05856                 }
05857                 if (!$sortsolved) {
05858                         $sortsolved = "ASC";
05859                 }
05860                 if (!$sortnr) {
05861                         $sortnr = "ASC";
05862                 }
05863                 
05864                 $img_solved = " <img border=\"0\"  align=\"middle\" src=\"" . ilUtil::getImagePath("solved.png", true) . "\" alt=\"".$this->lng->txt("tst_click_to_change_state")."\" />";
05865                 $img_not_solved = " <img border=\"0\" align=\"middle\" src=\"" . ilUtil::getImagePath("not_solved.png", true) . "\" alt=\"".$this->lng->txt("tst_click_to_change_state")."\" />";
05866                 $goto_question =  " <img border=\"0\" align=\"middle\" src=\"" . ilUtil::getImagePath("goto_question.png", true) . "\" alt=\"".$this->lng->txt("tst_qst_goto")."\" />";
05867                 
05868                 $disabled = $this->isMaxProcessingTimeReached() | $this->object->endingTimeReached();
05869                 
05870                 foreach ($result_array as $key => $value) {
05871                         if (preg_match("/\d+/", $key)) {
05872                                 $this->tpl->setCurrentBlock("question");
05873                                 $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
05874                                 $this->tpl->setVariable("VALUE_QUESTION_COUNTER", $value["nr"]);
05875                                 $this->tpl->setVariable("VALUE_QUESTION_TITLE", $value["title"]);
05876                                 $this->tpl->setVariable("VALUE_QUESTION_VISITED", ($value["visited"] > 0) ? " checked=\"checked\" ": ""); 
05877                                 $this->tpl->setVariable("VALUE_QUESTION_SOLVED", ($value["solved"] > 0) ?$img_solved : $img_not_solved);  
05878                                 if (!$disabled)
05879                                         $this->tpl->setVariable("VALUE_QUESTION_HREF_GOTO", "<a href=\"".$value["href_goto"]."\">");
05880                                 $this->tpl->setVariable("VALUE_QUESTION_GOTO", $goto_question);
05881                                 $this->tpl->setVariable("VALUE_QUESTION_HREF_SET_SOLVED", $value["href_setsolved"]."&sequence=".$_GET["sequence"]."&order=".$_GET["order"]."&sort_summary=".$_GET["sort_summary"]);
05882                                 $this->tpl->setVariable("VALUE_QUESTION_SET_SOLVED", ($value["solved"] > 0) ?$this->lng->txt("tst_qst_resetsolved"):$this->lng->txt("tst_qst_setsolved"));
05883                                 $this->tpl->setVariable("VALUE_QUESTION_DESCRIPTION", $value["description"]);
05884                                 $this->tpl->setVariable("VALUE_QUESTION_POINTS", $value["points"]."&nbsp;".$this->lng->txt("points_short"));
05885                                 $this->tpl->parseCurrentBlock();
05886                                 $counter ++;
05887                         }
05888                 }
05889 
05890                 $this->tpl->setCurrentBlock("results");
05891                 $this->tpl->setVariable("QUESTION_ACTION","actions");
05892                 $this->tpl->setVariable("QUESTION_COUNTER","<a href=\"".$this->getCallingScript()."$add_parameter&order=$sortnr&sort_summary=nr\">".$this->lng->txt("tst_qst_order")."</a>".$img_title_nr);
05893                 $this->tpl->setVariable("QUESTION_TITLE", "<a href=\"".$this->getCallingScript()."$add_parameter&order=$sorttitle&sort_summary=title\">".$this->lng->txt("tst_question_title")."</a>".$img_title_title);
05894                 $this->tpl->setVariable("QUESTION_VISITED", "<a href=\"".$this->getCallingScript()."$add_parameter&order=$sortvisited&sort_summary=visited\">".$this->lng->txt("tst_question_visited")."</a>".$img_title_visited);
05895                 $this->tpl->setVariable("QUESTION_SOLVED", "<a href=\"".$this->getCallingScript()."$add_parameter&order=$sortsolved&sort_summary=solved\">".$this->lng->txt("tst_question_solved_state")."</a>".$img_title_solved);
05896                 $this->tpl->setVariable("QUESTION_POINTS", $this->lng->txt("tst_maximum_points"));
05897                 $this->tpl->setVariable("USER_FEEDBACK", $this->lng->txt("tst_qst_summary_text"));
05898                 $this->tpl->setVariable("TXT_SHOW_AND_SUBMIT_ANSWERS", $this->lng->txt("save_finish"));
05899                 $this->tpl->setVariable("FORM_ACTION", $this->getCallingScript().$add_parameter);       
05900                 $this->tpl->setVariable("TEXT_RESULTS", $this->lng->txt("summary"));            
05901                 $this->tpl->parseCurrentBlock();
05902                 
05903                 if (!$disabled) {
05904                         $this->tpl->setCurrentBlock("back");
05905                         $this->tpl->setVariable("FORM_BACK_ACTION", $this->getCallingScript().$add_parameter);
05906                         $this->tpl->setVariable("TXT_BACK", $this->lng->txt("back"));
05907                         $this->tpl->parseCurrentBlock();
05908                 } else 
05909                 {
05910                         sendinfo($this->lng->txt("detail_max_processing_time_reached"));
05911                 }
05912                 
05913                 
05914                 if ($this->object->getEnableProcessingTime())
05915                         $this->outProcessingTime();
05916 
05917         }
05918         
05924         function confirmSubmitAnswers() {
05925                 $add_parameter = $this->getAddParameter();
05926                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_submit_answers_confirm.html", true);
05927                 $this->tpl->setCurrentBlock("adm_content");
05928                 if ($this->object->isActiveTestSubmitted()) 
05929                 {
05930                         $this->tpl->setCurrentBlock("not_submit_allowed");
05931                         $this->tpl->setVariable("TEXT_ALREADY_SUBMITTED", $this->lng->txt("tst_already_submitted"));
05932                         $this->tpl->setVariable("BTN_OK", $this->lng->txt("tst_show_answer_sheet"));
05933                 } else 
05934                 {
05935                         $this->tpl->setCurrentBlock("submit_allowed");
05936                         $this->tpl->setVariable("TEXT_CONFIRM_SUBMIT_RESULTS", $this->lng->txt("tst_confirm_submit_answers"));
05937                         $this->tpl->setVariable("BTN_OK", $this->lng->txt("tst_submit_results"));
05938                 }
05939                 $this->tpl->setVariable("BTN_BACK", $this->lng->txt("back"));           
05940                 $this->tpl->setVariable("FORM_ACTION", $this->getCallingScript().$add_parameter);
05941                 //$this->tpl->setVariable("FORM_PRINT_ACTION", $this->getCallingScript()."?ref_id=".$this->object->getRefId()."&cmd=printAnswers");
05942                 $this->tpl->parseCurrentBlock();
05943         }
05944         
05949         function printAnswersObject(){
05950                 global $ilUser,$rbacsystem;
05951                 if ((!$rbacsystem->checkAccess("read", $this->ref_id))) 
05952                 {
05953                         // allow only read and write access
05954                         sendInfo($this->lng->txt("cannot_edit_test"), true);
05955                         $path = $this->tree->getPathFull($this->object->getRefID());
05956                         ilUtil::redirect($this->getReturnLocation("cancel","../repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
05957                         return;
05958                 }
05959                 
05960                 if (!$this->object->isActiveTestSubmitted($ilUser->getId())) 
05961                 {
05962                         sendInfo($this->lng->txt("test_not_submitted"), true);
05963                         $path = $this->tree->getPathFull($this->object->getRefID());
05964                         ilUtil::redirect($this->getReturnLocation("cancel","../repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
05965                         return;
05966                 }
05967 
05968 
05969                 $this->object->setActiveTestSubmitted($ilUser->getId());
05970 
05971                 $this->tpl = new ilTemplate("./assessment/templates/default/tpl.il_as_tst_print_answers_sheet.html", true, true);
05972                 $this->tpl->setVariable("PRINT_CSS", "./templates/default/print_answers.css");
05973                 $this->tpl->setVariable ("FRAME_TITLE", $this->object->getTitle());
05974                 $this->tpl->setVariable ("FRAME_CLIENTIP",$_SERVER["REMOTE_ADDR"]);             
05975                 $this->tpl->setVariable ("FRAME_MATRICULATION",$ilUser->getMatriculation());
05976 
05977                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_print_answers_sheet_details.html", true);
05978                 
05979                 $this->outShowAnswersDetails(false, $ilUser); 
05980         }
05981         
05982         function _printAnswerSheets ($users) {  
05983                 $this->tpl = new ilTemplate("./assessment/templates/default/tpl.il_as_tst_print_answers_sheet.html", true, true);
05984                 $this->tpl->setVariable("PRINT_CSS", "./templates/default/print_answers.css");
05985                 $this->tpl->setVariable("TITLE", $this->object->getTitle());            
05986                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_print_answers_sheet_details.html", true);
05987                 
05988                 foreach ($users as $user_id) {
05989                         if ($this->object->isActiveTestSubmitted($user_id)) {
05990                                 $this->outShowAnswersDetails(false, new ilObjUser ($user_id));
05991                         }
05992                 }
05993         }
05994         
05995         function _printResultSheets ($users) {  
05996                 $this->tpl = new ilTemplate("./assessment/templates/default/tpl.il_as_tst_print_results.html", true, true);
05997                 $this->tpl->setVariable("PRINT_CSS", "./templates/default/print_results.css");
05998                 $this->tpl->setVariable("TITLE", $this->object->getTitle());            
05999                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_print_result_details.html", true);
06000                 
06001                 foreach ($users as $user_id) {
06002                         if ($this->object->isActiveTestSubmitted($user_id)) {
06003                                 $this->outPrintUserResults($user_id);                   
06004                         }
06005                 }
06006         }       
06007         
06008         function outShowAnswers ($isForm, &$ilUser) {
06009                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_print_answers_sheet_details.html", true);         
06010                 $this->outShowAnswersDetails($isForm, $ilUser);
06011         }
06012         
06013         function outShowAnswersDetails($isForm, &$ilUser) {
06014                 $tpl = &$this->tpl;                                             
06015                 $invited_users = array_pop($this->object->getInvitedUsers($ilUser->getId()));
06016                 $active = $this->object->getActiveTestUser($ilUser->getId());
06017                 $t = $active->submittimestamp;
06018                 
06019                 $add_parameter = $this->getAddParameter();
06020                 
06021                 // output of submit date and signature
06022                 if ($active->submitted)
06023                 {
06024                         // only display submit date when it exists (not in the summary but in the print form)
06025                         $tpl->setCurrentBlock("freefield_bottom");
06026                         $tpl->setVariable("TITLE", $this->object->getTitle());
06027                         $tpl->setVariable("TXT_DATE", $this->lng->txt("date"));
06028                         $tpl->setVariable("VALUE_DATE", strftime("%Y-%m-%d %H:%M:%S", ilUtil::date_mysql2time($t)));
06029                         $tpl->setVariable("TXT_ANSWER_SHEET", $this->lng->txt("tst_answer_sheet"));
06030         
06031                         $freefieldtypes = array ("freefield_bottom" =>  array(  array ("title" => $this->lng->txt("tst_signature"), "length" => 300)));
06032         /*                                      "freefield_top" =>              array ( array ("title" => $this->lng->txt("semester"), "length" => 300), 
06033                                                                                                                         array ("title" => $this->lng->txt("career"), "length" => 300)
06034                                                                                                                          ),*/
06035                                                 
06036                         
06037                         
06038                         foreach ($freefieldtypes as $type => $freefields) {
06039                                 $counter = 0;
06040         
06041                                 while ($counter < count ($freefields)) {
06042                                         $freefield = $freefields[$counter];
06043                                         
06044                                         //$tpl->setCurrentBlock($type);
06045                                 
06046                                         $tpl->setVariable("TXT_FREE_FIELD", $freefield["title"]);
06047                                         $tpl->setVariable("VALUE_FREE_FIELD", "<img height=\"30px\" border=\"0\" src=\"".ilUtil :: getImagePath("spacer.gif", false)."\" width=\"".$freefield["length"]."px\" />");
06048                                 
06049                                         $counter ++;
06050                                 
06051                                         //$tpl->parseCurrentBlock($type);
06052                                 }
06053                         }
06054                         $tpl->parseCurrentBlock();
06055                 }
06056 
06057                 $counter = 1;
06058                 
06059                 // output of questions with solutions
06060                 foreach ($this->object->questions as $question) 
06061                 {
06062                         $tpl->setCurrentBlock("question");
06063                         $question_gui = $this->object->createQuestionGUI("", $question);
06064 
06065                         //$tpl->setVariable("EDIT_QUESTION", $this->getCallingScript().$this->getAddParameter()."&sequence=".$counter);
06066                         $tpl->setVariable("COUNTER_QUESTION", $counter.". ");
06067                         $tpl->setVariable("QUESTION_TITLE", $question_gui->object->getTitle());
06068                         
06069                         $idx = $this->object->test_id;
06070                         
06071                         switch ($question_gui->getQuestionType()) {
06072                                 case "qt_imagemap" :
06073                                         $question_gui->outWorkingForm($idx, false, $show_solutions=false, $formaction, $show_question_page=false, $show_solution_only = false, $ilUser);
06074                                         break;
06075                                 case "qt_javaapplet" :
06076                                         $question_gui->outWorkingForm("", $is_postponed = false, $showsolution = 0, $show_question_page=false, $show_solution_only = false, $ilUser);
06077                                         break;
06078                                 default :
06079                                         $question_gui->outWorkingForm($idx, $is_postponed = false, $showsolution = 0, $show_question_page=false, $show_solution_only = false, $ilUser);
06080                         }
06081                         $tpl->parseCurrentBlock();
06082                         $counter ++;
06083                 }
06084                 // output of submit buttons
06085                 if ($isForm && !$active->submitted) 
06086                 {
06087                         $tpl->setCurrentBlock("confirm");
06088                         $tpl->setVariable("TXT_SUBMIT_ANSWERS", $this->lng->txt("tst_submit_answers_txt"));
06089                         $tpl->setVariable("BTN_CANCEL", $this->lng->txt("back"));
06090                         $tpl->setVariable("BTN_OK", $this->lng->txt("tst_submit_answers"));
06091                         $tpl->setVariable("FORM_ACTION", $this->getCallingScript().$add_parameter);
06092                         $tpl->parseCurrentBlock();
06093                 }
06094                 
06095                 // output of non-block elements
06096                 $tpl->setCurrentBlock("adm_content");
06097                 $tpl->setVariable("TXT_TEST_TITLE", $this->lng->txt("title"));
06098                 $tpl->setVariable("VALUE_TEST_TITLE", $this->object->getTitle());
06099                 $tpl->setVariable("TXT_USR_NAME", $this->lng->txt("name"));
06100                 $tpl->setVariable("VALUE_USR_NAME", $ilUser->getLastname().", ".$ilUser->getFirstname());
06101                 $tpl->setVariable("TXT_USR_MATRIC", $this->lng->txt("matriculation"));
06102                 $tpl->setVariable("VALUE_USR_MATRIC", $ilUser->getMatriculation());
06103                 $tpl->setVariable("TXT_CLIENT_IP", $this->lng->txt("client_ip"));
06104                 $tpl->setVariable("VALUE_CLIENT_IP", $invited_users->clientip);
06105                 $tpl->setVariable("TXT_TEST_PROLOG", $this->lng->txt("tst_your_answers"));
06106                 
06107                 $tpl->parseCurrentBlock();
06108                 
06109         }
06110         
06115         function updateWorkingTime() {
06116                 // todo: check update within summary and back
06117                 // todo: back in summary does not work
06118                 // todo: check working time in summary
06119                 
06120                 global $ilUser;
06121                 
06122                 // command which do not require update
06123                 
06124                 //print_r($_GET);
06125                                 //print_r($_POST);
06126                 
06127                 $negs =  //is_numeric($_GET["set_solved"]) || is_numeric($_GET["question_id"]) ||  
06128                                   isset($_POST["cmd"]["start"]) || isset($_POST["cmd"]["resume"]) || 
06129                                   isset($_POST["cmd"]["showresults"]) || isset($_POST["cmd"]["deleteresults"])|| 
06130                                   isset($_POST["cmd"]["confirmdeleteresults"]) || isset($_POST["cmd"]["canceldeleteresults"]) ||
06131                                   isset($_POST["cmd"]["submit_answers"]) || isset($_POST["cmd"]["confirm_submit_answers"]) ||
06132                                   isset($_POST["cmd"]["cancel_show_answers"]) || isset($_POST["cmd"]["show_answers"]);
06133                 
06134                 // all other commands which require update
06135                 $pos  = count($_POST["cmd"])>0 | isset($_GET["selImage"]) | isset($_GET["sequence"]);
06136                                 
06137                 $this->saveResult = false;
06138                 
06139                 if ($pos==true && $negs==false)         
06140                 {
06141                         // set new finish time for test
06142                         if ($_SESSION["active_time_id"]) // && $this->object->getEnableProcessingTime())
06143                         {
06144                                 $this->object->updateWorkingTime($_SESSION["active_time_id"]);
06145                                 //echo "updating Worktime<br>";
06146                         }       
06147                         
06148                         // save question solution
06149                         if ($this->cmdCtrl->canSaveResult())
06150                         {
06151                                 // but only if the ending time is not reached
06152                                 $q_id = $this->object->getQuestionIdFromActiveUserSequence($_GET["sequence"]);
06153                                 if (is_numeric($q_id)) 
06154                                 {
06155                                         $question_gui = $this->object->createQuestionGUI("", $q_id);
06156                                         $this->saveResult = $question_gui->object->saveWorkingData($this->object->getTestId());
06157                                         //echo "saving <br>";
06158                                 }                                                                                               
06159                         }                       
06160                 }               
06161         }       
06162         
06163         function resultsheetObject () {
06164                 global $rbacsystem, $ilUser, $ilErr;
06165                 
06166                 if ((!$rbacsystem->checkAccess("read", $this->ref_id)) && (!$rbacsystem->checkAccess("write", $this->ref_id))) 
06167                 {
06168                         // allow only read and write access
06169                         $ilErr->raiseError($this->lng->txt("cannot_edit_test"),$ilErr->WARNING);
06170                         return;
06171                 }
06172                 
06173                 $user_id = (int) $_GET["user_id"];
06174                 $user = $this->object->getInvitedUsers($user_id);
06175                 if (!is_array ($user) || count($user)!=1)
06176                 {
06177                         $ilErr->raiseError($this->lng->txt("user_not_invited"),$ilErr->WARNING);
06178                         return;
06179                 }
06180                         
06181                 $this->outPrintTestResults($user_id);
06182                 
06183         }
06184         
06185         function answersheetObject () {
06186                 global $rbacsystem, $ilUser, $ilErr;
06187                 
06188                 $user_id = (int) $_GET["user_id"];
06189                 
06190                 // user has to have at least read permission
06191                 if ((!$rbacsystem->checkAccess("read", $this->ref_id))) 
06192                 {
06193                         // allow only read and write access
06194                         $ilErr->raiseError($this->lng->txt("cannot_read_test"),$ilErr->WARNING); 
06195                         return;
06196                 }
06197 
06198                 // if GET["user_id"] is not set, then we assume that the user the current ilias user
06199                 // that means he does not have to have write permissions to see the results! 
06200 
06201                 if (!isset($_GET["user_id"])) {
06202                         if (!$rbacsystem->checkAccess("write", $this->ref_id)) 
06203                         {
06204                                 // allow only read and write access
06205                                 $ilErr->raiseError($this->lng->txt("cannot_edit_test"),$ilErr->WARNING); 
06206                                 return;
06207                         }
06208                         $user_id = $ilUser->getId();
06209                 } else 
06210                         $user_id = (int) $_GET["user_id"];
06211                 
06212                 // getInvitedUsers and see if the requested user belongs to the test
06213                 $users = $this->object->getInvitedUsers($user_id);
06214                 if (!is_array ($users) || count($users)!=1)
06215                 {
06216                         $ilErr->raiseError($this->lng->txt("user_not_invited"),$ilErr->WARNING); 
06217                         return;
06218                 }
06219                 
06220                 // create a new UserObject to be passed for showing answers
06221                 $userObject = new IlObjUser ($user_id); 
06222                 
06223                 // geht the invited user, we need the registered client ip in the print screen
06224                 $user = array_pop ($users);
06225                 
06226                 $this->tpl = new ilTemplate("./assessment/templates/default/tpl.il_as_tst_print_answers_sheet.html", true, true);
06227                 $this->tpl->setVariable("PRINT_CSS", "./templates/default/print_answers.css");
06228                 $this->tpl->setVariable("FRAME_TITLE", $this->object->getTitle());
06229                 $this->tpl->setVariable("FRAME_CLIENTIP", $user->clientip);             
06230                 $this->tpl->setVariable("FRAME_MATRICULATION",$userObject->getMatriculation());
06231                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_print_answers_sheet_details.html", true);
06232                 
06233                 // pass the user to the output procedure
06234                 $this->outShowAnswersDetails(false, $userObject);                       
06235         }
06236         
06237         
06238         
06246         function outPrintTestResults($user_id) {
06247                 $this->tpl = new ilTemplate("./assessment/templates/default/tpl.il_as_tst_print_results.html", true, true);
06248                 $this->tpl->setVariable("PRINT_CSS", "./templates/default/print_results.css");
06249                 $this->tpl->setVariable("TITLE", $this->object->getTitle());
06250                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_print_result_details.html", true);                        
06251                 
06252                 $this->outPrintUserResults ($user_id);
06253         }
06254         
06255         function outPrintUserResults ($user_id) {
06256                 $user = new IlObjUser ($user_id);
06257                 $active = $this->object->getActiveTestUser($user_id);
06258                 $t = $active->submittimestamp;
06259                 
06260                 $print_date = mktime(date("H"), date("i"), date("s"), date("m")  , date("d"), date("Y"));
06261                 
06262                 $this->tpl->setVariable("TXT_TEST_TITLE", $this->lng->txt("title"));
06263                 $this->tpl->setVariable("VALUE_TEST_TITLE", $this->object->getTitle());
06264                 $this->tpl->setVariable("TXT_USR_NAME", $this->lng->txt("name"));
06265                 $this->tpl->setVariable("VALUE_USR_NAME", $user->getLastname().", ".$user->getFirstname());
06266                 $this->tpl->setVariable("TXT_USR_MATRIC", $this->lng->txt("matriculation"));
06267                 $this->tpl->setVariable("VALUE_USR_MATRIC", $user->getMatriculation());
06268                 $this->tpl->setVariable("TXT_TEST_DATE", $this->lng->txt("tst_tst_date"));
06269                 $this->tpl->setVariable("VALUE_TEST_DATE", strftime("%Y-%m-%d %H:%M:%S",ilUtil::date_mysql2time($t)));
06270                 $this->tpl->setVariable("TXT_PRINT_DATE", $this->lng->txt("tst_print_date"));
06271                 $this->tpl->setVariable("VALUE_PRINT_DATE", strftime("%Y-%m-%d %H:%M:%S",$print_date));
06272                 
06273 
06274                 $add_parameter = $this->getAddParameter();
06275                 
06276                 $color_class = array("tblrow1", "tblrow2");
06277                 $counter = 0;
06278 
06279                 $result_array =& $this->object->getTestResult($user_id);
06280 
06281                 if (!$result_array["test"]["total_max_points"])
06282                 {
06283                         $percentage = 0;
06284                 }
06285                 else
06286                 {
06287                         $percentage = ($result_array["test"]["total_reached_points"]/$result_array["test"]["total_max_points"])*100;
06288                 }
06289                 
06290                 $total_max = $result_array["test"]["total_max_points"];
06291                 $total_reached = $result_array["test"]["total_reached_points"];
06292 
06293                 foreach ($result_array as $key => $value) {
06294                         if (preg_match("/\d+/", $key)) {
06295                                 $title = preg_replace ("/<a[^>]*>(.*?)<\/a>/", "\\1",$value["title"]);
06296                                 $this->tpl->setCurrentBlock("question");
06297                                 $this->tpl->setVariable("COLOR_CLASS", $color_class[$counter % 2]);
06298                                 $this->tpl->setVariable("VALUE_QUESTION_COUNTER", $value["nr"]);
06299                                 $this->tpl->setVariable("VALUE_QUESTION_TITLE", $title);
06300                                 $this->tpl->setVariable("VALUE_MAX_POINTS", $value["max"]);
06301                                 $this->tpl->setVariable("VALUE_REACHED_POINTS", $value["reached"]);
06302                                 $this->tpl->setVariable("VALUE_PERCENT_SOLVED", $value["percent"]);
06303                                 $this->tpl->parseCurrentBlock("question");
06304                                 $counter++;
06305                         }
06306                 }
06307 
06308                 $this->tpl->setCurrentBlock("adm_content");
06309 
06310                 $this->tpl->setVariable("QUESTION_COUNTER", $this->lng->txt("tst_question_no"));
06311                 $this->tpl->setVariable("QUESTION_TITLE", $this->lng->txt("tst_question_title"));
06312                 $this->tpl->setVariable("SOLUTION_HINT_HEADER", $this->lng->txt("solution_hint"));
06313                 $this->tpl->setVariable("MAX_POINTS", $this->lng->txt("tst_maximum_points"));
06314                 $this->tpl->setVariable("REACHED_POINTS", $this->lng->txt("tst_reached_points"));
06315                 $this->tpl->setVariable("PERCENT_SOLVED", $this->lng->txt("tst_percent_solved"));
06316 
06317                 // SUM
06318                 $this->tpl->setVariable("TOTAL", $this->lng->txt("total"));
06319                 $this->tpl->setVariable("TOTAL_MAX_POINTS", $total_max);
06320                 $this->tpl->setVariable("TOTAL_REACHED_POINTS",  $total_reached);
06321                 $this->tpl->setVariable("TOTAL_PERCENT_SOLVED", sprintf("%01.2f",$percentage)." %");
06322 
06323 
06324 
06325                 $mark_obj = $this->object->mark_schema->get_matching_mark($percentage);
06326                 if ($mark_obj)
06327                 {
06328                         $mark .= "<br /><strong>" . $this->lng->txt("tst_mark") . ": &quot;" . $mark_obj->get_official_name() . "&quot;</strong>";
06329                 }
06330                 if ($this->object->ects_output)
06331                 {
06332                         $ects_mark = $this->object->getECTSGrade($total_reached, $total_max);
06333                         $mark .= "<br />" . $this->lng->txt("tst_your_ects_mark_is") . ": &quot;" . $ects_mark . "&quot; (" . $this->lng->txt("ects_grade_". strtolower($ects_mark) . "_short") . ": " . $this->lng->txt("ects_grade_". strtolower($ects_mark)) . ")";
06334                 }       
06335  
06336                 $this->tpl->setVariable("GRADE", $mark);
06337                 $this->tpl->setVariable("TITLE", $this->object->getTitle());
06338                 $this->tpl->setVariable("TEXT_RESULTS", $this->lng->txt("tst_results"));
06339                 $this->tpl->parseCurrentBlock();
06340         }
06341         
06342         
06343         function printobject () {
06344                 global $rbacsystem, $ilUser;
06345                 
06346                 if ((!$rbacsystem->checkAccess("read", $this->ref_id)) && (!$rbacsystem->checkAccess("write", $this->ref_id))) 
06347                 {
06348                         // allow only read and write access
06349                         sendInfo($this->lng->txt("cannot_edit_test"), true);
06350                         $path = $this->tree->getPathFull($this->object->getRefID());
06351                         ilUtil::redirect($this->getReturnLocation("cancel","../repository.php?cmd=frameset&ref_id=" . $path[count($path) - 2]["child"]));
06352                         return;
06353                 }
06354 
06355                 if ($_POST["cmd"]["print"]) {
06356                         $this->outPrinttest();
06357                         return;
06358                 }
06359                 
06360                 $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_print_test_confirm.html", true);
06361                 $this->tpl->setVariable("TEXT_CONFIRM_PRINT_TEST", $this->lng->txt("tst_confirm_print"));
06362                 $this->tpl->setVariable("FORM_PRINT_ACTION", $this->getCallingScript().$this->getAddParameter());
06363                 $this->tpl->setVariable("BTN_PRINT", $this->lng->txt("print"));
06364                 
06365         }
06366         
06367         function outPrinttest() {
06368                 global $ilUser;
06369                 
06370                 
06371                 $print_date = mktime(date("H"), date("i"), date("s"), date("m")  , date("d"), date("Y"));
06372                 $this->tpl = new ilTemplate("./assessment/templates/default/tpl.il_as_tst_print_test.html", true, true);
06373                 
06374                 $this->tpl->setVariable("PRINT_CSS", "./templates/default/print_test.css");                             
06375                 $this->tpl->setVariable("SYNTAX_CSS","./templates/default/print_syntax.css");
06376                 
06377                 $this->tpl->setVariable("TITLE", $this->object->getTitle());            
06378                 $this->tpl->setVariable("PRINT_TEST", $this->lng->txt("tst_print"));
06379                 $this->tpl->setVariable("TXT_PRINT_DATE", $this->lng->txt("date"));
06380                 $this->tpl->setVariable("VALUE_PRINT_DATE", strftime("%c",$print_date));
06381                         
06382                 $tpl = &$this->tpl;                     
06383                 
06384                 $tpl->setVariable("TITLE", $this->object->getTitle());  
06385 
06386                 $max_points= 0;
06387                 $counter = 1;
06388                                         
06389                 foreach ($this->object->questions as $question) {               
06390                         $tpl->setCurrentBlock("question");                      
06391                         $question_gui = $this->object->createQuestionGUI("", $question);
06392                         
06393                         $tpl->setVariable("EDIT_QUESTION", $this->getCallingScript().$this->getAddParameter()."&sequence=".$counter);
06394                         $tpl->setVariable("COUNTER_QUESTION", $counter.".");
06395                         $tpl->setVariable("QUESTION_TITLE", $question_gui->object->getTitle());
06396                         
06397                         switch ($question_gui->getQuestionType()) {
06398                                 
06399                                 case "qt_imagemap" :
06400                                         $question_gui->outWorkingForm($idx = "", $postponed = false, $show_solution = true, $formaction, $show_pages= true, $show_solutions_only= true);
06401                                         break;
06402                                 case "qt_javaapplet" :
06403                                         $question_gui->outWorkingForm($idx = "", $postponed = false, $show_solution = true, $show_pages = true, $show_solutions_only= true);
06404                                         break;
06405                                 default :
06406                                         $question_gui->outWorkingForm($idx = "", $postponed = false, $show_solution = true, $show_pages = true, $show_solutions_only= true);
06407                         }
06408                         $tpl->parseCurrentBlock("question");
06409                         $counter ++;                                    
06410                         $max_points += $question_gui->object->getMaximumPoints();                       
06411                 }
06412                 $this->tpl->setVariable("TXT_MAXIMUM_POINTS", $this->lng->txt("tst_maximum_points"));
06413                 $this->tpl->setVariable("VALUE_MAXIMUM_POINTS", $max_points);
06414                 
06415                 
06416         }
06417         
06418         
06424         function endingTimeReached () {
06425                 sendInfo(sprintf($this->lng->txt("detail_ending_time_reached"), ilFormat::ftimestamp2datetimeDB($this->object->getEndingTime())));
06426                 $this->object->setActiveTestUser(1, "", true);
06427                 if (!$this->object->canViewResults()) 
06428                 {
06429                         $this->outIntroductionPage();
06430                 }
06431                 else
06432                 {
06433                         if ($this->object->isOnlineTest())
06434                                 $this->outTestSummary();
06435                         else
06436                                 $this->outTestResults();
06437                 }
06438         }
06439         
06440         
06441         function maxProcessingTimeReached (){
06442                 sendInfo($this->lng->txt("detail_max_processing_time_reached"));
06443                 $this->object->setActiveTestUser(1, "", true);
06444                 if (!$this->object->canViewResults()) 
06445                 {
06446                         $this->outIntroductionPage();
06447                 }
06448                 else
06449                 {
06450                         if ($this->object->isOnlineTest())
06451                                 $this->outTestSummary();
06452                         else                                    
06453                                 $this->outTestResults();
06454                 }
06455         }               
06456                 
06457                 
06458         function outProcessingTime () {
06459                 global $ilUser;
06460 
06461                 $starting_time = $this->object->getStartingTimeOfUser($ilUser->getId());
06462                 $processing_time = $this->object->getProcessingTimeInSeconds();
06463                 $time_left = $starting_time + $processing_time - mktime();
06464                 $date = getdate($starting_time);
06465                 $this->tpl->setCurrentBlock("enableprocessingtime");
06466                 $this->tpl->setVariable("USER_WORKING_TIME", 
06467                         sprintf($this->lng->txt("tst_time_already_spent"),
06468                                 ilFormat::formatDate(
06469                                         $date["year"]."-".
06470                                         sprintf("%02d", $date["mon"])."-".
06471                                         sprintf("%02d", $date["mday"])." ".
06472                                         sprintf("%02d", $date["hours"]).":".
06473                                         sprintf("%02d", $date["minutes"]).":".
06474                                         sprintf("%02d", $date["seconds"])
06475                                 ),
06476                                 $processing_time,
06477                                 $time_left
06478                         )
06479                 );
06480                 $this->tpl->parseCurrentBlock();
06481         }
06482         
06483         function outShortResult ($user_question_order) {
06484                 $this->tpl->setCurrentBlock("percentage");
06485                 $this->tpl->setVariable("PERCENTAGE", (int)(($this->sequence / count($user_question_order))*200));
06486                 $this->tpl->setVariable("PERCENTAGE_VALUE", (int)(($this->sequence / count($user_question_order))*100));
06487                 $this->tpl->setVariable("HUNDRED_PERCENT", "200");
06488                 $this->tpl->setVariable("TEXT_COMPLETED", $this->lng->txt("completed") . ": ");
06489                 $this->tpl->parseCurrentBlock();
06490                 $this->tpl->setCurrentBlock("percentage_bottom");
06491                 $this->tpl->setVariable("PERCENTAGE", (int)(($this->sequence / count($user_question_order))*200));
06492                 $this->tpl->setVariable("PERCENTAGE_VALUE", (int)(($this->sequence / count($user_question_order))*100));
06493                 $this->tpl->setVariable("HUNDRED_PERCENT", "200");
06494                 $this->tpl->setVariable("TEXT_COMPLETED", $this->lng->txt("completed") . ": ");
06495                 $this->tpl->parseCurrentBlock();                                
06496         }
06497         
06506         function isMaxProcessingTimeReached() 
06507         {
06508                 global $ilUser;
06509                 $starting_time = $this->object->getStartingTimeOfUser($ilUser->getId());
06510                 if ($starting_time === FALSE)
06511                 {
06512                         return FALSE;
06513                 }
06514                 else
06515                 {
06516                         return $this->object->isMaxProcessingTimeReached($starting_time);
06517                 }
06518         }
06519         
06520         function isEndingTimeReached () {
06521                 global $ilUser;
06522                 if (!is_bool($this->endingTimeReached))                 
06523                         $this->endingTimeReached = $this->object->endingTimeReached() && ($this->object->getTestType() == TYPE_ASSESSMENT || $this->object->isOnlineTest());
06524                         
06525                 return $this->endingTimeReached;
06526         }
06527 
06533         function getTabs(&$tabs_gui)
06534         {
06535                 $tabs_gui->getTargetsByObjectType($this, "tst");
06536 
06537                 $tabs_gui->addTarget("meta_data",
06538                          $this->ctrl->getLinkTargetByClass('ilmdeditorgui',''),
06539                          "meta_data", get_class($this));
06540         }
06541 
06542                                 
06543 } // END class.ilObjTestGUI
06544 
06545 ?>

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