announcements.php 42 KB

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