Exemplo n.º 1
0
/**
 * @param int $start
 * @param int $limit
 * @param int $column
 * @param string $direction
 * @param int $work_id
 * @param array $where_condition
 * @param int $studentId
 * @param bool $getCount
 * @return array
 */
function get_work_user_list($start, $limit, $column, $direction, $work_id, $where_condition = null, $studentId = null, $getCount = false)
{
    $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
    $iprop_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
    $user_table = Database::get_main_table(TABLE_MAIN_USER);
    $session_id = api_get_session_id();
    $group_id = api_get_group_id();
    $course_info = api_get_course_info();
    $course_id = $course_info['real_id'];
    $work_id = intval($work_id);
    $column = !empty($column) ? Database::escape_string($column) : 'sent_date';
    $start = intval($start);
    $limit = intval($limit);
    if (!in_array($direction, array('asc', 'desc'))) {
        $direction = 'desc';
    }
    $work_data = get_work_data_by_id($work_id);
    $is_allowed_to_edit = api_is_allowed_to_edit() || api_is_coach();
    $condition_session = api_get_session_condition($session_id, true, false, 'work.session_id');
    $locked = api_resource_is_locked_by_gradebook($work_id, LINK_STUDENTPUBLICATION);
    $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(api_get_user_id(), $course_info);
    if (!empty($work_data)) {
        if (!empty($group_id)) {
            $extra_conditions = " work.post_group_id = '" . intval($group_id) . "' ";
            // set to select only messages posted by the user's group
        } else {
            $extra_conditions = " work.post_group_id = '0' ";
        }
        if ($is_allowed_to_edit || $isDrhOfCourse) {
            $extra_conditions .= ' AND work.active IN (0, 1) ';
        } else {
            if (isset($course_info['show_score']) && $course_info['show_score'] == 1) {
                $extra_conditions .= " AND (u.user_id = " . api_get_user_id() . " AND work.active IN (0, 1)) ";
            } else {
                $extra_conditions .= ' AND work.active IN (0, 1) ';
            }
        }
        $extra_conditions .= " AND parent_id  = " . $work_id . " ";
        $select = 'SELECT DISTINCT
                        u.user_id,
                        work.id as id,
                        title as title,
                        description,
                        url,
                        sent_date,
                        contains_file,
                        has_properties,
                        view_properties,
                        qualification,
                        weight,
                        allow_text_assignment,
                        u.firstname,
                        u.lastname,
                        u.username,
                        parent_id,
                        accepted,
                        qualificator_id,
                        url_correction
                        ';
        if ($getCount) {
            $select = "SELECT DISTINCT count(u.user_id) as count ";
        }
        $user_condition = "INNER JOIN {$user_table} u  ON (work.user_id = u.user_id) ";
        $work_condition = "{$iprop_table} prop INNER JOIN {$work_table} work\n                           ON (prop.ref = work.id AND prop.c_id = {$course_id} AND work.c_id = {$course_id} ) ";
        $work_assignment = get_work_assignment_by_id($work_id);
        if (!empty($studentId)) {
            $where_condition .= " AND u.user_id = " . intval($studentId);
        }
        $sql = " {$select}\n                FROM {$work_condition}  {$user_condition}\n                WHERE {$extra_conditions} {$where_condition} {$condition_session}\n                    AND u.status != " . INVITEE . "\n                ORDER BY {$column} {$direction}";
        if (!empty($start) && !empty($limit)) {
            $sql .= " LIMIT {$start}, {$limit}";
        }
        $result = Database::query($sql);
        $works = array();
        if ($getCount) {
            $work = Database::fetch_array($result, 'ASSOC');
            return $work['count'];
        }
        $url = api_get_path(WEB_CODE_PATH) . 'work/';
        $unoconv = api_get_configuration_value('unoconv.binaries');
        while ($work = Database::fetch_array($result, 'ASSOC')) {
            $item_id = $work['id'];
            // Get the author ID for that document from the item_property table
            $is_author = false;
            $can_read = false;
            $owner_id = $work['user_id'];
            /* Because a bug found when saving items using the api_item_property_update()
               the field $item_property_data['insert_user_id'] is not reliable. */
            if (!$is_allowed_to_edit && $owner_id == api_get_user_id()) {
                $is_author = true;
            }
            if ($course_info['show_score'] == 0) {
                $can_read = true;
            }
            if ($work['accepted'] == '0') {
                $class = 'invisible';
            } else {
                $class = '';
            }
            $qualification_exists = false;
            if (!empty($work_data['qualification']) && intval($work_data['qualification']) > 0) {
                $qualification_exists = true;
            }
            $qualification_string = '';
            if ($qualification_exists) {
                if ($work['qualification'] == '') {
                    $qualification_string = Display::label('-');
                } else {
                    $label = 'info';
                    $relativeScore = $work['qualification'] / $work_data['qualification'];
                    if ($relativeScore < 0.5) {
                        $label = 'important';
                    } elseif ($relativeScore < 0.75) {
                        $label = 'warning';
                    }
                    $qualification_string = Display::label($work['qualification'] . ' / ' . $work_data['qualification'], $label);
                }
            }
            $work['qualification_score'] = $work['qualification'];
            $add_string = '';
            $time_expires = '';
            if (!empty($work_assignment['expires_on'])) {
                $time_expires = api_strtotime($work_assignment['expires_on'], 'UTC');
            }
            if (!empty($work_assignment['expires_on']) && !empty($time_expires) && $time_expires < api_strtotime($work['sent_date'], 'UTC')) {
                $add_string = Display::label(get_lang('Expired'), 'important');
            }
            if ($can_read && $work['accepted'] == '1' || $is_author && in_array($work['accepted'], array('1', '0')) || ($is_allowed_to_edit || api_is_drh())) {
                // Firstname, lastname, username
                $work['firstname'] = Display::div($work['firstname'], array('class' => $class));
                $work['lastname'] = Display::div($work['lastname'], array('class' => $class));
                $work['title_clean'] = $work['title'];
                if (strlen($work['title']) > 30) {
                    $short_title = substr($work['title'], 0, 27) . '...';
                    $work['title'] = Display::span($short_title, array('class' => $class, 'title' => $work['title']));
                } else {
                    $work['title'] = Display::div($work['title'], array('class' => $class));
                }
                // Type.
                $work['type'] = DocumentManager::build_document_icon_tag('file', $work['url']);
                // File name.
                $link_to_download = null;
                // If URL is present then there's a file to download keep BC.
                if ($work['contains_file'] || !empty($work['url'])) {
                    $link_to_download = '<a href="' . $url . 'download.php?id=' . $item_id . '&' . api_get_cidreq() . '">' . Display::return_icon('save.png', get_lang('Save'), array(), ICON_SIZE_SMALL) . '</a> ';
                }
                $send_to = Portfolio::share('work', $work['id'], array('style' => 'white-space:nowrap;'));
                $feedback = null;
                $count = getWorkCommentCount($item_id, $course_info);
                if (!is_null($count) && !empty($count)) {
                    if ($qualification_exists) {
                        $feedback .= "<br />";
                    }
                    $feedback .= '<a href="' . $url . 'view.php?' . api_get_cidreq() . '&id=' . $item_id . '" title="' . get_lang('View') . '">' . Display::label($count . ' ' . get_lang('Feedback'), 'info') . '</a> ';
                }
                $work['qualification'] = $qualification_string . $feedback;
                $work['qualification_only'] = $qualification_string;
                // Date.
                $work_date = api_convert_and_format_date($work['sent_date']);
                $work['sent_date_from_db'] = $work['sent_date'];
                $work['sent_date'] = '<div class="date-time">' . date_to_str_ago(api_get_local_time($work['sent_date'])) . ' ' . $add_string . ' ' . $work_date . '</div>';
                // Actions.
                $correction = '';
                $action = '';
                if (api_is_allowed_to_edit()) {
                    if (!empty($work['url_correction'])) {
                        $action .= Display::url(Display::return_icon('check-circle.png', get_lang('Correction'), null, ICON_SIZE_SMALL), api_get_path(WEB_CODE_PATH) . 'work/download.php?id=' . $item_id . '&' . api_get_cidreq() . '&correction=1');
                    }
                    $action .= '<a href="' . $url . 'view.php?' . api_get_cidreq() . '&id=' . $item_id . '" title="' . get_lang('View') . '">' . Display::return_icon('default.png', get_lang('View'), array(), ICON_SIZE_SMALL) . '</a> ';
                    if ($unoconv && empty($work['contains_file'])) {
                        $action .= '<a href="' . $url . 'work_list_all.php?' . api_get_cidreq() . '&id=' . $work_id . '&action=export_to_doc&item_id=' . $item_id . '" title="' . get_lang('ExportToDoc') . '" >' . Display::return_icon('export_doc.png', get_lang('ExportToDoc'), array(), ICON_SIZE_SMALL) . '</a> ';
                    }
                    $correction = '
                        <form
                        id="file_upload_' . $item_id . '"
                        class="work_correction_file_upload file_upload_small"
                        action="' . api_get_path(WEB_AJAX_PATH) . 'work.ajax.php?' . api_get_cidreq() . '&a=upload_correction_file&item_id=' . $item_id . '" method="POST" enctype="multipart/form-data"
                        >
                        <div class="button-load">
                            ' . get_lang('ClickOrDropFilesHere') . '
                        </div>
                        <input type="file" name="file" multiple>
                        <button type="submit"></button>
                        </form>
                    ';
                    $correction .= "\n                        <script>\n                        \$(document).ready(function() {\n                            \$('#file_upload_" . $item_id . "').fileupload({\n                                uploadTable: \$('.files'),\n                                downloadTable: \$('.files'),\n                                buildUploadRow: function (files, index) {\n                                    \$('.files').show();\n                                    return\n                                        \$('<tr><td>' + files[index].name + '<\\/td>' +\n                                        '<td class=\"file_upload_progress\"><div><\\/div><\\/td>' +\n                                        '<td class=\"file_upload_cancel\">' +\n                                        '<button class=\"ui-state-default ui-corner-all\" title=\"" . get_lang('Cancel') . "\">' +\n                                        '<span class=\"ui-icon ui-icon-cancel\">" . get_lang('Cancel') . "<\\/span>' +'<\\/button>'+\n                                        '<\\/td><\\/tr>');\n                                },\n                                buildDownloadRow: function (file) {\n                                    return \$('<tr><td>' + file.name + '<\\/td> <td> ' + file.size + ' <\\/td>  <td>&nbsp;' + file.result + ' <\\/td> <\\/tr>');\n                                }\n                            });\n                        });\n                        </script>\n                    ";
                    if ($locked) {
                        if ($qualification_exists) {
                            $action .= Display::return_icon('rate_work_na.png', get_lang('CorrectAndRate'), array(), ICON_SIZE_SMALL);
                        } else {
                            $action .= Display::return_icon('edit_na.png', get_lang('Comment'), array(), ICON_SIZE_SMALL);
                        }
                    } else {
                        if ($qualification_exists) {
                            $action .= '<a href="' . $url . 'edit.php?' . api_get_cidreq() . '&item_id=' . $item_id . '&id=' . $work['parent_id'] . '" title="' . get_lang('Edit') . '"  >' . Display::return_icon('rate_work.png', get_lang('CorrectAndRate'), array(), ICON_SIZE_SMALL) . '</a>';
                        } else {
                            $action .= '<a href="' . $url . 'edit.php?' . api_get_cidreq() . '&item_id=' . $item_id . '&id=' . $work['parent_id'] . '" title="' . get_lang('Modify') . '">' . Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL) . '</a>';
                        }
                    }
                    if ($work['contains_file']) {
                        if ($locked) {
                            $action .= Display::return_icon('move_na.png', get_lang('Move'), array(), ICON_SIZE_SMALL);
                        } else {
                            $action .= '<a href="' . $url . 'work.php?' . api_get_cidreq() . '&action=move&item_id=' . $item_id . '&id=' . $work['parent_id'] . '" title="' . get_lang('Move') . '">' . Display::return_icon('move.png', get_lang('Move'), array(), ICON_SIZE_SMALL) . '</a>';
                        }
                    }
                    if ($work['accepted'] == '1') {
                        $action .= '<a href="' . $url . 'work_list_all.php?' . api_get_cidreq() . '&id=' . $work_id . '&action=make_invisible&item_id=' . $item_id . '" title="' . get_lang('Invisible') . '" >' . Display::return_icon('visible.png', get_lang('Invisible'), array(), ICON_SIZE_SMALL) . '</a>';
                    } else {
                        $action .= '<a href="' . $url . 'work_list_all.php?' . api_get_cidreq() . '&id=' . $work_id . '&action=make_visible&item_id=' . $item_id . '" title="' . get_lang('Visible') . '" >' . Display::return_icon('invisible.png', get_lang('Visible'), array(), ICON_SIZE_SMALL) . '</a> ';
                    }
                    if ($locked) {
                        $action .= Display::return_icon('delete_na.png', get_lang('Delete'), '', ICON_SIZE_SMALL);
                    } else {
                        $action .= '<a href="' . $url . 'work_list_all.php?' . api_get_cidreq() . '&id=' . $work_id . '&action=delete&item_id=' . $item_id . '" onclick="javascript:if(!confirm(' . "'" . addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES)) . "'" . ')) return false;" title="' . get_lang('Delete') . '" >' . Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL) . '</a>';
                    }
                } elseif ($is_author && (empty($work['qualificator_id']) || $work['qualificator_id'] == 0)) {
                    $action .= '<a href="' . $url . 'view.php?' . api_get_cidreq() . '&id=' . $item_id . '" title="' . get_lang('View') . '">' . Display::return_icon('default.png', get_lang('View'), array(), ICON_SIZE_SMALL) . '</a>';
                    if (api_get_course_setting('student_delete_own_publication') == 1) {
                        if (api_is_allowed_to_session_edit(false, true)) {
                            $action .= '<a href="' . $url . 'edit.php?' . api_get_cidreq() . '&item_id=' . $item_id . '&id=' . $work['parent_id'] . '" title="' . get_lang('Modify') . '">' . Display::return_icon('edit.png', get_lang('Comment'), array(), ICON_SIZE_SMALL) . '</a>';
                        }
                        $action .= ' <a href="' . $url . 'work_list.php?' . api_get_cidreq() . '&action=delete&item_id=' . $item_id . '&id=' . $work['parent_id'] . '" onclick="javascript:if(!confirm(' . "'" . addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES)) . "'" . ')) return false;" title="' . get_lang('Delete') . '"  >' . Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL) . '</a>';
                    } else {
                        $action .= Display::return_icon('edit_na.png', get_lang('Modify'), array(), ICON_SIZE_SMALL);
                    }
                } else {
                    $action .= '<a href="' . $url . 'view.php?' . api_get_cidreq() . '&id=' . $item_id . '" title="' . get_lang('View') . '">' . Display::return_icon('default.png', get_lang('View'), array(), ICON_SIZE_SMALL) . '</a>';
                    $action .= Display::return_icon('edit_na.png', get_lang('Modify'), array(), ICON_SIZE_SMALL);
                }
                // Status.
                if (empty($work['qualificator_id'])) {
                    $qualificator_id = Display::label(get_lang('NotRevised'), 'warning');
                } else {
                    $qualificator_id = Display::label(get_lang('Revised'), 'success');
                }
                $work['qualificator_id'] = $qualificator_id;
                $work['actions'] = $send_to . $link_to_download . $action;
                $work['correction'] = $correction;
                $works[] = $work;
            }
        }
        return $works;
    }
}
Exemplo n.º 2
0
         }
     }
     $result = ExerciseLib::get_exam_results_data($start, $limit, $sidx, $sord, $exercise_id, $whereCondition);
     break;
 case 'get_hotpotatoes_exercise_results':
     $course = api_get_course_info();
     $documentPath = api_get_path(SYS_COURSE_PATH) . $course['path'] . "/document";
     if (api_is_allowed_to_edit()) {
         $columns = array('firstname', 'lastname', 'username', 'group_name', 'exe_date', 'score', 'actions');
     } else {
         $columns = array('exe_date', 'score', 'actions');
     }
     $result = ExerciseLib::get_exam_results_hotpotatoes_data($start, $limit, $sidx, $sord, $hotpot_path, $whereCondition);
     break;
 case 'get_work_student_list_overview':
     if (!(api_is_allowed_to_edit() || api_is_coach())) {
         return array();
     }
     require_once api_get_path(SYS_CODE_PATH) . 'work/work.lib.php';
     $columns = array('student', 'works');
     $result = getWorkUserListData($workId, api_get_course_id(), api_get_session_id(), api_get_group_id(), $start, $limit, $sidx, $sord);
     break;
 case 'get_hotpotatoes_exercise_results':
     $course = api_get_course_info();
     $documentPath = api_get_path(SYS_COURSE_PATH) . $course['path'] . "/document";
     if (api_is_allowed_to_edit(null, true) || api_is_drh()) {
         $columns = array('firstname', 'lastname', 'username', 'group_name', 'exe_date', 'score', 'actions');
     } else {
         $columns = array('exe_date', 'score', 'actions');
     }
     $result = ExerciseLib::get_exam_results_hotpotatoes_data($start, $limit, $sidx, $sord, $hotpot_path, $whereCondition);
Exemplo n.º 3
0
 *	Course admins can change user permissions, subscribe and unsubscribe users...
 *
 *	- show users registered in courses;
 *
 *	@author Roan Embrechts
 *	@author Julio Montoya Armas, Several fixes
 *	@package chamilo.user
 */
