/** * @param $visible * @param $id * @param int $start * @param string $user_id * @return string */ public static function display_all_announcements($visible, $id = -1, $start = 0, $user_id = '') { $user_selected_language = api_get_interface_language(); $start = intval($start); $userGroup = new UserGroup(); $tbl_announcement_group = Database::get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS_GROUPS); $temp_user_groups = $userGroup->get_groups_by_user(api_get_user_id(), 0); $groups = array(); foreach ($temp_user_groups as $user_group) { $groups = array_merge($groups, array($user_group['id'])); $groups = array_merge($groups, $userGroup->get_parent_groups($user_group['id'])); } // Checks if tables exists to not break platform not updated $groups_string = '(' . implode($groups, ',') . ')'; $db_table = Database::get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); $now = api_get_utc_datetime(); $sql = "SELECT * FROM " . $db_table . "\n\t\t\t\tWHERE\n\t\t\t\t (lang = '{$user_selected_language}' OR lang IS NULL) AND\n\t\t\t\t ( '{$now}' >= date_start AND '{$now}' <= date_end) "; switch ($visible) { case self::VISIBLE_GUEST: $sql .= " AND visible_guest = 1 "; break; case self::VISIBLE_STUDENT: $sql .= " AND visible_student = 1 "; break; case self::VISIBLE_TEACHER: $sql .= " AND visible_teacher = 1 "; break; } if (count($groups) > 0) { $sql .= " OR id IN (\n SELECT announcement_id FROM {$tbl_announcement_group}\n WHERE group_id in {$groups_string}\n ) "; } if (api_is_multiple_url_enabled()) { $current_access_url_id = api_get_current_access_url_id(); $sql .= " AND access_url_id IN ('1', '{$current_access_url_id}')"; } if (!isset($_GET['start']) || $_GET['start'] == 0) { $sql .= " ORDER BY date_start DESC LIMIT " . $start . ",20"; } else { $sql .= " ORDER BY date_start DESC LIMIT " . ($start + 1) . ",20"; } $announcements = Database::query($sql); $content = ''; if (Database::num_rows($announcements) > 0) { $query_string = ereg_replace('announcement=[1-9]+', '', $_SERVER['QUERY_STRING']); $query_string = ereg_replace('&$', '', $query_string); $url = api_get_self(); $content .= '<div class="system_announcements">'; $content .= '<h3>' . get_lang('SystemAnnouncements') . '</h3>'; $content .= '<table align="center">'; $content .= '<tr>'; $content .= '<td>'; $content .= SystemAnnouncementManager::display_arrow($user_id); $content .= '</td>'; $content .= '</tr>'; $content .= '</table>'; $content .= '<table align="center" border="0" width="900px">'; while ($announcement = Database::fetch_object($announcements)) { $display_date = api_convert_and_format_date($announcement->display_date, DATE_FORMAT_LONG); $content .= '<tr><td>'; $content .= '<a name="' . $announcement->id . '"></a> <div class="system_announcement"> <h2>' . $announcement->title . '</h2><div class="system_announcement_date">' . $display_date . '</div> <br /> <div class="system_announcement_content">' . $announcement->content . ' </div> </div><br />'; $content .= '</tr></td>'; } $content .= '</table>'; $content .= '<table align="center">'; $content .= '<tr>'; $content .= '<td>'; $content .= SystemAnnouncementManager::display_arrow($user_id); $content .= '</td>'; $content .= '</tr>'; $content .= '</table>'; $content .= '</div>'; } return $content; }