announcements.php 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363
  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. $this_section=SECTION_COURSES;
  26. $nameTools = get_lang('ToolAnnouncement');
  27. //session
  28. if(isset($_GET['id_session'])) {
  29. $_SESSION['id_session'] = intval($_GET['id_session']);
  30. }
  31. /* ACCESS RIGHTS */
  32. // notice for unauthorized people.
  33. api_protect_course_script();
  34. /*
  35. Constants and variables
  36. */
  37. // Configuration settings
  38. $display_announcement_list = true;
  39. $display_form = false;
  40. $display_title_list = true;
  41. // Maximum title messages to display
  42. $maximum = '12';
  43. // Length of the titles
  44. $length = '36';
  45. // Database Table Definitions
  46. $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  47. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  48. $tbl_courses = Database::get_main_table(TABLE_MAIN_COURSE);
  49. $tbl_sessions = Database::get_main_table(TABLE_MAIN_SESSION);
  50. $tbl_session_course_user= Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  51. $tbl_group = Database::get_course_table(TABLE_GROUP);
  52. $tbl_groupUser = Database::get_course_table(TABLE_GROUP_USER);
  53. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
  54. $tbl_announcement_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
  55. $tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
  56. /* Libraries */
  57. $lib = api_get_path(LIBRARY_PATH); //avoid useless function calls
  58. require_once $lib.'groupmanager.lib.php';
  59. require_once $lib.'mail.lib.inc.php';
  60. require_once $lib.'tracking.lib.php';
  61. require_once $lib.'fckeditor/fckeditor.php';
  62. require_once $lib.'fileUpload.lib.php';
  63. require_once 'announcements.inc.php';
  64. /*
  65. Resource linker
  66. $_SESSION['source_type']="Ad_Valvas";
  67. require_once '../resourcelinker/resourcelinker.inc.php';
  68. if (!empty($_POST['addresources'])) {
  69. // When the "Add Resource" button is clicked we store all the form data into a session
  70. $form_elements= array ('emailTitle'=>Security::remove_XSS($emailTitle), 'newContent'=>Security::remove_XSS($newContent), 'id'=>$id, 'to'=>$selectedform, 'emailoption'=>$email_ann);
  71. $_SESSION['formelements']=$form_elements;
  72. if($id) {
  73. // this is to correctly handle edits
  74. $action="edit";
  75. } else {
  76. $action="add";
  77. }
  78. // ============== //
  79. // 7 = Ad_Valvas //
  80. // ============== //
  81. if($surveyid) {
  82. header("Location: ../resourcelinker/resourcelinker.php?source_id=7&action=$action&id=$id&originalresource=no&publish_survey=$surveyid&db_name=$db_name&cidReq=$cidReq");
  83. exit;
  84. } else {
  85. header("Location: ../resourcelinker/resourcelinker.php?source_id=7&action=$action&id=$id&originalresource=no");
  86. exit;
  87. }
  88. exit;
  89. }
  90. */
  91. /* Tracking */
  92. event_access_tool(TOOL_ANNOUNCEMENT);
  93. /* POST TO */
  94. $safe_emailTitle = $_POST['emailTitle'];
  95. $safe_newContent = $_POST['newContent'];
  96. if (!empty($_POST['To'])) {
  97. if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) {
  98. api_not_allowed();
  99. }
  100. $display_form = true;
  101. $form_elements = array ('emailTitle'=>$safe_emailTitle, 'newContent'=>$safe_newContent, 'id'=>$_POST['id'], 'emailoption'=>$_POST['email_ann']);
  102. $_SESSION['formelements'] = $form_elements;
  103. $form_elements = $_SESSION['formelements'];
  104. $title_to_modify = $form_elements["emailTitle"];
  105. $content_to_modify = $form_elements["newContent"];
  106. $announcement_to_modify = $form_elements["id"];
  107. }
  108. /*
  109. Show/hide user/group form
  110. */
  111. $setting_select_groupusers = true;
  112. if (empty($_POST['To']) and !$_SESSION['select_groupusers']) {
  113. $_SESSION['select_groupusers'] = "hide";
  114. }
  115. $select_groupusers_status=$_SESSION['select_groupusers'];
  116. if (!empty($_POST['To']) and ($select_groupusers_status=="hide")) {
  117. $_SESSION['select_groupusers'] = "show";
  118. }
  119. if (!empty($_POST['To']) and ($select_groupusers_status=="show")) {
  120. $_SESSION['select_groupusers'] = "hide";
  121. }
  122. /*
  123. Action handling
  124. */
  125. // display the form
  126. if (((!empty($_GET['action']) && $_GET['action'] == 'add') && $_GET['origin'] == "") || (!empty($_GET['action']) && $_GET['action'] == 'edit') || !empty($_POST['To']))
  127. {
  128. if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) {
  129. api_not_allowed();
  130. }
  131. $display_form = true;
  132. }
  133. // clear all resources
  134. if ((empty($originalresource) || ($originalresource!=='no')) and (!empty($action) && $action=='add')) {
  135. $_SESSION['formelements']=null;
  136. //unset($_SESSION['formelements']);
  137. //unset_session_resources();
  138. }
  139. /*
  140. Javascript
  141. */
  142. $htmlHeadXtra[] = AnnouncementManager::to_javascript();
  143. $htmlHeadXtra[] = '<script type="text/javascript">
  144. function setFocus(){
  145. $("#emailTitle").focus();
  146. }
  147. $(document).ready(function () {
  148. setFocus();
  149. });
  150. </script>';
  151. /* Filter user/group */
  152. if(!empty($_GET['toolgroup'])){
  153. if($_GET['toolgroup'] == strval(intval($_GET['toolgroup']))){ //check is integer
  154. $toolgroup = $_GET['toolgroup'];
  155. $_SESSION['select_groupusers'] = 'hide';
  156. } else {
  157. $toolgroup = 0;
  158. }
  159. api_session_register("toolgroup");
  160. }
  161. /* Sessions */
  162. $ctok = $_SESSION['sec_token'];
  163. $stok = Security::get_token();
  164. if (!empty($_SESSION['formelements']) and !empty($_GET['originalresource']) and $_GET['originalresource'] == 'no') {
  165. $form_elements = $_SESSION['formelements'];
  166. $title_to_modify = $form_elements['emailTitle'];
  167. $content_to_modify = $form_elements['newContent'];
  168. $announcement_to_modify = $form_elements['id'];
  169. $to = $form_elements['to'];
  170. //load_edit_users('announcement',$announcement_to_modify);
  171. $email_ann = $form_elements['emailoption'];
  172. }
  173. if(!empty($_GET['remind_inactive'])) {
  174. $to[] = 'USER:'.intval($_GET['remind_inactive']);
  175. }
  176. /*
  177. //Survey
  178. $surveyid = 0;
  179. if(!empty($_REQUEST['publish_survey'])) {
  180. $surveyid=intval($_REQUEST['publish_survey']);
  181. }
  182. //@todo fix those request values
  183. $cidReq = Database::escape_string($_REQUEST['cidReq']);
  184. if($surveyid) {
  185. $db_name=Database::escape_string($_REQUEST['db_name']);
  186. $sql_temp = "SELECT * FROM $db_name.survey WHERE survey_id='$surveyid'";
  187. $res_temp = Database::query($sql_temp);
  188. $obj=@Database::fetch_object($res_temp);
  189. $template=$obj->template;
  190. }
  191. */
  192. if (!empty($_SESSION['toolgroup'])){
  193. $_clean_toolgroup=intval($_SESSION['toolgroup']);
  194. $group_properties = GroupManager :: get_group_properties($_clean_toolgroup);
  195. $interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups'));
  196. $interbreadcrumb[] = array ("url"=>"../group/group_space.php?gidReq=".$_clean_toolgroup, "name"=> get_lang('GroupSpace').' '.$group_properties['name']);
  197. }
  198. /*
  199. Learning path & css
  200. */
  201. // showing the header if we are not in the learning path, if we are in
  202. // the learning path, we do not include the banner so we have to explicitly
  203. // include the stylesheet, which is normally done in the header
  204. //$display_specific_announcement = true;
  205. $announcement_id = intval($_GET['id']);
  206. $message = null;
  207. if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath') {
  208. //we are not in the learning path
  209. Display::display_header($nameTools,get_lang('Announcements'));
  210. } else {
  211. /*//we are in the learning path, only display central data and change css
  212. $display_title_list = false;
  213. $display_announcement_list = false;
  214. $display_specific_announcement = true;
  215. $announcement_id = $_REQUEST['ann_id'];
  216. ?> <link rel="stylesheet" type="text/css" href="<?php echo api_get_path(WEB_CODE_PATH).'css/'.$my_style; ?>/default.css">
  217. <?php*/
  218. }
  219. // inserting an anchor (top) so one can jump back to the top of the page
  220. //echo "<a name=\"top\"></a>";
  221. /* ACTION HANDLING*/
  222. if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) {
  223. /*
  224. Change visibility of announcement
  225. */
  226. // $_GET['isStudentView']<>"false" is added to prevent that the visibility
  227. // is changed after you do the following:
  228. // change visibility -> studentview -> course manager view
  229. if (!isset($_GET['isStudentView']) || $_GET['isStudentView']!='false') {
  230. if (isset($_GET['id']) AND $_GET['id'] AND isset($_GET['action']) AND $_GET['action']=="showhide") {
  231. if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) {
  232. api_not_allowed();
  233. }
  234. if (!api_is_course_coach() || api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $_GET['id'])) {
  235. if ($ctok == $_GET['sec_token']) {
  236. AnnouncementManager::change_visibility_announcement($_course, $_GET['id']);
  237. $message = get_lang('VisibilityChanged');
  238. }
  239. }
  240. }
  241. }
  242. /*
  243. Delete announcement
  244. */
  245. if (!empty($_GET['action']) && $_GET['action']=='delete' && isset($_GET['id'])) {
  246. //Database::query("DELETE FROM $tbl_announcement WHERE id='$delete'");
  247. $id=intval($_GET['id']);
  248. if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) {
  249. api_not_allowed();
  250. }
  251. if (!api_is_course_coach() || api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $id)) {
  252. // tooledit : visibility = 2 : only visibile for platform administrator
  253. if ($ctok == $_GET['sec_token']) {
  254. AnnouncementManager::delete_announcement($_course, $id);
  255. //delete_added_resource("Ad_Valvas", $delete);
  256. $id = null;
  257. $emailTitle = null;
  258. $newContent = null;
  259. $message = get_lang('AnnouncementDeleted');
  260. }
  261. }
  262. }
  263. //delete attachment file
  264. if (isset($_GET['action']) && $_GET['action'] == 'delete') {
  265. $id = $_GET['id_attach'];
  266. AnnouncementManager::delete_announcement_attachment_file($id);
  267. }
  268. /*
  269. Delete all announcements
  270. */
  271. if (!empty($_GET['action']) and $_GET['action']=='delete_all') {
  272. if (api_is_allowed_to_edit()) {
  273. AnnouncementManager::delete_all_announcements($_course);
  274. $id = null;
  275. $emailTitle = null;
  276. $newContent = null;
  277. $message = get_lang('AnnouncementDeletedAll');
  278. }
  279. }
  280. /*
  281. Modify announcement
  282. */
  283. if (!empty($_GET['action']) and $_GET['action']=='modify' AND isset($_GET['id'])) {
  284. if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) {
  285. api_not_allowed();
  286. }
  287. $display_form = true;
  288. // RETRIEVE THE CONTENT OF THE ANNOUNCEMENT TO MODIFY
  289. $id = intval($_GET['id']);
  290. if (!api_is_course_coach() || api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $id)) {
  291. $sql="SELECT * FROM $tbl_announcement WHERE id='$id'";
  292. $rs = Database::query($sql);
  293. $myrow = Database::fetch_array($rs);
  294. $last_id = $id;
  295. $edit_attachment = AnnouncementManager::edit_announcement_attachment_file($last_id, $_FILES['user_upload'], $file_comment);
  296. if ($myrow) {
  297. $announcement_to_modify = $myrow['id'];
  298. $content_to_modify = $myrow['content'];
  299. $title_to_modify = $myrow['title'];
  300. if ($originalresource!=="no") {
  301. //unset_session_resources();
  302. //edit_added_resources("Ad_Valvas", $announcement_to_modify);
  303. $to=AnnouncementManager::load_edit_users("announcement", $announcement_to_modify);
  304. }
  305. $display_announcement_list = false;
  306. }
  307. if ($to=="everyone" OR !empty($_SESSION['toolgroup'])) {
  308. $_SESSION['select_groupusers']="hide";
  309. } else {
  310. $_SESSION['select_groupusers']="show";
  311. }
  312. }
  313. }
  314. /*
  315. Move announcement up/down
  316. */
  317. if (isset($_GET['sec_token']) && $ctok == $_GET['sec_token']) {
  318. if (!empty($_GET['down'])) {
  319. $thisAnnouncementId = intval($_GET['down']);
  320. $sortDirection = "DESC";
  321. }
  322. if (!empty($_GET['up'])) {
  323. $thisAnnouncementId = intval($_GET['up']);
  324. $sortDirection = "ASC";
  325. }
  326. }
  327. if (!empty($sortDirection)) {
  328. if (!in_array(trim(strtoupper($sortDirection)), array('ASC', 'DESC'))) {
  329. $sortDirection='ASC';
  330. }
  331. $my_sql = "SELECT announcement.id, announcement.display_order " .
  332. "FROM $tbl_announcement announcement, " .
  333. "$tbl_item_property itemproperty " .
  334. "WHERE itemproperty.ref=announcement.id " .
  335. "AND itemproperty.tool='".TOOL_ANNOUNCEMENT."' " .
  336. "AND itemproperty.visibility<>2 " .
  337. "ORDER BY display_order $sortDirection";
  338. $result = Database::query($my_sql);
  339. while (list ($announcementId, $announcementOrder) = Database::fetch_row($result)) {
  340. // STEP 2 : FOUND THE NEXT ANNOUNCEMENT ID AND ORDER.
  341. // COMMIT ORDER SWAP ON THE DB
  342. if ($thisAnnouncementOrderFound) {
  343. $nextAnnouncementId = $announcementId;
  344. $nextAnnouncementOrder = $announcementOrder;
  345. Database::query("UPDATE $tbl_announcement SET display_order = '$nextAnnouncementOrder' WHERE id = '$thisAnnouncementId'");
  346. Database::query("UPDATE $tbl_announcement SET display_order = '$thisAnnouncementOrder' WHERE id = '$nextAnnouncementId.'");
  347. break;
  348. }
  349. // STEP 1 : FIND THE ORDER OF THE ANNOUNCEMENT
  350. if ($announcementId == $thisAnnouncementId) {
  351. $thisAnnouncementOrder = $announcementOrder;
  352. $thisAnnouncementOrderFound = true;
  353. }
  354. }
  355. // show message
  356. $message = get_lang('AnnouncementMoved');
  357. }
  358. /*
  359. Submit announcement
  360. */
  361. //if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) {
  362. $emailTitle=(!empty($_POST['emailTitle'])?$safe_emailTitle:'');
  363. $newContent=(!empty($_POST['newContent'])?$safe_newContent:'');
  364. $submitAnnouncement=isset($_POST['submitAnnouncement'])?$_POST['submitAnnouncement']:0;
  365. $id = 0;
  366. if (!empty($_POST['id'])) {
  367. $id=intval($_POST['id']);
  368. }
  369. if ($submitAnnouncement && empty($emailTitle)) {
  370. $error_message = get_lang('TitleIsRequired');
  371. $content_to_modify = $newContent;
  372. } else if ($submitAnnouncement) {
  373. if (isset($id) && $id) {
  374. // there is an Id => the announcement already exists => update mode
  375. if ($ctok == $_POST['sec_token']) {
  376. $file_comment = $_POST['file_comment'];
  377. $file = $_FILES['user_upload'];
  378. $edit_id = AnnouncementManager::edit_announcement($id, $emailTitle, $newContent, $_POST['selectedform'], $file, $file_comment);
  379. /*
  380. if (!$delete) {
  381. update_added_resources("Ad_Valvas", $id);
  382. }*/
  383. $message = get_lang('AnnouncementModified');
  384. }
  385. } else {
  386. //insert mode
  387. if ($ctok == $_POST['sec_token']) {
  388. //if (!$surveyid) {
  389. $result = Database::query("SELECT MAX(display_order) FROM $tbl_announcement WHERE session_id=".api_get_session_id()." OR session_id=0");
  390. list($orderMax) = Database::fetch_row($result);
  391. $order = $orderMax + 1;
  392. $file = $_FILES['user_upload'];
  393. $file_comment = $_POST['file_comment'];
  394. if (!empty($_SESSION['toolgroup'])) {
  395. $insert_id = AnnouncementManager::add_group_announcement($safe_emailTitle,$safe_newContent,$order,array('GROUP:'.$_SESSION['toolgroup']),$_POST['selectedform'],$file,$file_comment);
  396. } else {
  397. $insert_id = AnnouncementManager::add_announcement($safe_emailTitle, $safe_newContent, $order, $_POST['selectedform'], $file, $file_comment);
  398. }
  399. //store_resources($_SESSION['source_type'],$insert_id);
  400. $_SESSION['select_groupusers']="hide";
  401. $message = get_lang('AnnouncementAdded');
  402. //}
  403. /* MAIL WHEN USER COMES FROM SURVEY */
  404. /*
  405. if ($_POST['emailsAdd']) {
  406. $to_email_address =$_POST['emailsAdd'];
  407. $to_email_to = explode(',', $to_email_address);
  408. $to_email = array_unique($to_email_to);
  409. $db_name = $_REQUEST['db_name'];
  410. for ($i=0;$i<count($to_email);$i++) {
  411. $to= trim($to_email[$i]);
  412. $db_name = $_REQUEST['db_name'];
  413. $newContentone=str_replace("#page#","choose_language.php",$newContent);
  414. $newContenttwo=str_replace("#temp#",$template,$newContentone);
  415. $newContentthree=str_replace("#sid#",$surveyid,$newContenttwo);
  416. $newContentfour=str_replace("#mail#",$to,$newContentthree);
  417. $newContentfive=str_replace("#db_name#",$db_name,$newContentfour);
  418. $newContentsix=str_replace("#uid#","",$newContentfive);
  419. if (eregi('^[0-9a-z_\.-]+@(([0-9]{1,3}\.){3}[0-9]{1,3}|([0-9a-z][0-9a-z-]*[0-9a-z]\.)+[a-z]{2,3})$', $to )) {
  420. $subject=stripslashes($emailTitle);
  421. $message=stripslashes($newContentsix);
  422. $sender_name = api_get_person_name($_SESSION['_user']['lastName'], $_SESSION['_user']['firstName'], null, PERSON_NAME_EMAIL_ADDRESS);
  423. $email = $_SESSION['_user']['mail'];
  424. $headers="From:$sender_name\r\nReply-to: $email";
  425. //@mail($to,$subject,$message,$headers);
  426. //api_send_mail($to,$subject,$message,$headers);
  427. @api_mail('',$to,$subject,$message,$sender_name,$email,$headers);
  428. $sql_date="SELECT * FROM $db_name.survey WHERE survey_id='$surveyid'";
  429. $res_date=Database::query($sql_date);
  430. $obj_date=Database::fetch_object($res_date);
  431. $end_date=$obj_date->avail_till;
  432. $table_reminder = Database :: get_main_table(TABLE_MAIN_SURVEY_REMINDER); // TODO: To be checked. TABLE_MAIN_SURVEY_REMINDER has not been defined.
  433. if ($_REQUEST['reminder']=="1") {
  434. $time=getdate();
  435. $time = $time['yday'];
  436. $time = $time+7;
  437. $sql_insert="INSERT INTO $table_reminder(sid,db_name,email,subject,content,reminder_choice,reminder_time,avail_till) values('$surveyid','$db_name','$to','".addslashes($subject)."','".addslashes($message)."','1','$time','$end_date')";
  438. Database::query($sql_insert);
  439. } else if ($_REQUEST['reminder']=="2") {
  440. $time=getdate();
  441. $time = $time['yday'];
  442. $time = $time+14;
  443. $sql_insert="INSERT INTO $table_reminder(sid,db_name,email,subject,content,reminder_choice,reminder_time,avail_till) values('$surveyid','$db_name','$to','".addslashes($subject)."','".addslashes($message)."','1','$time','$end_date')";
  444. Database::query($sql_insert);
  445. } else if($_REQUEST['reminder']=="3") {
  446. $time=getdate();
  447. $time = $time['yday'];
  448. $time = $time+30;
  449. $sql_insert="INSERT INTO $table_reminder(sid,db_name,email,subject,content,reminder_choice,reminder_time,avail_till) values('$surveyid','$db_name','$to','".addslashes($subject)."','".addslashes($message)."','1','$time','$end_date')";
  450. Database::query($sql_insert);
  451. }
  452. }
  453. }
  454. }
  455. */
  456. /* MAIL FUNCTION */
  457. if ($_POST['email_ann'] && empty($_POST['onlyThoseMails'])) {
  458. $sent_to = AnnouncementManager::sent_to("announcement", $insert_id);
  459. $userlist = $sent_to['users'];
  460. $grouplist = $sent_to['groups'];
  461. // groepen omzetten in users
  462. if ($grouplist) {
  463. $grouplist = "'".implode("', '",$grouplist)."'"; //protect individual elements with surrounding quotes
  464. $sql = "SELECT user_id
  465. FROM $tbl_groupUser gu
  466. WHERE gu.group_id IN (".$grouplist.")";
  467. $groupMemberResult = Database::query($sql);
  468. if ($groupMemberResult) {
  469. while ($u = Database::fetch_array($groupMemberResult)) {
  470. $userlist [] = $u ['user_id']; // complete the user id list ...
  471. }
  472. }
  473. }
  474. if (is_array($userlist)) {
  475. $userlist = "'".implode("', '", array_unique($userlist) )."'";
  476. // send to the created 'userlist'
  477. $sqlmail = "SELECT user_id, lastname, firstname, email
  478. FROM $tbl_user
  479. WHERE user_id IN (".$userlist.")";
  480. } else if (empty($_POST['not_selected_form'])) {
  481. if(empty($_SESSION['id_session']) || api_get_setting('use_session_mode')=='false') {
  482. // send to everybody
  483. $sqlmail = "SELECT user.user_id, user.email, user.lastname, user.firstname
  484. FROM $tbl_course_user, $tbl_user
  485. WHERE course_code='".Database::escape_string($_course['sysCode'])."'
  486. AND course_rel_user.user_id = user.user_id AND relation_type <>".COURSE_RELATION_TYPE_RRHH." ";
  487. } else {
  488. $sqlmail = "SELECT user.user_id, user.email, user.lastname, user.firstname
  489. FROM $tbl_user
  490. INNER JOIN $tbl_session_course_user
  491. ON $tbl_user.user_id = $tbl_session_course_user.id_user
  492. AND $tbl_session_course_user.course_code = '".$_course['id']."'
  493. AND $tbl_session_course_user.id_session = ".api_get_session_id();
  494. }
  495. }
  496. if ($sqlmail != '') {
  497. $rs_mail = Database::query($sqlmail);
  498. /* Send email one by one to avoid antispam */
  499. $db_name = Database::get_course_table(TABLE_MAIN_SURVEY);
  500. while ($myrow = Database::fetch_array($rs_mail)) {
  501. $emailSubject = "[" . $_course['official_code'] . "] " . $emailTitle;
  502. /* if ($surveyid) {
  503. $newContentone=str_replace("#page#","choose_language.php",$newContent);
  504. $newContenttwo=str_replace("#temp#",$template,$newContentone);
  505. $newContentthree=str_replace("#sid#",$surveyid,$newContenttwo);
  506. $newContentfour=str_replace("#mail#",$myrow["email"],$newContentthree);
  507. $newContentfive=str_replace("#db_name#",$db_name,$newContentfour);
  508. $newContentsix=str_replace("#uid#",$myrow["user_id"],$newContentfive);
  509. $message=stripslashes($newContentsix);
  510. $sender_name = api_get_person_name($_SESSION['_user']['lastName'], $_SESSION['_user']['firstName'], null, PERSON_NAME_EMAIL_ADDRESS);
  511. $email = $_SESSION['_user']['mail'];
  512. $headers="From:$sender_name\r\nReply-to: $email";
  513. @api_mail('',$myrow["email"],stripslashes($emailTitle),$message,$sender_name,$email);
  514. } else {*/
  515. // intro of the email: receiver name and subject
  516. $mail_body = api_get_person_name($myrow["lastname"], $myrow["firstname"], null, PERSON_NAME_EMAIL_ADDRESS)."<br />\n".stripslashes($emailTitle)."<br />";
  517. // Main part of the email
  518. $mail_body .= trim(stripslashes(AnnouncementManager::parse_content($newContent)));
  519. // Signature of email: sender name and course URL after -- line
  520. $mail_body .= "<br />-- <br />";
  521. $mail_body .= api_get_person_name($_user['firstName'], $_user['lastName'], null, PERSON_NAME_EMAIL_ADDRESS)." \n";
  522. $mail_body .= "<br /> \n<a href=\"".api_get_path(WEB_CODE_PATH).'announcements/announcements.php?'.api_get_cidreq()."\">";
  523. $mail_body .= $_course['official_code'].' '.$_course['name'] . "</a>";
  524. $recipient_name = api_get_person_name($myrow["firstname"], $myrow["lastname"], null, PERSON_NAME_EMAIL_ADDRESS);
  525. $mailid = $myrow["email"];
  526. $sender_name = api_get_person_name($_SESSION['_user']['firstName'], $_SESSION['_user']['lastName'], null, PERSON_NAME_EMAIL_ADDRESS);
  527. $sender_email = $_SESSION['_user']['mail'];
  528. // send attachment file
  529. $data_file = array();
  530. $sql = 'SELECT path, filename FROM '.$tbl_announcement_attachment.' WHERE announcement_id = "'.$insert_id.'"';
  531. $rs_attach = Database::query($sql);
  532. if (Database::num_rows($rs_attach) > 0) {
  533. $row_attach = Database::fetch_array($rs_attach);
  534. $path_attach = api_get_path(SYS_COURSE_PATH).$_course['path'].'/upload/announcements/'.$row_attach['path'];
  535. $filename_attach = $row_attach['filename'];
  536. $data_file = array('path' => $path_attach,'filename' => $filename_attach);
  537. }
  538. @api_mail_html($recipient_name, $mailid, stripslashes($emailSubject), $mail_body, $sender_name, $sender_email, null, $data_file, true);
  539. //}
  540. /*$sql_date="SELECT * FROM $db_name WHERE survey_id='$surveyid'";
  541. $res_date=Database::query($sql_date);
  542. $obj_date=Database::fetch_object($res_date);
  543. $end_date=$obj_date->avail_till;
  544. $table_reminder = Database :: get_main_table(TABLE_MAIN_SURVEY_REMINDER); // TODO: To be checked. TABLE_MAIN_SURVEY_REMINDER has not been defined.
  545. */
  546. if ($_REQUEST['reminder']=="1") {
  547. $time=getdate();
  548. $time = $time['yday'];
  549. $time = $time+7;
  550. $sql="INSERT INTO $table_reminder(sid,db_name,email,subject,content,reminder_choice,reminder_time,avail_till) values('$surveyid','$db_name','$mailid','".addslashes($emailSubject)."','".addslashes($mail_body)."','1','$time','$end_date')";
  551. Database::query($sql);
  552. } else if ($_REQUEST['reminder']=="2") {
  553. $time=getdate();
  554. $time = $time['yday'];
  555. $time = $time+14;
  556. $sql="INSERT INTO $table_reminder(sid,db_name,email,subject,content,reminder_choice,reminder_time,avail_till) values('$surveyid','$db_name','$mailid','".addslashes($emailSubject)."','".addslashes($mail_body)."','1','$time','$end_date')";
  557. Database::query($sql);
  558. } else if ($_REQUEST['reminder']=="3") {
  559. $time=getdate();
  560. $time = $time['yday'];
  561. $time = $time+30;
  562. $sql="INSERT INTO $table_reminder(sid,db_name,email,subject,content,reminder_choice,reminder_time,avail_till) values('$surveyid','$db_name','$mailid','".addslashes($emailSubject)."','".addslashes($mail_body)."','1','$time','$end_date')";
  563. Database::query($sql);
  564. }
  565. }
  566. AnnouncementManager::update_mail_sent($insert_id);
  567. $message = $added_and_sent;
  568. }
  569. } // $email_ann*/
  570. } // end condition token
  571. } // isset
  572. // UNSET VARIABLES
  573. unset($form_elements);
  574. $_SESSION['formelements']=null;
  575. $newContent = null;
  576. $emailTitle = null;
  577. unset($emailTitle);
  578. unset($newContent);
  579. unset($content_to_modify);
  580. unset($title_to_modify);
  581. } // if $submit Announcement
  582. }
  583. /* Tool introduction */
  584. if (empty($_GET['origin']) || $_GET['origin'] !== 'learnpath') {
  585. //api_display_tool_title($nameTools);
  586. Display::display_introduction_section(TOOL_ANNOUNCEMENT);
  587. }
  588. /* MAIN SECTION */
  589. /* DISPLAY LEFT COLUMN */
  590. //condition for the session
  591. $session_id = api_get_session_id();
  592. $condition_session = api_get_session_condition($session_id);
  593. if(api_is_allowed_to_edit(false,true)) {
  594. // check teacher status
  595. if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath') {
  596. if (api_get_group_id() == 0) {
  597. $group_condition = "";
  598. } else {
  599. $group_condition = "AND (ip.to_group_id='".api_get_group_id()."' OR ip.to_group_id = 0)";
  600. }
  601. $sql="SELECT
  602. announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
  603. FROM $tbl_announcement announcement, $tbl_item_property ip
  604. WHERE announcement.id = ip.ref
  605. AND ip.tool='announcement'
  606. AND ip.visibility<>'2'
  607. $group_condition
  608. $condition_session
  609. GROUP BY ip.ref
  610. ORDER BY display_order DESC
  611. LIMIT 0,$maximum";
  612. }
  613. } else {
  614. // students only get to see the visible announcements
  615. if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath') {
  616. $group_memberships=GroupManager::get_group_ids($_course['dbName'], $_user['user_id']);
  617. if ((api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) {
  618. if (api_get_group_id() == 0) {
  619. $cond_user_id = " AND (ip.lastedit_user_id = '".api_get_user_id()."' OR ( ip.to_user_id='".$_user['user_id']."'" .
  620. "OR ip.to_group_id IN (0, ".implode(", ", $group_memberships)."))) ";
  621. } else {
  622. $cond_user_id = " AND (ip.lastedit_user_id = '".api_get_user_id()."'
  623. OR ip.to_group_id IN (0, ".api_get_group_id()."))";
  624. }
  625. } else {
  626. if (api_get_group_id() == 0) {
  627. $cond_user_id = " AND ( ip.to_user_id='".$_user['user_id']."'" .
  628. "OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).")) ";
  629. } else {
  630. $cond_user_id = " AND ( ip.to_user_id='".$_user['user_id']."'" .
  631. "OR ip.to_group_id IN (0, ".api_get_group_id().")) ";
  632. }
  633. }
  634. // the user is member of several groups => display personal announcements AND his group announcements AND the general announcements
  635. if (is_array($group_memberships) && count($group_memberships)>0) {
  636. $sql="SELECT
  637. announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
  638. FROM $tbl_announcement announcement, $tbl_item_property ip
  639. WHERE announcement.id = ip.ref
  640. AND ip.tool='announcement'
  641. AND ip.visibility='1'
  642. $cond_user_id
  643. $condition_session
  644. GROUP BY ip.ref
  645. ORDER BY display_order DESC
  646. LIMIT 0,$maximum";
  647. } else {
  648. // the user is not member of any group
  649. // this is an identified user => show the general announcements AND his personal announcements
  650. if ($_user['user_id']) {
  651. if ((api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) {
  652. $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')) ";
  653. } else {
  654. $cond_user_id = " AND ( ip.to_user_id='".$_user['user_id']."' OR ip.to_group_id='0') ";
  655. }
  656. $sql="SELECT
  657. announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
  658. FROM $tbl_announcement announcement, $tbl_item_property ip
  659. WHERE announcement.id = ip.ref
  660. AND ip.tool='announcement'
  661. AND ip.visibility='1'
  662. $cond_user_id
  663. $condition_session
  664. GROUP BY ip.ref
  665. ORDER BY display_order DESC
  666. LIMIT 0,$maximum";
  667. } else {
  668. if (api_get_course_setting('allow_user_edit_announcement')) {
  669. $cond_user_id = " AND (ip.lastedit_user_id = '".api_get_user_id()."' OR ip.to_group_id='0') ";
  670. } else {
  671. $cond_user_id = " AND ip.to_group_id='0' ";
  672. }
  673. // the user is not identiefied => show only the general announcements
  674. $sql="SELECT
  675. announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
  676. FROM $tbl_announcement announcement, $tbl_item_property ip
  677. WHERE announcement.id = ip.ref
  678. AND ip.tool='announcement'
  679. AND ip.visibility='1'
  680. AND ip.to_group_id='0'
  681. $condition_session
  682. GROUP BY ip.ref
  683. ORDER BY display_order DESC
  684. LIMIT 0,$maximum";
  685. }
  686. }
  687. }
  688. }
  689. $result = Database::query($sql);
  690. $announcement_number = Database::num_rows($result);
  691. /*
  692. ADD ANNOUNCEMENT / DELETE ALL
  693. */
  694. $show_actions = false;
  695. 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')) {
  696. echo '<div class="actions">';
  697. if (isset($_GET['action']) && in_array($_GET['action'], array('add', 'modify','view'))) {
  698. echo "<a href='".api_get_self()."?".api_get_cidreq()."&origin=".(empty($_GET['origin'])?'':$_GET['origin'])."'>".Display::return_icon('back.png',get_lang('Back'),'','32')."</a>";
  699. } else {
  700. 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'),'','32')."</a>";
  701. }
  702. $show_actions = true;
  703. } else {
  704. if (in_array($_GET['action'], array('view'))) {
  705. echo '<div class="actions">';
  706. echo "<a href='".api_get_self()."?".api_get_cidreq()."&origin=".(empty($_GET['origin'])?'':$_GET['origin'])."'>".Display::return_icon('back.png',get_lang('Back'),'','32')."</a>";
  707. echo '</div>';
  708. }
  709. }
  710. if (api_is_allowed_to_edit() && $announcement_number > 1) {
  711. if (api_get_group_id() == 0 ) {
  712. if (!$show_actions)
  713. echo '<div class="actions">';
  714. if (!in_array($_GET['action'], array('add', 'modify','view')))
  715. 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'),'','32')."</a>";
  716. } // if announcementNumber > 1
  717. }
  718. if ($show_actions)
  719. echo '</div>';
  720. // ANNOUNCEMENTS LIST
  721. /*
  722. if ($display_title_list) {
  723. echo "<table>";
  724. while ($myrow = Database::fetch_array($result)) {
  725. $title = $myrow['title'];
  726. $title = Security::remove_XSS($title);
  727. if ($myrow['visibility']==0) {
  728. $class="class=\"invisible\"";
  729. } else {
  730. $class="";
  731. }
  732. //validation when belongs to a session
  733. $session_img = api_get_session_image($myrow['session_id'], $_user['status']);
  734. $title_td ="<a style=\"text-decoration:none\" href=\"announcements.php?".api_get_cidreq()."#".$myrow['id']."\" ".$class.">" . api_trunc_str($title, $length) . "</a>" . $session_img;
  735. $title_td = Display::tag('td', $title_td, array('width'=>'75%'));
  736. $date = api_convert_and_format_date($myrow['end_date'], DATE_FORMAT_SHORT);
  737. $date_td = Display::tag('td', $date, array('class'=>'announcements_datum', 'width'=>'50%'));
  738. echo Display::tag('tr', $title_td.$date_td);
  739. }
  740. echo "</table>";
  741. } // end $display_title_list
  742. */
  743. /*
  744. if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath') {
  745. echo "</td>";
  746. echo "<td width=\"20\" background=\"../img/verticalruler.gif\">&nbsp;</td>";
  747. // START RIGHT PART
  748. echo "<td valign=\"top\">";
  749. }*/
  750. /* DISPLAY ACTION MESSAGE */
  751. if ($message) {
  752. Display::display_confirmation_message($message);
  753. $display_announcement_list = true;
  754. $display_form = false;
  755. }
  756. if (!empty($error_message)) {
  757. Display::display_error_message($error_message);
  758. $display_announcement_list = false;
  759. $display_form = true;
  760. }
  761. /*
  762. DISPLAY FORM
  763. */
  764. if ($display_form) {
  765. $content_to_modify = stripslashes($content_to_modify);
  766. $title_to_modify = stripslashes($title_to_modify);
  767. // DISPLAY ADD ANNOUNCEMENT COMMAND
  768. 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;">';
  769. if (empty($_GET['id'])) {
  770. $form_name = get_lang('AddAnnouncement');
  771. } else {
  772. $form_name = get_lang('ModifyAnnouncement');
  773. }
  774. echo '<div class="row"><div class="form_header">'.$form_name.'</div></div>';
  775. //this variable defines if the course administrator can send a message to a specific user / group or not
  776. if (empty($_SESSION['toolgroup'])) {
  777. echo ' <div class="row">
  778. <div class="label">'.
  779. Display::return_icon('group.png', get_lang('ModifyRecipientList'), array ('align' => 'absmiddle'),22).'<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>
  780. </div>
  781. <div class="formw">';
  782. if (isset($_GET['id']) && is_array($to)) {
  783. echo '&nbsp;';
  784. } elseif (isset($_GET['remind_inactive'])) {
  785. $email_ann = '1';
  786. $_SESSION['select_groupusers']="show";
  787. $content_to_modify = sprintf(get_lang('RemindInactiveLearnersMailContent'), api_get_setting('siteName'), 7);
  788. $title_to_modify = sprintf(get_lang('RemindInactiveLearnersMailSubject'), api_get_setting('siteName'));
  789. } elseif (isset($_GET['remindallinactives']) && $_GET['remindallinactives']=='true') {
  790. // 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
  791. $since = isset($_GET['since']) ? intval($_GET['since']) : 6;
  792. // getting the users who have to be reminded
  793. $to = Tracking :: get_inactives_students_in_course($_course['id'],$since, api_get_session_id());
  794. // setting the variables for the form elements: the users who need to receive the message
  795. foreach($to as &$user) {
  796. $user = 'USER:'.$user;
  797. }
  798. // setting the variables for the form elements: the 'visible to' form element has to be expanded
  799. $_SESSION['select_groupusers']="show";
  800. // setting the variables for the form elements: the message has to be sent by email
  801. $email_ann = '1';
  802. // setting the variables for the form elements: the title of the email
  803. //$title_to_modify = sprintf(get_lang('RemindInactiveLearnersMailSubject'), api_get_setting('siteName'),' > ',$_course['name']);
  804. $title_to_modify = sprintf(get_lang('RemindInactiveLearnersMailSubject'), api_get_setting('siteName'));
  805. // setting the variables for the form elements: the message of the email
  806. //$content_to_modify = sprintf(get_lang('RemindInactiveLearnersMailContent'),api_get_setting('siteName'),' > ',$_course['name'],$since);
  807. $content_to_modify = sprintf(get_lang('RemindInactiveLearnersMailContent'),api_get_setting('siteName'),$since);
  808. // when we want to remind the users who have never been active then we have a different subject and content for the announcement
  809. if ($_GET['since'] == 'never') {
  810. $title_to_modify = sprintf(get_lang('RemindInactiveLearnersMailSubject'), api_get_setting('siteName'));
  811. $content_to_modify = get_lang('YourAccountIsActiveYouCanLoginAndCheckYourCourses');
  812. }
  813. } else {
  814. echo get_lang('Everybody');
  815. }
  816. AnnouncementManager::show_to_form($to);
  817. echo ' </div>
  818. </div>';
  819. if (!isset($announcement_to_modify) ) $announcement_to_modify ='';
  820. if ($announcement_to_modify=='') {
  821. ($email_ann=='1')?$checked='checked':$checked='';
  822. echo ' <div class="row">
  823. <div class="label">
  824. <input class="checkbox" type="checkbox" value="1" name="email_ann" checked>
  825. </div>
  826. <div class="formw">'.get_lang('EmailOption').'
  827. </div>
  828. </div>';
  829. }
  830. } else {
  831. if (!isset($announcement_to_modify) ) {
  832. $announcement_to_modify ="";
  833. }
  834. if ($announcement_to_modify=='') {
  835. ($email_ann=='1' || !empty($surveyid))?$checked='checked':$checked='';
  836. echo '<div class="row">
  837. <div class="label">
  838. <input class="checkbox" type="checkbox" value="1" name="email_ann" '.$checked.'>
  839. </div>
  840. <div class="formw">'.
  841. get_lang('EmailOption').': '.get_lang('MyGroup').'&nbsp;&nbsp;<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>';
  842. AnnouncementManager::show_to_form_group($_SESSION['toolgroup']);
  843. echo '</div></div>';
  844. }
  845. }
  846. // the announcement title
  847. echo ' <div class="row">
  848. <div id="msg_error" style="display:none;color:red;margin-left:20%"></div>
  849. <div class="label">
  850. <span class="form_required">*</span> '.get_lang('EmailTitle').'
  851. </div>
  852. <div class="formw">
  853. <input type="text" id="emailTitle" name="emailTitle" value="'.Security::remove_XSS($title_to_modify).'" size="60">
  854. </div>
  855. </div>';
  856. unset($title_to_modify);
  857. $title_to_modify = null;
  858. if (!isset($announcement_to_modify) ) $announcement_to_modify ="";
  859. if (!isset($content_to_modify) ) $content_to_modify ="";
  860. if (!isset($title_to_modify)) $title_to_modify = "";
  861. echo '<input type="hidden" name="id" value="'.$announcement_to_modify.'" />';
  862. $oFCKeditor = new FCKeditor('newContent') ;
  863. $oFCKeditor->Width = '100%';
  864. $oFCKeditor->Height = '300';
  865. if(!api_is_allowed_to_edit()) {
  866. $oFCKeditor->ToolbarSet = "AnnouncementsStudent";
  867. } else {
  868. $oFCKeditor->ToolbarSet = "Announcements";
  869. }
  870. $oFCKeditor->Value = $content_to_modify;
  871. echo '<div class="row"><div class="formw">';
  872. echo Display::display_normal_message(get_lang('Tags').' <br /><br />'.implode('<br />', AnnouncementManager::get_tags()), false);
  873. echo $oFCKeditor->CreateHtml();
  874. echo '</div></div>';
  875. //File attachment
  876. echo ' <div class="row">
  877. <div class="label">
  878. <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>
  879. </div>
  880. <div class="formw">
  881. <table id="options" style="display: none;">
  882. <tr>
  883. <td colspan="2">
  884. <label for="file_name">'.get_lang('FileName').'&nbsp;</label>
  885. <input type="file" name="user_upload"/>
  886. </td>
  887. </tr>
  888. <tr>
  889. <td colspan="2">
  890. <label for="comment">'.get_lang('FileComment').'</label><br />
  891. <textarea name="file_comment" rows ="4" cols = "34" ></textarea>
  892. </td>
  893. </tr>
  894. </table>
  895. </div>
  896. </div>';
  897. echo'<br />';
  898. echo '<div class="row"><div class="formw">';
  899. if (empty($_SESSION['toolgroup'])) {
  900. echo '<input type="hidden" name="submitAnnouncement" value="OK">';
  901. echo '<input type="hidden" name="sec_token" value="'.$stok.'" />';
  902. echo '<button class="save" type="button" value="'.' '.get_lang('Send').' '.'" onclick="selectAll(this.form.elements[3],true)" >'.get_lang('ButtonPublishAnnouncement').'</button><br /><br />';
  903. } else {
  904. echo '<input type="hidden" name="submitAnnouncement" value="OK">';
  905. echo '<input type="hidden" name="sec_token" value="'.$stok.'" />';
  906. echo '<button class="save" type="button" value="'.' '.get_lang('Send').' '.'" onclick="selectAll(this.form.elements[4],true)" >'.get_lang('ButtonPublishAnnouncement').'</button><br /><br />';
  907. }
  908. echo '</div></div>';
  909. echo '</form><br />';
  910. if ((isset($_GET['action']) && isset($_GET['id']) && is_array($to))||isset($_GET['remindallinactives'])||isset($_GET['remind_inactive'])) {
  911. echo '<script>document.getElementById(\'recipient_list\').style.display=\'block\';</script>';
  912. }
  913. } // displayform
  914. /*
  915. DISPLAY ANNOUNCEMENT LIST
  916. */
  917. //if ($display_announcement_list && !$surveyid) {
  918. if ($display_announcement_list) {
  919. // 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
  920. //$user_id=$_user['user_id'];
  921. if (isset($_SESSION['user'])) {
  922. //$user_id=$_SESSION['user'];
  923. }
  924. $user_id = api_get_user_id();
  925. if (isset($_SESSION['group'])) {
  926. //$group_id=$_SESSION['group'];
  927. }
  928. $group_id = api_get_group_id();
  929. //$group_memberships=GroupManager::get_group_ids($_course['dbName'], $_user['user_id']);
  930. $group_memberships = GroupManager::get_group_ids($_course['dbName'],api_get_user_id());
  931. if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) {
  932. // A.1. you are a course admin with a USER filter
  933. // => see only the messages of this specific user + the messages of the group (s)he is member of.
  934. if (!empty($_SESSION['user'])) {
  935. if (is_array($group_memberships) && count($group_memberships)>0) {
  936. $sql="SELECT
  937. announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date
  938. FROM $tbl_announcement announcement, $tbl_item_property ip
  939. WHERE announcement.id = ip.ref
  940. AND ip.tool='announcement'
  941. AND (ip.to_user_id=$user_id OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") )
  942. $condition_session
  943. ORDER BY display_order DESC";
  944. } else {
  945. $sql="SELECT
  946. announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date
  947. FROM $tbl_announcement announcement, $tbl_item_property ip
  948. WHERE announcement.id = ip.ref
  949. AND ip.tool='announcement'
  950. AND (ip.to_user_id=$user_id OR ip.to_group_id='0')
  951. AND ip.visibility='1'
  952. $condition_session
  953. ORDER BY display_order DESC";
  954. }
  955. } elseif (api_get_group_id() !=0 ) {
  956. // A.2. you are a course admin with a GROUP filter
  957. // => see only the messages of this specific group
  958. $sql="SELECT
  959. announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date
  960. FROM $tbl_announcement announcement, $tbl_item_property ip
  961. WHERE announcement.id = ip.ref
  962. AND ip.tool='announcement'
  963. AND ip.visibility<>'2'
  964. AND (ip.to_group_id=$group_id OR ip.to_group_id='0')
  965. $condition_session
  966. GROUP BY ip.ref
  967. ORDER BY display_order DESC";
  968. } else {
  969. // A.3 you are a course admin without any group or user filter
  970. // A.3.a you are a course admin without user or group filter but WITH studentview
  971. // => see all the messages of all the users and groups without editing possibilities
  972. if (isset($isStudentView) and $isStudentView=="true") {
  973. $sql="SELECT
  974. announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date
  975. FROM $tbl_announcement announcement, $tbl_item_property ip
  976. WHERE announcement.id = ip.ref
  977. AND ip.tool='announcement'
  978. AND ip.visibility='1'
  979. $condition_session
  980. GROUP BY ip.ref
  981. ORDER BY display_order DESC";
  982. } else {
  983. // A.3.a you are a course admin without user or group filter and WTIHOUT studentview (= the normal course admin view)
  984. // => see all the messages of all the users and groups with editing possibilities
  985. $sql="SELECT
  986. announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date
  987. FROM $tbl_announcement announcement, $tbl_item_property ip
  988. WHERE announcement.id = ip.ref
  989. AND ip.tool='announcement'
  990. AND (ip.visibility='0' or ip.visibility='1')
  991. $condition_session
  992. GROUP BY ip.ref
  993. ORDER BY display_order DESC";
  994. }
  995. }
  996. } else {
  997. //STUDENT
  998. if (is_array($group_memberships) && count($group_memberships)>0) {
  999. if ((api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) {
  1000. if (api_get_group_id() == 0) {
  1001. //No group
  1002. $cond_user_id = " AND (ip.lastedit_user_id = '".api_get_user_id()."' OR ( ip.to_user_id='".$_user['user_id']."'" .
  1003. "OR ip.to_group_id IN (0, ".implode(", ", $group_memberships)."))) ";
  1004. } else {
  1005. $cond_user_id = " AND (ip.lastedit_user_id = '".api_get_user_id()."'
  1006. OR ip.to_group_id IN (0, ".api_get_group_id()."))";
  1007. }
  1008. //$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).") )) ";
  1009. } else {
  1010. if (api_get_group_id() == 0) {
  1011. $cond_user_id = " AND (ip.to_user_id=$user_id OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).")) ";
  1012. } else {
  1013. $cond_user_id = " AND (ip.to_user_id=$user_id OR ip.to_group_id IN (0, ".api_get_group_id()."))";
  1014. }
  1015. }
  1016. $sql="SELECT announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id, ip.insert_date
  1017. FROM $tbl_announcement announcement, $tbl_item_property ip
  1018. WHERE announcement.id = ip.ref
  1019. AND ip.tool='announcement'
  1020. $cond_user_id
  1021. $condition_session
  1022. AND ip.visibility='1'
  1023. ORDER BY display_order DESC";
  1024. } else {
  1025. if ($_user['user_id']) {
  1026. if ((api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) {
  1027. $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')) ";
  1028. } else {
  1029. $cond_user_id = " AND (ip.to_user_id='".$_user['user_id']."' OR ip.to_group_id='0') ";
  1030. }
  1031. $sql="SELECT
  1032. announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
  1033. FROM $tbl_announcement announcement, $tbl_item_property ip
  1034. WHERE announcement.id = ip.ref
  1035. AND ip.tool='announcement'
  1036. $cond_user_id
  1037. $condition_session
  1038. AND ip.visibility='1'
  1039. AND announcement.session_id IN(0,".api_get_session_id().")
  1040. ORDER BY display_order DESC";
  1041. } else {
  1042. if ((api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) {
  1043. $cond_user_id = " AND (ip.lastedit_user_id = '".api_get_user_id()."' OR ip.to_group_id='0' ) ";
  1044. } else {
  1045. $cond_user_id = " AND ip.to_group_id='0' ";
  1046. }
  1047. $sql="SELECT
  1048. announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
  1049. FROM $tbl_announcement announcement, $tbl_item_property ip
  1050. WHERE announcement.id = ip.ref
  1051. AND ip.tool='announcement'
  1052. $cond_user_id
  1053. $condition_session
  1054. AND ip.visibility='1'
  1055. AND announcement.session_id IN(0,".api_get_session_id().")";
  1056. }
  1057. }
  1058. }
  1059. $result = Database::query($sql);
  1060. $num_rows = Database::num_rows($result);
  1061. // DISPLAY: NO ITEMS
  1062. if (!in_array($_GET['action'], array('add', 'modify','view')))
  1063. if ($num_rows == 0) {
  1064. Display::display_warning_message(get_lang('NoAnnouncements'));
  1065. } else {
  1066. $iterator = 1;
  1067. $bottomAnnouncement = $announcement_number;
  1068. echo '<table width="100%" class="data_table">';
  1069. $ths = Display::tag('th', get_lang('Title'));
  1070. //$ths .= Display::tag('th', get_lang('Content'));
  1071. $ths .= Display::tag('th', get_lang('By') );
  1072. //$ths .= Display::tag('th', get_lang('AnnouncementPublishedOn') );
  1073. $ths .= Display::tag('th', get_lang('LastUpdateDate') );
  1074. if (api_is_allowed_to_edit(false,true) OR (api_is_course_coach() && api_is_element_in_the_session(TOOL_ANNOUNCEMENT,$myrow['id']))
  1075. OR (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) {
  1076. //$ths .= Display::tag('th', get_lang('SentTo'));
  1077. $ths .= Display::tag('th', get_lang('Modify'));
  1078. }
  1079. echo Display::tag('tr', $ths);
  1080. $displayed = array();
  1081. while ($myrow = Database::fetch_array($result, 'ASSOC')) {
  1082. if (!in_array($myrow['id'], $displayed)) {
  1083. $sent_to_icon = '';
  1084. // the email icon
  1085. if ($myrow['email_sent'] == '1') {
  1086. $sent_to_icon = ' '.Display::return_icon('email.gif', get_lang('AnnounceSentByEmail'));
  1087. }
  1088. $title = $myrow['title'].$sent_to_icon;
  1089. $content = $myrow['content'];
  1090. $content = make_clickable($content);
  1091. $content = text_filter($content);
  1092. /* DATE */
  1093. $last_post_datetime = $myrow['end_date'];
  1094. // the styles
  1095. if ($myrow['visibility']=='0') {
  1096. $style='invisible';
  1097. } else {
  1098. $style = '';
  1099. }
  1100. echo "<tr>";
  1101. // show attachment list
  1102. $attachment_list = array();
  1103. $attachment_list = AnnouncementManager::get_attachment($myrow['id']);
  1104. $attachment = '';
  1105. $attachment_icon = '';
  1106. if (count($attachment_list)>0) {
  1107. $attachment_icon = ' '.Display::return_icon('attachment.gif',get_lang('Attachment'));
  1108. }
  1109. /* TITLE */
  1110. $title = Display::url($title.$attachment_icon, '?action=view&id='.$myrow['id']);
  1111. echo Display::tag('td', Security::remove_XSS($title), array('class' => $style));
  1112. //echo Display::tag('td', Security::remove_XSS($content).$attachment);
  1113. $user_info = api_get_user_info($myrow['insert_user_id']);
  1114. echo Display::tag('td', api_get_person_name($user_info['firstName'], $user_info['lastName']));
  1115. echo Display::tag('td', api_convert_and_format_date($myrow['insert_date'], DATE_TIME_FORMAT_LONG));
  1116. /* RESOURCES */
  1117. //echo "<tr class='row_odd'><td colspan=\"3\">";
  1118. /*
  1119. if (check_added_resources("Ad_Valvas", $myrow["id"])) {
  1120. echo "<i>".get_lang('AddedResources')."</i><br />";
  1121. display_added_resources("Ad_Valvas", $myrow["id"]);
  1122. }
  1123. */
  1124. // 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
  1125. $modify_icons = '';
  1126. if (api_is_allowed_to_edit(false,true) OR (api_is_course_coach() && api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $myrow['id']))
  1127. OR (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) {
  1128. $modify_icons = "<a href=\"".api_get_self()."?".api_get_cidreq()."&action=modify&id=".$myrow['id']."\">".Display::return_icon('edit.png', get_lang('Edit'),'',22)."</a>";
  1129. if ($myrow['visibility']==1) {
  1130. $image_visibility="visible";
  1131. $alt_visibility=get_lang('Hide');
  1132. } else {
  1133. $image_visibility="invisible";
  1134. $alt_visibility=get_lang('Visible');
  1135. }
  1136. $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."\">".
  1137. Display::return_icon($image_visibility.'.png', $alt_visibility,'',22)."</a>";
  1138. // DISPLAY MOVE UP COMMAND only if it is not the top announcement
  1139. if ($iterator != 1) {
  1140. $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>";
  1141. } else {
  1142. $modify_icons .= Display::return_icon('up_na.gif', get_lang('Up'));
  1143. }
  1144. if ($iterator < $bottomAnnouncement) {
  1145. $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>";
  1146. } else {
  1147. $modify_icons .= Display::return_icon('down_na.gif', get_lang('Down'));
  1148. }
  1149. if (api_is_allowed_to_edit(false,true)) {
  1150. $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;\">".
  1151. Display::return_icon('delete.png', get_lang('Delete'),'',22).
  1152. "</a>";
  1153. }
  1154. $iterator ++;
  1155. echo Display::tag('td', $modify_icons);
  1156. }
  1157. echo "</tr>";
  1158. }
  1159. $displayed[]=$myrow['id'];
  1160. } // end while
  1161. echo "</table>";
  1162. }
  1163. } // end: if ($displayAnnoucementList)
  1164. if ($_GET['action'] == 'view') {
  1165. AnnouncementManager::display_announcement($announcement_id);
  1166. }
  1167. /* FOOTER */
  1168. if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath') {
  1169. //we are not in learnpath tool
  1170. Display::display_footer();
  1171. }