$use_anonymous = true;
require_once '../inc/global.inc.php';
$current_course_tool = TOOL_USER;
$this_section = SECTION_COURSES;
// notice for unauthorized people.
api_protect_course_script(true);
if (!api_is_platform_admin(true)) {
    if (!api_is_course_admin() && !api_is_coach()) {
        if (api_get_course_setting('allow_user_view_user_list') == 0) {
            api_not_allowed(true);
        }
    }
}
/* Constants and variables */
$course_code = Database::escape_string(api_get_course_id());
$sessionId = api_get_session_id();
$is_western_name_order = api_is_western_name_order();
$sort_by_first_name = api_sort_by_first_name();
$course_info = api_get_course_info();
$user_id = api_get_user_id();
$courseCode = $course_info['code'];
$courseId = $course_info['real_id'];
//Can't auto unregister from a session
Exemplo n.º 4
0
 /**
  * @param int $filter
  * @param string $view
  * @return string
  */
 public function displayActions($view, $filter = 0)
 {
     $courseInfo = api_get_course_info();
     $actionsLeft = '';
     $actionsLeft .= "<a href='" . api_get_path(WEB_CODE_PATH) . "calendar/agenda_js.php?type={$this->type}'>" . Display::return_icon('calendar.png', get_lang('Calendar'), '', ICON_SIZE_MEDIUM) . "</a>";
     $courseCondition = '';
     if (!empty($courseInfo)) {
         $courseCondition = api_get_cidreq();
     }
     $actionsLeft .= "<a href='" . api_get_path(WEB_CODE_PATH) . "calendar/agenda_list.php?type={$this->type}&" . $courseCondition . "'>" . Display::return_icon('week.png', get_lang('AgendaList'), '', ICON_SIZE_MEDIUM) . "</a>";
     $form = '';
     if (api_is_allowed_to_edit(false, true) || api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous() && api_is_allowed_to_session_edit(false, true) || GroupManager::user_has_access(api_get_user_id(), api_get_group_id(), GroupManager::GROUP_TOOL_CALENDAR) && GroupManager::is_tutor_of_group(api_get_user_id(), api_get_group_id())) {
         $actionsLeft .= Display::url(Display::return_icon('new_event.png', get_lang('AgendaAdd'), '', ICON_SIZE_MEDIUM), api_get_path(WEB_CODE_PATH) . "calendar/agenda.php?" . api_get_cidreq() . "&action=add&type=" . $this->type);
         $actionsLeft .= Display::url(Display::return_icon('import_calendar.png', get_lang('ICalFileImport'), '', ICON_SIZE_MEDIUM), api_get_path(WEB_CODE_PATH) . "calendar/agenda.php?" . api_get_cidreq() . "&action=importical&type=" . $this->type);
         if ($this->type == 'course') {
             if (!isset($_GET['action'])) {
                 $form = new FormValidator('form-search', 'post', '', '', array(), FormValidator::LAYOUT_INLINE);
                 $attributes = array('multiple' => false, 'id' => 'select_form_id_search');
                 $selectedValues = $this->parseAgendaFilter($filter);
                 $this->showToForm($form, $selectedValues, $attributes);
                 $form = $form->returnForm();
             }
         }
     }
     if (api_is_platform_admin() || api_is_teacher() || api_is_student_boss() || api_is_drh() || api_is_session_admin() || api_is_coach()) {
         if ($this->type == 'personal') {
             $form = null;
             if (!isset($_GET['action'])) {
                 $form = new FormValidator('form-search', 'get', api_get_self() . '?type=personal&', '', array(), FormValidator::LAYOUT_INLINE);
                 $sessions = SessionManager::get_sessions_by_user(api_get_user_id());
                 $form->addHidden('type', 'personal');
                 $sessions = array_column($sessions, 'session_name', 'session_id');
                 $sessions = ['0' => get_lang('SelectAnOption')] + $sessions;
                 $form->addSelect('session_id', get_lang('Session'), $sessions, ['id' => 'session_id', 'onchange' => 'submit();']);
                 //$form->addButtonFilter(get_lang('Filter'));
                 //$renderer = $form->defaultRenderer();
                 //$renderer->setCustomElementTemplate('<div class="col-md-6">{element}</div>');
                 $form->addButtonReset(get_lang('Reset'));
                 $form = $form->returnForm();
             }
         }
     }
     $actionsRight = '';
     if ($view == 'calendar') {
         $actionsRight .= $form;
     }
     $toolbar = Display::toolbarAction('toolbar-agenda', array(0 => $actionsLeft, 1 => $actionsRight), 2, false);
     return $toolbar;
 }
Exemplo n.º 5
0
<?php

/* For licensing terms, see /license.txt */
/**
 * View (MVC patter) for attendance sheet (list, edit, add)
 * @author Christian Fasanando <*****@*****.**>
 * @author Julio Montoya reworked 2010
 * @package chamilo.attendance
 */
