Beispiel #1
0
 public function subscribeUserWithCode($params)
 {
     require_once _lms_ . '/lib/lib.subscribe.php';
     require_once _lms_ . '/lib/lib.course.php';
     $output = array();
     $output['success'] = true;
     if (empty($params['idst']) || (int) $params['idst'] <= 0) {
         return false;
     } else {
         $user_id = $params['idst'];
     }
     $registration_code_type = $params['reg_code_type'];
     $code = $params['reg_code'];
     $code = strtoupper($code);
     $code = str_replace('-', '', $code);
     if (empty($registration_code_type) || empty($code)) {
         $output['success'] = false;
     } else {
         if ($registration_code_type == 'tree_course') {
             $code = substr($code, 10, 10);
         }
         $course_registration_result = false;
         $man_course_user = new Man_CourseUser();
         $course_registration_result = $man_course_user->subscribeUserWithCode($code, $user_id);
         if ($course_registration_result <= 0) {
             if ($course_registration_result == 0) {
                 $output['message'] = 'Invalid code';
             } else {
                 if ($course_registration_result < 0) {
                     $output['message'] = 'Code already used';
                 }
             }
             $output['success'] = false;
         } else {
             $output['message'] = 'User has been subscribed to the course';
         }
     }
     return $output;
 }
Beispiel #2
0
function dashAcourse($id_course, $h_number)
{
    require_once _base_ . '/lib/lib.form.php';
    require_once _base_ . '/lib/lib.user_profile.php';
    require_once _base_ . '/lib/lib.navbar.php';
    require_once $GLOBALS['where_lms'] . '/lib/lib.preassessment.php';
    require_once $GLOBALS['where_lms'] . '/lib/lib.catalogue.php';
    require_once $GLOBALS['where_lms'] . '/lib/lib.coursepath.php';
    require_once $GLOBALS['where_lms'] . '/lib/lib.course.php';
    require_once $GLOBALS["where_lms"] . "/modules/coursecatalogue/lib.coursecatalogue.php";
    $lang =& DoceboLanguage::createInstance('standard', 'framework');
    $lang->setGlobal();
    $lang =& DoceboLanguage::createInstance('course', 'lms');
    $normal_subs = 1;
    $man_course = new DoceboCourse($id_course);
    $cinfo = $man_course->getAllInfo();
    $man_courseuser = new Man_CourseUser();
    $usercourses =& $man_courseuser->getUserSubscriptionsInfo(getLogUserId(), false);
    $select_edition = " SELECT * ";
    $from_edition = " FROM " . $GLOBALS["prefix_lms"] . "_course_edition";
    $where_edition = " WHERE idCourse = '" . $id_course . "' ";
    $order_edition = " ORDER BY date_begin ";
    $re_edition = sql_query($select_edition . $from_edition . $where_edition . $order_edition);
    $editions = array();
    if ($re_edition) {
        while ($edition_elem = mysql_fetch_assoc($re_edition)) {
            $edition_elem['waiting'] = 0;
            $edition_elem['user_count'] = 0;
            $edition_elem['theacher_list'] = getSubscribed($edition_elem["idCourse"], false, 6, true, $edition_elem["idCourseEdition"]);
            $editions[$edition_elem["idCourse"]][$edition_elem["idCourseEdition"]] = $edition_elem;
        }
    }
    $select_ed_count = "SELECT idCourse, edition_id, sum(waiting) as waiting, COUNT(*) as user_count ";
    $from_ed_count = "FROM " . $GLOBALS["prefix_lms"] . "_courseuser ";
    $where_ed_count = "WHERE edition_id <> 0 AND idCourse = '" . $id_course . "'";
    $group_ed_count = "GROUP BY edition_id ";
    $re_ed_count = sql_query($select_ed_count . $from_ed_count . $where_ed_count . $group_ed_count);
    if ($re_ed_count) {
        while ($ed_count_elem = mysql_fetch_assoc($re_ed_count)) {
            $editions[$ed_count_elem["idCourse"]][$ed_count_elem["edition_id"]]['waiting'] = $ed_count_elem['waiting'];
            $editions[$ed_count_elem["idCourse"]][$ed_count_elem["edition_id"]]['user_count'] = $ed_count_elem['user_count'];
        }
    }
    $cinfo['theacher_list'] = getSubscribed($cinfo['idCourse'], false, 6, true);
    $cinfo['edition_list'] = isset($editions[$cinfo['idCourse']]) ? $editions[$cinfo['idCourse']] : array();
    $cinfo['edition_available'] = count($cinfo['edition_list']);
    $cinfo['user_score'] = isset($user_score[$cinfo['idCourse']]) ? $user_score[$cinfo['idCourse']] : NULL;
    require_once _base_ . '/lib/lib.urlmanager.php';
    $url =& UrlManager::getInstance('catalogue');
    $url->setStdQuery('r=' . _after_login_);
    if ($normal_subs == 0) {
        $cinfo['can_subscribe'] = 0;
    }
    $html = dashcourse($url, $lang, $cinfo, isset($usercourses[$cinfo['idCourse']]) ? $usercourses[$cinfo['idCourse']] : false, 0, $h_number);
    return $html;
}
 function getCourseAtLevel($id_user, $lv)
 {
     require_once $GLOBALS['where_lms'] . '/lib/lib.course.php';
     $man_courseuser = new Man_CourseUser();
     $course = $man_courseuser->getUserCoursesLevelFilter($id_user, $lv, true);
     return $course;
 }
