function subscribeupdate() { checkPerm('subscribe', false, 'course'); require_once $GLOBALS['where_lms'] . '/lib/lib.course.php'; require_once $GLOBALS['where_lms'] . '/lib/lib.stats.php'; $id_course = importVar('id_course', true, 0); $edition_id = getCourseEditionId(); $course_info = Man_Course::getCourseInfo($id_course); $lang =& DoceboLanguage::CreateInstance('subscribe', 'lms'); $out =& $GLOBALS['page']; $acl_man =& Docebo::user()->getAclManager(); if (!isset($_POST['user_level_sel'])) { //the user selection is empty, return to course selection backcourse('err_selempty'); } //retrive id of group of the course for the various level --------------------------- $level_idst =& getCourseLevel($id_course); $actual_user_level = getSubscribedLevel($id_course, false, false, $edition_id); if (count($level_idst) == 0) { //if the group doesn't exists create it $level_idst =& DoceboCourse::createCourseLevel($id_course); } // Subscirbing user ----------------------------------------------------------------- $re = true; $user_subs = array(); while (list($id_user, $lv_sel) = each($_POST['user_level_sel'])) { $lv_old = $actual_user_level[$id_user]; if ($lv_sel != $lv_old) { // Add in group for permission $acl_man->removeFromGroup($level_idst[$lv_old], $id_user); $acl_man->addToGroup($level_idst[$lv_sel], $id_user); } $new_status = $_POST['user_status_sel'][$id_user]; $upd_query = "\r\n\t\tUPDATE " . $GLOBALS['prefix_lms'] . "_courseuser\r\n\t\tSET level = '" . $lv_sel . "',\r\n\t\t\tstatus = '" . $new_status . "',\r\n\t\t\tabsent = '" . (isset($_POST['user_absent'][$id_user]) ? $_POST['user_absent'][$id_user] : '0') . "'\r\n\t\t" . ($new_status == _CUS_RESERVED || $new_status == _CUS_WAITING_LIST || $new_status == _CUS_CONFIRMED ? ", waiting = '1'" : "") . "\r\n\t\t\r\n\t\t" . ($_POST['user_status_sel'][$id_user] == _CUS_CANCELLED ? ", cancelled_by = '" . getLogUserId() . "'" : ", cancelled_by = '0'") . "\r\n\t\t\r\n\t\tWHERE idUser = '******' \r\n\t\t\t AND idCourse = '" . $id_course . "'\r\n\t\t\t AND edition_id='" . $edition_id . "'"; if ($new_status == _CUS_END) { saveTrackStatusChange((int) $id_user, (int) $id_course, _CUS_END); } //update user's competence score require_once $GLOBALS['where_lms'] . '/lib/lib.competences.php'; $cman = new Competences_Manager(); switch ($new_status) { case _CUS_END: $cman->AssignCourseCompetencesToUser($id_course, $id_user); break; //... } // Add in table $re_sing = sql_query($upd_query); if ($re_sing) { $user_subs[] = $id_user; addUserToTimeTable($id_user, $id_course, $edition_id); } $re &= $re_sing; /*".( $_POST['user_status_sel'][$id_user] == _CUS_CANCELLED ? ", cancelled_by = '".getLogUserId()."'" : ", cancelled_by = '0'" )."*/ } Docebo::user()->loadUserSectionST('/lms/course/private/'); Docebo::user()->SaveInSession(); require_once _base_ . '/lib/lib.eventmanager.php'; $array_subst = array('[url]' => Get::sett('url'), '[course]' => $course_info['name']); if (!empty($user_subs)) { // message to user that is waiting $msg_composer = new EventMessageComposer(); $msg_composer->setSubjectLangText('email', '_MOD_USER_SUBSCRIPTION_SUBJECT', false); $msg_composer->setBodyLangText('email', '_MOD_USER_SUBSCRIPTION_TEXT', $array_subst); $msg_composer->setBodyLangText('sms', '_MOD_USER_SUBSCRIPTION_TEXT_SMS', $array_subst); // send message to the user subscribed createNewAlert('UserCourseLevelChanged', 'subscribe', 'modify', '1', 'User subscribed', $user_subs, $msg_composer); } backcourse($re ? 'ok_subs' : 'err_subs'); }
function required() { require_once _base_ . '/lib/lib.form.php'; require_once _base_ . '/lib/lib.table.php'; require_once _adm_ . '/lib/lib.publicadminmanager.php'; require_once _lms_ . '/lib/lib.course.php'; require_once _lms_ . '/lib/lib.date.php'; require_once _lms_ . '/lib/lib.competences.php'; $db = DbConn::getInstance(); $lang =& DoceboLanguage::CreateInstance('public_coursepanel', 'lms'); $sel_competence = Get::req('sel_competence_req', DOTY_INT, false); $sel_course = Get::req('sel_course_req', DOTY_INT, false); $back_url = "index.php?modname=public_coursepanel&op=coursepanel&sel_competence=" . (int) $sel_competence . "&sel_course=" . (int) $sel_course; $back_ui = getBackUi($back_url, $lang->def('_BACK')); $sel_comp = Get::req('required_selector', DOTY_INT, 0); if ($sel_comp) { $id_pa = getLogUserId(); if (!$id_pa) { //... } $acl_man = new DoceboACLManager(); $admin_manager = new PublicAdminManager(); $array_users = array(); $idst_associated = $admin_manager->getAdminTree($id_pa); $array_users =& $acl_man->getAllUsersFromIdst($idst_associated); $array_users = array_unique($array_users); if (empty($array_users)) { //error: no users to deal with cout($back_ui . $lang->def('_NO_USERS') . $back_ui, 'content'); return; } cout(getTitleArea($lang->def('_REQUIRED_USERS'), 'coursepanel') . '<div class="std_block">', 'content'); $table = new Table(); $head_labels = array($lang->def('_USERNAME'), $lang->def('_NAME')); $head_style = array('', '', 'align_center', 'align_center'); $table->addHead($head_labels, $head_style); //$date = date ("Y-m-d H:i:s", strtotime("+1 months")); //$now = date("Y-m-d H:i:s"); $man_comp = new Competences_Manager(); $comp_data = $man_comp->GetCompetence($sel_comp); $already = array(); $query = "SELECT id_user, score_init, score_got FROM %lms_competence_user WHERE id_competence='" . (int) $sel_comp . "'"; $res = $db->query($query); while (list($id_user, $score_init, $score_got) = $db->fetch_row($res)) { if ($comp_data['type'] == 'score') { //if the competence assignment exists in DB, but the total score is 0, then it's considered as non-assigned if ((int) $score_init + (int) $score_got > 0) { $already[] = $id_user; } } else { $already[] = $id_user; } } $already = array_unique($already); $array_users = array_diff($array_users, $already); //get required competences not got from users $query = ""; if ($comp_data['type'] == 'score') { $query = "SELECT u.idst, u.userid, u.lastname, u.firstname FROM %lms_competence_required as cr " . " JOIN %adm_user as u ON (cr.idst = u.idst)" . " WHERE cr.idst IN (" . implode(",", $array_users) . ") AND cr.id_competence=" . (int) $sel_comp . " ORDER BY u.userid"; } else { $query = "SELECT u.idst, u.userid, u.lastname, u.firstname FROM %lms_competence_required as cr " . " JOIN %adm_user as u ON (cr.idst = u.idst) " . " WHERE cr.idst IN (" . implode(",", $array_users) . ") AND cr.id_competence=" . (int) $sel_comp . " ORDER BY u.userid"; } $res = $db->query($query); if (sql_num_rows($res) > 0) { while (list($idst, $userid, $lastname, $firstname) = $db->fetch_row($res)) { $line = array(); $line[] = $acl_man->relativeId($userid); $line[] = $lastname . " " . $firstname; $table->addBody($line); } //cout(getTitleArea($lang->def('_EXPIRING_USERS'), 'coursepanel').'<div class="std_block">', 'content'); cout($lang->def('_COMPETENCE') . ': <b>' . $comp_data['name'] . '</b>', 'content'); cout($back_ui . $table->getTable() . $back_ui, 'content'); } else { cout($back_ui . $lang->def('_NO_REQUIRED_USER') . $back_ui, 'content'); } } else { //error, no competence selected cout($back_ui . $lang->def('_NO_COMPETENCE_SELECTED') . $back_ui, 'content'); return; } }