$form->addElement('radio', 'export_format', null, get_lang('ExportAsCSV'), 'csv', array('id' => 'export_format_csv_label'));
$form->addElement('radio', 'export_format', null, get_lang('ExportAsXLS'), 'xls', array('id' => 'export_format_xls_label'));
$form->addElement('checkbox', 'load_extra_data', null, get_lang('LoadExtraData'), '0', array('id' => 'export_format_xls_label'));
$form->addElement('checkbox', 'include_all_users', null, get_lang('IncludeAllUsers'), '0');
$form->addElement('checkbox', 'only_best_attempts', null, get_lang('OnlyBestAttempts'), '0');
$form->setDefaults(array('export_format' => 'csv'));
$extra .= $form->return_form();
$extra .= '</div>';
if ($is_allowedToEdit) {
    echo $extra;
}
echo $actions;
$url = api_get_path(WEB_AJAX_PATH) . 'model.ajax.php?a=get_exercise_results&exerciseId=' . $exercise_id . '&filter_by_user='******'&' . api_get_cidreq();
$action_links = '';
//Generating group list
$group_list = GroupManager::get_group_list();
$group_parameters = array('group_all:' . get_lang('All'), 'group_none:' . get_lang('None'));
foreach ($group_list as $group) {
    $group_parameters[] = $group['id'] . ':' . $group['name'];
}
if (!empty($group_parameters)) {
    $group_parameters = implode(';', $group_parameters);
}
$officialCodeInList = api_get_setting('exercise.show_official_code_exercise_result_list');
if ($is_allowedToEdit || $is_tutor) {
    // The order is important you need to check the the $column variable in the model.ajax.php file
    $columns = array(get_lang('FirstName'), get_lang('LastName'), get_lang('LoginName'), get_lang('Group'), get_lang('Duration') . ' (' . get_lang('MinMinute') . ')', get_lang('StartDate'), get_lang('EndDate'), get_lang('Score'), get_lang('IP'), get_lang('Status'), get_lang('ToolLearnpath'), get_lang('Actions'));
    if ($officialCodeInList === 'true') {
        $columns = array_merge(array(get_lang('OfficialCode')), $columns);
    }
    //Column config
Esempio n. 2
0
*/
// Step 1: We store all the forum categories in an array $forum_categories.
$forumCategories = get_forum_categories();
// Step 2: We find all the forums (only the visible ones if it is a student).
// display group forum in general forum tool depending to configuration option
$setting = api_get_setting('display_groups_forum_in_general_tool');
$forum_list = get_forums('', '', $setting == 'true');
$user_id = api_get_user_id();
/* RETRIEVING ALL GROUPS AND THOSE OF THE USER */
// The groups of the user.
$groups_of_user = array();
$groups_of_user = GroupManager::get_group_ids($_course['real_id'], $user_id);
// All groups in the course (and sorting them as the
// id of the group = the key of the array).
if (!api_is_anonymous()) {
    $all_groups = GroupManager::get_group_list();
    if (is_array($all_groups)) {
        foreach ($all_groups as $group) {
            $all_groups[$group['id']] = $group;
        }
    }
}
/* CLEAN GROUP ID FOR AJAXFILEMANAGER */
if (isset($_SESSION['_gid'])) {
    unset($_SESSION['_gid']);
}
/* ACTION LINKS */
echo '<div class="actions">';
//if is called from learning path
if (!empty($_GET['lp_id']) || !empty($_POST['lp_id'])) {
    echo "<a href=\"../newscorm/lp_controller.php?" . api_get_cidreq() . "&gradebook=&action=add_item&type=step&lp_id={$lp_id}#resource_tab-5\">" . Display::return_icon('back.png', get_lang("BackTo") . ' ' . get_lang("LearningPaths"), '', ICON_SIZE_MEDIUM) . "</a>";
Esempio n. 3
0
 /**
  * @param int $courseId
  * @param string $keyword
  * @return string
  */
 public static function getOverview($courseId, $keyword = null)
 {
     $content = null;
     $categories = GroupManager::get_categories();
     if (!empty($categories)) {
         foreach ($categories as $category) {
             if (api_get_setting('allow_group_categories') == 'true') {
                 $content .= '<h2>' . $category['title'] . '</h2>';
             }
             if (!empty($keyword)) {
                 $groups = GroupManager::getGroupListFilterByName($keyword, $category['id'], $courseId);
             } else {
                 $groups = GroupManager::get_group_list($category['id']);
             }
             $content .= '<ul>';
             if (!empty($groups)) {
                 foreach ($groups as $group) {
                     $content .= '<li>';
                     $content .= Display::tag('h3', Security::remove_XSS($group['name']));
                     $users = GroupManager::getTutors($group['id']);
                     if (!empty($users)) {
                         $content .= '<ul>';
                         $content .= "<li>" . Display::tag('h4', get_lang('Tutors')) . "</li><ul>";
                         foreach ($users as $user) {
                             $user_info = api_get_user_info($user['user_id']);
                             $content .= '<li title="' . $user_info['username'] . '">' . $user_info['complete_name_with_username'] . '</li>';
                         }
                         $content .= '</ul>';
                         $content .= '</ul>';
                     }
                     $users = GroupManager::getStudents($group['id']);
                     if (!empty($users)) {
                         $content .= '<ul>';
                         $content .= "<li>" . Display::tag('h4', get_lang('Students')) . "</li><ul>";
                         foreach ($users as $user) {
                             $user_info = api_get_user_info($user['user_id']);
                             $content .= '<li title="' . $user_info['username'] . '">' . $user_info['complete_name_with_username'] . '</li>';
                         }
                         $content .= '</ul>';
                         $content .= '</ul>';
                     }
                     $content .= '</li>';
                 }
             }
             $content .= '</ul>';
         }
     }
     return $content;
 }
Esempio n. 4
0
 /**
  * @param int $start
  * @param int $end
  * @param array $courseInfo
  * @param int $groupId
  * @param int $session_id
  * @param int $user_id
  * @param string $color
  *
  * @return array
  */
 public function getCourseEvents($start, $end, $courseInfo, $groupId = 0, $session_id = 0, $user_id = 0, $color = '')
 {
     $start = isset($start) && !empty($start) ? api_get_utc_datetime(intval($start)) : null;
     $end = isset($end) && !empty($end) ? api_get_utc_datetime(intval($end)) : null;
     if (empty($courseInfo)) {
         return array();
     }
     $course_id = $courseInfo['real_id'];
     if (empty($course_id)) {
         return array();
     }
     $session_id = intval($session_id);
     $user_id = intval($user_id);
     $groupList = GroupManager::get_group_list(null, $courseInfo['code']);
     $group_name_list = array();
     if (!empty($groupList)) {
         foreach ($groupList as $group) {
             $group_name_list[$group['id']] = $group['name'];
         }
     }
     $group_memberships = [];
     if (!empty($groupId)) {
         if (!api_is_allowed_to_edit()) {
             $user_id = api_get_user_id();
             $group_memberships = GroupManager::get_group_ids($course_id, $user_id);
         } else {
             $group_memberships = GroupManager::get_group_ids($course_id, $user_id);
         }
     } else {
         // if no group was defined but I am a student reviewing his agenda,
         // group events should show, so we should fetch those groups to which
         // I belong
         if (!api_is_allowed_to_edit()) {
             $user_id = api_get_user_id();
             $group_memberships = GroupManager::get_group_ids($course_id, $user_id);
         } else {
             // If no group was defined and I am a teacher/admin reviewing
             // someone else's agenda, we should fetch this person's groups
             $group_memberships = GroupManager::get_group_ids($course_id, $user_id);
         }
     }
     $tlb_course_agenda = Database::get_course_table(TABLE_AGENDA);
     $tbl_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
     if (!empty($groupId)) {
         $group_memberships = array($groupId);
     }
     if (is_array($group_memberships) && count($group_memberships) > 0) {
         if (api_is_allowed_to_edit()) {
             if (!empty($groupId)) {
                 $where_condition = "( ip.to_group_id IN (" . implode(", ", $group_memberships) . ") ) ";
             } else {
                 if (!empty($user_id)) {
                     $where_condition = "( ip.to_user_id = {$user_id} OR ip.to_user_id IS NULL OR (ip.to_group_id IN (0, " . implode(", ", $group_memberships) . ")) ) ";
                 } else {
                     $where_condition = "( ip.to_group_id IN (0, " . implode(", ", $group_memberships) . ") ) ";
                 }
             }
         } else {
             $where_condition = "( ip.to_user_id = {$user_id} OR ip.to_user_id IS NULL OR (ip.to_group_id IN (0, " . implode(", ", $group_memberships) . ")) ) ";
         }
         $sessionCondition = '';
         if (empty($session_id)) {
             $sessionCondition = "\n                (\n                    agenda.session_id = 0 AND\n                    ip.session_id IS NULL\n                ) ";
         } else {
             $sessionCondition = "\n                (\n                    agenda.session_id = {$session_id} AND\n                    ip.session_id = {$session_id}\n                ) ";
         }
         $sql = "SELECT DISTINCT\n                        agenda.*,\n                        ip.visibility,\n                        ip.to_group_id,\n                        ip.insert_user_id,\n                        ip.ref,\n                        to_user_id\n                    FROM {$tlb_course_agenda} agenda\n                    INNER JOIN {$tbl_property} ip\n                    ON (agenda.id = ip.ref AND agenda.c_id = ip.c_id)\n                    WHERE\n                        ip.tool = '" . TOOL_CALENDAR_EVENT . "' AND\n                        {$where_condition} AND\n                        ip.visibility = '1' AND\n                        agenda.c_id = {$course_id} AND\n                        ip.c_id = agenda.c_id AND\n                        {$sessionCondition}\n                    ";
     } else {
         $visibilityCondition = " ip.visibility='1' AND ";
         $sessionCondition = '';
         if (api_is_allowed_to_edit()) {
             if ($user_id == 0) {
                 $where_condition = "";
             } else {
                 $where_condition = " (ip.to_user_id = " . $user_id . " OR ip.to_user_id IS NULL) AND ip.to_group_id IS NULL AND ";
             }
             $visibilityCondition = " (ip.visibility IN ('1', '0')) AND ";
         } else {
             $where_condition = " ( (ip.to_user_id = " . api_get_user_id() . " OR ip.to_user_id IS NULL) AND ip.to_group_id IS NULL) AND ";
         }
         if (empty($session_id)) {
             $sessionCondition = "\n                (\n                    agenda.session_id = 0 AND\n                    ip.session_id IS NULL\n                ) ";
         } else {
             $sessionCondition = "\n                (\n                    agenda.session_id = {$session_id} AND\n                    ip.session_id = {$session_id}\n                ) ";
         }
         $sql = "SELECT DISTINCT\n                        agenda.*,\n                        ip.visibility,\n                        ip.to_group_id,\n                        ip.insert_user_id,\n                        ip.ref,\n                        to_user_id\n                    FROM {$tlb_course_agenda} agenda\n                    INNER JOIN {$tbl_property} ip\n                    ON (agenda.id = ip.ref AND agenda.c_id = ip.c_id)\n                    WHERE\n                        ip.tool='" . TOOL_CALENDAR_EVENT . "' AND\n                        {$where_condition}\n                        {$visibilityCondition}\n                        agenda.c_id = {$course_id} AND\n                        {$sessionCondition}\n                    ";
     }
     $dateCondition = null;
     if (!empty($start) && !empty($end)) {
         $dateCondition .= "AND (\n                 agenda.start_date BETWEEN '" . $start . "' AND '" . $end . "' OR\n                 agenda.end_date BETWEEN '" . $start . "' AND '" . $end . "' OR\n                 (\n                     agenda.start_date IS NOT NULL AND agenda.end_date IS NOT NULL AND\n                     YEAR(agenda.start_date) = YEAR(agenda.end_date) AND\n                     MONTH('{$start}') BETWEEN MONTH(agenda.start_date) AND MONTH(agenda.end_date)\n                 )\n            )";
     }
     $sql .= $dateCondition;
     $result = Database::query($sql);
     $coachCanEdit = false;
     if (!empty($session_id)) {
         $coachCanEdit = api_is_coach($session_id, $course_id);
     }
     if (Database::num_rows($result)) {
         $eventsAdded = array_column($this->events, 'unique_id');
         while ($row = Database::fetch_array($result, 'ASSOC')) {
             $eventId = $row['ref'];
             $items = $this->getUsersAndGroupSubscribedToEvent($eventId, $course_id, $this->sessionId);
             $group_to_array = $items['groups'];
             $user_to_array = $items['users'];
             $event = array();
             $event['id'] = 'course_' . $row['id'];
             $event['unique_id'] = 'course_' . $row['id'] . intval($row['session_id']);
             // To avoid doubles
             if (in_array($event['unique_id'], $eventsAdded)) {
                 continue;
             }
             $eventsAdded[] = $event['unique_id'];
             $attachment = $this->getAttachment($row['id'], $courseInfo);
             if (!empty($attachment)) {
                 $has_attachment = Display::return_icon('attachment.gif', get_lang('Attachment'));
                 $user_filename = $attachment['filename'];
                 $url = api_get_path(WEB_CODE_PATH) . 'calendar/download.php?file=' . $attachment['path'] . '&course_id=' . $course_id . '&' . api_get_cidreq();
                 $event['attachment'] = $has_attachment . Display::url($user_filename, $url);
             } else {
                 $event['attachment'] = '';
             }
             $event['title'] = $row['title'];
             $event['className'] = 'course';
             $event['allDay'] = 'false';
             $event['course_id'] = $course_id;
             $event['borderColor'] = $event['backgroundColor'] = $this->event_course_color;
             $sessionInfo = [];
             if (isset($row['session_id']) && !empty($row['session_id'])) {
                 $sessionInfo = api_get_session_info($session_id);
                 $event['borderColor'] = $event['backgroundColor'] = $this->event_session_color;
             }
             $event['session_name'] = isset($sessionInfo['name']) ? $sessionInfo['name'] : '';
             $event['course_name'] = isset($courseInfo['title']) ? $courseInfo['title'] : '';
             if (isset($row['to_group_id']) && !empty($row['to_group_id'])) {
                 $event['borderColor'] = $event['backgroundColor'] = $this->event_group_color;
             }
             if (!empty($color)) {
                 $event['borderColor'] = $event['backgroundColor'] = $color;
             }
             if (isset($row['color']) && !empty($row['color'])) {
                 $event['borderColor'] = $event['backgroundColor'] = $row['color'];
             }
             $event['editable'] = false;
             if (api_is_allowed_to_edit() && $this->type == 'course') {
                 $event['editable'] = true;
                 if (!empty($session_id)) {
                     if ($coachCanEdit == false) {
                         $event['editable'] = false;
                     }
                 }
             }
             if (!empty($row['start_date']) && $row['start_date'] != '0000-00-00 00:00:00') {
                 $event['start'] = $this->formatEventDate($row['start_date']);
                 $event['start_date_localtime'] = api_get_local_time($row['start_date']);
             }
             if (!empty($row['end_date']) && $row['end_date'] != '0000-00-00 00:00:00') {
                 $event['end'] = $this->formatEventDate($row['end_date']);
                 $event['end_date_localtime'] = api_get_local_time($row['end_date']);
             }
             $event['sent_to'] = '';
             $event['type'] = 'course';
             if ($row['session_id'] != 0) {
                 $event['type'] = 'session';
             }
             // Event Sent to a group?
             if (isset($row['to_group_id']) && !empty($row['to_group_id'])) {
                 $sent_to = array();
                 if (!empty($group_to_array)) {
                     foreach ($group_to_array as $group_item) {
                         $sent_to[] = $group_name_list[$group_item];
                     }
                 }
                 $sent_to = implode('@@', $sent_to);
                 $sent_to = str_replace('@@', '</div><div class="label_tag notice">', $sent_to);
                 $event['sent_to'] = '<div class="label_tag notice">' . $sent_to . '</div>';
                 $event['type'] = 'group';
             }
             //Event sent to a user?
             if (isset($row['to_user_id'])) {
                 $sent_to = array();
                 if (!empty($user_to_array)) {
                     foreach ($user_to_array as $item) {
                         $user_info = api_get_user_info($item);
                         // Add username as tooltip for $event['sent_to'] - ref #4226
                         $username = api_htmlentities(sprintf(get_lang('LoginX'), $user_info['username']), ENT_QUOTES);
                         $sent_to[] = "<span title='" . $username . "'>" . $user_info['complete_name'] . "</span>";
                     }
                 }
                 $sent_to = implode('@@', $sent_to);
                 $sent_to = str_replace('@@', '</div><div class="label_tag notice">', $sent_to);
                 $event['sent_to'] = '<div class="label_tag notice">' . $sent_to . '</div>';
             }
             //Event sent to everyone!
             if (empty($event['sent_to'])) {
                 $event['sent_to'] = '<div class="label_tag notice">' . get_lang('Everyone') . '</div>';
             }
             $event['description'] = $row['content'];
             $event['visibility'] = $row['visibility'];
             $event['real_id'] = $row['id'];
             $event['allDay'] = isset($row['all_day']) && $row['all_day'] == 1 ? $row['all_day'] : 0;
             $event['parent_event_id'] = $row['parent_event_id'];
             $event['has_children'] = $this->hasChildren($row['id'], $course_id) ? 1 : 0;
             $event['comment'] = $row['comment'];
             $this->events[] = $event;
         }
     }
     return $this->events;
 }
             }
         }
         if ($today == $attendance_date['date']) {
             $exists_attendance_today = true;
         }
         if ($includeCalendar) {
             $values[$attendance_date['id']] = $attendance_date['date_time'];
         }
     }
 }
 if (!$exists_attendance_today) {
     Display::display_warning_message(get_lang('ThereIsNoClassScheduledTodayTryPickingAnotherDay'));
 }
 $form->addSelect('filter', get_lang('Filter'), $values, ['id' => 'filter_id', 'onchange' => 'submit();']);
 //$form->addElement('select', 'filter', get_lang('Filter'), $values, array('id' => 'filter_id'));
 $groupList = GroupManager::get_group_list(null, null, 1);
 $groupIdList = array('--');
 foreach ($groupList as $group) {
     $groupIdList[$group['id']] = $group['name'];
 }
 if (!empty($groupList)) {
     $form->addSelect('group_id', get_lang('Group'), $groupIdList);
 }
 if (isset($_REQUEST['filter'])) {
     if (in_array($_REQUEST['filter'], array_keys($values))) {
         $default_filter = $_REQUEST['filter'];
     }
 } else {
     $default_filter = 'today';
 }
 $renderer = $form->defaultRenderer();
