system_announcements.php 13 KB

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