public function persistCMIData($userId = null, $packageId, $defaultLessonMode, $comments, $interactions, $objectives, $data = null)
 {
     global $ilLog;
     if ($defaultLessonMode == "browse") {
         return;
     }
     $jsMode = strpos($_SERVER['HTTP_ACCEPT'], 'text/javascript') !== false;
     $data = json_decode(is_string($data) ? $data : file_get_contents('php://input'));
     $ilLog->write("dataTo_setCMIData: " . file_get_contents('php://input'));
     if (!$data) {
         return;
     }
     if ($userId == null) {
         $userId = (int) $data->p;
         self::checkIfAllowed($packageId, $userId, $data->hash);
         //			header('Access-Control-Allow-Origin: http://localhost:50012');//just for tests - not for release UK
     }
     $return = array();
     $return = ilSCORM2004StoreData::setCMIData($userId, $packageId, $data, $comments, $interactions, $objectives);
     //$new_global_status=ilSCORM2004StoreData::setGlobalObjectivesAndGetGlobalStatus($userId, $packageId, $data);
     ilSCORM2004StoreData::setGlobalObjectives($userId, $packageId, $data);
     $new_global_status = $data->now_global_status;
     $return["new_global_status"] = $new_global_status;
     ilSCORM2004StoreData::syncGlobalStatus($userId, $packageId, $data, $new_global_status);
     $ilLog->write("SCORM: return of persistCMIData: " . json_encode($return));
     if ($jsMode) {
         header('Content-Type: text/javascript; charset=UTF-8');
         print json_encode($return);
     } else {
         header('Content-Type: text/html; charset=UTF-8');
         print var_export($return, true);
     }
 }
 function sop2il()
 {
     //		sleep(5);
     global $ilDB, $ilUser;
     $in = file_get_contents("php://input");
     $GLOBALS['ilLog']->write($in);
     $ret = array('msg' => array(), 'err' => array());
     if (!$in || $in == "") {
         $ret['err'][] = "no post data recieved";
         print json_encode($ret);
         exit;
     }
     $userId = $ilUser->getID();
     $result = true;
     if ($this->type == 'scorm2004') {
         $lm_set = $ilDB->queryF('SELECT default_lesson_mode, interactions, objectives, comments FROM sahs_lm WHERE id = %s', array('integer'), array($this->obj_id));
         while ($lm_rec = $ilDB->fetchAssoc($lm_set)) {
             $defaultLessonMode = $lm_rec["default_lesson_mode"];
             $interactions = ilUtil::yn2tf($lm_rec["interactions"]);
             $objectives = ilUtil::yn2tf($lm_rec["objectives"]);
             $comments = ilUtil::yn2tf($lm_rec["comments"]);
         }
         include_once './Modules/Scorm2004/classes/class.ilSCORM2004StoreData.php';
         $data = json_decode($in);
         $GLOBALS['ilLog']->write('cmi_count=' . count($data->cmi));
         for ($i = 0; $i < count($data->cmi); $i++) {
             if ($result == true) {
                 //$a_r=array();
                 $cdata = $data->cmi[$i];
                 $a_r = ilSCORM2004StoreData::setCMIData($userId, $this->obj_id, $data->cmi[$i], $comments, $interactions, $objectives);
                 if (!is_array($a_r)) {
                     $result = false;
                 }
             }
         }
         if ($result == true) {
             $result = ilSCORM2004StoreData::syncGlobalStatus($userId, $this->obj_id, $data, $data->now_global_status);
         }
     } else {
         include_once "./Modules/ScormAicc/classes/SCORM/class.ilObjSCORMTracking.php";
         $data = json_decode($in);
         $result = ilObjSCORMTracking::storeJsApiCmi($userId, $this->obj_id, $data);
         if ($result == true) {
             $result = ilObjSCORMTracking::syncGlobalStatus($userId, $this->obj_id, $data, $data->now_global_status);
         }
     }
     if ($result == true) {
         $result = self::scormPlayerUnloadForSOP2il($data);
     }
     if ($result == false) {
         $ret['err'][] = "invalid post data recieved";
     } else {
         $ret['msg'][] = "post data recieved";
     }
     header('Content-Type: text/plain; charset=UTF-8');
     print json_encode($ret);
 }