system_announcements.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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. // Setting the section (for the tabs).
  13. $this_section = SECTION_PLATFORM_ADMIN;
  14. $_SESSION['this_section']=$this_section;
  15. $action = isset($_GET['action']) ? $_GET['action'] : null;
  16. // Access restrictions
  17. api_protect_admin_script(true);
  18. // Setting breadcrumbs.
  19. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  20. $tool_name = null;
  21. if (empty($_GET['lang'])) {
  22. $_GET['lang'] = api_get_user_language();
  23. }
  24. $usergroup = new UserGroup();
  25. if (!empty($action)) {
  26. $interbreadcrumb[] = array ("url" => "system_announcements.php", "name" => get_lang('SystemAnnouncements'));
  27. if ($action == 'add') {
  28. $interbreadcrumb[] = array ("url" => '#', "name" => get_lang('AddAnnouncement'));
  29. }
  30. if ($action == 'edit') {
  31. $interbreadcrumb[] = array ("url" => '#', "name" => get_lang('Edit'));
  32. }
  33. } else {
  34. $tool_name = get_lang('SystemAnnouncements');
  35. }
  36. // Displaying the header.
  37. Display :: display_header($tool_name);
  38. if ($action != 'add' && $action != 'edit') {
  39. echo '<div class="actions">';
  40. echo '<a href="?action=add">'.Display::return_icon('add.png', get_lang('AddAnnouncement'), array(), 32).'</a>';
  41. echo '</div>';
  42. }
  43. /* MAIN CODE */
  44. $show_announcement_list = true;
  45. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
  46. // Form was posted?
  47. if (isset($_POST['action'])) {
  48. $action_todo = true;
  49. }
  50. //Actions
  51. switch($action) {
  52. case 'make_visible':
  53. case 'make_invisible':
  54. $status = false;
  55. if ($action == 'make_visible') {
  56. $status = true;
  57. }
  58. SystemAnnouncementManager :: set_visibility($_GET['id'], $_GET['person'], $status);
  59. break;
  60. case 'delete':
  61. // Delete an announcement.
  62. SystemAnnouncementManager :: delete_announcement($_GET['id']);
  63. Display :: display_confirmation_message(get_lang('AnnouncementDeleted'));
  64. break;
  65. case 'delete_selected':
  66. foreach($_POST['id'] as $index => $id) {
  67. SystemAnnouncementManager :: delete_announcement($id);
  68. }
  69. Display :: display_confirmation_message(get_lang('AnnouncementDeleted'));
  70. $action_todo = false;
  71. break;
  72. case 'add':
  73. // Add an announcement.
  74. $values['action'] = 'add';
  75. // Set default time window: NOW -> NEXT WEEK
  76. $values['start'] = date('Y-m-d H:i:s',api_strtotime(api_get_local_time()));
  77. $values['end'] = date('Y-m-d H:i:s',api_strtotime(api_get_local_time()) + (7 * 24 * 60 * 60));
  78. $values['range'] =
  79. substr(api_get_local_time(api_get_local_time()), 0, 16).' / '.
  80. substr(api_get_local_time(api_get_local_time()) + (7 * 24 * 60 * 60), 0, 16);
  81. $action_todo = true;
  82. break;
  83. case 'edit':
  84. // Edit an announcement.
  85. $announcement = SystemAnnouncementManager :: get_announcement($_GET['id']);
  86. $values['id'] = $announcement->id;
  87. $values['title'] = $announcement->title;
  88. $values['content'] = $announcement->content;
  89. $values['start'] = api_get_local_time($announcement->date_start);
  90. $values['end'] = api_get_local_time($announcement->date_end);
  91. $values['range'] =
  92. substr(api_get_local_time($announcement->date_start), 0, 16).' / '.
  93. substr(api_get_local_time($announcement->date_end), 0, 16);
  94. $values['visible_teacher'] = $announcement->visible_teacher;
  95. $values['visible_student'] = $announcement->visible_student ;
  96. $values['visible_guest'] = $announcement->visible_guest ;
  97. $values['lang'] = $announcement->lang;
  98. $values['action'] = 'edit';
  99. $groups = SystemAnnouncementManager :: get_announcement_groups($announcement->id);
  100. $values['group'] = isset($groups[0]['group_id']) ? $groups[0]['group_id'] : 0;
  101. $action_todo = true;
  102. break;
  103. }
  104. if ($action_todo) {
  105. if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'add') {
  106. $form_title = get_lang('AddNews');
  107. } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'edit') {
  108. $form_title = get_lang('EditNews');
  109. }
  110. $form = new FormValidator('system_announcement');
  111. $form->addElement('header', '', $form_title);
  112. $form->add_textfield('title', get_lang('Title'), true, array('class'=>'span4'));
  113. $language_list = api_get_languages();
  114. $language_list_with_keys = array();
  115. $language_list_with_keys['all'] = get_lang('All');
  116. for($i=0; $i<count($language_list['name']) ; $i++) {
  117. $language_list_with_keys[$language_list['folder'][$i]] = $language_list['name'][$i];
  118. }
  119. $form->addElement('select', 'lang',get_lang('Language'), $language_list_with_keys);
  120. if (api_get_setting('wcag_anysurfer_public_pages')=='true') {
  121. $form->addElement('textarea', 'content', get_lang('Content'));
  122. } else {
  123. $form->add_html_editor('content', get_lang('Content'), true, false, array('ToolbarSet' => 'PortalNews', 'Width' => '100%', 'Height' => '300'));
  124. }
  125. $form->addDateRangePicker('range', get_lang('StartTimeWindow'), true, array('id' => 'date_range'));
  126. $group = array();
  127. $group[]= $form->createElement('checkbox', 'visible_teacher', null, get_lang('Teacher'));
  128. $group[]= $form->createElement('checkbox', 'visible_student', null, get_lang('Student'));
  129. $group[]= $form->createElement('checkbox', 'visible_guest', null, get_lang('Guest'));
  130. $form->addGroup($group, null, get_lang('Visible'), '');
  131. $form->addElement('hidden', 'id');
  132. $group_list = $usergroup->get_groups_list();
  133. $group_list[0] = get_lang('All');
  134. $form->addElement('select', 'group',get_lang('AnnouncementForGroup'),$group_list);
  135. $values['group'] = isset($values['group']) ? $values['group'] : '0';
  136. $form->addElement('checkbox', 'send_mail', null, get_lang('SendMail'));
  137. if (isset($_REQUEST['action']) && $_REQUEST['action']=='add') {
  138. $form->addElement('checkbox', 'add_to_calendar', null, get_lang('AddToCalendar'));
  139. $text=get_lang('AddNews');
  140. $class='add';
  141. $form->addElement('hidden', 'action', 'add');
  142. } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'edit') {
  143. $text=get_lang('EditNews');
  144. $class='save';
  145. $form->addElement('hidden', 'action', 'edit');
  146. }
  147. $form->addElement('checkbox', 'send_email_test', null, get_lang('SendOnlyAnEmailToMySelfToTest'));
  148. $form->addElement('style_submit_button', 'submit', $text, 'class="'.$class.'"');
  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. $sendMail = isset($values['send_mail']) ? $values['send_mail'] : null;
  165. switch ($values['action']) {
  166. case 'add':
  167. $announcement_id = SystemAnnouncementManager::add_announcement(
  168. $values['title'],
  169. $values['content'],
  170. $values['range_start'],
  171. $values['range_end'],
  172. $values['visible_teacher'],
  173. $values['visible_student'],
  174. $values['visible_guest'],
  175. $values['lang'],
  176. $sendMail,
  177. $values['add_to_calendar'],
  178. $values['send_email_test']
  179. );
  180. if ($announcement_id !== false) {
  181. SystemAnnouncementManager::announcement_for_groups($announcement_id, array($values['group']));
  182. Display :: display_confirmation_message(get_lang('AnnouncementAdded'));
  183. } else {
  184. $show_announcement_list = false;
  185. $form->display();
  186. }
  187. break;
  188. case 'edit':
  189. if (SystemAnnouncementManager::update_announcement(
  190. $values['id'],
  191. $values['title'],
  192. $values['content'],
  193. $values['range_start'],
  194. $values['range_end'],
  195. $values['visible_teacher'],
  196. $values['visible_student'],
  197. $values['visible_guest'],
  198. $values['lang'],
  199. $sendMail,
  200. $values['send_email_test']
  201. )
  202. ) {
  203. SystemAnnouncementManager::announcement_for_groups($values['id'], array($values['group']));
  204. Display :: display_confirmation_message(get_lang('AnnouncementUpdated'));
  205. } else {
  206. $show_announcement_list = false;
  207. $form->display();
  208. }
  209. break;
  210. default:
  211. break;
  212. }
  213. $show_announcement_list = true;
  214. } else {
  215. if (api_get_setting('wcag_anysurfer_public_pages') == 'true') {
  216. echo '<div class="WCAG-form">';
  217. }
  218. $form->display();
  219. if (api_get_setting('wcag_anysurfer_public_pages') == 'true') {
  220. echo '</div>';
  221. }
  222. $show_announcement_list = false;
  223. }
  224. }
  225. if ($show_announcement_list) {
  226. $announcements = SystemAnnouncementManager :: get_all_announcements();
  227. $announcement_data = array ();
  228. foreach ($announcements as $index => $announcement) {
  229. $row = array();
  230. $row[] = $announcement->id;
  231. $row[] = Display::return_icon(($announcement->visible ? 'accept.png' : 'exclamation.png'), ($announcement->visible ? get_lang('AnnouncementAvailable') : get_lang('AnnouncementNotAvailable')));
  232. $row[] = $announcement->title;
  233. $row[] = api_convert_and_format_date($announcement->date_start);
  234. $row[] = api_convert_and_format_date($announcement->date_end);
  235. $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>";
  236. $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>";
  237. $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>";
  238. $row[] = $announcement->lang;
  239. $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>";
  240. $announcement_data[] = $row;
  241. }
  242. $table = new SortableTableFromArray($announcement_data);
  243. $table->set_header(0, '', false);
  244. $table->set_header(1, get_lang('Active'));
  245. $table->set_header(2, get_lang('Title'));
  246. $table->set_header(3, get_lang('StartTimeWindow'));
  247. $table->set_header(4, get_lang('EndTimeWindow'));
  248. $table->set_header(5, get_lang('Teacher'));
  249. $table->set_header(6, get_lang('Student'));
  250. $table->set_header(7, get_lang('Guest'));
  251. $table->set_header(8, get_lang('Language'));
  252. $table->set_header(9, get_lang('Modify'), false, 'width="50px"');
  253. $form_actions = array();
  254. $form_actions['delete_selected'] = get_lang('Delete');
  255. $table->set_form_actions($form_actions);
  256. $table->display();
  257. }
  258. /* FOOTER */
  259. Display :: display_footer();