announcements.php 25 KB

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