announcements.php 43 KB

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