system_announcements.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This page allows the administrator to manage the system announcements.
  5. * @package chamilo.admin.announcement
  6. */
  7. /* INIT SECTION */
  8. // Language files that need to be included.
  9. $language_file = array('admin', 'agenda', 'announcements');
  10. // Resetting the course id.
  11. $cidReset = true;
  12. // Including the global initialization file.
  13. require_once '../inc/global.inc.php';
  14. // Including additional libraries.
  15. require_once api_get_path(LIBRARY_PATH).'WCAG/WCAG_rendering.php';
  16. // Setting the section (for the tabs).
  17. $this_section = SECTION_PLATFORM_ADMIN;
  18. $_SESSION['this_section']=$this_section;
  19. // Access restrictions
  20. api_protect_admin_script(true);
  21. // Setting breadcrumbs.
  22. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  23. $tool_name = null;
  24. if (empty($_GET['lang'])) {
  25. $_GET['lang'] = api_get_user_language();
  26. }
  27. $usergroup = new UserGroup();
  28. if (isset($_GET['action'])) {
  29. $interbreadcrumb[] = array ("url" => "system_announcements.php", "name" => get_lang('SystemAnnouncements'));
  30. if ($_GET['action'] == 'add') {
  31. $interbreadcrumb[] = array ("url" => '#', "name" => get_lang('AddAnnouncement'));
  32. }
  33. if ($_GET['action'] == 'edit') {
  34. $interbreadcrumb[] = array ("url" => '#', "name" => get_lang('Edit'));
  35. }
  36. } else {
  37. $tool_name = get_lang('SystemAnnouncements');
  38. }
  39. // Displaying the header.
  40. Display :: display_header($tool_name);
  41. if ($_GET['action'] != 'add' && $_GET['action'] != 'edit') {
  42. echo '<div class="actions">';
  43. echo '<a href="?action=add">'.Display::return_icon('add.png', get_lang('AddAnnouncement'), array(), 32).'</a>';
  44. echo '</div>';
  45. }
  46. /* MAIN CODE */
  47. $show_announcement_list = true;
  48. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
  49. // Form was posted?
  50. $action_todo = false;
  51. if (isset($_POST['action'])) {
  52. $action_todo = true;
  53. }
  54. //Actions
  55. switch($action) {
  56. case 'make_visible':
  57. case 'make_invisible':
  58. $status = false;
  59. if ($action == 'make_visible') {
  60. $status = true;
  61. }
  62. SystemAnnouncementManager :: set_visibility($_GET['id'], $_GET['person'], $status);
  63. break;
  64. case 'delete':
  65. // Delete an announcement.
  66. SystemAnnouncementManager :: delete_announcement($_GET['id']);
  67. Display :: display_confirmation_message(get_lang('AnnouncementDeleted'));
  68. break;
  69. case 'delete_selected':
  70. foreach($_POST['id'] as $index => $id) {
  71. SystemAnnouncementManager :: delete_announcement($id);
  72. }
  73. Display :: display_confirmation_message(get_lang('AnnouncementDeleted'));
  74. $action_todo = false;
  75. break;
  76. case 'add':
  77. // Add an announcement.
  78. $values['action'] = 'add';
  79. // Set default time window: NOW -> NEXT WEEK
  80. $values['start'] = date('Y-m-d H:i:s',api_strtotime(api_get_local_time()));
  81. $values['end'] = date('Y-m-d H:i:s',api_strtotime(api_get_local_time()) + (7 * 24 * 60 * 60));
  82. $action_todo = true;
  83. break;
  84. case 'edit':
  85. // Edit an announcement.
  86. $announcement = SystemAnnouncementManager :: get_announcement($_GET['id']);
  87. $values['id'] = $announcement->id;
  88. $values['title'] = $announcement->title;
  89. $values['content'] = $announcement->content;
  90. $values['start'] = api_get_local_time($announcement->date_start);
  91. $values['end'] = api_get_local_time($announcement->date_end);
  92. $values['visible_teacher'] = $announcement->visible_teacher;
  93. $values['visible_student'] = $announcement->visible_student ;
  94. $values['visible_guest'] = $announcement->visible_guest ;
  95. $values['lang'] = $announcement->lang;
  96. $values['action'] = 'edit';
  97. $groups = SystemAnnouncementManager :: get_announcement_groups($announcement->id);
  98. $values['group'] = isset($groups[0]['group_id']) ? $groups[0]['group_id'] : 0;
  99. $action_todo = true;
  100. break;
  101. }
  102. if ($action_todo) {
  103. if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'add') {
  104. $form_title = get_lang('AddNews');
  105. } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'edit') {
  106. $form_title = get_lang('EditNews');
  107. }
  108. $form = new FormValidator('system_announcement');
  109. $form->addElement('header', '', $form_title);
  110. $form->add_textfield('title', get_lang('Title'), true, array('class'=>'span4'));
  111. $language_list = api_get_languages();
  112. $language_list_with_keys = array();
  113. $language_list_with_keys['all'] = get_lang('All');
  114. for($i=0; $i<count($language_list['name']) ; $i++) {
  115. $language_list_with_keys[$language_list['folder'][$i]] = $language_list['name'][$i];
  116. }
  117. $form->addElement('select', 'lang',get_lang('Language'), $language_list_with_keys);
  118. if (api_get_setting('wcag_anysurfer_public_pages')=='true') {
  119. $form->addElement('textarea', 'content', get_lang('Content'));
  120. } else {
  121. $form->add_html_editor('content', get_lang('Content'), true, false, array('ToolbarSet' => 'PortalNews', 'Width' => '100%', 'Height' => '300'));
  122. }
  123. $form->add_timewindow('start','end',get_lang('StartTimeWindow'),get_lang('EndTimeWindow'));
  124. $group = array();
  125. $group[]= $form->createElement('checkbox', 'visible_teacher', null, get_lang('Teacher'));
  126. $group[]= $form->createElement('checkbox', 'visible_student', null, get_lang('Student'));
  127. $group[]= $form->createElement('checkbox', 'visible_guest', null, get_lang('Guest'));
  128. $form->addGroup($group, null, get_lang('Visible'), '');
  129. $form->addElement('hidden', 'id');
  130. $group_list = $usergroup->get_groups_list();
  131. $group_list[0] = get_lang('All');
  132. $form->addElement('select', 'group',get_lang('AnnouncementForGroup'),$group_list);
  133. $values['group'] = isset($values['group']) ? $values['group'] : '0';
  134. $form->addElement('checkbox', 'send_mail', null, get_lang('SendMail'));
  135. if (isset($_REQUEST['action']) && $_REQUEST['action']=='add') {
  136. $form->addElement('checkbox', 'add_to_calendar', null, get_lang('AddToCalendar'));
  137. $text=get_lang('AddNews');
  138. $class='add';
  139. $form->addElement('hidden', 'action','add');
  140. } elseif (isset($_REQUEST['action']) && $_REQUEST['action']=='edit') {
  141. $text=get_lang('EditNews');
  142. $class='save';
  143. $form->addElement('hidden', 'action','edit');
  144. }
  145. $form->addElement('style_submit_button', 'submit', $text,'class="'.$class.'"');
  146. if (api_get_setting('wcag_anysurfer_public_pages') == 'true') {
  147. $values['content'] = WCAG_Rendering::HTML_to_text($values['content']);
  148. }
  149. $form->setDefaults($values);
  150. if ($form->validate()) {
  151. $values = $form->exportValues();
  152. if ( !isset($values['visible_teacher'])) {
  153. $values['visible_teacher'] = false;
  154. }
  155. if ( !isset($values['visible_student'])) {
  156. $values['visible_student'] = false;
  157. }
  158. if ( !isset($values['visible_guest'])) {
  159. $values['visible_guest'] = false;
  160. }
  161. if ($values['lang'] == 'all') {
  162. $values['lang'] = null;
  163. }
  164. if (api_get_setting('wcag_anysurfer_public_pages') == 'true') {
  165. $values['content'] = WCAG_Rendering::text_to_HTML($values['content']);
  166. }
  167. switch ($values['action']) {
  168. case 'add':
  169. $announcement_id = SystemAnnouncementManager::add_announcement($values['title'],$values['content'],$values['start'],$values['end'],$values['visible_teacher'],$values['visible_student'],$values['visible_guest'], $values['lang'],$values['send_mail'], $values['add_to_calendar']);
  170. if ($announcement_id !== false ) {
  171. SystemAnnouncementManager::announcement_for_groups($announcement_id, array($values['group']));
  172. Display :: display_confirmation_message(get_lang('AnnouncementAdded'));
  173. } else {
  174. $show_announcement_list = false;
  175. $form->display();
  176. }
  177. break;
  178. case 'edit':
  179. if (SystemAnnouncementManager::update_announcement($values['id'], $values['title'], $values['content'], $values['start'], $values['end'], $values['visible_teacher'], $values['visible_student'], $values['visible_guest'], $values['lang'], $values['send_mail'])) {
  180. SystemAnnouncementManager::announcement_for_groups($values['id'], array($values['group']));
  181. Display :: display_confirmation_message(get_lang('AnnouncementUpdated'));
  182. } else {
  183. $show_announcement_list = false;
  184. $form->display();
  185. }
  186. break;
  187. default:
  188. break;
  189. }
  190. $show_announcement_list = true;
  191. } else {
  192. if (api_get_setting('wcag_anysurfer_public_pages') == 'true') {
  193. echo '<div class="WCAG-form">';
  194. }
  195. $form->display();
  196. if (api_get_setting('wcag_anysurfer_public_pages') == 'true') {
  197. echo '</div>';
  198. }
  199. $show_announcement_list = false;
  200. }
  201. }
  202. if ($show_announcement_list) {
  203. $announcements = SystemAnnouncementManager :: get_all_announcements();
  204. $announcement_data = array ();
  205. foreach ($announcements as $index => $announcement) {
  206. $row = array();
  207. $row[] = $announcement->id;
  208. $row[] = Display::return_icon(($announcement->visible ? 'accept.png' : 'exclamation.png'), ($announcement->visible ? get_lang('AnnouncementAvailable') : get_lang('AnnouncementNotAvailable')));
  209. $row[] = $announcement->title;
  210. $row[] = api_convert_and_format_date($announcement->date_start);
  211. $row[] = api_convert_and_format_date($announcement->date_end);
  212. $row[] = "<a href=\"?id=".$announcement->id."&amp;person=".SystemAnnouncementManager::VISIBLE_TEACHER."&amp;action=". ($announcement->visible_teacher ? 'make_invisible' : 'make_visible')."\">".Display::return_icon(($announcement->visible_teacher ? 'visible.gif' : 'invisible.gif'), get_lang('ShowOrHide'))."</a>";
  213. $row[] = "<a href=\"?id=".$announcement->id."&amp;person=".SystemAnnouncementManager::VISIBLE_STUDENT."&amp;action=". ($announcement->visible_student ? 'make_invisible' : 'make_visible')."\">".Display::return_icon(($announcement->visible_student ? 'visible.gif' : 'invisible.gif'), get_lang('ShowOrHide'))."</a>";
  214. $row[] = "<a href=\"?id=".$announcement->id."&amp;person=".SystemAnnouncementManager::VISIBLE_GUEST."&amp;action=". ($announcement->visible_guest ? 'make_invisible' : 'make_visible')."\">".Display::return_icon(($announcement->visible_guest ? 'visible.gif' : 'invisible.gif'), get_lang('ShowOrHide'))."</a>";
  215. $row[] = $announcement->lang;
  216. $row[] = "<a href=\"?action=edit&id=".$announcement->id."\">".Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL)."</a> <a href=\"?action=delete&id=".$announcement->id."\" onclick=\"javascript:if(!confirm('".addslashes(get_lang("ConfirmYourChoice"))."')) return false;\">".Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL)."</a>";
  217. $announcement_data[] = $row;
  218. }
  219. $table = new SortableTableFromArray($announcement_data);
  220. $table->set_header(0, '', false);
  221. $table->set_header(1, get_lang('Active'));
  222. $table->set_header(2, get_lang('Title'));
  223. $table->set_header(3, get_lang('StartTimeWindow'));
  224. $table->set_header(4, get_lang('EndTimeWindow'));
  225. $table->set_header(5, get_lang('Teacher'));
  226. $table->set_header(6, get_lang('Student'));
  227. $table->set_header(7, get_lang('Guest'));
  228. $table->set_header(8, get_lang('Language'));
  229. $table->set_header(9, get_lang('Modify'), false, 'width="50px"');
  230. $form_actions = array();
  231. $form_actions['delete_selected'] = get_lang('Delete');
  232. $table->set_form_actions($form_actions);
  233. $table->display();
  234. }
  235. /* FOOTER */
  236. Display :: display_footer();