announcements.php 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217
  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. * @todo make AWACS out of the configuration settings
  13. * @todo this file is 1300+ lines without any functions -> needs to be split into
  14. * multiple functions
  15. */
  16. /*
  17. INIT SECTION
  18. */
  19. // name of the language file that needs to be included
  20. use \ChamiloSession as Session;
  21. $language_file = array('announcements', 'group', 'survey', 'document');
  22. // use anonymous mode when accessing this course tool
  23. $use_anonymous = true;
  24. // setting the global file that gets the general configuration, the databases, the languages, ...
  25. require_once '../inc/global.inc.php';
  26. $showImg = Display::return_icon('div_show.gif');
  27. $hideImg = Display::return_icon('div_hide.gif');
  28. $htmlHeadXtra[] = "
  29. <script>
  30. function plus_attachment() {
  31. 'use strict';
  32. if (document.getElementById('options').style.display == 'none') {
  33. document.getElementById('options').style.display = 'block';
  34. document.getElementById('plus').innerHTML = '&nbsp;".$hideImg."&nbsp;' + lang.AddAnAttachment;
  35. } else {
  36. document.getElementById('options').style.display = 'none';
  37. document.getElementById('plus').innerHTML = '&nbsp;".$showImg."&nbsp;' + lang.AddAnAttachment;
  38. }
  39. }
  40. </script>";
  41. /* Sessions */
  42. $ctok = Security::getCurrentToken();
  43. $stok = Security::get_token();
  44. $current_course_tool = TOOL_ANNOUNCEMENT;
  45. $this_section = SECTION_COURSES;
  46. $nameTools = get_lang('ToolAnnouncement');
  47. //session
  48. if (isset($_GET['id_session'])) {
  49. $_SESSION['id_session'] = intval($_GET['id_session']);
  50. }
  51. /* ACCESS RIGHTS */
  52. api_protect_course_script(true);
  53. // Configuration settings
  54. $display_announcement_list = true;
  55. $display_form = false;
  56. $display_title_list = true;
  57. // Maximum title messages to display
  58. $maximum = '12';
  59. // Database Table Definitions
  60. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
  61. $tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
  62. /* Libraries */
  63. $course_id = api_get_course_int_id();
  64. /* Tracking */
  65. event_access_tool(TOOL_ANNOUNCEMENT);
  66. /* POST TO */
  67. $safe_emailTitle = isset($_POST['emailTitle']) ? $_POST['emailTitle'] : null;
  68. $safe_newContent = isset($_POST['newContent']) ? $_POST['newContent'] : null;
  69. $content_to_modify = $title_to_modify = '';
  70. if (!empty($_POST['To'])) {
  71. if (api_get_session_id() != 0 && api_is_allowed_to_session_edit(false, true) == false) {
  72. api_not_allowed(true);
  73. }
  74. $display_form = true;
  75. $form_elements = array(
  76. 'emailTitle' => $safe_emailTitle,
  77. 'newContent' => $safe_newContent,
  78. 'id' => $_POST['id'],
  79. 'emailoption' => $_POST['email_ann']
  80. );
  81. $_SESSION['formelements'] = $form_elements;
  82. $form_elements = $_SESSION['formelements'];
  83. $title_to_modify = $form_elements["emailTitle"];
  84. $content_to_modify = $form_elements["newContent"];
  85. $announcement_to_modify = $form_elements["id"];
  86. }
  87. /*
  88. Show/hide user/group form
  89. */
  90. $setting_select_groupusers = true;
  91. if (empty($_POST['To']) and !$_SESSION['select_groupusers']) {
  92. $_SESSION['select_groupusers'] = "hide";
  93. }
  94. $select_groupusers_status = $_SESSION['select_groupusers'];
  95. if (!empty($_POST['To']) and ($select_groupusers_status == "hide")) {
  96. $_SESSION['select_groupusers'] = "show";
  97. }
  98. if (!empty($_POST['To']) and ($select_groupusers_status == "show")) {
  99. $_SESSION['select_groupusers'] = "hide";
  100. }
  101. $origin = empty($_GET['origin']) ? '' : Security::remove_XSS($_GET['origin']);
  102. /* Action handling */
  103. // display the form
  104. if (((!empty($_GET['action']) && $_GET['action'] == 'add') && $_GET['origin'] == "") || (!empty($_GET['action']) && $_GET['action'] == 'edit') || !empty($_POST['To'])) {
  105. if (api_get_session_id() != 0 && api_is_allowed_to_session_edit(false, true) == false) {
  106. api_not_allowed(true);
  107. }
  108. $display_form = true;
  109. }
  110. // clear all resources
  111. if ((empty($originalresource) || ($originalresource !== 'no')) and (!empty($action) && $action == 'add')) {
  112. $_SESSION['formelements'] = null;
  113. }
  114. $htmlHeadXtra[] = AnnouncementManager::to_javascript();
  115. /* Filter user/group */
  116. $group_id = api_get_group_id();
  117. if (!empty($group_id)) {
  118. $_SESSION['select_groupusers'] = 'hide';
  119. }
  120. $to = null;
  121. $email_ann = null;
  122. if (!empty($_SESSION['formelements']) and !empty($_GET['originalresource']) and $_GET['originalresource'] == 'no') {
  123. $form_elements = $_SESSION['formelements'];
  124. $title_to_modify = $form_elements['emailTitle'];
  125. $content_to_modify = $form_elements['newContent'];
  126. $announcement_to_modify = $form_elements['id'];
  127. $to = $form_elements['to'];
  128. $email_ann = $form_elements['emailoption'];
  129. }
  130. if (!empty($_GET['remind_inactive'])) {
  131. $to[] = 'USER:'.intval($_GET['remind_inactive']);
  132. }
  133. $group_id = api_get_group_id();
  134. if (!empty($group_id)) {
  135. $group_properties = GroupManager :: get_group_properties($group_id);
  136. $interbreadcrumb[] = array("url" => "../group/group.php", "name" => get_lang('Groups'));
  137. $interbreadcrumb[] = array(
  138. "url" => "../group/group_space.php?gidReq=".$group_id,
  139. "name" => get_lang('GroupSpace').' '.$group_properties['name']
  140. );
  141. }
  142. $announcement_id = isset($_GET['id']) ? intval($_GET['id']) : null;
  143. $message = null;
  144. if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath') {
  145. //we are not in the learning path
  146. Display::display_header($nameTools, get_lang('Announcements'));
  147. }
  148. if (AnnouncementManager::user_can_edit_announcement()) {
  149. /*
  150. Change visibility of announcement
  151. */
  152. // change visibility -> studentview -> course manager view
  153. if (!isset($_GET['isStudentView']) || $_GET['isStudentView'] != 'false') {
  154. if (isset($_GET['id']) AND $_GET['id'] AND isset($_GET['action']) AND $_GET['action'] == "showhide") {
  155. if (api_get_session_id() != 0 && api_is_allowed_to_session_edit(false, true) == false) {
  156. api_not_allowed();
  157. }
  158. if (!api_is_course_coach() || api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $_GET['id'])) {
  159. if ($ctok == $_GET['sec_token']) {
  160. AnnouncementManager::change_visibility_announcement($_course, $_GET['id']);
  161. $message = get_lang('VisibilityChanged');
  162. }
  163. }
  164. }
  165. }
  166. /*
  167. Delete announcement
  168. */
  169. if (!empty($_GET['action']) && $_GET['action'] == 'delete' && isset($_GET['id'])) {
  170. $id = intval($_GET['id']);
  171. if (api_get_session_id() != 0 && api_is_allowed_to_session_edit(false, true) == false) {
  172. api_not_allowed();
  173. }
  174. if (!api_is_course_coach() || api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $id)) {
  175. // tooledit : visibility = 2 : only visible for platform administrator
  176. if ($ctok == $_GET['sec_token']) {
  177. AnnouncementManager::delete_announcement($_course, $id);
  178. $id = null;
  179. $emailTitle = null;
  180. $newContent = null;
  181. $message = get_lang('AnnouncementDeleted');
  182. }
  183. }
  184. }
  185. //delete attachment file
  186. if (isset($_GET['action']) && $_GET['action'] == 'delete_attachment') {
  187. $id = $_GET['id_attach'];
  188. if ($ctok == $_GET['sec_token']) {
  189. if (api_is_allowed_to_edit()) {
  190. AnnouncementManager::delete_announcement_attachment_file($id);
  191. }
  192. }
  193. }
  194. /*
  195. Delete all announcements
  196. */
  197. if (!empty($_GET['action']) and $_GET['action'] == 'delete_all') {
  198. if (api_is_allowed_to_edit()) {
  199. AnnouncementManager::delete_all_announcements($_course);
  200. $id = null;
  201. $emailTitle = null;
  202. $newContent = null;
  203. $message = get_lang('AnnouncementDeletedAll');
  204. }
  205. }
  206. /*
  207. Modify announcement
  208. */
  209. if (!empty($_GET['action']) and $_GET['action'] == 'modify' AND isset($_GET['id'])) {
  210. if (api_get_session_id() != 0 && api_is_allowed_to_session_edit(false, true) == false) {
  211. api_not_allowed();
  212. }
  213. $display_form = true;
  214. // RETRIEVE THE CONTENT OF THE ANNOUNCEMENT TO MODIFY
  215. $id = intval($_GET['id']);
  216. if (!api_is_course_coach() || api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $id)) {
  217. $sql = "SELECT * FROM $tbl_announcement WHERE c_id = $course_id AND id = '$id'";
  218. $rs = Database::query($sql);
  219. $myrow = Database::fetch_array($rs);
  220. $last_id = $id;
  221. $edit_attachment = AnnouncementManager::edit_announcement_attachment_file(
  222. $last_id,
  223. $_FILES['user_upload'],
  224. $file_comment
  225. );
  226. if ($myrow) {
  227. $announcement_to_modify = $myrow['id'];
  228. $content_to_modify = $myrow['content'];
  229. $title_to_modify = $myrow['title'];
  230. if ($originalresource !== "no") {
  231. $to = AnnouncementManager::load_edit_users("announcement", $announcement_to_modify);
  232. }
  233. $display_announcement_list = false;
  234. }
  235. if ($to == "everyone" OR !empty($group_id)) {
  236. $_SESSION['select_groupusers'] = "hide";
  237. } else {
  238. $_SESSION['select_groupusers'] = "show";
  239. }
  240. }
  241. }
  242. /*
  243. Move announcement up/down
  244. */
  245. if (isset($_GET['sec_token']) && $ctok == $_GET['sec_token']) {
  246. if (!empty($_GET['down'])) {
  247. $thisAnnouncementId = intval($_GET['down']);
  248. $sortDirection = "DESC";
  249. }
  250. if (!empty($_GET['up'])) {
  251. $thisAnnouncementId = intval($_GET['up']);
  252. $sortDirection = "ASC";
  253. }
  254. }
  255. if (!empty($sortDirection)) {
  256. if (!in_array(trim(strtoupper($sortDirection)), array('ASC', 'DESC'))) {
  257. $sortDirection = 'ASC';
  258. }
  259. $my_sql = "SELECT announcement.id, announcement.display_order ".
  260. "FROM $tbl_announcement announcement, ".
  261. "$tbl_item_property itemproperty ".
  262. "WHERE
  263. announcement.c_id = $course_id AND
  264. itemproperty.c_id = $course_id AND
  265. itemproperty.ref=announcement.id ".
  266. "AND itemproperty.tool='".TOOL_ANNOUNCEMENT."' ".
  267. "AND itemproperty.visibility<>2 ".
  268. "ORDER BY display_order $sortDirection";
  269. $result = Database::query($my_sql);
  270. $thisAnnouncementOrderFound = false;
  271. $thisAnnouncementOrder = 1;
  272. while (list ($announcementId, $announcementOrder) = Database::fetch_row($result)) {
  273. // STEP 2 : FOUND THE NEXT ANNOUNCEMENT ID AND ORDER.
  274. // COMMIT ORDER SWAP ON THE DB
  275. if ($thisAnnouncementOrderFound) {
  276. $nextAnnouncementId = $announcementId;
  277. $nextAnnouncementOrder = $announcementOrder;
  278. Database::query(
  279. "UPDATE $tbl_announcement SET display_order = '$nextAnnouncementOrder' WHERE c_id = $course_id AND id = '$thisAnnouncementId'"
  280. );
  281. Database::query(
  282. "UPDATE $tbl_announcement SET display_order = '$thisAnnouncementOrder' WHERE c_id = $course_id AND id = '$nextAnnouncementId.'"
  283. );
  284. break;
  285. }
  286. // STEP 1 : FIND THE ORDER OF THE ANNOUNCEMENT
  287. if ($announcementId == $thisAnnouncementId) {
  288. $thisAnnouncementOrder = $announcementOrder;
  289. $thisAnnouncementOrderFound = true;
  290. }
  291. }
  292. // show message
  293. $message = get_lang('AnnouncementMoved');
  294. }
  295. /*
  296. Submit announcement
  297. */
  298. //if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) {
  299. $emailTitle = (!empty($_POST['emailTitle']) ? $safe_emailTitle : '');
  300. $newContent = (!empty($_POST['newContent']) ? $safe_newContent : '');
  301. $submitAnnouncement = isset($_POST['submitAnnouncement']) ? $_POST['submitAnnouncement'] : 0;
  302. $id = 0;
  303. if (!empty($_POST['id'])) {
  304. $id = intval($_POST['id']);
  305. }
  306. if ($submitAnnouncement && empty($emailTitle)) {
  307. $error_message = get_lang('TitleIsRequired');
  308. $content_to_modify = $newContent;
  309. } else {
  310. if ($submitAnnouncement) {
  311. $selected_form = isset($_POST['selectedform']) ? $_POST['selectedform'] : null;
  312. if (isset($id) && $id) {
  313. // there is an Id => the announcement already exists => update mode
  314. if ($ctok == $_POST['sec_token']) {
  315. $file_comment = $_POST['file_comment'];
  316. $file = $_FILES['user_upload'];
  317. AnnouncementManager::edit_announcement(
  318. $id,
  319. $emailTitle,
  320. $newContent,
  321. $selected_form,
  322. $file,
  323. $file_comment
  324. );
  325. /* MAIL FUNCTION */
  326. if ($_POST['email_ann'] && empty($_POST['onlyThoseMails'])) {
  327. AnnouncementManager::send_email($id);
  328. }
  329. $message = get_lang('AnnouncementModified');
  330. }
  331. } else {
  332. //insert mode
  333. if ($ctok == $_REQUEST['sec_token']) {
  334. $file = $_FILES['user_upload'];
  335. $file_comment = $_POST['file_comment'];
  336. if (!empty($group_id)) {
  337. $insert_id = AnnouncementManager::add_group_announcement(
  338. $safe_emailTitle,
  339. $safe_newContent,
  340. array('GROUP:'.$group_id),
  341. $selected_form,
  342. $file,
  343. $file_comment
  344. );
  345. } else {
  346. $insert_id = AnnouncementManager::add_announcement(
  347. $safe_emailTitle,
  348. $safe_newContent,
  349. $selected_form,
  350. $file,
  351. $file_comment
  352. );
  353. }
  354. //store_resources($_SESSION['source_type'],$insert_id);
  355. $_SESSION['select_groupusers'] = "hide";
  356. $message = get_lang('AnnouncementAdded');
  357. /* MAIL FUNCTION */
  358. if (isset($_POST['email_ann']) && $_POST['email_ann'] && empty($_POST['onlyThoseMails'])) {
  359. AnnouncementManager::send_email($insert_id);
  360. }
  361. } // end condition token
  362. } // isset
  363. // UNSET VARIABLES
  364. unset($form_elements);
  365. $_SESSION['formelements'] = null;
  366. $newContent = null;
  367. $emailTitle = null;
  368. unset($emailTitle);
  369. unset($newContent);
  370. unset($content_to_modify);
  371. unset($title_to_modify);
  372. }
  373. } // if $submit Announcement
  374. }
  375. /* Tool introduction */
  376. if (empty($_GET['origin']) || $_GET['origin'] !== 'learnpath') {
  377. Display::display_introduction_section(TOOL_ANNOUNCEMENT);
  378. }
  379. /* DISPLAY LEFT COLUMN */
  380. //condition for the session
  381. $session_id = api_get_session_id();
  382. $condition_session = api_get_session_condition($session_id, true, true);
  383. if (api_is_allowed_to_edit(false, true)) {
  384. // check teacher status
  385. if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath') {
  386. if (api_get_group_id() == 0) {
  387. $group_condition = "";
  388. } else {
  389. $group_condition = " AND (ip.to_group_id='".api_get_group_id()."' OR ip.to_group_id = 0)";
  390. }
  391. $sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
  392. FROM $tbl_announcement announcement, $tbl_item_property ip
  393. WHERE announcement.c_id = $course_id AND
  394. ip.c_id = $course_id AND
  395. announcement.id = ip.ref AND
  396. ip.tool = 'announcement' AND
  397. ip.visibility <> '2'
  398. $group_condition
  399. $condition_session
  400. GROUP BY ip.ref
  401. ORDER BY display_order DESC
  402. LIMIT 0,$maximum";
  403. }
  404. } else {
  405. // students only get to see the visible announcements
  406. if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath') {
  407. $group_memberships = GroupManager::get_group_ids($_course['real_id'], api_get_user_id());
  408. if ((api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) {
  409. if (api_get_group_id() == 0) {
  410. $cond_user_id = " AND (ip.lastedit_user_id = '".api_get_user_id(
  411. )."' OR ( ip.to_user_id='".api_get_user_id()."'".
  412. "OR ip.to_group_id IN (0, ".implode(", ", $group_memberships)."))) ";
  413. } else {
  414. $cond_user_id = " AND (ip.lastedit_user_id = '".api_get_user_id()."'
  415. OR ip.to_group_id IN (0, ".api_get_group_id()."))";
  416. }
  417. } else {
  418. if (api_get_group_id() == 0) {
  419. $cond_user_id = " AND ( ip.to_user_id='".api_get_user_id()."'".
  420. "OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).")) ";
  421. } else {
  422. $cond_user_id = " AND (
  423. (ip.to_user_id='".api_get_user_id()."' AND ip.to_group_id = ".api_get_group_id().") OR
  424. ip.to_group_id IN (".api_get_group_id().") AND ip.to_user_id = 0 ) ";
  425. }
  426. }
  427. // the user is member of several groups => display personal announcements AND his group announcements AND the general announcements
  428. if (is_array($group_memberships) && count($group_memberships) > 0) {
  429. $sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
  430. FROM $tbl_announcement announcement, $tbl_item_property ip
  431. WHERE
  432. announcement.c_id = $course_id AND
  433. ip.c_id = $course_id AND
  434. announcement.id = ip.ref AND
  435. ip.tool='announcement' AND
  436. ip.visibility='1'
  437. $cond_user_id
  438. $condition_session
  439. GROUP BY ip.ref
  440. ORDER BY display_order DESC
  441. LIMIT 0,$maximum";
  442. } else {
  443. // the user is not member of any group
  444. // this is an identified user => show the general announcements AND his personal announcements
  445. if ($_user['user_id']) {
  446. if ((api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) {
  447. $cond_user_id = " AND (ip.lastedit_user_id = '".api_get_user_id(
  448. )."' OR ( ip.to_user_id='".$_user['user_id']."' OR ip.to_group_id='0')) ";
  449. } else {
  450. $cond_user_id = " AND ( ip.to_user_id='".$_user['user_id']."' OR ip.to_group_id='0') ";
  451. }
  452. $sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
  453. FROM $tbl_announcement announcement, $tbl_item_property ip
  454. WHERE
  455. announcement.c_id = $course_id AND
  456. ip.c_id = $course_id AND
  457. announcement.id = ip.ref
  458. AND ip.tool='announcement'
  459. AND ip.visibility='1'
  460. $cond_user_id
  461. $condition_session
  462. GROUP BY ip.ref
  463. ORDER BY display_order DESC
  464. LIMIT 0,$maximum";
  465. } else {
  466. if (api_get_course_setting('allow_user_edit_announcement')) {
  467. $cond_user_id = " AND (ip.lastedit_user_id = '".api_get_user_id()."' OR ip.to_group_id='0') ";
  468. } else {
  469. $cond_user_id = " AND ip.to_group_id='0' ";
  470. }
  471. // the user is not identiefied => show only the general announcements
  472. $sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
  473. FROM $tbl_announcement announcement, $tbl_item_property ip
  474. WHERE
  475. announcement.c_id = $course_id AND
  476. ip.c_id = $course_id AND
  477. announcement.id = ip.ref
  478. AND ip.tool='announcement'
  479. AND ip.visibility='1'
  480. AND ip.to_group_id='0'
  481. $condition_session
  482. GROUP BY ip.ref
  483. ORDER BY display_order DESC
  484. LIMIT 0,$maximum";
  485. }
  486. }
  487. }
  488. }
  489. $result = Database::query($sql);
  490. $announcement_number = Database::num_rows($result);
  491. /*
  492. ADD ANNOUNCEMENT / DELETE ALL
  493. */
  494. $show_actions = false;
  495. if (AnnouncementManager::user_can_edit_announcement()) {
  496. echo '<div class="actions">';
  497. if (isset($_GET['action']) && in_array($_GET['action'], array('add', 'modify', 'view'))) {
  498. echo "<a href='".api_get_self()."?".api_get_cidreq(
  499. )."&origin=".$origin."'>".Display::return_icon(
  500. 'back.png',
  501. get_lang('Back'),
  502. '',
  503. ICON_SIZE_MEDIUM
  504. )."</a>";
  505. } else {
  506. echo "<a href='".api_get_self()."?".api_get_cidreq(
  507. )."&action=add&origin=".$origin."'>".Display::return_icon(
  508. 'new_announce.png',
  509. get_lang('AddAnnouncement'),
  510. '',
  511. ICON_SIZE_MEDIUM
  512. )."</a>";
  513. }
  514. $show_actions = true;
  515. } else {
  516. if (isset($_GET['action']) && in_array($_GET['action'], array('view'))) {
  517. echo '<div class="actions">';
  518. echo "<a href='".api_get_self()."?".api_get_cidreq(
  519. )."&origin=".$origin."'>".Display::return_icon(
  520. 'back.png',
  521. get_lang('Back'),
  522. '',
  523. ICON_SIZE_MEDIUM
  524. )."</a>";
  525. echo '</div>';
  526. }
  527. }
  528. if (api_is_allowed_to_edit() && $announcement_number > 1) {
  529. if ($group_id == 0) {
  530. if (!$show_actions) {
  531. echo '<div class="actions">';
  532. }
  533. if (!isset($_GET['action']) OR !in_array($_GET['action'], array('add', 'modify', 'view'))) {
  534. echo "<a href=\"".api_get_self()."?".api_get_cidreq(
  535. )."&action=delete_all\" onclick=\"javascript:if(!confirm('".get_lang(
  536. "ConfirmYourChoice"
  537. )."')) return false;\">".Display::return_icon(
  538. 'delete_announce.png',
  539. get_lang('AnnouncementDeleteAll'),
  540. '',
  541. ICON_SIZE_MEDIUM
  542. )."</a>";
  543. }
  544. }
  545. }
  546. if ($show_actions) {
  547. echo '</div>';
  548. }
  549. // ANNOUNCEMENTS LIST
  550. if ($message) {
  551. Display::display_confirmation_message($message);
  552. $display_announcement_list = true;
  553. $display_form = false;
  554. }
  555. if (!empty($error_message)) {
  556. Display::display_error_message($error_message);
  557. $display_announcement_list = false;
  558. $display_form = true;
  559. }
  560. /*
  561. DISPLAY FORM
  562. */
  563. if ($display_form) {
  564. $content_to_modify = stripslashes($content_to_modify);
  565. $title_to_modify = stripslashes($title_to_modify);
  566. // DISPLAY ADD ANNOUNCEMENT COMMAND
  567. //echo '<form method="post" name="f1" enctype = "multipart/form-data" action="'.api_get_self().'?publish_survey='.Security::remove_XSS($surveyid).'&id='.Security::remove_XSS($_GET['id']).'&db_name='.$db_name.'&cidReq='.Security::remove_XSS($_GET['cidReq']).'" style="margin:0px;">';
  568. $id = isset($_GET['id']) ? intval($_GET['id']) : 0;
  569. echo '<form class="form-horizontal" method="post" name="f1" enctype = "multipart/form-data" action="'.api_get_self(
  570. ).'?id='.$id.'&'.api_get_cidreq().'" style="margin:0px;">';
  571. if (empty($_GET['id'])) {
  572. $form_name = get_lang('AddAnnouncement');
  573. } else {
  574. $form_name = get_lang('ModifyAnnouncement');
  575. }
  576. echo '<legend>'.$form_name.'</legend>';
  577. //this variable defines if the course administrator can send a message to a specific user / group or not
  578. //@todo use formvalidator
  579. if (empty($group_id)) {
  580. echo '<div class="control-group">
  581. <label class="control-label">'.
  582. Display::return_icon(
  583. 'group.png',
  584. get_lang('ModifyRecipientList'),
  585. array('align' => 'absmiddle'),
  586. ICON_SIZE_SMALL
  587. ).'<a href="#" onclick="toggle_sendto();">'.get_lang('SentTo').'</a>
  588. </label>
  589. <div class="controls">';
  590. if (isset($_GET['id']) && is_array($to)) {
  591. echo '<span id="recipient_overview">&nbsp;</span>';
  592. } elseif (isset($_GET['remind_inactive'])) {
  593. $email_ann = '1';
  594. $_SESSION['select_groupusers'] = "show";
  595. $content_to_modify = sprintf(get_lang('RemindInactiveLearnersMailContent'), api_get_setting('siteName'), 7);
  596. $title_to_modify = sprintf(get_lang('RemindInactiveLearnersMailSubject'), api_get_setting('siteName'));
  597. } elseif (isset($_GET['remindallinactives']) && $_GET['remindallinactives'] == 'true') {
  598. // we want to remind inactive users. The $_GET['since'] parameter determines which users have to be warned (i.e the users who have been inactive for x days or more
  599. $since = isset($_GET['since']) ? intval($_GET['since']) : 6;
  600. // getting the users who have to be reminded
  601. $to = Tracking :: get_inactives_students_in_course(api_get_course_int_id(), $since, api_get_session_id());
  602. // setting the variables for the form elements: the users who need to receive the message
  603. foreach ($to as &$user) {
  604. $user = 'USER:'.$user;
  605. }
  606. // setting the variables for the form elements: the 'visible to' form element has to be expanded
  607. $_SESSION['select_groupusers'] = "show";
  608. // setting the variables for the form elements: the message has to be sent by email
  609. $email_ann = '1';
  610. // setting the variables for the form elements: the title of the email
  611. $title_to_modify = sprintf(get_lang('RemindInactiveLearnersMailSubject'), api_get_setting('siteName'));
  612. // setting the variables for the form elements: the message of the email
  613. $content_to_modify = sprintf(
  614. get_lang('RemindInactiveLearnersMailContent'),
  615. api_get_setting('siteName'),
  616. $since
  617. );
  618. // when we want to remind the users who have never been active then we have a different subject and content for the announcement
  619. if ($_GET['since'] == 'never') {
  620. $title_to_modify = sprintf(get_lang('RemindInactiveLearnersMailSubject'), api_get_setting('siteName'));
  621. $content_to_modify = get_lang('YourAccountIsActiveYouCanLoginAndCheckYourCourses');
  622. }
  623. } else {
  624. echo '<span id="recipient_overview">'.get_lang('Everybody').'</span>';
  625. }
  626. AnnouncementManager::show_to_form($to);
  627. echo ' </div>
  628. </div>';
  629. if (!isset($announcement_to_modify)) {
  630. $announcement_to_modify = '';
  631. }
  632. ($email_ann == '1') ? $checked = 'checked' : $checked = '';
  633. echo ' <div class="control-group">
  634. <div class="controls">
  635. <label class="checkbox" for="email_ann">
  636. <input id="email_ann" class="checkbox" type="checkbox" value="1" name="email_ann" checked> '.get_lang(
  637. 'EmailOption'
  638. ).'</label>
  639. </div>
  640. </div>';
  641. } else {
  642. if (!isset($announcement_to_modify)) {
  643. $announcement_to_modify = "";
  644. }
  645. ($email_ann == '1') ? $checked = 'checked' : $checked = '';
  646. echo '<div class="control-group">
  647. <div class="controls">
  648. <input class="checkbox" type="checkbox" value="1" name="email_ann" '.$checked.'>
  649. '.get_lang('EmailOption').': <span id="recipient_overview">'.Display::label(
  650. get_lang('MyGroup'),
  651. 'success'
  652. ).'</span>
  653. <a href="#" onclick="toggle_sendto();">'.get_lang('ModifyRecipientList').'</a>';
  654. AnnouncementManager::show_to_form_group($group_id, $to);
  655. echo '</div></div>';
  656. }
  657. // the announcement title
  658. echo ' <div class="control-group">
  659. <div id="msg_error" style="display:none;color:red;margin-left:20%"></div>
  660. <label class="control-label">
  661. <span class="form_required">*</span> '.get_lang('EmailTitle').'
  662. </label>
  663. <div class="controls">
  664. <input type="text" id="emailTitle" name="emailTitle" value="'.Security::remove_XSS(
  665. $title_to_modify
  666. ).'" class="span4">
  667. </div>
  668. </div>';
  669. unset($title_to_modify);
  670. $title_to_modify = null;
  671. if (!isset($announcement_to_modify)) {
  672. $announcement_to_modify = "";
  673. }
  674. if (!isset($content_to_modify)) {
  675. $content_to_modify = "";
  676. }
  677. if (!isset($title_to_modify)) {
  678. $title_to_modify = "";
  679. }
  680. echo '<input type="hidden" name="id" value="'.$announcement_to_modify.'" />';
  681. $oFCKeditor = new FCKeditor('newContent');
  682. $oFCKeditor->Width = '100%';
  683. $oFCKeditor->Height = '300';
  684. if (!api_is_allowed_to_edit()) {
  685. $oFCKeditor->ToolbarSet = "AnnouncementsStudent";
  686. } else {
  687. $oFCKeditor->ToolbarSet = "Announcements";
  688. }
  689. $oFCKeditor->Value = $content_to_modify;
  690. echo '<div class="row"><div class="formw">';
  691. echo Display::display_normal_message(
  692. get_lang('Tags').' <br /><br />'.implode('<br />', AnnouncementManager::get_tags()),
  693. false
  694. );
  695. echo $oFCKeditor->CreateHtml();
  696. echo '</div></div>';
  697. //File attachment
  698. echo ' <div class="control-group">
  699. <div class="controls">
  700. <a href="javascript://" onclick="return plus_attachment();"><span id="plus">'.$showImg.'&nbsp;'.get_lang(
  701. 'AddAnAttachment'
  702. ).'</span></a>
  703. <br />
  704. <table id="options" style="display: none;">
  705. <tr>
  706. <td colspan="2">
  707. <label for="file_name">'.get_lang('FileName').'&nbsp;</label>
  708. <input type="file" name="user_upload"/>
  709. </td>
  710. </tr>
  711. <tr>
  712. <td colspan="2">
  713. <label for="comment">'.get_lang('FileComment').'</label><br />
  714. <textarea name="file_comment" rows ="4" cols = "34" ></textarea>
  715. </td>
  716. </tr>
  717. </table>
  718. </div>
  719. </div>';
  720. echo'<br />';
  721. echo '<div class="row"><div class="formw">';
  722. if (empty($group_id)) {
  723. echo '<input type="hidden" name="submitAnnouncement" value="OK">';
  724. echo '<input type="hidden" name="sec_token" value="'.$stok.'" />';
  725. echo '<button class="btn save" type="button" value="'.' '.get_lang(
  726. 'Send'
  727. ).' '.'" onclick="selectAll(this.form.elements[3],true)" >'.get_lang(
  728. 'ButtonPublishAnnouncement'
  729. ).'</button><br /><br />';
  730. } else {
  731. echo '<input type="hidden" name="submitAnnouncement" value="OK">';
  732. echo '<input type="hidden" name="sec_token" value="'.$stok.'" />';
  733. echo '<button class="btn save" type="button" value="'.' '.get_lang(
  734. 'Send'
  735. ).' '.'" onclick="selectAll(this.form.elements[4],true)" >'.get_lang(
  736. 'ButtonPublishAnnouncement'
  737. ).'</button><br /><br />';
  738. }
  739. echo '</div></div>';
  740. echo '</form><br />';
  741. if ((isset($_GET['action']) && isset($_GET['id']) && is_array(
  742. $to
  743. )) || isset($_GET['remindallinactives']) || isset($_GET['remind_inactive'])
  744. ) {
  745. echo '<script>toggle_sendto();</script>';
  746. }
  747. } // displayform
  748. /*
  749. DISPLAY ANNOUNCEMENT LIST
  750. */
  751. if ($display_announcement_list) {
  752. $user_id = api_get_user_id();
  753. $group_id = api_get_group_id();
  754. $group_memberships = GroupManager::get_group_ids($course_id, api_get_user_id());
  755. if (api_is_allowed_to_edit(false, true) OR (api_get_course_setting(
  756. 'allow_user_edit_announcement'
  757. ) && !api_is_anonymous())
  758. ) {
  759. // A.1. you are a course admin with a USER filter
  760. // => see only the messages of this specific user + the messages of the group (s)he is member of.
  761. if (!empty($_SESSION['user'])) {
  762. if (is_array($group_memberships) && count($group_memberships) > 0) {
  763. $sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date
  764. FROM $tbl_announcement announcement, $tbl_item_property ip
  765. WHERE announcement.c_id = $course_id AND
  766. ip.c_id = $course_id AND
  767. announcement.id = ip.ref AND
  768. ip.tool = 'announcement' AND
  769. (ip.to_user_id = $user_id OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") )
  770. $condition_session
  771. ORDER BY display_order DESC";
  772. } else {
  773. $sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date
  774. FROM $tbl_announcement announcement, $tbl_item_property ip
  775. WHERE announcement.c_id = $course_id AND
  776. ip.c_id = $course_id AND
  777. announcement.id = ip.ref AND
  778. ip.tool ='announcement' AND
  779. (ip.to_user_id = $user_id OR ip.to_group_id='0') AND
  780. ip.visibility='1'
  781. $condition_session
  782. ORDER BY display_order DESC";
  783. }
  784. } elseif (api_get_group_id() != 0) {
  785. // A.2. you are a course admin with a GROUP filter
  786. // => see only the messages of this specific group
  787. $sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date
  788. FROM $tbl_announcement announcement, $tbl_item_property ip
  789. WHERE announcement.c_id = $course_id AND
  790. ip.c_id = $course_id AND
  791. announcement.id = ip.ref
  792. AND ip.tool='announcement'
  793. AND ip.visibility<>'2'
  794. AND (ip.to_group_id = $group_id OR ip.to_group_id='0')
  795. $condition_session
  796. GROUP BY ip.ref
  797. ORDER BY display_order DESC";
  798. } else {
  799. // A.3 you are a course admin without any group or user filter
  800. // A.3.a you are a course admin without user or group filter but WITH studentview
  801. // => see all the messages of all the users and groups without editing possibilities
  802. if (isset($isStudentView) and $isStudentView == "true") {
  803. $sql = "SELECT
  804. announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date
  805. FROM $tbl_announcement announcement, $tbl_item_property ip
  806. WHERE announcement.c_id = $course_id AND
  807. ip.c_id = $course_id AND
  808. announcement.id = ip.ref
  809. AND ip.tool='announcement'
  810. AND ip.visibility='1'
  811. $condition_session
  812. GROUP BY ip.ref
  813. ORDER BY display_order DESC";
  814. } else {
  815. // A.3.a you are a course admin without user or group filter and WITHOUT studentview (= the normal course admin view)
  816. // => see all the messages of all the users and groups with editing possibilities
  817. $sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date
  818. FROM $tbl_announcement announcement, $tbl_item_property ip
  819. WHERE announcement.c_id = $course_id AND
  820. ip.c_id = $course_id AND
  821. announcement.id = ip.ref AND
  822. ip.tool='announcement' AND
  823. (ip.visibility='0' or ip.visibility='1') AND
  824. to_group_id = 0
  825. $condition_session
  826. GROUP BY ip.ref
  827. ORDER BY display_order DESC";
  828. }
  829. }
  830. } else {
  831. //STUDENT
  832. if (is_array($group_memberships) && count($group_memberships) > 0) {
  833. if (AnnouncementManager::user_can_edit_announcement()) {
  834. if (api_get_group_id() == 0) {
  835. //No group
  836. $cond_user_id = " AND (ip.lastedit_user_id = '".api_get_user_id(
  837. )."' OR ( ip.to_user_id='".$_user['user_id']."'".
  838. " OR ip.to_group_id IN (0, ".implode(", ", $group_memberships)."))) ";
  839. } else {
  840. $cond_user_id = " AND (
  841. ip.lastedit_user_id = '".api_get_user_id()."' OR
  842. ip.to_group_id IN (".api_get_group_id().")
  843. )";
  844. }
  845. } else {
  846. if (api_get_group_id() == 0) {
  847. $cond_user_id = " AND (ip.to_user_id=$user_id OR ip.to_group_id IN (0, ".implode(
  848. ", ",
  849. $group_memberships
  850. ).")) ";
  851. } else {
  852. $cond_user_id = " AND (
  853. (ip.to_user_id = $user_id AND ip.to_group_id = ".api_get_group_id().") OR
  854. (ip.to_group_id IN (".api_get_group_id().") AND ip.to_user_id = 0 )
  855. )";
  856. }
  857. }
  858. $visibility_condition = " ip.visibility='1'";
  859. if (GroupManager::is_tutor_of_group(api_get_user_id(), $group_id)) {
  860. $visibility_condition = " ip.visibility IN ('0', '1') ";
  861. }
  862. $sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date
  863. FROM $tbl_announcement announcement, $tbl_item_property ip
  864. WHERE announcement.c_id = $course_id AND
  865. ip.c_id = $course_id AND
  866. announcement.id = ip.ref
  867. AND ip.tool='announcement'
  868. $cond_user_id
  869. $condition_session AND $visibility_condition
  870. ORDER BY display_order DESC";
  871. } else {
  872. if ($_user['user_id']) {
  873. if ((api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) {
  874. $cond_user_id = " AND (ip.lastedit_user_id = '".api_get_user_id(
  875. )."' OR (ip.to_user_id='".$_user['user_id']."' OR ip.to_group_id='0')) ";
  876. } else {
  877. $cond_user_id = " AND (ip.to_user_id='".$_user['user_id']."' OR ip.to_group_id='0') ";
  878. }
  879. $sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date
  880. FROM $tbl_announcement announcement, $tbl_item_property ip
  881. WHERE
  882. announcement.c_id = $course_id AND
  883. ip.c_id = $course_id AND
  884. announcement.id = ip.ref AND
  885. ip.tool='announcement'
  886. $cond_user_id
  887. $condition_session
  888. AND ip.visibility='1'
  889. AND announcement.session_id IN(0,".api_get_session_id().")
  890. ORDER BY display_order DESC";
  891. } else {
  892. if ((api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) {
  893. $cond_user_id = " AND (ip.lastedit_user_id = '".api_get_user_id()."' OR ip.to_group_id='0' ) ";
  894. } else {
  895. $cond_user_id = " AND ip.to_group_id='0' ";
  896. }
  897. $sql = "SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date
  898. FROM $tbl_announcement announcement, $tbl_item_property ip
  899. WHERE
  900. announcement.c_id = $course_id AND
  901. ip.c_id = $course_id AND
  902. announcement.id = ip.ref
  903. AND ip.tool='announcement'
  904. $cond_user_id
  905. $condition_session
  906. AND ip.visibility='1'
  907. AND announcement.session_id IN(0,".api_get_session_id().")";
  908. }
  909. }
  910. }
  911. $result = Database::query($sql);
  912. $num_rows = Database::num_rows($result);
  913. // DISPLAY: NO ITEMS
  914. if (!isset($_GET['action']) || !in_array($_GET['action'], array('add', 'modify', 'view'))) {
  915. if ($num_rows == 0) {
  916. if ((api_is_allowed_to_edit(false, true) OR (api_get_course_setting(
  917. 'allow_user_edit_announcement'
  918. ) && !api_is_anonymous())) and (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath')
  919. ) {
  920. echo '<div id="no-data-view">';
  921. echo '<h2>'.get_lang('Announcements').'</h2>';
  922. echo Display::return_icon('valves.png', '', array(), 64);
  923. echo '<div class="controls">';
  924. echo Display::url(
  925. get_lang('AddAnnouncement'),
  926. api_get_self()."?".api_get_cidreq(
  927. )."&action=add&origin=".$origin,
  928. array('class' => 'btn')
  929. );
  930. echo '</div>';
  931. echo '</div>';
  932. } else {
  933. Display::display_warning_message(get_lang('NoAnnouncements'));
  934. }
  935. } else {
  936. $iterator = 1;
  937. $bottomAnnouncement = $announcement_number;
  938. echo '<table width="100%" class="data_table">';
  939. $ths = Display::tag('th', get_lang('Title'));
  940. $ths .= Display::tag('th', get_lang('By'));
  941. $ths .= Display::tag('th', get_lang('LastUpdateDate'));
  942. if (api_is_allowed_to_edit(false, true) OR (api_is_course_coach() && api_is_element_in_the_session(
  943. TOOL_ANNOUNCEMENT,
  944. $myrow['id']
  945. ))
  946. OR (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())
  947. ) {
  948. $ths .= Display::tag('th', get_lang('Modify'));
  949. }
  950. echo Display::tag('tr', $ths);
  951. $displayed = array();
  952. while ($myrow = Database::fetch_array($result, 'ASSOC')) {
  953. if (!in_array($myrow['id'], $displayed)) {
  954. $sent_to_icon = '';
  955. // the email icon
  956. if ($myrow['email_sent'] == '1') {
  957. $sent_to_icon = ' '.Display::return_icon('email.gif', get_lang('AnnounceSentByEmail'));
  958. }
  959. $title = $myrow['title'].$sent_to_icon;
  960. $item_visibility = api_get_item_visibility(
  961. $_course,
  962. TOOL_ANNOUNCEMENT,
  963. $myrow['id'],
  964. $session_id
  965. );
  966. $myrow['visibility'] = $item_visibility;
  967. // the styles
  968. if ($myrow['visibility'] == '0') {
  969. $style = 'invisible';
  970. } else {
  971. $style = '';
  972. }
  973. echo "<tr>";
  974. // show attachment list
  975. $attachment_list = AnnouncementManager::get_attachment($myrow['id']);
  976. $attachment_icon = '';
  977. if (count($attachment_list) > 0) {
  978. $attachment_icon = ' '.Display::return_icon('attachment.gif', get_lang('Attachment'));
  979. }
  980. /* TITLE */
  981. $title = Display::url($title.$attachment_icon, '?action=view&id='.$myrow['id']);
  982. echo Display::tag('td', Security::remove_XSS($title), array('class' => $style));
  983. $user_info = api_get_user_info($myrow['insert_user_id']);
  984. $username = sprintf(get_lang("LoginX"), $user_info['username']);
  985. $username_span = Display::tag(
  986. 'span',
  987. api_get_person_name($user_info['firstName'], $user_info['lastName']),
  988. array('title' => $username)
  989. );
  990. echo Display::tag('td', $username_span);
  991. echo Display::tag(
  992. 'td',
  993. api_convert_and_format_date($myrow['insert_date'], DATE_TIME_FORMAT_LONG)
  994. );
  995. // we can edit if : we are the teacher OR the element belongs to the session we are coaching OR the option to allow users to edit is on
  996. $modify_icons = '';
  997. if (api_is_allowed_to_edit(false, true) OR (api_is_course_coach() && api_is_element_in_the_session(
  998. TOOL_ANNOUNCEMENT,
  999. $myrow['id']
  1000. ))
  1001. OR (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())
  1002. ) {
  1003. $modify_icons = "<a href=\"".api_get_self()."?".api_get_cidreq(
  1004. )."&action=modify&id=".$myrow['id']."\">".Display::return_icon(
  1005. 'edit.png',
  1006. get_lang('Edit'),
  1007. '',
  1008. ICON_SIZE_SMALL
  1009. )."</a>";
  1010. if ($myrow['visibility'] == 1) {
  1011. $image_visibility = "visible";
  1012. $alt_visibility = get_lang('Hide');
  1013. } else {
  1014. $image_visibility = "invisible";
  1015. $alt_visibility = get_lang('Visible');
  1016. }
  1017. $modify_icons .= "<a href=\"".api_get_self()."?".api_get_cidreq(
  1018. )."&origin=".$origin."&action=showhide&id=".$myrow['id']."&sec_token=".$stok."\">".
  1019. Display::return_icon(
  1020. $image_visibility.'.png',
  1021. $alt_visibility,
  1022. '',
  1023. ICON_SIZE_SMALL
  1024. )."</a>";
  1025. // DISPLAY MOVE UP COMMAND only if it is not the top announcement
  1026. if ($iterator != 1) {
  1027. $modify_icons .= "<a href=\"".api_get_self()."?".api_get_cidreq(
  1028. )."&up=".$myrow["id"]."&sec_token=".$stok."\">".Display::return_icon(
  1029. 'up.gif',
  1030. get_lang('Up')
  1031. )."</a>";
  1032. } else {
  1033. $modify_icons .= Display::return_icon('up_na.gif', get_lang('Up'));
  1034. }
  1035. if ($iterator < $bottomAnnouncement) {
  1036. $modify_icons .= "<a href=\"".api_get_self()."?".api_get_cidreq(
  1037. )."&down=".$myrow["id"]."&sec_token=".$stok."\">".Display::return_icon(
  1038. 'down.gif',
  1039. get_lang('Down')
  1040. )."</a>";
  1041. } else {
  1042. $modify_icons .= Display::return_icon('down_na.gif', get_lang('Down'));
  1043. }
  1044. if (api_is_allowed_to_edit(false, true)) {
  1045. $modify_icons .= "<a href=\"".api_get_self()."?".api_get_cidreq(
  1046. )."&action=delete&id=".$myrow['id']."&sec_token=".$stok."\" onclick=\"javascript:if(!confirm('".addslashes(
  1047. api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)
  1048. )."')) return false;\">".
  1049. Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).
  1050. "</a>";
  1051. }
  1052. $iterator++;
  1053. echo Display::tag('td', $modify_icons);
  1054. }
  1055. echo "</tr>";
  1056. }
  1057. $displayed[] = $myrow['id'];
  1058. } // end while
  1059. echo "</table>";
  1060. }
  1061. }
  1062. } // end: if ($displayAnnoucementList)
  1063. if (isset($_GET['action']) && $_GET['action'] == 'view') {
  1064. AnnouncementManager::display_announcement($announcement_id);
  1065. }
  1066. /* FOOTER */
  1067. if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath') {
  1068. //we are not in learnpath tool
  1069. Display::display_footer();
  1070. }