Ejemplo n.º 1
0
/**
 * Print statistic on one item
 *
 **/
function statitem()
{
    require_once _lms_ . '/class.module/track.object.php';
    require_once _base_ . '/lib/lib.form.php';
    require_once _base_ . '/lib/lib.table.php';
    require_once _lms_ . '/lib/lib.subscribe.php';
    $cs = new CourseSubscribe_Manager();
    $lang =& DoceboLanguage::createInstance('stats', 'lms');
    $out =& $GLOBALS['page'];
    $form = new Form();
    $aclManager =& Docebo::user()->getACLManager();
    $acl =& Docebo::user()->getACL();
    $idItem = (int) $_GET['idItem'];
    $group_filter = Get::req('group_filter', DOTY_INT, -1);
    $status_filter = Get::req('status_filter', DOTY_INT, -1);
    $user_filter = Get::req('user_filter', DOTY_MIXED, '');
    $tabStat = new Table(Get::sett('visuItem'), $lang->def('_STATSITEM') . $titleLO, $lang->def('_STATSITEM') . $titleLO);
    $tabStat->initNavBar('ini', 'button');
    $limit = $tabStat->getSelectedElement();
    list($titleLO, $objectType) = sql_fetch_row(sql_query("SELECT title, objectType FROM " . $GLOBALS['prefix_lms'] . "_organization" . " WHERE idOrg='" . $idItem . "'"));
    $lev = false;
    $group_all_members = false;
    if ($group_filter != '-1') {
        $group_all_members = $aclManager->getGroupAllUser($group_filter);
    }
    $students = getSubscribedInfo((int) $_SESSION['idCourse'], false, $lev, true, $status_filter != -1 ? $status_filter : false, $editions_filter != -1 ? $editions_filter : false, true, $user_filter, $group_all_members, $limit);
    $query = "SELECT COUNT(*)" . " FROM %lms_courseuser AS cu" . ($user_filter !== '' ? " JOIN " . $GLOBALS['prefix_fw'] . "_user AS u ON u.idst = cu.idUser" : '') . " WHERE cu.idCourse = " . (int) $_SESSION['idCourse'] . ($status_filter != -1 ? " AND cu.status = '" . $status_filter . "'" : '') . ($user_filter !== '' ? " AND (u.firstname LIKE '%" . $user_filter . "%' OR u.lastname LIKE '%" . $user_filter . "%' OR u.userid LIKE '%" . $user_filter . "%')" : '') . ($group_all_members !== false ? " AND c.idUser IN (" . implode(',', $group_all_members) . ")" : '');
    list($total_user) = sql_fetch_row(sql_query($query));
    // get idst of the access in item
    $query = "SELECT value FROM " . $GLOBALS['prefix_lms'] . "_organization_access" . " WHERE idOrgAccess = '" . $idItem . "'";
    if (($rs = sql_query($query)) === FALSE) {
        UiFeedback::error("Error on query to load item access");
        return;
    }
    $arr_access = array();
    while (list($value) = sql_fetch_row($rs)) {
        $arr_access[] = $value;
    }
    $out->setWorkingZone('content');
    $out->add(getTitleArea($lang->def('_STATSITEM') . $titleLO, 'stats'));
    $out->add('<div class="std_block">' . getBackUi('index.php?modname=stats&amp;op=statcourse', $lang->def('_BACK')));
    $out->add($form->openForm('orgshow', 'index.php?modname=stats&amp;op=statitem&amp;idItem=' . $idItem));
    if (isset($_POST['view_open_quest'])) {
        $query_resource = "SELECT idResource" . " FROM " . $GLOBALS['prefix_lms'] . "_organization" . " WHERE idOrg = '" . $idItem . "'";
        list($id_poll) = sql_fetch_row(sql_query($query_resource));
        $query_quest = "SELECT id_quest, title_quest" . " FROM " . $GLOBALS['prefix_lms'] . "_pollquest" . " WHERE id_poll = '" . $id_poll . "'" . " AND type_quest = 'extended_text'";
        $result_quest = sql_query($query_quest);
        $type_h = array('');
        $cont_h = array($lang->def('_ANSWER'));
        while (list($id_quest, $title_quest) = sql_fetch_row($result_quest)) {
            $tb = new Table(400, $title_quest);
            $tb->setColsStyle($type_h);
            $tb->addHead($cont_h);
            $query_answer = "SELECT more_info" . " FROM " . $GLOBALS['prefix_lms'] . "_polltrack_answer" . " WHERE id_quest = '" . $id_quest . "'";
            $result_answer = sql_query($query_answer);
            while (list($answer) = sql_fetch_row($result_answer)) {
                $cont = array();
                $cont[] = $answer;
                $tb->addBody($cont);
            }
            $out->add($tb->getTable() . '<br/>');
        }
        $out->add($form->openButtonSpace() . $form->getButton('back', 'back', $lang->def('_BACK')) . $form->closeButtonSpace());
    } else {
        $arr_idst = $aclManager->getBasePathGroupST('/lms/course/' . (int) $_SESSION['idCourse'] . '/group');
        $arr_result_groups = $aclManager->getGroups($arr_idst);
        $std_content = $aclManager->getContext();
        $aclManager->setContext('/lms/course/' . (int) $_SESSION['idCourse'] . '/group');
        $arr_groups = array(-1 => $lang->def('_ALL'));
        foreach ($arr_result_groups as $idst_group => $info_group) {
            if (!$info_group[ACL_INFO_GROUPHIDDEN]) {
                $arr_groups[$idst_group] = $aclManager->relativeId($info_group[ACL_INFO_GROUPID]);
            }
        }
        $aclManager->setContext($std_content);
        $out->add(Form::getTextField(Lang::t('_FULLNAME', 'standard'), 'user_filter', 'user_filter', 255, $user_filter));
        $out->add($form->getDropdown($lang->def('_GROUPS'), 'group_filter', 'group_filter', $arr_groups, $group_filter));
        // ------ Filter on status
        $arr_status = array(-1 => $lang->def('_FILTERSTATUSSELECTONEOPTION'), _CUS_SUBSCRIBED => $lang->def('_USER_STATUS_SUBS'), _CUS_BEGIN => $lang->def('_USER_STATUS_BEGIN'), _CUS_END => $lang->def('_END'), _CUS_SUSPEND => $lang->def('_SUSPENDED'));
        $out->add($form->getDropdown($lang->def('_STATUS'), 'status_filter', 'status_filter', $arr_status, $status_filter));
        $out->add($form->getButton('gofilter', 'gofilter', $lang->def('_SEARCH')));
        //-----------------------------------------
        $content_h = array($lang->def('_USERNAME'), $lang->def('_STATS_FULLNAME'), $lang->def('_STATUS'), $lang->def('_PROGRESS'));
        $type_h = array('', '', 'image', 'image', '');
        $tabStat->setColsStyle($type_h);
        $tabStat->addHead($content_h);
        //-----------------------------------------
        foreach ($students as $idst => $user_course_info) {
            $user_info = $aclManager->getUser($idst, FALSE);
            if ($user_info != false) {
                $arr_allst = $acl->getUserAllST($user_info[ACL_INFO_USERID]);
                if (count($arr_access) === 0 || count(array_intersect($arr_access, $arr_allst)) > 0) {
                    $status = Track_Object::getStatusFromId($idItem, $idst);
                    // NOTE: How to get stat_status for users?
                    $stat_status = $cs->getUserStatusTr($user_course_info['status']);
                    $tabStat->addBody(array('<a href="index.php?modname=stats&amp;op=statoneuseroneitem&amp;idUser='******'&amp;idItem=' . $idItem . '" >' . $aclManager->relativeId($user_info[ACL_INFO_USERID]) . '</a>', $user_info[ACL_INFO_LASTNAME] . '&nbsp;' . $user_info[ACL_INFO_FIRSTNAME], $stat_status, printReport($status, TRUE)));
                }
            }
        }
        $out->add($tabStat->getTable());
        $out->add($tabStat->getNavBar($limit, $total_user));
        $query = "SELECT idResource" . " FROM " . $GLOBALS['prefix_lms'] . "_organization" . " WHERE idOrg = '" . $idItem . "'";
        list($id_poll) = sql_fetch_row(sql_query($query));
        $query = "SELECT id_quest" . " FROM " . $GLOBALS['prefix_lms'] . "_pollquest" . " WHERE id_poll = '" . $id_poll . "'" . " AND type_quest = 'extended_text'";
        $result = sql_query($query);
        if (sql_num_rows($result) && $objectType == 'poll') {
            $out->add($form->openButtonSpace() . '<br/>' . $form->getButton('view_open_quest', 'view_open_quest', $lang->def('_VIEW_OPEN_QUEST')) . $form->closeButtonSpace());
        }
    }
    $out->add($form->closeForm());
    $out->add('</div>' . "\n");
}