Esempio n. 6
0
 /**
  * @param string $in_name is the name and the id of the <select>
  * @param string $in_default default value for option
  * @param string $in_onchange
  * @return string the html code of the <select>
  */
 public static function displayGroupMenu($in_name, $in_default, $in_onchange = "")
 {
     // check the default value of option
     $tabSelected = array($in_default => " selected='selected' ");
     $res = "";
     $res .= "<select name='{$in_name}' id='{$in_name}' onchange='" . $in_onchange . "' >";
     $res .= "<option value='-1'" . $tabSelected["-1"] . ">-- " . get_lang('AllGroups') . " --</option>";
     $res .= "<option value='0'" . $tabSelected["0"] . ">- " . get_lang('NotInAGroup') . " -</option>";
     $tabGroups = GroupManager::get_group_list();
     $currentCatId = 0;
     for ($i = 0; $i < count($tabGroups); $i++) {
         $tabCategory = GroupManager::get_category_from_group($tabGroups[$i]["id"]);
         if ($tabCategory["id"] != $currentCatId) {
             $res .= "<option value='-1' disabled='disabled'>" . $tabCategory["title"] . "</option>";
             $currentCatId = $tabCategory["id"];
         }
         $res .= "<option " . $tabSelected[$tabGroups[$i]["id"]] . "style='margin-left:40px' value='" . $tabGroups[$i]["id"] . "'>" . $tabGroups[$i]["name"] . "</option>";
     }
     $res .= "</select>";
     return $res;
 }
