/**
  * Get all completed tests
  */
 protected function getItems()
 {
     global $ilUser, $tree;
     $data = array();
     include_once "Services/Certificate/classes/class.ilCertificate.php";
     if (ilCertificate::isActive()) {
         $obj_ids = array();
         $root = $tree->getNodeData($tree->getRootId());
         foreach ($tree->getSubTree($root, true, "sahs") as $node) {
             $obj_ids[] = $node["obj_id"];
         }
         if ($obj_ids) {
             include_once "./Services/Tracking/classes/class.ilObjUserTracking.php";
             include_once "./Services/Tracking/classes/class.ilLPStatus.php";
             include_once "./Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php";
             include_once "./Modules/ScormAicc/classes/class.ilObjSCORMLearningModule.php";
             include_once "./Modules/Scorm2004/classes/class.ilObjSCORM2004LearningModule.php";
             include_once "./Modules/ScormAicc/classes/class.ilSCORMCertificateAdapter.php";
             $lp_active = ilObjUserTracking::_enabledLearningProgress();
             foreach (ilCertificate::areObjectsActive($obj_ids) as $obj_id => $active) {
                 if ($active) {
                     $type = ilObjSAHSLearningModule::_lookupSubType($obj_id);
                     if ($type == "scorm") {
                         $lm = new ilObjSCORMLearningModule($obj_id, false);
                     } else {
                         $lm = new ilObjSCORM2004LearningModule($obj_id, false);
                     }
                     $adapter = new ilSCORMCertificateAdapter($lm);
                     if (ilCertificate::_isComplete($adapter)) {
                         $lpdata = $completed = false;
                         if ($lp_active) {
                             $completed = ilLPStatus::_hasUserCompleted($obj_id, $ilUser->getId());
                             $lpdata = true;
                         }
                         if (!$lpdata) {
                             switch ($type) {
                                 case "scorm":
                                     $completed = ilObjSCORMLearningModule::_getCourseCompletionForUser($obj_id, $ilUser->getId());
                                     break;
                                 case "scorm2004":
                                     $completed = ilObjSCORM2004LearningModule::_getCourseCompletionForUser($obj_id, $ilUser->getId());
                                     break;
                             }
                         }
                         $data[] = array("id" => $obj_id, "title" => ilObject::_lookupTitle($obj_id), "passed" => (bool) $completed);
                     }
                 }
             }
         }
     }
     $this->setData($data);
 }
 public function getScoresForUserAndCP_Node_Id($item_id, $user_id)
 {
     include_once './Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php';
     switch (ilObjSAHSLearningModule::_lookupSubType($this->obj_id)) {
         case 'hacp':
         case 'aicc':
             include_once './Modules/ScormAicc/classes/class.ilObjAICCLearningModule.php';
             return ilObjAICCLearningModule::_getScoresForUser($item_id, $user_id);
         case 'scorm':
             include_once './Modules/ScormAicc/classes/class.ilObjSCORMLearningModule.php';
             //include_once './Modules/ScormAicc/classes/SCORM/class.ilSCORMItem.php';
             return ilObjSCORMLearningModule::_getScoresForUser($item_id, $user_id);
         case 'scorm2004':
             include_once './Modules/Scorm2004/classes/class.ilObjSCORM2004LearningModule.php';
             return ilObjSCORM2004LearningModule::_getScores2004ForUser($item_id, $user_id);
     }
     return array("raw" => null, "max" => null, "scaled" => null);
 }
 /**
  * Import relevant properties from given learning module
  *
  * @param ilObjSAHSLearningModule $a_lm
  * @return object
  */
 public static function createFromSCORMLM(ilObjSAHSLearningModule $a_lm, $a_user_id)
 {
     global $lng;
     $lng->loadLanguageModule("sahs");
     $newObj = new self();
     $newObj->setTitle($a_lm->getTitle());
     $newObj->setDescription($a_lm->getDescription());
     include_once "Services/Tracking/classes/class.ilLPMarks.php";
     $lp_marks = new ilLPMarks($a_lm->getId(), $a_user_id);
     $newObj->setProperty("issued_on", new ilDate($lp_marks->getStatusChanged(), IL_CAL_DATETIME));
     // create certificate
     if (!stristr(get_class($a_lm), "2004")) {
         $last_access = ilObjSCORMLearningModule::_lookupLastAccess($a_lm->getId(), $a_user_id);
     } else {
         $last_access = ilObjSCORM2004LearningModule::_lookupLastAccess($a_lm->getId(), $a_user_id);
     }
     $params = array("user_data" => ilObjUser::_lookupFields($a_user_id), "last_access" => $last_access);
     include_once "Services/Certificate/classes/class.ilCertificate.php";
     include_once "Modules/ScormAicc/classes/class.ilSCORMCertificateAdapter.php";
     $certificate = new ilCertificate(new ilSCORMCertificateAdapter($a_lm));
     $certificate = $certificate->outCertificate($params, false);
     // save pdf file
     if ($certificate) {
         // we need the object id for storing the certificate file
         $newObj->create();
         $path = self::initStorage($newObj->getId(), "certificate");
         $file_name = "sahs_" . $a_lm->getId() . "_" . $a_user_id . ".pdf";
         if (file_put_contents($path . $file_name, $certificate)) {
             $newObj->setProperty("file", $file_name);
             $newObj->update();
             return $newObj;
         }
         // file creation failed, so remove to object, too
         $newObj->delete();
     }
 }
 /**
  * Paste item (tree) from clipboard or other learning module to target scorm learning module
  *
  * @param object $a_target_slm target scorm 2004 learning module object
  * @param int $a_item_id id of item that should be pasted
  * @param int $a_parent_id parent id in target tree,
  * @param int $a_target predecessor target node, no ID means: last child
  * @param string $a_insert_time cliboard insert time (not needed, if $a_from_cliboard is false)
  * @param array $a_copied_nodes array of IDs od copied nodes, key is ID of source node, value is ID of copied node
  * @param bool $a_as_copy if true, items are copied otherwise they are moved
  * @param bool $a_from_clipboard if true, child node information is read from clipboard, otherwise from source tree
  */
 static function pasteTree($a_target_slm, $a_item_id, $a_parent_id, $a_target, $a_insert_time, &$a_copied_nodes, $a_as_copy = false, $a_from_clipboard = true)
 {
     global $ilUser, $ilias, $ilLog;
     // source lm id, item type and lm object
     $item_slm_id = ilSCORM2004Node::_lookupSLMID($a_item_id);
     $item_type = ilSCORM2004Node::_lookupType($a_item_id);
     //$slm_obj = $ilias->obj_factory->getInstanceByObjId($item_slm_id);
     include_once "./Modules/Scorm2004/classes/class.ilObjSCORM2004LearningModule.php";
     $slm_obj = new ilObjSCORM2004LearningModule($item_slm_id, false);
     if ($item_type == "chap") {
         include_once "./Modules/Scorm2004/classes/class.ilSCORM2004Chapter.php";
         $item = new ilSCORM2004Chapter($slm_obj, $a_item_id);
     } else {
         if ($item_type == "page") {
             include_once "./Modules/Scorm2004/classes/class.ilSCORM2004PageNode.php";
             $item = new ilSCORM2004PageNode($slm_obj, $a_item_id);
         } else {
             if ($item_type == "sco") {
                 include_once "./Modules/Scorm2004/classes/class.ilSCORM2004Sco.php";
                 $item = new ilSCORM2004Sco($slm_obj, $a_item_id);
             } else {
                 if ($item_type == "ass") {
                     include_once "./Modules/Scorm2004/classes/class.ilSCORM2004Asset.php";
                     $item = new ilSCORM2004Asset($slm_obj, $a_item_id);
                 }
             }
         }
     }
     $ilLog->write("Getting from clipboard type " . $item_type . ", " . "Item ID: " . $a_item_id . ", of original SLM: " . $item_slm_id);
     if ($item_slm_id != $a_target_slm->getId() && !$a_as_copy) {
         // @todo: check whether st is NOT in tree
         // "move" metadata to new lm
         include_once "Services/MetaData/classes/class.ilMD.php";
         $md = new ilMD($item_slm_id, $item->getId(), $item->getType());
         $new_md = $md->cloneMD($a_target_slm->getId(), $item->getId(), $item->getType());
         // update lm object
         $item->setSLMId($a_target_slm->getId());
         $item->setSLMObject($a_target_slm);
         $item->update();
         // delete old meta data set
         $md->deleteAll();
         if ($item_type == "page") {
             $page = $item->getPageObject();
             $page->buildDom($a_from_clipboard);
             $page->setParentId($a_target_slm->getId());
             $page->update();
         }
     }
     if ($a_as_copy) {
         $target_item = $item->copy($a_target_slm);
         $a_copied_nodes[$item->getId()] = $target_item->getId();
     } else {
         $target_item = $item;
     }
     $ilLog->write("Putting into tree type " . $target_item->getType() . "Item ID: " . $target_item->getId() . ", Parent: " . $a_parent_id . ", " . "Target: " . $a_target . ", Item LM:" . $target_item->getContentObject()->getId());
     ilSCORM2004Node::putInTree($target_item, $a_parent_id, $a_target);
     if ($a_from_clipboard) {
         $childs = $ilUser->getClipboardChilds($item->getId(), $a_insert_time);
     } else {
         // get childs of source tree
         $source_tree = $slm_obj->getTree();
         $childs = $source_tree->getChilds($a_item_id);
     }
     foreach ($childs as $child) {
         $child_id = $a_from_clipboard ? $child["id"] : $child["child"];
         ilSCORM2004Node::pasteTree($a_target_slm, $child_id, $target_item->getId(), IL_LAST_NODE, $a_insert_time, $a_copied_nodes, $a_as_copy);
     }
     return $target_item->getId();
 }
    /**
     * Synch read event table
     *
     * @param
     * @return
     */
    function _syncReadEvent($a_obj_id, $a_user_id, $a_type, $a_ref_id)
    {
        global $ilDB, $ilLog;
        // get attempts
        $val_set = $ilDB->queryF('
		SELECT rvalue FROM cmi_custom 
		WHERE user_id = %s
				AND sco_id = %s
				AND lvalue = %s
				AND obj_id = %s', array('integer', 'integer', 'text', 'integer'), array($a_user_id, 0, 'package_attempts', $a_obj_id));
        $val_rec = $ilDB->fetchAssoc($val_set);
        $val_rec["rvalue"] = str_replace("\r\n", "\n", $val_rec["rvalue"]);
        if ($val_rec["rvalue"] == null) {
            $val_rec["rvalue"] = "";
        }
        $attempts = $val_rec["rvalue"];
        // time
        $scos = array();
        $val_set = $ilDB->queryF('SELECT cp_node_id FROM cp_node 
			WHERE nodename = %s
			AND cp_node.slm_id = %s', array('text', 'integer'), array('item', $a_obj_id));
        while ($val_rec = $ilDB->fetchAssoc($val_set)) {
            array_push($scos, $val_rec['cp_node_id']);
        }
        $time = 0;
        foreach ($scos as $sco) {
            include_once "./Modules/Scorm2004/classes/class.ilObjSCORM2004LearningModule.php";
            $data_set = $ilDB->queryF('
				SELECT total_time
				FROM cmi_node 
				WHERE cp_node_id = %s
				AND user_id = %s', array('integer', 'integer'), array($sco, $a_user_id));
            while ($data_rec = $ilDB->fetchAssoc($data_set)) {
                // see bug report 7246
                //				$sec = ilObjSCORM2004LearningModule::_ISODurationToCentisec($data_rec["session_time"]) / 100;
                $sec = ilObjSCORM2004LearningModule::_ISODurationToCentisec($data_rec["total_time"]) / 100;
            }
            $time += (int) $sec;
            $sec = 0;
            //$ilLog->write("++".$time);
        }
        include_once "./Services/Tracking/classes/class.ilChangeEvent.php";
        ilChangeEvent::_recordReadEvent($a_type, $a_ref_id, $a_obj_id, $a_user_id, false, $attempts, $time);
    }
 /**
  * save new learning module to db
  */
 function saveObject()
 {
     if (trim($_POST["title"]) == "") {
         $this->ilias->raiseError($this->lng->txt("msg_no_title"), $this->ilias->error_obj->MESSAGE);
     }
     include_once "./Modules/Scorm2004/classes/class.ilObjSCORM2004LearningModule.php";
     $newObj = new ilObjSCORM2004LearningModule();
     $newObj->setTitle(ilUtil::stripSlashes($_POST["title"]));
     $newObj->setSubType("scorm2004");
     $newObj->setEditable(true);
     $newObj->setDescription(ilUtil::stripSlashes($_POST["desc"]));
     $newObj->create();
     $newObj->createReference();
     $newObj->putInTree($_GET["ref_id"]);
     $newObj->setPermissions($_GET["ref_id"]);
     $newObj->notify("new", $_GET["ref_id"], $_GET["parent_non_rbac_id"], $_GET["ref_id"], $newObj->getRefId());
     $newObj->createDataDirectory();
     $newObj->createScorm2004Tree();
     ilUtil::sendInfo($this->lng->txt($newObj->getType() . "_added"), true);
     ilUtil::redirect("ilias.php?baseClass=ilSAHSEditGUI&ref_id=" . $newObj->getRefId());
 }
 /**
  * Get participant ids for given object
  *
  * @param	int		$a_ref_id
  * @return	array
  */
 public static function getParticipantsForObject($a_ref_id)
 {
     global $tree;
     $obj_id = ilObject::_lookupObjectId($a_ref_id);
     $obj_type = ilObject::_lookupType($obj_id);
     // try to get participants from (parent) course/group
     switch ($obj_type) {
         case "crs":
             include_once "Modules/Course/classes/class.ilCourseParticipants.php";
             $member_obj = ilCourseParticipants::_getInstanceByObjId($obj_id);
             return $member_obj->getMembers();
         case "grp":
             include_once "Modules/Group/classes/class.ilGroupParticipants.php";
             $member_obj = ilGroupParticipants::_getInstanceByObjId($obj_id);
             return $member_obj->getMembers();
         default:
             // walk path to find course or group object and use members of that object
             $path = $tree->getPathId($a_ref_id);
             array_pop($path);
             foreach (array_reverse($path) as $path_ref_id) {
                 $type = ilObject::_lookupType($path_ref_id, true);
                 if ($type == "crs" || $type == "grp") {
                     return self::getParticipantsForObject($path_ref_id);
                 }
             }
             break;
     }
     $a_users = null;
     // no participants possible: use tracking/object data where possible
     switch ($obj_type) {
         case "sahs":
             include_once "./Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php";
             $subtype = ilObjSAHSLearningModule::_lookupSubType($obj_id);
             if ($subtype == "scorm2004") {
                 // based on cmi_node/cp_node, used for scorm tracking data views
                 include_once "./Modules/Scorm2004/classes/class.ilObjSCORM2004LearningModule.php";
                 $mod = new ilObjSCORM2004LearningModule($obj_id, false);
                 $all = $mod->getTrackedUsers("");
                 if ($all) {
                     $a_users = array();
                     foreach ($all as $item) {
                         $a_users[] = $item["user_id"];
                     }
                 }
             } else {
                 include_once "./Modules/ScormAicc/classes/SCORM/class.ilObjSCORMTracking.php";
                 $a_users = ilObjSCORMTracking::_getTrackedUsers($obj_id);
             }
             break;
         case "exc":
             include_once "./Modules/Exercise/classes/class.ilExerciseMembers.php";
             include_once "./Modules/Exercise/classes/class.ilObjExercise.php";
             $exc = new ilObjExercise($obj_id, false);
             $members = new ilExerciseMembers($exc);
             $a_users = $members->getMembers();
             break;
         case "tst":
             include_once "./Services/Tracking/classes/class.ilLPStatusTestFinished.php";
             $a_users = ilLPStatusTestFinished::getParticipants($obj_id);
             break;
         default:
             // no sensible data: return null
             break;
     }
     return $a_users;
 }
 function _getStatusInfo($a_obj_id)
 {
     // Which sco's determine the status
     include_once './Services/Object/classes/class.ilObjectLP.php';
     $olp = ilObjectLP::getInstance($a_obj_id);
     $collection = $olp->getCollectionInstance();
     if ($collection) {
         $status_info['scos'] = $collection->getItems();
     } else {
         $status_info['scos'] = array();
     }
     $status_info['num_scos'] = count($status_info['scos']);
     // Get subtype
     include_once './Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php';
     $status_info['subtype'] = ilObjSAHSLearningModule::_lookupSubType($a_obj_id);
     switch ($status_info['subtype']) {
         case 'hacp':
         case 'aicc':
             include_once './Modules/ScormAicc/classes/SCORM/class.ilObjSCORMTracking.php';
             $status_info['num_completed'] = ilObjSCORMTracking::_getCountCompletedPerUser($status_info['scos'], $a_obj_id);
             include_once './Modules/ScormAicc/classes/class.ilObjAICCLearningModule.php';
             foreach (ilObjAICCLearningModule::_getTrackingItems($a_obj_id) as $item) {
                 if (in_array($item['obj_id'], $status_info['scos'])) {
                     $status_info['scos_title']["{$item['obj_id']}"] = $item['title'];
                 }
             }
             $info = ilObjSCORMTracking::_getProgressInfo($status_info['scos'], $a_obj_id);
             break;
         case 'scorm':
             include_once './Modules/ScormAicc/classes/SCORM/class.ilObjSCORMTracking.php';
             $status_info['num_completed'] = ilObjSCORMTracking::_getCountCompletedPerUser($status_info['scos'], $a_obj_id);
             include_once './Modules/ScormAicc/classes/SCORM/class.ilSCORMItem.php';
             foreach ($status_info['scos'] as $sco_id) {
                 $status_info['scos_title'][$sco_id] = ilSCORMItem::_lookupTitle($sco_id);
             }
             $info = ilObjSCORMTracking::_getProgressInfo($status_info['scos'], $a_obj_id);
             break;
         case "scorm2004":
             include_once './Modules/Scorm2004/classes/class.ilSCORM2004Tracking.php';
             $status_info['num_completed'] = ilSCORM2004Tracking::_getCountCompletedPerUser($status_info['scos'], $a_obj_id, true);
             include_once './Modules/Scorm2004/classes/class.ilObjSCORM2004LearningModule.php';
             foreach ($status_info['scos'] as $sco_id) {
                 $status_info['scos_title'][$sco_id] = ilObjSCORM2004LearningModule::_lookupItemTitle($sco_id);
             }
             $info = ilSCORM2004Tracking::_getItemProgressInfo($status_info['scos'], $a_obj_id, true);
             break;
     }
     $status_info['completed'] = array();
     $status_info['failed'] = array();
     $status_info['in_progress'] = array();
     foreach ($status_info['scos'] as $sco_id) {
         $status_info['completed'][$sco_id] = $info['completed'][$sco_id] ? $info['completed'][$sco_id] : array();
         $status_info['failed'][$sco_id] = $info['failed'][$sco_id] ? $info['failed'][$sco_id] : array();
         $status_info['in_progress'][$sco_id] = $info['in_progress'][$sco_id] ? $info['in_progress'][$sco_id] : array();
     }
     //var_dump($status_info["completed"]);
     return $status_info;
 }
 /**
  * Clone scorm object
  *
  * @param int target ref_id
  * @param int copy id
  */
 public function cloneObject($a_target_id, $a_copy_id = 0)
 {
     global $ilDB, $ilUser, $ilias;
     $new_obj = parent::cloneObject($a_target_id, $a_copy_id);
     $this->cloneMetaData($new_obj);
     // copy properties
     $new_obj->setTitle($this->getTitle());
     $new_obj->setDescription($this->getDescription());
     $new_obj->setSubType($this->getSubType());
     $new_obj->setAPIAdapterName($this->getAPIAdapterName());
     $new_obj->setAPIFunctionsPrefix($this->getAPIFunctionsPrefix());
     $new_obj->setAutoReviewChar($this->getAutoReviewChar());
     $new_obj->setDefaultLessonMode($this->getDefaultLessonMode());
     $new_obj->setEditable($this->getEditable());
     $new_obj->setMaxAttempt($this->getMaxAttempt());
     //		$new_obj->getModuleVersion($this->getModuleVersion());	??
     $new_obj->setModuleVersion(1);
     $new_obj->setCreditMode($this->getCreditMode());
     $new_obj->setAssignedGlossary($this->getAssignedGlossary());
     $new_obj->setTries($this->getTries());
     $new_obj->setSession($this->getSession());
     $new_obj->setNoMenu($this->getNoMenu());
     $new_obj->setHideNavig($this->getHideNavig());
     $new_obj->setSequencing($this->getSequencing());
     $new_obj->setInteractions($this->getInteractions());
     $new_obj->setObjectives($this->getObjectives());
     $new_obj->setComments($this->getComments());
     $new_obj->setTime_from_lms($this->getTime_from_lms());
     $new_obj->setDebug($this->getDebug());
     $new_obj->setLocalization($this->getLocalization());
     $new_obj->setSequencingExpertMode($this->getSequencingExpertMode());
     $new_obj->setDebugPw($this->getDebugPw());
     $new_obj->setOpenMode($this->getOpenMode());
     $new_obj->setWidth($this->getWidth());
     $new_obj->setHeight($this->getHeight());
     $new_obj->setAutoContinue($this->getAutoContinue());
     $new_obj->setAuto_last_visited($this->getAuto_last_visited());
     $new_obj->setCheck_values($this->getCheck_values());
     $new_obj->setOfflineMode($this->getOfflineMode());
     $new_obj->setAutoSuspend($this->getAutoSuspend());
     $new_obj->update();
     // set/copy stylesheet
     /*		include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
     		$style_id = $this->getStyleSheetId();
     		if ($style_id > 0 && !ilObjStyleSheet::_lookupStandard($style_id))
     		{
     			$style_obj = $ilias->obj_factory->getInstanceByObjId($style_id);
     			$new_id = $style_obj->ilClone();
     			$new_obj->setStyleSheetId($new_id);
     			$new_obj->update();
     		}*/
     // up to this point $new_obj is of type ilobjsahslearning module
     // create instance of correct subtype and call forward it to
     // cloneIntoNewObject method
     switch ($this->getSubType()) {
         case "scorm":
             include_once "./Modules/ScormAicc/classes/class.ilObjSCORMLearningModule.php";
             $source_obj = new ilObjSCORMLearningModule($this->getRefId());
             $new_obj = new ilObjSCORMLearningModule($new_obj->getRefId());
             break;
         case "scorm2004":
             include_once "./Modules/Scorm2004/classes/class.ilObjSCORM2004LearningModule.php";
             $source_obj = new ilObjSCORM2004LearningModule($this->getRefId());
             $new_obj = new ilObjSCORM2004LearningModule($new_obj->getRefId());
             break;
         case "aicc":
             include_once "./Modules/ScormAicc/classes/class.ilObjAICCLearningModule.php";
             $source_obj = new ilObjAICCLearningModule($this->getRefId());
             $new_obj = new ilObjAICCLearningModule($new_obj->getRefId());
             break;
         case "hacp":
             include_once "./Modules/ScormAicc/classes/class.ilObjHACPLearningModule.php";
             $source_obj = new ilObjHACPLearningModule($this->getRefId());
             $new_obj = new ilObjHACPLearningModule($new_obj->getRefId());
             break;
     }
     // copy data directory
     $new_obj->populateByDirectoy($source_obj->getDataDirectory());
     // copy authored content ...
     if ($new_obj->getEditable()) {
         $source_obj->copyAuthoredContent($new_obj);
     } else {
         // ... or read manifest file
         $new_obj->readObject();
     }
     return $new_obj;
 }
 /**
  * Download the certificate for the active user
  */
 public function downloadCertificate()
 {
     global $ilUser, $tree, $ilCtrl;
     $allowed = false;
     $last_access = 0;
     $obj_id = ilObject::_lookupObjId($_GET["ref_id"]);
     include_once "./Modules/ScormAicc/classes/class.ilObjSAHSLearningModuleAccess.php";
     if (ilObjSAHSLearningModuleAccess::_lookupUserCertificate($obj_id)) {
         include_once "./Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php";
         $type = ilObjSAHSLearningModule::_lookupSubType($obj_id);
         switch ($type) {
             case "scorm":
                 include_once "./Modules/ScormAicc/classes/class.ilObjSCORMLearningModule.php";
                 $allowed = true;
                 $last_access = ilObjSCORMLearningModule::_lookupLastAccess($obj_id, $ilUser->getId());
                 break;
             case "scorm2004":
                 include_once "./Modules/Scorm2004/classes/class.ilObjSCORM2004LearningModule.php";
                 $allowed = true;
                 $last_access = ilObjSCORM2004LearningModule::_lookupLastAccess($obj_id, $ilUser->getId());
                 break;
             default:
                 break;
         }
     }
     if ($allowed) {
         include_once "./Services/Certificate/classes/class.ilCertificate.php";
         include_once "./Modules/ScormAicc/classes/class.ilSCORMCertificateAdapter.php";
         $certificate = new ilCertificate(new ilSCORMCertificateAdapter($this->slm));
         $params = array("user_data" => ilObjUser::_lookupFields($ilUser->getId()), "last_access" => $last_access);
         $certificate->outCertificate($params, true);
         exit;
     }
     // redirect to parent category if certificate is not accessible
     $parent = $tree->getParentId($_GET["ref_id"]);
     $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $parent);
     $ilCtrl->redirectByClass("ilrepositorygui", "");
 }
 /**
  * Checks whether a certificate exists for the active user or not
  * @param int obj_id Object ID of the SCORM Learning Module
  * @param int usr_id Object ID of the user. If not given, the active user will be taken
  * @return true/false
  */
 public static function _lookupUserCertificate($obj_id, $usr_id = 0)
 {
     global $ilUser;
     $uid = $usr_id ? $usr_id : $ilUser->getId();
     $completed = false;
     // check for certificates
     include_once "./Services/Certificate/classes/class.ilCertificate.php";
     if (ilCertificate::isActive() && ilCertificate::isObjectActive($obj_id)) {
         $lpdata = false;
         include_once "./Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php";
         $type = ilObjSAHSLearningModule::_lookupSubType($obj_id);
         include_once "Services/Tracking/classes/class.ilObjUserTracking.php";
         if (ilObjUserTracking::_enabledLearningProgress()) {
             include_once "./Services/Tracking/classes/class.ilLPStatus.php";
             $completed = ilLPStatus::_hasUserCompleted($obj_id, $uid);
             $lpdata = true;
         }
         switch ($type) {
             case "scorm":
                 if (!$lpdata) {
                     include_once "./Modules/ScormAicc/classes/class.ilObjSCORMLearningModule.php";
                     $completed = ilObjSCORMLearningModule::_getCourseCompletionForUser($obj_id, $uid);
                 }
                 break;
             case "scorm2004":
                 if (!$lpdata) {
                     include_once "./Modules/Scorm2004/classes/class.ilObjSCORM2004LearningModule.php";
                     $completed = ilObjSCORM2004LearningModule::_getCourseCompletionForUser($obj_id, $uid);
                 }
                 break;
             default:
                 break;
         }
     }
     return $completed;
 }
    /**
     * should be avoided; store value to increase performance for further requests
     */
    function getSumTotalTimeSecondsFromScos($a_obj_id, $a_user_id, $a_write = false)
    {
        global $ilDB, $ilLog;
        $scos = array();
        $val_set = $ilDB->queryF('SELECT cp_node_id FROM cp_node 
			WHERE nodename = %s
			AND cp_node.slm_id = %s', array('text', 'integer'), array('item', $a_obj_id));
        while ($val_rec = $ilDB->fetchAssoc($val_set)) {
            array_push($scos, $val_rec['cp_node_id']);
        }
        $time = 0;
        foreach ($scos as $sco) {
            include_once "./Modules/Scorm2004/classes/class.ilObjSCORM2004LearningModule.php";
            $data_set = $ilDB->queryF('
				SELECT total_time
				FROM cmi_node 
				WHERE cp_node_id = %s
				AND user_id = %s', array('integer', 'integer'), array($sco, $a_user_id));
            while ($data_rec = $ilDB->fetchAssoc($data_set)) {
                $sec = ilObjSCORM2004LearningModule::_ISODurationToCentisec($data_rec["total_time"]) / 100;
            }
            $time += (int) $sec;
            $sec = 0;
            //$ilLog->write("++".$time);
        }
        if ($a_write && $time > 0) {
            $ilDB->queryF('UPDATE sahs_user SET sco_total_time_sec=%s WHERE obj_id = %s AND user_id = %s', array('integer', 'integer', 'integer'), array($time, $a_obj_id, $a_user_id));
        }
        return $time;
    }
    function tracInteractionUser($a_user = array(), $a_sco = array(), $b_orderBySCO = false, $allowExportPrivacy = false)
    {
        global $ilDB, $lng;
        $lng->loadLanguageModule("scormtrac");
        $returnData = array();
        $scoTitles = self::scoTitlesForExportSelected();
        $scoProgress = self::markedLearningStatusForExportSelected($scoTitles);
        $a_correct = array();
        $a_incorrect = array();
        $a_other = array();
        $query = 'SELECT cmi_node.user_id, cmi_node.cp_node_id, count(*) as counter
				FROM cmi_interaction, cmi_node 
				WHERE ' . $ilDB->in('cp_node_id', $a_sco, false, 'integer') . ' 
				AND ' . $ilDB->in('cmi_node.user_id', $a_user, false, 'integer') . '
				AND cmi_node.cmi_node_id = cmi_interaction.cmi_node_id 
				AND cmi_interaction.result = %s 
				GROUP BY cmi_node.user_id,cmi_node.cp_node_id';
        $res = $ilDB->queryF($query, array('text'), array('correct'));
        while ($row = $ilDB->fetchAssoc($res)) {
            $a_correct[$row['user_id'] . ':' . $row['cp_node_id']] = $row['counter'];
        }
        $res = $ilDB->queryF($query, array('text'), array('incorrect'));
        while ($row = $ilDB->fetchAssoc($res)) {
            $a_incorrect[$row['user_id'] . ':' . $row['cp_node_id']] = $row['counter'];
        }
        $query = 'SELECT cmi_node.user_id, cmi_node.cp_node_id, count(*) as counter
				FROM cmi_interaction, cmi_node 
				WHERE ' . $ilDB->in('cp_node_id', $a_sco, false, 'integer') . ' 
				AND ' . $ilDB->in('cmi_node.user_id', $a_user, false, 'integer') . '
				AND cmi_node.cmi_node_id = cmi_interaction.cmi_node_id 
				AND cmi_interaction.result <> %s AND  cmi_interaction.result <> %s
				GROUP BY cmi_node.user_id,cmi_node.cp_node_id';
        $res = $ilDB->queryF($query, array('text', 'text'), array('correct', 'incorrect'));
        while ($row = $ilDB->fetchAssoc($res)) {
            $a_other[$row['user_id'] . ':' . $row['cp_node_id']] = $row['counter'];
        }
        $dbdata = array();
        $query = 'SELECT user_id, cp_node_id, ' . 'audio_captioning, audio_level, completion_status, completion_threshold, credit, delivery_speed, ' . 'c_entry, c_exit, c_language, location as c_location, c_mode, progress_measure, c_max, c_min, c_raw, scaled, ' . 'scaled_passing_score, session_time, success_status, total_time, c_timestamp, suspend_data, launch_data ' . 'FROM cmi_node ' . 'WHERE ' . $ilDB->in('cp_node_id', $a_sco, false, 'integer') . ' ' . 'AND ' . $ilDB->in('user_id', $a_user, false, 'integer') . ' ' . 'ORDER BY ';
        if ($b_orderBySCO) {
            $query .= 'cp_node_id, user_id';
        } else {
            $query .= 'user_id, cp_node_id';
        }
        $res = $ilDB->query($query);
        while ($row = $ilDB->fetchAssoc($res)) {
            $dbdata[] = $row;
        }
        foreach ($dbdata as $data) {
            $skey = $data["user_id"] . ':' . $data["cp_node_id"];
            $correct = 0;
            if ($a_correct[$skey] != null) {
                $correct = $a_correct[$skey];
            }
            $incorrect = 0;
            if ($a_incorrect[$skey] != null) {
                $incorrect = $a_incorrect[$skey];
            }
            $other = 0;
            if ($a_other[$skey] != null) {
                $other = $a_other[$skey];
            }
            $all = $correct + $incorrect + $other;
            $data["lm_id"] = $this->getObjId();
            $data["lm_title"] = $this->lmTitle;
            $data = array_merge($data, self::userDataArrayForExport($data["user_id"], $allowExportPrivacy));
            $data["sco_marked_for_learning_progress"] = $scoProgress[$data["cp_node_id"]];
            $data["sco_title"] = $scoTitles[$data["cp_node_id"]];
            $data["counter_i_correct"] = $correct;
            if ($all > 0) {
                $data["counter_i_correct_percent"] = $correct * 100 / $all;
            } else {
                $data["counter_i_correct_percent"] = 0;
            }
            $data["counter_i_incorrect"] = $incorrect;
            if ($all > 0) {
                $data["counter_i_incorrect_percent"] = $incorrect * 100 / $all;
            } else {
                $data["counter_i_incorrect_percent"] = 0;
            }
            $data["counter_i_other"] = $other;
            if ($all > 0) {
                $data["counter_i_other_percent"] = $other * 100 / $all;
            } else {
                $data["counter_i_other_percent"] = 0;
            }
            $data["audio_captioning"] = "" . $data["audio_captioning"];
            $data["audio_level"] = "" . $data["audio_level"];
            $data["completion_status"] = "" . $data["completion_status"];
            $data["completion_threshold"] = "" . $data["completion_threshold"];
            $data["credit"] = "" . $data["credit"];
            $data["delivery_speed"] = "" . $data["delivery_speed"];
            $data["c_entry"] = "" . $data["c_entry"];
            $data["c_exit"] = "" . $data["c_exit"];
            $data["c_language"] = "" . $data["c_language"];
            $data["c_location"] = "" . str_replace('"', '', $data["c_location"]);
            $data["c_mode"] = "" . $data["c_mode"];
            $data["progress_measure"] = "" . $data["progress_measure"];
            $data["c_max"] = "" . $data["c_max"];
            $data["c_min"] = "" . $data["c_min"];
            $data["c_raw"] = "" . $data["c_raw"];
            $data["scaled"] = "" . $data["scaled"];
            //$data["scaled"]*100)
            $data["scaled_passing_score"] = "" . $data["scaled_passing_score"];
            $data["session_time"] = "" . $data["session_time"];
            $data["session_time_seconds"] = "";
            if ($data["session_time"] != "") {
                $data["session_time_seconds"] = round(ilObjSCORM2004LearningModule::_ISODurationToCentisec($data["session_time"]) / 100);
            }
            $data["success_status"] = "" . $data["success_status"];
            $data["total_time"] = "" . $data["total_time"];
            $data["total_time_seconds"] = "";
            if ($data["total_time"] != "") {
                $data["total_time_seconds"] = round(ilObjSCORM2004LearningModule::_ISODurationToCentisec($data["total_time"]) / 100);
            }
            $data["c_timestamp"] = $data["c_timestamp"];
            //ilDatePresentation::formatDate(new ilDateTime($data["c_timestamp"],IL_CAL_UNIX));
            $data["suspend_data"] = "" . $data["suspend_data"];
            $data["launch_data"] = "" . $data["launch_data"];
            // if ($data["success_status"]!="" && $data["success_status"]!="unknown") {
            // $status = $data["success_status"];
            // } else {
            // if ($data["completion_status"]=="") {
            // $status="unknown";
            // } else {
            // $status = $data["completion_status"];
            // }
            // }
            $returnData[] = $data;
        }
        return $returnData;
    }