Beispiel #4
0
 function selectLmsWiki()
 {
     include_once _lms_ . '/lib/lib.course.php';
     include_once _base_ . '/lib/lib.form.php';
     include_once _lib_ . '/lib.table.php';
     $um =& UrlManager::getInstance();
     $back_url = $um->getUrl();
     $course_id = $this->getCourseId();
     if (isset($_POST["undo"])) {
         Util::jump_to($back_url);
     } else {
         if (isset($_POST["save"])) {
             $this->wikiManager->saveLmsSelectedWiki($course_id, $_POST);
             Util::jump_to($back_url);
         } else {
             $res = "";
             $form = new Form();
             $table_caption = $this->lang->def("_TABLE_SELECT_WIKI_CAP");
             $table_summary = $this->lang->def("_TABLE_SELECT_WIKI_SUM");
             $tab = new Table(0, $table_caption, $table_summary);
             $head = array($this->lang->def("_TITLE"), "");
             $head_type = array("", "image");
             $tab->setColsStyle($head_type);
             $tab->addHead($head);
             $course_list = Man_CourseUser::getUserCourseList(getLogUserId());
             $selectable_wiki = $this->wikiManager->getCourseWikiList($course_list);
             $wiki_list = $this->wikiManager->getCourseWikiList($course_id);
             $source_platform = $this->getSourcePlatform();
             $data_info = $this->wikiManager->getWikiList(FALSE, FALSE, " wiki_id IN (" . implode(',', $selectable_wiki['list']) . ") ", $source_platform);
             $data_arr = $data_info["data_arr"];
             $db_tot = $data_info["data_tot"];
             $tot = count($data_arr);
             for ($i = 0; $i < $tot; $i++) {
                 $id = $data_arr[$i]["wiki_id"];
                 $rowcnt = array();
                 $rowcnt[] = $data_arr[$i]["title"];
                 $check_cell = "";
                 $checked = in_array($id, $wiki_list["list"]) ? TRUE : FALSE;
                 $disabled = "";
                 if ($checked) {
                     $field_id = "db_sel_wiki_" . $id;
                     $field_name = "db_sel_wiki[" . $id . "]";
                     $check_cell .= $form->getHidden($field_id, $field_name, $id);
                     $is_owner = $wiki_list["data"][$id]["is_owner"] == 1 ? TRUE : FALSE;
                     if ($is_owner) {
                         $disabled = ' disabled="disabled"';
                         $field_id = "owned_wiki_" . $id;
                         $field_name = "owned_wiki[" . $id . "]";
                         $check_cell .= $form->getHidden($field_id, $field_name, $id);
                     }
                 }
                 $chk_id = "sel_wiki_" . $id;
                 $chk_name = "sel_wiki[" . $id . "]";
                 $check_cell .= $form->getCheckbox("", $chk_id, $chk_name, $id, $checked, $disabled);
                 $rowcnt[] = $check_cell;
                 $tab->addBody($rowcnt);
             }
             $url = $um->getUrl("op=selectwiki");
             $res .= $form->openForm("main_form", $url);
             $res .= $tab->getTable();
             $res .= $form->openButtonSpace();
             $res .= $form->getButton('save', 'save', $this->lang->def("_SAVE"));
             $res .= $form->getButton('undo', 'undo', $this->lang->def('_UNDO'));
             $res .= $form->closeButtonSpace();
             $res .= $form->closeForm();
             return $res;
         }
     }
 }
