@@ -306,7 +306,7 @@ |
||
| 306 | 306 | * @param int Whether the announcement should be visible to anonymous users (1) or not (0) |
| 307 | 307 | * @param string The language for which the announvement should be shown. Leave null for all langages |
| 308 | 308 | * @param int Whether to send an e-mail to all users (1) or not (0) |
| 309 | - * @return mixed insert_id on success, false on failure |
|
| 309 | + * @return false|string insert_id on success, false on failure |
|
| 310 | 310 | */ |
| 311 | 311 | public static function add_announcement( |
| 312 | 312 | $title, |
@@ -10,17 +10,17 @@ discard block |
||
| 10 | 10 | CONST VISIBLE_STUDENT = 2; |
| 11 | 11 | CONST VISIBLE_TEACHER = 3; |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * Displays all announcements |
|
| 15 | - * @param int $visible VISIBLE_GUEST, VISIBLE_STUDENT or VISIBLE_TEACHER |
|
| 16 | - * @param int $id The identifier of the announcement to display |
|
| 17 | - */ |
|
| 18 | - public static function display_announcements($visible, $id = -1) |
|
| 13 | + /** |
|
| 14 | + * Displays all announcements |
|
| 15 | + * @param int $visible VISIBLE_GUEST, VISIBLE_STUDENT or VISIBLE_TEACHER |
|
| 16 | + * @param int $id The identifier of the announcement to display |
|
| 17 | + */ |
|
| 18 | + public static function display_announcements($visible, $id = -1) |
|
| 19 | 19 | { |
| 20 | - $user_selected_language = api_get_interface_language(); |
|
| 21 | - $db_table = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
|
| 20 | + $user_selected_language = api_get_interface_language(); |
|
| 21 | + $db_table = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
|
| 22 | 22 | $tbl_announcement_group = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS_GROUPS); |
| 23 | - $userGroup = new UserGroup(); |
|
| 23 | + $userGroup = new UserGroup(); |
|
| 24 | 24 | |
| 25 | 25 | $temp_user_groups = $userGroup->get_groups_by_user(api_get_user_id(),0); |
| 26 | 26 | $groups = array(); |
@@ -55,47 +55,47 @@ discard block |
||
| 55 | 55 | WHERE group_id in $groups_string |
| 56 | 56 | ) "; |
| 57 | 57 | } |
| 58 | - $current_access_url_id = 1; |
|
| 59 | - if (api_is_multiple_url_enabled()) { |
|
| 60 | - $current_access_url_id = api_get_current_access_url_id(); |
|
| 61 | - } |
|
| 62 | - $sql .= " AND access_url_id = '$current_access_url_id' "; |
|
| 63 | - $sql .= " ORDER BY date_start DESC LIMIT 0,7"; |
|
| 64 | - |
|
| 65 | - $announcements = Database::query($sql); |
|
| 66 | - if (Database::num_rows($announcements) > 0) { |
|
| 67 | - $query_string = ereg_replace('announcement=[1-9]+', '', $_SERVER['QUERY_STRING']); |
|
| 68 | - $query_string = ereg_replace('&$', '', $query_string); |
|
| 69 | - $url = api_get_self(); |
|
| 70 | - echo '<div class="system_announcements">'; |
|
| 71 | - echo '<h3>'.get_lang('SystemAnnouncements').'</h3>'; |
|
| 72 | - echo '<div style="margin:10px;text-align:right;"><a href="news_list.php">'.get_lang('More').'</a></div>'; |
|
| 73 | - |
|
| 74 | - while ($announcement = Database::fetch_object($announcements)) { |
|
| 75 | - if ($id != $announcement->id) { |
|
| 76 | - if (strlen($query_string) > 0) { |
|
| 77 | - $show_url = 'news_list.php#'.$announcement->id; |
|
| 78 | - } else { |
|
| 79 | - $show_url = 'news_list.php#'.$announcement->id; |
|
| 80 | - } |
|
| 81 | - $display_date = api_convert_and_format_date($announcement->display_date, DATE_FORMAT_LONG); |
|
| 82 | - echo '<a name="'.$announcement->id.'"></a> |
|
| 58 | + $current_access_url_id = 1; |
|
| 59 | + if (api_is_multiple_url_enabled()) { |
|
| 60 | + $current_access_url_id = api_get_current_access_url_id(); |
|
| 61 | + } |
|
| 62 | + $sql .= " AND access_url_id = '$current_access_url_id' "; |
|
| 63 | + $sql .= " ORDER BY date_start DESC LIMIT 0,7"; |
|
| 64 | + |
|
| 65 | + $announcements = Database::query($sql); |
|
| 66 | + if (Database::num_rows($announcements) > 0) { |
|
| 67 | + $query_string = ereg_replace('announcement=[1-9]+', '', $_SERVER['QUERY_STRING']); |
|
| 68 | + $query_string = ereg_replace('&$', '', $query_string); |
|
| 69 | + $url = api_get_self(); |
|
| 70 | + echo '<div class="system_announcements">'; |
|
| 71 | + echo '<h3>'.get_lang('SystemAnnouncements').'</h3>'; |
|
| 72 | + echo '<div style="margin:10px;text-align:right;"><a href="news_list.php">'.get_lang('More').'</a></div>'; |
|
| 73 | + |
|
| 74 | + while ($announcement = Database::fetch_object($announcements)) { |
|
| 75 | + if ($id != $announcement->id) { |
|
| 76 | + if (strlen($query_string) > 0) { |
|
| 77 | + $show_url = 'news_list.php#'.$announcement->id; |
|
| 78 | + } else { |
|
| 79 | + $show_url = 'news_list.php#'.$announcement->id; |
|
| 80 | + } |
|
| 81 | + $display_date = api_convert_and_format_date($announcement->display_date, DATE_FORMAT_LONG); |
|
| 82 | + echo '<a name="'.$announcement->id.'"></a> |
|
| 83 | 83 | <div class="system_announcement"> |
| 84 | 84 | <div class="system_announcement_title"><a name="ann'.$announcement->id.'" href="'.$show_url.'">'.$announcement->title.'</a></div><div class="system_announcement_date">'.$display_date.'</div> |
| 85 | 85 | </div>'; |
| 86 | - } else { |
|
| 87 | - echo '<div class="system_announcement"> |
|
| 86 | + } else { |
|
| 87 | + echo '<div class="system_announcement"> |
|
| 88 | 88 | <div class="system_announcement_title">' |
| 89 | - .$announcement->display_date.' |
|
| 89 | + .$announcement->display_date.' |
|
| 90 | 90 | <a name="ann'.$announcement->id.'" href="'.$url.'?'.$query_string.'#ann'.$announcement->id.'">'.$announcement->title.'</a> |
| 91 | 91 | </div>'; |
| 92 | - } |
|
| 93 | - echo '<br />'; |
|
| 94 | - } |
|
| 95 | - echo '</div>'; |
|
| 96 | - } |
|
| 97 | - return; |
|
| 98 | - } |
|
| 92 | + } |
|
| 93 | + echo '<br />'; |
|
| 94 | + } |
|
| 95 | + echo '</div>'; |
|
| 96 | + } |
|
| 97 | + return; |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | 100 | /** |
| 101 | 101 | * @param $visible |
@@ -106,100 +106,100 @@ discard block |
||
| 106 | 106 | */ |
| 107 | 107 | public static function display_all_announcements($visible, $id = -1, $start = 0,$user_id='') |
| 108 | 108 | { |
| 109 | - $user_selected_language = api_get_interface_language(); |
|
| 110 | - $start = intval($start); |
|
| 109 | + $user_selected_language = api_get_interface_language(); |
|
| 110 | + $start = intval($start); |
|
| 111 | 111 | $userGroup = new UserGroup(); |
| 112 | - $tbl_announcement_group = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS_GROUPS); |
|
| 113 | - $temp_user_groups = $userGroup->get_groups_by_user(api_get_user_id(),0); |
|
| 112 | + $tbl_announcement_group = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS_GROUPS); |
|
| 113 | + $temp_user_groups = $userGroup->get_groups_by_user(api_get_user_id(),0); |
|
| 114 | 114 | $groups = array(); |
| 115 | - foreach ($temp_user_groups as $user_group) { |
|
| 116 | - $groups = array_merge($groups, array($user_group['id'])); |
|
| 117 | - $groups = array_merge($groups, $userGroup->get_parent_groups($user_group['id'])); |
|
| 118 | - } |
|
| 115 | + foreach ($temp_user_groups as $user_group) { |
|
| 116 | + $groups = array_merge($groups, array($user_group['id'])); |
|
| 117 | + $groups = array_merge($groups, $userGroup->get_parent_groups($user_group['id'])); |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - // Checks if tables exists to not break platform not updated |
|
| 121 | - $groups_string = '('.implode($groups,',').')'; |
|
| 120 | + // Checks if tables exists to not break platform not updated |
|
| 121 | + $groups_string = '('.implode($groups,',').')'; |
|
| 122 | 122 | |
| 123 | - $db_table = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
|
| 124 | - $now = api_get_utc_datetime(); |
|
| 123 | + $db_table = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
|
| 124 | + $now = api_get_utc_datetime(); |
|
| 125 | 125 | |
| 126 | - $sql = "SELECT * FROM ".$db_table." |
|
| 126 | + $sql = "SELECT * FROM ".$db_table." |
|
| 127 | 127 | WHERE |
| 128 | 128 | (lang = '$user_selected_language' OR lang IS NULL) AND |
| 129 | 129 | ( '$now' >= date_start AND '$now' <= date_end) "; |
| 130 | 130 | |
| 131 | - switch ($visible) { |
|
| 132 | - case self::VISIBLE_GUEST : |
|
| 133 | - $sql .= " AND visible_guest = 1 "; |
|
| 134 | - break; |
|
| 135 | - case self::VISIBLE_STUDENT : |
|
| 136 | - $sql .= " AND visible_student = 1 "; |
|
| 137 | - break; |
|
| 138 | - case self::VISIBLE_TEACHER : |
|
| 139 | - $sql .= " AND visible_teacher = 1 "; |
|
| 140 | - break; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - if (count($groups) > 0) { |
|
| 131 | + switch ($visible) { |
|
| 132 | + case self::VISIBLE_GUEST : |
|
| 133 | + $sql .= " AND visible_guest = 1 "; |
|
| 134 | + break; |
|
| 135 | + case self::VISIBLE_STUDENT : |
|
| 136 | + $sql .= " AND visible_student = 1 "; |
|
| 137 | + break; |
|
| 138 | + case self::VISIBLE_TEACHER : |
|
| 139 | + $sql .= " AND visible_teacher = 1 "; |
|
| 140 | + break; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + if (count($groups) > 0) { |
|
| 144 | 144 | $sql .= " OR id IN ( |
| 145 | 145 | SELECT announcement_id FROM $tbl_announcement_group |
| 146 | 146 | WHERE group_id in $groups_string |
| 147 | 147 | ) "; |
| 148 | - } |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - if (api_is_multiple_url_enabled()) { |
|
| 151 | - $current_access_url_id = api_get_current_access_url_id(); |
|
| 150 | + if (api_is_multiple_url_enabled()) { |
|
| 151 | + $current_access_url_id = api_get_current_access_url_id(); |
|
| 152 | 152 | $sql .= " AND access_url_id IN ('1', '$current_access_url_id')"; |
| 153 | - } |
|
| 154 | - |
|
| 155 | - if(!isset($_GET['start']) || $_GET['start'] == 0) { |
|
| 156 | - $sql .= " ORDER BY date_start DESC LIMIT ".$start.",20"; |
|
| 157 | - } else { |
|
| 158 | - $sql .= " ORDER BY date_start DESC LIMIT ".($start+1).",20"; |
|
| 159 | - } |
|
| 160 | - $announcements = Database::query($sql); |
|
| 161 | - $content = ''; |
|
| 162 | - if (Database::num_rows($announcements) > 0) { |
|
| 163 | - $query_string = ereg_replace('announcement=[1-9]+', '', $_SERVER['QUERY_STRING']); |
|
| 164 | - $query_string = ereg_replace('&$', '', $query_string); |
|
| 165 | - $url = api_get_self(); |
|
| 166 | - $content .= '<div class="system_announcements">'; |
|
| 167 | - $content .= '<h3>'.get_lang('SystemAnnouncements').'</h3>'; |
|
| 168 | - $content .= '<table align="center">'; |
|
| 169 | - $content .= '<tr>'; |
|
| 170 | - $content .= '<td>'; |
|
| 171 | - $content .= SystemAnnouncementManager :: display_arrow($user_id); |
|
| 172 | - $content .= '</td>'; |
|
| 173 | - $content .= '</tr>'; |
|
| 174 | - $content .= '</table>'; |
|
| 175 | - $content .= '<table align="center" border="0" width="900px">'; |
|
| 176 | - while ($announcement = Database::fetch_object($announcements)) { |
|
| 177 | - $display_date = api_convert_and_format_date($announcement->display_date, DATE_FORMAT_LONG); |
|
| 178 | - $content .= '<tr><td>'; |
|
| 179 | - $content .= '<a name="'.$announcement->id.'"></a> |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + if(!isset($_GET['start']) || $_GET['start'] == 0) { |
|
| 156 | + $sql .= " ORDER BY date_start DESC LIMIT ".$start.",20"; |
|
| 157 | + } else { |
|
| 158 | + $sql .= " ORDER BY date_start DESC LIMIT ".($start+1).",20"; |
|
| 159 | + } |
|
| 160 | + $announcements = Database::query($sql); |
|
| 161 | + $content = ''; |
|
| 162 | + if (Database::num_rows($announcements) > 0) { |
|
| 163 | + $query_string = ereg_replace('announcement=[1-9]+', '', $_SERVER['QUERY_STRING']); |
|
| 164 | + $query_string = ereg_replace('&$', '', $query_string); |
|
| 165 | + $url = api_get_self(); |
|
| 166 | + $content .= '<div class="system_announcements">'; |
|
| 167 | + $content .= '<h3>'.get_lang('SystemAnnouncements').'</h3>'; |
|
| 168 | + $content .= '<table align="center">'; |
|
| 169 | + $content .= '<tr>'; |
|
| 170 | + $content .= '<td>'; |
|
| 171 | + $content .= SystemAnnouncementManager :: display_arrow($user_id); |
|
| 172 | + $content .= '</td>'; |
|
| 173 | + $content .= '</tr>'; |
|
| 174 | + $content .= '</table>'; |
|
| 175 | + $content .= '<table align="center" border="0" width="900px">'; |
|
| 176 | + while ($announcement = Database::fetch_object($announcements)) { |
|
| 177 | + $display_date = api_convert_and_format_date($announcement->display_date, DATE_FORMAT_LONG); |
|
| 178 | + $content .= '<tr><td>'; |
|
| 179 | + $content .= '<a name="'.$announcement->id.'"></a> |
|
| 180 | 180 | <div class="system_announcement"> |
| 181 | 181 | <h2>'.$announcement->title.'</h2><div class="system_announcement_date">'.$display_date.'</div> |
| 182 | 182 | <br /> |
| 183 | 183 | <div class="system_announcement_content">' |
| 184 | - .$announcement->content.' |
|
| 184 | + .$announcement->content.' |
|
| 185 | 185 | </div> |
| 186 | 186 | </div><br />'; |
| 187 | - $content .= '</tr></td>'; |
|
| 188 | - } |
|
| 189 | - $content .= '</table>'; |
|
| 190 | - |
|
| 191 | - $content .= '<table align="center">'; |
|
| 192 | - $content .= '<tr>'; |
|
| 193 | - $content .= '<td>'; |
|
| 194 | - $content .= SystemAnnouncementManager :: display_arrow($user_id); |
|
| 195 | - $content .= '</td>'; |
|
| 196 | - $content .= '</tr>'; |
|
| 197 | - $content .= '</table>'; |
|
| 198 | - $content .= '</div>'; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - return $content; |
|
| 202 | - } |
|
| 187 | + $content .= '</tr></td>'; |
|
| 188 | + } |
|
| 189 | + $content .= '</table>'; |
|
| 190 | + |
|
| 191 | + $content .= '<table align="center">'; |
|
| 192 | + $content .= '<tr>'; |
|
| 193 | + $content .= '<td>'; |
|
| 194 | + $content .= SystemAnnouncementManager :: display_arrow($user_id); |
|
| 195 | + $content .= '</td>'; |
|
| 196 | + $content .= '</tr>'; |
|
| 197 | + $content .= '</table>'; |
|
| 198 | + $content .= '</div>'; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + return $content; |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | 204 | /** |
| 205 | 205 | * @param int $user_id |
@@ -207,23 +207,23 @@ discard block |
||
| 207 | 207 | */ |
| 208 | 208 | public static function display_arrow($user_id) |
| 209 | 209 | { |
| 210 | - $start = (int)$_GET['start']; |
|
| 211 | - $nb_announcement = SystemAnnouncementManager :: count_nb_announcement($start,$user_id); |
|
| 212 | - $next = ((int)$_GET['start']+19); |
|
| 213 | - $prev = ((int)$_GET['start']-19); |
|
| 214 | - $content = ''; |
|
| 215 | - if(!isset($_GET['start']) || $_GET['start'] == 0) { |
|
| 216 | - if($nb_announcement > 20) { |
|
| 217 | - $content .= '<a href="news_list.php?start='.$next.'">'.get_lang('NextBis').' >> </a>'; |
|
| 218 | - } |
|
| 219 | - } else { |
|
| 220 | - echo '<a href="news_list.php?start='.$prev.'"> << '.get_lang('Prev').'</a>'; |
|
| 221 | - if ($nb_announcement > 20) { |
|
| 222 | - $content .= '<a href="news_list.php?start='.$next.'">'.get_lang('NextBis').' >> </a>'; |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - return $content; |
|
| 226 | - } |
|
| 210 | + $start = (int)$_GET['start']; |
|
| 211 | + $nb_announcement = SystemAnnouncementManager :: count_nb_announcement($start,$user_id); |
|
| 212 | + $next = ((int)$_GET['start']+19); |
|
| 213 | + $prev = ((int)$_GET['start']-19); |
|
| 214 | + $content = ''; |
|
| 215 | + if(!isset($_GET['start']) || $_GET['start'] == 0) { |
|
| 216 | + if($nb_announcement > 20) { |
|
| 217 | + $content .= '<a href="news_list.php?start='.$next.'">'.get_lang('NextBis').' >> </a>'; |
|
| 218 | + } |
|
| 219 | + } else { |
|
| 220 | + echo '<a href="news_list.php?start='.$prev.'"> << '.get_lang('Prev').'</a>'; |
|
| 221 | + if ($nb_announcement > 20) { |
|
| 222 | + $content .= '<a href="news_list.php?start='.$next.'">'.get_lang('NextBis').' >> </a>'; |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + return $content; |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | 228 | /** |
| 229 | 229 | * @param int $start |
@@ -232,82 +232,82 @@ discard block |
||
| 232 | 232 | */ |
| 233 | 233 | public static function count_nb_announcement($start = 0, $user_id = '') |
| 234 | 234 | { |
| 235 | - $start = intval($start); |
|
| 236 | - $visibility = api_is_allowed_to_create_course() ? self::VISIBLE_TEACHER : self::VISIBLE_STUDENT; |
|
| 237 | - $user_selected_language = api_get_interface_language(); |
|
| 238 | - $db_table = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
|
| 239 | - $sql = 'SELECT id FROM '.$db_table.' |
|
| 235 | + $start = intval($start); |
|
| 236 | + $visibility = api_is_allowed_to_create_course() ? self::VISIBLE_TEACHER : self::VISIBLE_STUDENT; |
|
| 237 | + $user_selected_language = api_get_interface_language(); |
|
| 238 | + $db_table = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
|
| 239 | + $sql = 'SELECT id FROM '.$db_table.' |
|
| 240 | 240 | WHERE (lang="'.$user_selected_language.'" OR lang IS NULL) '; |
| 241 | - if (isset($user_id)) { |
|
| 242 | - switch ($visibility) { |
|
| 243 | - case self::VISIBLE_GUEST : |
|
| 244 | - $sql .= " AND visible_guest = 1 "; |
|
| 245 | - break; |
|
| 246 | - case self::VISIBLE_STUDENT : |
|
| 247 | - $sql .= " AND visible_student = 1 "; |
|
| 248 | - break; |
|
| 249 | - case self::VISIBLE_TEACHER : |
|
| 250 | - $sql .= " AND visible_teacher = 1 "; |
|
| 251 | - break; |
|
| 252 | - } |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - $current_access_url_id = 1; |
|
| 256 | - if (api_is_multiple_url_enabled()) { |
|
| 257 | - $current_access_url_id = api_get_current_access_url_id(); |
|
| 258 | - } |
|
| 259 | - $sql .= " AND access_url_id = '$current_access_url_id' "; |
|
| 260 | - |
|
| 261 | - |
|
| 262 | - $sql .= 'LIMIT '.$start.', 21'; |
|
| 263 | - $announcements = Database::query($sql); |
|
| 264 | - $i = 0; |
|
| 265 | - while ($rows = Database::fetch_array($announcements)) { |
|
| 266 | - $i++; |
|
| 267 | - } |
|
| 268 | - return $i; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * Get all announcements |
|
| 273 | - * @return array An array with all available system announcements (as php |
|
| 274 | - * objects) |
|
| 275 | - */ |
|
| 276 | - public static function get_all_announcements() |
|
| 241 | + if (isset($user_id)) { |
|
| 242 | + switch ($visibility) { |
|
| 243 | + case self::VISIBLE_GUEST : |
|
| 244 | + $sql .= " AND visible_guest = 1 "; |
|
| 245 | + break; |
|
| 246 | + case self::VISIBLE_STUDENT : |
|
| 247 | + $sql .= " AND visible_student = 1 "; |
|
| 248 | + break; |
|
| 249 | + case self::VISIBLE_TEACHER : |
|
| 250 | + $sql .= " AND visible_teacher = 1 "; |
|
| 251 | + break; |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + $current_access_url_id = 1; |
|
| 256 | + if (api_is_multiple_url_enabled()) { |
|
| 257 | + $current_access_url_id = api_get_current_access_url_id(); |
|
| 258 | + } |
|
| 259 | + $sql .= " AND access_url_id = '$current_access_url_id' "; |
|
| 260 | + |
|
| 261 | + |
|
| 262 | + $sql .= 'LIMIT '.$start.', 21'; |
|
| 263 | + $announcements = Database::query($sql); |
|
| 264 | + $i = 0; |
|
| 265 | + while ($rows = Database::fetch_array($announcements)) { |
|
| 266 | + $i++; |
|
| 267 | + } |
|
| 268 | + return $i; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * Get all announcements |
|
| 273 | + * @return array An array with all available system announcements (as php |
|
| 274 | + * objects) |
|
| 275 | + */ |
|
| 276 | + public static function get_all_announcements() |
|
| 277 | 277 | { |
| 278 | - $table = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
|
| 279 | - $now = api_get_utc_datetime(); |
|
| 280 | - $sql = "SELECT *, IF ( '$now' >= date_start AND '$now' <= date_end, '1', '0') AS visible |
|
| 278 | + $table = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
|
| 279 | + $now = api_get_utc_datetime(); |
|
| 280 | + $sql = "SELECT *, IF ( '$now' >= date_start AND '$now' <= date_end, '1', '0') AS visible |
|
| 281 | 281 | FROM $table"; |
| 282 | 282 | |
| 283 | - $current_access_url_id = 1; |
|
| 284 | - if (api_is_multiple_url_enabled()) { |
|
| 285 | - $current_access_url_id = api_get_current_access_url_id(); |
|
| 286 | - } |
|
| 287 | - $sql .= " WHERE access_url_id = '$current_access_url_id' "; |
|
| 288 | - $sql .= " ORDER BY date_start ASC"; |
|
| 289 | - |
|
| 290 | - $announcements = Database::query($sql); |
|
| 291 | - $all_announcements = array(); |
|
| 292 | - while ($announcement = Database::fetch_object($announcements)) { |
|
| 293 | - $all_announcements[] = $announcement; |
|
| 294 | - } |
|
| 295 | - return $all_announcements; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * Adds an announcement to the database |
|
| 300 | - * @param string Title of the announcement |
|
| 301 | - * @param string Content of the announcement |
|
| 302 | - * @param string Start date (YYYY-MM-DD HH:II: SS) |
|
| 303 | - * @param string End date (YYYY-MM-DD HH:II: SS) |
|
| 304 | - * @param int Whether the announcement should be visible to teachers (1) or not (0) |
|
| 305 | - * @param int Whether the announcement should be visible to students (1) or not (0) |
|
| 306 | - * @param int Whether the announcement should be visible to anonymous users (1) or not (0) |
|
| 307 | - * @param string The language for which the announvement should be shown. Leave null for all langages |
|
| 308 | - * @param int Whether to send an e-mail to all users (1) or not (0) |
|
| 309 | - * @return mixed insert_id on success, false on failure |
|
| 310 | - */ |
|
| 283 | + $current_access_url_id = 1; |
|
| 284 | + if (api_is_multiple_url_enabled()) { |
|
| 285 | + $current_access_url_id = api_get_current_access_url_id(); |
|
| 286 | + } |
|
| 287 | + $sql .= " WHERE access_url_id = '$current_access_url_id' "; |
|
| 288 | + $sql .= " ORDER BY date_start ASC"; |
|
| 289 | + |
|
| 290 | + $announcements = Database::query($sql); |
|
| 291 | + $all_announcements = array(); |
|
| 292 | + while ($announcement = Database::fetch_object($announcements)) { |
|
| 293 | + $all_announcements[] = $announcement; |
|
| 294 | + } |
|
| 295 | + return $all_announcements; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * Adds an announcement to the database |
|
| 300 | + * @param string Title of the announcement |
|
| 301 | + * @param string Content of the announcement |
|
| 302 | + * @param string Start date (YYYY-MM-DD HH:II: SS) |
|
| 303 | + * @param string End date (YYYY-MM-DD HH:II: SS) |
|
| 304 | + * @param int Whether the announcement should be visible to teachers (1) or not (0) |
|
| 305 | + * @param int Whether the announcement should be visible to students (1) or not (0) |
|
| 306 | + * @param int Whether the announcement should be visible to anonymous users (1) or not (0) |
|
| 307 | + * @param string The language for which the announvement should be shown. Leave null for all langages |
|
| 308 | + * @param int Whether to send an e-mail to all users (1) or not (0) |
|
| 309 | + * @return mixed insert_id on success, false on failure |
|
| 310 | + */ |
|
| 311 | 311 | public static function add_announcement( |
| 312 | 312 | $title, |
| 313 | 313 | $content, |
@@ -321,113 +321,113 @@ discard block |
||
| 321 | 321 | $add_to_calendar = false, |
| 322 | 322 | $sendEmailTest = false |
| 323 | 323 | ) { |
| 324 | - $original_content = $content; |
|
| 325 | - $a_dateS = explode(' ',$date_start); |
|
| 326 | - $a_arraySD = explode('-',$a_dateS[0]); |
|
| 327 | - $a_arraySH = explode(':',$a_dateS[1]); |
|
| 328 | - $date_start_to_compare = array_merge($a_arraySD,$a_arraySH); |
|
| 324 | + $original_content = $content; |
|
| 325 | + $a_dateS = explode(' ',$date_start); |
|
| 326 | + $a_arraySD = explode('-',$a_dateS[0]); |
|
| 327 | + $a_arraySH = explode(':',$a_dateS[1]); |
|
| 328 | + $date_start_to_compare = array_merge($a_arraySD,$a_arraySH); |
|
| 329 | 329 | |
| 330 | - $a_dateE = explode(' ',$date_end); |
|
| 331 | - $a_arrayED = explode('-',$a_dateE[0]); |
|
| 332 | - $a_arrayEH = explode(':',$a_dateE[1]); |
|
| 333 | - $date_end_to_compare = array_merge($a_arrayED,$a_arrayEH); |
|
| 330 | + $a_dateE = explode(' ',$date_end); |
|
| 331 | + $a_arrayED = explode('-',$a_dateE[0]); |
|
| 332 | + $a_arrayEH = explode(':',$a_dateE[1]); |
|
| 333 | + $date_end_to_compare = array_merge($a_arrayED,$a_arrayEH); |
|
| 334 | 334 | |
| 335 | - $db_table = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
|
| 335 | + $db_table = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
|
| 336 | 336 | |
| 337 | - if (!checkdate($date_start_to_compare[1], $date_start_to_compare[2], $date_start_to_compare[0])) { |
|
| 338 | - Display :: display_normal_message(get_lang('InvalidStartDate')); |
|
| 339 | - return false; |
|
| 340 | - } |
|
| 337 | + if (!checkdate($date_start_to_compare[1], $date_start_to_compare[2], $date_start_to_compare[0])) { |
|
| 338 | + Display :: display_normal_message(get_lang('InvalidStartDate')); |
|
| 339 | + return false; |
|
| 340 | + } |
|
| 341 | 341 | |
| 342 | - if (($date_end_to_compare[1] || |
|
| 342 | + if (($date_end_to_compare[1] || |
|
| 343 | 343 | $date_end_to_compare[2] || |
| 344 | 344 | $date_end_to_compare[0]) && |
| 345 | 345 | !checkdate($date_end_to_compare[1], $date_end_to_compare[2], $date_end_to_compare[0]) |
| 346 | 346 | ) { |
| 347 | - Display :: display_normal_message(get_lang('InvalidEndDate')); |
|
| 348 | - return false; |
|
| 349 | - } |
|
| 347 | + Display :: display_normal_message(get_lang('InvalidEndDate')); |
|
| 348 | + return false; |
|
| 349 | + } |
|
| 350 | 350 | |
| 351 | - if (strlen(trim($title)) == 0) { |
|
| 352 | - Display::display_normal_message(get_lang('InvalidTitle')); |
|
| 351 | + if (strlen(trim($title)) == 0) { |
|
| 352 | + Display::display_normal_message(get_lang('InvalidTitle')); |
|
| 353 | 353 | |
| 354 | - return false; |
|
| 355 | - } |
|
| 354 | + return false; |
|
| 355 | + } |
|
| 356 | 356 | |
| 357 | - $start = api_get_utc_datetime($date_start); |
|
| 357 | + $start = api_get_utc_datetime($date_start); |
|
| 358 | 358 | $end = api_get_utc_datetime($date_end); |
| 359 | 359 | |
| 360 | - // Fixing urls that are sent by email |
|
| 361 | - $content = str_replace('src=\"/home/', 'src=\"'.api_get_path(WEB_PATH).'home/', $content); |
|
| 362 | - $content = str_replace('file=/home/', 'file='.api_get_path(WEB_PATH).'home/', $content); |
|
| 360 | + // Fixing urls that are sent by email |
|
| 361 | + $content = str_replace('src=\"/home/', 'src=\"'.api_get_path(WEB_PATH).'home/', $content); |
|
| 362 | + $content = str_replace('file=/home/', 'file='.api_get_path(WEB_PATH).'home/', $content); |
|
| 363 | 363 | |
| 364 | 364 | $lang = is_null($lang) ? '' : $lang; |
| 365 | 365 | |
| 366 | - $current_access_url_id = 1; |
|
| 367 | - if (api_is_multiple_url_enabled()) { |
|
| 368 | - $current_access_url_id = api_get_current_access_url_id(); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - $params = [ |
|
| 372 | - 'title' => $title, |
|
| 373 | - 'content' => $content, |
|
| 374 | - 'date_start' => $start, |
|
| 375 | - 'date_end' => $end, |
|
| 376 | - 'visible_teacher' => $visible_teacher, |
|
| 377 | - 'visible_student' => $visible_student, |
|
| 378 | - 'visible_guest' => $visible_guest, |
|
| 379 | - 'lang' => $lang, |
|
| 380 | - 'access_url_id' => $current_access_url_id, |
|
| 381 | - ]; |
|
| 382 | - |
|
| 383 | - $resultId = Database::insert($db_table, $params); |
|
| 384 | - |
|
| 385 | - if ($resultId) { |
|
| 386 | - if ($sendEmailTest) { |
|
| 387 | - SystemAnnouncementManager::send_system_announcement_by_email( |
|
| 388 | - $title, |
|
| 389 | - $content, |
|
| 390 | - $visible_teacher, |
|
| 391 | - $visible_student, |
|
| 392 | - $lang, |
|
| 393 | - true |
|
| 394 | - ); |
|
| 395 | - } else { |
|
| 396 | - if ($send_mail == 1) { |
|
| 397 | - SystemAnnouncementManager::send_system_announcement_by_email( |
|
| 398 | - $title, |
|
| 399 | - $content, |
|
| 400 | - $visible_teacher, |
|
| 401 | - $visible_student, |
|
| 402 | - $lang |
|
| 403 | - ); |
|
| 404 | - } |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - if ($add_to_calendar) { |
|
| 408 | - $agenda = new Agenda(); |
|
| 409 | - $agenda->setType('admin'); |
|
| 410 | - $agenda->addEvent( |
|
| 411 | - $date_start, |
|
| 412 | - $date_end, |
|
| 413 | - false, |
|
| 414 | - $title, |
|
| 415 | - $original_content |
|
| 416 | - ); |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - return $resultId; |
|
| 420 | - |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - return false; |
|
| 424 | - } |
|
| 366 | + $current_access_url_id = 1; |
|
| 367 | + if (api_is_multiple_url_enabled()) { |
|
| 368 | + $current_access_url_id = api_get_current_access_url_id(); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + $params = [ |
|
| 372 | + 'title' => $title, |
|
| 373 | + 'content' => $content, |
|
| 374 | + 'date_start' => $start, |
|
| 375 | + 'date_end' => $end, |
|
| 376 | + 'visible_teacher' => $visible_teacher, |
|
| 377 | + 'visible_student' => $visible_student, |
|
| 378 | + 'visible_guest' => $visible_guest, |
|
| 379 | + 'lang' => $lang, |
|
| 380 | + 'access_url_id' => $current_access_url_id, |
|
| 381 | + ]; |
|
| 382 | + |
|
| 383 | + $resultId = Database::insert($db_table, $params); |
|
| 384 | + |
|
| 385 | + if ($resultId) { |
|
| 386 | + if ($sendEmailTest) { |
|
| 387 | + SystemAnnouncementManager::send_system_announcement_by_email( |
|
| 388 | + $title, |
|
| 389 | + $content, |
|
| 390 | + $visible_teacher, |
|
| 391 | + $visible_student, |
|
| 392 | + $lang, |
|
| 393 | + true |
|
| 394 | + ); |
|
| 395 | + } else { |
|
| 396 | + if ($send_mail == 1) { |
|
| 397 | + SystemAnnouncementManager::send_system_announcement_by_email( |
|
| 398 | + $title, |
|
| 399 | + $content, |
|
| 400 | + $visible_teacher, |
|
| 401 | + $visible_student, |
|
| 402 | + $lang |
|
| 403 | + ); |
|
| 404 | + } |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + if ($add_to_calendar) { |
|
| 408 | + $agenda = new Agenda(); |
|
| 409 | + $agenda->setType('admin'); |
|
| 410 | + $agenda->addEvent( |
|
| 411 | + $date_start, |
|
| 412 | + $date_end, |
|
| 413 | + false, |
|
| 414 | + $title, |
|
| 415 | + $original_content |
|
| 416 | + ); |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + return $resultId; |
|
| 420 | + |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + return false; |
|
| 424 | + } |
|
| 425 | 425 | |
| 426 | 426 | /** |
| 427 | - * Makes the announcement id visible only for groups in groups_array |
|
| 428 | - * @param int announcement id |
|
| 429 | - * @param array array of group id |
|
| 430 | - **/ |
|
| 427 | + * Makes the announcement id visible only for groups in groups_array |
|
| 428 | + * @param int announcement id |
|
| 429 | + * @param array array of group id |
|
| 430 | + **/ |
|
| 431 | 431 | public static function announcement_for_groups($announcement_id, $group_array) |
| 432 | 432 | { |
| 433 | 433 | $tbl_announcement_group = Database:: get_main_table( |
@@ -461,10 +461,10 @@ discard block |
||
| 461 | 461 | } |
| 462 | 462 | |
| 463 | 463 | /** |
| 464 | - * Gets the groups of this announce |
|
| 465 | - * @param int announcement id |
|
| 466 | - * @return array array of group id |
|
| 467 | - **/ |
|
| 464 | + * Gets the groups of this announce |
|
| 465 | + * @param int announcement id |
|
| 466 | + * @return array array of group id |
|
| 467 | + **/ |
|
| 468 | 468 | public static function get_announcement_groups($announcement_id) |
| 469 | 469 | { |
| 470 | 470 | $tbl_announcement_group = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS_GROUPS); |
@@ -483,15 +483,15 @@ discard block |
||
| 483 | 483 | return $groups; |
| 484 | 484 | } |
| 485 | 485 | |
| 486 | - /** |
|
| 487 | - * Updates an announcement to the database |
|
| 488 | - * @param integer $id : id of the announcement |
|
| 489 | - * @param string $title : title of the announcement |
|
| 490 | - * @param string $content : content of the announcement |
|
| 491 | - * @param array $date_start: start date of announcement (0 => day ; 1 => month ; 2 => year ; 3 => hour ; 4 => minute) |
|
| 492 | - * @param array $date_end : end date of announcement (0 => day ; 1 => month ; 2 => year ; 3 => hour ; 4 => minute) |
|
| 493 | - * @return bool True on success, false on failure |
|
| 494 | - */ |
|
| 486 | + /** |
|
| 487 | + * Updates an announcement to the database |
|
| 488 | + * @param integer $id : id of the announcement |
|
| 489 | + * @param string $title : title of the announcement |
|
| 490 | + * @param string $content : content of the announcement |
|
| 491 | + * @param array $date_start: start date of announcement (0 => day ; 1 => month ; 2 => year ; 3 => hour ; 4 => minute) |
|
| 492 | + * @param array $date_end : end date of announcement (0 => day ; 1 => month ; 2 => year ; 3 => hour ; 4 => minute) |
|
| 493 | + * @return bool True on success, false on failure |
|
| 494 | + */ |
|
| 495 | 495 | public static function update_announcement( |
| 496 | 496 | $id, |
| 497 | 497 | $title, |
@@ -506,53 +506,53 @@ discard block |
||
| 506 | 506 | $sendEmailTest = false |
| 507 | 507 | ) { |
| 508 | 508 | $em = Database::getManager(); |
| 509 | - $announcement = $em->find('ChamiloCoreBundle:SysAnnouncement', $id); |
|
| 509 | + $announcement = $em->find('ChamiloCoreBundle:SysAnnouncement', $id); |
|
| 510 | 510 | |
| 511 | - if (!$announcement) { |
|
| 511 | + if (!$announcement) { |
|
| 512 | 512 | |
| 513 | - return false; |
|
| 514 | - } |
|
| 513 | + return false; |
|
| 514 | + } |
|
| 515 | 515 | |
| 516 | - $a_dateS = explode(' ',$date_start); |
|
| 517 | - $a_arraySD = explode('-',$a_dateS[0]); |
|
| 518 | - $a_arraySH = explode(':',$a_dateS[1]); |
|
| 519 | - $date_start_to_compare = array_merge($a_arraySD,$a_arraySH); |
|
| 516 | + $a_dateS = explode(' ',$date_start); |
|
| 517 | + $a_arraySD = explode('-',$a_dateS[0]); |
|
| 518 | + $a_arraySH = explode(':',$a_dateS[1]); |
|
| 519 | + $date_start_to_compare = array_merge($a_arraySD,$a_arraySH); |
|
| 520 | 520 | |
| 521 | - $a_dateE = explode(' ',$date_end); |
|
| 522 | - $a_arrayED = explode('-',$a_dateE[0]); |
|
| 523 | - $a_arrayEH = explode(':',$a_dateE[1]); |
|
| 524 | - $date_end_to_compare = array_merge($a_arrayED,$a_arrayEH); |
|
| 521 | + $a_dateE = explode(' ',$date_end); |
|
| 522 | + $a_arrayED = explode('-',$a_dateE[0]); |
|
| 523 | + $a_arrayEH = explode(':',$a_dateE[1]); |
|
| 524 | + $date_end_to_compare = array_merge($a_arrayED,$a_arrayEH); |
|
| 525 | 525 | |
| 526 | 526 | $lang = is_null($lang) ? '' : $lang; |
| 527 | 527 | |
| 528 | - if (!checkdate($date_start_to_compare[1], $date_start_to_compare[2], $date_start_to_compare[0])) { |
|
| 529 | - Display :: display_normal_message(get_lang('InvalidStartDate')); |
|
| 528 | + if (!checkdate($date_start_to_compare[1], $date_start_to_compare[2], $date_start_to_compare[0])) { |
|
| 529 | + Display :: display_normal_message(get_lang('InvalidStartDate')); |
|
| 530 | 530 | |
| 531 | - return false; |
|
| 532 | - } |
|
| 531 | + return false; |
|
| 532 | + } |
|
| 533 | 533 | |
| 534 | - if (($date_end_to_compare[1] || |
|
| 534 | + if (($date_end_to_compare[1] || |
|
| 535 | 535 | $date_end_to_compare[2] || |
| 536 | 536 | $date_end_to_compare[0]) && |
| 537 | 537 | !checkdate($date_end_to_compare[1], $date_end_to_compare[2], $date_end_to_compare[0]) |
| 538 | 538 | ) { |
| 539 | - Display :: display_normal_message(get_lang('InvalidEndDate')); |
|
| 539 | + Display :: display_normal_message(get_lang('InvalidEndDate')); |
|
| 540 | 540 | |
| 541 | - return false; |
|
| 542 | - } |
|
| 541 | + return false; |
|
| 542 | + } |
|
| 543 | 543 | |
| 544 | - if (strlen(trim($title)) == 0) { |
|
| 545 | - Display::display_normal_message(get_lang('InvalidTitle')); |
|
| 544 | + if (strlen(trim($title)) == 0) { |
|
| 545 | + Display::display_normal_message(get_lang('InvalidTitle')); |
|
| 546 | 546 | |
| 547 | - return false; |
|
| 548 | - } |
|
| 547 | + return false; |
|
| 548 | + } |
|
| 549 | 549 | |
| 550 | - $start = api_get_utc_datetime($date_start); |
|
| 550 | + $start = api_get_utc_datetime($date_start); |
|
| 551 | 551 | $end = api_get_utc_datetime($date_end); |
| 552 | 552 | |
| 553 | - // Fixing urls that are sent by email |
|
| 554 | - $content = str_replace('src=\"/home/', 'src=\"'.api_get_path(WEB_PATH).'home/', $content); |
|
| 555 | - $content = str_replace('file=/home/', 'file='.api_get_path(WEB_PATH).'home/', $content); |
|
| 553 | + // Fixing urls that are sent by email |
|
| 554 | + $content = str_replace('src=\"/home/', 'src=\"'.api_get_path(WEB_PATH).'home/', $content); |
|
| 555 | + $content = str_replace('file=/home/', 'file='.api_get_path(WEB_PATH).'home/', $content); |
|
| 556 | 556 | |
| 557 | 557 | if ($sendEmailTest) { |
| 558 | 558 | SystemAnnouncementManager::send_system_announcement_by_email( |
@@ -592,90 +592,90 @@ discard block |
||
| 592 | 592 | $em->merge($announcement); |
| 593 | 593 | $em->flush(); |
| 594 | 594 | |
| 595 | - return true; |
|
| 596 | - } |
|
| 595 | + return true; |
|
| 596 | + } |
|
| 597 | 597 | |
| 598 | - /** |
|
| 599 | - * Deletes an announcement |
|
| 600 | - * @param int $id The identifier of the announcement that should be |
|
| 601 | - * @return bool True on success, false on failure |
|
| 602 | - */ |
|
| 603 | - public static function delete_announcement($id) |
|
| 598 | + /** |
|
| 599 | + * Deletes an announcement |
|
| 600 | + * @param int $id The identifier of the announcement that should be |
|
| 601 | + * @return bool True on success, false on failure |
|
| 602 | + */ |
|
| 603 | + public static function delete_announcement($id) |
|
| 604 | 604 | { |
| 605 | - $db_table = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
|
| 606 | - $id = intval($id); |
|
| 607 | - $sql = "DELETE FROM ".$db_table." WHERE id =".$id; |
|
| 608 | - $res = Database::query($sql); |
|
| 609 | - if ($res === false) { |
|
| 610 | - |
|
| 611 | - return false; |
|
| 612 | - } |
|
| 613 | - return true; |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - /** |
|
| 617 | - * Gets an announcement |
|
| 618 | - * @param int $id The identifier of the announcement that should be |
|
| 619 | - * @return object Object of class StdClass or the required class, containing the query result row |
|
| 620 | - */ |
|
| 621 | - public static function get_announcement($id) |
|
| 605 | + $db_table = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
|
| 606 | + $id = intval($id); |
|
| 607 | + $sql = "DELETE FROM ".$db_table." WHERE id =".$id; |
|
| 608 | + $res = Database::query($sql); |
|
| 609 | + if ($res === false) { |
|
| 610 | + |
|
| 611 | + return false; |
|
| 612 | + } |
|
| 613 | + return true; |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + /** |
|
| 617 | + * Gets an announcement |
|
| 618 | + * @param int $id The identifier of the announcement that should be |
|
| 619 | + * @return object Object of class StdClass or the required class, containing the query result row |
|
| 620 | + */ |
|
| 621 | + public static function get_announcement($id) |
|
| 622 | 622 | { |
| 623 | - $db_table = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
|
| 624 | - $id = intval($id); |
|
| 625 | - $sql = "SELECT * FROM ".$db_table." WHERE id = ".$id; |
|
| 626 | - $announcement = Database::fetch_object(Database::query($sql)); |
|
| 627 | - |
|
| 628 | - return $announcement; |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - /** |
|
| 632 | - * Change the visibility of an announcement |
|
| 633 | - * @param int $announcement_id |
|
| 634 | - * @param int $user For who should the visibility be changed |
|
| 623 | + $db_table = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
|
| 624 | + $id = intval($id); |
|
| 625 | + $sql = "SELECT * FROM ".$db_table." WHERE id = ".$id; |
|
| 626 | + $announcement = Database::fetch_object(Database::query($sql)); |
|
| 627 | + |
|
| 628 | + return $announcement; |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + /** |
|
| 632 | + * Change the visibility of an announcement |
|
| 633 | + * @param int $announcement_id |
|
| 634 | + * @param int $user For who should the visibility be changed |
|
| 635 | 635 | * (possible values are VISIBLE_TEACHER, VISIBLE_STUDENT, VISIBLE_GUEST) |
| 636 | - * @return bool True on success, false on failure |
|
| 637 | - */ |
|
| 638 | - public static function set_visibility($announcement_id, $user, $visible) |
|
| 636 | + * @return bool True on success, false on failure |
|
| 637 | + */ |
|
| 638 | + public static function set_visibility($announcement_id, $user, $visible) |
|
| 639 | 639 | { |
| 640 | - $db_table = Database::get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
|
| 641 | - $visible = intval($visible); |
|
| 642 | - $announcement_id = intval($announcement_id); |
|
| 640 | + $db_table = Database::get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
|
| 641 | + $visible = intval($visible); |
|
| 642 | + $announcement_id = intval($announcement_id); |
|
| 643 | 643 | |
| 644 | 644 | if (!in_array($user, array(self::VISIBLE_GUEST, self::VISIBLE_STUDENT, self::VISIBLE_TEACHER))) { |
| 645 | 645 | return false; |
| 646 | 646 | } |
| 647 | 647 | |
| 648 | - $field = ($user == self::VISIBLE_TEACHER ? 'visible_teacher' : ($user == self::VISIBLE_STUDENT ? 'visible_student' : 'visible_guest')); |
|
| 648 | + $field = ($user == self::VISIBLE_TEACHER ? 'visible_teacher' : ($user == self::VISIBLE_STUDENT ? 'visible_student' : 'visible_guest')); |
|
| 649 | 649 | |
| 650 | - $sql = "UPDATE ".$db_table." SET ".$field." = '".$visible."' |
|
| 650 | + $sql = "UPDATE ".$db_table." SET ".$field." = '".$visible."' |
|
| 651 | 651 | WHERE id='".$announcement_id."'"; |
| 652 | - $res = Database::query($sql); |
|
| 653 | - |
|
| 654 | - if ($res === false) { |
|
| 655 | - return false; |
|
| 656 | - } |
|
| 657 | - |
|
| 658 | - return true; |
|
| 659 | - } |
|
| 660 | - |
|
| 661 | - /** |
|
| 662 | - * Send a system announcement by e-mail to all teachers/students depending on parameters |
|
| 663 | - * @param string $title |
|
| 664 | - * @param string $content |
|
| 665 | - * @param int $teacher Whether to send to all teachers (1) or not (0) |
|
| 666 | - * @param int $student Whether to send to all students (1) or not (0) |
|
| 667 | - * @param string $language Language (optional, considered for all languages if left empty) |
|
| 652 | + $res = Database::query($sql); |
|
| 653 | + |
|
| 654 | + if ($res === false) { |
|
| 655 | + return false; |
|
| 656 | + } |
|
| 657 | + |
|
| 658 | + return true; |
|
| 659 | + } |
|
| 660 | + |
|
| 661 | + /** |
|
| 662 | + * Send a system announcement by e-mail to all teachers/students depending on parameters |
|
| 663 | + * @param string $title |
|
| 664 | + * @param string $content |
|
| 665 | + * @param int $teacher Whether to send to all teachers (1) or not (0) |
|
| 666 | + * @param int $student Whether to send to all students (1) or not (0) |
|
| 667 | + * @param string $language Language (optional, considered for all languages if left empty) |
|
| 668 | 668 | * @param bool $sendEmailTest |
| 669 | - * @return bool True if the message was sent or there was no destination matching. False on database or e-mail sending error. |
|
| 670 | - */ |
|
| 671 | - public static function send_system_announcement_by_email( |
|
| 672 | - $title, |
|
| 673 | - $content, |
|
| 674 | - $teacher, |
|
| 675 | - $student, |
|
| 676 | - $language = null, |
|
| 677 | - $sendEmailTest = false |
|
| 678 | - ) { |
|
| 669 | + * @return bool True if the message was sent or there was no destination matching. False on database or e-mail sending error. |
|
| 670 | + */ |
|
| 671 | + public static function send_system_announcement_by_email( |
|
| 672 | + $title, |
|
| 673 | + $content, |
|
| 674 | + $teacher, |
|
| 675 | + $student, |
|
| 676 | + $language = null, |
|
| 677 | + $sendEmailTest = false |
|
| 678 | + ) { |
|
| 679 | 679 | $content = str_replace(array('\r\n', '\n', '\r'),'', $content); |
| 680 | 680 | $now = api_get_utc_datetime(); |
| 681 | 681 | |
@@ -693,26 +693,26 @@ discard block |
||
| 693 | 693 | } |
| 694 | 694 | |
| 695 | 695 | if ($teacher <> 0 && $student == 0) { |
| 696 | - $sql = "SELECT DISTINCT u.user_id FROM $user_table u $url_condition |
|
| 696 | + $sql = "SELECT DISTINCT u.user_id FROM $user_table u $url_condition |
|
| 697 | 697 | WHERE status = '1' "; |
| 698 | - } |
|
| 698 | + } |
|
| 699 | 699 | |
| 700 | - if ($teacher == 0 && $student <> 0) { |
|
| 701 | - $sql = "SELECT DISTINCT u.user_id FROM $user_table u $url_condition |
|
| 700 | + if ($teacher == 0 && $student <> 0) { |
|
| 701 | + $sql = "SELECT DISTINCT u.user_id FROM $user_table u $url_condition |
|
| 702 | 702 | WHERE status = '5' "; |
| 703 | - } |
|
| 703 | + } |
|
| 704 | 704 | |
| 705 | - if ($teacher<> 0 && $student <> 0) { |
|
| 706 | - $sql = "SELECT DISTINCT u.user_id FROM $user_table u $url_condition |
|
| 705 | + if ($teacher<> 0 && $student <> 0) { |
|
| 706 | + $sql = "SELECT DISTINCT u.user_id FROM $user_table u $url_condition |
|
| 707 | 707 | WHERE 1 = 1 "; |
| 708 | - } |
|
| 708 | + } |
|
| 709 | 709 | |
| 710 | - if (!empty($language)) { |
|
| 711 | - //special condition because language was already treated for SQL insert before |
|
| 712 | - $sql .= " AND language = '".Database::escape_string($language)."' "; |
|
| 713 | - } |
|
| 710 | + if (!empty($language)) { |
|
| 711 | + //special condition because language was already treated for SQL insert before |
|
| 712 | + $sql .= " AND language = '".Database::escape_string($language)."' "; |
|
| 713 | + } |
|
| 714 | 714 | |
| 715 | - if (api_is_multiple_url_enabled()) { |
|
| 715 | + if (api_is_multiple_url_enabled()) { |
|
| 716 | 716 | $sql .= " AND access_url_id = '".$current_access_url_id."' "; |
| 717 | 717 | } |
| 718 | 718 | |
@@ -722,27 +722,27 @@ discard block |
||
| 722 | 722 | // Expiration date |
| 723 | 723 | $sql .= " AND (expiration_date = '' OR expiration_date IS NULL OR expiration_date > '$now') "; |
| 724 | 724 | |
| 725 | - if ((empty($teacher) || $teacher == '0') && (empty($student) || $student == '0')) { |
|
| 725 | + if ((empty($teacher) || $teacher == '0') && (empty($student) || $student == '0')) { |
|
| 726 | 726 | |
| 727 | 727 | return true; |
| 728 | - } |
|
| 728 | + } |
|
| 729 | 729 | |
| 730 | - $result = Database::query($sql); |
|
| 731 | - if ($result === false) { |
|
| 730 | + $result = Database::query($sql); |
|
| 731 | + if ($result === false) { |
|
| 732 | 732 | |
| 733 | 733 | return false; |
| 734 | - } |
|
| 734 | + } |
|
| 735 | 735 | |
| 736 | 736 | $message_sent = false; |
| 737 | - while ($row = Database::fetch_array($result,'ASSOC')) { |
|
| 737 | + while ($row = Database::fetch_array($result,'ASSOC')) { |
|
| 738 | 738 | MessageManager::send_message_simple($row['user_id'], $title, $content); |
| 739 | 739 | $message_sent = true; |
| 740 | - } |
|
| 740 | + } |
|
| 741 | 741 | |
| 742 | - return $message_sent; //true if at least one e-mail was sent |
|
| 743 | - } |
|
| 742 | + return $message_sent; //true if at least one e-mail was sent |
|
| 743 | + } |
|
| 744 | 744 | |
| 745 | - /** |
|
| 745 | + /** |
|
| 746 | 746 | * Displays announcements as an slideshow |
| 747 | 747 | * @param int $visible VISIBLE_GUEST, VISIBLE_STUDENT or VISIBLE_TEACHER |
| 748 | 748 | * @param int $id The identifier of the announcement to display |
@@ -22,14 +22,14 @@ discard block |
||
| 22 | 22 | $tbl_announcement_group = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS_GROUPS); |
| 23 | 23 | $userGroup = new UserGroup(); |
| 24 | 24 | |
| 25 | - $temp_user_groups = $userGroup->get_groups_by_user(api_get_user_id(),0); |
|
| 25 | + $temp_user_groups = $userGroup->get_groups_by_user(api_get_user_id(), 0); |
|
| 26 | 26 | $groups = array(); |
| 27 | 27 | foreach ($temp_user_groups as $user_group) { |
| 28 | 28 | $groups = array_merge($groups, array($user_group['id'])); |
| 29 | 29 | $groups = array_merge($groups, $userGroup->get_parent_groups($user_group['id'])); |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - $groups_string = '('.implode($groups,',').')'; |
|
| 32 | + $groups_string = '('.implode($groups, ',').')'; |
|
| 33 | 33 | $now = api_get_utc_datetime(); |
| 34 | 34 | $sql = "SELECT *, DATE_FORMAT(date_start,'%d-%m-%Y %h:%i:%s') AS display_date |
| 35 | 35 | FROM $db_table |
@@ -104,13 +104,13 @@ discard block |
||
| 104 | 104 | * @param string $user_id |
| 105 | 105 | * @return string |
| 106 | 106 | */ |
| 107 | - public static function display_all_announcements($visible, $id = -1, $start = 0,$user_id='') |
|
| 107 | + public static function display_all_announcements($visible, $id = -1, $start = 0, $user_id = '') |
|
| 108 | 108 | { |
| 109 | 109 | $user_selected_language = api_get_interface_language(); |
| 110 | - $start = intval($start); |
|
| 110 | + $start = intval($start); |
|
| 111 | 111 | $userGroup = new UserGroup(); |
| 112 | 112 | $tbl_announcement_group = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS_GROUPS); |
| 113 | - $temp_user_groups = $userGroup->get_groups_by_user(api_get_user_id(),0); |
|
| 113 | + $temp_user_groups = $userGroup->get_groups_by_user(api_get_user_id(), 0); |
|
| 114 | 114 | $groups = array(); |
| 115 | 115 | foreach ($temp_user_groups as $user_group) { |
| 116 | 116 | $groups = array_merge($groups, array($user_group['id'])); |
@@ -118,10 +118,10 @@ discard block |
||
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | // Checks if tables exists to not break platform not updated |
| 121 | - $groups_string = '('.implode($groups,',').')'; |
|
| 121 | + $groups_string = '('.implode($groups, ',').')'; |
|
| 122 | 122 | |
| 123 | 123 | $db_table = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
| 124 | - $now = api_get_utc_datetime(); |
|
| 124 | + $now = api_get_utc_datetime(); |
|
| 125 | 125 | |
| 126 | 126 | $sql = "SELECT * FROM ".$db_table." |
| 127 | 127 | WHERE |
@@ -152,10 +152,10 @@ discard block |
||
| 152 | 152 | $sql .= " AND access_url_id IN ('1', '$current_access_url_id')"; |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - if(!isset($_GET['start']) || $_GET['start'] == 0) { |
|
| 155 | + if (!isset($_GET['start']) || $_GET['start'] == 0) { |
|
| 156 | 156 | $sql .= " ORDER BY date_start DESC LIMIT ".$start.",20"; |
| 157 | 157 | } else { |
| 158 | - $sql .= " ORDER BY date_start DESC LIMIT ".($start+1).",20"; |
|
| 158 | + $sql .= " ORDER BY date_start DESC LIMIT ".($start + 1).",20"; |
|
| 159 | 159 | } |
| 160 | 160 | $announcements = Database::query($sql); |
| 161 | 161 | $content = ''; |
@@ -207,13 +207,13 @@ discard block |
||
| 207 | 207 | */ |
| 208 | 208 | public static function display_arrow($user_id) |
| 209 | 209 | { |
| 210 | - $start = (int)$_GET['start']; |
|
| 211 | - $nb_announcement = SystemAnnouncementManager :: count_nb_announcement($start,$user_id); |
|
| 212 | - $next = ((int)$_GET['start']+19); |
|
| 213 | - $prev = ((int)$_GET['start']-19); |
|
| 210 | + $start = (int) $_GET['start']; |
|
| 211 | + $nb_announcement = SystemAnnouncementManager :: count_nb_announcement($start, $user_id); |
|
| 212 | + $next = ((int) $_GET['start'] + 19); |
|
| 213 | + $prev = ((int) $_GET['start'] - 19); |
|
| 214 | 214 | $content = ''; |
| 215 | - if(!isset($_GET['start']) || $_GET['start'] == 0) { |
|
| 216 | - if($nb_announcement > 20) { |
|
| 215 | + if (!isset($_GET['start']) || $_GET['start'] == 0) { |
|
| 216 | + if ($nb_announcement > 20) { |
|
| 217 | 217 | $content .= '<a href="news_list.php?start='.$next.'">'.get_lang('NextBis').' >> </a>'; |
| 218 | 218 | } |
| 219 | 219 | } else { |
@@ -322,15 +322,15 @@ discard block |
||
| 322 | 322 | $sendEmailTest = false |
| 323 | 323 | ) { |
| 324 | 324 | $original_content = $content; |
| 325 | - $a_dateS = explode(' ',$date_start); |
|
| 326 | - $a_arraySD = explode('-',$a_dateS[0]); |
|
| 327 | - $a_arraySH = explode(':',$a_dateS[1]); |
|
| 328 | - $date_start_to_compare = array_merge($a_arraySD,$a_arraySH); |
|
| 325 | + $a_dateS = explode(' ', $date_start); |
|
| 326 | + $a_arraySD = explode('-', $a_dateS[0]); |
|
| 327 | + $a_arraySH = explode(':', $a_dateS[1]); |
|
| 328 | + $date_start_to_compare = array_merge($a_arraySD, $a_arraySH); |
|
| 329 | 329 | |
| 330 | - $a_dateE = explode(' ',$date_end); |
|
| 331 | - $a_arrayED = explode('-',$a_dateE[0]); |
|
| 332 | - $a_arrayEH = explode(':',$a_dateE[1]); |
|
| 333 | - $date_end_to_compare = array_merge($a_arrayED,$a_arrayEH); |
|
| 330 | + $a_dateE = explode(' ', $date_end); |
|
| 331 | + $a_arrayED = explode('-', $a_dateE[0]); |
|
| 332 | + $a_arrayEH = explode(':', $a_dateE[1]); |
|
| 333 | + $date_end_to_compare = array_merge($a_arrayED, $a_arrayEH); |
|
| 334 | 334 | |
| 335 | 335 | $db_table = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
| 336 | 336 | |
@@ -513,15 +513,15 @@ discard block |
||
| 513 | 513 | return false; |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | - $a_dateS = explode(' ',$date_start); |
|
| 517 | - $a_arraySD = explode('-',$a_dateS[0]); |
|
| 518 | - $a_arraySH = explode(':',$a_dateS[1]); |
|
| 519 | - $date_start_to_compare = array_merge($a_arraySD,$a_arraySH); |
|
| 516 | + $a_dateS = explode(' ', $date_start); |
|
| 517 | + $a_arraySD = explode('-', $a_dateS[0]); |
|
| 518 | + $a_arraySH = explode(':', $a_dateS[1]); |
|
| 519 | + $date_start_to_compare = array_merge($a_arraySD, $a_arraySH); |
|
| 520 | 520 | |
| 521 | - $a_dateE = explode(' ',$date_end); |
|
| 522 | - $a_arrayED = explode('-',$a_dateE[0]); |
|
| 523 | - $a_arrayEH = explode(':',$a_dateE[1]); |
|
| 524 | - $date_end_to_compare = array_merge($a_arrayED,$a_arrayEH); |
|
| 521 | + $a_dateE = explode(' ', $date_end); |
|
| 522 | + $a_arrayED = explode('-', $a_dateE[0]); |
|
| 523 | + $a_arrayEH = explode(':', $a_dateE[1]); |
|
| 524 | + $date_end_to_compare = array_merge($a_arrayED, $a_arrayEH); |
|
| 525 | 525 | |
| 526 | 526 | $lang = is_null($lang) ? '' : $lang; |
| 527 | 527 | |
@@ -564,7 +564,7 @@ discard block |
||
| 564 | 564 | $sendEmailTest |
| 565 | 565 | ); |
| 566 | 566 | } else { |
| 567 | - if ($send_mail==1) { |
|
| 567 | + if ($send_mail == 1) { |
|
| 568 | 568 | SystemAnnouncementManager::send_system_announcement_by_email( |
| 569 | 569 | $title, |
| 570 | 570 | $content, |
@@ -676,7 +676,7 @@ discard block |
||
| 676 | 676 | $language = null, |
| 677 | 677 | $sendEmailTest = false |
| 678 | 678 | ) { |
| 679 | - $content = str_replace(array('\r\n', '\n', '\r'),'', $content); |
|
| 679 | + $content = str_replace(array('\r\n', '\n', '\r'), '', $content); |
|
| 680 | 680 | $now = api_get_utc_datetime(); |
| 681 | 681 | |
| 682 | 682 | if ($sendEmailTest) { |
@@ -702,7 +702,7 @@ discard block |
||
| 702 | 702 | WHERE status = '5' "; |
| 703 | 703 | } |
| 704 | 704 | |
| 705 | - if ($teacher<> 0 && $student <> 0) { |
|
| 705 | + if ($teacher <> 0 && $student <> 0) { |
|
| 706 | 706 | $sql = "SELECT DISTINCT u.user_id FROM $user_table u $url_condition |
| 707 | 707 | WHERE 1 = 1 "; |
| 708 | 708 | } |
@@ -734,7 +734,7 @@ discard block |
||
| 734 | 734 | } |
| 735 | 735 | |
| 736 | 736 | $message_sent = false; |
| 737 | - while ($row = Database::fetch_array($result,'ASSOC')) { |
|
| 737 | + while ($row = Database::fetch_array($result, 'ASSOC')) { |
|
| 738 | 738 | MessageManager::send_message_simple($row['user_id'], $title, $content); |
| 739 | 739 | $message_sent = true; |
| 740 | 740 | } |
@@ -755,7 +755,7 @@ discard block |
||
| 755 | 755 | $cut_size = 500; |
| 756 | 756 | $now = api_get_utc_datetime(); |
| 757 | 757 | |
| 758 | - $sql = "SELECT * FROM " . $table . " |
|
| 758 | + $sql = "SELECT * FROM ".$table." |
|
| 759 | 759 | WHERE |
| 760 | 760 | (lang = '$user_selected_language' OR lang = '') AND |
| 761 | 761 | ('$now' >= date_start AND '$now' <= date_end) "; |