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

content/classes/SCORM/class.ilSCORMPresentationGUI.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2006 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 require_once("content/classes/class.ilObjSCORMLearningModule.php");
00025 require_once("content/classes/SCORM/class.ilSCORMObjectGUI.php");
00026 //require_once("./classes/class.ilMainMenuGUI.php");
00027 //require_once("./classes/class.ilObjStyleSheet.php");
00028 
00039 class ilSCORMPresentationGUI
00040 {
00041         var $ilias;
00042         var $slm;
00043         var $tpl;
00044         var $lng;
00045 
00046         function ilSCORMPresentationGUI()
00047         {
00048                 global $ilias, $tpl, $lng, $ilCtrl;
00049 
00050                 $this->ilias =& $ilias;
00051                 $this->tpl =& $tpl;
00052                 $this->lng =& $lng;
00053                 $this->ctrl =& $ilCtrl;
00054 
00055                 // Todo: check lm id
00056                 $this->slm =& new ilObjSCORMLearningModule($_GET["ref_id"], true);
00057         }
00058         
00062         function &executeCommand()
00063         {
00064                 global $ilAccess, $ilLog,$ilErr;
00065 
00066                 $next_class = $this->ctrl->getNextClass($this);
00067                 $cmd = $this->ctrl->getCmd("frameset");
00068 
00069                 if (!$ilAccess->checkAccess("read", "", $_GET["ref_id"]))
00070                 {
00071                         $ilErr->raiseError($this->lng->txt('permission_denied'),$ilErr->WARNING);
00072                 }
00073 
00074                 switch($next_class)
00075                 {
00076                         default:
00077                                 $this->$cmd();
00078                 }
00079         }
00080 
00081 
00082         function attrib2arr(&$a_attributes)
00083         {
00084                 $attr = array();
00085                 if(!is_array($a_attributes))
00086                 {
00087                         return $attr;
00088                 }
00089                 foreach ($a_attributes as $attribute)
00090                 {
00091                         $attr[$attribute->name()] = $attribute->value();
00092                 }
00093                 return $attr;
00094         }
00095 
00096 
00101         function frameset()
00102         {
00103 //echo "h".strtolower(get_class($this->slm))."h";
00104                 include_once("content/classes/SCORM/class.ilSCORMObject.php");
00105                 $items = ilSCORMObject::_lookupPresentableItems($this->slm->getId());
00106 
00107                 if (count($items) > 1
00108                         || strtolower(get_class($this->slm)) == "ilobjaicclearningmodule"
00109                         || strtolower(get_class($this->slm)) == "ilobjhacplearningmodule")
00110                 {
00111                         $this->ctrl->setParameter($this, "expand", "1");
00112                         $exp_link = $this->ctrl->getLinkTarget($this, "explorer");
00113                         $this->tpl = new ilTemplate("tpl.sahs_pres_frameset.html", false, false, "content");
00114                         $this->tpl->setVariable("EXPLORER_LINK", $exp_link);
00115                         $api_link = $this->ctrl->getLinkTarget($this, "api");
00116                         $this->tpl->setVariable("API_LINK", $api_link);
00117                         $pres_link = $this->ctrl->getLinkTarget($this, "view");
00118                         $this->tpl->setVariable("PRESENTATION_LINK", $pres_link);
00119                         $this->tpl->show("DEFAULT", false);
00120                 }
00121                 else if (count($items) == 1)
00122                 {
00123                         //$this->ctrl->setParameter($this, "expand", "1");
00124                         //$exp_link = $this->ctrl->getLinkTarget($this, "explorer");
00125                         $this->tpl = new ilTemplate("tpl.sahs_pres_frameset_one_page.html",
00126                                 false, false, "content");
00127                         //$this->tpl->setVariable("EXPLORER_LINK", $exp_link);
00128                         $this->ctrl->setParameter($this, "autolaunch", $items[0]);
00129                         $api_link = $this->ctrl->getLinkTarget($this, "api");
00130                         $this->tpl->setVariable("API_LINK", $api_link);
00131                         $pres_link = $this->ctrl->getLinkTarget($this, "view");
00132                         $this->tpl->setVariable("PRESENTATION_LINK", $pres_link);
00133                         $this->tpl->show("DEFAULT", false);
00134                 }
00135                 exit;
00136         }
00137 
00138 
00142         function explorer($a_target = "sahs_content")
00143         {
00144                 global $ilBench, $ilLog;
00145 
00146                 $ilBench->start("SCORMExplorer", "initExplorer");
00147                 
00148                 $this->tpl = new ilTemplate("tpl.sahs_exp_main.html", true, true, true);
00149                 //$this->tpl->setVariable("LOCATION_JAVASCRIPT", "./scorm_functions.js");
00150                 
00151                 require_once("./content/classes/SCORM/class.ilSCORMExplorer.php");
00152                 $exp = new ilSCORMExplorer($this->ctrl->getLinkTarget($this, "view"), $this->slm);
00153                 $exp->setTargetGet("obj_id");
00154                 $exp->setFrameTarget($a_target);
00155                 
00156                 //$exp->setFiltered(true);
00157 
00158                 if ($_GET["scexpand"] == "")
00159                 {
00160                         $mtree = new ilSCORMTree($this->slm->getId());
00161                         $expanded = $mtree->readRootId();
00162                 }
00163                 else
00164                 {
00165                         $expanded = $_GET["scexpand"];
00166                 }
00167                 $exp->setExpand($expanded);
00168                 
00169                 $exp->forceExpandAll(true, false);
00170                 $ilBench->stop("SCORMExplorer", "initExplorer");
00171 
00172                 // build html-output
00173                 $ilBench->start("SCORMExplorer", "setOutput");
00174                 $exp->setOutput(0);
00175                 $ilBench->stop("SCORMExplorer", "setOutput");
00176 
00177                 $ilBench->start("SCORMExplorer", "getOutput");
00178                 $output = $exp->getOutput();
00179                 $ilBench->stop("SCORMExplorer", "getOutput");
00180 
00181                 $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation());
00182                 $this->tpl->addBlockFile("CONTENT", "content", "tpl.sahs_explorer.html", "content");
00183                 //$this->tpl->setVariable("TXT_EXPLORER_HEADER", $this->lng->txt("cont_content"));
00184                 $this->tpl->setVariable("EXP_REFRESH", $this->lng->txt("refresh"));
00185                 $this->tpl->setVariable("EXPLORER",$output);
00186                 $this->tpl->setVariable("ACTION", "sahs_presentation.php?cmd=".$_GET["cmd"]."&frame=".$_GET["frame"].
00187                         "&ref_id=".$this->slm->getRefId()."&scexpand=".$_GET["scexpand"]);
00188                 $this->tpl->parseCurrentBlock();
00189                 $this->tpl->show();
00190         }
00191 
00192 
00196         function view()
00197         {
00198                 $sc_gui_object =& ilSCORMObjectGUI::getInstance($_GET["obj_id"]);
00199 
00200                 if(is_object($sc_gui_object))
00201                 {
00202                         $sc_gui_object->view();
00203                 }
00204 
00205                 $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation());
00206                 $this->tpl->show(false);
00207         }
00208 
00209         function api()
00210         {
00211                 global $ilias;
00212 
00213                 $slm_obj =& new ilObjSCORMLearningModule($_GET["ref_id"]);
00214 
00215                 $this->tpl = new ilTemplate("tpl.sahs_api.html", true, true, true);
00216                 
00217                 // for scorm modules with only one presentable item: launch item
00218                 if ($_GET["autolaunch"] != "")
00219                 {
00220                         $this->tpl->setCurrentBlock("auto_launch");
00221                         include_once("content/classes/SCORM/class.ilSCORMItem.php");
00222                         include_once("content/classes/SCORM/class.ilSCORMResource.php");
00223                         $sc_object =& new ilSCORMItem($_GET["autolaunch"]);
00224                         $id_ref = $sc_object->getIdentifierRef();
00225                         $sc_res_id = ilSCORMResource::_lookupIdByIdRef($id_ref, $sc_object->getSLMId());
00226                         $scormtype = strtolower(ilSCORMResource::_lookupScormType($sc_res_id));
00227                         
00228                         if ($scormtype == "asset")
00229                         {
00230                                 $item_command = "IliasLaunchAsset";
00231                         }
00232                         else
00233                         {
00234                                 $item_command = "IliasLaunchSahs";
00235                         }
00236                         $this->tpl->setVariable("AUTO_LAUNCH_ID", $_GET["autolaunch"]);
00237                         $this->tpl->setVariable("AUTO_LAUNCH_CMD", "this.autoLaunch();");
00238                         $this->tpl->setVariable("AUTO_LAUNCH_ITEM_CMD", $item_command);
00239                         $this->tpl->parseCurrentBlock();
00240                 }
00241 
00242                 $this->tpl->setVariable("USER_ID",$ilias->account->getId());
00243                 $this->tpl->setVariable("USER_FIRSTNAME",$ilias->account->getFirstname());
00244                 $this->tpl->setVariable("USER_LASTNAME",$ilias->account->getLastname());
00245                 $this->tpl->setVariable("REF_ID",$_GET["ref_id"]);
00246                 $this->tpl->setVariable("SESSION_ID",session_id());
00247                 $this->tpl->setVariable("CODE_BASE", "http://".$_SERVER['SERVER_NAME'].substr($_SERVER['PHP_SELF'], 0, strpos ($_SERVER['PHP_SELF'], "/sahs_presentation.php")));
00248                 
00249                 $this->tpl->parseCurrentBlock();
00250                 $this->tpl->show(false);
00251                 exit;
00252         }
00253 
00258         function launchSahs()
00259         {
00260                 global $ilUser, $ilDB;
00261 
00262                 $sco_id = ($_GET["sahs_id"] == "")
00263                         ? $_POST["sahs_id"]
00264                         : $_GET["sahs_id"];
00265                 $ref_id = ($_GET["ref_id"] == "")
00266                         ? $_POST["ref_id"]
00267                         : $_GET["ref_id"];
00268 
00269                 $this->slm =& new ilObjSCORMLearningModule($ref_id, true);
00270 
00271                 include_once("content/classes/SCORM/class.ilSCORMItem.php");
00272                 include_once("content/classes/SCORM/class.ilSCORMResource.php");
00273                 $item =& new ilSCORMItem($sco_id);
00274 
00275                 $id_ref = $item->getIdentifierRef();
00276                 $resource =& new ilSCORMResource();
00277                 $resource->readByIdRef($id_ref, $item->getSLMId());
00278                 //$slm_obj =& new ilObjSCORMLearningModule($_GET["ref_id"]);
00279                 $href = $resource->getHref();
00280                 $this->tpl = new ilTemplate("tpl.sahs_launch_cbt.html", true, true, true);
00281                 $this->tpl->setVariable("HREF", $this->slm->getDataDirectory("output")."/".$href);
00282 
00283                 // set item data
00284                 $this->tpl->setVariable("LAUNCH_DATA", $item->getDataFromLms());
00285                 $this->tpl->setVariable("MAST_SCORE", $item->getMasteryScore());
00286                 $this->tpl->setVariable("MAX_TIME", $item->getMaxTimeAllowed());
00287                 $this->tpl->setVariable("LIMIT_ACT", $item->getTimeLimitAction());
00288 
00289                 // set alternative API name
00290                 if ($this->slm->getAPIAdapterName() != "API")
00291                 {
00292                         $this->tpl->setCurrentBlock("alt_api_ref");
00293                         $this->tpl->setVariable("API_NAME", $this->slm->getAPIAdapterName());
00294                         $this->tpl->parseCurrentBlock();
00295                 }
00296 
00297                 $query = "SELECT * FROM scorm_tracking WHERE".
00298                         " user_id = ".$ilDB->quote($ilUser->getId()).
00299                         " AND sco_id = ".$ilDB->quote($sco_id);
00300 
00301 
00302                 $val_set = $ilDB->query($query);
00303                 $re_value = array();
00304                 while($val_rec = $val_set->fetchRow(DB_FETCHMODE_ASSOC))
00305                 {
00306                         $val_rec["rvalue"] = str_replace("\r\n", "\n", $val_rec["rvalue"]);
00307                         $val_rec["rvalue"] = str_replace("\r", "\n", $val_rec["rvalue"]);
00308                         $val_rec["rvalue"] = str_replace("\n", "\\n", $val_rec["rvalue"]);
00309                         $re_value[$val_rec["lvalue"]] = $val_rec["rvalue"];
00310                 }
00311                 
00312                 foreach($re_value as $var => $value)
00313                 {
00314                         switch ($var)
00315                         {
00316                                 case "cmi.core.lesson_location":
00317                                 case "cmi.core.lesson_status":
00318                                 case "cmi.core.entry":
00319                                 case "cmi.core.score.raw":
00320                                 case "cmi.core.score.max":
00321                                 case "cmi.core.score.min":
00322                                 case "cmi.core.total_time":
00323                                 case "cmi.core.exit":
00324                                 case "cmi.suspend_data":
00325                                 case "cmi.comments":
00326                                 case "cmi.student_preference.audio":
00327                                 case "cmi.student_preference.language":
00328                                 case "cmi.student_preference.speed":
00329                                 case "cmi.student_preference.text":
00330                                         $this->setSingleVariable($var, $value);
00331                                         break;
00332 
00333                                 case "cmi.objectives._count":
00334                                         $this->setSingleVariable($var, $value);
00335                                         $this->setArray("cmi.objectives", $value, "id", $re_value);
00336                                         $this->setArray("cmi.objectives", $value, "score.raw", $re_value);
00337                                         $this->setArray("cmi.objectives", $value, "score.max", $re_value);
00338                                         $this->setArray("cmi.objectives", $value, "score.min", $re_value);
00339                                         $this->setArray("cmi.objectives", $value, "status", $re_value);
00340                                         break;
00341 
00342                                 case "cmi.interactions._count":
00343                                         $this->setSingleVariable($var, $value);
00344                                         $this->setArray("cmi.interactions", $value, "id", $re_value);
00345                                         for($i=0; $i<$value; $i++)
00346                                         {
00347                                                 $var2 = "cmi.interactions.".$i.".objectives._count";
00348                                                 if (isset($v_array[$var2]))
00349                                                 {
00350                                                         $cnt = $v_array[$var2];
00351                                                         $this->setArray("cmi.interactions.".$i.".objectives",
00352                                                                 $cnt, "id", $re_value);
00353                                                         /*
00354                                                         $this->setArray("cmi.interactions.".$i.".objectives",
00355                                                                 $cnt, "score.raw", $re_value);
00356                                                         $this->setArray("cmi.interactions.".$i.".objectives",
00357                                                                 $cnt, "score.max", $re_value);
00358                                                         $this->setArray("cmi.interactions.".$i.".objectives",
00359                                                                 $cnt, "score.min", $re_value);
00360                                                         $this->setArray("cmi.interactions.".$i.".objectives",
00361                                                                 $cnt, "status", $re_value);*/
00362                                                 }
00363                                         }
00364                                         $this->setArray("cmi.interactions", $value, "time", $re_value);
00365                                         $this->setArray("cmi.interactions", $value, "type", $re_value);
00366                                         for($i=0; $i<$value; $i++)
00367                                         {
00368                                                 $var2 = "cmi.interactions.".$i.".correct_responses._count";
00369                                                 if (isset($v_array[$var2]))
00370                                                 {
00371                                                         $cnt = $v_array[$var2];
00372                                                         $this->setArray("cmi.interactions.".$i.".correct_responses",
00373                                                                 $cnt, "pattern", $re_value);
00374                                                         $this->setArray("cmi.interactions.".$i.".correct_responses",
00375                                                                 $cnt, "weighting", $re_value);
00376                                                 }
00377                                         }
00378                                         $this->setArray("cmi.interactions", $value, "student_response", $re_value);
00379                                         $this->setArray("cmi.interactions", $value, "result", $re_value);
00380                                         $this->setArray("cmi.interactions", $value, "latency", $re_value);
00381                                         break;
00382                         }
00383                 }
00384 
00385                 global $lng;
00386                 $this->tpl->setCurrentBlock("switch_icon");
00387                 $this->tpl->setVariable("SCO_ID", $_GET["sahs_id"]);
00388                 $this->tpl->setVariable("SCO_ICO", ilUtil::getImagePath("scorm/running.gif"));
00389                 $this->tpl->setVariable("SCO_ALT",
00390                          $lng->txt("cont_status").": "
00391                         .$lng->txt("cont_sc_stat_running")
00392                 );
00393                 $this->tpl->parseCurrentBlock();
00394                 
00395                 // set icon, if more than one SCO/Asset is presented
00396                 $items = ilSCORMObject::_lookupPresentableItems($this->slm->getId());
00397                 if (count($items) > 1
00398                         || strtolower(get_class($this->slm)) == "ilobjaicclearningmodule"
00399                         || strtolower(get_class($this->slm)) == "ilobjhacplearningmodule")
00400                 {
00401                         $this->tpl->setVariable("SWITCH_ICON_CMD", "switch_icon();");
00402                 }
00403 
00404 
00405                 // lesson mode
00406                 $lesson_mode = $this->slm->getDefaultLessonMode();
00407                 if ($this->slm->getAutoReview())
00408                 {
00409                         if ($re_value["cmi.core.lesson_status"] == "completed" ||
00410                                 $re_value["cmi.core.lesson_status"] == "passed" ||
00411                                 $re_value["cmi.core.lesson_status"] == "failed")
00412                         {
00413                                 $lesson_mode = "review";
00414                         }
00415                 }
00416                 $this->tpl->setVariable("LESSON_MODE", $lesson_mode);
00417 
00418                 // credit mode
00419                 if ($lesson_mode == "normal")
00420                 {
00421                         $this->tpl->setVariable("CREDIT_MODE",
00422                                 str_replace("_", "-", $this->slm->getCreditMode()));
00423                 }
00424                 else
00425                 {
00426                         $this->tpl->setVariable("CREDIT_MODE", "no-credit");
00427                 }
00428 
00429                 // init cmi.core.total_time, cmi.core.lesson_status and cmi.core.entry
00430                 $sahs_obj_id = ilObject::_lookupObjId($_GET["ref_id"]);
00431                 if (!isset($re_value["cmi.core.total_time"]))
00432                 {
00433                         $item->insertTrackData("cmi.core.total_time", "0000:00:00", $sahs_obj_id);
00434                 }
00435                 if (!isset($re_value["cmi.core.lesson_status"]))
00436                 {
00437                         $item->insertTrackData("cmi.core.lesson_status", "not attempted", $sahs_obj_id);
00438                 }
00439                 if (!isset($re_value["cmi.core.entry"]))
00440                 {
00441                         $item->insertTrackData("cmi.core.entry", "", $sahs_obj_id);
00442                 }
00443 
00444                 $this->tpl->show();
00445                 //echo htmlentities($this->tpl->get()); exit;
00446         }
00447 
00448         function finishSahs ()
00449         {
00450                 global $lng;
00451                 $this->tpl = new ilTemplate("tpl.sahs_finish_cbt.html", true, true, true);
00452                 $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation());
00453 
00454                 $this->tpl->setCurrentBlock("switch_icon");
00455                 $this->tpl->setVariable("SCO_ID", $_GET["sahs_id"]);
00456                 $this->tpl->setVariable("SCO_ICO", ilUtil::getImagePath(
00457                         "scorm/".str_replace(" ", "_", $_GET["status"]).'.gif')
00458                 );
00459                 $this->tpl->setVariable("SCO_ALT",
00460                          $lng->txt("cont_status").": "
00461                         .$lng->txt("cont_sc_stat_".str_replace(" ", "_", $_GET["status"])).", "
00462                         .$lng->txt("cont_total_time").  ": "
00463                         .$_GET["totime"]
00464                 );
00465                 $this->tpl->setVariable("SCO_LAUNCH_ID", $_GET["launch"]);
00466                 $this->tpl->parseCurrentBlock();
00467                 $this->tpl->show();
00468         }
00469 
00470         function unloadSahs ()
00471         {
00472                 $this->tpl = new ilTemplate("tpl.sahs_unload_cbt.html", true, true, true);
00473                 $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation());
00474                 $this->tpl->setVariable("SCO_ID", $_GET["sahs_id"]);
00475                 $this->tpl->show();
00476         }
00477 
00478 
00479         function launchAsset()
00480         {
00481                 global $ilUser, $ilDB;
00482 
00483                 $sco_id = ($_GET["asset_id"] == "")
00484                         ? $_POST["asset_id"]
00485                         : $_GET["asset_id"];
00486                 $ref_id = ($_GET["ref_id"] == "")
00487                         ? $_POST["ref_id"]
00488                         : $_GET["ref_id"];
00489 
00490                 $this->slm =& new ilObjSCORMLearningModule($ref_id, true);
00491 
00492                 include_once("content/classes/SCORM/class.ilSCORMItem.php");
00493                 include_once("content/classes/SCORM/class.ilSCORMResource.php");
00494                 $item =& new ilSCORMItem($sco_id);
00495 
00496                 $id_ref = $item->getIdentifierRef();
00497                 $resource =& new ilSCORMResource();
00498                 $resource->readByIdRef($id_ref, $item->getSLMId());
00499                 $href = $resource->getHref();
00500                 $this->tpl->setVariable("HREF", $this->slm->getDataDirectory("output")."/".$href);
00501                 $this->tpl = new ilTemplate("tpl.scorm_launch_asset.html", true, true, true);
00502                 $this->tpl->setVariable("HREF", $this->slm->getDataDirectory("output")."/".$href);
00503                 $this->tpl->show();
00504         }
00505 
00506 
00510         function setSingleVariable($a_var, $a_value)
00511         {
00512                 $this->tpl->setCurrentBlock("set_value");
00513                 $this->tpl->setVariable("VAR", $a_var);
00514                 $this->tpl->setVariable("VALUE", $a_value);
00515                 $this->tpl->parseCurrentBlock();
00516         }
00517 
00521         function setArray($a_left, $a_value, $a_name, &$v_array)
00522         {
00523                 for($i=0; $i<$a_value; $i++)
00524                 {
00525                         $var = $a_left.".".$i.".".$a_name;
00526                         if (isset($v_array[$var]))
00527                         {
00528                                 $this->tpl->setCurrentBlock("set_value");
00529                                 $this->tpl->setVariable("VAR", $var);
00530                                 $this->tpl->setVariable("VALUE", $v_array[$var]);
00531                                 $this->tpl->parseCurrentBlock();
00532                         }
00533                 }
00534         }
00535 }
00536 ?>

Generated on Fri Dec 13 2013 13:52:10 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1