Beispiel #5
0
 function isViewerTeacher()
 {
     if ($this->_viewer_teacher != NULL) {
         return $this->_viewer_teacher;
     }
     require_once $GLOBALS['where_lms'] . '/lib/lib.course.php';
     $re = Man_CourseUser::getUserWithLevelFilter(array('4', '5', '6', '7'), array($this->_viewer));
     $this->_viewer_teacher = !empty($re);
     return $this->_viewer_teacher;
 }
 /**
  * processRegistrationCode
  * @param AclManager $acl_man
  * @param UserManagerAdmin $uma
  * @param int $iduser
  * @param string $reg_code
  * @param string $registration_code_type
  * @return array 'success'=>boolean, 'msg'=>string
  */
 public function processRegistrationCode(&$acl_man, &$uma, $iduser, $reg_code, $registration_code_type)
 {
     $res = array('success' => true, 'msg' => '');
     $lang =& DoceboLanguage::createInstance('register', 'lms');
     $code_is_mandatory = Get::sett('mandatory_code', 'off') == 'on';
     if ($reg_code != '') {
         switch ($registration_code_type) {
             case "0":
                 //nothin to do
                 break;
             case "tree_course":
                 //a mixed code, let's cut the tree part and go on with the tree_man and resolve here the course part
                 $course_code = substr(str_replace('-', '', $reg_code), 10, 10);
                 $reg_code = substr(str_replace('-', '', $reg_code), 0, 10);
                 //control course registration
                 require_once _lms_ . '/lib/lib.course.php';
                 $man_course_user = new Man_CourseUser();
                 $jolly_code = Get::sett('jolly_course_code', '');
                 if ($jolly_code == '' || $jolly_code != $course_code) {
                     $course_registration_result = $man_course_user->subscribeUserWithCode($course_code, $iduser);
                     if ($course_registration_result <= 0 && $code_is_mandatory) {
                         $res['success'] = false;
                         $res['msg'] = $lang->def('_INVALID_CODE');
                         return $res;
                     }
                 }
                 //procced with tree_man
             //procced with tree_man
             case "tree_man":
                 // resolving the tree_man
                 $array_folder = $uma->getFoldersFromCode($reg_code);
                 if (empty($array_folder) && $code_is_mandatory) {
                     //invalid code
                     $res['success'] = false;
                     $res['msg'] = $lang->def('_INVALID_CODE');
                     return $res;
                 }
                 break;
             case "code_module":
                 require_once _adm_ . '/lib/lib.code.php';
                 $code_manager = new CodeManager();
                 $valid_code = $code_manager->controlCodeValidity($reg_code);
                 if ($valid_code == 1) {
                     $array_folder = $code_manager->getOrgAssociateWithCode($reg_code);
                     $array_course = $code_manager->getCourseAssociateWithCode($reg_code);
                     $code_manager->setCodeUsed($reg_code, $iduser);
                 } elseif ($valid_code == 0) {
                     //duplicated code entered
                     $res['success'] = false;
                     $res['msg'] = $lang->def('_CODE_ALREDY_USED');
                     return $res;
                 } elseif ($valid_code == -1 && $code_is_mandatory) {
                     //invalid code entered
                     $res['success'] = false;
                     $res['msg'] = $lang->def('_INVALID_CODE');
                     return $res;
                 }
                 break;
             case "tree_drop":
                 // from the dropdown we will recive the id of the folder
                 $array_folder = array($reg_code => $reg_code);
                 //is a valid id ?
                 break;
             case "custom":
                 //Custom code
                 require_once _adm_ . '/lib/lib.field.php';
                 $field_man = new FieldList();
                 $id_common_filed_1 = $field_man->getFieldIdCommonFromTranslation('Filiale');
                 $id_common_filed_2 = $field_man->getFieldIdCommonFromTranslation('Codice Concessionario');
                 $query = "SELECT `translation`" . " FROM core_field_son" . " WHERE id_common_son = " . (int) $_POST['field_dropdown'][$id_common_filed_1] . " AND lang_code = '" . getLanguage() . "'";
                 list($filed_1_translation) = sql_fetch_row(sql_query($query));
                 $code_part = substr($filed_1_translation, 1, 1);
                 $reg_code = strtoupper($code_part . '_' . $_POST['field_textfield'][$id_common_filed_2]);
                 // resolving the tree_man
                 $array_folder = $uma->getFoldersFromCode($reg_code);
                 if (empty($array_folder) && $code_is_mandatory) {
                     //invalid code
                     $res['success'] = false;
                     $res['msg'] = $lang->def('_INVALID_CODE');
                     return $res;
                 }
                 break;
         }
     } elseif ($code_is_mandatory) {
         //invalid code
         $res['success'] = false;
         $res['msg'] = $lang->def('_INVALID_CODE');
         return $res;
     }
     // now in array_folder we have the associated folder for the users
     if (!empty($array_folder)) {
         //let's find the oc and ocd
         $oc_folders = $uma->getOcFolders($array_folder);
         while (list($id, $ocs) = each($oc_folders)) {
             $acl_man->addToGroup($ocs[0], $iduser);
             $acl_man->addToGroup($ocs[1], $iduser);
         }
         $enrollrules = new EnrollrulesAlms();
         $enrollrules->newRules('_NEW_USER', array($iduser), Lang::get(), current($array_folder));
     }
     // and in array_course the courses
     if (!empty($array_course)) {
         foreach ($array_course as $id_course) {
             require_once _lms_ . '/lib/lib.subscribe.php';
             $subscriber = new CourseSubscribe_Management();
             $subscriber->subscribeUser($iduser, $id_course, '3');
         }
     }
     return $res;
 }
 function getSubstitution()
 {
     $subs = array();
     $lang =& DoceboLanguage::createInstance('course', 'lms');
     $lang =& DoceboLanguage::createInstance('certificate', 'lms');
     if ($this->id_meta != 0) {
         require_once $GLOBALS['where_lms'] . '/lib/lib.course.php';
         require_once $GLOBALS['where_lms'] . '/lib/lib.coursereport.php';
         $acl_man =& $GLOBALS['current_user']->getAclManager();
         $courses = array();
         $array_coursetype = array('elearning' => $lang->def('_COURSE_TYPE_ELEARNING', 'course', 'lms'), 'classroom' => $lang->def('_CLASSROOM', 'course', 'lms'), 'web_seminar' => $lang->def('Web seminar'));
         $course_time = 0;
         $blended_time = 0;
         $query = "SELECT DISTINCT idCourse" . " FROM " . $GLOBALS['prefix_lms'] . "_certificate_meta_course" . " WHERE idMetaCertificate = '" . $this->id_meta . "'" . " AND idUser = '******'";
         $result = sql_query($query);
         $table_course = '<table width="100%" cellspacing="1" cellpadding="1" border="1" align="" summary="Corsi frequentati">' . '<thead>' . '<tr>' . '<td>' . $lang->def('_COURSE_NAME') . '</td>' . '<td>' . $lang->def('_COURSE_TYPE') . '</td>' . '<td align="right">' . $lang->def('_COURSE_TIME') . '</td>' . '</tr>' . '</thead>' . '</tbody>';
         $table_blended = '<table width="100%" cellspacing="1" cellpadding="1" border="1" align="" summary="Corsi frequentati">' . '<thead>' . '<tr>' . '<td>' . $lang->def('_COURSE_NAME') . '</td>' . '<td>' . $lang->def('_COURSE_PROF') . '</td>' . '<td>' . $lang->def('_COURSE_TYPE') . '</td>' . '<td align="right">' . $lang->def('_COURSE_TIME') . '</td>' . '</thead>' . '</tbody>';
         $course_count = 0;
         $blended_count = 0;
         $array_meta_complete = array();
         $array_meta_inscr = array();
         $array_meta_access = array();
         while (list($id_course) = sql_fetch_row($result)) {
             $query = "SELECT date_complete, date_inscr, date_first_access" . " FROM " . $GLOBALS['prefix_lms'] . "_courseuser" . " WHERE idCourse = '" . $id_course . "'" . " AND idUser = '******'";
             list($date_complete_meta, $date_inscr_meta, $date_access_meta) = sql_fetch_row(sql_query($query));
             $array_meta_complete[] = $date_complete_meta;
             $array_meta_inscr[] = $date_inscr_meta;
             $array_meta_access[] = $date_access_meta;
             $man_course = new Man_Course();
             $course_info = $man_course->getCourseInfo($id_course);
             $rep_man = new CourseReportManager();
             $score_course = $rep_man->getUserFinalScore(array($this->id_user), array($this->id_course));
             if ($course_info['course_type'] === 'blended') {
                 $teacher_array = getSubscribed($id_course, false, 6, true);
                 $first = true;
                 if (is_array($teacher_array) && !empty($teacher_array)) {
                     while (list(, $id_teach) = each($teacher_array)) {
                         $teacher_info = $acl_man->getUser($id_teach);
                         if ($first) {
                             $teacher = $teacher_info[ACL_INFO_FIRSTNAME] . ' ' . $teacher_info[ACL_INFO_LASTNAME];
                             $first = false;
                         } else {
                             $teacher = '<br/>' . $teacher_info[ACL_INFO_FIRSTNAME] . ' ' . $teacher_info[ACL_INFO_LASTNAME];
                         }
                     }
                 } else {
                     $teacher = '&nbsp;';
                 }
                 $table_blended .= '<tr>' . '<td>' . $course_info['name'] . '</td>' . '<td>' . $teacher . '</td>' . '<td>' . $array_coursetype[$course_info['course_type']] . '</td>' . '<td align="right">' . $course_info['mediumTime'] . '</td>' . '</tr>';
                 $blended_time += $course_info['mediumTime'];
                 $blended_count++;
             } else {
                 $table_course .= '<tr>' . '<td>' . $course_info['name'] . '</td>' . '<td>' . $array_coursetype[$course_info['course_type']] . '</td>' . '<td align="right">' . $course_info['mediumTime'] . '</td>' . '</tr>';
                 $course_time += $course_info['mediumTime'];
                 $course_count++;
             }
         }
         $table_course .= '<tr>' . '<td align="right" colspan="2">' . $lang->def('_TOTAL_HOURS') . '</td>' . '<td align="right">' . $course_time . '</td>' . '</tr>' . '</tbody>' . '</table>';
         $table_blended .= '<tr>' . '<td align="right" colspan="2">' . $lang->def('_TOTAL_HOURS') . '</td>' . '<td align="right">' . $blended_time . '</td>' . '</tr>' . '</tbody>' . '</table>';
         rsort($array_meta_complete);
         sort($array_meta_inscr);
         sort($array_meta_access);
         $subs['[meta_complete]'] = $array_meta_complete[0];
         $subs['[meta_inscr]'] = $array_meta_inscr[0];
         $subs['[meta_access]'] = $array_meta_access[0];
         $subs['[table_course]'] = $course_count ? $table_course : '';
         $subs['[table_blended]'] = $blended_count ? $table_blended : '';
     } else {
         require_once $GLOBALS['where_lms'] . '/lib/lib.course.php';
         $courseuser = new Man_CourseUser();
         $course_stat =& $courseuser->getUserCourses($this->id_user, false, false, false, array($this->id_course));
         if (isset($course_stat[$this->id_course])) {
             $subs['[date_enroll]'] = Format::date($course_stat[$this->id_course]['date_inscr'], 'date');
             $subs['[date_first_access]'] = Format::date($course_stat[$this->id_course]['date_first_access'], 'date');
             $subs['[date_complete]'] = Format::date($course_stat[$this->id_course]['date_complete'], 'date');
             $subs['[date_complete_year]'] = substr($course_stat[$this->id_course]['date_complete'], 0, 4);
         } else {
             $subs['[date_enroll]'] = '';
             $subs['[date_first_access]'] = '';
             $subs['[date_complete]'] = '';
             $subs['[date_complete_year]'] = '';
         }
         require_once $GLOBALS['where_lms'] . '/lib/lib.orgchart.php';
         $org_man = new OrganizationManagement($this->id_course);
         $score_start = $org_man->getStartObjectScore(array($this->id_user), array($this->id_course));
         $score_final = $org_man->getFinalObjectScore(array($this->id_user), array($this->id_course));
         require_once $GLOBALS['where_lms'] . '/lib/lib.coursereport.php';
         $rep_man = new CourseReportManager();
         $score_course = $rep_man->getUserFinalScore(array($this->id_user), array($this->id_course));
         $subs['[test_score_start]'] = isset($score_start[$this->id_course][$this->id_user]) ? $score_start[$this->id_course][$this->id_user]['score'] : '';
         $subs['[test_score_start_max]'] = isset($score_start[$this->id_course][$this->id_user]) ? $score_start[$this->id_course][$this->id_user]['max_score'] : '';
         $subs['[test_score_final]'] = isset($score_final[$this->id_course][$this->id_user]) ? $score_final[$this->id_course][$this->id_user]['score'] : '';
         $subs['[test_score_final_max]'] = !empty($score_final[$this->id_course][$this->id_user]['max_score']) ? $score_final[$this->id_course][$this->id_user]['max_score'] : '100';
         $subs['[course_score_final]'] = isset($score_course[$this->id_user][$this->id_course]) ? $score_course[$this->id_user][$this->id_course]['score'] : '';
         $subs['[course_score_final_max]'] = isset($score_course[$this->id_user][$this->id_course]) ? $score_course[$this->id_user][$this->id_course]['max_score'] : '';
         require_once $GLOBALS['where_lms'] . '/lib/lib.track_user.php';
         $time_in = TrackUser::getUserTotalCourseTime($this->id_user, $this->id_course);
         $hours = (int) ($time_in / 3600);
         $minutes = (int) ($time_in % 3600 / 60);
         $seconds = (int) ($time_in % 60);
         if ($minutes < 10) {
             $minutes = '0' . $minutes;
         }
         if ($seconds < 10) {
             $seconds = '0' . $seconds;
         }
         $subs['[total_time]'] = $hours . 'h ' . $minutes . 'm ' . $seconds . 's';
         $subs['[total_time_hour]'] = $hours;
         $subs['[total_time_minute]'] = $minutes;
         $subs['[total_time_second]'] = $seconds;
     }
     return $subs;
 }
     $value = array("next_op" => '', "id" => 'course_comment', "title" => $lang->def('_COMMENTS'), "content" => $content);
     require_once _base_ . '/lib/lib.json.php';
     $json = new Services_JSON();
     $output = $json->encode($value);
     aout($output);
     break;
 case "comment_it":
     require_once $GLOBALS["where_framework"] . "/lib/lib.ajax_comment.php";
     require_once $GLOBALS["where_lms"] . "/lib/lib.course.php";
     $lang =& DoceboLanguage::createInstance('standard', 'framework');
     $lang->setGlobal();
     $lang =& DoceboLanguage::createInstance('catalogue', 'lms');
     $id_course = importVar('id_course', true, 0);
     $ax_comm = new AjaxComment('course', 'lms');
     $ax_rend = new AjaxCommentRender('catalogue', 'lms');
     $man_courseuser = new Man_CourseUser();
     $usercourses =& $man_courseuser->getUserSubscriptionsInfo(getLogUserId(), true);
     if (Docebo::user()->isAnonymous()) {
         $ax_comm->canReply(false);
     } else {
         $ax_comm->canReply(isset($usercourses[$id_course]));
     }
     $content = '<div style="overflow:scroll;height:500px">';
     $comments = $ax_comm->getCommentByResourceKey($id_course);
     $ax_rend->setCommentToDisplay($comments);
     while (!$ax_rend->isEnd()) {
         $content .= $ax_rend->nextComment();
     }
     //$content.= $ax_rend->getAddCommentMask($id_course);
     if ($ax_comm->isReplyActive()) {
         $content .= $ax_rend->getAddCommentMask_2($id_course);
function displayCoursePathList(&$url, $selected_tab)
{
    require_once _base_ . '/lib/lib.form.php';
    require_once _base_ . '/lib/lib.user_profile.php';
    require_once _base_ . '/lib/lib.navbar.php';
    require_once $GLOBALS['where_lms'] . '/lib/lib.preassessment.php';
    require_once $GLOBALS['where_lms'] . '/lib/lib.catalogue.php';
    require_once $GLOBALS['where_lms'] . '/lib/lib.coursepath.php';
    require_once $GLOBALS['where_lms'] . '/lib/lib.course.php';
    require_once $GLOBALS['where_lms'] . '/lib/lib.preassessment.php';
    require_once $GLOBALS['where_lms'] . '/lib/lib.coursereport.php';
    $lang =& DoceboLanguage::createInstance('catalogue');
    $lang_c =& DoceboLanguage::createInstance('course');
    $nav_bar = new NavBar('ini', Get::sett('visuItem'), 0);
    $nav_bar->setLink($url->getUrl());
    $ini = $nav_bar->getSelectedElement();
    $course_man = new Man_Course();
    $path_man = new CoursePath_Manager();
    $cat_man = new Catalogue_Manager();
    $man_courseuser = new Man_CourseUser();
    $profile = new UserProfile(getLogUserId());
    $profile->init('profile', 'framework', '', 'ap');
    $profile->addStyleSheet('lms');
    $catalogues =& $cat_man->getUserAllCatalogueId(getLogUserId());
    if (!empty($catalogues)) {
        // at least one catalogue is assigned to this user
        $cat_path =& $cat_man->getAllCoursepathOfUser(getLogUserId());
        if (!empty($cat_path)) {
            $path_man->filterInPath($cat_path);
        }
    } elseif (Get::sett('on_catalogue_empty') == 'off') {
        $path_man->filterInPath(array(0));
    }
    if (!Docebo::user()->isAnonymous()) {
        if (!isset($_SESSION['cp_assessment_effect'])) {
            $pa_man = new AssessmentList();
            $arr_assessment = $pa_man->getUserAssessmentSubsription(Docebo::user()->getArrSt());
            $report = new CourseReportManager();
            $user_result = $report->getAllUserFinalScore(getLogUserId(), $arr_assessment['course_list']);
            $rule_man = new AssessmentRule();
            $ass_elem = $rule_man->getCompleteEffectListForAssessmentWithUserResult($arr_assessment['course_list'], $user_result);
            $_SESSION['cp_assessment_effect'] = urlencode(serialize($ass_elem));
        } else {
            $ass_elem = unserialize(urldecode($_SESSION['cp_assessment_effect']));
        }
        if (!empty($ass_elem['parsed']['coursepath'])) {
            $path_man->filterOrInPath($ass_elem['parsed']['coursepath']);
        }
    }
    // retrive all the classroorm
    // search for the coursepath ------------------------------------------------------
    $coursepath = $path_man->getCoursepathList($ini, Get::sett('visuItem'));
    if (empty($coursepath)) {
        // no path found for the criteria ---------------------------------------------
        $GLOBALS['page']->add('<p class="no_course_found">' . $lang->def('_NO_COURSE_FOUND') . '</p></div>', 'content');
        return;
    }
    // find structures of the course path ---------------------------------------------
    $courses = $path_man->getPathStructure(array_keys($coursepath));
    $path_slot = $path_man->getPathSlot(array_keys($coursepath));
    // fin user subscription needed ---------------------------------------------------
    $user_paths =& $path_man->getUserSubscriptionsInfo(getLogUserId(), false);
    $usercourses =& $man_courseuser->getUserSubscriptionsInfo(getLogUserId(), false);
    // find course basilar information ------------------------------------------------
    $course_info = $course_man->getAllCourses(false, false, $courses['all_items'], true);
    $GLOBALS['page']->add($nav_bar->getNavBar($ini), 'content');
    while (list($id_path, $path) = each($coursepath)) {
        $html = '<div class="coursepath_container">';
        $in_h = ' <span class="coursepath_subscribe">';
        $can_subs = true;
        if (isset($ass_elem['parsed']['coursepath'])) {
            if (isset($ass_elem['not_done']['coursepath']) && in_array($id_path, $ass_elem['not_done']['coursepath'])) {
                // the assosiacted preassessment is not done
                $in_h .= '';
                //$lang->def('_MUST_DO_PREASSESSMENT');
                $can_subs = false;
            } elseif (isset($ass_elem['to_apply']['coursepath']) && in_array($id_path, $ass_elem['to_apply']['coursepath'])) {
                // the assosiacted preassessment suggest this coursepath
                $in_h .= $lang->def('_PREASSESSMENT_SUGGESTION');
            }
        } else {
            switch ($path[COURSEPATH_METHOD]) {
                case METHOD_WAIT:
                    $in_h .= $lang->def('_METHOD_WAIT');
                    break;
                case METHOD_AUTO:
                    $in_h .= $lang->def('_METHOD_AUTO');
                    break;
                case METHOD_MANUAL:
                default:
                    $in_h .= $lang->def('_METHOD_MANUAL');
                    $can_subs = false;
                    break;
            }
        }
        $in_h .= '</span>';
        $in_h .= ' <span class="coursepath_status">';
        if (isset($usercourses[$id_path])) {
            // user is alredy subscribed to this coursepath
            if ($usercourses[$id_path]['waiting']) {
                $in_h .= $lang->def('_COURSEPATH_WAITING');
            } else {
                $in_h .= $lang->def('_USER_STATUS_SUBS');
            }
        }
        $in_h .= '</span>';
        // -------------------------------------------------------------
        $html .= '<div class="coursepath_info_container">';
        $html .= '<h2 class="pathtitle">' . $in_h . ($path[COURSEPATH_CODE] != '' ? '[' . $path[COURSEPATH_CODE] . '] ' : '') . $path[COURSEPATH_NAME] . '</h2>' . '<p class="course_support_info">' . str_replace('[enrolled]', $path[CP_ENROLLED], $lang->def('_COURSEPATH_INTRO')) . '</p>';
        if (!isset($courses[$id_path]) || empty($courses[$id_path])) {
            $html .= $lang->def('_NO_COURSE_ASSIGNED_TO_COURSEPATH') . '<br />';
        } else {
            // display the slots
            foreach ($path_slot[$id_path] as $id_slot => $slot_info) {
                if ($id_slot == 0) {
                    $html .= '<h4>' . $lang->def('_MANDATORY') . '</h4>';
                    if (!empty($courses[$id_path][$id_slot])) {
                        $html .= '<ul class="coursepath_mainslot">';
                    }
                } else {
                    if ($slot_info['min_selection'] > 0 && $slot_info['max_selection'] > 0) {
                        $title = str_replace(array('[min_selection]', '[max_selection]'), array($slot_info['min_selection'], $slot_info['max_selection']), $lang->def('_COURSE_PATH_SLOT_MIN_MAX'));
                    } elseif ($slot_info['max_selection'] > 0) {
                        $title = str_replace('[max_selection]', $slot_info['max_selection'], $lang->def('_COURSE_PATH_SLOT_MAX'));
                    } else {
                        $title = $lang->def('_COURSE_PATH_SLOT');
                    }
                    $html .= '<h4>' . $title . '</h4>';
                    if (!empty($courses[$id_path][$id_slot])) {
                        $html .= '<ul class="coursepath_otherslot">';
                    }
                }
                $i = 0;
                while (list($id) = each($courses[$id_path][$id_slot])) {
                    $html .= '<li class="path_course ' . ($i % 2 ? 'path_odd' : '') . '">' . '<a class="show_details_more" href="javascript:;" onclick="course_dash(this, \'' . $id . '\',\'info_' . $id_path . '_' . $id . '\', \'' . $can_subs . '\');">' . $lang->def('_DETAILS') . '</a>' . ($course_info[$id]['code'] != '' ? ' [' . $course_info[$id]['code'] . '] ' : '') . $course_info[$id]['name'] . '<div id="info_' . $id_path . '_' . $id . '"></div>' . '</li>';
                    $i++;
                }
                if (!empty($courses[$id_path][$id_slot])) {
                    $html .= '</ul>';
                }
            }
        }
        $html .= '</div>';
        $html .= '</div>';
        $GLOBALS['page']->add($html, 'content');
    }
    $GLOBALS['page']->add($nav_bar->getNavBar($ini), 'content');
}
function subscribe()
{
    checkPerm('view');
    require_once _base_ . '/lib/lib.form.php';
    $form = new Form();
    if (isset($_POST['course_autoregistration_code'])) {
        require_once _lms_ . '/lib/lib.course.php';
        $out =& $GLOBALS['page'];
        $out->setWorkingZone('content');
        $code = $_POST['course_autoregistration_code'];
        $code = strtoupper($code);
        $code = str_replace('-', '', $code);
        $registration_code_type = Get::sett('registration_code_type', '0');
        if ($registration_code_type == 'tree_course') {
            $code = substr($code, 10, 10);
        }
        $course_registration_result = false;
        $man_course_user = new Man_CourseUser();
        $course_registration_result = $man_course_user->subscribeUserWithCode($code, getLogUserId());
        $out->add(getTitleArea(Lang::t('_AUTOREGISTRATION', 'course_autoregistration')) . '<div class="std_block">');
        if ($course_registration_result > 0) {
            $out->add(str_replace('[course_added]', $course_registration_result, Lang::t('_OPERATION_SUCCESSFUL', 'course_autoregistration')));
            $out->add('<br/><a href="index.php?r=' . _after_login_ . '">' . Lang::t('_BACK_TO_COURSE', 'course_autoregistration') . '</a>');
        } else {
            if ($course_registration_result == -1) {
                $out->add(getErrorUi(Lang::t('_CODE_ALREDY_USED', 'course_autoregistration')));
                $out->add($form->openForm('course_autoregistration', 'index.php?modname=course_autoregistration&amp;op=course_autoregistration') . $form->openElementSpace() . $form->getTextfield(Lang::t('_COURSE_AUTOREGISTRATION_CODE', 'course_autoregistration'), 'course_autoregistration_code', 'course_autoregistration_code', '255', '') . $form->closeElementSpace() . $form->openButtonSpace() . $form->getButton('subscribe', 'subscribe', Lang::t('_SEND', 'course_autoregistration')) . $form->closeButtonSpace());
            } else {
                if ($course_registration_result == -2) {
                    $out->add(getErrorUi(Lang::t('_SUBSCRIPTION_NOT_ALLOWED_YET', 'course_autoregistration')));
                    $out->add($form->openForm('course_autoregistration', 'index.php?modname=course_autoregistration&amp;op=course_autoregistration') . $form->openElementSpace() . $form->getTextfield(Lang::t('_COURSE_AUTOREGISTRATION_CODE', 'course_autoregistration'), 'course_autoregistration_code', 'course_autoregistration_code', '255', '') . $form->closeElementSpace() . $form->openButtonSpace() . $form->getButton('subscribe', 'subscribe', Lang::t('_SEND', 'course_autoregistration')) . $form->closeButtonSpace());
                } else {
                    require_once _adm_ . '/lib/lib.code.php';
                    $code = $_POST['course_autoregistration_code'];
                    $code_manager = new CodeManager();
                    $valid_code = $code_manager->controlCodeValidity($code);
                    if ($valid_code == 1) {
                        $array_course = $code_manager->getAvailableCourseAssociateWithCode($code);
                        require_once _lms_ . '/lib/lib.course.php';
                        $man_course = new Man_Course();
                        $array_course_name = array();
                        $counter = 0;
                        require_once _lms_ . '/lib/lib.subscribe.php';
                        $subscribe = new CourseSubscribe_Management();
                        foreach ($array_course as $id_course) {
                            $query_control = "SELECT COUNT(*)" . " FROM %lms_courseuser" . " WHERE idCourse = " . $id_course . " AND idUser = "******"index.php?r=' . _after_login_ . '">' . Lang::t('_BACK_TO_COURSE', 'course_autoregistration') . '</a>');
                        } else {
                            if (sizeof($array_course) == 0) {
                                $out->add(getErrorUi(Lang::t('_SUBSCRIPTION_NOT_ALLOWED_YET', 'course_autoregistration')));
                            } else {
                                $out->add(getErrorUi(Lang::t('_ALREADY_SUBSCRIBED', 'course_autoregistration')));
                            }
                            $out->add($form->openForm('course_autoregistration', 'index.php?modname=course_autoregistration&amp;op=course_autoregistration') . $form->openElementSpace() . $form->getTextfield(Lang::t('_COURSE_AUTOREGISTRATION_CODE', 'course_autoregistration'), 'course_autoregistration_code', 'course_autoregistration_code', '255', '') . $form->closeElementSpace() . $form->openButtonSpace() . $form->getButton('subscribe', 'subscribe', Lang::t('_SEND', 'course_autoregistration')) . $form->closeButtonSpace());
                        }
                    } else {
                        if ($valid_code == 0) {
                            $out->add(getErrorUi(Lang::t('_CODE_ALREDY_USED', 'course_autoregistration')));
                        } else {
                            $out->add(getErrorUi(Lang::t('_CODE_NOT_VALID', 'course_autoregistration')));
                        }
                        $out->add($form->openForm('course_autoregistration', 'index.php?modname=course_autoregistration&amp;op=course_autoregistration') . $form->openElementSpace() . $form->getTextfield(Lang::t('_COURSE_AUTOREGISTRATION_CODE', 'course_autoregistration'), 'course_autoregistration_code', 'course_autoregistration_code', '255', '') . $form->closeElementSpace() . $form->openButtonSpace() . $form->getButton('subscribe', 'subscribe', Lang::t('_SEND', 'course_autoregistration')) . $form->closeButtonSpace());
                    }
                }
            }
        }
        $out->add('</div>');
    }
}