// Protect a course script
api_protect_course_script(true);
$isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(api_get_user_id(), api_get_course_info());
if (api_is_allowed_to_edit(null, true) || api_is_coach(api_get_session_id(), api_get_course_int_id()) || $isDrhOfCourse) {
    $groupId = isset($_REQUEST['group_id']) ? intval($_REQUEST['group_id']) : null;
    $form = new FormValidator('filter', 'post', 'index.php?action=attendance_sheet_list&' . api_get_cidreq() . '&attendance_id=' . $attendance_id, null, array(), 'inline');
    $values = array('all' => get_lang('All'), 'today' => get_lang('Today'), 'all_done' => get_lang('AllDone'), 'all_not_done' => get_lang('AllNotDone'));
    $today = api_convert_and_format_date(null, DATE_FORMAT_SHORT);
    $exists_attendance_today = false;
    if (!empty($attendant_calendar_all)) {
        $values[''] = '---------------';
        foreach ($attendant_calendar_all as $attendance_date) {
            $includeCalendar = true;
            if (isset($attendance_date['groups']) && !empty($groupId)) {
                foreach ($attendance_date['groups'] as $group) {
                    if ($groupId == $group['group_id']) {
                        $includeCalendar = true;
                        break;
                    } else {
                        $includeCalendar = false;
                    }
                }
Exemplo n.º 6
0
/**
 * @param array $session_info
 * @param string $course_code
 * @param bool $ignore_visibility_for_admins
 * @param bool $check_coach_dates
 * @return bool
 */
function api_get_session_date_validation($session_info, $course_code, $ignore_visibility_for_admins = true, $check_coach_dates = true)
{
    if (api_is_platform_admin()) {
        if ($ignore_visibility_for_admins) {
            return true;
        }
    }
    $session_id = $session_info['id'];
    $now = time();
    $access = false;
    if ($session_info) {
        // I don't care the field visibility because there are not limit dates.
        if (empty($session_info['access_start_date']) && empty($session_info['access_end_date']) || $session_info['access_start_date'] == '0000-00-00 00:00:00' && $session_info['access_end_date'] == '0000-00-00 00:00:00') {
            return true;
        } else {
            $accessStart = true;
            // If access_start_date is set
            if (!empty($session_info['access_start_date']) && $session_info['access_start_date'] != '0000-00-00 00:00:00') {
                if ($now > api_strtotime($session_info['access_start_date'], 'UTC')) {
                    $access = true;
                } else {
                    $access = false;
                    $accessStart = false;
                }
            }
            if ($accessStart == true) {
                //if access_end_date is set
                if (!empty($session_info['access_end_date']) && $session_info['access_end_date'] != '0000-00-00 00:00:00') {
                    //only if access_end_date said that it was ok
                    if ($now <= api_strtotime($session_info['access_end_date'], 'UTC')) {
                        //date still available
                        $access = true;
                    } else {
                        //session ends
                        $access = false;
                    }
                }
            }
        }
        if ($check_coach_dates) {
            //2. If I'm a coach
            $is_coach = api_is_coach($session_id, $course_code);
            if ($is_coach) {
                if (isset($session_info['access_end_date']) && !empty($session_info['access_end_date']) && $session_info['access_end_date'] != '0000-00-00 00:00:00' && isset($session_info['coach_access_end_date']) && !empty($session_info['coach_access_end_date']) && $session_info['coach_access_end_date'] != '0000-00-00 00:00:00') {
                    $end_date_extra_for_coach = api_strtotime($session_info['coach_access_end_date'], 'UTC');
                    if ($now <= $end_date_extra_for_coach) {
                        $access = true;
                    } else {
                        $access = false;
                    }
                }
                //Test start date
                if (isset($session_info['access_start_date']) && !empty($session_info['access_start_date']) && $session_info['access_start_date'] != '0000-00-00 00:00:00' && isset($session_info['coach_start_date']) && !empty($session_info['coach_start_date']) && $session_info['coach_start_date'] != '0000-00-00 00:00:00') {
                    $start_date_for_coach = api_strtotime($session_info['coach_start_date'], 'UTC');
                    if ($now > $start_date_for_coach) {
                        $access = true;
                    } else {
                        $access = false;
                    }
                }
            }
        }
        return $access;
    }
}
 /**
  * It's used for controlling attendance sheet (list, add),
  * render to attendance_sheet view
  * @param string $action
  * @param int    $attendance_id
  * @param int    $student_id
  * @param bool   $edit
  */
 public function attendance_sheet($action, $attendance_id, $student_id = 0, $edit = true)
 {
     $attendance = new Attendance();
     $data = array();
     $data['attendance_id'] = $attendance_id;
     $groupId = isset($_REQUEST['group_id']) ? $_REQUEST['group_id'] : null;
     $data['users_in_course'] = $attendance->get_users_rel_course($attendance_id, $groupId);
     $filter_type = 'today';
     if (!empty($_REQUEST['filter'])) {
         $filter_type = $_REQUEST['filter'];
     }
     $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(api_get_user_id(), api_get_course_info());
     if ($edit == true) {
         if (api_is_allowed_to_edit(null, true) || $isDrhOfCourse) {
             $data['users_presence'] = $attendance->get_users_attendance_sheet($attendance_id, 0, $groupId);
         }
     } else {
         if (!empty($student_id)) {
             $user_id = intval($student_id);
         } else {
             $user_id = api_get_user_id();
         }
         if (api_is_allowed_to_edit(null, true) || api_is_coach(api_get_session_id(), api_get_course_int_id()) || $isDrhOfCourse) {
             $data['users_presence'] = $attendance->get_users_attendance_sheet($attendance_id, 0, $groupId);
         } else {
             $data['users_presence'] = $attendance->get_users_attendance_sheet($attendance_id, $user_id, $groupId);
         }
         $data['faults'] = $attendance->get_faults_of_user($user_id, $attendance_id, $groupId);
         $data['user_id'] = $user_id;
     }
     $data['next_attendance_calendar_id'] = $attendance->get_next_attendance_calendar_id($attendance_id);
     $data['next_attendance_calendar_datetime'] = $attendance->get_next_attendance_calendar_datetime($attendance_id);
     if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
         if (isset($_POST['hidden_input'])) {
             foreach ($_POST['hidden_input'] as $cal_id) {
                 $users_present = array();
                 if (isset($_POST['check_presence'][$cal_id])) {
                     $users_present = $_POST['check_presence'][$cal_id];
                 }
                 $attendance->attendance_sheet_add($cal_id, $users_present, $attendance_id);
             }
         }
         $data['users_in_course'] = $attendance->get_users_rel_course($attendance_id, $groupId);
         $my_calendar_id = null;
         if (is_numeric($filter_type)) {
             $my_calendar_id = $filter_type;
             $filter_type = 'calendar_id';
         }
         $data['attendant_calendar'] = $attendance->get_attendance_calendar($attendance_id, $filter_type, $my_calendar_id, $groupId);
         $data['attendant_calendar_all'] = $attendance->get_attendance_calendar($attendance_id, 'all', null, $groupId);
         $data['users_presence'] = $attendance->get_users_attendance_sheet($attendance_id, 0, $groupId);
         $data['next_attendance_calendar_id'] = $attendance->get_next_attendance_calendar_id($attendance_id);
         $data['next_attendance_calendar_datetime'] = $attendance->get_next_attendance_calendar_datetime($attendance_id);
     } else {
         $data['attendant_calendar_all'] = $attendance->get_attendance_calendar($attendance_id, 'all', null, $groupId);
         $data['attendant_calendar'] = $attendance->get_attendance_calendar($attendance_id, $filter_type, null, $groupId);
     }
     $data['edit_table'] = intval($edit);
     $data['is_locked_attendance'] = $attendance->is_locked_attendance($attendance_id);
     $this->view->set_data($data);
     $this->view->set_layout('layout');
     $this->view->set_template('attendance_sheet');
     $this->view->render();
 }
Exemplo n.º 8
0
/**
 * @param int $start
 * @param int $limit
 * @param int $column
 * @param string $direction
 * @param int $work_id
 * @param array $where_condition
 * @param int $studentId
 * @param bool $getCount
 * @return array
 */
function get_work_user_list(
    $start,
    $limit,
    $column,
    $direction,
    $work_id,
    $where_condition = null,
    $studentId = null,
    $getCount = false
) {
    $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
    $iprop_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
    $user_table = Database::get_main_table(TABLE_MAIN_USER);

    $session_id = api_get_session_id();
    $course_id = api_get_course_int_id();
    $group_id = api_get_group_id();
    $course_info = api_get_course_info(api_get_course_id());

    $work_id = intval($work_id);
    $column = !empty($column) ? Database::escape_string($column) : 'sent_date';
    $start = intval($start);
    $limit = intval($limit);

    if (!in_array($direction, array('asc','desc'))) {
        $direction = 'desc';
    }

    $work_data = get_work_data_by_id($work_id);
    $is_allowed_to_edit = api_is_allowed_to_edit() || api_is_coach();
    $condition_session  = api_get_session_condition($session_id);
    $locked = api_resource_is_locked_by_gradebook($work_id, LINK_STUDENTPUBLICATION);

    $isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
        api_get_user_id(),
        $course_info
    );

    if (!empty($work_data)) {
        if (!empty($group_id)) {
            $extra_conditions = " work.post_group_id = '".intval($group_id)."' ";
            // set to select only messages posted by the user's group
        } else {
            $extra_conditions = " work.post_group_id = '0' ";
        }

        if ($is_allowed_to_edit || $isDrhOfCourse) {
            $extra_conditions .= ' AND work.active IN (0, 1) ';
        } else {
            if (isset($course_info['show_score']) &&
                $course_info['show_score'] == 1
            ) {
                $extra_conditions .= " AND (u.user_id = ".api_get_user_id()." AND work.active IN (0, 1)) ";
            } else {
                $extra_conditions .= ' AND work.active IN (0, 1) ';
            }
        }

        $extra_conditions .= " AND parent_id  = ".$work_id." ";

        $select = 'SELECT DISTINCT
                        u.user_id,
                        work.id as id,
                        title as title,
                        description,
                        url,
                        sent_date,
                        contains_file,
                        has_properties,
                        view_properties,
                        qualification,
                        weight,
                        allow_text_assignment,
                        u.firstname,
                        u.lastname,
                        u.username,
                        parent_id,
                        accepted,
                        qualificator_id';
        if ($getCount) {
            $select = "SELECT DISTINCT count(u.user_id) as count ";
        }

        $user_condition = "INNER JOIN $user_table u  ON (work.user_id = u.user_id) ";
        $work_condition = "$iprop_table prop INNER JOIN $work_table work
                           ON (prop.ref = work.id AND prop.c_id = $course_id AND work.c_id = $course_id ) ";

        $work_assignment = get_work_assignment_by_id($work_id);

        if (!empty($studentId)) {
            $where_condition.= " AND u.user_id = ".intval($studentId);
        }

        $sql = " $select
                FROM $work_condition  $user_condition
                WHERE $extra_conditions $where_condition $condition_session
                ORDER BY $column $direction";

        if (!empty($start) && !empty($limit)) {
            $sql .= " LIMIT $start, $limit";
        }
        $result = Database::query($sql);
        $works = array();

        if ($getCount) {
            $work = Database::fetch_array($result, 'ASSOC');
            return $work['count'];
        }

        $url = api_get_path(WEB_CODE_PATH).'work/';

        while ($work = Database::fetch_array($result, 'ASSOC')) {
            $item_id = $work['id'];

            // Get the author ID for that document from the item_property table
            $is_author  = false;
            $can_read   = false;

            $owner_id = $work['user_id'];

            /* Because a bug found when saving items using the api_item_property_update()
               the field $item_property_data['insert_user_id'] is not reliable. */

            if (!$is_allowed_to_edit && $owner_id == api_get_user_id()) {
                $is_author = true;
            }

            if ($course_info['show_score'] == 0) {
                $can_read = true;
            }

            if ($work['accepted'] == '0') {
                $class = 'invisible';
            } else {
                $class = '';
            }

            $qualification_exists = false;
            if (!empty($work_data['qualification']) &&
                intval($work_data['qualification']) > 0
            ) {
                $qualification_exists = true;
            }

            $qualification_string = '';
            if ($qualification_exists) {
                if ($work['qualification'] == '') {
                    $qualification_string = Display::label('-');
                } else {
                    $label = 'info';
                    $relativeScore = $work['qualification']/$work_data['qualification'];
                    if ($relativeScore < 0.5) {
                        $label = 'important';
                    } elseif ($relativeScore < 0.75) {
                        $label = 'warning';
                    }
                    $qualification_string = Display::label(
                        $work['qualification'].' / '.$work_data['qualification'],
                        $label
                    );
                }
            }

            $work['qualification_score'] = $work['qualification'];

            $add_string = '';
            $time_expires = api_strtotime($work_assignment['expires_on'], 'UTC');

            if (!empty($work_assignment['expires_on']) &&
                $work_assignment['expires_on'] != '0000-00-00 00:00:00' &&
                $time_expires && ($time_expires < api_strtotime($work['sent_date'], 'UTC'))) {
                $add_string = Display::label(get_lang('Expired'), 'important');
            }

            if (($can_read && $work['accepted'] == '1') ||
                ($is_author && in_array($work['accepted'], array('1', '0'))) ||
                ($is_allowed_to_edit || api_is_drh())
            ) {
                // Firstname, lastname, username
                $work['firstname'] = Display::div($work['firstname'], array('class' => $class));
                $work['lastname'] = Display::div($work['lastname'], array('class' => $class));

                if (strlen($work['title']) > 30) {
                    $short_title = substr($work['title'], 0, 27).'...';
                    $work['title'] = Display::span($short_title, array('class' => $class, 'title' => $work['title']));
                } else {
                    $work['title'] = Display::div($work['title'], array('class' => $class));
                }

                // Type.
                $work['type'] = build_document_icon_tag('file', $work['url']);

                // File name.
                $link_to_download = null;

                // If URL is present then there's a file to download keep BC.
                if ($work['contains_file'] || !empty($work['url'])) {
                    $link_to_download = '<a href="'.$url.'download.php?id='.$item_id.'&'.api_get_cidreq().'">'.
                        Display::return_icon('save.png', get_lang('Save'),array(), ICON_SIZE_SMALL).'</a> ';
                }

                $send_to = Portfolio::share('work', $work['id'],  array('style' => 'white-space:nowrap;'));

                $feedback = null;
                $count = getWorkCommentCount($item_id, $course_info);
                if (!is_null($count) && !empty($count)) {
                    if ($qualification_exists) {
                        $feedback .= "<br />";
                    }
                    $feedback .= '<a href="'.$url.'view.php?'.api_get_cidreq().'&id='.$item_id.'" title="'.get_lang('View').'">'.
                        Display::label($count.' '.get_lang('Feedback'), 'info').'</a> ';
                }

                $work['qualification'] = $qualification_string.$feedback;
                $work['qualification_only'] = $qualification_string;

                // Date.
                $work_date = api_convert_and_format_date($work['sent_date']);

                $work['sent_date_from_db'] = $work['sent_date'];
                $work['sent_date'] = date_to_str_ago(api_get_local_time($work['sent_date'])) . ' ' . $add_string . '<br />' . $work_date;

                // Actions.

                $action = '';
                if (api_is_allowed_to_edit()) {
                    $action .= '<a href="'.$url.'view.php?'.api_get_cidreq().'&id='.$item_id.'" title="'.get_lang('View').'">'.
                        Display::return_icon('default.png', get_lang('View'),array(), ICON_SIZE_SMALL).'</a> ';

                    if ($locked) {
                        if ($qualification_exists) {
                            $action .= Display::return_icon('rate_work_na.png', get_lang('CorrectAndRate'),array(), ICON_SIZE_SMALL);
                        } else {
                            $action .= Display::return_icon('edit_na.png', get_lang('Comment'),array(), ICON_SIZE_SMALL);
                        }
                    } else {
                        if ($qualification_exists) {
                            $action .= '<a href="'.$url.'edit.php?'.api_get_cidreq().'&item_id='.$item_id.'&id='.$work['parent_id'].'" title="'.get_lang('Edit').'"  >'.
                                Display::return_icon('rate_work.png', get_lang('CorrectAndRate'), array(), ICON_SIZE_SMALL).'</a>';
                        } else {
                            $action .= '<a href="'.$url.'edit.php?'.api_get_cidreq().'&item_id='.$item_id.'&id='.$work['parent_id'].'" title="'.get_lang('Modify').'">'.
                                Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>';
                        }
                    }

                    if ($work['contains_file']) {
                        if ($locked) {
                            $action .= Display::return_icon('move_na.png', get_lang('Move'),array(), ICON_SIZE_SMALL);
                        } else {
                            $action .= '<a href="'.$url.'work.php?'.api_get_cidreq().'&action=move&item_id='.$item_id.'" title="'.get_lang('Move').'">'.
                                Display::return_icon('move.png', get_lang('Move'),array(), ICON_SIZE_SMALL).'</a>';
                        }
                    }

                    if ($work['accepted'] == '1') {
                        $action .= '<a href="'.$url.'work_list_all.php?'.api_get_cidreq().'&id='.$work_id.'&action=make_invisible&item_id='.$item_id.'" title="'.get_lang('Invisible').'" >'.
                            Display::return_icon('visible.png', get_lang('Invisible'),array(), ICON_SIZE_SMALL).'</a>';
                    } else {
                        $action .= '<a href="'.$url.'work_list_all.php?'.api_get_cidreq().'&id='.$work_id.'&action=make_visible&item_id='.$item_id.'" title="'.get_lang('Visible').'" >'.
                            Display::return_icon('invisible.png', get_lang('Visible'),array(), ICON_SIZE_SMALL).'</a> ';
                    }

                    if ($locked) {
                        $action .= Display::return_icon('delete_na.png', get_lang('Delete'), '', ICON_SIZE_SMALL);
                    } else {
                        $action .= '<a href="'.$url.'work_list_all.php?'.api_get_cidreq().'&id='.$work_id.'&action=delete&amp;item_id='.$item_id.'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES))."'".')) return false;" title="'.get_lang('Delete').'" >'.
                            Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>';
                    }
                } elseif ($is_author && (empty($work['qualificator_id']) || $work['qualificator_id'] == 0)) {
                    $action .= '<a href="'.$url.'view.php?'.api_get_cidreq().'&id='.$item_id.'" title="'.get_lang('View').'">'.
                        Display::return_icon('default.png', get_lang('View'),array(), ICON_SIZE_SMALL).'</a>';

                    if (api_get_course_setting('student_delete_own_publication') == 1) {
                        if (api_is_allowed_to_session_edit(false, true)) {
                            $action .= '<a href="'.$url.'edit.php?'.api_get_cidreq().'&item_id='.$item_id.'&id='.$work['parent_id'].'" title="'.get_lang('Modify').'">'.
                                Display::return_icon('edit.png', get_lang('Comment'),array(), ICON_SIZE_SMALL).'</a>';
                        }
                        $action .= ' <a href="'.$url.'work_list.php?'.api_get_cidreq().'&action=delete&item_id='.$item_id.'&id='.$work['parent_id'].'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES))."'".')) return false;" title="'.get_lang('Delete').'"  >'.
                            Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>';
                    } else {
                        $action .= Display::return_icon('edit_na.png', get_lang('Modify'),array(), ICON_SIZE_SMALL);
                    }
                } else {
                    $action .= '<a href="'.$url.'view.php?'.api_get_cidreq().'&id='.$item_id.'" title="'.get_lang('View').'">'.
                        Display::return_icon('default.png', get_lang('View'),array(), ICON_SIZE_SMALL).'</a>';
                    $action .= Display::return_icon('edit_na.png', get_lang('Modify'),array(), ICON_SIZE_SMALL);
                }

                // Status.
                if (empty($work['qualificator_id'])) {
                    $qualificator_id = Display::label(get_lang('NotRevised'), 'warning');
                } else {
                    $qualificator_id = Display::label(get_lang('Revised'), 'success');
                }
                $work['qualificator_id'] = $qualificator_id;
                $work['actions'] = $send_to.$link_to_download.$action;
                $works[] = $work;
            }
        }
        return $works;
    }
}
Exemplo n.º 9
0
} else {
    if ($is_allowedToEdit) {
        // the form
        if (api_is_platform_admin() || api_is_course_admin() || api_is_course_tutor() || api_is_course_coach()) {
            // @todo check if $path is used
            $path = isset($_GET['path']) ? Security::remove_XSS($_GET['path']) : null;
            $actions .= '<a href="admin.php?exerciseId=' . intval($_GET['exerciseId']) . '">' . Display::return_icon('back.png', get_lang('GoBackToQuestionList'), '', ICON_SIZE_MEDIUM) . '</a>';
            $actions .= '<a href="live_stats.php?' . api_get_cidreq() . '&exerciseId=' . $exercise_id . '">' . Display::return_icon('activity_monitor.png', get_lang('LiveResults'), '', ICON_SIZE_MEDIUM) . '</a>';
            $actions .= '<a href="stats.php?' . api_get_cidreq() . '&exerciseId=' . $exercise_id . '">' . Display::return_icon('statistics.png', get_lang('ReportByQuestion'), '', ICON_SIZE_MEDIUM) . '</a>';
            $actions .= '<a id="export_opener" href="' . api_get_self() . '?export_report=1&hotpotato_name=' . $path . '&exerciseId=' . intval($_GET['exerciseId']) . '" >' . Display::return_icon('save.png', get_lang('Export'), '', ICON_SIZE_MEDIUM) . '</a>';
            $actions .= '<a href="recalculate_scores.php?' . api_get_cidreq() . '&exerciseId=' . $exercise_id . '">' . Display::return_icon('history.png', get_lang('RecalculateResults'), '', ICON_SIZE_MEDIUM) . '</a>';
        }
    }
}
//Deleting an attempt
if (($is_allowedToEdit || $is_tutor || api_is_coach()) && isset($_GET['delete']) && $_GET['delete'] == 'delete' && !empty($_GET['did']) && $locked == false) {
    $exe_id = intval($_GET['did']);
    if (!empty($exe_id)) {
        $sql = 'DELETE FROM ' . $TBL_TRACK_EXERCICES . ' WHERE exe_id = ' . $exe_id;
        Database::query($sql);
        $sql = 'DELETE FROM ' . $TBL_TRACK_ATTEMPT . ' WHERE exe_id = ' . $exe_id;
        Database::query($sql);
        header('Location: exercise_report.php?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&exerciseId=' . $exercise_id);
        exit;
    }
}
if ($is_allowedToEdit || $is_tutor) {
    $nameTools = get_lang('StudentScore');
    $interbreadcrumb[] = array("url" => "exercice.php?gradebook={$gradebook}", "name" => get_lang('Exercices'));
    $objExerciseTmp = new Exercise();
    if ($objExerciseTmp->read($exercise_id)) {
Exemplo n.º 10
0
/**
 * Function that removes the need to directly use is_courseAdmin global in
 * tool scripts. It returns true or false depending on the user's rights in
 * this particular course.
 * Optionally checking for tutor and coach roles here allows us to use the
 * student_view feature altogether with these roles as well.
 * @param bool  Whether to check if the user has the tutor role
 * @param bool  Whether to check if the user has the coach role
 * @param bool  Whether to check if the user has the session coach role
 * @param bool  check the student view or not
 *
 * @author Roan Embrechts
 * @author Patrick Cool
 * @version 1.1, February 2004
 * @return boolean, true: the user has the rights to edit, false: he does not
 */
function api_is_allowed_to_edit($tutor = false, $coach = false, $session_coach = false, $check_student_view = true)
{
    $my_session_id = api_get_session_id();
    $is_allowed_coach_to_edit = api_is_coach();
    $session_visibility = api_get_session_visibility($my_session_id);
    // Admins can edit anything.
    if (api_is_platform_admin(false)) {
        $studentView = Session::read('studentview');
        // The student preview was on.
        if ($check_student_view && $studentView == "studentview") {
            return false;
        } else {
            return true;
        }
    }
    $is_courseAdmin = api_is_course_admin();
    if (!$is_courseAdmin && $tutor) {
        // If we also want to check if the user is a tutor...
        $is_courseAdmin = $is_courseAdmin || api_is_course_tutor();
    }
    if (!$is_courseAdmin && $coach) {
        // If we also want to check if the user is a coach...';
        // Check if session visibility is read only for coaches.
        if ($session_visibility == SESSION_VISIBLE_READ_ONLY) {
            $is_allowed_coach_to_edit = false;
        }
        if (api_get_setting('allow_coach_to_edit_course_session') == 'true') {
            // Check if coach is allowed to edit a course.
            $is_courseAdmin = $is_courseAdmin || $is_allowed_coach_to_edit;
        } else {
            $is_courseAdmin = $is_courseAdmin;
        }
    }
    if (!$is_courseAdmin && $session_coach) {
        $is_courseAdmin = $is_courseAdmin || api_is_coach();
    }
    // Check if the student_view is enabled, and if so, if it is activated.
    if (api_get_setting('course.student_view_enabled') == 'true') {
        $studentViewSession = Session::read('studentview');
        if (!empty($my_session_id)) {
            // Check if session visibility is read only for coachs
            if ($session_visibility == SESSION_VISIBLE_READ_ONLY) {
                $is_allowed_coach_to_edit = false;
            }
            if (api_get_setting('allow_coach_to_edit_course_session') == 'true') {
                // Check if coach is allowed to edit a course.
                $is_allowed = $is_allowed_coach_to_edit;
            } else {
                $is_allowed = false;
            }
            if ($check_student_view) {
                $is_allowed = $is_allowed && $studentViewSession != 'studentview';
            }
        } else {
            if ($check_student_view) {
                $is_allowed = $is_courseAdmin && $studentViewSession != 'studentview';
            } else {
                $is_allowed = $is_courseAdmin;
            }
        }
        return $is_allowed;
    } else {
        return $is_courseAdmin;
    }
}
Exemplo n.º 11
0
// resetting the course id
$cidReset = true;
require_once '../inc/global.inc.php';
$htmlHeadXtra[] = api_get_jqgrid_js();
// the section (for the tabs)
$this_section = SECTION_TRACKING;
//for HTML editor repository
unset($_SESSION['this_section']);
ob_start();
$export_csv = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
$display = isset($_GET['display']) ? Security::remove_XSS($_GET['display']) : null;
$csv_content = array();
$nameTools = get_lang('MySpace');
$user_id = api_get_user_id();
$session_id = isset($_GET['session_id']) ? intval($_GET['session_id']) : 0;
$is_coach = api_is_coach($session_id);
$is_platform_admin = api_is_platform_admin();
$is_drh = api_is_drh();
$is_session_admin = api_is_session_admin();
$count_sessions = 0;
$count_courses = 0;
$title = null;
// Access control
api_block_anonymous_users();
if (!$export_csv) {
    Display::display_header($nameTools);
}
// Database table definitions
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$tbl_sessions = Database::get_main_table(TABLE_MAIN_SESSION);
$tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
 * @author Julio Montoya <*****@*****.**> Lots of bug fixes/improvements
 * @author Angel Fernando Quiroz Campos <*****@*****.**> Code conventions
 * @package chamilo.backup
 */
//require_once '../inc/global.inc.php';
$current_course_tool = TOOL_COURSE_MAINTENANCE;
api_protect_course_script(true, true);
require_once 'classes/CourseBuilder.class.php';
require_once 'classes/CourseRestorer.class.php';
require_once 'classes/CourseSelectForm.class.php';
$xajax = new xajax();
$xajax->registerFunction('searchCourses');
if (!api_is_allowed_to_edit()) {
    api_not_allowed(true);
}
if (!api_is_coach()) {
    api_not_allowed(true);
}
$courseId = api_get_course_int_id();
$courseInfo = api_get_course_info_by_id($courseId);
$courseCode = $courseInfo['code'];
$sessionId = api_get_session_id();
if (empty($courseCode) or empty($sessionId)) {
    api_not_allowed(true);
}
// Remove memory and time limits as much as possible as this might be a long process...
if (function_exists('ini_set')) {
    ini_set('memory_limit', '256M');
    ini_set('max_execution_time', 1800);
}
$this_section = SECTION_COURSES;
Exemplo n.º 13
0
 /**
  * @return array
  */
 private function renderActivityView()
 {
     $session_id = api_get_session_id();
     $urlGenerator = $this->get('router');
     $content = null;
     // Start of tools for CourseAdmins (teachers/tutors)
     $totalList = array();
     if ($session_id == 0 && api_is_course_admin() && api_is_allowed_to_edit(null, true)) {
         $list = CourseHome::get_tools_category(TOOL_AUTHORING);
         $result = CourseHome::show_tools_category($urlGenerator, $list);
         $content .= $this->return_block(get_lang('Authoring'), $result['content']);
         $totalList = $result['tool_list'];
         $list = CourseHome::get_tools_category(TOOL_INTERACTION);
         $list2 = CourseHome::get_tools_category(TOOL_COURSE_PLUGIN);
         $list = array_merge($list, $list2);
         $result = CourseHome::show_tools_category($urlGenerator, $list);
         $totalList = array_merge($totalList, $result['tool_list']);
         $content .= $this->return_block(get_lang('Interaction'), $result['content']);
         $list = CourseHome::get_tools_category(TOOL_ADMIN_PLATFORM);
         $totalList = array_merge($totalList, $list);
         $result = CourseHome::show_tools_category($urlGenerator, $list);
         $totalList = array_merge($totalList, $result['tool_list']);
         $content .= $this->return_block(get_lang('Administration'), $result['content']);
     } elseif (api_is_coach()) {
         $content .= '<div class="row">';
         $list = CourseHome::get_tools_category(TOOL_STUDENT_VIEW);
         $content .= CourseHome::show_tools_category($urlGenerator, $result['content']);
         $totalList = array_merge($totalList, $result['tool_list']);
         $content .= '</div>';
     } else {
         $list = CourseHome::get_tools_category(TOOL_STUDENT_VIEW);
         if (count($list) > 0) {
             $content .= '<div class="row">';
             $result = CourseHome::show_tools_category($urlGenerator, $list);
             $content .= $result['content'];
             $totalList = array_merge($totalList, $result['tool_list']);
             $content .= '</div>';
         }
     }
     return array('content' => $content, 'tool_list' => $totalList);
 }
Exemplo n.º 14
0
 /**
  * Displays the tools of a certain category.
  * @param Symfony\Component\Routing\RouterInterface $urlGenerator
  * @param array List of tools as returned by get_tools_category()
  * @param bool rows
  * @return string
  */
 public static function show_tools_category($urlGenerator, $toolList, $rows = false)
 {
     $rowDiv = '<div class="row">';
     $theme = api_get_setting('homepage_view');
     if ($theme == 'vertical_activity') {
         //ordering by get_lang name
         $order_tool_list = array();
         if (is_array($toolList) && count($toolList) > 0) {
             foreach ($toolList as $key => $new_tool) {
                 $tool_name = self::translate_tool_name($new_tool);
                 $order_tool_list[$key] = $tool_name;
             }
             natsort($order_tool_list);
             $my_temp_tool_array = array();
             foreach ($order_tool_list as $key => $new_tool) {
                 $my_temp_tool_array[] = $toolList[$key];
             }
             $toolList = $my_temp_tool_array;
         } else {
             $toolList = array();
         }
     }
     $courseInfo = api_get_course_info();
     $web_code_path = api_get_path(WEB_CODE_PATH);
     $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
     $is_platform_admin = api_is_platform_admin();
     $session_id = api_get_session_id();
     $items = array();
     $app_plugin = new AppPlugin();
     if (isset($toolList)) {
         $lnk = '';
         foreach ($toolList as &$tool) {
             $item = array();
             $tool['admin'] = isset($tool['admin']) ? $tool['admin'] : null;
             $tool['id'] = isset($tool['id']) ? $tool['id'] : null;
             $tool['target'] = isset($tool['target']) ? $tool['target'] : null;
             if (isset($tool['link_id'])) {
                 $tool['original_link'] = api_get_path(WEB_CODE_PATH) . 'link/link_goto.php?link_id=' . $tool['link_id'] . '&' . api_get_cidreq();
                 $tool['link'] = $tool['original_link'];
             } else {
                 $tool['original_link'] = $tool['link'];
             }
             // Re-writing URL for new tools
             $newTools = array(TOOL_CURRICULUM);
             $toolName = isset($tool['name']) ? $tool['name'] : null;
             if (in_array($toolName, $newTools)) {
                 $tool['link'] = $courseInfo['course_web_public_url'] . $tool['name'] . '/';
             }
             if ($tool['image'] == 'scormbuilder.gif') {
                 // Check if the published learnpath is visible for student
                 $published_lp_id = self::get_published_lp_id_from_link($tool['link']);
                 if (!api_is_allowed_to_edit(null, true) && !learnpath::is_lp_visible_for_student($published_lp_id, api_get_user_id())) {
                     continue;
                 }
             }
             if ($session_id != 0 && in_array($tool['name'], array('course_maintenance', 'course_setting'))) {
                 continue;
             }
             if ($tool['name'] == 'course_description') {
                 $tool['link'] = 'course_description/index.php';
             }
             // This part displays the links to hide or remove a tool.
             // These links are only visible by the course manager.
             unset($lnk);
             $item['extra'] = null;
             if ($is_allowed_to_edit && !api_is_coach()) {
                 if (empty($session_id)) {
                     if ($tool['visibility'] == '1' && $tool['admin'] != '1') {
                         $link['name'] = Display::return_icon('visible.gif', get_lang('Deactivate'), array('id' => 'linktool_' . $tool['id']), ICON_SIZE_MEDIUM, false);
                         if (!empty($tool['id'])) {
                             $link['cmd'] = $urlGenerator->generate('course_home.controller:hideIconAction', array('course' => api_get_course_id(), 'iconId' => $tool['id']));
                         }
                         $lnk[] = $link;
                     }
                     if ($tool['visibility'] == '0' && $tool['admin'] != '1') {
                         $link['name'] = Display::return_icon('invisible.gif', get_lang('Activate'), array('id' => 'linktool_' . $tool['id']), ICON_SIZE_MEDIUM, false);
                         if (!empty($tool['id'])) {
                             $link['cmd'] = $urlGenerator->generate('course_home.controller:showIconAction', array('course' => api_get_course_id(), 'iconId' => $tool['id']));
                         }
                         $lnk[] = $link;
                     }
                 }
                 if (!empty($tool['adminlink'])) {
                     $item['extra'] = '<a href="' . $tool['adminlink'] . '">' . Display::return_icon('edit.gif', get_lang('Edit')) . '</a>';
                 }
             }
             // Both checks are necessary as is_platform_admin doesn't take student view into account
             if ($is_platform_admin && $is_allowed_to_edit) {
                 if ($tool['admin'] != '1') {
                     $link['cmd'] = 'hide=yes';
                 }
             }
             $item['visibility'] = null;
             if (isset($lnk) && is_array($lnk)) {
                 foreach ($lnk as $this_link) {
                     if (empty($tool['adminlink'])) {
                         $item['visibility'] .= '<a class="make_visible_and_invisible" href="' . $this_link['cmd'] . '">' . $this_link['name'] . '</a>';
                     }
                 }
             } else {
                 $item['visibility'] .= null;
             }
             // NOTE : Table contains only the image file name, not full path
             if (stripos($tool['link'], 'http://') === false && stripos($tool['link'], 'https://') === false && stripos($tool['link'], 'ftp://') === false) {
                 $tool['link'] = $web_code_path . $tool['link'];
             }
             if (!empty($tool['custom_icon'])) {
                 $tool['image'] = self::getCustomIconPath($courseInfo) . $tool['custom_icon'];
             }
             if ($tool['visibility'] == '0' && $tool['admin'] != '1') {
                 $class = 'invisible';
                 $info = pathinfo($tool['image']);
                 $dirName = null;
                 if ($info['dirname'] != '.') {
                     $dirName = $info['dirname'] . '/';
                 }
                 $basename = basename($tool['image'], '.' . $info['extension']);
                 // $file is set to "index"
                 $tool['image'] = $dirName . $basename . '_na.' . $info['extension'];
             } else {
                 $class = '';
             }
             $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&';
             // If it's a link, we don't add the cidReq
             if ($tool['image'] == 'file_html.gif' || $tool['image'] == 'file_html_na.gif') {
                 $tool['link'] = $tool['link'] . $qm_or_amp;
             } else {
                 $tool['link'] = $tool['link'] . $qm_or_amp . api_get_cidreq();
             }
             $tool_link_params = array();
             //@todo this visio stuff should be removed
             if (strpos($tool['name'], 'visio_') !== false) {
                 $tool_link_params = array('id' => 'tooldesc_' . $tool["id"], 'href' => '"javascript: void(0);"', 'class' => $class, 'onclick' => 'javascript: window.open(\'' . $tool['link'] . '\',\'window_visio' . $_SESSION['_cid'] . '\',config=\'height=\'+730+\', width=\'+1020+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')', 'target' => $tool['target']);
             } elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) {
                 $tool_link_params = array('id' => 'tooldesc_' . $tool["id"], 'class' => $class, 'href' => 'javascript: void(0);', 'onclick' => 'javascript: window.open(\'' . $tool['link'] . '\',\'window_chat' . $_SESSION['_cid'] . '\',config=\'height=\'+380+\', width=\'+625+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')', 'target' => $tool['target']);
             } else {
                 if (count(explode('type=classroom', $tool['link'])) == 2 || count(explode('type=conference', $tool['link'])) == 2) {
                     $tool_link_params = array('id' => 'tooldesc_' . $tool["id"], 'href' => $tool['link'], 'class' => $class, 'target' => '_blank');
                 } else {
                     $tool_link_params = array('id' => 'tooldesc_' . $tool["id"], 'href' => $tool['link'], 'class' => $class, 'target' => $tool['target']);
                 }
             }
             $tool_name = self::translate_tool_name($tool);
             $toolTip = $tool_name;
             if (!empty($tool['description'])) {
                 $toolTip = $tool['description'];
             }
             $tool_link_params['data-original-title'] = $toolTip;
             $tool_link_params['data-toggle'] = 'tooltip';
             //$tool_link_params['title'] = $toolTip;
             // Including Courses Plugins
             // Creating title and the link
             if (isset($tool['category']) && $tool['category'] == 'plugin') {
                 $plugin_info = $app_plugin->get_plugin_info($tool['name']);
                 if (isset($plugin_info) && isset($plugin_info['title'])) {
                     $tool_name = $plugin_info['title'];
                 }
                 $tool_link_params['href'] = api_get_path(WEB_PLUGIN_PATH) . $tool['original_link'] . '?' . api_get_cidreq();
             }
             if (!empty($tool['custom_icon'])) {
                 //self::getCustomIconPath($courseInfo)
                 $icon = Display::img($tool['image'], null, array('class' => 'tool-icon', 'id' => 'toolimage_' . $tool['id']));
             } else {
                 $image = substr($tool['image'], 0, strpos($tool['image'], '.')) . '.png';
                 $icon = Display::return_icon($image, null, array('class' => 'tool-icon', 'id' => 'toolimage_' . $tool['id']), ICON_SIZE_BIG, false);
             }
             $userInfo = api_get_user_info();
             $userStatus = isset($userInfo['status']) ? $userInfo['status'] : null;
             // Validation when belongs to a session
             $session_img = api_get_session_image($tool['session_id'], $userStatus);
             $item['url_params'] = $tool_link_params;
             $item['icon'] = Display::url($icon, $tool_link_params['href'], $tool_link_params);
             $item['tool'] = $tool;
             $item['name'] = $tool_name;
             $tool_link_params['id'] = 'is' . $tool_link_params['id'];
             $item['link'] = Display::url($tool_name . $session_img, $tool_link_params['href'], $tool_link_params);
             $items[] = $item;
         }
         // end of foreach
     }
     $i = 0;
     $html = '';
     $counter = 0;
     if (!empty($items)) {
         foreach ($items as $item) {
             switch ($theme) {
                 case 'activity_big':
                     $data = '';
                     if ($counter == 0) {
                         $html .= $rowDiv;
                     }
                     $html .= '<div class="col-xs-4 col-md-4 course-tool">';
                     $image = substr($item['tool']['image'], 0, strpos($item['tool']['image'], '.')) . '.png';
                     if (!empty($item['tool']['custom_icon'])) {
                         $original_image = Display::img($item['tool']['image'], null, array('id' => 'toolimage_' . $item['tool']['id']));
                     } else {
                         $original_image = Display::return_icon($image, null, array('id' => 'toolimage_' . $item['tool']['id']), ICON_SIZE_BIG, false);
                     }
                     switch ($image) {
                         case 'scormbuilder.png':
                             if (api_is_allowed_to_edit(null, true)) {
                                 $item['url_params']['href'] .= '&isStudentView=true';
                             }
                             $image = $original_image;
                             $lp_id = self::get_published_lp_id_from_link($item['link']);
                             if ($lp_id) {
                                 $lp = new learnpath(api_get_course_id(), $lp_id, api_get_user_id());
                                 $path = $lp->get_preview_image_path(64);
                                 if ($path) {
                                     $image = '<img src="' . $path . '">';
                                 }
                             }
                             break;
                         default:
                             $image = $original_image;
                     }
                     $data .= Display::url($image, $item['url_params']['href'], $item['url_params']);
                     $html .= Display::div($data, array('class' => 'big_icon'));
                     //box-image reflection
                     $html .= Display::div('<h4>' . $item['visibility'] . $item['extra'] . $item['link'] . '</h4>', array('class' => 'content'));
                     $html .= '</div>';
                     if ($counter == 2) {
                         $html .= '</div>';
                         $counter = -1;
                     }
                     $counter++;
                     break;
                 case 'activity':
                     if ($counter == 0) {
                         $html .= $rowDiv;
                     }
                     $html .= '<div class="col-md-6 course-tool">';
                     $content = $item['extra'];
                     $content .= $item['visibility'];
                     $content .= $item['icon'];
                     $content .= $item['link'];
                     $html .= Display::div($content, array('class' => 'activity_content'));
                     $html .= '</div>';
                     if ($counter == 1) {
                         $html .= '</div>';
                         $counter = -1;
                     }
                     $counter++;
                     break;
                 case 'vertical_activity':
                     if ($i == 0) {
                         $html .= '<ul>';
                     }
                     $html .= '<li class="course-tool">';
                     $html .= $item['extra'];
                     $html .= $item['visibility'];
                     $html .= $item['icon'];
                     $html .= $item['link'];
                     $html .= '</li>';
                     if ($i == count($items) - 1) {
                         $html .= '</ul>';
                     }
                     break;
             }
             $i++;
         }
     }
     return array('content' => $html, 'tool_list' => $items);
 }
Exemplo n.º 15
0
        $dirForm = DocumentManager::create_dir_form($document_id);
    }
}
/* 	VISIBILITY COMMANDS */
if ($is_allowed_to_edit) {
    if (isset($_GET['set_invisible']) && !empty($_GET['set_invisible']) || isset($_GET['set_visible']) && !empty($_GET['set_visible'])) {
        // Make visible or invisible?
        if (isset($_GET['set_visible'])) {
            $update_id = intval($_GET['set_visible']);
            $visibility_command = 'visible';
        } else {
            $update_id = intval($_GET['set_invisible']);
            $visibility_command = 'invisible';
        }
        if (!$is_allowed_to_edit) {
            if (api_is_coach()) {
                if (!DocumentManager::is_visible_by_id($update_id, $courseInfo, $sessionId, api_get_user_id())) {
                    api_not_allowed(true);
                }
            }
            if (DocumentManager::check_readonly($courseInfo, api_get_user_id(), '', $update_id)) {
                api_not_allowed(true);
            }
        }
        // Update item_property to change visibility
        if (api_item_property_update($courseInfo, TOOL_DOCUMENT, $update_id, $visibility_command, api_get_user_id(), null, null, null, null, $sessionId)) {
            Display::addFlash(Display::return_message(get_lang('VisibilityChanged'), 'confirmation'));
        } else {
            Display::addFlash(Display::return_message(get_lang('ViModProb'), 'error'));
        }
        header('Location: ' . $currentUrl);
Exemplo n.º 16
0
$interbreadcrumb[] = array('url' => 'work.php', 'name' => get_lang('StudentPublications'));
$my_folder_data = get_work_data_by_id($work['parent_id']);
$courseInfo = api_get_course_info();
protectWork(api_get_course_info(), $work['parent_id']);
$isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(api_get_user_id(), $courseInfo);
if (user_is_author($id) || $isDrhOfCourse || (api_is_allowed_to_edit() || api_is_coach()) || $courseInfo['show_score'] == 0 && $work['active'] == 1 && $work['accepted'] == 1) {
    if (api_is_allowed_to_edit() || api_is_coach() || api_is_drh()) {
        $url_dir = 'work_list_all.php?id=' . $my_folder_data['id'];
    } else {
        $url_dir = 'work_list.php?id=' . $my_folder_data['id'];
    }
    $userInfo = api_get_user_info($work['user_id']);
    $interbreadcrumb[] = array('url' => $url_dir, 'name' => $my_folder_data['title']);
    $interbreadcrumb[] = array('url' => '#', 'name' => $userInfo['complete_name']);
    $interbreadcrumb[] = array('url' => '#', 'name' => $work['title']);
    if ($courseInfo['show_score'] == 0 && $work['active'] == 1 && $work['accepted'] == 1 || (api_is_allowed_to_edit() || api_is_coach()) || user_is_author($id) || $isDrhOfCourse) {
        $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
        $page = isset($_REQUEST['page']) ? $_REQUEST['page'] : null;
        if ($page == 'edit') {
            $url = api_get_path(WEB_CODE_PATH) . 'work/edit.php?id=' . $my_folder_data['id'] . '&item_id=' . $work['id'] . '&' . api_get_cidreq();
        } else {
            $url = api_get_path(WEB_CODE_PATH) . 'work/view.php?id=' . $work['id'] . '&' . api_get_cidreq();
        }
        switch ($action) {
            case 'send_comment':
                if (isset($_FILES["file"])) {
                    $_POST['file'] = $_FILES["file"];
                }
                addWorkComment(api_get_course_info(), api_get_user_id(), $my_folder_data, $work, $_POST);
                Display::addFlash(Display::return_message(get_lang('CommentCreated')));
                header('Location: ' . $url);
Exemplo n.º 17
0
    /**
     * Prints the session and course list (user_portal.php)
     * @param int $user_id
     * @return string
     */
    public function return_courses_and_sessions($user_id)
    {
        global $_configuration;

        $load_history = (isset($_GET['history']) && intval($_GET['history']) == 1) ? true : false;
        if ($load_history) {
            // Load sessions in category in *history*
            $session_categories = UserManager::get_sessions_by_category(
                $user_id,
                true
            );
        } else {
            // Load sessions in category
            $session_categories = UserManager::get_sessions_by_category(
                $user_id,
                false
            );
        }

        $html = '';

        // Showing history title

        if ($load_history) {
            $html .= Display::page_subheader(get_lang('HistoryTrainingSession'));
            if (empty($session_categories)) {
                $html .= get_lang('YouDoNotHaveAnySessionInItsHistory');
            }
        }

        $courses_html = '';
        $special_courses = '';

        // If we're not in the history view...
        if (!isset($_GET['history'])) {
            // Display special courses.
            $special_courses = CourseManager::display_special_courses($user_id, $this->load_directories_preview);
            // Display courses.
            $courses_html .= CourseManager::display_courses($user_id, $this->load_directories_preview);
        }

        $sessions_with_category = '';
        $sessions_with_no_category = '';
        if (is_array($session_categories)) {
            foreach ($session_categories as $session_category) {
                $session_category_id = $session_category['session_category']['id'];

                // Sessions and courses that are not in a session category
                if ($session_category_id == 0 &&
                    isset($session_category['sessions'])
                ) {
                    // Independent sessions
                    foreach ($session_category['sessions'] as $session) {
                        $session_id = $session['session_id'];

                        // Don't show empty sessions.
                        if (count($session['courses']) < 1) {
                            continue;
                        }

                        // Courses inside the current session.
                        $date_session_start = $session['date_start'];
                        $date_session_end = $session['date_end'];
                        $days_access_before_beginning  = $session['nb_days_access_before_beginning'];
                        $days_access_after_end = $session['nb_days_access_after_end'];

                        $session_now = time();
                        $count_courses_session = 0;

                        // Loop course content
                        $html_courses_session = '';
                        $atLeastOneCourseIsVisible = false;

                        foreach ($session['courses'] as $course) {
                            $is_coach_course = api_is_coach($session_id, $course['code']);
                            $allowed_time = 0;
                            $dif_time_after = 0;
                            if ($date_session_start != '0000-00-00') {
                                if ($is_coach_course) {
                                    $allowed_time = api_strtotime($date_session_start.' 00:00:00') - ($days_access_before_beginning * 86400);
                                } else {
                                    $allowed_time = api_strtotime($date_session_start.' 00:00:00');
                                }
                                if (!isset($_GET['history'])) {
                                    if ($date_session_end != '0000-00-00') {
                                        $endSessionToTms = api_strtotime($date_session_end.' 23:59:59');
                                        if ($session_now > $endSessionToTms) {
                                            $dif_time_after = $session_now - $endSessionToTms;
                                            $dif_time_after = round($dif_time_after/86400);
                                        }
                                    }
                                }
                            }

                            if ($session_now > $allowed_time &&
                                $days_access_after_end > $dif_time_after - 1
                            ) {
                                // Read only and accessible.
                                $atLeastOneCourseIsVisible = true;

                                if (api_get_setting('hide_courses_in_sessions') == 'false') {
                                    $c = CourseManager::get_logged_user_course_html(
                                        $course,
                                        $session_id,
                                        'session_course_item',
                                        true,
                                        $this->load_directories_preview
                                    );
                                    $html_courses_session .= isset($c[1]) ? $c[1] : null;
                                }
                                $count_courses_session++;
                            }
                        }

                        // No courses to show.
                        if ($atLeastOneCourseIsVisible == false) {
                            if (empty($html_courses_session)) {
                                continue;
                            }
                        }

                        if ($count_courses_session > 0) {
                            $params = array();
                            $session_box = Display::get_session_title_box($session_id);
                            $params['icon'] = Display::return_icon(
                                'window_list.png',
                                $session_box['title'],
                                array('id' => 'session_img_' . $session_id),
                                ICON_SIZE_LARGE
                            );
                            $extra_info = !empty($session_box['coach']) ? $session_box['coach'] : null;
                            $extra_info .= !empty($session_box['coach']) ? ' - '.$session_box['dates'] : $session_box['dates'];
                            $extra_info .= isset($session_box['duration']) ? ' '.$session_box['duration'] : null;

                            if (api_is_drh()) {
                                $session_link = $session_box['title'];
                                $params['link'] = null;
                            } else {
                                $session_link = Display::tag(
                                    'a',
                                    $session_box['title'],
                                    array(
                                        'href' => api_get_path(
                                                WEB_CODE_PATH
                                            ) . 'session/index.php?session_id=' . $session_id
                                    )
                                );
                                $params['link'] = api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id;
                            }

                            $params['title'] = $session_link;
                            $params['subtitle'] = $extra_info;

                            $params['right_actions'] = '';
                            if (api_is_platform_admin()) {
                                $params['right_actions'] .= '<a href="'.api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$session_id.'">';
                                $params['right_actions'] .= Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'), ICON_SIZE_SMALL).'</a>';
                            }

                            if (api_get_setting('hide_courses_in_sessions') == 'false') {
                                // $params['extra'] .=  $html_courses_session;
                            }

                            $params['description'] = isset($session_box['description']) ? $session_box['description'] : null;

                            $parentInfo = CourseManager::course_item_html($params, true);

                            if (isset($_configuration['show_simple_session_info']) &&
                                $_configuration['show_simple_session_info']
                            ) {
                                $params['title'] = $session_box['title'];
                                $parentInfo = CourseManager::course_item_html_no_icon($params);
                            }
                            $sessions_with_no_category .= CourseManager::course_item_parent(
                                $parentInfo,
                                $html_courses_session
                            );
                        }
                    }
                } else {
                    // All sessions included in
                    $count_courses_session = 0;
                    $html_sessions = '';
                    if (isset($session_category['sessions'])) {
                        foreach ($session_category['sessions'] as $session) {
                            $session_id = $session['session_id'];

                            // Don't show empty sessions.
                            if (count($session['courses']) < 1) {
                                continue;
                            }
                            $date_session_start = $session['date_start'];
                            $date_session_end = $session['date_end'];
                            $days_access_before_beginning = $session['nb_days_access_before_beginning'];
                            $days_access_after_end = $session['nb_days_access_after_end'];

                            $session_now = time();
                            $html_courses_session = '';
                            $count = 0;

                            foreach ($session['courses'] as $course) {
                                $is_coach_course = api_is_coach(
                                    $session_id,
                                    $course['code']
                                );

                                $dif_time_after = 0;
                                $allowed_time = 0;
                                if ($is_coach_course) {
                                    // 24 hours = 86400
                                    if ($date_session_start != '0000-00-00') {
                                        $allowed_time = api_strtotime($date_session_start . ' 00:00:00') - ($days_access_before_beginning * 86400);
                                    }
                                    if (!isset($_GET['history'])) {
                                        if ($date_session_end != '0000-00-00') {
                                            $endSessionToTms = api_strtotime(
                                                $date_session_end . ' 23:59:59'
                                            );
                                            if ($session_now > $endSessionToTms) {
                                                $dif_time_after = $session_now - $endSessionToTms;
                                                $dif_time_after = round(
                                                    $dif_time_after / 86400
                                                );
                                            }
                                        }
                                    }
                                } else {
                                    $allowed_time = api_strtotime(
                                        $date_session_start . ' 00:00:00'
                                    );
                                }

                                if ($session_now > $allowed_time &&
                                    $days_access_after_end > $dif_time_after - 1
                                ) {
                                    if (api_get_setting('hide_courses_in_sessions') == 'false') {
                                        $c = CourseManager:: get_logged_user_course_html(
                                            $course,
                                            $session_id,
                                            'session_course_item'
                                        );
                                        $html_courses_session .= $c[1];
                                    }
                                    $count_courses_session++;
                                    $count++;
                                }
                            }

                            $params = array();

                            if ($count > 0) {
                                $session_box = Display:: get_session_title_box(
                                    $session_id
                                );
                                $params['icon'] = Display::return_icon(
                                        'window_list.png',
                                        $session_box['title'],
                                        array(
                                            'width' => '48px',
                                            'align' => 'absmiddle',
                                            'id' => 'session_img_' . $session_id
                                        )
                                    ) . ' ';

                                if (api_is_drh()) {
                                    $session_link = $session_box['title'];
                                    $params['link'] = null;
                                } else {
                                    $session_link = Display::tag(
                                        'a',
                                        $session_box['title'],
                                        array(
                                            'href' => api_get_path(WEB_CODE_PATH) . 'session/index.php?session_id=' . $session_id
                                        )
                                    );
                                    $params['link'] = api_get_path(WEB_CODE_PATH) . 'session/index.php?session_id=' . $session_id;
                                }

                                $params['title'] = $session_link;
                                $params['subtitle'] = (!empty($session_box['coach']) ? $session_box['coach'] . ' | ' : '') . $session_box['dates'];

                                if (api_is_platform_admin()) {
                                    $params['right_actions'] = '<a href="' . api_get_path(WEB_CODE_PATH) . 'admin/resume_session.php?id_session=' . $session_id . '">' .
                                        Display::return_icon(
                                            'edit.png',
                                            get_lang('Edit'),
                                            array('align' => 'absmiddle'),
                                            ICON_SIZE_SMALL
                                        ) . '</a>';
                                }

                                $parentInfo = CourseManager::course_item_html(
                                    $params,
                                    true
                                );

                                if (isset($_configuration['show_simple_session_info']) && $_configuration['show_simple_session_info']) {
                                    $params['title'] = $session_box['title'];
                                    $parentInfo = CourseManager::course_item_html_no_icon(
                                        $params
                                    );
                                }

                                $html_sessions .= $parentInfo . $html_courses_session;
                            }
                        }
                    }

                    if ($count_courses_session > 0) {
                        $params = array();
                        $params['icon'] = Display::return_icon('folder_blue.png', $session_category['session_category']['name'], array(), ICON_SIZE_LARGE);

                        if (api_is_platform_admin()) {
                            $params['right_actions'] = '<a href="'.api_get_path(WEB_CODE_PATH).'admin/session_category_edit.php?&id='.$session_category['session_category']['id'].'">'.Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>';
                        }

                        $params['title'] = $session_category['session_category']['name'];

                        if (api_is_platform_admin()) {
                            $params['link']   = api_get_path(WEB_CODE_PATH).'admin/session_category_edit.php?&id='.$session_category['session_category']['id'];
                        }

                        $session_category_start_date = $session_category['session_category']['date_start'];
                        $session_category_end_date = $session_category['session_category']['date_end'];

                        if (!empty($session_category_start_date) && $session_category_start_date != '0000-00-00' && !empty($session_category_end_date) && $session_category_end_date != '0000-00-00' ) {
                            $params['subtitle'] = sprintf(get_lang('FromDateXToDateY'), $session_category['session_category']['date_start'], $session_category['session_category']['date_end']);
                        } else {
                            if (!empty($session_category_start_date) && $session_category_start_date != '0000-00-00') {
                                 $params['subtitle'] = get_lang('From').' '.$session_category_start_date;
                            }
                            if (!empty($session_category_end_date) && $session_category_end_date != '0000-00-00') {
                                $params['subtitle'] = get_lang('Until').' '.$session_category_end_date;
                            }
                        }
                        $sessions_with_category .= CourseManager::course_item_parent(
                            CourseManager::course_item_html($params, true),
                            $html_sessions
                        );
                    }

                }
            }
        }

        return $sessions_with_category.
               $sessions_with_no_category.
               $courses_html.$special_courses;
    }
Exemplo n.º 18
0
 /**
  * Prints the session and course list (user_portal.php)
  * @param int $user_id
  * @return string
  */
 public function returnCoursesAndSessions($user_id)
 {
     global $_configuration;
     $gamificationModeIsActive = api_get_setting('platform.gamification_mode');
     $load_history = isset($_GET['history']) && intval($_GET['history']) == 1 ? true : false;
     if ($load_history) {
         // Load sessions in category in *history*
         $session_categories = UserManager::get_sessions_by_category($user_id, true);
     } else {
         // Load sessions in category
         $session_categories = UserManager::get_sessions_by_category($user_id, false);
     }
     $html = '';
     // Showing history title
     if ($load_history) {
         $html .= Display::page_subheader(get_lang('HistoryTrainingSession'));
         if (empty($session_categories)) {
             $html .= get_lang('YouDoNotHaveAnySessionInItsHistory');
         }
     }
     $courses_html = '';
     $special_courses = '';
     $sessionCount = 0;
     $courseCount = 0;
     // If we're not in the history view...
     if (!isset($_GET['history'])) {
         // Display special courses.
         $specialCourses = CourseManager::display_special_courses($user_id, $this->load_directories_preview);
         $special_courses = $specialCourses['html'];
         // Display courses.
         $courses = CourseManager::display_courses($user_id, $this->load_directories_preview);
         $courses_html .= $courses['html'];
         $courseCount = $specialCourses['course_count'] + $courses['course_count'];
     }
     $sessions_with_category = '';
     $sessions_with_no_category = '';
     $sessionTitleLink = api_get_configuration_value('courses_list_session_title_link');
     $sessionTitleLink = $sessionTitleLink === false ? 1 : $sessionTitleLink;
     if (is_array($session_categories)) {
         foreach ($session_categories as $session_category) {
             $session_category_id = $session_category['session_category']['id'];
             // Sessions and courses that are not in a session category
             if (empty($session_category_id) && isset($session_category['sessions'])) {
                 // Independent sessions
                 foreach ($session_category['sessions'] as $session) {
                     $session_id = $session['session_id'];
                     // Don't show empty sessions.
                     if (count($session['courses']) < 1) {
                         continue;
                     }
                     // Courses inside the current session.
                     $date_session_start = $session['access_start_date'];
                     $date_session_end = $session['access_end_date'];
                     $coachAccessStartDate = $session['coach_access_start_date'];
                     $coachAccessEndDate = $session['coach_access_end_date'];
                     $session_now = time();
                     $count_courses_session = 0;
                     // Loop course content
                     $html_courses_session = [];
                     $atLeastOneCourseIsVisible = false;
                     foreach ($session['courses'] as $course) {
                         $is_coach_course = api_is_coach($session_id, $course['real_id']);
                         $allowed_time = 0;
                         $dif_time_after = 0;
                         if (!empty($date_session_start) && $date_session_start != '0000-00-00 00:00:00') {
                             if ($is_coach_course) {
                                 $allowed_time = api_strtotime($coachAccessStartDate);
                             } else {
                                 $allowed_time = api_strtotime($date_session_start);
                             }
                             if (!isset($_GET['history'])) {
                                 if (!empty($date_session_end) && $date_session_end != '0000-00-00 00:00:00') {
                                     $endSessionToTms = api_strtotime($date_session_end);
                                     if ($session_now > $endSessionToTms) {
                                         $dif_time_after = $session_now - $endSessionToTms;
                                         $dif_time_after = round($dif_time_after / 86400);
                                     }
                                 }
                             }
                         }
                         if ($session_now > $allowed_time) {
                             // Read only and accessible.
                             $atLeastOneCourseIsVisible = true;
                             if (api_get_setting('session.hide_courses_in_sessions') == 'false') {
                                 $courseUserHtml = CourseManager::get_logged_user_course_html($course, $session_id, 'session_course_item', true, $this->load_directories_preview);
                                 if (isset($courseUserHtml[1])) {
                                     $course_session = $courseUserHtml[1];
                                     $course_session['skill'] = isset($courseUserHtml['skill']) ? $courseUserHtml['skill'] : '';
                                     $html_courses_session[] = $course_session;
                                 }
                             }
                             $count_courses_session++;
                         }
                     }
                     // No courses to show.
                     if ($atLeastOneCourseIsVisible == false) {
                         if (empty($html_courses_session)) {
                             continue;
                         }
                     }
                     if ($count_courses_session > 0) {
                         $params = array('id' => $session_id);
                         $session_box = Display::get_session_title_box($session_id);
                         $extra_info = !empty($session_box['coach']) ? $session_box['coach'] : null;
                         $extra_info .= !empty($session_box['coach']) ? ' - ' . $session_box['dates'] : $session_box['dates'];
                         $extra_info .= isset($session_box['duration']) ? ' ' . $session_box['duration'] : null;
                         $params['extra_fields'] = $session_box['extra_fields'];
                         $params['show_link_to_session'] = !api_is_drh() && $sessionTitleLink;
                         $params['title'] = $session_box['title'];
                         $params['subtitle'] = $extra_info;
                         $params['show_actions'] = api_is_platform_admin() ? true : false;
                         if (api_get_setting('session.hide_courses_in_sessions') == 'false') {
                             // $params['extra'] .=  $html_courses_session;
                         }
                         $params['description'] = $session_box['description'];
                         $params['show_description'] = $session_box['show_description'];
                         $params['courses'] = $html_courses_session;
                         $params['show_simple_session_info'] = false;
                         if (isset($_configuration['show_simple_session_info']) && $_configuration['show_simple_session_info']) {
                             $params['show_simple_session_info'] = true;
                         }
                         if ($gamificationModeIsActive) {
                             $params['stars'] = GamificationUtils::getSessionStars($params['id'], $this->user_id);
                             $params['progress'] = GamificationUtils::getSessionProgress($params['id'], $this->user_id);
                             $params['points'] = GamificationUtils::getSessionPoints($params['id'], $this->user_id);
                         }
                         $this->tpl->assign('session', $params);
                         $this->tpl->assign('gamification_mode', $gamificationModeIsActive);
                         $sessions_with_no_category .= $this->tpl->fetch($this->tpl->get_template('/user_portal/session.tpl'));
                         $sessionCount++;
                     }
                 }
             } else {
                 // All sessions included in
                 $count_courses_session = 0;
                 $html_sessions = '';
                 if (isset($session_category['sessions'])) {
                     foreach ($session_category['sessions'] as $session) {
                         $session_id = $session['session_id'];
                         // Don't show empty sessions.
                         if (count($session['courses']) < 1) {
                             continue;
                         }
                         $date_session_start = $session['access_start_date'];
                         $date_session_end = $session['access_end_date'];
                         $coachAccessStartDate = $session['coach_access_start_date'];
                         $coachAccessEndDate = $session['coach_access_end_date'];
                         $session_now = time();
                         $html_courses_session = [];
                         $count = 0;
                         foreach ($session['courses'] as $course) {
                             $is_coach_course = api_is_coach($session_id, $course['real_id']);
                             $dif_time_after = 0;
                             $allowed_time = 0;
                             if ($is_coach_course) {
                                 // 24 hours = 86400
                                 if ($date_session_start != '0000-00-00 00:00:00') {
                                     $allowed_time = api_strtotime($coachAccessStartDate);
                                 }
                                 if (!isset($_GET['history'])) {
                                     if ($date_session_end != '0000-00-00 00:00:00') {
                                         $endSessionToTms = api_strtotime($date_session_end);
                                         if ($session_now > $endSessionToTms) {
                                             $dif_time_after = $session_now - $endSessionToTms;
                                             $dif_time_after = round($dif_time_after / 86400);
                                         }
                                     }
                                 }
                             } else {
                                 $allowed_time = api_strtotime($date_session_start);
                             }
                             if ($session_now > $allowed_time) {
                                 if (api_get_setting('session.hide_courses_in_sessions') == 'false') {
                                     $c = CourseManager::get_logged_user_course_html($course, $session_id, 'session_course_item');
                                     $html_courses_session[] = $c[1];
                                 }
                                 $count_courses_session++;
                                 $count++;
                             }
                         }
                         $sessionParams = array();
                         //Category
                         if ($count > 0) {
                             $session_box = Display::get_session_title_box($session_id);
                             $sessionParams['id'] = $session_id;
                             $sessionParams['show_link_to_session'] = !api_is_drh() && $sessionTitleLink;
                             $sessionParams['title'] = $session_box['title'];
                             $sessionParams['subtitle'] = (!empty($session_box['coach']) ? $session_box['coach'] . ' | ' : '') . $session_box['dates'];
                             $sessionParams['show_actions'] = api_is_platform_admin();
                             $sessionParams['courses'] = $html_courses_session;
                             $sessionParams['show_simple_session_info'] = false;
                             if (isset($_configuration['show_simple_session_info']) && $_configuration['show_simple_session_info']) {
                                 $sessionParams['show_simple_session_info'] = true;
                             }
                             $this->tpl->assign('session', $sessionParams);
                             $html_sessions .= $this->tpl->fetch($this->tpl->get_template('user_portal/session.tpl'));
                             $sessionCount++;
                         }
                     }
                 }
                 if ($count_courses_session > 0) {
                     $categoryParams = array('id' => $session_category['session_category']['id'], 'title' => $session_category['session_category']['name'], 'show_actions' => api_is_platform_admin(), 'subtitle' => null, 'sessions' => $html_sessions);
                     $session_category_start_date = $session_category['session_category']['date_start'];
                     $session_category_end_date = $session_category['session_category']['date_end'];
                     if (!empty($session_category_start_date) && $session_category_start_date != '0000-00-00' && !empty($session_category_end_date) && $session_category_end_date != '0000-00-00') {
                         $categoryParams['subtitle'] = sprintf(get_lang('FromDateXToDateY'), $session_category['session_category']['date_start'], $session_category['session_category']['date_end']);
                     } else {
                         if (!empty($session_category_start_date) && $session_category_start_date != '0000-00-00') {
                             $categoryParams['subtitle'] = get_lang('From') . ' ' . $session_category_start_date;
                         }
                         if (!empty($session_category_end_date) && $session_category_end_date != '0000-00-00') {
                             $categoryParams['subtitle'] = get_lang('Until') . ' ' . $session_category_end_date;
                         }
                     }
                     $this->tpl->assign('session_category', $categoryParams);
                     $sessions_with_category .= $this->tpl->fetch("{$this->tpl->templateFolder}/user_portal/session_category.tpl");
                 }
             }
         }
     }
     return ['html' => $sessions_with_category . $sessions_with_no_category . $courses_html . $special_courses, 'session_count' => $sessionCount, 'course_count' => $courseCount];
 }
Exemplo n.º 19
0
 /**
  * Fetches all document data for the given user/group
  *
  * @param array $_course
  * @param string $path
  * @param int $to_group_id
  * @param int $to_user_id
  * @param boolean $can_see_invisible
  * @return array with all document data
  */
 public static function get_all_document_data($_course, $path = '/', $to_group_id = 0, $to_user_id = 0, $can_see_invisible = false, $search = false)
 {
     $TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
     $TABLE_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
     $to_user_id = Database::escape_string($to_user_id);
     if (empty($_course)) {
         return false;
     }
     if (!empty($to_user_id)) {
         $to_field = 'last.to_user_id';
         $to_value = $to_user_id;
     } else {
         $to_field = 'last.to_group_id';
         $to_value = $to_group_id;
     }
     //escape underscores in the path so they don't act as a wildcard
     $path = Database::escape_string(str_replace('_', '\\_', $path));
     $to_value = Database::escape_string($to_value);
     $visibility_bit = ' <> 2';
     //the given path will not end with a slash, unless it's the root '/'
     //so no root -> add slash
     $added_slash = $path == '/' ? '' : '/';
     //condition for the session
     $current_session_id = api_get_session_id();
     $condition_session = " AND (id_session = '{$current_session_id}' OR id_session = '0' OR id_session IS NULL)";
     //condition for search (get ALL folders and documents)
     $sql = "SELECT  docs.id,\n                        docs.filetype,\n                        docs.path,\n                        docs.title,\n                        docs.comment,\n                        docs.size,\n                        docs.readonly,\n                        docs.session_id,\n                        last.id_session item_property_session_id,\n                        last.lastedit_date,\n                        last.visibility,\n                        last.insert_user_id\n                FROM  " . $TABLE_ITEMPROPERTY . " AS last INNER JOIN " . $TABLE_DOCUMENT . "  AS docs\n                    ON (docs.id = last.ref AND last.tool = '" . TOOL_DOCUMENT . "' AND docs.c_id = {$_course['real_id']} AND last.c_id = {$_course['real_id']})\n                WHERE\n                    docs.path LIKE '" . $path . $added_slash . "%' AND\n                    docs.path NOT LIKE '" . $path . $added_slash . "%/%' AND\n                    " . $to_field . " = " . $to_value . " AND\n                    last.visibility" . $visibility_bit . $condition_session;
     $result = Database::query($sql);
     $doc_list = array();
     $document_data = array();
     $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
     if ($result !== false && Database::num_rows($result) != 0) {
         while ($row = Database::fetch_array($result, 'ASSOC')) {
             if (api_is_coach()) {
                 //Looking for course items that are invisible to hide it in the session
                 if (in_array($row['id'], array_keys($doc_list))) {
                     if ($doc_list[$row['id']]['item_property_session_id'] == 0 && $doc_list[$row['id']]['session_id'] == 0) {
                         if ($doc_list[$row['id']]['visibility'] == 0) {
                             unset($document_data[$row['id']]);
                             continue;
                         }
                     }
                 }
                 $doc_list[$row['id']] = $row;
             }
             if (!api_is_coach() && !$is_allowed_to_edit) {
                 $doc_list[] = $row;
             }
             if ($row['filetype'] == 'file' && pathinfo($row['path'], PATHINFO_EXTENSION) == 'html') {
                 //Templates management
                 $table_template = Database::get_main_table(TABLE_MAIN_TEMPLATES);
                 $sql_is_template = "SELECT id FROM {$table_template}\n                                        WHERE course_code = '" . $_course['code'] . "'\n                                        AND user_id='" . api_get_user_id() . "'\n                                        AND ref_doc='" . $row['id'] . "'";
                 $template_result = Database::query($sql_is_template);
                 $row['is_template'] = Database::num_rows($template_result) > 0 ? 1 : 0;
             }
             //just filling $document_data
             $document_data[$row['id']] = $row;
         }
         //Only for the student we filter the results see BT#1652
         if (!api_is_coach() && !$is_allowed_to_edit) {
             $ids_to_remove = array();
             $my_repeat_ids = $temp = array();
             //Selecting repetead ids
             foreach ($doc_list as $row) {
                 if (in_array($row['id'], array_keys($temp))) {
                     $my_repeat_ids[] = $row['id'];
                 }
                 $temp[$row['id']] = $row;
             }
             //@todo use the DocumentManager::is_visible function
             //Checking disponibility in a session
             foreach ($my_repeat_ids as $id) {
                 foreach ($doc_list as $row) {
                     if ($id == $row['id']) {
                         if ($row['visibility'] == 0 && $row['item_property_session_id'] == 0) {
                             $delete_repeated[$id] = true;
                         }
                         if ($row['visibility'] == 0 && $row['item_property_session_id'] != 0) {
                             $delete_repeated[$id] = true;
                         }
                     }
                 }
             }
             foreach ($doc_list as $key => $row) {
                 if (in_array($row['visibility'], array('0', '2')) && !in_array($row['id'], $my_repeat_ids)) {
                     $ids_to_remove[] = $row['id'];
                     unset($doc_list[$key]);
                 }
             }
             foreach ($document_data as $row) {
                 if (in_array($row['id'], $ids_to_remove)) {
                     unset($document_data[$row['id']]);
                 }
                 if (isset($delete_repeated[$row['id']]) && $delete_repeated[$row['id']]) {
                     unset($document_data[$row['id']]);
                 }
             }
             //Checking parents visibility
             $final_document_data = array();
             foreach ($document_data as $row) {
                 $is_visible = DocumentManager::check_visibility_tree($row['id'], $_course['code'], $current_session_id, api_get_user_id());
                 if ($is_visible) {
                     $final_document_data[$row['id']] = $row;
                 }
             }
         } else {
             $final_document_data = $document_data;
         }
         return $final_document_data;
     } else {
         //display_error("Error getting document info from database (".Database::error().")!");
         return false;
     }
 }
Exemplo n.º 20
0
 /**
  * Displays the tools of a certain category.
  * @param array $all_tools_list List of tools as returned by get_tools_category()
  * @param bool  $rows
  *
  * @return void
  */
 public static function show_tools_category($all_tools_list, $rows = false)
 {
     $_user = api_get_user_info();
     $theme = api_get_setting('homepage_view');
     if ($theme == 'vertical_activity') {
         //ordering by get_lang name
         $order_tool_list = array();
         if (is_array($all_tools_list) && count($all_tools_list) > 0) {
             foreach ($all_tools_list as $key => $new_tool) {
                 $tool_name = self::translate_tool_name($new_tool);
                 $order_tool_list[$key] = $tool_name;
             }
             natsort($order_tool_list);
             $my_temp_tool_array = array();
             foreach ($order_tool_list as $key => $new_tool) {
                 $my_temp_tool_array[] = $all_tools_list[$key];
             }
             $all_tools_list = $my_temp_tool_array;
         } else {
             $all_tools_list = array();
         }
     }
     $web_code_path = api_get_path(WEB_CODE_PATH);
     $session_id = api_get_session_id();
     $is_platform_admin = api_is_platform_admin();
     if ($session_id == 0) {
         $is_allowed_to_edit = api_is_allowed_to_edit(null, true) && api_is_course_admin();
     } else {
         $is_allowed_to_edit = api_is_allowed_to_edit(null, true) && !api_is_coach();
     }
     $i = 0;
     $items = array();
     $app_plugin = new AppPlugin();
     if (isset($all_tools_list)) {
         $lnk = '';
         foreach ($all_tools_list as &$tool) {
             $item = array();
             $studentview = false;
             $tool['original_link'] = $tool['link'];
             if ($tool['image'] == 'scormbuilder.gif') {
                 // check if the published learnpath is visible for student
                 $published_lp_id = self::get_published_lp_id_from_link($tool['link']);
                 if (api_is_allowed_to_edit(null, true)) {
                     $studentview = true;
                 }
                 if (!api_is_allowed_to_edit(null, true) && !learnpath::is_lp_visible_for_student($published_lp_id, api_get_user_id(), api_get_course_id(), api_get_session_id())) {
                     continue;
                 }
             }
             if ($session_id != 0 && in_array($tool['name'], array('course_setting'))) {
                 continue;
             }
             // This part displays the links to hide or remove a tool.
             // These links are only visible by the course manager.
             unset($lnk);
             $item['extra'] = null;
             $toolAdmin = isset($tool['admin']) ? $tool['admin'] : '';
             if ($is_allowed_to_edit) {
                 if (empty($session_id)) {
                     if (isset($tool['id'])) {
                         if ($tool['visibility'] == '1' && $toolAdmin != '1') {
                             $link['name'] = Display::return_icon('visible.png', get_lang('Deactivate'), array('id' => 'linktool_' . $tool['id']), ICON_SIZE_SMALL, false);
                             $link['cmd'] = 'hide=yes';
                             $lnk[] = $link;
                         }
                         if ($tool['visibility'] == '0' && $toolAdmin != '1') {
                             $link['name'] = Display::return_icon('invisible.png', get_lang('Activate'), array('id' => 'linktool_' . $tool['id']), ICON_SIZE_SMALL, false);
                             $link['cmd'] = 'restore=yes';
                             $lnk[] = $link;
                         }
                     }
                 }
                 if (!empty($tool['adminlink'])) {
                     $item['extra'] = '<a href="' . $tool['adminlink'] . '">' . Display::return_icon('edit.gif', get_lang('Edit')) . '</a>';
                 }
             }
             // Both checks are necessary as is_platform_admin doesn't take student view into account
             if ($is_platform_admin && $is_allowed_to_edit) {
                 if ($toolAdmin != '1') {
                     $link['cmd'] = 'hide=yes';
                 }
             }
             $item['visibility'] = null;
             if (isset($lnk) && is_array($lnk)) {
                 foreach ($lnk as $this_link) {
                     if (empty($tool['adminlink'])) {
                         $item['visibility'] .= '<a class="make_visible_and_invisible" href="' . api_get_self() . '?' . api_get_cidreq() . '&amp;id=' . $tool['id'] . '&amp;' . $this_link['cmd'] . '">' . $this_link['name'] . '</a>';
                     }
                 }
             } else {
                 $item['visibility'] .= '';
             }
             // NOTE : Table contains only the image file name, not full path
             if (stripos($tool['link'], 'http://') === false && stripos($tool['link'], 'https://') === false && stripos($tool['link'], 'ftp://') === false) {
                 $tool['link'] = $web_code_path . $tool['link'];
             }
             if ($tool['visibility'] == '0' && $toolAdmin != '1' && !isset($tool['original_link'])) {
                 $class = 'invisible';
                 $info = pathinfo($tool['image']);
                 $basename = basename($tool['image'], '.' . $info['extension']);
                 // $file is set to "index"
                 $tool['image'] = $basename . '_na.' . $info['extension'];
             } else {
                 $class = '';
             }
             $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&';
             // If it's a link, we don't add the cidReq
             if ($tool['image'] == 'file_html.png' || $tool['image'] == 'file_html_na.png') {
                 $tool['link'] = $tool['link'] . $qm_or_amp;
             } else {
                 $tool['link'] = $tool['link'] . $qm_or_amp . api_get_cidreq();
             }
             $tool_link_params = array();
             $toolId = isset($tool["id"]) ? $tool["id"] : null;
             //@todo this visio stuff should be removed
             if (strpos($tool['name'], 'visio_') !== false) {
                 $tool_link_params = array('id' => 'tooldesc_' . $toolId, 'href' => '"javascript: void(0);"', 'class' => $class, 'onclick' => 'javascript: window.open(\'' . $tool['link'] . '\',\'window_visio' . $_SESSION['_cid'] . '\',config=\'height=\'+730+\', width=\'+1020+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')', 'target' => $tool['target']);
             } elseif (strpos($tool['name'], 'chat') !== false && api_get_course_setting('allow_open_chat_window')) {
                 $tool_link_params = array('id' => 'tooldesc_' . $toolId, 'class' => $class, 'href' => 'javascript: void(0);', 'onclick' => 'javascript: window.open(\'' . $tool['link'] . '\',\'window_chat' . $_SESSION['_cid'] . '\',config=\'height=\'+600+\', width=\'+825+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')', 'target' => $tool['target']);
             } else {
                 if (count(explode('type=classroom', $tool['link'])) == 2 || count(explode('type=conference', $tool['link'])) == 2) {
                     $tool_link_params = array('id' => 'tooldesc_' . $toolId, 'href' => $tool['link'], 'class' => $class, 'target' => '_blank');
                 } else {
                     $tool_link_params = array('id' => 'tooldesc_' . $toolId, 'href' => $tool['link'], 'class' => $class, 'target' => $tool['target']);
                 }
             }
             $tool_name = self::translate_tool_name($tool);
             // Including Courses Plugins
             // Creating title and the link
             if (isset($tool['category']) && $tool['category'] == 'plugin') {
                 $plugin_info = $app_plugin->getPluginInfo($tool['name']);
                 if (isset($plugin_info) && isset($plugin_info['title'])) {
                     $tool_name = $plugin_info['title'];
                 }
                 if (!file_exists(api_get_path(SYS_CODE_PATH) . 'img/' . $tool['image']) && !file_exists(api_get_path(SYS_CODE_PATH) . 'img/icons/22/' . $tool['image'])) {
                     $tool['image'] = 'plugins.png';
                 }
                 $tool_link_params['href'] = api_get_path(WEB_PLUGIN_PATH) . $tool['original_link'] . '?' . api_get_cidreq();
             }
             $icon = Display::return_icon($tool['image'], $tool_name, array('class' => 'tool-icon', 'id' => 'toolimage_' . $toolId), ICON_SIZE_BIG, false);
             /*if (!empty($tool['custom_icon'])) {
                   $image = self::getCustomWebIconPath().$tool['custom_icon'];
                   $icon = Display::img(
                       $image,
                       $tool['description'],
                       array(
                           'class' => 'tool-icon',
                           'id' => 'toolimage_'.$tool['id']
                       )
                   );
               }*/
             // Validation when belongs to a session
             $session_img = api_get_session_image($tool['session_id'], !empty($_user['status']) ? $_user['status'] : '');
             if ($studentview) {
                 $tool_link_params['href'] .= '&isStudentView=true';
             }
             $item['url_params'] = $tool_link_params;
             $item['icon'] = Display::url($icon, $tool_link_params['href'], $tool_link_params);
             $item['tool'] = $tool;
             $item['name'] = $tool_name;
             $tool_link_params['id'] = 'is' . $tool_link_params['id'];
             $item['link'] = Display::url($tool_name . $session_img, $tool_link_params['href'], $tool_link_params);
             $items[] = $item;
             $i++;
         }
         // end of foreach
     }
     $i = 0;
     $html = '';
     if (!empty($items)) {
         foreach ($items as $item) {
             switch ($theme) {
                 case 'activity_big':
                     $data = '';
                     $html .= '<div class="col-xs-6 col-md-3 course-tool">';
                     $image = substr($item['tool']['image'], 0, strpos($item['tool']['image'], '.')) . '.png';
                     $toolId = isset($item['tool']['id']) ? $item['tool']['id'] : null;
                     if (isset($item['tool']['custom_image'])) {
                         $original_image = Display::img($item['tool']['custom_image'], $item['name'], array('id' => 'toolimage_' . $toolId));
                     } elseif (isset($item['tool']['custom_icon']) && !empty($item['tool']['custom_icon'])) {
                         $customIcon = $item['tool']['custom_icon'];
                         if ($item['tool']['visibility'] == '0') {
                             $fileInfo = pathinfo($item['tool']['custom_icon']);
                             $customIcon = self::getDisableIcon($item['tool']['custom_icon']);
                         }
                         $original_image = Display::img(self::getCustomWebIconPath() . $customIcon, $item['name'], array('id' => 'toolimage_' . $toolId));
                     } else {
                         $original_image = Display::return_icon($image, $item['name'], array('id' => 'toolimage_' . $toolId), ICON_SIZE_BIG, false);
                     }
                     $data .= Display::url($original_image, $item['url_params']['href'], $item['url_params']);
                     $html .= Display::div($data, array('class' => 'big_icon'));
                     //box-image reflection
                     $html .= Display::div('<h4>' . $item['visibility'] . $item['extra'] . $item['link'] . '</h4>', array('class' => 'content'));
                     $html .= '</div>';
                     break;
                 case 'activity':
                     $html .= '<div class="offset2 col-md-4 course-tool">';
                     $html .= $item['extra'];
                     $html .= $item['visibility'];
                     $html .= $item['icon'];
                     $html .= $item['link'];
                     $html .= '</div>';
                     break;
                 case 'vertical_activity':
                     if ($i == 0) {
                         $html .= '<ul>';
                     }
                     $html .= '<li class="course-tool">';
                     $html .= $item['extra'];
                     $html .= $item['visibility'];
                     $html .= $item['icon'];
                     $html .= $item['link'];
                     $html .= '</li>';
                     if ($i == count($items) - 1) {
                         $html .= '</ul>';
                     }
                     break;
             }
             $i++;
         }
     }
     return $html;
 }
Exemplo n.º 21
0
 /**
  * Display code for one specific course a logged in user is subscribed to.
  * Shows a link to the course, what's new icons...
  *
  * $my_course['d'] - course directory
  * $my_course['i'] - course title
  * $my_course['c'] - visual course code
  * $my_course['k']  - system course code
  *
  * @param   array       Course details
  * @param   integer     Session ID
  * @param   string      CSS class to apply to course entry
  * @param   boolean     Whether the session is supposedly accessible now
  * (not in the case it has passed and is in invisible/unaccessible mode)
  * @param bool      Whether to show the document quick-loader or not
  * @return  string      The HTML to be printed for the course entry
  *
  * @version 1.0.3
  * @todo refactor into different functions for database calls | logic | display
  * @todo replace single-character $my_course['d'] indices
  * @todo move code for what's new icons to a separate function to clear things up
  * @todo add a parameter user_id so that it is possible to show the
  * courselist of other users (=generalisation).
  * This will prevent having to write a new function for this.
  */
 public static function get_logged_user_course_html($course, $session_id = 0, $class = 'courses', $session_accessible = true, $load_dirs = false)
 {
     $entityManager = Database::getManager();
     $user_id = api_get_user_id();
     $course_info = api_get_course_info_by_id($course['real_id']);
     $status_course = CourseManager::get_user_in_course_status($user_id, $course_info['code']);
     $course_info['status'] = empty($session_id) ? $status_course : STUDENT;
     $course_info['id_session'] = $session_id;
     $objUser = $entityManager->find('ChamiloUserBundle:User', $user_id);
     $objCourse = $entityManager->find('ChamiloCoreBundle:Course', $course['real_id']);
     $objSession = $entityManager->find('ChamiloCoreBundle:Session', $session_id);
     /*$date_start = $sess[$course_info['id_session']]['access_start_date'];
       $date_end = $sess[$course_info['id_session']]['access_end_date'];*/
     $now = date('Y-m-d h:i:s');
     // Table definitions
     $main_user_table = Database::get_main_table(TABLE_MAIN_USER);
     $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
     $tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
     $course_access_settings = CourseManager::get_access_settings($course_info['code']);
     $course_visibility = $course_access_settings['visibility'];
     if ($course_visibility == COURSE_VISIBILITY_HIDDEN) {
         return '';
     }
     $user_in_course_status = CourseManager::get_user_in_course_status(api_get_user_id(), $course_info['code']);
     $is_coach = api_is_coach($course_info['id_session'], $course_info['real_id']);
     // Display course entry.
     // Show a hyperlink to the course, unless the course is closed and user is not course admin.
     $session_url = '';
     $session_title = '';
     $params = array();
     $params['icon'] = Display::return_icon('blackboard_blue.png', api_htmlentities($course_info['name']), array(), ICON_SIZE_LARGE);
     // Display the "what's new" icons
     $notifications = '';
     if ($course_visibility != COURSE_VISIBILITY_CLOSED && $course_visibility != COURSE_VISIBILITY_HIDDEN) {
         $notifications .= Display::show_notification($course_info);
     }
     if ($session_accessible) {
         if ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER) {
             if (empty($course_info['id_session'])) {
                 $course_info['id_session'] = 0;
             }
             $sessionCourseAvailable = false;
             $sessionCourseStatus = api_get_session_visibility($session_id, $course_info['real_id']);
             if (in_array($sessionCourseStatus, array(SESSION_VISIBLE_READ_ONLY, SESSION_VISIBLE, SESSION_AVAILABLE))) {
                 $sessionCourseAvailable = true;
             }
             if ($user_in_course_status == COURSEMANAGER || $sessionCourseAvailable) {
                 $session_url = $course_info['course_public_url'] . '?id_session=' . $course_info['id_session'];
                 $session_title = '<h4><a href="' . $session_url . '">' . $course_info['name'] . '</a>' . $notifications . '</h4>';
             } else {
                 $session_title = $course_info['name'];
             }
         } else {
             $session_title = $course_info['name'] . ' ' . Display::tag('span', get_lang('CourseClosed'), array('class' => 'item_closed'));
         }
     } else {
         $session_title = $course_info['name'];
     }
     $showCustomIcon = api_get_setting('course.course_images_in_courses_list');
     $iconName = basename($course_info['course_image']);
     if ($showCustomIcon === 'true' && $iconName != 'course.png') {
         $params['icon'] = Display::img($course_info['course_image'], api_htmlentities($course_info['name']), array());
     }
     $params['link'] = $session_url;
     $params['title'] = $session_title;
     $params['right_actions'] = '';
     if ($course_visibility != COURSE_VISIBILITY_CLOSED && $course_visibility != COURSE_VISIBILITY_HIDDEN) {
         if ($load_dirs) {
             $params['right_actions'] .= '<a id="document_preview_' . $course_info['real_id'] . '_' . $course_info['id_session'] . '" class="document_preview" href="javascript:void(0);">' . Display::return_icon('folder.png', get_lang('Documents'), array('align' => 'absmiddle'), ICON_SIZE_SMALL) . '</a>';
             $params['right_actions'] .= Display::div('', array('id' => 'document_result_' . $course_info['real_id'] . '_' . $course_info['id_session'], 'class' => 'document_preview_container'));
         }
     }
     if (api_get_setting('course.display_coursecode_in_courselist') == 'true') {
         $session_title .= ' (' . $course_info['visual_code'] . ') ';
     }
     if (api_get_setting('course.display_teacher_in_courselist') == 'true') {
         $teacher_list = CourseManager::getTeacherListFromCourseToString($course_info['real_id'], self::USER_SEPARATOR, true);
         $course_coachs = self::get_coachs_from_course($course_info['id_session'], $course_info['real_id']);
         if ($course_info['status'] == COURSEMANAGER || $course_info['status'] == STUDENT && empty($course_info['id_session']) || empty($course_info['status'])) {
             $params['teachers'] = $teacher_list;
         }
         if ($course_info['status'] == STUDENT && !empty($course_info['id_session']) || $is_coach && $course_info['status'] != COURSEMANAGER) {
             $params['coaches'] = $course_coachs;
         }
     }
     $session_title .= isset($course['special_course']) ? ' ' . Display::return_icon('klipper.png', get_lang('CourseAutoRegister')) : '';
     $params['title'] = $session_title;
     $params['extra'] = '';
     $html = $params;
     $session_category_id = null;
     if (1) {
         $session = '';
         $active = false;
         if (!empty($course_info['session_name'])) {
             // Request for the name of the general coach
             $sql = 'SELECT lastname, firstname,sc.name
                     FROM ' . $tbl_session . ' ts
                     LEFT JOIN ' . $main_user_table . ' tu
                     ON ts.id_coach = tu.user_id
                     INNER JOIN ' . $tbl_session_category . ' sc
                     ON ts.session_category_id = sc.id
                     WHERE ts.id=' . (int) $course_info['id_session'] . '
                     LIMIT 1';
             $rs = Database::query($sql);
             $sessioncoach = Database::store_result($rs);
             $sessioncoach = $sessioncoach[0];
             $session = array();
             $session['title'] = $course_info['session_name'];
             $session_category_id = CourseManager::get_session_category_id_by_session_id($course_info['id_session']);
             $session['category'] = $sessioncoach['name'];
             if ($course_info['access_start_date'] == '0000-00-00') {
                 //$session['dates'] = get_lang('WithoutTimeLimits');
                 $session['dates'] = '';
                 if (api_get_setting('session.show_session_coach') === 'true') {
                     $session['coach'] = get_lang('GeneralCoach') . ': ' . api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']);
                 }
                 $active = true;
             } else {
                 $session['dates'] = ' - ' . get_lang('From') . ' ' . $course_info['access_start_date'] . ' ' . get_lang('To') . ' ' . $course_info['access_end_date'];
                 if (api_get_setting('session.show_session_coach') === 'true') {
                     $session['coach'] = get_lang('GeneralCoach') . ': ' . api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']);
                 }
                 $active = $date_start <= $now && $date_end >= $now;
             }
         }
         $user_course_category = '';
         if (isset($course_info['user_course_cat'])) {
             $user_course_category = $course_info['user_course_cat'];
         }
         $output = array($user_course_category, $html, $course_info['id_session'], $session, 'active' => $active, 'session_category_id' => $session_category_id);
         if (api_get_setting('skill.allow_skills_tool') === 'true') {
             $skill = $entityManager->getRepository('ChamiloCoreBundle:Skill')->getLastByUser($objUser, $objCourse, $objSession);
             $output['skill'] = null;
             if ($skill) {
                 $output['skill']['name'] = $skill->getName();
                 $output['skill']['icon'] = $skill->getIcon();
             }
         }
     } else {
         $output = array($course_info['user_course_cat'], $html);
     }
     return $output;
 }
Exemplo n.º 22
0
 /**
  * @param $id
  * @return bool
  */
 public static function protect_teacher_session_edit($id)
 {
     if (!api_is_coach($id) && !api_is_platform_admin()) {
         api_not_allowed(true);
     } else {
         return true;
     }
 }
Exemplo n.º 23
0
 /**
  * Fetches all document data for the given user/group
  *
  * @param array $_course
  * @param string $path
  * @param int $to_group_id
  * @param int $to_user_id
  * @param boolean $can_see_invisible
  * @param boolean $search
  * @return array with all document data
  */
 public static function get_all_document_data($_course, $path = '/', $to_group_id = 0, $to_user_id = null, $can_see_invisible = false, $search = false)
 {
     $TABLE_ITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
     $TABLE_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
     $userGroupFilter = '';
     if (!is_null($to_user_id)) {
         $to_user_id = intval($to_user_id);
         $userGroupFilter = "last.to_user_id = {$to_user_id}";
         if (empty($to_user_id)) {
             $userGroupFilter = " (last.to_user_id = 0 OR last.to_user_id IS NULL) ";
         }
     } else {
         $to_group_id = intval($to_group_id);
         $userGroupFilter = "last.to_group_id = {$to_group_id}";
         if (empty($to_group_id)) {
             $userGroupFilter = "( last.to_group_id = 0 OR last.to_group_id IS NULL) ";
         }
     }
     // Escape underscores in the path so they don't act as a wildcard
     $originalPath = $path;
     $path = str_replace('_', '\\_', $path);
     $visibility_bit = ' <> 2';
     // The given path will not end with a slash, unless it's the root '/'
     // so no root -> add slash
     $added_slash = $path == '/' ? '' : '/';
     // Condition for the session
     $sessionId = api_get_session_id();
     $condition_session = " AND (last.session_id = '{$sessionId}' OR (last.session_id = '0' OR last.session_id IS NULL) )";
     $condition_session .= self::getSessionFolderFilters($originalPath, $sessionId);
     $sharedCondition = null;
     if ($originalPath == '/shared_folder') {
         $students = CourseManager::get_user_list_from_course_code($_course['code'], $sessionId);
         if (!empty($students)) {
             $conditionList = array();
             foreach ($students as $studentId => $studentInfo) {
                 $conditionList[] = '/shared_folder/sf_user_' . $studentInfo['user_id'];
             }
             $sharedCondition .= ' AND docs.path IN ("' . implode('","', $conditionList) . '")';
         }
     }
     $sql = "SELECT\n                    docs.id,\n                    docs.filetype,\n                    docs.path,\n                    docs.title,\n                    docs.comment,\n                    docs.size,\n                    docs.readonly,\n                    docs.session_id,\n                    last.session_id item_property_session_id,\n                    last.lastedit_date,\n                    last.visibility,\n                    last.insert_user_id\n                FROM {$TABLE_ITEMPROPERTY} AS last\n                INNER JOIN {$TABLE_DOCUMENT} AS docs\n                ON (\n                    docs.id = last.ref AND\n                    last.tool = '" . TOOL_DOCUMENT . "' AND\n                    docs.c_id = {$_course['real_id']} AND\n                    last.c_id = {$_course['real_id']}\n                )\n                WHERE\n                    docs.path LIKE '" . Database::escape_string($path . $added_slash . '%') . "' AND\n                    docs.path NOT LIKE '" . Database::escape_string($path . $added_slash . '%/%') . "' AND\n                    docs.path NOT LIKE '%_DELETED_%' AND\n                    {$userGroupFilter} AND\n                    last.visibility {$visibility_bit}\n                    {$condition_session}\n                    {$sharedCondition}\n                ";
     $result = Database::query($sql);
     $doc_list = array();
     $document_data = array();
     $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
     $isCoach = api_is_coach();
     if ($result !== false && Database::num_rows($result) != 0) {
         while ($row = Database::fetch_array($result, 'ASSOC')) {
             if ($isCoach) {
                 // Looking for course items that are invisible to hide it in the session
                 if (in_array($row['id'], array_keys($doc_list))) {
                     if ($doc_list[$row['id']]['item_property_session_id'] == 0 && $doc_list[$row['id']]['session_id'] == 0) {
                         if ($doc_list[$row['id']]['visibility'] == 0) {
                             unset($document_data[$row['id']]);
                             continue;
                         }
                     }
                 }
                 $doc_list[$row['id']] = $row;
             }
             if (!$isCoach && !$is_allowed_to_edit) {
                 $doc_list[] = $row;
             }
             if ($row['filetype'] == 'file' && pathinfo($row['path'], PATHINFO_EXTENSION) == 'html') {
                 // Templates management
                 $table_template = Database::get_main_table(TABLE_MAIN_TEMPLATES);
                 $sql = "SELECT id FROM {$table_template}\n                            WHERE\n                                course_code = '" . $_course['code'] . "' AND\n                                user_id = '" . api_get_user_id() . "' AND\n                                ref_doc = '" . $row['id'] . "'";
                 $template_result = Database::query($sql);
                 $row['is_template'] = Database::num_rows($template_result) > 0 ? 1 : 0;
             }
             // Just filling $document_data.
             $document_data[$row['id']] = $row;
         }
         // Only for the student we filter the results see BT#1652
         if (!$isCoach && !$is_allowed_to_edit) {
             $ids_to_remove = array();
             $my_repeat_ids = $temp = array();
             // Selecting repeated ids
             foreach ($doc_list as $row) {
                 if (in_array($row['id'], array_keys($temp))) {
                     $my_repeat_ids[] = $row['id'];
                 }
                 $temp[$row['id']] = $row;
             }
             //@todo use the DocumentManager::is_visible function
             // Checking visibility in a session
             foreach ($my_repeat_ids as $id) {
                 foreach ($doc_list as $row) {
                     if ($id == $row['id']) {
                         if ($row['visibility'] == 0 && $row['item_property_session_id'] == 0) {
                             $delete_repeated[$id] = true;
                         }
                         if ($row['visibility'] == 0 && $row['item_property_session_id'] != 0) {
                             $delete_repeated[$id] = true;
                         }
                     }
                 }
             }
             foreach ($doc_list as $key => $row) {
                 if (in_array($row['visibility'], array('0', '2')) && !in_array($row['id'], $my_repeat_ids)) {
                     $ids_to_remove[] = $row['id'];
                     unset($doc_list[$key]);
                 }
             }
             foreach ($document_data as $row) {
                 if (in_array($row['id'], $ids_to_remove)) {
                     unset($document_data[$row['id']]);
                 }
                 if (isset($delete_repeated[$row['id']]) && $delete_repeated[$row['id']]) {
                     unset($document_data[$row['id']]);
                 }
             }
             // Checking parents visibility.
             $final_document_data = array();
             foreach ($document_data as $row) {
                 $is_visible = DocumentManager::check_visibility_tree($row['id'], $_course['code'], $sessionId, api_get_user_id(), $to_group_id);
                 if ($is_visible) {
                     $final_document_data[$row['id']] = $row;
                 }
             }
         } else {
             $final_document_data = $document_data;
         }
         return $final_document_data;
     } else {
         return false;
     }
 }
Exemplo n.º 24
0
                </table>
            </div>
        </div>';
    }
    $my_list = CourseHome::get_tools_category(TOOL_AUTHORING);
    $items = CourseHome::show_tools_category($my_list);
    $content .= return_block(get_lang('Authoring'), $items, 'course-tools-author');
    $my_list = CourseHome::get_tools_category(TOOL_INTERACTION);
    $list2 = CourseHome::get_tools_category(TOOL_COURSE_PLUGIN);
    $my_list = array_merge($my_list, $list2);
    $items = CourseHome::show_tools_category($my_list);
    $content .= return_block(get_lang('Interaction'), $items, 'course-tools-interaction');
    $my_list = CourseHome::get_tools_category(TOOL_ADMIN_PLATFORM);
    $items = CourseHome::show_tools_category($my_list);
    $content .= return_block(get_lang('Administration'), $items, 'course-tools-administration');
} elseif (api_is_coach()) {
    $content .= $pluginExtra;
    if (api_get_setting('show_session_data') == 'true' && $session_id > 0) {
        $content .= '<div class="row">
            <div class="col-xs-12 col-md-12">
			<span class="viewcaption">' . get_lang('SessionData') . '</span>
			<table class="course_activity_home">';
        $content .= CourseHome::show_session_data($session_id);
        $content .= '</table></div></div>';
    }
    $content .= '<div class="row">';
    $my_list = CourseHome::get_tools_category(TOOL_STUDENT_VIEW);
    $content .= CourseHome::show_tools_category($my_list);
    $content .= '</div>';
    $sessionsCopy = api_get_setting('session.allow_session_course_copy_for_teachers');
    if ($sessionsCopy === 'true') {
 /**
  * It's used for controlling attendace sheet (list, add),
  * render to attendance_sheet view
  * @param string action
  * @param int	 attendance id
  */
 public function attendance_sheet($action, $attendance_id, $user_id = 0, $edit = true)
 {
     $attendance = new Attendance();
     $data = array();
     $data['attendance_id'] = $attendance_id;
     $data['attendance_obj'] = $attendance;
     $data['attendance_states'] = $attendance->get_attendance_states();
     $data['users_in_course'] = $attendance->get_users_rel_course($attendance_id);
     $filter_type = 'today';
     if (!empty($user_id)) {
         $user_id = intval($user_id);
     } else {
         $user_id = api_get_user_id();
     }
     if (!empty($_REQUEST['filter'])) {
         $filter_type = $_REQUEST['filter'];
     }
     if ($edit == true) {
         if (api_is_allowed_to_edit(null, true)) {
             $data['users_presence'] = $attendance->get_users_attendance_sheet($attendance_id);
         }
     } else {
         if (api_is_allowed_to_edit(null, true) || api_is_coach(api_get_session_id(), api_get_course_int_id())) {
             $data['users_presence'] = $attendance->get_users_attendance_sheet($attendance_id);
         } else {
             $data['users_presence'] = $attendance->get_users_attendance_sheet($attendance_id, $user_id);
         }
         $data['faults'] = $attendance->get_faults_of_user($user_id, $attendance_id);
         $data['user_id'] = $user_id;
     }
     $data['next_attendance_calendar_id'] = $attendance->get_next_attendance_calendar_id($attendance_id);
     $data['next_attendance_calendar_datetime'] = $attendance->get_next_attendance_calendar_datetime($attendance_id);
     if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
         if (isset($_POST['hidden_input'])) {
             $columns_to_update = $_POST['hidden_input'];
             $columns_to_update = array_unique(array_filter($columns_to_update));
             foreach ($columns_to_update as $cal_id) {
                 $users_result = array();
                 if (isset($_POST['check_presence'][$cal_id])) {
                     $users_result = $_POST['check_presence'][$cal_id];
                 }
                 $user_final_results = array();
                 if (!empty($users_result)) {
                     foreach ($users_result as $result) {
                         //Example: state_1_link_2_12_3  ==> state_[stateid]_YY_[userid]_calid
                         $user_status = explode('_', $result);
                         if (isset($user_status[0]) && $user_status[0] == 'state' && isset($user_status[4]) && isset($user_status[1])) {
                             $user_final_results[$user_status[4]] = $user_status[1];
                         }
                     }
                 }
                 if (!empty($user_final_results)) {
                     $attendance->attendance_sheet_add($cal_id, $user_final_results, $attendance_id, false, true);
                 }
             }
         }
         $data['users_in_course'] = $attendance->get_users_rel_course($attendance_id);
         $my_calendar_id = null;
         if (is_numeric($filter_type)) {
             $my_calendar_id = $filter_type;
             $filter_type = 'calendar_id';
         }
         $data['attendant_calendar'] = $attendance->get_attendance_calendar($attendance_id, $filter_type, $my_calendar_id);
         $data['attendant_calendar_all'] = $attendance->get_attendance_calendar($attendance_id);
         $data['users_presence'] = $attendance->get_users_attendance_sheet($attendance_id);
         $data['next_attendance_calendar_id'] = $attendance->get_next_attendance_calendar_id($attendance_id);
         $data['next_attendance_calendar_datetime'] = $attendance->get_next_attendance_calendar_datetime($attendance_id);
     } else {
         $data['attendant_calendar_all'] = $attendance->get_attendance_calendar($attendance_id);
         $data['attendant_calendar'] = $attendance->get_attendance_calendar($attendance_id, $filter_type);
     }
     $data['edit_table'] = intval($edit);
     $data['is_locked_attendance'] = $attendance->is_locked_attendance($attendance_id);
     $this->view->set_data($data);
     $this->view->set_layout('layout');
     $this->view->set_template('attendance_sheet');
     $this->view->render();
 }
Exemplo n.º 26
0
}
/*	TOOLS VISIBLE FOR EVERYBODY */
$content .= '<div class="everybodyview">';
$content .= '<table width="100%">';
$content .= CourseHome::show_tool_2column(TOOL_PUBLIC);
$content .= '</table>';
$content .= '</div>';
/*	COURSE ADMIN ONLY VIEW */
// Start of tools for CourseAdmins (teachers/tutors)
if (api_is_allowed_to_edit(null, true) && !api_is_coach()) {
    $content .= "<div class=\"courseadminview\">";
    $content .= "<span class=\"viewcaption\">";
    $content .= get_lang('CourseAdminOnly');
    $content .= "</span>";
    $content .= "<table width=\"100%\">";
    $content .= CourseHome::show_tool_2column(TOOL_COURSE_ADMIN);
    /*	INACTIVE TOOLS - HIDDEN (GREY) LINKS */
    $content .= "<tr><td colspan=\"4\"><hr style='color:\"#4171B5\"' noshade=\"noshade\" size=\"1\" /></td></tr>\n" . "<tr>\n" . "<td colspan=\"4\">\n" . "<div style=\"margin-bottom: 10px;\"><font color=\"#808080\">\n" . get_lang('InLnk') . "</font></div>" . "</td>\n" . "</tr>";
    $content .= CourseHome::show_tool_2column(TOOL_PUBLIC_BUT_HIDDEN);
    $content .= "</table>";
    $content .= "</div> ";
}
/*	Tools for platform admin only */
if (api_is_platform_admin() && api_is_allowed_to_edit(null, true) && !api_is_coach()) {
    $content .= '<div class="platformadminview">
	<span class="viewcaption">' . get_lang('PlatformAdminOnly') . '</span>
	<table width="100%">
		' . CourseHome::show_tool_2column(TOOL_PLATFORM_ADMIN) . '
	</table>
	</div>';
}
Exemplo n.º 27
0
 /**
  * Checks whether a user is teacher in the current course
  * @return bool True if the user can be considered a teacher in this course, false otherwise
  */
 public function isTeacher()
 {
     return api_is_course_admin() || api_is_coach() || api_is_platform_admin();
 }
Exemplo n.º 28
0
    'admin',
    'gradebook',
    'tracking'
);

require_once '../inc/global.inc.php';
$current_course_tool  = TOOL_STUDENTPUBLICATION;

api_protect_course_script(true);

// Including necessary files
require_once 'work.lib.php';
$this_section = SECTION_COURSES;

$workId = isset($_GET['id']) ? intval($_GET['id']) : null;
$is_allowed_to_edit = api_is_allowed_to_edit() || api_is_coach();

if (empty($workId)) {
    api_not_allowed(true);
}

$my_folder_data = get_work_data_by_id($workId);
if (empty($my_folder_data)) {
    api_not_allowed(true);
}

$work_data = get_work_assignment_by_id($workId);

$isDrhOfCourse = CourseManager::isUserSubscribedInCourseAsDrh(
    api_get_user_id(),
    api_get_course_info()
Exemplo n.º 29
0
    $nameTools = get_lang('StudentScore');
    $interbreadcrumb[] = array("url" => "exercise.php?" . api_get_cidreq(), "name" => get_lang('Exercises'));
    $objExerciseTmp = new Exercise();
    if ($objExerciseTmp->read($exercise_id)) {
        $interbreadcrumb[] = array("url" => "admin.php?exerciseId=" . $exercise_id . "&" . api_get_cidreq(), "name" => $objExerciseTmp->name);
    }
} else {
    $interbreadcrumb[] = array("url" => "exercise.php?" . api_get_cidreq(), "name" => get_lang('Exercises'));
    $objExerciseTmp = new Exercise();
    if ($objExerciseTmp->read($exercise_id)) {
        $nameTools = get_lang('Results') . ': ' . $objExerciseTmp->name;
    }
}
Display::display_header($nameTools);
// Clean all results for this test before the selected date
if (($is_allowedToEdit || $is_tutor || api_is_coach()) && isset($_GET['delete_before_date']) && $locked == false) {
    // ask for the date
    $check = Security::check_token('get');
    if ($check) {
        $objExerciseTmp = new Exercise();
        if ($objExerciseTmp->read($exercise_id)) {
            $count = $objExerciseTmp->clean_results(true, $_GET['delete_before_date'] . ' 23:59:59');
            Display::display_confirmation_message(sprintf(get_lang('XResultsCleaned'), $count));
        }
    }
}
// Security token to protect deletion
$token = Security::get_token();
$actions = Display::div($actions, array('class' => 'actions'));
$extra = '<script>
    $(document).ready(function() {
Exemplo n.º 30
0
 /**
  * @param int $user_id
  * @param string $filter current|history
  * @param int $page
  * @return bool|null|string
  */
 public function returnSessions($user_id, $filter, $page)
 {
     if (empty($user_id)) {
         return false;
     }
     $loadHistory = isset($filter) && $filter == 'history' ? true : false;
     /*$app['session_menu'] = function ($app) use ($loadHistory) {
                 $menu = $app['knp_menu.factory']->createItem(
                     'root',
                     array(
                         'childrenAttributes' => array(
                             'class'        => 'nav nav-tabs',
                             'currentClass' => 'active'
                         )
                     )
                 );
     
                 $current = $menu->addChild(
                     get_lang('Current'),
                     array(
                         'route'           => 'userportal',
                         'routeParameters' => array(
                             'filter' => 'current',
                             'type'   => 'sessions'
                         )
                     )
                 );
                 $history = $menu->addChild(
                     get_lang('HistoryTrainingSession'),
                     array(
                         'route'           => 'userportal',
                         'routeParameters' => array(
                             'filter' => 'history',
                             'type'   => 'sessions'
                         )
                     )
                 );
                 //@todo use URIVoter
                 if ($loadHistory) {
                     $history->setCurrent(true);
                 } else {
                     $current->setCurrent(true);
                 }
     
                 return $menu;
             };*/
     //@todo move this in template
     //$app['knp_menu.menus'] = array('actions_menu' => 'session_menu');
     $start = ($page - 1) * $this->maxPerPage;
     if ($loadHistory) {
         // Load sessions in category in *history*.
         $nbResults = (int) UserManager::get_sessions_by_category($user_id, true, true, true, null, null, 'no_category');
         $session_categories = UserManager::get_sessions_by_category($user_id, true, false, true, $start, $this->maxPerPage, 'no_category');
     } else {
         // Load sessions in category.
         $nbResults = (int) UserManager::get_sessions_by_category($user_id, false, true, false, null, null, 'no_category');
         $session_categories = UserManager::get_sessions_by_category($user_id, false, false, false, $start, $this->maxPerPage, 'no_category');
     }
     $html = null;
     // Showing history title
     if ($loadHistory) {
         // $html .= Display::page_subheader(get_lang('HistoryTrainingSession'));
         if (empty($session_categories)) {
             $html .= get_lang('YouDoNotHaveAnySessionInItsHistory');
         }
     }
     $load_directories_preview = api_get_setting('document.show_documents_preview') == 'true' ? true : false;
     $sessions_with_no_category = $html;
     if (isset($session_categories) && !empty($session_categories)) {
         foreach ($session_categories as $session_category) {
             $session_category_id = $session_category['session_category']['id'];
             // Sessions does not belong to a session category
             if ($session_category_id == 0) {
                 // Independent sessions
                 if (isset($session_category['sessions'])) {
                     foreach ($session_category['sessions'] as $session) {
                         $session_id = $session['session_id'];
                         // Don't show empty sessions.
                         if (count($session['courses']) < 1) {
                             continue;
                         }
                         // Courses inside the current session.
                         $date_session_start = $session['access_start_date'];
                         $date_session_end = $session['access_end_date'];
                         $coachAccessStartDate = $session['coach_access_start_date'];
                         $coachAccessEndDate = $session['coach_access_end_date'];
                         $session_now = time();
                         $count_courses_session = 0;
                         $count_courses_session = 0;
                         // Loop course content
                         $html_courses_session = [];
                         $atLeastOneCourseIsVisible = false;
                         foreach ($session['courses'] as $course) {
                             $is_coach_course = api_is_coach($session_id, $course['real_id']);
                             $allowed_time = 0;
                             // Read only and accessible
                             if (api_get_setting('session.hide_courses_in_sessions') == 'false') {
                                 $courseUserHtml = CourseManager::get_logged_user_course_html($course, $session_id, $load_directories_preview);
                                 if (isset($courseUserHtml[1])) {
                                     $course_session = $courseUserHtml[1];
                                     $course_session['skill'] = isset($courseUserHtml['skill']) ? $courseUserHtml['skill'] : '';
                                     $html_courses_session[] = $course_session;
                                 }
                             }
                             $count_courses_session++;
                         }
                         if ($count_courses_session > 0) {
                             $params = array();
                             $params['icon'] = Display::return_icon('window_list.png', $session['session_name'], array('id' => 'session_img_' . $session_id), ICON_SIZE_LARGE);
                             $params['is_session'] = true;
                             //Default session name
                             $session_link = $session['session_name'];
                             $params['link'] = null;
                             if (api_get_setting('session.session_page_enabled') == 'true' && !api_is_drh()) {
                                 //session name with link
                                 $session_link = Display::tag('a', $session['session_name'], array('href' => api_get_path(WEB_CODE_PATH) . 'session/index.php?session_id=' . $session_id));
                                 $params['link'] = api_get_path(WEB_CODE_PATH) . 'session/index.php?session_id=' . $session_id;
                             }
                             $params['title'] = $session_link;
                             $moved_status = \SessionManager::get_session_change_user_reason($session['moved_status']);
                             $moved_status = isset($moved_status) && !empty($moved_status) ? ' (' . $moved_status . ')' : null;
                             $params['subtitle'] = isset($session['coach_info']) ? $session['coach_info']['complete_name'] : null . $moved_status;
                             $params['dates'] = $session['date_message'];
                             $params['right_actions'] = '';
                             if (api_is_platform_admin()) {
                                 $params['right_actions'] .= Display::url(Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'), ICON_SIZE_SMALL), api_get_path(WEB_CODE_PATH) . 'session/resume_session.php?id_session=' . $session_id);
                             }
                             if (api_get_setting('session.hide_courses_in_sessions') == 'false') {
                                 //    $params['extra'] .=  $html_courses_session;
                             }
                             $courseDataToString = CourseManager::parseCourseListData($html_courses_session);
                             $sessions_with_no_category .= CourseManager::course_item_parent(CourseManager::course_item_html($params, true), $courseDataToString);
                         }
                     }
                 }
             }
         }
         /*$adapter = new FixedAdapter($nbResults, array());
                     $pagerfanta = new Pagerfanta($adapter);
                     $pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default
                     $pagerfanta->setCurrentPage($page); // 1 by default
         
                     $this->app['pagerfanta.view.router.name']   = 'userportal';
                     $this->app['pagerfanta.view.router.params'] = array(
                         'filter' => $filter,
                         'type'   => 'sessions',
                         'page'   => $page
                     );
                     $this->app['template']->assign('pagination', $pagerfanta);*/
     }
     return $sessions_with_no_category;
 }