function subscribeToCourse($id_user, $id_course, $id_date = 0) { require_once _lms_ . '/admin/modules/subscribe/subscribe.php'; require_once _lms_ . '/lib/lib.date.php'; require_once _lms_ . '/lib/lib.course.php'; $date_man = new DateManager(); $acl_man =& Docebo::user()->getAclManager(); $query = "SELECT idCourse" . " FROM " . $GLOBALS['prefix_lms'] . "_courseuser" . " WHERE idUser = "******"SELECT subscribe_method FROM " . $GLOBALS['prefix_lms'] . "_course WHERE idCourse = " . $id_course)); $waiting = 0; if ($subscribe_method == '1') { $waiting = 1; } if ($id_date != 0) { if (array_search($id_course, $courses) !== false) { if (array_search($id_date, $dates) === false) { if (!$date_man->addUserToDate($id_date, $id_user, getLogUserId())) { return false; } } } else { $acl_man->addToGroup($level_idst[3], $id_user); $re = sql_query("INSERT INTO " . $GLOBALS['prefix_lms'] . "_courseuser\r\n\t\t\t\t\t\t\t\t\t(idUser, idCourse, edition_id, level, waiting, subscribed_by, date_inscr)\r\n\t\t\t\t\t\t\t\t\tVALUES ('" . $id_user . "', '" . $id_course . "', '0', '3', '" . $waiting . "', '" . getLogUserId() . "', '" . date("Y-m-d H:i:s") . "')"); if ($re) { addUserToTimeTable($id_user, $id_course, 0); if (!$date_man->addUserToDate($id_date, $id_user, getLogUserId())) { return false; } } } } else { if (array_search($id_course, $courses) === false) { $acl_man->addToGroup($level_idst[3], $id_user); $re = sql_query("INSERT INTO " . $GLOBALS['prefix_lms'] . "_courseuser\r\n\t\t\t\t\t\t\t\t\t(idUser, idCourse, edition_id, level, waiting, subscribed_by, date_inscr)\r\n\t\t\t\t\t\t\t\t\tVALUES ('" . $id_user . "', '" . $id_course . "', '0', '3', '" . $waiting . "', '" . getLogUserId() . "', '" . date("Y-m-d H:i:s") . "')"); if ($re) { addUserToTimeTable($id_user, $id_course, 0); } else { return false; } } } return true; }
public function activateCourses($id_transaction, $id_user, $activations) { require_once _lms_ . '/lib/lib.subscribe.php'; require_once _lms_ . '/admin/modules/subscribe/subscribe.php'; require_once _lms_ . '/lib/lib.date.php'; require_once _lms_ . '/lib/lib.course.php'; $subscribe_man = new CourseSubscribe_Management(); $date_man = new DateManager(); $acl_man =& Docebo::user()->getAclManager(); $query = "SELECT idCourse" . " FROM " . $this->table_courseuser . " WHERE idUser = "******"UPDATE " . $this->table_transaction_info . " SET activated = 1" . " WHERE id_transaction = " . $id_transaction . " AND id_course = " . $id_course . " AND id_date = " . $id_date; if (!sql_query($query_up)) { return false; } } } else { $query_up = "UPDATE " . $this->table_transaction_info . " SET activated = 1" . " WHERE id_transaction = " . $id_transaction . " AND id_course = " . $id_course . " AND id_date = " . $id_date; if (!sql_query($query_up)) { return false; } } } else { $acl_man->addToGroup($level_idst[3], $id_user); $re = mysql_query("INSERT INTO " . $GLOBALS['prefix_lms'] . "_courseuser\n\t\t\t\t\t\t\t\t\t\t\t(idUser, idCourse, edition_id, level, waiting, subscribed_by, date_inscr)\n\t\t\t\t\t\t\t\t\t\t\tVALUES ('" . $id_user . "', '" . $id_course . "', '0', '3', '0', '" . getLogUserId() . "', '" . date("Y-m-d H:i:s") . "')"); if ($re) { $courses[$id_course] = $id_course; addUserToTimeTable($id_user, $id_course, 0); if (!$date_man->addUserToDate($id_date, $id_user, getLogUserId())) { return false; } else { $query_up = "UPDATE " . $this->table_transaction_info . " SET activated = 1" . " WHERE id_transaction = " . $id_transaction . " AND id_course = " . $id_course . " AND id_date = " . $id_date; if (!sql_query($query_up)) { return false; } } } else { return false; } } } } else { if (array_search($id_course, $courses) !== false) { $query_up = "UPDATE " . $this->table_transaction_info . " SET activated = 1" . " WHERE id_transaction = " . $id_transaction . " AND id_course = " . $id_course . " AND id_date = 0"; if (!sql_query($query_up)) { return false; } } else { $acl_man->addToGroup($level_idst[3], $id_user); $re = mysql_query("INSERT INTO " . $GLOBALS['prefix_lms'] . "_courseuser\n\t\t\t\t\t\t\t\t\t\t(idUser, idCourse, edition_id, level, waiting, subscribed_by, date_inscr)\n\t\t\t\t\t\t\t\t\t\tVALUES ('" . $id_user . "', '" . $id_course . "', '0', '3', '0', '" . getLogUserId() . "', '" . date("Y-m-d H:i:s") . "')"); if ($re) { $courses[$id_course] = $id_course; addUserToTimeTable($id_user, $id_course, 0); $query_up = "UPDATE " . $this->table_transaction_info . " SET activated = 1" . " WHERE id_transaction = " . $id_transaction . " AND id_course = " . $id_course . " AND id_date = 0"; if (!sql_query($query_up)) { return false; } } else { return false; } } } } return true; }
function savePanel() { checkPerm('mod'); require_once _base_ . '/lib/lib.form.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'; $save = Get::req('save', DOTY_MIXED, false); $undo = Get::req('undo', DOTY_MIXED, false); $update = Get::req('update', DOTY_MIXED, false); $db = DbConn::getInstance(); $lang =& DoceboLanguage::CreateInstance('public_coursepanel', 'lms'); $man_competences = new Competences_Manager(); //back page link $back_ui = getBackUi('index.php?modname=public_coursepanel&op=coursepanel', $lang->def('_BACK')); cout(getTitleArea($lang->def('_COURSEPANEL'), 'coursepanel') . '<div class="std_block">' . $back_ui, 'content'); $sel_competence = Get::req('sel_competence', DOTY_INT, false); $sel_course = Get::req('sel_course', DOTY_INT, false); $required_filter = Get::req('required_filter', DOTY_INT, 0); $is_retraining = $man_competences->isRetrainingCourse($sel_course, $sel_competence); $back_url = "index.php?modname=public_coursepanel&op=coursepanel&sel_competence=" . (int) $sel_competence . "&sel_course=" . (int) $sel_course; if ($required_filter > 0) { $back_url .= '&required_filter=1'; } $to_consider = Get::req('to_consider', DOTY_MIXED, false); if ($to_consider) { require_once _base_ . '/lib/lib.json.php'; $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); $to_consider = $json->decode(base64_decode($to_consider)); } else { $to_consider = array('users' => array(), 'editions' => array()); } if ($undo) { Util::jump_to("index.php"); } elseif ($save) { //change users' subscription to course editions $data = Get::req('subscriptions', DOTY_MIXED, array()); $man_course = new Man_Course(); $course_info = $man_course->getCourseInfo($sel_course); if (!$sel_competence || !$sel_course) { //error ... Util::jump_to($back_url . "&err=invalid"); } //check the admin level of the current user, if it's not an admin or the idst is invalid, return an error $id_pa = getLogUserId(); if (!$id_pa) { Util::jump_to($back_url . "&err=invalid"); } $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)) { Util::jump_to($back_url . "&err=invalid"); } //filter array of user ids by competence $filtered_users = array(); $query_filter = "SELECT id_user FROM %lms_competence_user WHERE id_user IN (" . implode(",", $array_users) . ") AND id_competence='" . (int) $sel_competence . "'"; $res_filter = $db->query($query_filter); while (list($idst) = $db->fetch_row($res_filter)) { $filtered_users[] = $idst; } $subs_limit = array(); $subs_count = array(); if ($course_info['course_type'] == 'elearning') { $editions[] = $sel_course; $subscribed[$sel_course] = getSubscribed((int) $sel_course); $course_info = $man_course->getCourseInfo($sel_course); $subs_count[$sel_course] = count($data); } elseif ($course_info['course_type'] == 'classroom') { //get all combinations id_user - id_date $date_man = new DateManager(); $editions = array(); $query_editions = "SELECT id_date, id_course, code, name FROM %lms_course_date WHERE id_course='" . (int) $sel_course . "'"; $res_editions = $db->query($query_editions); while (list($id_edition, $id_course, $code, $name) = $db->fetch_row($res_editions)) { $editions[] = $id_edition; $subscribed[$id_edition] = $date_man->getDateSubscribed($id_edition); $date_info = $date_man->getDateInfo($id_edition); $subs_limit[$id_edition] = array('max' => $date_info['max_par'], 'subs' => $date_info['user_subscribed']); $subs_count[$id_edition] = 0; } } //------------------------------------------------------------------------------ //count the users to be subscribed/unsubscribed and check subscription limits, if any //subtract users to de-subscribe from courses foreach ($subscribed as $id_edition => $users_list) { foreach ($users_list as $id_user) { if ($course_info['course_type'] == 'elearning') { if (!isset($data[$id_user])) { $subs_count[$id_edition]--; } } elseif ($course_info['course_type'] == 'classroom') { //check if the current selection match the current subscriptions if (!isset($data[$id_user][$id_edition])) { $subs_count[$id_edition]--; } } } } foreach ($data as $user => $edition_list) { //id user foreach ($edition_list as $edition => $val) { //id date edition if (isset($subscribed[$edition][$user])) { //already subscribed, do nothing } else { $subs_count[$edition]++; } } } //check if we have enough room to subscribe users //{at the moment, rely on js ...} //------------------------------------------------------------------------------ //unsubscribe deselected users foreach ($subscribed as $id_edition => $users_list) { foreach ($users_list as $id_user) { if ($course_info['course_type'] == 'elearning') { if (!isset($data[$id_user])) { if (in_array($id_user, $to_consider['users']) && in_array($id_edition, $to_consider['editions'])) { $group_levels = DoceboCourse::getCourseLevel($sel_course); $user_levels = getSubscribedLevel($sel_course, false, false, 0); $_res = _removeCourseSubscription($sel_course, $id_user, $group_levels[$user_levels[$id_user]], 0); } } } elseif ($course_info['course_type'] == 'classroom') { //check if the current selection match the current subscriptions if (!isset($data[$id_user][$id_edition])) { if (in_array($id_user, $to_consider['users']) && in_array($id_edition, $to_consider['editions'])) { $date_man->removeUserFromDate($id_user, $id_edition, $sel_course); } } } } } //------------------------------------------------------------------------------ //check every single user for inscription $count = 0; $lv_sel = 3; //student level $waiting = 0; //don't subscribe as "waiting for approvation" //retrive id of group of the course for the varioud level $level_idst = DoceboCourse::getCourseLevel((int) $sel_course); //if the group doesn't exists create it if (count($level_idst) == 0 || $level_idst[1] == '') { $level_idst =& DoceboCourse::createCourseLevel((int) $sel_course); } foreach ($data as $user => $edition_list) { //id user foreach ($edition_list as $edition => $val) { //id date edition if (isset($subscribed[$edition][$user])) { //already subscribed, do nothing } else { //this user is to be subscribed, do it //add to level group of the course $acl_man->addToGroup($level_idst[$lv_sel], $user); // Add in table $re = $db->query("INSERT INTO %lms_courseuser (idUser, idCourse, edition_id, level, waiting, subscribed_by, date_inscr)" . " VALUES ( '" . (int) $user . "', '" . (int) $sel_course . "', '0', '" . $lv_sel . "', '" . $waiting . "', '" . getLogUserId() . "', '" . date("Y-m-d H:i:s") . "' )\t"); //additional operations for editions if ($course_info['course_type'] == 'elearning') { //... } elseif ($course_info['course_type'] == 'classroom') { $ret = $date_man->addUserToDate($edition, $user, getLogUserId()); if ($ret) { $count++; } } } } } Util::jump_to($back_url . "&err=ok&count=" . (int) $count); } elseif ($update) { $sel_competence = Get::req('sel_competence', DOTY_INT, false); $sel_course = Get::req('sel_course', DOTY_INT, false); Util::jump_to($back_url); //."&sel_competence=".(int)$sel_competence."&sel_course=".(int)$sel_course); } else { //... } cout($back_ui . '</div>', 'content'); }
function addsubscriptionedition() { require_once _lms_ . '/lib/lib.subscribe.php'; require_once _lms_ . '/lib/lib.coursepath.php'; $cpath_man = new CoursePath_Manager(); $subs_man = new CourseSubscribe_Management(); $id_path = Get::req('id_path', DOTY_INT, 0); $user_selected = unserialize(urldecode(Get::req('users', DOTY_MIXED, array()))); $courses = $cpath_man->getAllCourses(array($id_path)); if (isset($_POST['undo']) || !isset($_POST['save'])) { Util::jump_to('index.php?modname=coursepath&op=addsubscription&id_path=' . $id_path); } $re = true; $query_pathlist = "\r\n\tSELECT path_name, subscribe_method\r\n\tFROM " . $GLOBALS['prefix_lms'] . "_coursepath\r\n\tWHERE id_path = '" . $id_path . "'\r\n\tORDER BY path_name "; list($path_name, $subscribe_method) = sql_fetch_row(sql_query($query_pathlist)); if ($subscribe_method != 1 && !checkPerm('moderate', true)) { $waiting = 1; } else { $waiting = 0; } $users_subsc = array(); $course_man = new Man_Course(); $assessment = $course_man->getAllCourses(false, 'assessment', $courses); $classroom = $course_man->getAllCourses(false, 'classroom', $courses); $edition = $course_man->getAllCourses(false, 'edition', $courses); $array_id_date = array(); $array_id_edition = array(); if (!empty($classroom)) { foreach ($classroom as $id_course => $info) { if (Get::req('classroom_' . $id_course, DOTY_INT, 0) != 0) { $array_id_date[Get::req('classroom_' . $id_course, DOTY_INT, 0)] = Get::req('classroom_' . $id_course, DOTY_INT, 0); } } } if (!empty($edition)) { foreach ($edition as $id_course => $info) { if (Get::req('edition_' . $id_course, DOTY_INT, 0) != 0) { $array_id_edition[Get::req('edition_' . $id_course, DOTY_INT, 0)] = Get::req('edition_' . $id_course, DOTY_INT, 0); } } } require_once _lms_ . '/lib/lib.date.php'; $date_man = new DateManager(); require_once _lms_ . '/lib/lib.edition.php'; $edition_man = new EditionManager(); while (list(, $id_user) = each($user_selected)) { $text_query = "\r\n\t\tINSERT INTO " . $GLOBALS['prefix_lms'] . "_coursepath_user\r\n\t\t( id_path, idUser, waiting, subscribed_by ) VALUES\r\n\t\t( '" . $id_path . "', '" . $id_user . "', '" . $waiting . "', '" . getLogUserId() . "' )"; $re_s = sql_query($text_query); if ($re_s == true) { $users_subsc[] = $id_user; } $re &= $re_s; if (!empty($assessment)) { foreach ($assessment as $id_assessment => $assessment_info) { sql_query("INSERT INTO %lms_assessment_user (id_assessment, id_user, type_of) VALUES ('" . $id_assessment . "', '" . $id_user . "', 'user')"); } reset($assessment); } if (!empty($array_id_date)) { foreach ($array_id_date as $id_date) { $date_man->addUserToDate($id_date, $id_user, Docebo::user()->getIdSt()); } reset($array_id_date); } if (!empty($array_id_edition)) { foreach ($array_id_edition as $id_edition) { $edition_man->addUserToEdition($id_edition, $id_user, Docebo::user()->getIdSt()); } reset($array_id_edition); } } // now subscribe user to all the course if ($waiting == 0) { $re &= $subs_man->multipleSubscribe($users_subsc, $courses, 3); } Util::jump_to('index.php?modname=coursepath&op=pathlist&result=' . ($re ? 'ok' : 'err')); }