Esempio n. 7
0
 /**
  * @param int $start
  * @param int $end
  * @param array $course_info
  * @param int $group_id
  * @param int $session_id
  * @param int $user_id
  * @return array
  */
 public function get_course_events($start, $end, $course_info, $group_id = 0, $session_id = 0, $user_id = 0)
 {
     $course_id = $course_info['real_id'];
     $user_id = intval($user_id);
     $group_list = GroupManager::get_group_list(null, $course_info['code']);
     $group_name_list = array();
     if (!empty($group_list)) {
         foreach ($group_list as $group) {
             $group_name_list[$group['id']] = $group['name'];
         }
     }
     if (!api_is_allowed_to_edit()) {
         $group_memberships = GroupManager::get_group_ids($course_id, api_get_user_id());
         $user_id = api_get_user_id();
     } else {
         $group_memberships = array_keys($group_name_list);
     }
     $tlb_course_agenda = Database::get_course_table(TABLE_AGENDA);
     $tbl_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
     if (!empty($group_id)) {
         $group_memberships = array($group_id);
     }
     $session_id = intval($session_id);
     if (is_array($group_memberships) && count($group_memberships) > 0) {
         if (api_is_allowed_to_edit()) {
             if (!empty($user_id)) {
                 $where_condition = "( ip.to_user_id = {$user_id} AND ip.to_group_id is null OR ip.to_group_id IN (0, " . implode(", ", $group_memberships) . ") ) ";
             } else {
                 $where_condition = "( ip.to_group_id is null OR ip.to_group_id IN (0, " . implode(", ", $group_memberships) . ") ) ";
             }
         } else {
             $where_condition = "( ip.to_user_id = {$user_id} OR ip.to_group_id IN (0, " . implode(", ", $group_memberships) . ") ) ";
         }
         $sql = "SELECT DISTINCT\n                    agenda.*,\n                    ip.visibility,\n                    ip.to_group_id,\n                    ip.insert_user_id,\n                    ip.ref,\n                    to_user_id\n                    FROM " . $tlb_course_agenda . " agenda, " . $tbl_property . " ip\n                    WHERE   agenda.id       = ip.ref  AND\n                            ip.tool         ='" . TOOL_CALENDAR_EVENT . "' AND\n                            {$where_condition} AND\n                            ip.visibility   = '1' AND\n                            agenda.c_id     = {$course_id} AND\n                            ip.c_id         = {$course_id}\n                    GROUP BY id";
     } else {
         if (api_is_allowed_to_edit()) {
             $where_condition = "";
         } else {
             $where_condition = "( ip.to_user_id={$user_id} OR ip.to_group_id='0') AND ";
         }
         $sql = "SELECT DISTINCT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref, to_user_id\n                    FROM " . $tlb_course_agenda . " agenda, " . $tbl_property . " ip\n                    WHERE   agenda.id = ip.ref AND\n                            ip.tool='" . TOOL_CALENDAR_EVENT . "' AND\n                            {$where_condition}\n                            ip.visibility='1' AND\n                            agenda.c_id = {$course_id} AND\n                            ip.c_id = {$course_id} AND\n                            agenda.session_id = {$session_id} AND\n                            ip.id_session = {$session_id}\n                    ";
     }
     $result = Database::query($sql);
     $events = array();
     if (Database::num_rows($result)) {
         $events_added = array();
         while ($row = Database::fetch_array($result, 'ASSOC')) {
             //to gather sent_tos
             $sql = "SELECT to_user_id, to_group_id\n                    FROM " . $tbl_property . " ip\n                    WHERE   ip.tool         = '" . TOOL_CALENDAR_EVENT . "' AND\n                            ref             = {$row['ref']} AND\n                            ip.visibility   = '1' AND\n                            ip.c_id         = {$course_id}";
             $sent_to_result = Database::query($sql);
             $user_to_array = array();
             $group_to_array = array();
             while ($row_send_to = Database::fetch_array($sent_to_result, 'ASSOC')) {
                 if (!empty($row_send_to['to_group_id'])) {
                     $group_to_array[] = $row_send_to['to_group_id'];
                 }
                 if (!empty($row_send_to['to_user_id'])) {
                     $user_to_array[] = $row_send_to['to_user_id'];
                 }
             }
             //Only show events from the session
             /*if (api_get_course_int_id()) {
                   if ($row['session_id'] != api_get_session_id()) {
                       continue;
                   }
               }*/
             $event = array();
             $event['id'] = 'course_' . $row['id'];
             //To avoid doubles
             if (in_array($row['id'], $events_added)) {
                 continue;
             }
             $events_added[] = $row['id'];
             $attachment = get_attachment($row['id'], $course_id);
             $has_attachment = '';
             if (!empty($attachment)) {
                 $has_attachment = Display::return_icon('attachment.gif', get_lang('Attachment'));
                 $user_filename = $attachment['filename'];
                 $full_file_name = 'download.php?file=' . $attachment['path'] . '&course_id=' . $course_id;
                 $event['attachment'] = $has_attachment . Display::url($user_filename, $full_file_name);
             } else {
                 $event['attachment'] = '';
             }
             $event['title'] = $row['title'];
             $event['className'] = 'course';
             $event['allDay'] = 'false';
             $event['course_id'] = $course_id;
             $event['borderColor'] = $event['backgroundColor'] = $this->event_course_color;
             if (isset($row['session_id']) && !empty($row['session_id'])) {
                 $event['borderColor'] = $event['backgroundColor'] = $this->event_session_color;
             }
             if (isset($row['to_group_id']) && !empty($row['to_group_id'])) {
                 $event['borderColor'] = $event['backgroundColor'] = $this->event_group_color;
             }
             $event['editable'] = false;
             if (api_is_allowed_to_edit() && $this->type == 'course') {
                 $event['editable'] = true;
             }
             if (!empty($row['start_date']) && $row['start_date'] != '0000-00-00 00:00:00') {
                 $event['start'] = $this->format_event_date($row['start_date']);
             }
             if (!empty($row['end_date']) && $row['end_date'] != '0000-00-00 00:00:00') {
                 $event['end'] = $this->format_event_date($row['end_date']);
             }
             $event['sent_to'] = '';
             //$event['type']    = $this->type;
             $event['type'] = 'course';
             if ($row['session_id'] != 0) {
                 $event['type'] = 'session';
             }
             //Event Sent to a group?
             if (isset($row['to_group_id']) && !empty($row['to_group_id'])) {
                 $sent_to = array();
                 if (!empty($group_to_array)) {
                     foreach ($group_to_array as $group_item) {
                         $sent_to[] = $group_name_list[$group_item];
                     }
                 }
                 $sent_to = implode('@@', $sent_to);
                 $sent_to = str_replace('@@', '</div><div class="label_tag notice">', $sent_to);
                 $event['sent_to'] = '<div class="label_tag notice">' . $sent_to . '</div>';
                 $event['type'] = 'group';
             }
             //Event sent to a user?
             if (isset($row['to_user_id'])) {
                 $sent_to = array();
                 if (!empty($user_to_array)) {
                     foreach ($user_to_array as $item) {
                         $user_info = api_get_user_info($item);
                         // add username as tooltip for $event['sent_to'] - ref #4226
                         $username = api_htmlentities(sprintf(get_lang('LoginX'), $user_info['username']), ENT_QUOTES);
                         $sent_to[] = "<span title='" . $username . "'>" . $user_info['complete_name'] . "</span>";
                     }
                 }
                 $sent_to = implode('@@', $sent_to);
                 $sent_to = str_replace('@@', '</div><div class="label_tag notice">', $sent_to);
                 $event['sent_to'] = '<div class="label_tag notice">' . $sent_to . '</div>';
             }
             //Event sent to everyone!
             if (empty($event['sent_to'])) {
                 $event['sent_to'] = '<div class="label_tag notice">' . get_lang('Everyone') . '</div>';
             }
             $event['description'] = $row['content'];
             $event['allDay'] = isset($row['all_day']) && $row['all_day'] == 1 ? $row['all_day'] : 0;
             $this->events[] = $event;
         }
     }
     return $this->events;
 }
