Пример #1
0
 public function delDate($id_date)
 {
     $res = false;
     $id_course = $this->getDateCourse($id_date);
     $subscribed = $this->getDateSubscribed($id_date);
     foreach ($subscribed as $id_user) {
         $control = $this->removeUserFromDate($id_user, $id_date, $id_course);
         if (!$control) {
             require_once _lms_ . '/admin/modules/subscribe/subscribe.php';
             require_once _lms_ . '/lib/lib.course.php';
             $docebo_course = new DoceboCourse($id_course);
             $course_man = new Man_Course();
             $course_info = $course_man->getCourseInfo($id_course);
             $date_begin = $course_info["date_begin"];
             $date_end = $course_info["date_end"];
             $group_levels = $docebo_course->getCourseLevel($id_course);
             $user_levels = getSubscribedLevel($id_course, false, false, 0);
             removeSubscription($id_course, $id_user, $group_levels[$user_levels[$id_user]], 0, $date_begin, $date_end);
         }
     }
     if ($this->clearDateDay($id_date)) {
         $query = "DELETE FROM " . $this->date_table . " WHERE id_date = " . $id_date;
         $res = sql_query($query);
     }
     return $res;
 }
Пример #2
0
function subscriberemove()
{
    checkPerm('subscribe', false, 'course');
    require_once $GLOBALS['where_lms'] . '/lib/lib.course.php';
    $id_course = importVar('id_course', true, 0);
    $course_info = Man_Course::getCourseInfo($id_course);
    $edition_id = getCourseEditionId();
    if ($edition_id > 0) {
        $edition_info = Man_Course::getEditionInfo($edition_id, $id_course);
        $course_info = $edition_info + $course_info;
    }
    $lang =& DoceboLanguage::CreateInstance('subscribe', 'lms');
    $out =& $GLOBALS['page'];
    $acl_man =& Docebo::user()->getAclManager();
    if (!isset($_POST['user_to_remove'])) {
        //the user selection is empty, return to course selection
        backcourse('err_selempty');
    }
    $group_levels = getCourseLevel($id_course);
    $user_levels = getSubscribedLevel($id_course, false, false, $edition_id);
    // Subscirbing user
    $re = true;
    $user_del = array();
    while (list($id_user, $v) = each($_POST['user_to_remove'])) {
        $date_begin = $course_info["date_begin"];
        $date_end = $course_info["date_end"];
        $re_sing = removeSubscription($id_course, $id_user, $group_levels[$user_levels[$id_user]], $edition_id, $date_begin, $date_end);
        if ($re_sing) {
            $user_del[] = $id_user;
        }
        $re &= $re_sing;
    }
    require_once _base_ . '/lib/lib.eventmanager.php';
    $array_subst = array('[url]' => Get::sett('url'), '[course]' => $course_info['name']);
    if (!empty($user_del)) {
        // message to user that is waiting
        $msg_composer = new EventMessageComposer();
        $msg_composer->setSubjectLangText('email', '_DEL_USER_SUBSCRIPTION_SUBJECT', false);
        $msg_composer->setBodyLangText('email', '_DEL_USER_SUBSCRIPTION_TEXT', $array_subst);
        $msg_composer->setBodyLangText('sms', '_DEL_USER_SUBSCRIPTION_TEXT_SMS', $array_subst);
        // send message to the user subscribed
        createNewAlert('UserCourseRemoved', 'subscribe', 'remove', '1', 'User removed form a course', $user_del, $msg_composer);
    }
    backcourse($re ? 'ok_subs' : 'err_subs');
}
Пример #3
0
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');
}