diff --git a/main/admin/system_announcements.php b/main/admin/system_announcements.php
index c05b7332a2..62b3500a55 100755
--- a/main/admin/system_announcements.php
+++ b/main/admin/system_announcements.php
@@ -28,8 +28,9 @@ $interbreadcrumb[] = array(
"name" => get_lang('PlatformAdmin'),
);
-$tool_name = null;
+$visibleToUsers = SystemAnnouncementManager::getVisibilityList();
+$tool_name = null;
if (empty($_GET['lang'])) {
$_GET['lang'] = isset($_SESSION['user_language_choice']) ? $_SESSION['user_language_choice'] : null;
}
@@ -54,7 +55,6 @@ if (!empty($action)) {
// Displaying the header.
Display :: display_header($tool_name);
-
if ($action != 'add' && $action != 'edit') {
echo '
';
echo '
'.Display::return_icon('add.png', get_lang('AddAnnouncement'), array(), 32).'';
@@ -78,7 +78,7 @@ switch ($action) {
if ($action == 'make_visible') {
$status = true;
}
- SystemAnnouncementManager:: set_visibility(
+ SystemAnnouncementManager::set_visibility(
$_GET['id'],
$_GET['person'],
$status
@@ -86,12 +86,12 @@ switch ($action) {
break;
case 'delete':
// Delete an announcement.
- SystemAnnouncementManager :: delete_announcement($_GET['id']);
+ SystemAnnouncementManager::delete_announcement($_GET['id']);
echo Display::return_message(get_lang('AnnouncementDeleted'), 'confirmation');
break;
case 'delete_selected':
foreach ($_POST['id'] as $index => $id) {
- SystemAnnouncementManager :: delete_announcement($id);
+ SystemAnnouncementManager::delete_announcement($id);
}
echo Display::return_message(get_lang('AnnouncementDeleted'), 'confirmation');
$action_todo = false;
@@ -101,8 +101,7 @@ switch ($action) {
$values['action'] = 'add';
// Set default time window: NOW -> NEXT WEEK
$values['range_start'] = date('Y-m-d H:i:s', api_strtotime(api_get_local_time()));
- $values['range_end'] = date('Y-m-d H:i:s', api_strtotime(api_get_local_time()) + (7 * 24 * 60 * 60));
-
+ $values['range_end'] = date('Y-m-d H:i:s', api_strtotime(api_get_local_time()) + (7 * 24 * 60 * 60));
$values['range'] =
substr(api_get_local_time(time()), 0, 16).' / '.
substr(api_get_local_time(time() + (7 * 24 * 60 * 60)), 0, 16);
@@ -116,14 +115,19 @@ switch ($action) {
$values['content'] = $announcement->content;
$values['start'] = api_get_local_time($announcement->date_start);
$values['end'] = api_get_local_time($announcement->date_end);
-
- $values['range'] =
- substr(api_get_local_time($announcement->date_start), 0, 16).' / '.
+ $values['range'] =substr(api_get_local_time($announcement->date_start), 0, 16).' / '.
substr(api_get_local_time($announcement->date_end), 0, 16);
- $values['visible_teacher'] = $announcement->visible_teacher;
+ $data = (array) $announcement;
+ foreach ($visibleToUsers as $key => $value) {
+ if (isset($data[$key])) {
+ $values[$key] = $data[$key];
+ }
+ }
+ /*$values['visible_teacher'] = $announcement->visible_teacher;
$values['visible_student'] = $announcement->visible_student;
- $values['visible_guest'] = $announcement->visible_guest;
+ $values['visible_guest'] = $announcement->visible_guest;*/
+
$values['lang'] = $announcement->lang;
$values['action'] = 'edit';
$groups = SystemAnnouncementManager::get_announcement_groups($announcement->id);
@@ -171,15 +175,6 @@ if ($action_todo) {
array('id' => 'range')
);
- $visibleToUsers = [
- 'visible_teacher' => get_lang('Teacher'),
- 'visible_student' => get_lang('Student'),
- 'visible_drh' => get_lang('DRH'),
- 'visible_session_admin' => get_lang('SessionAdministrator'),
- 'visible_boss' => get_lang('StudentBoss'),
- 'visible_guest' => get_lang('Guest')
- ];
-
$group = [];
foreach ($visibleToUsers as $key => $name) {
$group[] = $form->createElement(
@@ -207,7 +202,6 @@ if ($action_todo) {
}
$values['group'] = isset($values['group']) ? $values['group'] : '0';
-
$form->addElement('checkbox', 'send_mail', null, get_lang('SendMail'));
if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'add') {
@@ -226,16 +220,15 @@ if ($action_todo) {
$form->setDefaults($values);
if ($form->validate()) {
- $values = $form->exportValues();
- if (!isset($values['visible_teacher'])) {
- $values['visible_teacher'] = false;
- }
- if (!isset($values['visible_student'])) {
- $values['visible_student'] = false;
- }
- if (!isset($values['visible_guest'])) {
- $values['visible_guest'] = false;
+ $values = $form->getSubmitValues();
+ $visibilityResult = [];
+ foreach ($visibleToUsers as $key => $value) {
+ if (!isset($values[$key])) {
+ $values[$key] = false;
+ }
+ $visibilityResult[$key] = $values[$key];
}
+
if ($values['lang'] == 'all') {
$values['lang'] = null;
}
@@ -249,9 +242,7 @@ if ($action_todo) {
$values['content'],
$values['range_start'],
$values['range_end'],
- $values['visible_teacher'],
- $values['visible_student'],
- $values['visible_guest'],
+ $visibilityResult,
$values['lang'],
$sendMail,
empty($values['add_to_calendar']) ? false : true,
@@ -283,14 +274,11 @@ if ($action_todo) {
$values['content'],
$values['range_start'],
$values['range_end'],
- $values['visible_teacher'],
- $values['visible_student'],
- $values['visible_guest'],
+ $visibilityResult,
$values['lang'],
$sendMail,
$sendMailTest
- )
- ) {
+ )) {
if (isset($values['group'])) {
SystemAnnouncementManager::announcement_for_groups(
$values['id'],
@@ -326,25 +314,42 @@ 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=".SystemAnnouncementManager::VISIBLE_TEACHER."&action=".($announcement->visible_teacher ? 'make_invisible' : 'make_visible')."\">".Display::return_icon(($announcement->visible_teacher ? 'eyes.png' : 'eyes-close.png'), get_lang('ShowOrHide'))."";
+
+ $data = (array) $announcement;
+ foreach ($visibleToUsers as $key => $value) {
+ $value = $data[$key];
+ $action = $value ? 'make_invisible' : 'make_visible';
+ $row[] = "
id."&person=".$key."&action=".$action."\">".
+ Display::return_icon(($value ? 'eyes.png' : 'eyes-close.png'), get_lang('ShowOrHide'))."";
+ }
+ /*$row[] = "
id."&person=".SystemAnnouncementManager::VISIBLE_TEACHER."&action=".($announcement->visible_teacher ? 'make_invisible' : 'make_visible')."\">".Display::return_icon(($announcement->visible_teacher ? 'eyes.png' : 'eyes-close.png'), get_lang('ShowOrHide'))."";
$row[] = "
id."&person=".SystemAnnouncementManager::VISIBLE_STUDENT."&action=".($announcement->visible_student ? 'make_invisible' : 'make_visible')."\">".Display::return_icon(($announcement->visible_student ? 'eyes.png' : 'eyes-close.png'), get_lang('ShowOrHide'))."";
- $row[] = "
id."&person=".SystemAnnouncementManager::VISIBLE_GUEST."&action=".($announcement->visible_guest ? 'make_invisible' : 'make_visible')."\">".Display::return_icon(($announcement->visible_guest ? 'eyes.png' : 'eyes-close.png'), get_lang('ShowOrHide'))."";
+ $row[] = "
id."&person=".SystemAnnouncementManager::VISIBLE_GUEST."&action=".($announcement->visible_guest ? 'make_invisible' : 'make_visible')."\">".Display::return_icon(($announcement->visible_guest ? 'eyes.png' : 'eyes-close.png'), 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)."";
$announcement_data[] = $row;
}
$table = new SortableTableFromArray($announcement_data);
- $table->set_header(0, '', false);
+ $table->set_header(0, '', false, 'width="20px"');
$table->set_header(1, get_lang('Active'));
$table->set_header(2, get_lang('Title'));
$table->set_header(3, get_lang('StartTimeWindow'));
$table->set_header(4, get_lang('EndTimeWindow'));
- $table->set_header(5, get_lang('Teacher'));
- $table->set_header(6, get_lang('Student'));
- $table->set_header(7, get_lang('Guest'));
- $table->set_header(8, get_lang('Language'));
- $table->set_header(9, get_lang('Modify'), false, 'width="50px"');
+ $count = 5;
+ foreach ($visibleToUsers as $key => $value) {
+ $table->set_header($count, $value);
+ $count++;
+ }
+
+ //$table->set_header(5, get_lang('Teacher'));
+ //$table->set_header(6, get_lang('Student'));
+ //$table->set_header(7, get_lang('Guest'));
+
+ $table->set_header($count++, get_lang('Language'));
+ $table->set_header($count++, get_lang('Modify'), false, 'width="50px"');
$form_actions = array();
$form_actions['delete_selected'] = get_lang('Delete');
$table->set_form_actions($form_actions);
diff --git a/main/inc/lib/system_announcements.lib.php b/main/inc/lib/system_announcements.lib.php
index e2821204c7..c02e67e100 100755
--- a/main/inc/lib/system_announcements.lib.php
+++ b/main/inc/lib/system_announcements.lib.php
@@ -298,9 +298,7 @@ class SystemAnnouncementManager
* @param string $content Content of the announcement
* @param string $date_start Start date (YYYY-MM-DD HH:II: SS)
* @param string $date_end End date (YYYY-MM-DD HH:II: SS)
- * @param int $visible_teacher Whether the announcement should be visible to teachers (1) or not (0)
- * @param int $visible_student Whether the announcement should be visible to students (1) or not (0)
- * @param int $visible_guest Whether the announcement should be visible to anonymous users (1) or not (0)
+ * @param array $visibility
* @param string $lang The language for which the announvement should be shown. Leave null for all langages
* @param int $send_mail Whether to send an e-mail to all users (1) or not (0)
* @param bool $add_to_calendar
@@ -313,9 +311,7 @@ class SystemAnnouncementManager
$content,
$date_start,
$date_end,
- $visible_teacher = 0,
- $visible_student = 0,
- $visible_guest = 0,
+ $visibility,
$lang = '',
$send_mail = 0,
$add_to_calendar = false,
@@ -376,13 +372,14 @@ class SystemAnnouncementManager
'content' => $content,
'date_start' => $start,
'date_end' => $end,
- 'visible_teacher' => $visible_teacher,
- 'visible_student' => $visible_student,
- 'visible_guest' => $visible_guest,
'lang' => $lang,
'access_url_id' => $current_access_url_id
];
+ foreach ($visibility as $key => $value) {
+ $params[$key] = $value;
+ }
+
$resultId = Database::insert($db_table, $params);
if ($resultId) {
@@ -390,8 +387,7 @@ class SystemAnnouncementManager
self::send_system_announcement_by_email(
$title,
$content,
- $visible_teacher,
- $visible_student,
+ $visibility,
$lang,
true
);
@@ -400,8 +396,7 @@ class SystemAnnouncementManager
self::send_system_announcement_by_email(
$title,
$content,
- $visible_teacher,
- $visible_student,
+ $visibility,
$lang
);
}
@@ -487,12 +482,14 @@ class SystemAnnouncementManager
/**
* Updates an announcement to the database
- * @param integer $id : id of the announcement
- * @param string $title : title of the announcement
- * @param string $content : content of the announcement
- * @param array $date_start: start date of announcement (0 => day ; 1 => month ; 2 => year ; 3 => hour ; 4 => minute)
- * @param array $date_end : end date of announcement (0 => day ; 1 => month ; 2 => year ; 3 => hour ; 4 => minute)
- * @return bool True on success, false on failure
+ *
+ * @param integer $id of the announcement
+ * @param string $title title of the announcement
+ * @param string $content content of the announcement
+ * @param array $date_start start date (0 => day ; 1 => month ; 2 => year ; 3 => hour ; 4 => minute)
+ * @param array $date_end end date of (0 => day ; 1 => month ; 2 => year ; 3 => hour ; 4 => minute)
+ * @param array $visibility
+ * @return bool True on success, false on failure
*/
public static function update_announcement(
$id,
@@ -500,16 +497,13 @@ class SystemAnnouncementManager
$content,
$date_start,
$date_end,
- $visible_teacher = 0,
- $visible_student = 0,
- $visible_guest = 0,
+ $visibility,
$lang = null,
$send_mail = 0,
$sendEmailTest = false
) {
$em = Database::getManager();
$announcement = $em->find('ChamiloCoreBundle:SysAnnouncement', $id);
-
if (!$announcement) {
return false;
}
@@ -532,31 +526,35 @@ class SystemAnnouncementManager
return false;
}
- if (($date_end_to_compare[1] ||
+ if (($date_end_to_compare[1] ||
$date_end_to_compare[2] ||
$date_end_to_compare[0]) &&
!checkdate($date_end_to_compare[1], $date_end_to_compare[2], $date_end_to_compare[0])
) {
- echo Display::return_message(get_lang('InvalidEndDate'));
+ echo Display::return_message(get_lang('InvalidEndDate'));
- return false;
- }
+ return false;
+ }
- if (strlen(trim($title)) == 0) {
- echo Display::return_message(get_lang('InvalidTitle'));
+ if (strlen(trim($title)) == 0) {
+ echo Display::return_message(get_lang('InvalidTitle'));
- return false;
- }
+ return false;
+ }
$start = api_get_utc_datetime($date_start);
$end = api_get_utc_datetime($date_end);
- //Fixing urls that are sent by email
- //$content = str_replace('src=\"/home/', 'src=\"'.api_get_path(WEB_PATH).'home/', $content);
- //$content = str_replace('file=/home/', 'file='.api_get_path(WEB_PATH).'home/', $content);
+ //Fixing urls that are sent by email
+ //$content = str_replace('src=\"/home/', 'src=\"'.api_get_path(WEB_PATH).'home/', $content);
+ //$content = str_replace('file=/home/', 'file='.api_get_path(WEB_PATH).'home/', $content);
$content = str_replace('src=\"'.api_get_path(REL_HOME_PATH), 'src=\"'.api_get_path(WEB_PATH).api_get_path(REL_HOME_PATH), $content);
$content = str_replace('file='.api_get_path(REL_HOME_PATH), 'file='.api_get_path(WEB_PATH).api_get_path(REL_HOME_PATH), $content);
+ $visible_teacher = $visibility['visible_teacher'];
+ $visible_student = $visibility['visible_student'];
+ $visible_guest = $visibility['visible_guest'];
+
if ($sendEmailTest) {
self::send_system_announcement_by_email(
$title,
@@ -587,33 +585,41 @@ class SystemAnnouncementManager
->setContent($content)
->setDateStart($dateStart)
->setDateEnd($dateEnd)
- ->setVisibleTeacher($visible_teacher)
- ->setVisibleStudent($visible_student)
- ->setVisibleGuest($visible_guest)
+ //->setVisibleTeacher($visible_teacher)
+ //->setVisibleStudent($visible_student)
+ //->setVisibleGuest($visible_guest)
->setAccessUrlId(api_get_current_access_url_id());
$em->merge($announcement);
$em->flush();
- return true;
- }
+ // Update visibility
+ $list = self::getVisibilityList();
+ $table = Database::get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS);
+ foreach ($list as $key => $title) {
+ $value = isset($visibility[$key]) && $visibility[$key] ? 1 : 0;
+ $sql = "UPDATE $table SET $key = '$value' WHERE id = $id";
+ Database::query($sql);
+ }
+ return true;
+ }
- /**
- * Deletes an announcement
- * @param int $id The identifier of the announcement that should be
- * @return bool True on success, false on failure
- */
- public static function delete_announcement($id)
+ /**
+ * Deletes an announcement
+ * @param int $id The identifier of the announcement that should be
+ * @return bool True on success, false on failure
+ */
+ public static function delete_announcement($id)
{
- $db_table = Database::get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS);
- $id = intval($id);
- $sql = "DELETE FROM ".$db_table." WHERE id =".$id;
- $res = Database::query($sql);
+ $table = Database::get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS);
+ $id = intval($id);
+ $sql = "DELETE FROM $table WHERE id =".$id;
+ $res = Database::query($sql);
if ($res === false) {
- return false;
- }
- return true;
- }
+ return false;
+ }
+ return true;
+ }
/**
* Gets an announcement
@@ -632,25 +638,25 @@ class SystemAnnouncementManager
/**
* Change the visibility of an announcement
- * @param int $announcement_id
- * @param int $user For who should the visibility be changed
+ * @param int $id
+ * @param int $user For who should the visibility be changed
+ * @param int $visible
* (possible values are VISIBLE_TEACHER, VISIBLE_STUDENT, VISIBLE_GUEST)
* @return bool True on success, false on failure
*/
- public static function set_visibility($announcement_id, $user, $visible)
+ public static function set_visibility($id, $user, $visible)
{
- $db_table = Database::get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS);
- $visible = intval($visible);
- $announcement_id = intval($announcement_id);
-
- if (!in_array($user, array(self::VISIBLE_GUEST, self::VISIBLE_STUDENT, self::VISIBLE_TEACHER))) {
- return false;
+ $table = Database::get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS);
+ $id = (int) $id;
+ $list = array_keys(self::getVisibilityList());
+ $user = trim($user);
+ if (!in_array($user, $list)) {
+ 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."'";
+ $field = $user;
+ $sql = "UPDATE $table SET ".$field." = '".$visible."'
+ WHERE id='".$id."'";
$res = Database::query($sql);
if ($res === false) {
@@ -660,12 +666,37 @@ class SystemAnnouncementManager
return true;
}
+ /**
+ * @return array
+ */
+ public static function getVisibilityList()
+ {
+ $extraRoles = api_get_configuration_value('system_announce_extra_roles');
+ /* Requires DB change:
+ ALTER TABLE sys_announcement ADD COLUMN visible_drh INT DEFAULT 0;
+ ALTER TABLE sys_announcement ADD COLUMN visible_session_admin INT DEFAULT 0;
+ ALTER TABLE sys_announcement ADD COLUMN visible_boss INT DEFAULT 0;
+ */
+ $visibleToUsers = [
+ 'visible_teacher' => get_lang('Teacher'),
+ 'visible_student' => get_lang('Student'),
+ 'visible_guest' => get_lang('Guest')
+ ];
+
+ if ($extraRoles) {
+ $visibleToUsers['visible_drh'] = get_lang('DRH');
+ $visibleToUsers['visible_session_admin'] = get_lang('SessionAdministrator');
+ $visibleToUsers['visible_boss'] = get_lang('StudentBoss');
+ }
+
+ return $visibleToUsers;
+ }
+
/**
* Send a system announcement by e-mail to all teachers/students depending on parameters
* @param string $title
* @param string $content
- * @param int $teacher Whether to send to all teachers (1) or not (0)
- * @param int $student Whether to send to all students (1) or not (0)
+ * @param array $visibility
* @param string $language Language (optional, considered for all languages if left empty)
* @param bool $sendEmailTest
* @return bool True if the message was sent or there was no destination matching. False on database or e-mail sending error.
@@ -673,14 +704,14 @@ class SystemAnnouncementManager
public static function send_system_announcement_by_email(
$title,
$content,
- $teacher,
- $student,
+ $visibility,
$language = null,
$sendEmailTest = false
) {
$content = str_replace(array('\r\n', '\n', '\r'), '', $content);
$now = api_get_utc_datetime();
-
+ $teacher = $visibility['visible_teacher'];
+ $student = $visibility['visible_student'];
if ($sendEmailTest) {
MessageManager::send_message_simple(api_get_user_id(), $title, $content);
diff --git a/main/install/configuration.dist.php b/main/install/configuration.dist.php
index 43e3d9ad7f..edd01906da 100755
--- a/main/install/configuration.dist.php
+++ b/main/install/configuration.dist.php
@@ -371,3 +371,5 @@ $_configuration['agenda_legend'] = [
//$_configuration['session_list_show_count_users'] = false;
// Session admin access to all course content
//$_configuration['session_admins_access_all_content'] = false;
+// Adds roles to the system announcements (requires DB change BT#12476)
+//$_configuration['system_announce_extra_roles'] = false;