diff --git a/main/admin/system_announcements.php b/main/admin/system_announcements.php
index f42f896610..cf2e3bf1f6 100644
--- a/main/admin/system_announcements.php
+++ b/main/admin/system_announcements.php
@@ -60,82 +60,62 @@ if ($_GET['action'] != 'add' && $_GET['action'] != 'edit') {
/* MAIN CODE */
-$form_action = '';
$show_announcement_list = true;
-if (isset ($_GET['action']) && $_GET['action'] == 'make_visible') {
- switch ($_GET['person']) {
- case VISIBLE_TEACHER :
- SystemAnnouncementManager :: set_visibility($_GET['id'], VISIBLE_TEACHER, true);
- break;
- case VISIBLE_STUDENT :
- SystemAnnouncementManager :: set_visibility($_GET['id'], VISIBLE_STUDENT, true);
- break;
- case VISIBLE_GUEST :
- SystemAnnouncementManager :: set_visibility($_GET['id'], VISIBLE_GUEST, true);
- break;
- }
-}
-
-if (isset ($_GET['action']) && $_GET['action'] == 'make_invisible') {
- switch ($_GET['person']) {
- case VISIBLE_TEACHER :
- SystemAnnouncementManager :: set_visibility($_GET['id'], VISIBLE_TEACHER, false);
- break;
- case VISIBLE_STUDENT :
- SystemAnnouncementManager :: set_visibility($_GET['id'], VISIBLE_STUDENT, false);
- break;
- case VISIBLE_GUEST :
- SystemAnnouncementManager :: set_visibility($_GET['id'], VISIBLE_GUEST, false);
- break;
- }
-}
+$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
// Form was posted?
if (isset ($_POST['action'])) {
$action_todo = true;
}
-// Delete an announcement.
-if (isset ($_GET['action']) && $_GET['action'] == 'delete') {
- SystemAnnouncementManager :: delete_announcement($_GET['id']);
- Display :: display_confirmation_message(get_lang('AnnouncementDeleted'));
-}
-
-// Delete selected announcements.
-if (isset ($_POST['action']) && $_POST['action'] == 'delete_selected') {
- foreach($_POST['id'] as $index => $id) {
- SystemAnnouncementManager :: delete_announcement($id);
- }
- Display :: display_confirmation_message(get_lang('AnnouncementDeleted'));
- $action_todo = false;
-}
-
-// Add an announcement.
-if (isset ($_GET['action']) && $_GET['action'] == 'add') {
- $values['action'] = 'add';
- // Set default time window: NOW -> NEXT WEEK
- $values['start'] = date('Y-m-d H:i:s',api_strtotime(api_get_local_time()));
- $values['end'] = date('Y-m-d H:i:s',api_strtotime(api_get_local_time()) + (7 * 24 * 60 * 60));
- $action_todo = true;
-}
-
-// Edit an announcement.
-if (isset ($_GET['action']) && $_GET['action'] == 'edit') {
-
- $announcement = SystemAnnouncementManager :: get_announcement($_GET['id']);
- $values['id'] = $announcement->id;
- $values['title'] = $announcement->title;
- $values['content'] = $announcement->content;
- $values['start'] = api_get_local_time($announcement->date_start);
- $values['end'] = api_get_local_time($announcement->date_end);
- $values['visible_teacher'] = $announcement->visible_teacher;
- $values['visible_student'] = $announcement->visible_student ;
- $values['visible_guest'] = $announcement->visible_guest ;
- $values['lang'] = $announcement->lang;
- $values['action'] = 'edit';
- $groups = SystemAnnouncementManager :: get_announcement_groups($announcement->id);
- $values['group'] = isset($groups[0]['group_id']) ? $groups[0]['group_id'] : 0;
- $action_todo = true;
+//Actions
+switch($action) {
+ case 'make_visible':
+ case 'make_invisible':
+ $status = false;
+ if ($action == 'make_visible') {
+ $status = true;
+ }
+ SystemAnnouncementManager :: set_visibility($_GET['id'], $_GET['person'], $status);
+ break;
+ case 'delete':
+ // Delete an announcement.
+ SystemAnnouncementManager :: delete_announcement($_GET['id']);
+ Display :: display_confirmation_message(get_lang('AnnouncementDeleted'));
+ break;
+
+ case 'delete_selected':
+ foreach($_POST['id'] as $index => $id) {
+ SystemAnnouncementManager :: delete_announcement($id);
+ }
+ Display :: display_confirmation_message(get_lang('AnnouncementDeleted'));
+ $action_todo = false;
+ break;
+ case 'add':
+ // Add an announcement.
+ $values['action'] = 'add';
+ // Set default time window: NOW -> NEXT WEEK
+ $values['start'] = date('Y-m-d H:i:s',api_strtotime(api_get_local_time()));
+ $values['end'] = date('Y-m-d H:i:s',api_strtotime(api_get_local_time()) + (7 * 24 * 60 * 60));
+ $action_todo = true;
+ break;
+ case 'edit':
+ // Edit an announcement.
+ $announcement = SystemAnnouncementManager :: get_announcement($_GET['id']);
+ $values['id'] = $announcement->id;
+ $values['title'] = $announcement->title;
+ $values['content'] = $announcement->content;
+ $values['start'] = api_get_local_time($announcement->date_start);
+ $values['end'] = api_get_local_time($announcement->date_end);
+ $values['visible_teacher'] = $announcement->visible_teacher;
+ $values['visible_student'] = $announcement->visible_student ;
+ $values['visible_guest'] = $announcement->visible_guest ;
+ $values['lang'] = $announcement->lang;
+ $values['action'] = 'edit';
+ $groups = SystemAnnouncementManager :: get_announcement_groups($announcement->id);
+ $values['group'] = isset($groups[0]['group_id']) ? $groups[0]['group_id'] : 0;
+ $action_todo = true;
+ break;
}
if ($action_todo) {
@@ -144,7 +124,6 @@ if ($action_todo) {
} elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'edit') {
$form_title = get_lang('EditNews');
}
-
$form = new FormValidator('system_announcement');
$form->addElement('header', '', $form_title);
$form->add_textfield('title', get_lang('Title'), true, array('size'=>'60px'));
@@ -259,9 +238,9 @@ if ($show_announcement_list) {
$row[] = $announcement->title;
$row[] = api_convert_and_format_date($announcement->date_start);
$row[] = api_convert_and_format_date($announcement->date_end);
- $row[] = "id."&person=".VISIBLE_TEACHER."&action=". ($announcement->visible_teacher ? 'make_invisible' : 'make_visible')."\">".Display::return_icon(($announcement->visible_teacher ? 'visible.gif' : 'invisible.gif'), get_lang('ShowOrHide'))."";
- $row[] = "id."&person=".VISIBLE_STUDENT."&action=". ($announcement->visible_student ? 'make_invisible' : 'make_visible')."\">".Display::return_icon(($announcement->visible_student ? 'visible.gif' : 'invisible.gif'), get_lang('ShowOrHide'))."";
- $row[] = "id."&person=".VISIBLE_GUEST."&action=". ($announcement->visible_guest ? 'make_invisible' : 'make_visible')."\">".Display::return_icon(($announcement->visible_guest ? 'visible.gif' : 'invisible.gif'), get_lang('ShowOrHide'))."";
+ $row[] = "id."&person=".SystemAnnouncementManager::VISIBLE_TEACHER."&action=". ($announcement->visible_teacher ? 'make_invisible' : 'make_visible')."\">".Display::return_icon(($announcement->visible_teacher ? 'visible.gif' : 'invisible.gif'), get_lang('ShowOrHide'))."";
+ $row[] = "id."&person=".SystemAnnouncementManager::VISIBLE_STUDENT."&action=". ($announcement->visible_student ? 'make_invisible' : 'make_visible')."\">".Display::return_icon(($announcement->visible_student ? 'visible.gif' : 'invisible.gif'), get_lang('ShowOrHide'))."";
+ $row[] = "id."&person=".SystemAnnouncementManager::VISIBLE_GUEST."&action=". ($announcement->visible_guest ? 'make_invisible' : 'make_visible')."\">".Display::return_icon(($announcement->visible_guest ? 'visible.gif' : 'invisible.gif'), get_lang('ShowOrHide'))."";
$row[] = $announcement->lang;
$row[] = "id."\">".Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL)." id."\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES))."')) return false;\">".Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL)."";
diff --git a/main/inc/lib/system_announcements.lib.php b/main/inc/lib/system_announcements.lib.php
index 0df5238ebe..36041efd9c 100644
--- a/main/inc/lib/system_announcements.lib.php
+++ b/main/inc/lib/system_announcements.lib.php
@@ -6,9 +6,7 @@
/**
* Code
*/
-define('VISIBLE_GUEST', 1);
-define('VISIBLE_STUDENT', 2);
-define('VISIBLE_TEACHER', 3);
+
/**
* This is the system announcements library for Dokeos.
@@ -16,6 +14,11 @@ define('VISIBLE_TEACHER', 3);
* @package chamilo.library
*/
class SystemAnnouncementManager {
+
+ CONST VISIBLE_GUEST = 1;
+ CONST VISIBLE_STUDENT = 2;
+ CONST VISIBLE_TEACHER = 3;
+
/**
* Displays all announcements
* @param int $visible VISIBLE_GUEST, VISIBLE_STUDENT or VISIBLE_TEACHER
@@ -44,13 +47,13 @@ class SystemAnnouncementManager {
." AND ((NOW() BETWEEN date_start AND date_end) OR date_end='0000-00-00') ";
switch ($visible) {
- case VISIBLE_GUEST :
+ case self::VISIBLE_GUEST :
$sql .= " AND visible_guest = 1 ";
break;
- case VISIBLE_STUDENT :
+ case self::VISIBLE_STUDENT :
$sql .= " AND visible_student = 1 ";
break;
- case VISIBLE_TEACHER :
+ case self::VISIBLE_TEACHER :
$sql .= " AND visible_teacher = 1 ";
break;
}
@@ -128,13 +131,13 @@ class SystemAnnouncementManager {
WHERE ( lang = '$user_selected_language' OR lang IS NULL) AND ( '$now' >= date_start AND '$now' <= date_end) ";
switch ($visible) {
- case VISIBLE_GUEST :
+ case self::VISIBLE_GUEST :
$sql .= " AND visible_guest = 1 ";
break;
- case VISIBLE_STUDENT :
+ case self::VISIBLE_STUDENT :
$sql .= " AND visible_student = 1 ";
break;
- case VISIBLE_TEACHER :
+ case self::VISIBLE_TEACHER :
$sql .= " AND visible_teacher = 1 ";
break;
}
@@ -219,19 +222,19 @@ class SystemAnnouncementManager {
public static function count_nb_announcement($start = 0, $user_id = '') {
$start = intval($start);
- $visibility = api_is_allowed_to_create_course() ? VISIBLE_TEACHER : VISIBLE_STUDENT;
+ $visibility = api_is_allowed_to_create_course() ? self::VISIBLE_TEACHER : self::VISIBLE_STUDENT;
$user_selected_language = api_get_interface_language();
$db_table = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS);
$sql = 'SELECT id FROM '.$db_table.' WHERE (lang="'.$user_selected_language.'" OR lang IS NULL) ';
if (isset($user_id)) {
switch ($visibility) {
- case VISIBLE_GUEST :
+ case self::VISIBLE_GUEST :
$sql .= " AND visible_guest = 1 ";
break;
- case VISIBLE_STUDENT :
+ case self::VISIBLE_STUDENT :
$sql .= " AND visible_student = 1 ";
break;
- case VISIBLE_TEACHER :
+ case self::VISIBLE_TEACHER :
$sql .= " AND visible_teacher = 1 ";
break;
}
@@ -496,8 +499,13 @@ class SystemAnnouncementManager {
$db_table = Database::get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS);
$visible = intval($visible);
$announcement_id = intval($announcement_id);
-
- $field = ($user == VISIBLE_TEACHER ? 'visible_teacher' : ($user == VISIBLE_STUDENT ? 'visible_student' : 'visible_guest'));
+
+ if (!in_array($user, array(self::VISIBLE_GUEST, self::VISIBLE_STUDENT, self::VISIBLE_TEACHER))) {
+ return false;
+ }
+
+ $field = ($user == self::VISIBLE_TEACHER ? 'visible_teacher' : ($user == self::VISIBLE_STUDENT ? 'visible_student' : 'visible_guest'));
+
$sql = "UPDATE ".$db_table." SET ".$field." = '".$visible."' WHERE id='".$announcement_id."'";
$res = Database::query($sql);
if ($res === false) {
@@ -586,13 +594,13 @@ class SystemAnnouncementManager {
WHERE ( lang = '$user_selected_language' OR lang IS NULL) AND ( '$now' >= date_start AND '$now' <= date_end) ";
switch ($visible) {
- case VISIBLE_GUEST :
+ case self::VISIBLE_GUEST :
$sql .= " AND visible_guest = 1 ";
break;
- case VISIBLE_STUDENT :
+ case self::VISIBLE_STUDENT :
$sql .= " AND visible_student = 1 ";
break;
- case VISIBLE_TEACHER :
+ case self::VISIBLE_TEACHER :
$sql .= " AND visible_teacher = 1 ";
break;
}
diff --git a/main/inc/lib/userportal.lib.php b/main/inc/lib/userportal.lib.php
index 62f19b7f24..8fd7c64523 100644
--- a/main/inc/lib/userportal.lib.php
+++ b/main/inc/lib/userportal.lib.php
@@ -83,7 +83,7 @@ class IndexManager {
$announcement = intval($announcement);
if (!api_is_anonymous() && $this->user_id) {
- $visibility = api_is_allowed_to_create_course() ? VISIBLE_TEACHER : VISIBLE_STUDENT;
+ $visibility = api_is_allowed_to_create_course() ? SystemAnnouncementManager::VISIBLE_TEACHER : SystemAnnouncementManager::VISIBLE_STUDENT;
if ($show_slide) {
$announcements = SystemAnnouncementManager :: display_announcements_slider($visibility, $announcement);
} else {
@@ -91,9 +91,9 @@ class IndexManager {
}
} else {
if ($show_slide) {
- $announcements = SystemAnnouncementManager :: display_announcements_slider(VISIBLE_GUEST, $announcement);
+ $announcements = SystemAnnouncementManager :: display_announcements_slider(SystemAnnouncementManager::VISIBLE_GUEST, $announcement);
} else {
- $announcements = SystemAnnouncementManager :: display_all_announcements(VISIBLE_GUEST, $announcement);
+ $announcements = SystemAnnouncementManager :: display_all_announcements(SystemAnnouncementManager::VISIBLE_GUEST, $announcement);
}
}
return $announcements;
diff --git a/news_list.php b/news_list.php
index 886491d3a7..b34d80d819 100644
--- a/news_list.php
+++ b/news_list.php
@@ -14,15 +14,13 @@ if (api_is_platform_admin()) {
}
if (api_is_anonymous()) {
- $visibility = VISIBLE_GUEST;
+ $visibility = SystemAnnouncementManager::VISIBLE_GUEST;
} else {
- $visibility = api_is_allowed_to_create_course() ? VISIBLE_TEACHER : VISIBLE_STUDENT;
+ $visibility = api_is_allowed_to_create_course() ? SystemAnnouncementManager::VISIBLE_TEACHER : SystemAnnouncementManager::VISIBLE_STUDENT;
}
-
$content = SystemAnnouncementManager ::display_announcements_slider($visibility, $_GET['id']);
$tpl = new Template($tool_name);
-
$tpl->assign('actions', $actions);
//$tpl->assign('message', $message);
$tpl->assign('content', $content);