Example #1
0
function modactivityscore()
{
    checkPerm('mod');
    require_once $GLOBALS['where_lms'] . '/lib/lib.coursereport.php';
    require_once _base_ . '/lib/lib.form.php';
    require_once _base_ . '/lib/lib.table.php';
    // XXX: Initializaing
    $id_report = importVar('id_report', true, 0);
    $lang =& DoceboLanguage::createInstance('coursereport', 'lms');
    $out =& $GLOBALS['page'];
    $out->setWorkingZone('content');
    // XXX: Instance management
    $acl_man = Docebo::user()->getAclManager();
    $report_man = new CourseReportManager();
    // XXX: Find users
    $type_filter = false;
    if (isset($_GET['type_filter']) && $_GET['type_filter'] != null) {
        $type_filter = $_GET['type_filter'];
    }
    $lev = $type_filter;
    $students = getSubscribed((int) $_SESSION['idCourse'], FALSE, $lev, TRUE, false, false, true);
    $id_students = array_keys($students);
    $students_info =& $acl_man->getUsers($id_students);
    if (isset($_POST['save'])) {
        // retirive activity info
        $info_report = array('id_report' => importVar('id_report', true, 0), 'title' => importVar('title'), 'max_score' => importVar('max_score', true), 'required_score' => importVar('required_score', true), 'source_of' => importVar('source_of'), 'weight' => importVar('weight', true), 'show_to_user' => importVar('show_to_user', false, 'true'), 'use_for_final' => importVar('use_for_final', false, 'true'));
        // XXX: retrive scores
    } else {
        // retirive activity info
        $query_report = "\r\n\t\tSELECT id_report, title, max_score, required_score, weight, show_to_user, use_for_final, id_source, source_of\r\n\t\tFROM " . $GLOBALS['prefix_lms'] . "_coursereport\r\n\t\tWHERE id_course = '" . $_SESSION['idCourse'] . "' AND id_report = '" . $id_report . "'\r\n\t\t\t\tAND (source_of = 'scoitem' OR source_of = 'activity')";
        // TBD AND id_source = '0'";
        $info_report = sql_fetch_assoc(sql_query($query_report));
        // XXX: retrive scores
        $report_score =& $report_man->getReportsScores(array($id_report));
    }
    // XXX: Write in output
    $page_title = array('index.php?modname=coursereport&op=coursereport' => $lang->def('_COURSEREPORT', 'menu_course'), strip_tags($info_report['title']));
    $out->add(getTitleArea($page_title, 'coursereport') . '<div class="std_block">' . Form::openForm('activity', 'index.php?modname=coursereport&amp;op=modactivityscore'));
    // XXX: Save input if needed
    if (isset($_POST['save'])) {
        if ($_POST['title'] == '') {
            $_POST['title'] = $lang->def('_NOTITLE');
        }
        $re_check = $report_man->checkActivityData($_POST);
        if (!$re_check['error']) {
            if (!$report_man->updateActivity($id_report, $_SESSION['idCourse'], $info_report)) {
                $out->add(getErrorUi($lang->def('_OPERATION_FAILURE')));
            } else {
                // save user score modification
                $query_upd_report = "\r\n\t\t\t\tUPDATE " . $GLOBALS['prefix_lms'] . "_coursereport\r\n\t\t\t\tSET weight = '" . $info_report['weight'] . "',\r\n\t\t\t\t\tuse_for_final = '" . $info_report['use_for_final'] . "',\r\n\t\t\t\t\tshow_to_user = '******'show_to_user'] . "'\r\n\t\t\t\tWHERE id_course = '" . $_SESSION['idCourse'] . "' AND id_report = '" . $id_report . "'";
                $re = sql_query($query_upd_report);
                $re = $report_man->saveReportScore($id_report, $_POST['user_score'], $_POST['date_attempt'], $_POST['comment']);
                Util::jump_to('index.php?modname=coursereport&amp;op=coursereport&result=' . ($re ? 'ok' : 'err'));
            }
        } else {
            $out->add(getErrorUi($re_check['message']));
        }
    }
    // main form
    $out->add(Form::openElementSpace() . Form::getOpenFieldSet($lang->def('_ACTIVITY_INFO')) . Form::getHidden('id_report', 'id_report', $id_report) . Form::getHidden('id_source', 'id_source', $info_report['id_source']) . Form::getHidden('source_of', 'source_of', $info_report['source_of']));
    // for scorm object changing title, maxScore and requiredScore is not allowed
    switch ($info_report['source_of']) {
        case 'scoitem':
            $out->add(Form::getLinebox($lang->def('_TITLE_ACT'), strip_tags($info_report['title'])) . Form::getLinebox($lang->def('_MAX_SCORE'), strip_tags($info_report['max_score'])) . Form::getLinebox($lang->def('_REQUIRED_SCORE'), strip_tags($info_report['required_score'])));
            break;
        case 'activity':
            $out->add(Form::getTextfield($lang->def('_TITLE_ACT'), 'title', 'title', '255', $info_report['title']) . Form::getTextfield($lang->def('_MAX_SCORE'), 'max_score', 'max_score', '11', $info_report['max_score']) . Form::getTextfield($lang->def('_REQUIRED_SCORE'), 'required_score', 'required_score', '11', $info_report['required_score']));
            break;
    }
    $out->add(Form::getTextfield($lang->def('_WEIGHT'), 'weight', 'weight', '11', $info_report['weight']) . Form::getDropdown($lang->def('_SHOW_TO_USER'), 'show_to_user', 'show_to_user', array('true' => $lang->def('_YES'), 'false' => $lang->def('_NO')), $info_report['show_to_user']) . Form::getDropdown($lang->def('_USE_FOR_FINAL'), 'use_for_final', 'use_for_final', array('true' => $lang->def('_YES'), 'false' => $lang->def('_NO')), $info_report['use_for_final']) . Form::getCloseFieldSet() . Form::closeElementSpace());
    if ($info_report['source_of'] != 'scoitem') {
        /* XXX: scores */
        $tb = new Table(0, $lang->def('_STUDENTS_VOTE'), $lang->def('_STUDENTS_VOTE'));
        $type_h = array('', 'align-center', 'align-center', '');
        $tb->setColsStyle($type_h);
        $cont_h = array($lang->def('_STUDENTS'), $lang->def('_SCORE'), $lang->def('_DATE'), $lang->def('_COMMENTS'));
        $tb->addHead($cont_h);
        // XXX: Display user scores
        $i = 0;
        while (list($idst_user, $user_info) = each($students_info)) {
            $user_name = $user_info[ACL_INFO_LASTNAME] . $user_info[ACL_INFO_FIRSTNAME] ? $user_info[ACL_INFO_LASTNAME] . ' ' . $user_info[ACL_INFO_FIRSTNAME] : $acl_man->relativeId($user_info[ACL_INFO_USERID]);
            $cont = array(Form::getLabel('user_score_' . $idst_user, $user_name));
            $cont[] = Form::getInputTextfield('textfield_nowh', 'user_score_' . $idst_user, 'user_score[' . $idst_user . ']', isset($report_score[$id_report][$idst_user]['score']) ? $report_score[$id_report][$idst_user]['score'] : (isset($_POST['user_score'][$idst_user]) ? $_POST['user_score'][$idst_user] : ''), strip_tags($lang->def('_SCORE')), '8', ' tabindex="' . $i++ . '" ');
            $cont[] = Form::getInputDatefield('textfield_nowh', 'date_attempt_' . $idst_user, 'date_attempt[' . $idst_user . ']', Format::date(isset($report_score[$id_report][$idst_user]['date_attempt']) ? $report_score[$id_report][$idst_user]['date_attempt'] : (isset($_POST['date_attempt'][$idst_user]) ? $_POST['date_attempt'][$idst_user] : ''), 'date'));
            $cont[] = Form::getInputTextarea('comment_' . $idst_user, 'comment[' . $idst_user . ']', isset($report_score[$id_report][$idst_user]['comment']) ? $report_score[$id_report][$idst_user]['comment'] : (isset($_POST['comment'][$idst_user]) ? stripslashes($_POST['comment'][$idst_user]) : ''), 'textarea_wh_full', 2);
            $tb->addBody($cont);
        }
    }
    $out->add(Form::openButtonSpace() . Form::getButton('save', 'save', $lang->def('_SAVE')) . Form::getButton('undo', 'undo', $lang->def('_UNDO')) . Form::closeButtonSpace());
    if ($info_report['source_of'] != 'scoitem') {
        $out->add($tb->getTable() . Form::openButtonSpace() . Form::getButton('save', 'save', $lang->def('_SAVE')) . Form::getButton('undo', 'undo', $lang->def('_UNDO')) . Form::closeButtonSpace());
    }
    $out->add(Form::closeForm() . '</div>');
}