$name = $user_infos['firstname'] . ' ' . $user_infos['lastname'];
if (!api_is_platform_admin(true) && !CourseManager::is_course_teacher($_user['user_id'], $cidReq) && !Tracking::is_allowed_to_coach_student($_user['user_id'], $_GET['student_id']) && $user_infos['hr_dept_id'] !== $_user['user_id']) {
    Display::display_header('');
    api_not_allowed();
    Display::display_footer();
}
$course_exits = CourseManager::course_exists($cidReq);
if (!empty($course_exits)) {
    $_course = CourseManager::get_course_information($cidReq);
} else {
    api_not_allowed();
}
$_course['dbNameGlu'] = $_configuration['table_prefix'] . $_course['db_name'] . $_configuration['db_glue'];
$lp_id = intval($_GET['lp_id']);
$lp_view_id = cloud_getLpViewId($cidReq, $lp_id, $user_id);
$regid = cloud_getRegId($cidReq, $lp_view_id);
$interbreadcrumb[] = array("url" => api_get_path(WEB_COURSE_PATH) . $_course['directory'], 'name' => $_course['title']);
$interbreadcrumb[] = array("url" => "../tracking/courseLog.php?cidReq=" . $cidReq . '&studentlist=true&id_session=' . $_SESSION['id_session'], "name" => get_lang("Tracking"));
$interbreadcrumb[] = array("url" => "../mySpace/myStudents.php?student=" . Security::remove_XSS($_GET['student_id']) . "&course=" . $cidReq . "&details=true&origin=" . Security::remove_XSS($_GET['origin']), "name" => get_lang("DetailsStudentInCourse"));
$interbreadcrumb[] = array("url" => "cloudCourseDetails.php?regid=" . $regid . "&course=" . $cidReq . "&lp_id=" . $lp_id . "&student_id=" . $user_id, "name" => "Course Activity Report");
$nameTools = get_lang('launchHistoryReport');
$htmlHeadXtra[] = '
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){

    });
    </script>
<script type="text/javascript">
        var extConfigurationString = "";
        var reportsHelperUrl = "LaunchHistoryHelper.php";
	Copyright (c) 2009 Rustici Software
	
	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	See the GNU General Public License for more details.

==============================================================================
*/
require_once '../newscorm/back_compat.inc.php';
require_once '../newscorm/learnpath.class.php';
require_once 'scorm_cloud.lib.php';
//get the courseid and userid
//Dokeos Course ID (a db, training, etc. - can contain many courses (or none))
$cid = $_GET['cidReq'];
//learningPath Id - learningpath is a course
$lp_id = $_GET['lp_id'];
$userInfo = api_get_user_info();
$userId = $userInfo['user_id'];
$need_to_create_reg = false;
$lp_view_id = cloud_getLpViewId($cid, $lp_id, $userId, true);
//echo $lp_view_id;
$regId = cloud_getRegId($cid, $lp_view_id);
$ScormService = cloud_getScormEngineService();
$regService = $ScormService->getRegistrationService();
$exitUrl = api_get_path(WEB_PATH) . 'main/scorm_cloud/RegistrationResults.php?regid=' . $regId . '&lp_id=' . $lp_id;
$launchUrl = $regService->GetLaunchUrl($regId, $exitUrl, null, null, $cid . ',TEST1', "TEST2,TEST3");
//echo $launchUrl;
header('location: ' . $launchUrl);
function cloud_deleteRegistrations($cid, $lp_id)
{
    $ScormService = cloud_getScormEngineService();
    $regService = $ScormService->getRegistrationService();
    $lpv_table = Database::get_course_table_from_code($cid, TABLE_LP_VIEW);
    //selecting by view_count descending allows to get the highest view_count first
    $sql = "SELECT * FROM {$lpv_table} WHERE lp_id = {$lp_id}";
    $view_res = api_sql_query($sql, __FILE__, __LINE__);
    while ($row = Database::fetch_array($view_res)) {
        $lp_view_id = $row['id'];
        $regid = cloud_getRegId($cid, $lp_view_id);
        //echo $regid.' ';
        $regService->DeleteRegistration($regid, 'false');
    }
    $tbl_scorm_cloud = Database::get_main_table('scorm_cloud');
    $sql_cloud_delete = "Delete From {$tbl_scorm_cloud} " . "Where course_code = '{$cid}' AND lp_id = {$lp_id}";
    $res_insert2 = api_sql_query($sql_cloud_delete, __FILE__, __LINE__);
}