announcements.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @author Frederik Vermeire <frederik.vermeire@pandora.be>, UGent Internship
  5. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: code cleaning
  6. * @author Julio Montoya <gugli100@gmail.com>, MORE code cleaning 2011
  7. *
  8. * @abstract The task of the internship was to integrate the 'send messages to specific users' with the
  9. * Announcements tool and also add the resource linker here. The database also needed refactoring
  10. * as there was no title field (the title was merged into the content field)
  11. *
  12. * @package chamilo.announcements
  13. * multiple functions
  14. */
  15. // use anonymous mode when accessing this course tool
  16. $use_anonymous = true;
  17. // setting the global file that gets the general configuration, the databases, the languages, ...
  18. require_once __DIR__.'/../inc/global.inc.php';
  19. api_protect_course_script(true);
  20. api_protect_course_group(GroupManager::GROUP_TOOL_ANNOUNCEMENT);
  21. $token = Security::get_existing_token();
  22. $courseId = api_get_course_int_id();
  23. $_course = api_get_course_info_by_id($courseId);
  24. $group_id = api_get_group_id();
  25. $sessionId = api_get_session_id();
  26. $current_course_tool = TOOL_ANNOUNCEMENT;
  27. $this_section = SECTION_COURSES;
  28. $nameTools = get_lang('ToolAnnouncement');
  29. $allowToEdit = (
  30. api_is_allowed_to_edit(false, true) ||
  31. (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())
  32. );
  33. $sessionId = api_get_session_id();
  34. $drhHasAccessToSessionContent = api_drh_can_access_all_session_content();
  35. if (!empty($sessionId) && $drhHasAccessToSessionContent) {
  36. $allowToEdit = $allowToEdit || api_is_drh();
  37. }
  38. // Configuration settings
  39. $display_announcement_list = true;
  40. $display_form = false;
  41. $display_title_list = true;
  42. // Maximum title messages to display
  43. $maximum = '12';
  44. // Length of the titles
  45. $length = '36';
  46. // Database Table Definitions
  47. $tbl_courses = Database::get_main_table(TABLE_MAIN_COURSE);
  48. $tbl_sessions = Database::get_main_table(TABLE_MAIN_SESSION);
  49. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
  50. $tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
  51. $isTutor = false;
  52. if (!empty($group_id)) {
  53. $groupProperties = GroupManager:: get_group_properties($group_id);
  54. $interbreadcrumb[] = [
  55. "url" => api_get_path(WEB_CODE_PATH)."group/group.php?".api_get_cidreq(),
  56. "name" => get_lang('Groups'),
  57. ];
  58. $interbreadcrumb[] = [
  59. "url" => api_get_path(WEB_CODE_PATH)."group/group_space.php?".api_get_cidreq(),
  60. "name" => get_lang('GroupSpace').' '.$groupProperties['name'],
  61. ];
  62. if ($allowToEdit === false) {
  63. // Check if user is tutor group
  64. $isTutor = GroupManager::is_tutor_of_group(api_get_user_id(), $groupProperties, $courseId);
  65. if ($isTutor) {
  66. $allowToEdit = true;
  67. }
  68. }
  69. }
  70. /* Tracking */
  71. Event::event_access_tool(TOOL_ANNOUNCEMENT);
  72. $announcement_id = isset($_GET['id']) ? intval($_GET['id']) : null;
  73. $action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : 'list';
  74. $announcement_number = AnnouncementManager::getNumberAnnouncements();
  75. $homeUrl = api_get_self().'?action=list&'.api_get_cidreq();
  76. $content = '';
  77. $searchFormToString = '';
  78. switch ($action) {
  79. case 'move':
  80. if (!$allowToEdit) {
  81. api_not_allowed(true);
  82. }
  83. /* Move announcement up/down */
  84. if (!empty($_GET['down'])) {
  85. $thisAnnouncementId = intval($_GET['down']);
  86. $sortDirection = "DESC";
  87. }
  88. if (!empty($_GET['up'])) {
  89. $thisAnnouncementId = intval($_GET['up']);
  90. $sortDirection = "ASC";
  91. }
  92. if (!empty($sortDirection)) {
  93. if (!in_array(trim(strtoupper($sortDirection)), ['ASC', 'DESC'])) {
  94. $sortDirection = 'ASC';
  95. }
  96. $announcementInfo = AnnouncementManager::get_by_id($courseId, $thisAnnouncementId);
  97. $sql = "SELECT DISTINCT announcement.id, announcement.display_order
  98. FROM $tbl_announcement announcement,
  99. $tbl_item_property itemproperty
  100. WHERE
  101. announcement.c_id = $courseId AND
  102. itemproperty.c_id = $courseId AND
  103. itemproperty.ref = announcement.id AND
  104. itemproperty.tool = '".TOOL_ANNOUNCEMENT."' AND
  105. itemproperty.visibility <> 2
  106. ORDER BY display_order $sortDirection";
  107. $result = Database::query($sql);
  108. $thisAnnouncementOrderFound = false;
  109. $thisAnnouncementOrder = null;
  110. while (list($announcementId, $announcementOrder) = Database::fetch_row($result)) {
  111. if ($thisAnnouncementOrderFound) {
  112. $nextAnnouncementId = $announcementId;
  113. $nextAnnouncementOrder = $announcementOrder;
  114. $sql = "UPDATE $tbl_announcement SET display_order = '$nextAnnouncementOrder'
  115. WHERE c_id = $courseId AND id = $thisAnnouncementId";
  116. Database::query($sql);
  117. $sql = "UPDATE $tbl_announcement SET display_order = '$thisAnnouncementOrder'
  118. WHERE c_id = $courseId AND id = $nextAnnouncementId";
  119. Database::query($sql);
  120. break;
  121. }
  122. // STEP 1 : FIND THE ORDER OF THE ANNOUNCEMENT
  123. if ($announcementId == $thisAnnouncementId) {
  124. $thisAnnouncementOrder = $announcementOrder;
  125. $thisAnnouncementOrderFound = true;
  126. }
  127. }
  128. Display::addFlash(Display::return_message(get_lang('AnnouncementMoved')));
  129. header('Location: '.$homeUrl);
  130. exit;
  131. }
  132. break;
  133. case 'view':
  134. $interbreadcrumb[] = [
  135. "url" => api_get_path(WEB_CODE_PATH).'announcements/announcements.php?'.api_get_cidreq(),
  136. "name" => $nameTools,
  137. ];
  138. $nameTools = get_lang('View');
  139. $content = AnnouncementManager::displayAnnouncement($announcement_id);
  140. break;
  141. case 'list':
  142. $htmlHeadXtra[] = api_get_jqgrid_js();
  143. $searchForm = new FormValidator(
  144. 'search_simple',
  145. 'post',
  146. api_get_self().'?'.api_get_cidreq(),
  147. '',
  148. [],
  149. FormValidator::LAYOUT_INLINE
  150. );
  151. $searchForm->addElement('text', 'keyword', get_lang('Title'));
  152. $users = CourseManager::get_user_list_from_course_code(api_get_course_id(), $sessionId);
  153. $userList = ['' => ''];
  154. if (!empty($users)) {
  155. foreach ($users as $user) {
  156. $userList[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']);
  157. }
  158. }
  159. $users = [];
  160. $searchForm->addElement('select', 'user_id', get_lang('Users'), $userList);
  161. $searchForm->addButtonSearch(get_lang('Search'));
  162. $filterData = [];
  163. $keyword = '';
  164. $userIdToSearch = 0;
  165. if ($searchForm->validate()) {
  166. $filterData = $searchForm->getSubmitValues();
  167. $keyword = $filterData['keyword'];
  168. $userIdToSearch = $filterData['user_id'];
  169. }
  170. // jqgrid will use this URL to do the selects
  171. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_course_announcements&'.api_get_cidreq().'&title_to_search='.$keyword.'&user_id_to_search='.$userIdToSearch;
  172. $deleteUrl = api_get_path(WEB_AJAX_PATH).'announcement.ajax.php?a=delete_item&'.api_get_cidreq();
  173. $columns = [
  174. get_lang('Title'),
  175. get_lang('By'),
  176. get_lang('LastUpdateDate'),
  177. get_lang('Actions'),
  178. ];
  179. // Column config
  180. $columnModel = [
  181. [
  182. 'name' => 'title',
  183. 'index' => 'title',
  184. 'width' => '300',
  185. 'align' => 'left',
  186. 'sortable' => 'false',
  187. ],
  188. [
  189. 'name' => 'username',
  190. 'index' => 'username',
  191. 'width' => '100',
  192. 'align' => 'left',
  193. 'sortable' => 'false',
  194. ],
  195. [
  196. 'name' => 'lastedit_date',
  197. 'index' => 'lastedit_date',
  198. 'width' => '200',
  199. 'align' => 'left',
  200. 'sortable' => 'false',
  201. ],
  202. [
  203. 'name' => 'actions',
  204. 'index' => 'actions',
  205. 'width' => '150',
  206. 'align' => 'left',
  207. //'formatter' => 'action_formatter',
  208. 'sortable' => 'false',
  209. ],
  210. ];
  211. // Autowidth
  212. $extra_params['autowidth'] = 'true';
  213. // height auto
  214. $extra_params['height'] = 'auto';
  215. $editOptions = '';
  216. if (api_is_allowed_to_edit() || $isTutor) {
  217. $extra_params['multiselect'] = true;
  218. $editOptions = '
  219. $("#announcements").jqGrid(
  220. "navGrid",
  221. "#announcements_pager",
  222. { edit: false, add: false, del: true },
  223. { height:280, reloadAfterSubmit:false }, // edit options
  224. { height:280, reloadAfterSubmit:false }, // add options
  225. { reloadAfterSubmit:false, url: "'.$deleteUrl.'" }, // del options
  226. { width:500 } // search options
  227. );
  228. ';
  229. }
  230. $content = '<script>
  231. $(function() {'.
  232. Display::grid_js(
  233. 'announcements',
  234. $url,
  235. $columns,
  236. $columnModel,
  237. $extra_params,
  238. [],
  239. '',
  240. true
  241. ).$editOptions.'
  242. });
  243. </script>';
  244. $count = AnnouncementManager::getAnnouncements(
  245. $token,
  246. $announcement_number,
  247. true
  248. );
  249. if (empty($count)) {
  250. $html = '';
  251. if ($allowToEdit && (empty($_GET['origin']) || $_GET['origin'] !== 'learnpath')) {
  252. $html .= '<div id="no-data-view">';
  253. $html .= '<h3>'.get_lang('Announcements').'</h3>';
  254. $html .= Display::return_icon('valves.png', '', [], 64);
  255. $html .= '<div class="controls">';
  256. $html .= Display::url(
  257. get_lang('AddAnnouncement'),
  258. api_get_self()."?".api_get_cidreq()."&action=add",
  259. ['class' => 'btn btn-primary']
  260. );
  261. $html .= '</div>';
  262. $html .= '</div>';
  263. } else {
  264. $html = Display::return_message(get_lang('NoAnnouncements'), 'warning');
  265. }
  266. $content = $html;
  267. } else {
  268. $content .= Display::grid_html('announcements');
  269. }
  270. break;
  271. case 'delete':
  272. /* Delete announcement */
  273. $id = intval($_GET['id']);
  274. if ($sessionId != 0 && api_is_allowed_to_session_edit(false, true) == false) {
  275. api_not_allowed();
  276. }
  277. if (!api_is_session_general_coach() || api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $id)) {
  278. AnnouncementManager::delete_announcement($_course, $id);
  279. Display::addFlash(Display::return_message(get_lang('AnnouncementDeleted')));
  280. }
  281. header('Location: '.$homeUrl);
  282. exit;
  283. break;
  284. case 'delete_all':
  285. if (api_is_allowed_to_edit()) {
  286. $allow = api_get_configuration_value('disable_delete_all_announcements');
  287. if ($allow === false) {
  288. AnnouncementManager::delete_all_announcements($_course);
  289. Display::addFlash(Display::return_message(get_lang('AnnouncementDeletedAll')));
  290. }
  291. header('Location: '.$homeUrl);
  292. exit;
  293. }
  294. break;
  295. case 'delete_attachment':
  296. $id = $_GET['id_attach'];
  297. if (api_is_allowed_to_edit()) {
  298. AnnouncementManager::delete_announcement_attachment_file($id);
  299. }
  300. header('Location: '.$homeUrl);
  301. exit;
  302. break;
  303. case 'showhide':
  304. if (!isset($_GET['isStudentView']) || $_GET['isStudentView'] != 'false') {
  305. if (isset($_GET['id']) && $_GET['id']) {
  306. if ($sessionId != 0 &&
  307. api_is_allowed_to_session_edit(false, true) == false
  308. ) {
  309. api_not_allowed();
  310. }
  311. if (!$allowToEdit) {
  312. api_not_allowed(true);
  313. }
  314. if (!api_is_session_general_coach() ||
  315. api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $_GET['id'])
  316. ) {
  317. AnnouncementManager::change_visibility_announcement(
  318. $_course,
  319. $_GET['id']
  320. );
  321. Display::addFlash(Display::return_message(get_lang('VisibilityChanged')));
  322. header('Location: '.$homeUrl);
  323. exit;
  324. }
  325. }
  326. }
  327. break;
  328. case 'add':
  329. case 'modify':
  330. if ($sessionId != 0 &&
  331. api_is_allowed_to_session_edit(false, true) == false
  332. ) {
  333. api_not_allowed(true);
  334. }
  335. if (!$allowToEdit) {
  336. api_not_allowed(true);
  337. }
  338. // DISPLAY ADD ANNOUNCEMENT COMMAND
  339. $id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
  340. $url = api_get_self().'?action='.$action.'&id='.$id.'&'.api_get_cidreq();
  341. $form = new FormValidator(
  342. 'f1',
  343. 'post',
  344. $url,
  345. null,
  346. ['enctype' => 'multipart/form-data']
  347. );
  348. $form_name = get_lang('ModifyAnnouncement');
  349. if (empty($id)) {
  350. $form_name = get_lang('AddAnnouncement');
  351. }
  352. $interbreadcrumb[] = [
  353. 'url' => api_get_path(WEB_CODE_PATH).'announcements/announcements.php?'.api_get_cidreq(),
  354. 'name' => $nameTools,
  355. ];
  356. $nameTools = $form_name;
  357. $form->addHeader($form_name);
  358. $form->addButtonAdvancedSettings(
  359. 'choose_recipients',
  360. [get_lang('ChooseRecipients')]
  361. );
  362. $form->addHtml('<div id="choose_recipients_options" style="display:none;">');
  363. $to = [];
  364. if (empty($group_id)) {
  365. if (isset($_GET['remind_inactive'])) {
  366. $email_ann = '1';
  367. $content_to_modify = sprintf(
  368. get_lang('RemindInactiveLearnersMailContent'),
  369. api_get_setting('siteName'),
  370. 7
  371. );
  372. $title_to_modify = sprintf(
  373. get_lang('RemindInactiveLearnersMailSubject'),
  374. api_get_setting('siteName')
  375. );
  376. } elseif (isset($_GET['remindallinactives']) && $_GET['remindallinactives'] === 'true') {
  377. // we want to remind inactive users. The $_GET['since'] parameter
  378. // determines which users have to be warned (i.e the users who have been inactive for x days or more
  379. $since = isset($_GET['since']) ? (int) $_GET['since'] : 6;
  380. // Getting the users who have to be reminded
  381. $to = Tracking::getInactiveStudentsInCourse(
  382. api_get_course_int_id(),
  383. $since,
  384. $sessionId
  385. );
  386. // setting the variables for the form elements: the users who need to receive the message
  387. foreach ($to as &$user) {
  388. $user = 'USER:'.$user;
  389. }
  390. // setting the variables for the form elements: the message has to be sent by email
  391. $email_ann = '1';
  392. // setting the variables for the form elements: the title of the email
  393. $title_to_modify = sprintf(
  394. get_lang('RemindInactiveLearnersMailSubject'),
  395. api_get_setting('siteName')
  396. );
  397. // setting the variables for the form elements: the message of the email
  398. $content_to_modify = sprintf(
  399. get_lang('RemindInactiveLearnersMailContent'),
  400. api_get_setting('siteName'),
  401. $since
  402. );
  403. // when we want to remind the users who have never been active
  404. // then we have a different subject and content for the announcement
  405. if ($_GET['since'] == 'never') {
  406. $title_to_modify = sprintf(
  407. get_lang('RemindInactiveLearnersMailSubject'),
  408. api_get_setting('siteName')
  409. );
  410. $content_to_modify = get_lang(
  411. 'YourAccountIsActiveYouCanLoginAndCheckYourCourses'
  412. );
  413. }
  414. }
  415. $element = CourseManager::addUserGroupMultiSelect($form, []);
  416. } else {
  417. $element = CourseManager::addGroupMultiSelect($form, $groupProperties, []);
  418. }
  419. $form->addHtml('</div>');
  420. $form->addCheckBox('email_ann', '', get_lang('EmailOption'));
  421. if (!isset($announcement_to_modify)) {
  422. $announcement_to_modify = '';
  423. }
  424. $announcementInfo = AnnouncementManager::get_by_id($courseId, $id);
  425. if (isset($announcementInfo) && !empty($announcementInfo)) {
  426. $to = AnnouncementManager::load_edit_users('announcement', $id);
  427. $defaults = [
  428. 'title' => $announcementInfo['title'],
  429. 'content' => $announcementInfo['content'],
  430. 'id' => $announcementInfo['id'],
  431. 'users' => $to,
  432. ];
  433. } else {
  434. $defaults = [];
  435. if (!empty($to)) {
  436. $defaults['users'] = $to;
  437. }
  438. }
  439. if (isset($defaults['users'])) {
  440. foreach ($defaults['users'] as $value) {
  441. $parts = explode(':', $value);
  442. if (!isset($parts[1]) || empty($parts[1])) {
  443. continue;
  444. }
  445. $form->addHtml("
  446. <script>
  447. $(document).on('ready', function () {
  448. $('#choose_recipients').click();
  449. });
  450. </script>
  451. ");
  452. break;
  453. }
  454. }
  455. $defaults['email_ann'] = true;
  456. $form->addElement(
  457. 'text',
  458. 'title',
  459. get_lang('EmailTitle'),
  460. ['onkeypress' => 'return event.keyCode != 13;']
  461. );
  462. $form->addRule('title', get_lang('ThisFieldIsRequired'), 'required');
  463. $form->addElement('hidden', 'id');
  464. $htmlTags = '';
  465. $tags = AnnouncementManager::getTags();
  466. foreach ($tags as $tag) {
  467. $htmlTags .= "<b>$tag</b><br />";
  468. }
  469. $form->addButtonAdvancedSettings('tags', get_lang('Tags'));
  470. $form->addElement('html', '<div id="tags_options" style="display:none">');
  471. $form->addLabel('', Display::return_message($htmlTags, 'normal', false));
  472. $form->addElement('html', '</div>');
  473. $form->addHtmlEditor(
  474. 'content',
  475. get_lang('Description'),
  476. true,
  477. false,
  478. ['ToolbarSet' => 'Announcements']
  479. );
  480. $form->addElement('file', 'user_upload', get_lang('AddAnAttachment'));
  481. $form->addElement('textarea', 'file_comment', get_lang('FileComment'));
  482. $form->addHidden('sec_token', $token);
  483. if (empty($sessionId)) {
  484. $form->addCheckBox('send_to_users_in_session', null, get_lang('SendToUsersInSessions'));
  485. }
  486. $config = api_get_configuration_value('announcements_hide_send_to_hrm_users');
  487. if ($config === false) {
  488. $form->addCheckBox('send_to_hrm_users', null, get_lang('SendAnnouncementCopyToDRH'));
  489. }
  490. $form->addButtonSave(get_lang('ButtonPublishAnnouncement'));
  491. $form->setDefaults($defaults);
  492. if ($form->validate()) {
  493. $data = $form->getSubmitValues();
  494. $data['users'] = isset($data['users']) ? $data['users'] : [];
  495. $sendToUsersInSession = isset($data['send_to_users_in_session']) ? true : false;
  496. if (isset($id) && $id) {
  497. // there is an Id => the announcement already exists => update mode
  498. if (Security::check_token('post')) {
  499. $file_comment = $_POST['file_comment'];
  500. $file = $_FILES['user_upload'];
  501. AnnouncementManager::edit_announcement(
  502. $id,
  503. $data['title'],
  504. $data['content'],
  505. $data['users'],
  506. $file,
  507. $file_comment,
  508. $sendToUsersInSession
  509. );
  510. // Send mail
  511. if (isset($_POST['email_ann']) && empty($_POST['onlyThoseMails'])) {
  512. AnnouncementManager::sendEmail(
  513. api_get_course_info(),
  514. api_get_session_id(),
  515. $id,
  516. $sendToUsersInSession,
  517. isset($data['send_to_hrm_users'])
  518. );
  519. }
  520. Display::addFlash(
  521. Display::return_message(
  522. get_lang('AnnouncementModified'),
  523. 'success'
  524. )
  525. );
  526. Security::clear_token();
  527. header('Location: '.$homeUrl);
  528. exit;
  529. }
  530. } else {
  531. // Insert mode
  532. if (Security::check_token('post')) {
  533. $file = $_FILES['user_upload'];
  534. $file_comment = $data['file_comment'];
  535. if (empty($group_id)) {
  536. $insert_id = AnnouncementManager::add_announcement(
  537. api_get_course_info(),
  538. api_get_session_id(),
  539. $data['title'],
  540. $data['content'],
  541. $data['users'],
  542. $file,
  543. $file_comment,
  544. null,
  545. $sendToUsersInSession
  546. );
  547. } else {
  548. $insert_id = AnnouncementManager::add_group_announcement(
  549. $data['title'],
  550. $data['content'],
  551. ['GROUP:'.$group_id],
  552. $data['users'],
  553. $file,
  554. $file_comment,
  555. $sendToUsersInSession
  556. );
  557. }
  558. if ($insert_id) {
  559. Display::addFlash(
  560. Display::return_message(
  561. get_lang('AnnouncementAdded'),
  562. 'success'
  563. )
  564. );
  565. // Send mail
  566. if (isset($data['email_ann']) && $data['email_ann']) {
  567. AnnouncementManager::sendEmail(
  568. api_get_course_info(),
  569. api_get_session_id(),
  570. $insert_id,
  571. $sendToUsersInSession
  572. );
  573. }
  574. Security::clear_token();
  575. header('Location: '.$homeUrl);
  576. exit;
  577. }
  578. api_not_allowed(true);
  579. } // end condition token
  580. }
  581. }
  582. $content = $form->returnForm();
  583. break;
  584. }
  585. if (!empty($_GET['remind_inactive'])) {
  586. $to[] = 'USER:'.intval($_GET['remind_inactive']);
  587. }
  588. if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath') {
  589. // We are not in the learning path
  590. Display::display_header($nameTools, get_lang('Announcements'));
  591. }
  592. // Tool introduction
  593. if (empty($_GET['origin']) || $_GET['origin'] !== 'learnpath') {
  594. Display::display_introduction_section(TOOL_ANNOUNCEMENT);
  595. }
  596. // Actions
  597. $show_actions = false;
  598. $actionsLeft = '';
  599. if ($allowToEdit && (empty($_GET['origin']) || $_GET['origin'] !== 'learnpath')) {
  600. if (in_array($action, ['add', 'modify', 'view'])) {
  601. $actionsLeft .= "<a href='".api_get_self()."?".api_get_cidreq()."'>".
  602. Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).
  603. "</a>";
  604. } else {
  605. $actionsLeft .= "<a href='".api_get_self()."?".api_get_cidreq()."&action=add'>".
  606. Display::return_icon('new_announce.png', get_lang('AddAnnouncement'), '', ICON_SIZE_MEDIUM).
  607. "</a>";
  608. }
  609. $show_actions = true;
  610. } else {
  611. if (in_array($action, ['view'])) {
  612. $actionsLeft .= "<a href='".api_get_self()."?".api_get_cidreq()."'>".
  613. Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM)."</a>";
  614. }
  615. }
  616. if ($allowToEdit && api_get_group_id() == 0) {
  617. $allow = api_get_configuration_value('disable_delete_all_announcements');
  618. if ($allow === false) {
  619. if (!isset($_GET['action']) ||
  620. isset($_GET['action']) && $_GET['action'] == 'list'
  621. ) {
  622. $actionsLeft .= "<a href=\"".api_get_self()."?".api_get_cidreq()."&action=delete_all\" onclick=\"javascript:if(!confirm('".get_lang("ConfirmYourChoice")."')) return false;\">".
  623. Display::return_icon(
  624. 'delete_announce.png',
  625. get_lang('AnnouncementDeleteAll'),
  626. '',
  627. ICON_SIZE_MEDIUM
  628. )."</a>";
  629. }
  630. }
  631. }
  632. if ($show_actions) {
  633. echo Display::toolbarAction('toolbar', [$actionsLeft, $searchFormToString]);
  634. }
  635. echo $content;
  636. if (empty($_GET['origin']) || $_GET['origin'] !== 'learnpath') {
  637. //we are not in learnpath tool
  638. Display::display_footer();
  639. }