announcements.php 42 KB

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