/** * Unsubscribe all users from one or more groups * @param mixed $group_id Can be an array with group-id's or a single group-id * @return bool TRUE if successful */ public static function unsubscribe_all_users($group_ids) { $course_id = api_get_course_int_id(); $group_ids = is_array($group_ids) ? $group_ids : array($group_ids); $group_ids = array_map('intval', $group_ids); if (count($group_ids) > 0) { if (api_is_course_coach()) { for ($i = 0; $i < count($group_ids); $i++) { if (!api_is_element_in_the_session(TOOL_GROUP, $group_ids[$i])) { array_splice($group_ids, $i, 1); $i--; } } if (count($group_ids) == 0) { return false; } } $table_group_user = Database::get_course_table(TABLE_GROUP_USER); $sql = 'DELETE FROM ' . $table_group_user . ' WHERE group_id IN (' . implode(',', $group_ids) . ') AND c_id = ' . $course_id; $result = Database::query($sql); return $result; } return true; }
} } display_agenda_items(); break; case "showhide": $id = (int) $_GET['id']; if (!(api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $id))) { // a coach can only delete an element belonging to his session showhide_agenda_item($id); } display_agenda_items(); break; case "announce": //copying the agenda item into an announcement $id = (int) $_GET['id']; if (!(api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $id))) { // a coach can only delete an element belonging to his session $ann_id = store_agenda_item_as_announcement($id); $tool_group_link = isset($_SESSION['toolgroup']) ? '&toolgroup=' . $_SESSION['toolgroup'] : ''; echo '<br />'; Display::display_normal_message(get_lang('CopiedAsAnnouncement') . '<a href="../announcements/announcements.php?id=' . $ann_id . $tool_group_link . '">' . get_lang('NewAnnouncement') . '</a>', false); } display_agenda_items(); break; case "delete_attach": //delete attachment file $id_attach = (int) $_GET['id_attach']; if (!empty($id_attach)) { delete_attachment_file($id_attach); } display_agenda_items();
break; case 'delete_attachment': $id = $_GET['id_attach']; if (api_is_allowed_to_edit()) { AnnouncementManager::delete_announcement_attachment_file($id); } header('Location: ' . $homeUrl); exit; break; case 'showhide': if (!isset($_GET['isStudentView']) || $_GET['isStudentView'] != 'false') { if (isset($_GET['id']) && $_GET['id']) { if ($sessionId != 0 && api_is_allowed_to_session_edit(false, true) == false) { api_not_allowed(); } if (!api_is_course_coach() || api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $_GET['id'])) { AnnouncementManager::change_visibility_announcement($_course, $_GET['id']); Display::addFlash(Display::return_message(get_lang('VisibilityChanged'))); header('Location: ' . $homeUrl); exit; } } } break; case 'add': case 'modify': if ($sessionId != 0 && api_is_allowed_to_session_edit(false, true) == false) { api_not_allowed(true); } // DISPLAY ADD ANNOUNCEMENT COMMAND $id = isset($_GET['id']) ? intval($_GET['id']) : 0;
/** * * See : fill_groups * Fill the groups with students. * * note : optimize fill_groups_list <--> fill_groups * @param array $group_ids * @return array|bool */ public static function fill_groups_list($group_ids) { $group_ids = is_array($group_ids) ? $group_ids : array($group_ids); $group_ids = array_map('intval', $group_ids); if (api_is_course_coach()) { for ($i = 0; $i < count($group_ids); $i++) { if (!api_is_element_in_the_session(TOOL_GROUP, $group_ids[$i])) { array_splice($group_ids, $i, 1); $i--; } } if (count($group_ids) == 0) { return false; } } $_course = api_get_course_info(); $category = self::get_category_from_group($group_ids[0]); $number_groups_per_user = self::GROUP_PER_MEMBER_NO_LIMIT; $categoryId = 0; if ($category) { $groups_per_user = $category['groups_per_user']; $number_groups_per_user = $groups_per_user == self::GROUP_PER_MEMBER_NO_LIMIT ? self::INFINITE : $groups_per_user; $categoryId = $category['id']; } $group_table = Database::get_course_table(TABLE_GROUP); $group_user_table = Database::get_course_table(TABLE_GROUP_USER); $session_id = api_get_session_id(); $complete_user_list = CourseManager::get_real_and_linked_user_list($_course['code'], true, $session_id); $course_id = api_get_course_int_id(); /* * Retrieve all the groups where enrollment is still allowed * (reverse) ordered by the number of place available */ $sql = "SELECT g.id gid, count(ug.user_id) count_users, g.max_student\n FROM " . $group_table . " g\n LEFT JOIN " . $group_user_table . " ug\n ON g.id = ug.group_id\n WHERE g.c_id = {$course_id} AND\n ug.c_id = {$course_id} AND\n g.id IN (" . implode(',', $group_ids) . ")\n GROUP BY (g.id)"; $sql_result = Database::query($sql); $group_available_place = array(); while ($group = Database::fetch_array($sql_result, 'ASSOC')) { if (!empty($group['max_student'])) { $places = intval($group['max_student'] - $group['count_users']); } else { $places = self::MEMBER_PER_GROUP_NO_LIMIT; } $group_available_place[$group['gid']] = $places; } /* * Retrieve course users (reverse) ordered by the number * of group they are already enrolled */ for ($i = 0; $i < count($complete_user_list); $i++) { // find # of groups the user is enrolled in $number_of_groups = self::user_in_number_of_groups($complete_user_list[$i]["user_id"], $categoryId); // add # of groups to user list $complete_user_list[$i]['number_groups_left'] = $number_groups_per_user - $number_of_groups; } //first sort by user_id to filter out duplicates $complete_user_list = TableSort::sort_table($complete_user_list, 'user_id'); $complete_user_list = self::filter_duplicates($complete_user_list, 'user_id'); //$complete_user_list = self :: filter_only_students($complete_user_list); //now sort by # of group left $complete_user_list = TableSort::sort_table($complete_user_list, 'number_groups_left', SORT_DESC); return $complete_user_list; }
* @version $Id: create_new_survey.php 22297 2009-07-22 22:08:30Z cfasanando $ * * @todo only the available platform languages should be used => need an * api get_languages and and api_get_available_languages (or a parameter) */ require_once '../inc/global.inc.php'; $this_section = SECTION_COURSES; // Database table definitions $table_survey = Database::get_course_table(TABLE_SURVEY); $table_user = Database::get_main_table(TABLE_MAIN_USER); $table_course = Database::get_main_table(TABLE_MAIN_COURSE); $table_gradebook_link = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK); /** @todo this has to be moved to a more appropriate place (after the display_header of the code) */ // If user is not teacher or if he's a coach trying to access an element out of his session if (!api_is_allowed_to_edit()) { if (!api_is_course_coach() || !empty($_GET['survey_id']) && !api_is_element_in_the_session(TOOL_SURVEY, $_GET['survey_id'])) { api_not_allowed(true); exit; } } // Getting the survey information $survey_id = isset($_GET['survey_id']) ? intval($_GET['survey_id']) : null; $survey_data = SurveyManager::get_survey($survey_id); // Additional information $course_id = api_get_course_id(); $session_id = api_get_session_id(); $gradebook_link_type = 8; $urlname = isset($survey_data['title']) ? strip_tags($survey_data['title']) : null; // Breadcrumbs if ($_GET['action'] == 'add') { $interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH) . 'survey/survey_list.php?' . api_get_cidreq(), 'name' => get_lang('SurveyList'));
/** * This function changes the modify column of the sortable table * * @param integer $survey_id the id of the survey * @param bool $drh * @return string html code that are the actions that can be performed on any survey * * @author Patrick Cool <*****@*****.**>, Ghent University * @version January 2007 */ static function modify_filter($survey_id, $drh = false) { $survey_id = Security::remove_XSS($survey_id); $return = ''; if ($drh) { return '<a href="' . api_get_path(WEB_CODE_PATH) . 'survey/reporting.php?' . api_get_cidreq() . '&survey_id=' . $survey_id . '">' . Display::return_icon('stats.png', get_lang('Reporting'), '', ICON_SIZE_SMALL) . '</a>'; } // Coach can see that only if the survey is in his session if (api_is_allowed_to_edit() || api_is_element_in_the_session(TOOL_SURVEY, $survey_id)) { $return .= '<a href="' . api_get_path(WEB_CODE_PATH) . 'survey/create_new_survey.php?' . api_get_cidreq() . '&action=edit&survey_id=' . $survey_id . '">' . Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL) . '</a>'; if (SurveyManager::survey_generation_hash_available()) { $return .= Display::url(Display::return_icon('new_link.png', get_lang('GenerateSurveyAccessLink'), '', ICON_SIZE_SMALL), api_get_path(WEB_CODE_PATH) . 'survey/generate_link.php?survey_id=' . $survey_id . '&' . api_get_cidreq()); } $return .= Display::url(Display::return_icon('copy.png', get_lang('DuplicateSurvey'), '', ICON_SIZE_SMALL), 'survey_list.php?action=copy_survey&survey_id=' . $survey_id . '&' . api_get_cidreq()); $return .= ' <a href="' . api_get_path(WEB_CODE_PATH) . 'survey/survey_list.php?' . api_get_cidreq() . '&action=empty&survey_id=' . $survey_id . '" onclick="javascript: if(!confirm(\'' . addslashes(api_htmlentities(get_lang("EmptySurvey") . '?')) . '\')) return false;">' . Display::return_icon('clean.png', get_lang('EmptySurvey'), '', ICON_SIZE_SMALL) . '</a> '; } $return .= '<a href="' . api_get_path(WEB_CODE_PATH) . 'survey/preview.php?' . api_get_cidreq() . '&survey_id=' . $survey_id . '">' . Display::return_icon('preview_view.png', get_lang('Preview'), '', ICON_SIZE_SMALL) . '</a> '; $return .= '<a href="' . api_get_path(WEB_CODE_PATH) . 'survey/survey_invite.php?' . api_get_cidreq() . '&survey_id=' . $survey_id . '">' . Display::return_icon('mail_send.png', get_lang('Publish'), '', ICON_SIZE_SMALL) . '</a> '; $return .= '<a href="' . api_get_path(WEB_CODE_PATH) . 'survey/reporting.php?' . api_get_cidreq() . '&survey_id=' . $survey_id . '">' . Display::return_icon('stats.png', get_lang('Reporting'), '', ICON_SIZE_SMALL) . '</a>'; if (api_is_allowed_to_edit() || api_is_element_in_the_session(TOOL_SURVEY, $survey_id)) { $return .= '<a href="' . api_get_path(WEB_CODE_PATH) . 'survey/survey_list.php?' . api_get_cidreq() . '&action=delete&survey_id=' . $survey_id . '" onclick="javascript: if(!confirm(\'' . addslashes(api_htmlentities(get_lang("DeleteSurvey") . '?', ENT_QUOTES)) . '\')) return false;">' . Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL) . '</a> '; } return $return; }
setFocus(); }); </script>'; // Database table definitions $table_survey = Database :: get_course_table(TABLE_SURVEY); $table_user = Database :: get_main_table(TABLE_MAIN_USER); $table_course = Database :: get_main_table(TABLE_MAIN_COURSE); $table_gradebook_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); /** @todo this has to be moved to a more appropriate place (after the display_header of the code) */ // If user is not teacher or if he's a coach trying to access an element out of his session if (!api_is_allowed_to_edit()) { if (!api_is_course_coach() || (!empty($_GET['survey_id']) && !api_is_element_in_the_session(TOOL_SURVEY, $_GET['survey_id'])) ) { api_not_allowed(true); exit; } } // Getting the survey information $survey_id = isset($_GET['survey_id']) ? intval($_GET['survey_id']) : null; $survey_data = survey_manager::get_survey($survey_id); // Additional information $course_id = api_get_course_id(); $session_id = api_get_session_id(); $gradebook_link_type = 8; $urlname = isset($survey_data['title']) ? strip_tags($survey_data['title']) : null;
} // If the survey is shared => also delete the shared content if (is_numeric($survey_data['survey_share'])) { survey_manager::delete_survey($survey_data['survey_share'], true); } $return = survey_manager::delete_survey($_GET['survey_id']); if ($return) { Display::display_confirmation_message(get_lang('SurveyDeleted'), false); } else { Display::display_error_message(get_lang('ErrorOccurred'), false); } } if (isset($_GET['action']) && $_GET['action'] == 'empty') { $mysession = api_get_session_id(); if ($mysession != 0) { if (!((api_is_course_coach() || api_is_platform_admin()) && api_is_element_in_the_session(TOOL_SURVEY, $_GET['survey_id']))) { // The coach can't empty a survey not belonging to his session api_not_allowed(); exit; } } else { if (!(api_is_course_admin() || api_is_platform_admin())) { api_not_allowed(); exit; } } $return = survey_manager::empty_survey(intval($_GET['survey_id'])); if ($return) { Display::display_confirmation_message(get_lang('SurveyEmptied'), false); } else { Display::display_error_message(get_lang('ErrorOccurred'), false);
/** * @param $stok * @param $announcement_number */ public static function getAnnouncements($stok, $announcement_number) { $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT); $tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY); $user_id = api_get_user_id(); $group_id = api_get_group_id(); $session_id = api_get_session_id(); $condition_session = api_get_session_condition($session_id, true, true, 'announcement.session_id'); $course_id = api_get_course_int_id(); $_course = api_get_course_info(); $group_memberships = GroupManager::get_group_ids($course_id, api_get_user_id()); $allowUserEditSetting = api_get_course_setting('allow_user_edit_announcement'); if (api_is_allowed_to_edit(false, true) || $allowUserEditSetting && !api_is_anonymous()) { // A.1. you are a course admin with a USER filter // => see only the messages of this specific user + the messages of the group (s)he is member of. //if (!empty($user_id)) { if (0) { if (is_array($group_memberships) && count($group_memberships) > 0) { $sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date\n FROM {$tbl_announcement} announcement, {$tbl_item_property} ip\n WHERE\n announcement.c_id = {$course_id} AND\n ip.c_id = {$course_id} AND\n announcement.id = ip.ref AND\n ip.tool = 'announcement' AND\n (\n ip.to_user_id = {$user_id} OR\n ip.to_group_id IS NULL OR\n ip.to_group_id IN (0, " . implode(", ", $group_memberships) . ")\n ) AND\n ip.visibility IN ('1', '0')\n {$condition_session}\n ORDER BY display_order DESC"; } else { $sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date\n FROM {$tbl_announcement} announcement, {$tbl_item_property} ip\n WHERE\n announcement.c_id = {$course_id} AND\n ip.c_id = {$course_id} AND\n announcement.id = ip.ref AND\n ip.tool ='announcement' AND\n (ip.to_user_id = {$user_id} OR ip.to_group_id='0' OR ip.to_group_id IS NULL) AND\n ip.visibility IN ('1', '0')\n {$condition_session}\n ORDER BY display_order DESC"; } } elseif ($group_id != 0) { // A.2. you are a course admin with a GROUP filter // => see only the messages of this specific group $sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date\n FROM {$tbl_announcement} announcement, {$tbl_item_property} ip\n WHERE\n announcement.c_id = {$course_id} AND\n ip.c_id = {$course_id} AND\n announcement.id = ip.ref\n AND ip.tool='announcement'\n AND ip.visibility<>'2'\n AND (ip.to_group_id = {$group_id} OR ip.to_group_id='0' OR ip.to_group_id IS NULL)\n {$condition_session}\n GROUP BY ip.ref\n ORDER BY display_order DESC"; } else { // A.3 you are a course admin without any group or user filter // A.3.a you are a course admin without user or group filter but WITH studentview // => see all the messages of all the users and groups without editing possibilities if (isset($isStudentView) and $isStudentView == "true") { $sql = "SELECT\n announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date\n FROM {$tbl_announcement} announcement, {$tbl_item_property} ip\n WHERE\n announcement.c_id = {$course_id} AND\n ip.c_id = {$course_id} AND\n announcement.id = ip.ref\n AND ip.tool='announcement'\n AND ip.visibility='1'\n {$condition_session}\n GROUP BY ip.ref\n ORDER BY display_order DESC"; } else { // A.3.a you are a course admin without user or group filter and WTIHOUT studentview (= the normal course admin view) // => see all the messages of all the users and groups with editing possibilities $sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date\n FROM {$tbl_announcement} announcement, {$tbl_item_property} ip\n WHERE\n announcement.c_id = {$course_id} AND\n ip.c_id = {$course_id} AND\n announcement.id = ip.ref\n AND ip.tool='announcement'\n AND (ip.visibility='0' or ip.visibility='1')\n {$condition_session}\n GROUP BY ip.ref\n ORDER BY display_order DESC"; } } } else { // STUDENT if (is_array($group_memberships) && count($group_memberships) > 0) { if ($allowUserEditSetting && !api_is_anonymous()) { if (api_get_group_id() == 0) { // No group $cond_user_id = " AND (\n ip.lastedit_user_id = '" . $user_id . "' OR (\n ip.to_user_id='" . $user_id . "' OR\n (ip.to_group_id IS NULL OR ip.to_group_id IN (0, " . implode(", ", $group_memberships) . "))\n )\n ) "; } else { $cond_user_id = " AND (\n ip.lastedit_user_id = '" . $user_id . "' OR ip.to_group_id IS NULL OR ip.to_group_id IN (0, " . $group_id . ")\n )"; } } else { if (api_get_group_id() == 0) { $cond_user_id = " AND (\n ip.to_user_id={$user_id} OR (ip.to_group_id IS NULL OR ip.to_group_id IN (0, " . implode(", ", $group_memberships) . "))\n ) "; } else { $cond_user_id = " AND (\n ip.to_user_id={$user_id} OR (ip.to_group_id IS NULL OR ip.to_group_id IN (0, " . api_get_group_id() . "))\n )"; } } $sql = "SELECT\n announcement.*,\n ip.visibility,\n ip.to_group_id,\n ip.insert_user_id,\n ip.insert_date\n FROM {$tbl_announcement} announcement,\n {$tbl_item_property} ip\n WHERE\n announcement.c_id = {$course_id} AND\n ip.c_id = {$course_id} AND\n announcement.id = ip.ref\n AND ip.tool='announcement'\n {$cond_user_id}\n {$condition_session} AND\n ip.visibility='1'\n ORDER BY display_order DESC"; } else { if ($user_id) { if ($allowUserEditSetting && !api_is_anonymous()) { $cond_user_id = " AND (\n ip.lastedit_user_id = '" . api_get_user_id() . "' OR\n (ip.to_user_id='" . $user_id . "' AND (ip.to_group_id='0' OR ip.to_group_id IS NULL))\n ) "; } else { $cond_user_id = " AND (ip.to_user_id='" . $user_id . "' AND (ip.to_group_id='0' OR ip.to_group_id IS NULL) ) "; } $sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date\n\t\t\t\t\t\tFROM {$tbl_announcement} announcement, {$tbl_item_property} ip\n\t\t\t\t\t\tWHERE\n \t\t\t\t\t\tannouncement.c_id = {$course_id} AND\n\t\t\t\t\t\t\tip.c_id = {$course_id} AND\n \t\t\t\t\t\tannouncement.id = ip.ref AND\n \t\t\t\t\t\tip.tool='announcement'\n \t\t\t\t\t\t{$cond_user_id}\n \t\t\t\t\t\t{$condition_session}\n \t\t\t\t\t\tAND ip.visibility='1'\n \t\t\t\t\t\tAND announcement.session_id IN(0, " . api_get_session_id() . ")\n\t\t\t\t\t\tORDER BY display_order DESC"; } else { if ($allowUserEditSetting && !api_is_anonymous()) { $cond_user_id = " AND (\n ip.lastedit_user_id = '" . $user_id . "' OR ip.to_group_id='0' OR ip.to_group_id IS NULL\n )"; } else { $cond_user_id = " AND ip.to_group_id='0' OR ip.to_group_id IS NULL "; } $sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date\n\t\t\t\t\t\tFROM {$tbl_announcement} announcement, {$tbl_item_property} ip\n\t\t\t\t\t\tWHERE\n announcement.c_id = {$course_id} AND\n ip.c_id = {$course_id} AND\n announcement.id = ip.ref AND\n ip.tool='announcement'\n {$cond_user_id}\n {$condition_session} AND\n ip.visibility='1' AND\n announcement.session_id IN ( 0," . api_get_session_id() . ")"; } } } $result = Database::query($sql); $num_rows = Database::num_rows($result); $html = null; if ($num_rows == 0) { if ((api_is_allowed_to_edit(false, true) or api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous()) and (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath')) { $html .= '<div id="no-data-view">'; $html .= '<h3>' . get_lang('Announcements') . '</h3>'; $html .= Display::return_icon('valves.png', '', array(), 64); $html .= '<div class="controls">'; $html .= Display::url(get_lang('AddAnnouncement'), api_get_self() . "?" . api_get_cidreq() . "&action=add", array('class' => 'btn btn-primary')); $html .= '</div>'; $html .= '</div>'; } else { $html = Display::return_message(get_lang('NoAnnouncements'), 'warning'); } return $html; } $iterator = 1; $bottomAnnouncement = $announcement_number; $origin = null; $html .= '<table width="100%" class="data_table announcements-list">'; $ths = Display::tag('th', get_lang('Title')); $ths .= Display::tag('th', get_lang('By')); $ths .= Display::tag('th', get_lang('LastUpdateDate')); if (api_is_allowed_to_edit(false, true) or api_is_course_coach() && api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $myrow['id']) or api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous()) { $ths .= Display::tag('th', get_lang('Modify')); } $html .= Display::tag('tr', $ths); $displayed = array(); while ($myrow = Database::fetch_array($result, 'ASSOC')) { if (!in_array($myrow['id'], $displayed)) { $sent_to_icon = ''; // the email icon if ($myrow['email_sent'] == '1') { $sent_to_icon = ' ' . Display::return_icon('email.gif', get_lang('AnnounceSentByEmail')); } $title = $myrow['title'] . $sent_to_icon; $item_visibility = api_get_item_visibility($_course, TOOL_ANNOUNCEMENT, $myrow['id'], $session_id); $myrow['visibility'] = $item_visibility; // the styles if ($myrow['visibility'] == '0') { $style = 'invisible'; } else { $style = ''; } $html .= '<tr class="announcements-list-line">'; // show attachment list $attachment_list = AnnouncementManager::get_attachment($myrow['id']); $attachment_icon = ''; if (count($attachment_list) > 0) { $attachment_icon = ' ' . Display::return_icon('attachment.gif', get_lang('Attachment')); } /* TITLE */ $user_info = api_get_user_info($myrow['insert_user_id']); $username = sprintf(get_lang("LoginX"), $user_info['username']); $username_span = Display::tag('span', api_get_person_name($user_info['firstName'], $user_info['lastName']), array('title' => $username)); $title = Display::url($title . $attachment_icon, api_get_self() . '?' . api_get_cidreq() . '&action=view&id=' . $myrow['id']); $html .= Display::tag('td', Security::remove_XSS($title), array('class' => 'announcements-list-line-title ' . $style)); $html .= Display::tag('td', $username_span, array('class' => 'announcements-list-line-by-user')); $html .= Display::tag('td', api_convert_and_format_date($myrow['insert_date'], DATE_TIME_FORMAT_LONG), array('class' => 'announcements-list-line-datetime')); // we can edit if : we are the teacher OR the element belongs to // the session we are coaching OR the option to allow users to edit is on if (api_is_allowed_to_edit(false, true) or api_is_course_coach() && api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $myrow['id']) or api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous()) { $modify_icons = "<a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&action=modify&id=" . $myrow['id'] . "\">" . Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL) . "</a>"; if ($myrow['visibility'] == 1) { $image_visibility = "visible"; $alt_visibility = get_lang('Hide'); } else { $image_visibility = "invisible"; $alt_visibility = get_lang('Visible'); } $modify_icons .= "<a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&origin=" . $origin . "&action=showhide&id=" . $myrow['id'] . "&sec_token=" . $stok . "\">" . Display::return_icon($image_visibility . '.png', $alt_visibility, '', ICON_SIZE_SMALL) . "</a>"; // DISPLAY MOVE UP COMMAND only if it is not the top announcement if ($iterator != 1) { $modify_icons .= "<a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&action=move&up=" . $myrow["id"] . "&sec_token=" . $stok . "\">" . Display::return_icon('up.gif', get_lang('Up')) . "</a>"; } else { $modify_icons .= Display::return_icon('up_na.gif', get_lang('Up')); } if ($iterator < $bottomAnnouncement) { $modify_icons .= "<a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&action=move&down=" . $myrow["id"] . "&sec_token=" . $stok . "\">" . Display::return_icon('down.gif', get_lang('Down')) . "</a>"; } else { $modify_icons .= Display::return_icon('down_na.gif', get_lang('Down')); } if (api_is_allowed_to_edit(false, true)) { $modify_icons .= "<a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&action=delete&id=" . $myrow['id'] . "&sec_token=" . $stok . "\" onclick=\"javascript:if(!confirm('" . addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, api_get_system_encoding())) . "')) return false;\">" . Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL) . "</a>"; } $iterator++; $html .= Display::tag('td', $modify_icons, array('class' => 'announcements-list-line-actions')); } $html .= "</tr>"; } $displayed[] = $myrow['id']; } $html .= "</table>"; return $html; }
$user_info = api_get_user_info($myrow['insert_user_id']); $username = sprintf(get_lang("LoginX"), $user_info['username']); $username_span = Display::tag('span', api_get_person_name($user_info['firstName'], $user_info['lastName']), array('title' => $username)); echo Display::tag('td', $username_span, array('class' => 'announcements-list-line-by-user')); $sent_to_list = array(); $sent_to_list = AnnouncementManager::sent_to('announcement', $myrow['id']); $sent_to_form = AnnouncementManager::sent_to_form($sent_to_list); echo '<td class="announcements-list-line-by-user">' . substr($sent_to_form, 0, 45) . ' '; if (strlen($sent_to_form) > 45) { echo '...'; } '</td>'; echo Display::tag('td', api_convert_and_format_date($myrow['insert_date'], DATE_TIME_FORMAT_SHORT), array('class' => 'announcements-list-line-datetime')); // we can edit if : we are the teacher OR the element belongs to the session we are coaching OR the option to allow users to edit is on $modify_icons = ''; if (api_is_allowed_to_edit(false, true) or api_is_course_coach() && api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $myrow['id']) or api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous()) { $modify_icons = "<a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&action=modify&id=" . $myrow['id'] . "\">" . Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL) . "</a>"; if ($myrow['visibility'] == 1) { $image_visibility = "visible"; $alt_visibility = get_lang('Hide'); } else { $image_visibility = "invisible"; $alt_visibility = get_lang('Visible'); } $modify_icons .= "<a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&origin=" . $origin . "&action=showhide&id=" . $myrow['id'] . "&sec_token=" . $stok . "\">" . Display::return_icon($image_visibility . '.png', $alt_visibility, '', ICON_SIZE_SMALL) . "</a>"; // DISPLAY MOVE UP COMMAND only if it is not the top announcement if ($iterator != 1) { $modify_icons .= "<a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&up=" . $myrow["id"] . "&sec_token=" . $stok . "\">" . Display::return_icon('up.gif', get_lang('Up')) . "</a>"; } else { $modify_icons .= Display::return_icon('up_na.gif', get_lang('Up')); }
/** * @param $stok * @param $announcement_number * @param bool $getCount * @param null $start * @param null $limit * @param string $sidx * @param string $sord * @param string $titleToSearch * @param int $userIdToSearch * * @return array */ public static function getAnnouncements($stok, $announcement_number, $getCount = false, $start = null, $limit = null, $sidx = '', $sord = '', $titleToSearch = '', $userIdToSearch = 0) { $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT); $tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY); $user_id = api_get_user_id(); $group_id = api_get_group_id(); $session_id = api_get_session_id(); $condition_session = api_get_session_condition($session_id, true, true, 'announcement.session_id'); $course_id = api_get_course_int_id(); $_course = api_get_course_info(); $group_memberships = GroupManager::get_group_ids($course_id, api_get_user_id()); $allowUserEditSetting = api_get_course_setting('announcement.allow_user_edit_announcement'); $select = ' DISTINCT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date'; if ($getCount) { $select = ' COUNT(announcement.iid) count'; } $searchCondition = ''; if (!empty($titleToSearch)) { $titleToSearch = Database::escape_string($titleToSearch); $searchCondition .= " AND (title LIKE '%{$titleToSearch}%')"; } if (!empty($userIdToSearch)) { $userIdToSearch = intval($userIdToSearch); $searchCondition .= " AND (ip.insert_user_id = {$userIdToSearch})"; } if (api_is_allowed_to_edit(false, true) || $allowUserEditSetting && !api_is_anonymous()) { // A.1. you are a course admin with a USER filter // => see only the messages of this specific user + the messages of the group (s)he is member of. //if (!empty($user_id)) { if (0) { if (is_array($group_memberships) && count($group_memberships) > 0) { $sql = "SELECT {$select}\n FROM {$tbl_announcement} announcement, {$tbl_item_property} ip\n WHERE\n announcement.c_id = {$course_id} AND\n ip.c_id = {$course_id} AND\n announcement.id = ip.ref AND\n ip.tool = 'announcement' AND\n (\n ip.to_user_id = {$user_id} OR\n ip.to_group_id IS NULL OR\n ip.to_group_id IN (0, " . implode(", ", $group_memberships) . ")\n ) AND\n ip.visibility IN ('1', '0')\n {$condition_session}\n {$searchCondition}\n ORDER BY display_order DESC"; } else { $sql = "SELECT {$select}\n FROM {$tbl_announcement} announcement, {$tbl_item_property} ip\n WHERE\n announcement.c_id = {$course_id} AND\n ip.c_id = {$course_id} AND\n announcement.id = ip.ref AND\n ip.tool ='announcement' AND\n (ip.to_user_id = {$user_id} OR ip.to_group_id='0' OR ip.to_group_id IS NULL) AND\n ip.visibility IN ('1', '0')\n {$condition_session}\n {$searchCondition}\n ORDER BY display_order DESC"; } } elseif ($group_id != 0) { // A.2. you are a course admin with a GROUP filter // => see only the messages of this specific group $sql = "SELECT {$select}\n FROM {$tbl_announcement} announcement INNER JOIN {$tbl_item_property} ip\n ON (announcement.id = ip.ref AND ip.tool='announcement')\n WHERE\n announcement.c_id = {$course_id} AND\n ip.c_id = {$course_id} AND\n ip.visibility<>'2' AND\n (ip.to_group_id = {$group_id} OR ip.to_group_id='0' OR ip.to_group_id IS NULL)\n {$condition_session}\n {$searchCondition}\n ORDER BY display_order DESC"; //GROUP BY ip.ref } else { // A.3 you are a course admin without any group or user filter // A.3.a you are a course admin without user or group filter but WITH studentview // => see all the messages of all the users and groups without editing possibilities if (isset($isStudentView) && $isStudentView == "true") { $sql = "SELECT {$select}\n FROM {$tbl_announcement} announcement INNER JOIN {$tbl_item_property} ip\n ON (announcement.id = ip.ref AND ip.tool='announcement')\n WHERE\n announcement.c_id = {$course_id} AND\n ip.c_id = {$course_id} AND\n ip.tool='announcement' AND\n ip.visibility='1'\n {$condition_session}\n {$searchCondition}\n ORDER BY display_order DESC"; //GROUP BY ip.ref } else { // A.3.a you are a course admin without user or group filter and WTIHOUT studentview (= the normal course admin view) // => see all the messages of all the users and groups with editing possibilities $sql = "SELECT {$select}\n FROM {$tbl_announcement} announcement INNER JOIN {$tbl_item_property} ip\n ON (announcement.id = ip.ref AND ip.tool='announcement')\n WHERE\n announcement.c_id = {$course_id} AND\n ip.c_id = {$course_id} AND\n (ip.visibility='0' or ip.visibility='1')\n {$condition_session}\n {$searchCondition}\n ORDER BY display_order DESC"; //GROUP BY ip.ref } } } else { // STUDENT if (is_array($group_memberships) && count($group_memberships) > 0) { if ($allowUserEditSetting && !api_is_anonymous()) { if ($group_id == 0) { // No group $cond_user_id = " AND (\n ip.lastedit_user_id = '" . $user_id . "' OR (\n ip.to_user_id='" . $user_id . "' OR\n (ip.to_group_id IS NULL OR ip.to_group_id IN (0, " . implode(", ", $group_memberships) . "))\n )\n ) "; } else { $cond_user_id = " AND (\n ip.lastedit_user_id = '" . $user_id . "' OR ip.to_group_id IS NULL OR ip.to_group_id IN (0, " . $group_id . ")\n )"; } } else { if ($group_id == 0) { $cond_user_id = " AND (\n ip.to_user_id = {$user_id} AND (ip.to_group_id IS NULL OR ip.to_group_id IN (0, " . implode(", ", $group_memberships) . "))\n ) "; } else { $cond_user_id = " AND (\n ip.to_user_id = {$user_id} AND (ip.to_group_id IS NULL OR ip.to_group_id IN (0, " . $group_id . "))\n )"; } } $sql = "SELECT {$select}\n FROM {$tbl_announcement} announcement,\n {$tbl_item_property} ip\n WHERE\n announcement.c_id = {$course_id} AND\n ip.c_id = {$course_id} AND\n announcement.id = ip.ref\n AND ip.tool='announcement'\n {$cond_user_id}\n {$condition_session}\n {$searchCondition}\n AND ip.visibility='1'\n ORDER BY display_order DESC"; } else { if ($user_id) { if ($allowUserEditSetting && !api_is_anonymous()) { $cond_user_id = " AND (\n ip.lastedit_user_id = '" . api_get_user_id() . "' OR\n (ip.to_user_id='" . $user_id . "' AND (ip.to_group_id='0' OR ip.to_group_id IS NULL))\n ) "; } else { $cond_user_id = " AND (ip.to_user_id='" . $user_id . "' AND (ip.to_group_id='0' OR ip.to_group_id IS NULL) ) "; } $sql = "SELECT {$select}\n\t\t\t\t\t\tFROM {$tbl_announcement} announcement, {$tbl_item_property} ip\n\t\t\t\t\t\tWHERE\n \t\t\t\t\t\tannouncement.c_id = {$course_id} AND\n\t\t\t\t\t\t\tip.c_id = {$course_id} AND\n \t\t\t\t\t\tannouncement.id = ip.ref AND\n \t\t\t\t\t\tip.tool='announcement'\n \t\t\t\t\t\t{$cond_user_id}\n \t\t\t\t\t\t{$condition_session}\n \t\t\t\t\t\t{$searchCondition}\n \t\t\t\t\t\tAND ip.visibility='1'\n \t\t\t\t\t\tAND announcement.session_id IN(0, " . $session_id . ")\n\t\t\t\t\t\tORDER BY display_order DESC"; } else { if ($allowUserEditSetting && !api_is_anonymous()) { $cond_user_id = " AND (\n ip.lastedit_user_id = '" . $user_id . "' OR ip.to_group_id='0' OR ip.to_group_id IS NULL\n )"; } else { $cond_user_id = " AND ip.to_group_id='0' OR ip.to_group_id IS NULL "; } $sql = "SELECT {$select}\n\t\t\t\t\t\tFROM {$tbl_announcement} announcement, {$tbl_item_property} ip\n\t\t\t\t\t\tWHERE\n announcement.c_id = {$course_id} AND\n ip.c_id = {$course_id} AND\n announcement.id = ip.ref AND\n ip.tool='announcement'\n {$cond_user_id}\n {$condition_session}\n {$searchCondition}\n AND\n ip.visibility='1' AND\n announcement.session_id IN ( 0," . api_get_session_id() . ")"; } } } if (!is_null($start) && !is_null($limit)) { $start = intval($start); $limit = intval($limit); $sql .= " LIMIT {$start}, {$limit}"; } $result = Database::query($sql); if ($getCount) { $result = Database::fetch_array($result, 'ASSOC'); return $result['count']; } $iterator = 1; $bottomAnnouncement = $announcement_number; $origin = null; $displayed = []; $results = []; $actionUrl = api_get_path(WEB_CODE_PATH) . 'announcements/announcements.php?' . api_get_cidreq(); while ($myrow = Database::fetch_array($result, 'ASSOC')) { if (!in_array($myrow['id'], $displayed)) { $sent_to_icon = ''; // the email icon if ($myrow['email_sent'] == '1') { $sent_to_icon = ' ' . Display::return_icon('email.gif', get_lang('AnnounceSentByEmail')); } $title = $myrow['title'] . $sent_to_icon; $item_visibility = api_get_item_visibility($_course, TOOL_ANNOUNCEMENT, $myrow['id'], $session_id); $myrow['visibility'] = $item_visibility; // show attachment list $attachment_list = AnnouncementManager::get_attachment($myrow['id']); $attachment_icon = ''; if (count($attachment_list) > 0) { $attachment_icon = ' ' . Display::return_icon('attachment.gif', get_lang('Attachment')); } /* TITLE */ $user_info = api_get_user_info($myrow['insert_user_id']); $username = sprintf(get_lang("LoginX"), $user_info['username']); $username_span = Display::tag('span', api_get_person_name($user_info['firstName'], $user_info['lastName']), array('title' => $username)); $title = Display::url($title . $attachment_icon, $actionUrl . '&action=view&id=' . $myrow['id']); //$html .= Display::tag('td', $username_span, array('class' => 'announcements-list-line-by-user')); //$html .= Display::tag('td', api_convert_and_format_date($myrow['insert_date'], DATE_TIME_FORMAT_LONG), array('class' => 'announcements-list-line-datetime')); $modify_icons = ''; // we can edit if : we are the teacher OR the element belongs to // the session we are coaching OR the option to allow users to edit is on if (api_is_allowed_to_edit(false, true) || api_is_course_coach() && api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $myrow['id']) || api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous()) { $modify_icons = "<a href=\"" . $actionUrl . "&action=modify&id=" . $myrow['id'] . "\">" . Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL) . "</a>"; if ($myrow['visibility'] == 1) { $image_visibility = "visible"; $alt_visibility = get_lang('Hide'); } else { $image_visibility = "invisible"; $alt_visibility = get_lang('Visible'); } $modify_icons .= "<a href=\"" . $actionUrl . "&origin=" . $origin . "&action=showhide&id=" . $myrow['id'] . "&sec_token=" . $stok . "\">" . Display::return_icon($image_visibility . '.png', $alt_visibility, '', ICON_SIZE_SMALL) . "</a>"; // DISPLAY MOVE UP COMMAND only if it is not the top announcement if ($iterator != 1) { $modify_icons .= "<a href=\"" . $actionUrl . "&action=move&up=" . $myrow["id"] . "&sec_token=" . $stok . "\">" . Display::return_icon('up.gif', get_lang('Up')) . "</a>"; } else { $modify_icons .= Display::return_icon('up_na.gif', get_lang('Up')); } if ($iterator < $bottomAnnouncement) { $modify_icons .= "<a href=\"" . $actionUrl . "&action=move&down=" . $myrow["id"] . "&sec_token=" . $stok . "\">" . Display::return_icon('down.gif', get_lang('Down')) . "</a>"; } else { $modify_icons .= Display::return_icon('down_na.gif', get_lang('Down')); } if (api_is_allowed_to_edit(false, true)) { $modify_icons .= "<a href=\"" . $actionUrl . "&action=delete&id=" . $myrow['id'] . "&sec_token=" . $stok . "\" onclick=\"javascript:if(!confirm('" . addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, api_get_system_encoding())) . "')) return false;\">" . Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL) . "</a>"; } $iterator++; } else { $modify_icons = Display::url(Display::return_icon('default.png'), $actionUrl . '&action=view&id=' . $myrow['id']); } $announcement = ['id' => $myrow["id"], 'title' => $title, 'username' => $username_span, 'insert_date' => api_convert_and_format_date($myrow['insert_date'], DATE_TIME_FORMAT_LONG), 'actions' => $modify_icons]; $results[] = $announcement; } $displayed[] = $myrow['id']; } return $results; }
/* For licensing terms, see /license.txt */ /** * Responses to AJAX calls */ require_once '../global.inc.php'; $action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null; $isAllowedToEdit = api_is_allowed_to_edit(); $courseInfo = api_get_course_info(); switch ($action) { case 'delete_item': if ($isAllowedToEdit) { if (empty($_REQUEST['id'])) { return false; } if (api_get_session_id() != 0 && api_is_allowed_to_session_edit(false, true) == false) { return false; } $list = explode(',', $_REQUEST['id']); foreach ($list as $itemId) { if (!api_is_course_coach() || api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $itemId)) { AnnouncementManager::delete_announcement($courseInfo, $itemId); } } } break; default: echo ''; break; } exit;
/** * Displays all the agenda items * @author Patrick Cool <*****@*****.**>, Ghent University * @author Yannick Warnier <*****@*****.**> - cleanup * @author Julio Montoya <*****@*****.**> - Refactoring */ function display_agenda_items($agenda_items, $day = false) { global $charset; if (isset($day) && $day) { $new_items = array(); foreach ($agenda_items as $item) { if (substr($item['start_date'], 8, 2) == $day) { $new_items[] = $item; } } $agenda_items = $new_items; } if (isset($_GET['sort']) && $_GET['sort'] == 'asc') { $sort_inverse = 'desc'; $sort = 'asc'; } else { $sort_inverse = 'asc'; $sort = 'desc'; } if (isset($_GET['col']) && $_GET['col'] == 'end') { $sort_item = 'end_date_tms'; $col = 'end'; } else { $sort_item = 'start_date_tms'; $col = 'start'; } $agenda_items = msort($agenda_items, $sort_item, $sort); //DISPLAY: NO ITEMS if (empty($agenda_items)) { echo Display::display_warning_message(get_lang('NoAgendaItems')); } else { echo '<table class="data_table">'; $th = Display::tag('th', get_lang('Title')); $month = isset($_GET['month']) ? intval($_GET['month']) : null; $year = isset($_GET['year']) ? intval($_GET['year']) : null; $day = isset($_GET['day']) ? intval($_GET['day']) : null; $url = api_get_self() . '?' . api_get_cidreq() . '&month=' . $month . '&year=' . $year . '&day=' . $day; $th .= Display::tag('th', Display::url(get_lang('StartTimeWindow'), $url . '&sort=' . $sort_inverse . '&col=start')); $th .= Display::tag('th', Display::url(get_lang('EndTimeWindow'), $url . '&sort=' . $sort_inverse . '&col=end')); if (api_is_allowed_to_edit(false, true) or api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()) { $th .= Display::tag('th', get_lang('Modify')); } echo Display::tag('tr', $th); $counter = 0; foreach ($agenda_items as $myrow) { $is_repeated = !empty($myrow['parent_event_id']); $class = 'row_even'; if ($counter % 2) { $class = 'row_odd'; } /* display: the icon, title, destinees of the item */ echo '<tr class="' . $class . '">'; //Title echo "<td>"; $attach_icon = ''; // attachment list $attachment_list = get_attachment($myrow['id']); if (!empty($attachment_list)) { $attach_icon = ' ' . Display::return_icon('attachment.gif', get_lang('Attachment')); } $title_class = ''; if (isset($myrow['visibility']) && $myrow['visibility'] == 0) { $title_class = 'invisible'; } switch ($myrow['calendar_type']) { case 'global': $icon_type = Display::return_icon('view_remove.png', get_lang('GlobalEvent'), array(), 22); echo $icon_type . ' ' . $myrow['title'] . $attach_icon; break; case 'personal': $icon_type = Display::return_icon('user.png', get_lang(' '), array(), 22); echo $icon_type . ' ' . $myrow['title'] . $attach_icon; break; case 'course': $icon_type = Display::return_icon('course.png', get_lang('Course'), array(), 22); $agenda_url = api_get_path(WEB_CODE_PATH) . 'calendar/agenda.php?agenda_id=' . $myrow['id'] . '&action=view'; echo Display::url($icon_type . ' ' . $myrow['title'] . $attach_icon, $agenda_url, array('class' => $title_class)); break; } echo '</td>'; //Start date echo '<td>'; if (!empty($myrow['start_date']) && $myrow['start_date'] != '0000-00-00 00:00:00') { echo api_format_date($myrow['start_date']); } echo '</td>'; //End date echo '<td>'; if (!empty($myrow['end_date']) && $myrow['end_date'] != '0000-00-00 00:00:00') { echo api_format_date($myrow['end_date']); } echo '</td>'; /* Display: edit delete button (course admin only) */ if (!$is_repeated && (api_is_allowed_to_edit(false, true) or api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()) && $myrow['calendar_type'] == 'course') { echo '<td align="center">'; if (!(api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $myrow['id']))) { // a coach can only delete an element belonging to his session $mylink = api_get_self() . '?' . api_get_cidreq() . '&origin=' . Security::remove_XSS($_GET['origin']) . '&id=' . $myrow['id'] . '&sort=' . $sort . '&col=' . $col . '&'; // edit echo '<a href="' . $mylink . api_get_cidreq() . "&toolgroup=" . Security::remove_XSS($_GET['toolgroup']) . '&action=edit&id_attach=' . $attachment_list['id'] . '" title="' . get_lang("ModifyCalendarItem") . '">'; echo Display::return_icon('edit.png', get_lang('ModifyCalendarItem'), '', ICON_SIZE_SMALL) . "</a>"; echo '<a href="' . $mylink . api_get_cidreq() . "&toolgroup=" . Security::remove_XSS($_GET['toolgroup']) . '&action=announce" title="' . get_lang("AddAnnouncement") . '">'; echo Display::return_icon('new_announce.png', get_lang('AddAnnouncement'), array(), ICON_SIZE_SMALL) . "</a> "; if ($myrow['visibility'] == 1) { $image_visibility = "visible"; $text_visibility = get_lang("Hide"); $next_action = 0; } else { $image_visibility = "invisible"; $text_visibility = get_lang("Show"); $next_action = 1; } echo '<a href="' . $mylink . api_get_cidreq() . '&toolgroup=' . Security::remove_XSS($_GET['toolgroup']) . '&action=showhide&next_action=' . $next_action . '" title="' . $text_visibility . '">' . Display::return_icon($image_visibility . '.png', $text_visibility, '', ICON_SIZE_SMALL) . '</a> '; echo "<a href=\"" . $mylink . api_get_cidreq() . "&toolgroup=" . Security::remove_XSS($_GET['toolgroup']) . "&action=delete\" onclick=\"javascript:if(!confirm('" . addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset)) . "')) return false;\" title=\"" . get_lang("Delete") . "\"> "; echo Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL) . " </a>"; } $mylink = 'ical_export.php?' . api_get_cidreq() . '&type=course&id=' . $myrow['id']; //echo '<a class="ical_export" href="'.$mylink.'&class=confidential" title="'.get_lang('ExportiCalConfidential').'">'.Display::return_icon($export_icon_high, get_lang('ExportiCalConfidential')).'</a> '; //echo '<a class="ical_export" href="'.$mylink.'&class=private" title="'.get_lang('ExportiCalPrivate').'">'.Display::return_icon($export_icon_low, get_lang('ExportiCalPrivate')).'</a> '; //echo '<a class="ical_export" href="'.$mylink.'&class=public" title="'.get_lang('ExportiCalPublic').'">'.Display::return_icon($export_icon, get_lang('ExportiCalPublic')).'</a> '; echo '<a href="#" onclick="javascript:win_print=window.open(\'print.php?id=' . $myrow['id'] . '\',\'popup\',\'left=100,top=100,width=700,height=500,scrollbars=1,resizable=0\'); win_print.focus(); return false;">' . Display::return_icon('printer.png', get_lang('Print'), '', ICON_SIZE_SMALL) . '</a> '; echo '</td>'; } else { if ($is_repeated && (api_is_allowed_to_edit(false, true) || api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous())) { echo '<td align="center">'; echo get_lang('RepeatedEvent'), ' <a href="', api_get_self(), '?', api_get_cidreq(), '&agenda_id=', $myrow['parent_event_id'], '" alt="', get_lang('RepeatedEventViewOriginalEvent'), '">', get_lang('RepeatedEventViewOriginalEvent'), '</a>'; echo '</td>'; } if ((api_is_allowed_to_edit(false, true) || api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()) && ($myrow['calendar_type'] == 'personal' or $myrow['calendar_type'] == 'global')) { echo '<td align="center">'; echo '</td>'; } } $counter++; echo "</tr>"; } // end while ($myrow=Database::fetch_array($result)) echo "</table><br /><br />"; } if (!empty($event_list)) { $event_list = api_substr($event_list, 0, -1); } else { $event_list = '0'; } echo "<form name=\"event_list_form\"><input type=\"hidden\" name=\"event_list\" value=\"{$event_list}\" /></form>"; // closing the layout table echo "</td>", "</tr>", "</table>"; }
/** * Displays only 1 agenda item. This is used when an agenda item is added to the learning path. * @author Patrick Cool <*****@*****.**>, Ghent University */ function display_one_agenda_item($agenda_id) { global $TABLEAGENDA; global $TABLE_ITEM_PROPERTY; global $select_month, $select_year; global $DaysShort, $DaysLong, $MonthsLong; global $dateFormatLong, $timeNoSecFormat, $charset; // getting the name of the groups $group_names = get_course_groups(); $agenda_id = intval($agenda_id); if (!(api_is_allowed_to_edit(false, true) || api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous())) { $visibility_condition = " AND ip.visibility='1' "; } $sql = "SELECT agenda.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.ref\n\t\t\tFROM " . $TABLEAGENDA . " agenda, " . $TABLE_ITEM_PROPERTY . " ip\n\t\t\tWHERE agenda.id = ip.ref\n\t\t\tAND ip.tool='" . TOOL_CALENDAR_EVENT . "'\n\t\t\t{$visibility_condition}\n\t\t\tAND agenda.id='{$agenda_id}'"; $result = Database::query($sql); $number_items = Database::num_rows($result); $myrow = Database::fetch_array($result, 'ASSOC'); // there should be only one item so no need for a while loop $sql_rep = "SELECT * FROM {$TABLEAGENDA} WHERE id = {$agenda_id} AND parent_event_id IS NOT NULL AND parent_event_id !=0"; $res_rep = Database::query($sql_rep); $repeat = false; $repeat_id = 0; if (Database::num_rows($res_rep) > 0) { $repeat = true; $row_rep = Database::fetch_array($res_rep); $repeat_id = $row_rep['parent_event_id']; } // DISPLAY: NO ITEMS if ($number_items == 0) { Display::display_warning_message(get_lang("NoAgendaItems")); return false; } // DISPLAY: THE ITEMS echo "<table id=\"data_table\" class=\"data_table\">"; // DISPLAY : the icon, title, destinees of the item $myrow["start_date"] = api_get_local_time($myrow["start_date"]); // highlight: if a date in the small calendar is clicked we highlight the relevant items $db_date = (int) api_format_date($myrow["start_date"], "%d") . intval(api_format_date($myrow["start_date"], "%m")) . api_format_date($myrow["start_date"], "%Y"); if ($_GET["day"] . $_GET["month"] . $_GET["year"] != $db_date) { if ($myrow['visibility'] == '0') { $style = "data_hidden"; $stylenotbold = "datanotbold_hidden"; $text_style = "text_hidden"; } else { $style = "data"; $stylenotbold = "datanotbold"; $text_style = "text"; } } else { $style = "datanow"; $stylenotbold = "datanotboldnow"; $text_style = "textnow"; } echo Display::tag('h2', $myrow['title']); echo "<tr>"; if (api_is_allowed_to_edit(false, true)) { if (!(api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $myrow['id']))) { // a coach can only delete an element belonging to his session // DISPLAY: edit delete button (course admin only) $export_icon = '../img/export.png'; $export_icon_low = '../img/export_low_fade.png'; $export_icon_high = '../img/export_high_fade.png'; echo '<th style="text-align:right">'; if (!$repeat && api_is_allowed_to_edit(false, true)) { // edit $mylink = api_get_self() . "?" . api_get_cidreq() . "&origin=" . Security::remove_XSS($_GET['origin']) . "&id=" . $myrow['id']; if (!empty($_GET['agenda_id'])) { // rather ugly hack because the id parameter is already set above but below we set it again $mylink .= '&agenda_id=' . Security::remove_XSS($_GET['agenda_id']) . '&id=' . Security::remove_XSS($_GET['agenda_id']); } if ($myrow['visibility'] == 1) { $image_visibility = "visible"; $next_action = 0; } else { $image_visibility = "invisible"; $next_action = 1; } echo '<a href="' . $mylink . '&action=showhide&next_action=' . $next_action . '">' . Display::return_icon($image_visibility . '.png', get_lang('Visible'), '', ICON_SIZE_SMALL) . '</a>'; echo "<a href=\"" . $mylink . "&action=edit\">", Display::return_icon('edit.png', get_lang('ModifyCalendarItem'), '', ICON_SIZE_SMALL), "</a>", "<a href=\"" . $mylink . "&action=delete\" onclick=\"javascript:if(!confirm('" . addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset)) . "')) return false;\">", Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL), "</a>"; } $mylink = 'ical_export.php?' . api_get_cidreq() . '&type=course&id=' . $myrow['id']; //echo '<a class="ical_export" href="'.$mylink.'&class=confidential" title="'.get_lang('ExportiCalConfidential').'">'.Display::return_icon($export_icon_high, get_lang('ExportiCalConfidential')).'</a> '; //echo '<a class="ical_export" href="'.$mylink.'&class=private" title="'.get_lang('ExportiCalPrivate').'">'.Display::return_icon($export_icon_low, get_lang('ExportiCalPrivate')).'</a> '; //echo '<a class="ical_export" href="'.$mylink.'&class=public" title="'.get_lang('ExportiCalPublic').'">'.Display::return_icon($export_icon, get_lang('ExportiCalPublic')).'</a> '; echo '<a href="javascript: void(0);" onclick="javascript:win_print=window.open(\'print.php?id=' . $myrow['id'] . '\',\'popup\',\'left=100,top=100,width=700,height=500,scrollbars=1,resizable=0\'); win_print.focus(); return false;">' . Display::return_icon('printer.png', get_lang('Print'), '', ICON_SIZE_SMALL) . '</a> '; echo "</th>"; } } // title echo "<tr class='row_odd'>"; echo '<td colspan="2">' . get_lang("StartTime") . ": "; echo api_format_date($myrow['start_date']); echo "</td>"; echo "</td>"; echo "<tr class='row_odd'>"; echo '<td colspan="2">' . get_lang("EndTime") . ": "; echo api_convert_and_format_date($myrow['end_date']); echo "</td>"; // Content $content = $myrow['content']; $content = Text::make_clickable($content); echo '<tr class="row_even">'; echo '<td ' . (api_is_allowed_to_edit() ? 'colspan="3"' : 'colspan="2"') . '>'; echo $content; echo '</td></tr>'; //Attachments $attachment_list = get_attachment($agenda_id); if (!empty($attachment_list)) { echo '<tr class="row_even"><td colspan="2">'; $realname = $attachment_list['path']; $user_filename = $attachment_list['filename']; $full_file_name = 'download.php?file=' . $realname; echo Display::return_icon('attachment.gif', get_lang('Attachment')); echo '<a href="' . $full_file_name . '"> ' . $user_filename . '</a>'; if (api_is_allowed_to_edit()) { echo ' <a href="' . api_get_self() . '?' . api_get_cidreq() . '&origin=' . Security::remove_XSS($_GET['origin']) . '&action=delete_attach&id_attach=' . $attachment_list['id'] . '" onclick="javascript:if(!confirm(\'' . addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset)) . '\')) return false;">' . Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL) . '</a><br />'; } echo '<br /><span class="forum_attach_comment" >' . $attachment_list['comment'] . '</span>'; echo '</td></tr>'; } // the message has been sent to echo '<tr>'; echo "<td class='announcements_datum'>" . get_lang("SentTo") . ": "; $sent_to = sent_to(TOOL_CALENDAR_EVENT, $myrow["ref"]); $sent_to_form = sent_to_form($sent_to); echo $sent_to_form; echo "</td></tr>"; if ($repeat) { echo '<tr>'; echo '<td colspan="2">'; echo get_lang('RepeatedEvent') . ' <a href="', api_get_self(), '?', api_get_cidreq(), '&agenda_id=', $repeat_id, '" alt="', get_lang('RepeatedEventViewOriginalEvent'), '">', get_lang('RepeatedEventViewOriginalEvent'), '</a>'; echo '</td>'; echo '</tr>'; } /* Added resources */ if (check_added_resources("Agenda", $myrow["id"])) { echo "<tr><td colspan='3'>"; echo "<i>" . get_lang("AddedResources") . "</i><br/>"; if ($myrow['visibility'] == 0) { $addedresource_style = "invisible"; } display_added_resources("Agenda", $myrow["id"], $addedresource_style); echo "</td></tr>"; } // closing the layout table echo "</td>", "</tr>", "</table>"; }
/** * Displays all the agenda items * @author Patrick Cool <*****@*****.**>, Ghent University * @author Yannick Warnier <*****@*****.**> - cleanup */ function display_agenda_items() { global $select_month, $select_year; global $DaysShort, $DaysLong, $MonthsLong; global $is_courseAdmin; global $dateFormatLong, $timeNoSecFormat, $charset, $_user, $_course; $TABLEAGENDA = Database::get_main_table(TABLE_MAIN_SYSTEM_CALENDAR); // getting the group memberships //$group_memberships=GroupManager::get_group_ids($_course['dbName'],$_user['user_id']); // getting the name of the groups //$group_names=get_course_groups(); /*-------------------------------------------------- CONSTRUCT THE SQL STATEMENT --------------------------------------------------*/ $start = 0; $stop = 0; // this is to make a difference between showing everything (all months) or only the current month) // $show_all_current is a part of the sql statement if ($_SESSION['show_all_admin'] !== "showall") { $show_all_current = " AND MONTH(start_date)={$select_month} AND year(start_date)={$select_year}"; $start = mktime(0, 0, 0, $select_month, 1, $select_year); $stop = 0; if (empty($select_year)) { $select_year = date('Y'); } if (empty($select_month)) { $select_month = date('m'); } if ($select_month == 12) { $stop = mktime(0, 0, 0, 1, 1, $select_year + 1) - 1; } else { $stop = mktime(0, 0, 0, $select_month + 1, 1, $select_year) - 1; } } else { $show_all_current = ""; $start = time(); $stop = mktime(0, 0, 0, 1, 1, 2038); //by default, set year to maximum for mktime() } // by default we use the id of the current user. The course administrator can see the agenda of other users by using the user / group filter $repeats = array(); //placeholder for repeated events if (api_is_allowed_to_edit() && !api_is_anonymous()) { $sql = "SELECT * FROM " . $TABLEAGENDA; global $_configuration; $current_access_url_id = 1; if ($_configuration['multiple_access_urls']) { $current_access_url_id = api_get_current_access_url_id(); } $sql .= " WHERE access_url_id = {$current_access_url_id}"; $sql .= ' ORDER BY start_date ' . $_SESSION['sort']; //echo "<pre>".$sql."</pre>"; $result = Database::query($sql) or die(Database::error()); $number_items = Database::num_rows($result); } else { $number_items = 0; } /*-------------------------------------------------- DISPLAY: NO ITEMS --------------------------------------------------*/ if ($number_items == 0) { echo "<table class=\"data_table\" ><tr><td>" . get_lang("NoAgendaItems") . "</td></tr></table>"; } /*-------------------------------------------------- DISPLAY: THE ITEMS --------------------------------------------------*/ $month_bar = ""; $event_list = ""; $counter = 0; $export_icon = 'export.png'; $export_icon_low = 'export_low_fade.png'; $export_icon_high = 'export_high_fade.png'; while ($myrow = Database::fetch_array($result)) { $is_repeated = !empty($myrow['parent_event_id']); echo '<table class="data_table">'; $myrow["start_date"] = api_get_local_time($myrow["start_date"]); if ($month_bar != api_format_date($myrow["start_date"], "%m%Y")) { $month_bar = api_format_date($myrow["start_date"], "%m%Y"); echo "<tr><td class=\"agenda_month_divider\" colspan=\"3\" valign=\"top\">" . api_format_date($myrow["start_date"], "%B %Y") . "</td></tr>"; } /*-------------------------------------------------- display: the icon, title, destinees of the item -------------------------------------------------*/ echo '<tr>'; // highlight: if a date in the small calendar is clicked we highlight the relevant items $db_date = (int) api_format_date($myrow["start_date"], "%d") . intval(api_format_date($myrow["start_date"], "%m")) . api_format_date($myrow["start_date"], "%Y"); if ($_GET["day"] . $_GET["month"] . $_GET["year"] != $db_date) { if ($myrow['visibility'] == '0') { $style = "data_hidden"; $stylenotbold = "datanotbold_hidden"; $text_style = "text_hidden"; } else { $style = "data"; $stylenotbold = "datanotbold"; $text_style = "text"; } } else { $style = "datanow"; $stylenotbold = "datanotboldnow"; $text_style = "textnow"; } echo "<th>"; // adding an internal anchor echo "<a name=\"" . (int) date("d", strtotime($myrow["start_date"])) . "\"></a>"; // the icons. If the message is sent to one or more specific users/groups // we add the groups icon // 2do: if it is sent to groups we display the group icon, if it is sent to a user we show the user icon Display::display_icon('platform_event.png', get_lang('GlobalEvent'), '', ICON_SIZE_SMALL); /*if ($myrow['to_group_id']!=='0') { echo Display::return_icon('group.gif', get_lang('AllUsersOfThePlatform')); }*/ echo " " . $myrow['title'] . ""; echo "</th>"; // the message has been sent to echo "<th>" . get_lang("SentTo") . ": " . get_lang('AllUsersOfThePlatform'); //$sent_to=sent_to(TOOL_CALENDAR_EVENT, $myrow["ref"]); //$sent_to_form=sent_to_form($sent_to); // echo $sent_to_form; echo "</th>"; if (!$is_repeated && (api_is_allowed_to_edit(false, true) or api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous())) { if (!(api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $myrow['id']))) { // a coach can only delete an element belonging to his session echo '<th>' . get_lang('Actions'); echo '</th></tr>'; } } // display: the title echo "<tr class='row_odd'>"; echo "<td>" . get_lang("StartTimeWindow") . ": "; echo api_format_date($myrow["start_date"], DATE_TIME_FORMAT_LONG); echo "</td>"; echo "<td>"; if ($myrow["end_date"] != "0000-00-00 00:00:00") { $myrow["end_date"] = api_get_local_time($myrow["end_date"]); echo get_lang("EndTimeWindow") . ": "; echo api_format_date($myrow["end_date"], DATE_TIME_FORMAT_LONG); } echo "</td>"; if (!$is_repeated && (api_is_allowed_to_edit(false, true) or api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous())) { if (!(api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $myrow['id']))) { // a coach can only delete an element belonging to his session $mylink = api_get_self() . '?' . api_get_cidreq() . '&origin=' . Security::remove_XSS($_GET['origin']) . '&id=' . $myrow['id']; echo '<td align="center">'; // edit echo '<a href="' . $mylink . '&action=edit&title="' . get_lang("ModifyCalendarItem") . '">'; echo Display::return_icon('edit.gif', get_lang('ModifyCalendarItem')) . "</a>"; echo "<a href=\"" . $mylink . "&action=delete\" onclick=\"javascript:if(!confirm('" . addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset)) . "')) return false;\" title=\"" . get_lang("Delete") . "\"> "; echo Display::return_icon('delete.gif', get_lang('Delete')) . "</a>"; } if (!$is_repeated && (api_is_allowed_to_edit(false, true) or api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous())) { if (!(api_is_course_coach() && !api_is_element_in_the_session(TOOL_AGENDA, $myrow['id']))) { // a coach can only delete an element belonging to his session $td_colspan = '<td colspan="3">'; } else { $td_colspan = '<td colspan="2">'; } } else { $td_colspan = '<td colspan="2">'; } $mylink = 'calendar_ical_export.php?' . api_get_cidreq() . '&type=course&id=' . $myrow['id']; echo '<a class="ical_export" href="' . $mylink . '&class=confidential" title="' . get_lang('ExportiCalConfidential') . '">' . Display::return_icon($export_icon_high, get_lang('ExportiCalConfidential')) . '</a> '; echo '<a class="ical_export" href="' . $mylink . '&class=private" title="' . get_lang('ExportiCalPrivate') . '">' . Display::return_icon($export_icon_low, get_lang('ExportiCalPrivate')) . '</a> '; echo '<a class="ical_export" href="' . $mylink . '&class=public" title="' . get_lang('ExportiCalPublic') . '">' . Display::return_icon($export_icon, get_lang('ExportiCalPublic')) . '</a> '; echo '<a href="#" onclick="javascript:win_print=window.open(\'calendar_view_print.php?id=' . $myrow['id'] . '\',\'popup\',\'left=100,top=100,width=700,height=500,scrollbars=1,resizable=0\'); win_print.focus(); return false;">' . Display::return_icon('print.gif', get_lang('Print')) . '</a> '; echo '</td>'; echo '</tr>'; } /*-------------------------------------------------- display: the content --------------------------------------------------*/ $content = $myrow['content']; $content = make_clickable($content); echo "<tr class='row_even'>"; echo "<td colspan='3'>"; echo $content; // show attachment list if (!empty($attachment_list)) { $realname = $attachment_list['path']; $user_filename = $attachment_list['filename']; $full_file_name = 'download.php?file=' . $realname; echo Display::return_icon('attachment.gif', get_lang('Attachment')); echo '<a href="' . $full_file_name . ''; echo ' "> ' . $user_filename . ' </a>'; echo '<span class="forum_attach_comment" >' . $attachment_list['comment'] . '</span>'; if (api_is_allowed_to_edit()) { echo ' <a href="' . api_get_self() . '?' . api_get_cidreq() . '&origin=' . Security::remove_XSS($_GET['origin']) . '&action=delete_attach&id_attach=' . $attachment_list['id'] . '" onclick="javascript:if(!confirm(\'' . addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES, $charset)) . '\')) return false;">' . Display::return_icon('delete.gif', get_lang('Delete')) . '</a><br />'; } } echo '</td></tr>'; /*-------------------------------------------------- display: the added resources -------------------------------------------------- if (check_added_resources("Agenda", $myrow["id"])) { echo '<tr>'; echo '<td colspan="3">'; echo "<i>".get_lang("AddedResources")."</i><br/>"; if ($myrow['visibility']==0) { $addedresource_style="invisible"; } display_added_resources("Agenda", $myrow["id"], $addedresource_style); echo "</td></tr>"; }*/ $event_list .= $myrow['id'] . ','; $counter++; /*-------------------------------------------------- display: jump-to-top icon --------------------------------------------------*/ echo '<tr>'; echo '<td colspan="3">'; if ($is_repeated) { echo get_lang('RepeatedEvent'), '<a href="', api_get_self(), '?', api_get_cidreq, '&agenda_id=', $myrow['parent_event_id'], '" alt="', get_lang('RepeatedEventViewOriginalEvent'), '">', get_lang('RepeatedEventViewOriginalEvent'), '</a>'; } echo "<a href=\"#top\">" . Display::return_icon('top.gif', get_lang('Top')) . "</a></td></tr>"; echo "</table><br /><br />"; } // end while ($myrow=Database::fetch_array($result)) if (!empty($event_list)) { $event_list = substr($event_list, 0, -1); } else { $event_list = '0'; } echo "<form name=\"event_list_form\"><input type=\"hidden\" name=\"event_list\" value=\"{$event_list}\" /></form>"; // closing the layout table echo "</td>", "</tr>", "</table>"; }