announcements.php 43 KB

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