announcements.php 47 KB

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