/**
 * This function displays the form that is used to add a forum category.
 *
 * @param array $inputvalues
 * @param int $lp_id
 * @return void HTML
 *
 * @author Patrick Cool <*****@*****.**>, Ghent University
 * @author Juan Carlos Raña Trabado (return to lp_id)
 *
 * @version may 2011, Chamilo 1.8.8
 */
function show_add_forum_form($inputvalues = array(), $lp_id)
{
    $_course = api_get_course_info();
    // Initialize the object.
    $form = new FormValidator('forumcategory', 'post', 'index.php?' . api_get_cidreq());
    // The header for the form
    if (!empty($inputvalues)) {
        $form_title = get_lang('EditForum');
    } else {
        $form_title = get_lang('AddForum');
    }
    $session_header = Session::read('session_name');
    $form->addElement('header', $form_title . $session_header);
    // We have a hidden field if we are editing.
    if (!empty($inputvalues) && is_array($inputvalues)) {
        $my_forum_id = isset($inputvalues['forum_id']) ? $inputvalues['forum_id'] : null;
        $form->addElement('hidden', 'forum_id', $my_forum_id);
    }
    $lp_id = intval($lp_id);
    // hidden field if from learning path
    $form->addElement('hidden', 'lp_id', $lp_id);
    // The title of the forum
    $form->addElement('text', 'forum_title', get_lang('Title'), array('autofocus'));
    // The comment of the forum.
    $form->addHtmlEditor('forum_comment', get_lang('Description'), null, null, array('ToolbarSet' => 'Forum', 'Width' => '98%', 'Height' => '200'));
    // Dropdown list: Forum categories
    $forum_categories = get_forum_categories();
    foreach ($forum_categories as $key => $value) {
        $forum_categories_titles[$value['cat_id']] = $value['cat_title'];
    }
    $form->addElement('select', 'forum_category', get_lang('InForumCategory'), $forum_categories_titles);
    $form->applyFilter('forum_category', 'html_filter');
    if ($_course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD) {
        // This is for horizontal
        $group = array();
        $group[] = $form->createElement('radio', 'allow_anonymous', null, get_lang('Yes'), 1);
        $group[] = $form->createElement('radio', 'allow_anonymous', null, get_lang('No'), 0);
        $form->addGroup($group, 'allow_anonymous_group', get_lang('AllowAnonymousPosts'), ' ');
    }
    $form->addButtonAdvancedSettings('advanced_params');
    $form->addElement('html', '<div id="advanced_params_options" style="display:none">');
    $group = array();
    $group[] = $form->createElement('radio', 'students_can_edit', null, get_lang('Yes'), 1);
    $group[] = $form->createElement('radio', 'students_can_edit', null, get_lang('No'), 0);
    $form->addGroup($group, 'students_can_edit_group', get_lang('StudentsCanEdit'), ' ');
    $group = array();
    $group[] = $form->createElement('radio', 'approval_direct', null, get_lang('Approval'), 1);
    $group[] = $form->createElement('radio', 'approval_direct', null, get_lang('Direct'), 0);
    $group = array();
    $group[] = $form->createElement('radio', 'allow_attachments', null, get_lang('Yes'), 1);
    $group[] = $form->createElement('radio', 'allow_attachments', null, get_lang('No'), 0);
    $group = array();
    $group[] = $form->createElement('radio', 'allow_new_threads', null, get_lang('Yes'), 1);
    $group[] = $form->createElement('radio', 'allow_new_threads', null, get_lang('No'), 0);
    $form->addGroup($group, 'allow_new_threads_group', get_lang('AllowNewThreads'), ' ');
    $group = array();
    $group[] = $form->createElement('radio', 'default_view_type', null, get_lang('Flat'), 'flat');
    $group[] = $form->createElement('radio', 'default_view_type', null, get_lang('Threaded'), 'threaded');
    $group[] = $form->createElement('radio', 'default_view_type', null, get_lang('Nested'), 'nested');
    $form->addGroup($group, 'default_view_type_group', get_lang('DefaultViewType'), ' ');
    // Drop down list: Groups
    $groups = GroupManager::get_group_list();
    $groups_titles[0] = get_lang('NotAGroupForum');
    foreach ($groups as $key => $value) {
        $groups_titles[$value['id']] = $value['name'];
    }
    $form->addElement('select', 'group_forum', get_lang('ForGroup'), $groups_titles);
    // Public or private group forum
    $group = array();
    $group[] = $form->createElement('radio', 'public_private_group_forum', null, get_lang('Public'), 'public');
    $group[] = $form->createElement('radio', 'public_private_group_forum', null, get_lang('Private'), 'private');
    $form->addGroup($group, 'public_private_group_forum_group', get_lang('PublicPrivateGroupForum'), '');
    // Forum image
    $form->add_progress_bar();
    if (isset($inputvalues['forum_image']) && strlen($inputvalues['forum_image']) > 0) {
        $image_path = api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/upload/forum/images/' . $inputvalues['forum_image'];
        $image_size = api_getimagesize($image_path);
        $img_attributes = '';
        if (!empty($image_size)) {
            if ($image_size['width'] > 100 || $image_size['height'] > 100) {
                //limit display width and height to 100px
                $img_attributes = 'width="100" height="100"';
            }
            $show_preview_image = '<img src="' . $image_path . '" ' . $img_attributes . '>';
            $form->addElement('label', get_lang('PreviewImage'), $show_preview_image);
            $form->addElement('checkbox', 'remove_picture', null, get_lang('DelImage'));
        }
    }
    $forum_image = isset($inputvalues['forum_image']) ? $inputvalues['forum_image'] : '';
    $form->addElement('file', 'picture', $forum_image != '' ? get_lang('UpdateImage') : get_lang('AddImage'));
    $form->addRule('picture', get_lang('OnlyImagesAllowed'), 'filetype', array('jpg', 'jpeg', 'png', 'gif'));
    $form->addElement('html', '</div>');
    // The OK button
    if (isset($_GET['id']) && $_GET['action'] == 'edit') {
        $form->addButtonUpdate(get_lang('ModifyForum'), 'SubmitForum');
    } else {
        $form->addButtonCreate(get_lang('CreateForum'), 'SubmitForum');
    }
    // setting the rules
    $form->addRule('forum_title', get_lang('ThisFieldIsRequired'), 'required');
    $form->addRule('forum_category', get_lang('ThisFieldIsRequired'), 'required');
    $defaultSettingAllowNewThreads = api_get_default_tool_setting('forum', 'allow_new_threads', 0);
    // Settings the defaults
    if (empty($inputvalues) || !is_array($inputvalues)) {
        $defaults['allow_anonymous_group']['allow_anonymous'] = 0;
        $defaults['students_can_edit_group']['students_can_edit'] = 0;
        $defaults['approval_direct_group']['approval_direct'] = 0;
        $defaults['allow_attachments_group']['allow_attachments'] = 1;
        $defaults['allow_new_threads_group']['allow_new_threads'] = $defaultSettingAllowNewThreads;
        $defaults['default_view_type_group']['default_view_type'] = api_get_setting('forum.default_forum_view');
        $defaults['public_private_group_forum_group']['public_private_group_forum'] = 'public';
        if (isset($_GET['forumcategory'])) {
            $defaults['forum_category'] = Security::remove_XSS($_GET['forumcategory']);
        }
    } else {
        // the default values when editing = the data in the table
        $defaults['forum_id'] = isset($inputvalues['forum_id']) ? $inputvalues['forum_id'] : null;
        $defaults['forum_title'] = prepare4display(isset($inputvalues['forum_title']) ? $inputvalues['forum_title'] : null);
        $defaults['forum_comment'] = prepare4display(isset($inputvalues['forum_comment']) ? $inputvalues['forum_comment'] : null);
        $defaults['forum_category'] = isset($inputvalues['forum_category']) ? $inputvalues['forum_category'] : null;
        $defaults['allow_anonymous_group']['allow_anonymous'] = isset($inputvalues['allow_anonymous']) ? $inputvalues['allow_anonymous'] : null;
        $defaults['students_can_edit_group']['students_can_edit'] = isset($inputvalues['allow_edit']) ? $inputvalues['allow_edit'] : null;
        $defaults['approval_direct_group']['approval_direct'] = isset($inputvalues['approval_direct_post']) ? $inputvalues['approval_direct_post'] : null;
        $defaults['allow_attachments_group']['allow_attachments'] = isset($inputvalues['allow_attachments']) ? $inputvalues['allow_attachments'] : null;
        $defaults['allow_new_threads_group']['allow_new_threads'] = isset($inputvalues['allow_new_threads']) ? $inputvalues['allow_new_threads'] : $defaultSettingAllowNewThreads;
        $defaults['default_view_type_group']['default_view_type'] = isset($inputvalues['default_view']) ? $inputvalues['default_view'] : null;
        $defaults['public_private_group_forum_group']['public_private_group_forum'] = isset($inputvalues['forum_group_public_private']) ? $inputvalues['forum_group_public_private'] : null;
        $defaults['group_forum'] = isset($inputvalues['forum_of_group']) ? $inputvalues['forum_of_group'] : null;
    }
    $form->setDefaults($defaults);
    // Validation or display
    if ($form->validate()) {
        $check = Security::check_token('post');
        if ($check) {
            $values = $form->exportValues();
            $return_message = store_forum($values);
            Display::display_confirmation_message($return_message);
        }
        Security::clear_token();
    } else {
        $token = Security::get_token();
        $form->addElement('hidden', 'sec_token');
        $form->setConstants(array('sec_token' => $token));
        $form->display();
    }
}
/**
* this function displays the form to upload a new item to the dropbox.
*
* @author Patrick Cool <*****@*****.**>, Ghent University
* @version march 2006
*/
function display_add_form($dropbox_unid, $viewReceivedCategory, $viewSentCategory, $view)
{
    $course_info = api_get_course_info();
    $_user = api_get_user_info();
    $is_courseAdmin = api_is_course_admin();
    $is_courseTutor = api_is_course_tutor();
    $origin = isset($_GET['origin']) ? $_GET['origin'] : null;
    $token = Security::get_token();
    $dropbox_person = new Dropbox_Person(api_get_user_id(), $is_courseAdmin, $is_courseTutor);
    $form = new FormValidator('sent_form', 'post', api_get_self() . '?view_received_category=' . $viewReceivedCategory . '&view_sent_category=' . $viewSentCategory . '&view=' . $view . '&' . api_get_cidreq(), null, array('enctype' => 'multipart/form-data', 'onsubmit' => 'javascript: return checkForm(this);'));
    $form->addElement('header', get_lang('UploadNewFile'));
    $form->addElement('hidden', 'MAX_FILE_SIZE', dropbox_cnf('maxFilesize'));
    $form->addElement('hidden', 'dropbox_unid', $dropbox_unid);
    $form->addElement('hidden', 'sec_token', $token);
    $form->addElement('hidden', 'origin', $origin);
    $form->addElement('file', 'file', get_lang('UploadFile'), array('onChange' => 'javascript: checkfile(this.value);'));
    if (dropbox_cnf('allowOverwrite')) {
        $form->addElement('checkbox', 'cb_overwrite', null, get_lang('OverwriteFile'), array('id' => 'cb_overwrite'));
    }
    // List of all users in this course and all virtual courses combined with it
    if (api_get_session_id()) {
        $complete_user_list_for_dropbox = array();
        if (api_get_setting('dropbox_allow_student_to_student') == 'true' || $_user['status'] != STUDENT) {
            $complete_user_list_for_dropbox = CourseManager::get_user_list_from_course_code($course_info['code'], api_get_session_id());
        }
        $complete_user_list2 = CourseManager::get_coach_list_from_course_code($course_info['code'], api_get_session_id());
        $complete_user_list_for_dropbox = array_merge($complete_user_list_for_dropbox, $complete_user_list2);
    } else {
        if (api_get_setting('dropbox_allow_student_to_student') == 'true' || $_user['status'] != STUDENT) {
            $complete_user_list_for_dropbox = CourseManager::get_user_list_from_course_code($course_info['code'], api_get_session_id());
        } else {
            $complete_user_list_for_dropbox = CourseManager::get_teacher_list_from_course_code($course_info['code'], false);
        }
    }
    if (!empty($complete_user_list_for_dropbox)) {
        foreach ($complete_user_list_for_dropbox as $k => $e) {
            $complete_user_list_for_dropbox[$k] = $e + array('lastcommafirst' => api_get_person_name($e['firstname'], $e['lastname']));
        }
        $complete_user_list_for_dropbox = TableSort::sort_table($complete_user_list_for_dropbox, 'lastcommafirst');
    }
    /*
        Create the options inside the select box:
        List all selected users their user id as value and a name string as display
    */
    $current_user_id = '';
    $options = array();
    foreach ($complete_user_list_for_dropbox as $current_user) {
        if (($dropbox_person->isCourseTutor || $dropbox_person->isCourseAdmin || dropbox_cnf('allowStudentToStudent') || $current_user['status'] != 5 || $current_user['tutor_id'] == 1) && $current_user['user_id'] != $_user['user_id']) {
            // Don't include yourself.
            if ($current_user['user_id'] == $current_user_id) {
                continue;
            }
            $full_name = $current_user['lastcommafirst'];
            $current_user_id = $current_user['user_id'];
            $options['user_' . $current_user_id] = $full_name;
            //echo '<option value="user_' . $current_user_id . '">' . $full_name . '</option>';
        }
    }
    /*
     * Show groups
     */
    if (($dropbox_person->isCourseTutor || $dropbox_person->isCourseAdmin) && dropbox_cnf('allowGroup') || dropbox_cnf('allowStudentToStudent')) {
        $complete_group_list_for_dropbox = GroupManager::get_group_list(null, dropbox_cnf('courseId'));
        if (count($complete_group_list_for_dropbox) > 0) {
            foreach ($complete_group_list_for_dropbox as $current_group) {
                if ($current_group['number_of_members'] > 0) {
                    //echo '<option value="group_'.$current_group['id'].'">G: '.$current_group['name'].' - '.$current_group['number_of_members'].' '.get_lang('Users').'</option>';
                    $options['group_' . $current_group['id']] = 'G: ' . $current_group['name'] . ' - ' . $current_group['number_of_members'] . ' ' . get_lang('Users');
                }
            }
        }
    }
    if (dropbox_cnf('allowJustUpload')) {
        //echo '<option value="upload">'.get_lang('JustUploadInSelect').'</option>';
        //echo '<option value="user_'.$_user['user_id'].'">'.get_lang('JustUploadInSelect').'</option>';
        $options['user_' . $_user['user_id']] = get_lang('JustUploadInSelect');
    }
    $form->addElement('select', 'recipients', get_lang('SendTo'), $options, array('multiple' => 'multiple', 'size' => '10', 'class' => 'span4'));
    $form->addElement('button', 'submitWork', get_lang('Upload'));
    $form->display();
}
/**
* this function displays the form to upload a new item to the dropbox.
*
* @author Patrick Cool <*****@*****.**>, Ghent University
* @version march 2006
*/
function display_add_form($dropbox_unid, $viewReceivedCategory, $viewSentCategory, $view)
{
    $course_info = api_get_course_info();
    $_user = api_get_user_info();
    $is_courseAdmin = api_is_course_admin();
    $is_courseTutor = api_is_course_tutor();
    $origin = isset($_GET['origin']) ? $_GET['origin'] : null;
    $token = Security::get_token();
    $dropbox_person = new Dropbox_Person(api_get_user_id(), $is_courseAdmin, $is_courseTutor);
    $form = new FormValidator('sent_form', 'post', api_get_self() . '?view_received_category=' . $viewReceivedCategory . '&view_sent_category=' . $viewSentCategory . '&view=' . $view . '&' . api_get_cidreq(), null, array('enctype' => 'multipart/form-data', 'onsubmit' => 'javascript: return checkForm(this);'));
    $form->addElement('header', get_lang('UploadNewFile'));
    $form->addElement('hidden', 'MAX_FILE_SIZE', dropbox_cnf('maxFilesize'));
    $form->addElement('hidden', 'dropbox_unid', $dropbox_unid);
    $form->addElement('hidden', 'sec_token', $token);
    $form->addElement('hidden', 'origin', $origin);
    $form->addElement('file', 'file', get_lang('UploadFile'), array('onChange' => 'javascript: checkfile(this.value);'));
    if (dropbox_cnf('allowOverwrite')) {
        $form->addElement('checkbox', 'cb_overwrite', null, get_lang('OverwriteFile'), array('id' => 'cb_overwrite'));
    }
    // List of all users in this course and all virtual courses combined with it
    if (api_get_session_id()) {
        $complete_user_list_for_dropbox = array();
        if (api_get_setting('dropbox.dropbox_allow_student_to_student') == 'true' || $_user['status'] != STUDENT) {
            $complete_user_list_for_dropbox = CourseManager::get_user_list_from_course_code($course_info['code'], api_get_session_id(), null, null, 0);
        }
        $complete_user_list2 = CourseManager::get_coach_list_from_course_code($course_info['code'], api_get_session_id());
        $generalCoachList = array();
        $courseCoachList = array();
        foreach ($complete_user_list2 as $coach) {
            if ($coach['type'] == 'general_coach') {
                $generalCoachList[] = $coach;
            } else {
                $courseCoachList[] = $coach;
            }
        }
        $hideCourseCoach = api_get_setting('dropbox_hide_course_coach');
        if ($hideCourseCoach == 'false') {
            $complete_user_list_for_dropbox = array_merge($complete_user_list_for_dropbox, $courseCoachList);
        }
        $hideGeneralCoach = api_get_setting('dropbox_hide_general_coach');
        if ($hideGeneralCoach == 'false') {
            $complete_user_list_for_dropbox = array_merge($complete_user_list_for_dropbox, $generalCoachList);
        }
    } else {
        if (api_get_setting('dropbox.dropbox_allow_student_to_student') == 'true' || $_user['status'] != STUDENT) {
            $complete_user_list_for_dropbox = CourseManager::get_user_list_from_course_code($course_info['code'], api_get_session_id());
        } else {
            $complete_user_list_for_dropbox = CourseManager::getTeacherListFromCourse($course_info['real_id'], false);
        }
    }
    if (!empty($complete_user_list_for_dropbox)) {
        foreach ($complete_user_list_for_dropbox as $k => $e) {
            $complete_user_list_for_dropbox[$k] = $e + array('lastcommafirst' => api_get_person_name($e['firstname'], $e['lastname']));
        }
        $complete_user_list_for_dropbox = TableSort::sort_table($complete_user_list_for_dropbox, 'lastcommafirst');
    }
    /*
        Create the options inside the select box:
        List all selected users their user id as value and a name string as display
    */
    $current_user_id = '';
    $options = array();
    $userGroup = new UserGroup();
    foreach ($complete_user_list_for_dropbox as $current_user) {
        if (($dropbox_person->isCourseTutor || $dropbox_person->isCourseAdmin || dropbox_cnf('allowStudentToStudent') || $current_user['status'] != 5 || $current_user['is_tutor'] == 1) && $current_user['user_id'] != $_user['user_id']) {
            // Don't include yourself.
            if ($current_user['user_id'] == $current_user_id) {
                continue;
            }
            $userId = $current_user['user_id'];
            $userInfo = api_get_user_info($userId);
            if ($userInfo['status'] != INVITEE) {
                $groupNameListToString = '';
                if (!empty($groups)) {
                    $groupNameList = array_column($groups, 'name');
                    $groupNameListToString = ' - [' . implode(', ', $groupNameList) . ']';
                }
                $groups = $userGroup->getUserGroupListByUser($userId);
                $full_name = $userInfo['complete_name'] . $groupNameListToString;
                $current_user_id = $current_user['user_id'];
                $options['user_' . $current_user_id] = $full_name;
            }
        }
    }
    /*
     * Show groups
     */
    if (($dropbox_person->isCourseTutor || $dropbox_person->isCourseAdmin) && dropbox_cnf('allowGroup') || dropbox_cnf('allowStudentToStudent')) {
        $complete_group_list_for_dropbox = GroupManager::get_group_list(null, dropbox_cnf('courseId'));
        if (count($complete_group_list_for_dropbox) > 0) {
            foreach ($complete_group_list_for_dropbox as $current_group) {
                if ($current_group['number_of_members'] > 0) {
                    $options['group_' . $current_group['id']] = 'G: ' . $current_group['name'] . ' - ' . $current_group['number_of_members'] . ' ' . get_lang('Users');
                }
            }
        }
    }
    if (dropbox_cnf('allowJustUpload')) {
        $options['user_' . $_user['user_id']] = get_lang('JustUploadInSelect');
    }
    $form->addSelect('recipients', get_lang('SendTo'), $options, array('multiple' => 'multiple', 'size' => '10'));
    $form->addButtonUpload(get_lang('Upload'), 'submitWork');
    $headers = array(get_lang('Upload'), get_lang('Upload') . ' (' . get_lang('Simple') . ')');
    $multipleForm = new FormValidator('sent_multiple', 'post', '#', null, array('enctype' => 'multipart/form-data', 'id' => 'fileupload'));
    $multipleForm->addSelect('recipients', get_lang('SendTo'), $options, array('multiple' => 'multiple', 'size' => '10', 'id' => 'recipient_form'));
    $url = api_get_path(WEB_AJAX_PATH) . 'dropbox.ajax.php?' . api_get_cidreq() . '&a=upload_file&id=';
    $multipleForm->addHtml('<div id="multiple_form" style="display:none">');
    $multipleForm->addMultipleUpload($url);
    $multipleForm->addHtml('</div>');
    echo Display::tabs($headers, array($multipleForm->returnForm(), $form->returnForm()), 'tabs');
}