/**
  * get instance of specialized GUI class
  *
  * static
  */
 function &getInstance($a_id)
 {
     $object = new ilSCORMObject($a_id);
     switch ($object->getType()) {
         case "sit":
             // item
             $item =& new ilSCORMItemGUI($a_id);
             return $item;
             break;
         case "sos":
             // organizations
             $sos_gui =& new ilSCORMOrganizationsGUI($a_id);
             return $sos_gui;
             break;
         case "sor":
             // organization
             $sor_gui =& new ilSCORMOrganizationGUI($a_id);
             return $sor_gui;
             break;
         case "sma":
             // manifest
             $sma_gui =& new ilSCORMManifestGUI($a_id);
             return $sma_gui;
             break;
         case "srs":
             // resources
             $srs_gui =& new ilSCORMResourcesGUI($a_id);
             return $srs_gui;
             break;
         case "sre":
             // resource
             $sre_gui =& new ilSCORMResourceGUI($a_id);
             return $sre_gui;
             break;
     }
 }
 function delete()
 {
     global $ilDB;
     parent::delete();
     $ilDB->manipulateF('DELETE FROM sc_resource WHERE obj_id = %s', array('integer'), array($this->getId()));
     $ilDB->manipulateF('DELETE FROM sc_resource_file WHERE res_id = %s', array('integer'), array($this->getId()));
     $ilDB->manipulateF('DELETE FROM sc_resource_dependen WHERE res_id = %s', array('integer'), array($this->getId()));
 }
 function delete()
 {
     global $ilDB;
     parent::delete();
     $ilDB->manipulateF('DELETE FROM sc_manifest WHERE obj_id = %s', array('integer'), array($this->getId()));
 }
    /**
     * delete SCORM learning module and all related data
     *
     * this method has been tested on may 9th 2004
     * meta data, scorm lm data, scorm tree, scorm objects (organization(s),
     * manifest, resources and items), tracking data and data directory
     * have been deleted correctly as desired
     *
     * @access	public
     * @return	boolean	true if all object data were removed; false if only a references were removed
     */
    function delete()
    {
        global $ilDB, $ilLog;
        // always call parent delete function first!!
        if (!parent::delete()) {
            return false;
        }
        // delete meta data of scorm content object
        /*
        		$nested = new ilNestedSetXML();
        		$nested->init($this->getId(), $this->getType());
        		$nested->deleteAllDBData();
        */
        $this->deleteMetaData();
        // delete data directory
        ilUtil::delDir($this->getDataDirectory());
        // delete scorm learning module record
        $ilDB->manipulateF('DELETE FROM sahs_lm WHERE id = %s', array('integer'), array($this->getId()));
        $ilLog->write("SAHS Delete(SAHSLM), Subtype: " . $this->getSubType());
        if ($this->getSubType() == "scorm") {
            // remove all scorm objects and scorm tree
            include_once "./Modules/ScormAicc/classes/SCORM/class.ilSCORMTree.php";
            include_once "./Modules/ScormAicc/classes/SCORM/class.ilSCORMObject.php";
            $sc_tree = new ilSCORMTree($this->getId());
            $r_id = $sc_tree->readRootId();
            if ($r_id > 0) {
                $items = $sc_tree->getSubTree($sc_tree->getNodeData($r_id));
                foreach ($items as $item) {
                    $sc_object =& ilSCORMObject::_getInstance($item["obj_id"], $this->getId());
                    if (is_object($sc_object)) {
                        $sc_object->delete();
                    }
                }
                $sc_tree->removeTree($sc_tree->getTreeId());
            }
        }
        if ($this->getSubType() != "scorm") {
            // delete aicc data
            $res = $ilDB->queryF('
				SELECT aicc_object.obj_id FROM aicc_object, aicc_units
				WHERE aicc_object.obj_id = aicc_units.obj_id
				AND aicc_object.slm_id = %s', array('integer'), array($this->getId()));
            while ($row = $ilDB->fetchAssoc($res)) {
                $obj_id = $row['obj_id'];
                $ilDB->manipulateF('
					DELETE FROM aicc_units WHERE obj_id = %s', array('integer'), array($obj_id));
            }
            $res = $ilDB->queryF('
				SELECT aicc_object.obj_id FROM aicc_object, aicc_course
				WHERE aicc_object.obj_id = aicc_course.obj_id
				AND aicc_object.slm_id = %s', array('integer'), array($this->getId()));
            while ($row = $ilDB->fetchAssoc($res)) {
                $obj_id = $row['obj_id'];
                $ilDB->manipulateF('
					DELETE FROM aicc_course WHERE obj_id = %s', array('integer'), array($obj_id));
            }
            $ilDB->manipulateF('
				DELETE FROM aicc_object WHERE slm_id = %s', array('integer'), array($this->getId()));
        }
        $q_log = "DELETE FROM scorm_tracking WHERE obj_id = " . $ilDB->quote($this->getId());
        $ilLog->write("SAHS Delete(SAHSLM): " . $q_log);
        $ilDB->manipulateF('DELETE FROM scorm_tracking WHERE obj_id = %s', array('integer'), array($this->getId()));
        $q_log = "DELETE FROM sahs_user WHERE obj_id = " . $ilDB->quote($this->getId());
        $ilLog->write("SAHS Delete(SAHSLM): " . $q_log);
        $ilDB->manipulateF('DELETE FROM sahs_user WHERE obj_id = %s', array('integer'), array($this->getId()));
        // always call parent delete function at the end!!
        return true;
    }
    /**
     * This function is called by the API applet in the content frame
     * when a SCO is started.
     */
    function launchSahs()
    {
        global $ilUser, $ilDB;
        $sco_id = $_GET["sahs_id"] == "" ? $_POST["sahs_id"] : $_GET["sahs_id"];
        $ref_id = $_GET["ref_id"] == "" ? $_POST["ref_id"] : $_GET["ref_id"];
        $this->slm =& new ilObjSCORMLearningModule($ref_id, true);
        include_once "./Modules/ScormAicc/classes/SCORM/class.ilSCORMItem.php";
        include_once "./Modules/ScormAicc/classes/SCORM/class.ilSCORMResource.php";
        $item =& new ilSCORMItem($sco_id);
        $id_ref = $item->getIdentifierRef();
        $resource =& new ilSCORMResource();
        $resource->readByIdRef($id_ref, $item->getSLMId());
        //$slm_obj =& new ilObjSCORMLearningModule($_GET["ref_id"]);
        $href = $resource->getHref();
        $this->tpl = new ilTemplate("tpl.sahs_launch_cbt.html", true, true, "Modules/ScormAicc");
        $this->tpl->setVariable("HREF", $this->slm->getDataDirectory("output") . "/" . $href);
        // set item data
        $this->tpl->setVariable("LAUNCH_DATA", $item->getDataFromLms());
        $this->tpl->setVariable("MAST_SCORE", $item->getMasteryScore());
        $this->tpl->setVariable("MAX_TIME", $item->getMaxTimeAllowed());
        $this->tpl->setVariable("LIMIT_ACT", $item->getTimeLimitAction());
        // set alternative API name
        if ($this->slm->getAPIAdapterName() != "API") {
            $this->tpl->setCurrentBlock("alt_api_ref");
            $this->tpl->setVariable("API_NAME", $this->slm->getAPIAdapterName());
            $this->tpl->parseCurrentBlock();
        }
        $val_set = $ilDB->queryF('
			SELECT * FROM scorm_tracking 
			WHERE user_id = %s
			AND sco_id = %s
			AND obj_id = %s', array('integer', 'integer', 'integer'), array($ilUser->getId(), $sco_id, $this->slm->getId()));
        $re_value = array();
        while ($val_rec = $ilDB->fetchAssoc($val_set)) {
            $val_rec["rvalue"] = str_replace("\r\n", "\n", $val_rec["rvalue"]);
            $val_rec["rvalue"] = str_replace("\r", "\n", $val_rec["rvalue"]);
            $val_rec["rvalue"] = str_replace("\n", "\\n", $val_rec["rvalue"]);
            $re_value[$val_rec["lvalue"]] = $val_rec["rvalue"];
        }
        foreach ($re_value as $var => $value) {
            switch ($var) {
                case "cmi.core.lesson_location":
                case "cmi.core.lesson_status":
                case "cmi.core.entry":
                case "cmi.core.score.raw":
                case "cmi.core.score.max":
                case "cmi.core.score.min":
                case "cmi.core.total_time":
                case "cmi.core.exit":
                case "cmi.suspend_data":
                case "cmi.comments":
                case "cmi.student_preference.audio":
                case "cmi.student_preference.language":
                case "cmi.student_preference.speed":
                case "cmi.student_preference.text":
                    $this->setSingleVariable($var, $value);
                    break;
                case "cmi.objectives._count":
                    $this->setSingleVariable($var, $value);
                    $this->setArray("cmi.objectives", $value, "id", $re_value);
                    $this->setArray("cmi.objectives", $value, "score.raw", $re_value);
                    $this->setArray("cmi.objectives", $value, "score.max", $re_value);
                    $this->setArray("cmi.objectives", $value, "score.min", $re_value);
                    $this->setArray("cmi.objectives", $value, "status", $re_value);
                    break;
                case "cmi.interactions._count":
                    $this->setSingleVariable($var, $value);
                    $this->setArray("cmi.interactions", $value, "id", $re_value);
                    for ($i = 0; $i < $value; $i++) {
                        $var2 = "cmi.interactions." . $i . ".objectives._count";
                        if (isset($v_array[$var2])) {
                            $cnt = $v_array[$var2];
                            $this->setArray("cmi.interactions." . $i . ".objectives", $cnt, "id", $re_value);
                            /*
                            							$this->setArray("cmi.interactions.".$i.".objectives",
                            								$cnt, "score.raw", $re_value);
                            							$this->setArray("cmi.interactions.".$i.".objectives",
                            								$cnt, "score.max", $re_value);
                            							$this->setArray("cmi.interactions.".$i.".objectives",
                            								$cnt, "score.min", $re_value);
                            							$this->setArray("cmi.interactions.".$i.".objectives",
                            								$cnt, "status", $re_value);*/
                        }
                    }
                    $this->setArray("cmi.interactions", $value, "time", $re_value);
                    $this->setArray("cmi.interactions", $value, "type", $re_value);
                    for ($i = 0; $i < $value; $i++) {
                        $var2 = "cmi.interactions." . $i . ".correct_responses._count";
                        if (isset($v_array[$var2])) {
                            $cnt = $v_array[$var2];
                            $this->setArray("cmi.interactions." . $i . ".correct_responses", $cnt, "pattern", $re_value);
                            $this->setArray("cmi.interactions." . $i . ".correct_responses", $cnt, "weighting", $re_value);
                        }
                    }
                    $this->setArray("cmi.interactions", $value, "student_response", $re_value);
                    $this->setArray("cmi.interactions", $value, "result", $re_value);
                    $this->setArray("cmi.interactions", $value, "latency", $re_value);
                    break;
            }
        }
        global $lng;
        $this->tpl->setCurrentBlock("switch_icon");
        $this->tpl->setVariable("SCO_ID", $_GET["sahs_id"]);
        $this->tpl->setVariable("SCO_ICO", ilUtil::getImagePath("scorm/running.png"));
        $this->tpl->setVariable("SCO_ALT", $lng->txt("cont_status") . ": " . $lng->txt("cont_sc_stat_running"));
        $this->tpl->parseCurrentBlock();
        // set icon, if more than one SCO/Asset is presented
        $items = ilSCORMObject::_lookupPresentableItems($this->slm->getId());
        if (count($items) > 1 || strtolower(get_class($this->slm)) == "ilobjaicclearningmodule" || strtolower(get_class($this->slm)) == "ilobjhacplearningmodule") {
            $this->tpl->setVariable("SWITCH_ICON_CMD", "switch_icon();");
        }
        // lesson mode
        $lesson_mode = $this->slm->getDefaultLessonMode();
        if ($this->slm->getAutoReview()) {
            if ($re_value["cmi.core.lesson_status"] == "completed" || $re_value["cmi.core.lesson_status"] == "passed" || $re_value["cmi.core.lesson_status"] == "failed") {
                $lesson_mode = "review";
            }
        }
        $this->tpl->setVariable("LESSON_MODE", $lesson_mode);
        // credit mode
        if ($lesson_mode == "normal") {
            $this->tpl->setVariable("CREDIT_MODE", str_replace("_", "-", $this->slm->getCreditMode()));
        } else {
            $this->tpl->setVariable("CREDIT_MODE", "no-credit");
        }
        // init cmi.core.total_time, cmi.core.lesson_status and cmi.core.entry
        $sahs_obj_id = ilObject::_lookupObjId($_GET["ref_id"]);
        if (!isset($re_value["cmi.core.total_time"])) {
            $item->insertTrackData("cmi.core.total_time", "0000:00:00", $sahs_obj_id);
        }
        if (!isset($re_value["cmi.core.lesson_status"])) {
            $item->insertTrackData("cmi.core.lesson_status", "not attempted", $sahs_obj_id);
        }
        if (!isset($re_value["cmi.core.entry"])) {
            $item->insertTrackData("cmi.core.entry", "", $sahs_obj_id);
        }
        $this->tpl->show();
        //echo htmlentities($this->tpl->get()); exit;
    }
 function delete()
 {
     global $ilDB;
     parent::delete();
     $query = 'DELETE FROM sc_organization WHERE obj_id = %s';
     $ilDB->manipulateF($query, array('integer'), array($this->getId()));
 }
 function delete()
 {
     global $ilDB, $ilLog;
     parent::delete();
     $ilDB->manipulateF('DELETE FROM sc_item WHERE obj_id = %s', array('integer'), array($this->getId()));
     $ilLog->write("SAHS Delete(ScormItem): " . 'DELETE FROM scorm_tracking WHERE sco_id = ' . $this->getId() . ' AND obj_id = ' . $this->getSLMId());
     $ilDB->manipulateF('DELETE FROM scorm_tracking WHERE sco_id = %s AND obj_id = %s', array('integer', 'integer'), array($this->getId(), $this->getSLMId()));
     include_once "./Services/Tracking/classes/class.ilLPStatusWrapper.php";
     ilLPStatusWrapper::_refreshStatus($this->getSLMId());
 }