Пример #1
0
/**
 * This function check if classrooms to be occupated are available or not
 *
 * @param int $idCourse
 * @return array $course_class or false if classrooms are available
 */
function checkAvailableClass($idCourse, $edition_id = FALSE)
{
    require_once $GLOBALS["where_framework"] . "/lib/resources/lib.timetable.php";
    $tt = new TimeTable();
    $resource = "classroom";
    if ($edition_id === FALSE) {
        $consumer = "course";
        $consumer_id = $idCourse;
        $qtxt = "SELECT date_begin, date_end FROM " . $GLOBALS["prefix_lms"] . "_course ";
        $qtxt .= "WHERE idCourse='" . (int) $idCourse . "'";
    } else {
        $consumer = "course_edition";
        $consumer_id = $edition_id;
        $qtxt = "SELECT date_begin, date_end FROM " . $GLOBALS["prefix_lms"] . "_course_edition ";
        $qtxt .= "WHERE idCourseEdition='" . (int) $edition_id . "'";
    }
    $q = sql_query($qtxt);
    if ($q && mysql_num_rows($q) > 0) {
        $row = mysql_fetch_assoc($q);
        $start_date = $row["date_begin"];
        $end_date = $row["date_end"];
    } else {
        return FALSE;
    }
    // Occupied resources
    $in_use = $tt->getResourcesInUse($resource, $start_date, $end_date);
    // Classroom Resources used by current consumer
    $consumer_resources = $tt->getConsumerResources($consumer, $consumer_id, $start_date, $end_date, $resource);
    foreach ($consumer_resources as $val) {
        $tmp_id = $val["resource_id"];
        if (in_array($tmp_id, $in_use)) {
            unset($in_use[$tmp_id]);
        }
    }
    if (empty($in_use)) {
        $in_use = FALSE;
    }
    return $in_use;
}
Пример #2
0
function chooselevel()
{
    checkPerm('subscribe', false, 'course');
    require_once $GLOBALS['where_lms'] . '/lib/lib.course.php';
    require_once _base_ . '/lib/lib.form.php';
    require_once _base_ . '/lib/lib.table.php';
    require_once _base_ . '/lib/lib.userselector.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;
    }
    $out =& $GLOBALS['page'];
    $acl_man =& Docebo::user()->getAclManager();
    $lang =& DoceboLanguage::CreateInstance('subscribe', 'lms');
    $levels = CourseLevel::getLevels();
    // Find limitation
    $can_subscribe = true;
    $max_num_subscribe = $course_info['max_num_subscribe'];
    $subscribe_method = $course_info['subscribe_method'];
    if (Docebo::user()->getUserLevelId() != ADMIN_GROUP_GODADMIN) {
        $limited_subscribe = Docebo::user()->preference->getAdminPreference('admin_rules.limit_course_subscribe');
        $max_subscribe = Docebo::user()->preference->getAdminPreference('admin_rules.max_course_subscribe');
        $direct_subscribe = Docebo::user()->preference->getAdminPreference('admin_rules.direct_course_subscribe');
        if ($limited_subscribe == 'on') {
            $limited_subscribe = true;
        } else {
            $limited_subscribe = false;
        }
        if ($direct_subscribe == 'on') {
            $direct_subscribe = true;
        } else {
            $direct_subscribe = false;
        }
    } else {
        $limited_subscribe = false;
        $max_subscribe = 0;
        $direct_subscribe = true;
    }
    // Print page
    $page_title = array('index.php?modname=course&op=course_list' => $lang->def('_COURSES'), $lang->def('_SUBSCRIBE'), $course_info['name']);
    $GLOBALS['page']->add(getTitleArea($page_title, 'subscribe') . '<div class="std_block">' . getBackUi('index.php?modname=course&amp;op=course_list', $lang->def('_BACK')), 'content');
    // User selected
    $user_alredy_subscribed = getSubscribed($id_course, FALSE, FALSE, FALSE, $edition_id);
    $num_all_user = count($user_alredy_subscribed);
    if (!isset($_POST['user_level_sel'])) {
        $user_select = new UserSelector();
        $entity_selected = $user_select->getSelection($_POST);
        // convert to user only
        $user_selected =& $acl_man->getAllUsersFromIdst($entity_selected);
        $user_selected = array_diff($user_selected, $user_alredy_subscribed);
        $num_selected = count($user_selected);
    } else {
        $num_selected = 0;
        $user_selected = array();
        while (list($id_user, $lv) = each($_POST['user_level_sel'])) {
            $user_selected[$id_user] = $id_user;
            if ($lv != 0) {
                $num_selected++;
            }
        }
        reset($_POST['user_level_sel']);
    }
    $user_selected_info =& $acl_man->getUsers($user_selected);
    if ($num_selected == 0) {
        $GLOBALS['page']->add($lang->def('_EMPTY_SELECTION') . '</div>', 'content');
        return;
    }
    if ($subscribe_method != 3 && !$direct_subscribe) {
        $GLOBALS['page']->add(getResultUi($lang->def('_BEFORE_THIS_APPROVE') . '<br />'), 'content');
    }
    if (isset($_POST['subscribe']) && $can_subscribe) {
        // do subscription
        //retrive id of group of the course for the varioud level
        $level_idst =& getCourseLevel($id_course);
        if (count($level_idst) == 0) {
            //if the group doesn't exists create it
            $level_idst =& DoceboCourse::createCourseLevel($id_course);
        }
        // Subscirbing user
        $waiting = 0;
        $user_subscribed = array();
        $user_waiting = array();
        if ($subscribe_method != 3 && !$direct_subscribe) {
            $waiting = 1;
        }
        while (list($id_user, $lv_sel) = each($_POST['user_level_sel'])) {
            if (!$limited_subscribe || $max_subscribe) {
                if ($lv_sel != 0) {
                    // Add in group for permission
                    $acl_man->addToGroup($level_idst[$lv_sel], $id_user);
                    // Add to edition group
                    if ($edition_id > 0) {
                        $group = '/lms/course_edition/' . $edition_id . '/subscribed';
                        $group_idst = $acl_man->getGroupST($group);
                        if ($group_idst === FALSE) {
                            $group_idst = $acl_man->registerGroup($group, 'all the user of a course edition', true, "course");
                        }
                        $acl_man->addToGroup($group_idst, $id_user);
                    }
                    // Add in table
                    $re = sql_query("\r\n\t\t\t\t\tINSERT INTO " . $GLOBALS['prefix_lms'] . "_courseuser\r\n\t\t\t\t\t( idUser, idCourse, edition_id, level, waiting, subscribed_by, date_inscr )\r\n\t\t\t\t\tVALUES\r\n\t\t\t\t\t( '" . $id_user . "', '" . $id_course . "', '" . $edition_id . "', '" . $lv_sel . "', '" . $waiting . "', '" . getLogUserId() . "', '" . date("Y-m-d H:i:s") . "' )\t");
                    if ($re) {
                        if ($waiting) {
                            $user_waiting[] = $id_user;
                        } else {
                            $user_subscribed[] = $id_user;
                        }
                        addUserToTimeTable($id_user, $id_course, $edition_id);
                    }
                }
                $max_subscribe--;
            }
        }
        //end while
        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'], '[medium_time]' => $course_info['mediumTime'], '[course_name]' => $course_info['name'], '[course_code]' => $course['code']);
        if (!empty($user_subscribed)) {
            // message to user subscribed
            $msg_composer = new EventMessageComposer();
            $msg_composer->setSubjectLangText('email', '_NEW_USER_SUBSCRIBED_SUBJECT', false);
            $msg_composer->setBodyLangText('email', '_NEW_USER_SUBSCRIBED_TEXT', $array_subst);
            $msg_composer->setBodyLangText('sms', '_NEW_USER_SUBSCRIBED_TEXT_SMS', $array_subst);
            // send message to the user subscribed
            createNewAlert('UserCourseInserted', 'subscribe', 'insert', '1', 'User subscribed', $user_subscribed, $msg_composer);
        }
        if (!empty($user_waiting)) {
            // message to user that is waiting
            $msg_composer = new EventMessageComposer();
            $msg_composer->setSubjectLangText('email', '_NEW_USER_SUBS_WAITING_SUBJECT', false);
            $msg_composer->setBodyLangText('email', '_NEW_USER_SUBS_WAITING_TEXT', $array_subst);
            $msg_composer->setBodyLangText('sms', '_NEW_USER_SUBS_WAITING_TEXT_SMS', $array_subst);
            // send message to the user subscribed
            createNewAlert('UserCourseInsertModerate', 'subscribe', 'insert', '1', 'User subscribed with moderation', $user_waiting, $msg_composer);
        }
        if (Docebo::user()->getUserLevelId() != ADMIN_GROUP_GODADMIN) {
            Docebo::user()->preference->setPreference('admin_rules.max_course_subscribe', $max_subscribe);
        }
        backcourse('ok_subs');
    }
    $GLOBALS['page']->add(Form::openForm('levelselection', 'index.php?modname=subscribe&amp;op=chooselevel') . Form::getHidden('id_course', 'id_course', $id_course) . Form::getHidden('edition_id', 'edition_id', $edition_id), 'content');
    $tb = new Table(0, $lang->def('_CAPTION_SELECT_LEVELS'), $lang->def('_SUMMARY_SELECT_LEVEL'));
    $type_h = array('image', '', '');
    $img = '<img src="' . getPathImage('fw') . 'standard/warning_triangle.png" ';
    $img .= 'alt="' . $lang->def("_USER_IS_BUSY") . '" title="' . $lang->def("_USER_IS_BUSY") . '" />';
    $content_h = array($img, $lang->def('_USERNAME'), $lang->def('_FULLNAME'));
    foreach ($levels as $lv => $lv_name) {
        $type_h[] = 'image';
        $content_h[] = '<a href="javascript:SelAll(\'' . $lv . '\');">' . $lv_name . '</a>';
    }
    $type_h[] = 'image';
    $content_h[] = $lang->def('_CANCEL');
    $tb->addHead($content_h, $type_h);
    if ($course_info["course_type"] === "elearning") {
        $busy_users = array();
    } else {
        require_once $GLOBALS['where_framework'] . "/lib/resources/lib.timetable.php";
        $tt = new TimeTable();
        $busy_users = $tt->getResourcesInUse("user", $course_info["date_begin"], $course_info["date_end"], TRUE);
    }
    $num_user_sel = 0;
    $enought_credit = true;
    reset($user_selected_info);
    $jsArr = "var elementi = new Array(";
    $i = 0;
    while ((list($id_user, $user_info) = each($user_selected_info)) && $enought_credit) {
        if ($i != 0) {
            $jsArr .= ",";
        }
        $i++;
        $jsArr .= "'" . $id_user . "'";
        // if the user isn't alredy subscribed to the course
        if (!isset($user_alredy_subscribed[$id_user])) {
            if (in_array($id_user, $busy_users)) {
                $img = '<img src="' . getPathImage('fw') . 'standard/warning_triangle.png" ';
                $img .= 'alt="' . $lang->def("_USER_IS_BUSY") . '" title="' . $lang->def("_USER_IS_BUSY") . '" />';
                $msg = $lang->def("_USER_IS_BUSY_MSG");
                $is_user_busy = $img;
                //."</a>";
            } else {
                $is_user_busy = "&nbsp;";
            }
            $content = array($is_user_busy, substr($user_info[ACL_INFO_USERID], 1), $user_info[ACL_INFO_LASTNAME] . ' ' . $user_info[ACL_INFO_FIRSTNAME]);
            foreach ($levels as $lv => $lv_name) {
                $content[] = Form::getInputRadio('user_level_sel_' . $id_user . '_' . $lv, 'user_level_sel[' . $id_user . ']', $lv, isset($_POST['user_level_sel']) ? $lv == $_POST['user_level_sel'][$id_user] : $lv == 3, '') . '<label class="access-only" for="user_level_sel_' . $id_user . '_' . $lv . '">' . $lv_name . '</label>';
            }
            $content[] = Form::getInputRadio('user_level_sel_' . $id_user . '_0', 'user_level_sel[' . $id_user . ']', 0, isset($_POST['user_level_sel']) ? 0 == $_POST['user_level_sel'][$id_user] : false, '') . '<label class="access-only" for="user_level_sel_' . $id_user . '_0">' . $lang->def('_CANCEL') . '</label>';
            $tb->addBody($content);
            $num_user_sel++;
        }
    }
    $GLOBALS['page']->add($tb->getTable(), 'content');
    $GLOBALS['page']->add(Form::openButtonSpace() . '<br />' . Form::getButton('subscribe', 'subscribe', $lang->def('_SUBSCRIBE')) . Form::getButton('cancelselector', 'cancelselector', $lang->def('_UNDO')) . Form::closeButtonSpace() . Form::closeForm(), 'content');
    $GLOBALS['page']->add('</div>', 'content');
    $GLOBALS['page']->add('
<script>
' . $jsArr . ');
function SelAll (lvl)
{
        var nb;
        ne = elementi.length;
        mod = document.getElementById(\'levelselection\');
        for (var i=0;i<ne;i++)
        {
                elem = \'user_level_sel_\'+elementi[i]+\'_\'+lvl;
                var e = document.getElementById(elem);
                e.checked = 1;
        }
}
</script>');
}