announcements.php 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486
  1. <?php //$Id: announcements.php 14830 2008-04-10 10:05:03Z pcool $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2005 Dokeos S.A.
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) various contributors
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  17. Mail: info@dokeos.com
  18. ==============================================================================
  19. */
  20. /**
  21. ==============================================================================
  22. * @author Frederik Vermeire <frederik.vermeire@pandora.be>, UGent Internship
  23. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: code cleaning
  24. * @abstract The task of the internship was to integrate the 'send messages to specific users' with the
  25. * Announcements tool and also add the resource linker here. The database also needed refactoring
  26. * as there was no title field (the title was merged into the content field)
  27. * @package dokeos.announcements
  28. * @todo make AWACS out of the configuration settings
  29. * @todo this file is 1200+ lines without any functions -> needs to be split into
  30. * multiple functions
  31. ==============================================================================
  32. */
  33. /*
  34. ==============================================================================
  35. INIT SECTION
  36. ==============================================================================
  37. */
  38. // name of the language file that needs to be included
  39. $language_file[] = "announcements";
  40. $language_file[] = "group";
  41. $language_file[] = "survey";
  42. // use anonymous mode when accessing this course tool
  43. $use_anonymous = true;
  44. // setting the global file that gets the general configuration, the databases, the languages, ...
  45. include('../inc/global.inc.php');
  46. $this_section=SECTION_COURSES;
  47. $nameTools = get_lang('Announcement');
  48. //session
  49. if(isset($_GET['id_session']))
  50. $_SESSION['id_session'] = $_GET['id_session'];
  51. /* ------------ ACCESS RIGHTS ------------ */
  52. // notice for unauthorized people.
  53. api_protect_course_script();
  54. /*
  55. -----------------------------------------------------------
  56. Constants and variables
  57. -----------------------------------------------------------
  58. */
  59. // Configuration settings
  60. $display_announcement_list = true;
  61. $display_form = false;
  62. $display_title_list = true;
  63. // Maximum title messages to display
  64. $maximum = '12';
  65. // Length of the titles
  66. $length = '36';
  67. // Database Table Definitions
  68. $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  69. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  70. $tbl_courses = Database::get_main_table(TABLE_MAIN_COURSE);
  71. $tbl_sessions = Database::get_main_table(TABLE_MAIN_SESSION);
  72. $tbl_session_course_user= Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  73. $tbl_group = Database::get_course_table(TABLE_GROUP);
  74. $tbl_groupUser = Database::get_course_table(TABLE_GROUP_USER);
  75. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
  76. $tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
  77. /*
  78. -----------------------------------------------------------
  79. Resource linker
  80. -----------------------------------------------------------
  81. */
  82. $_SESSION['source_type']="Ad_Valvas";
  83. include('../resourcelinker/resourcelinker.inc.php');
  84. if ($_POST['addresources']) // When the "Add Resource" button is clicked we store all the form data into a session
  85. {
  86. include('announcements.inc.php');
  87. $form_elements= array ('emailTitle'=>stripslashes($emailTitle), 'newContent'=>stripslashes($newContent), 'id'=>$id, 'to'=>$selectedform, 'emailoption'=>$email_ann);
  88. $_SESSION['formelements']=$form_elements;
  89. if($id) // this is to correctly handle edits
  90. {
  91. $action="edit";
  92. }else
  93. {
  94. $action="add";
  95. }
  96. // ============== //
  97. // 7 = Ad_Valvas //
  98. // ============== //
  99. if($surveyid)
  100. {
  101. header("Location: ../resourcelinker/resourcelinker.php?source_id=7&action=$action&id=$id&originalresource=no&publish_survey=$surveyid&db_name=$db_name&cidReq=$cidReq");
  102. exit;
  103. }
  104. else
  105. {
  106. header("Location: ../resourcelinker/resourcelinker.php?source_id=7&action=$action&id=$id&originalresource=no");
  107. exit;
  108. }
  109. exit;
  110. }
  111. /*
  112. -----------------------------------------------------------
  113. Tracking
  114. -----------------------------------------------------------
  115. */
  116. include(api_get_path(LIBRARY_PATH).'events.lib.inc.php');
  117. event_access_tool(TOOL_ANNOUNCEMENT);
  118. /*
  119. -----------------------------------------------------------
  120. Libraries
  121. -----------------------------------------------------------
  122. */
  123. require_once(api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
  124. require_once('announcements.inc.php');
  125. require_once(api_get_path(INCLUDE_PATH).'lib/mail.lib.inc.php');
  126. require_once(api_get_path(INCLUDE_PATH).'conf/mail.conf.php');
  127. require_once(api_get_path(LIBRARY_PATH).'debug.lib.inc.php');
  128. require_once(api_get_path(LIBRARY_PATH).'tracking.lib.php');
  129. /*
  130. -----------------------------------------------------------
  131. POST TO
  132. -----------------------------------------------------------
  133. */
  134. if ($_POST['To'])
  135. {
  136. $display_form = true;
  137. $form_elements= array ('emailTitle'=>$_POST['emailTitle'], 'newContent'=>$_POST['newContent'], 'id'=>$_POST['id'], 'emailoption'=>$_POST['email_ann']);
  138. $_SESSION['formelements']=$form_elements;
  139. $form_elements = $_SESSION['formelements'];
  140. $title_to_modify = $form_elements["emailTitle"];
  141. $content_to_modify = $form_elements["newContent"];
  142. $announcement_to_modify = $form_elements["id"];
  143. }
  144. /*
  145. -----------------------------------------------------------
  146. Show/hide user/group form
  147. -----------------------------------------------------------
  148. */
  149. $setting_select_groupusers=true;
  150. if (!$_POST['To'] and !$_SESSION['select_groupusers'])
  151. {
  152. $_SESSION['select_groupusers']="hide";
  153. }
  154. $select_groupusers_status=$_SESSION['select_groupusers'];
  155. if ($_POST['To'] and ($select_groupusers_status=="hide"))
  156. {
  157. $_SESSION['select_groupusers']="show";
  158. }
  159. if ($_POST['To'] and ($select_groupusers_status=="show"))
  160. {
  161. $_SESSION['select_groupusers']="hide";
  162. }
  163. /*
  164. -----------------------------------------------------------
  165. Action handling
  166. -----------------------------------------------------------
  167. */
  168. // display the form
  169. if (($_GET['action'] == 'add' && $_GET['origin'] == "") || $_GET['action'] == 'edit' || $_POST['To'])
  170. {
  171. $display_form = true;
  172. }
  173. // clear all resources
  174. if ($originalresource!=="no" and $action=="add")
  175. {
  176. $_SESSION["formelements"]=null;
  177. unset_session_resources();
  178. }
  179. /*
  180. -----------------------------------------------------------
  181. Javascript
  182. -----------------------------------------------------------
  183. */
  184. $htmlHeadXtra[] = to_javascript();
  185. /*
  186. -----------------------------------------------------------
  187. Filter user/group
  188. -----------------------------------------------------------
  189. */
  190. if(!empty($_GET['toolgroup'])){
  191. if($_GET['toolgroup'] == strval(intval($_GET['toolgroup']))){ //check is integer
  192. $toolgroup = $_GET['toolgroup'];
  193. $_SESSION['select_groupusers'] = 'hide';
  194. }else{
  195. $toolgroup = 0;
  196. }
  197. api_session_register("toolgroup");
  198. }
  199. /*
  200. -----------------------------------------------------------
  201. Sessions
  202. -----------------------------------------------------------
  203. */
  204. if ($_SESSION['formelements'] and $_GET['originalresource'] == 'no')
  205. {
  206. $form_elements = $_SESSION['formelements'];
  207. $title_to_modify = $form_elements['emailTitle'];
  208. $content_to_modify = $form_elements['newContent'];
  209. $announcement_to_modify = $form_elements['id'];
  210. $to = $form_elements['to'];
  211. //load_edit_users('announcement',$announcement_to_modify);
  212. $email_ann = $form_elements['emailoption'];
  213. }
  214. if(!empty($_GET['remind_inactive']))
  215. {
  216. $to[] = 'USER:'.intval($_GET['remind_inactive']);
  217. }
  218. /*
  219. -----------------------------------------------------------
  220. Survey
  221. -----------------------------------------------------------
  222. */
  223. $surveyid=Database::escape_string($_REQUEST['publish_survey']);
  224. $cidReq=Database::escape_string($_REQUEST['cidReq']);
  225. if($surveyid)
  226. {
  227. $db_name=Database::escape_string($_REQUEST['db_name']);
  228. $sql_temp = "SELECT * FROM $db_name.survey WHERE survey_id='$surveyid'";
  229. $res_temp = api_sql_query($sql_temp, __FILE__, __LINE__);
  230. $obj=@mysql_fetch_object($res_temp);
  231. $template=$obj->template;
  232. }
  233. if($surveyid)
  234. {
  235. $interbreadcrumb[] = array ("url" => "../survey/survey_list.php?cidReq=$cidReq", "name" => get_lang('Survey'));
  236. $nameTools = get_lang('PublishSurvey');
  237. }
  238. else
  239. $nameTools = get_lang('Announcement');
  240. $nameTools12 = get_lang('PublishSurvey');
  241. /*
  242. -----------------------------------------------------------
  243. Learning path & css
  244. -----------------------------------------------------------
  245. */
  246. // showing the header if we are not in the learning path, if we are in
  247. // the learning path, we do not include the banner so we have to explicitly
  248. // include the stylesheet, which is normally done in the header
  249. if ($_GET['origin'] !== 'learnpath')
  250. {
  251. //we are not in the learning path
  252. Display::Display_header($nameTools,"Announcements");
  253. }
  254. else
  255. {
  256. //we are in the learning path, only display central data and change css
  257. $display_title_list = false;
  258. $display_announcement_list = false;
  259. $display_specific_announcement = true;
  260. $announcement_id = $_REQUEST['ann_id'];
  261. ?> <link rel="stylesheet" type="text/css" href="<?php echo $clarolineRepositoryWeb ?>css/default.css">
  262. <!-- css file for announcements -->
  263. <link href="../css/announcements.css" rel="stylesheet" type="text/css">
  264. <?php
  265. }
  266. // inserting an anchor (top) so one can jump back to the top of the page
  267. echo "<a name=\"top\"></a>";
  268. /*=============================================
  269. ACTION HANDLING
  270. =============================================*/
  271. if (api_is_allowed_to_edit() OR (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous()))
  272. {
  273. /*
  274. -----------------------------------------------------------
  275. Change visibility of announcement
  276. -----------------------------------------------------------
  277. */
  278. // $_GET['isStudentView']<>"false" is added to prevent that the visibility
  279. // is changed after you do the following:
  280. // change visibility -> studentview -> course manager view
  281. if ($_GET['isStudentView']<>"false")
  282. {
  283. if (isset($_GET['id']) AND $_GET['id'] AND isset($_GET['action']) AND $_GET['action']=="showhide")
  284. {
  285. $id=intval(addslashes($_GET['id']));
  286. change_visibility(TOOL_ANNOUNCEMENT,$id);
  287. $message = get_lang("Visible");
  288. }
  289. }
  290. /*
  291. -----------------------------------------------------------
  292. Delete announcement
  293. -----------------------------------------------------------
  294. */
  295. if ($_GET['action']=="delete" AND isset($_GET['id']))
  296. {
  297. //api_sql_query("DELETE FROM $tbl_announcement WHERE id='$delete'",__FILE__,__LINE__);
  298. $id=intval(addslashes($_GET['id']));
  299. // tooledit : visibility = 2 : only visibile for platform administrator
  300. api_sql_query("UPDATE $tbl_item_property SET visibility='2' WHERE tool='".TOOL_ANNOUNCEMENT."' and ref='".$id."'",__FILE__,__LINE__);
  301. delete_added_resource("Ad_Valvas", $delete);
  302. $id = null;
  303. $emailTitle = null;
  304. $newContent = null;
  305. $message = get_lang("AnnouncementDeleted");
  306. }
  307. /*
  308. -----------------------------------------------------------
  309. Delete all announcements
  310. -----------------------------------------------------------
  311. */
  312. if ($_GET['action']=="delete_all")
  313. {
  314. //api_sql_query("DELETE FROM $tbl_announcement",__FILE__,__LINE__);
  315. api_sql_query("UPDATE $tbl_item_property SET visibility='2' WHERE tool='".TOOL_ANNOUNCEMENT."'",__FILE__,__LINE__);
  316. delete_all_resources_type("Ad_Valvas");
  317. $id = null;
  318. $emailTitle = null;
  319. $newContent = null;
  320. $message = get_lang("AnnouncementDeletedAll");
  321. }
  322. /*
  323. -----------------------------------------------------------
  324. Modify announcement
  325. -----------------------------------------------------------
  326. */
  327. if ($_GET['action']=="modify" AND isset($_GET['id']))
  328. {
  329. $display_form = true;
  330. // RETRIEVE THE CONTENT OF THE ANNOUNCEMENT TO MODIFY
  331. $id = intval(addslashes($_GET['id']));
  332. $sql="SELECT * FROM $tbl_announcement WHERE id='$id'";
  333. $result = api_sql_query($sql,__FILE__,__LINE__);
  334. $myrow = mysql_fetch_array($result);
  335. if ($myrow)
  336. {
  337. $announcement_to_modify = $myrow['id'];
  338. $content_to_modify = $myrow['content'];
  339. $title_to_modify = $myrow['title'];
  340. if ($originalresource!=="no") // and !addresources)
  341. {
  342. //unset_session_resources();
  343. edit_added_resources("Ad_Valvas", $announcement_to_modify);
  344. $to=load_edit_users("announcement", $announcement_to_modify);
  345. }
  346. $display_announcement_list = false;
  347. }
  348. if ($to=="everyone" OR !empty($_SESSION['toolgroup']))
  349. {
  350. $_SESSION['select_groupusers']="hide";
  351. }
  352. else
  353. {
  354. $_SESSION['select_groupusers']="show";
  355. }
  356. }
  357. /*
  358. -----------------------------------------------------------
  359. Move announcement up/down
  360. -----------------------------------------------------------
  361. */
  362. if ($_GET['down'])
  363. {
  364. $thisAnnouncementId = intval($_GET['down']);
  365. $sortDirection = "DESC";
  366. }
  367. if ($_GET['up'])
  368. {
  369. $thisAnnouncementId = intval($_GET['up']);
  370. $sortDirection = "ASC";
  371. }
  372. if ($sortDirection)
  373. {
  374. if (!in_array(trim(strtoupper($sortDirection)), array('ASC', 'DESC')))
  375. {
  376. $sortDirection='ASC';
  377. }
  378. $my_sql = "SELECT announcement.id, announcement.display_order " .
  379. "FROM $tbl_announcement announcement, " .
  380. "$tbl_item_property itemproperty " .
  381. "WHERE itemproperty.ref=announcement.id " .
  382. "AND itemproperty.tool='".TOOL_ANNOUNCEMENT."' " .
  383. "AND itemproperty.visibility<>2 " .
  384. "ORDER BY display_order $sortDirection";
  385. $result = api_sql_query($my_sql,__FILE__,__LINE__);
  386. while (list ($announcementId, $announcementOrder) = mysql_fetch_row($result))
  387. {
  388. // STEP 2 : FOUND THE NEXT ANNOUNCEMENT ID AND ORDER.
  389. // COMMIT ORDER SWAP ON THE DB
  390. if (isset ($thisAnnouncementOrderFound) && $thisAnnouncementOrderFound == true)
  391. {
  392. $nextAnnouncementId = $announcementId;
  393. $nextAnnouncementOrder = $announcementOrder;
  394. api_sql_query("UPDATE $tbl_announcement " .
  395. "SET display_order = '$nextAnnouncementOrder' " .
  396. "WHERE id = '$thisAnnouncementId'",__FILE__,__LINE__);
  397. api_sql_query("UPDATE $tbl_announcement " .
  398. "SET display_order = '$thisAnnouncementOrder' " .
  399. "WHERE id = '$nextAnnouncementId.'",__FILE__,__LINE__);
  400. break;
  401. }
  402. // STEP 1 : FIND THE ORDER OF THE ANNOUNCEMENT
  403. if ($announcementId == $thisAnnouncementId)
  404. {
  405. $thisAnnouncementOrder = $announcementOrder;
  406. $thisAnnouncementOrderFound = true;
  407. }
  408. }
  409. // show message
  410. $message = get_lang('AnnouncementMoved');
  411. }
  412. /*
  413. -----------------------------------------------------------
  414. Submit announcement
  415. -----------------------------------------------------------
  416. */
  417. if (api_is_allowed_to_edit() OR (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous()))
  418. {
  419. $emailTitle=$_POST['emailTitle'];
  420. $newContent=$_POST['newContent'];
  421. $submitAnnouncement=isset($_POST['submitAnnouncement'])?$_POST['submitAnnouncement']:0;
  422. $id=intval($_POST['id']);
  423. if ($submitAnnouncement)
  424. {
  425. if(isset($id)&&$id) // there is an Id => the announcement already exists => update mode
  426. {
  427. $edit_id = edit_advalvas_item($id,$emailTitle,$newContent,$_POST['selectedform']);
  428. if(!$delete)
  429. {
  430. update_added_resources("Ad_Valvas", $id);
  431. }
  432. $message = get_lang('AnnouncementModified');
  433. }
  434. else //insert mode
  435. {
  436. if(!$surveyid){
  437. $result = api_sql_query("SELECT MAX(display_order) FROM $tbl_announcement",__FILE__,__LINE__);
  438. list($orderMax) = mysql_fetch_row($result);
  439. $order = $orderMax + 1;
  440. if(!empty($_SESSION['toolgroup'])){
  441. //$insert_id=store_advalvas_item($_POST['emailTitle'],$_POST['newContent'],$order,array('GROUP:'.$_SESSION['toolgroup']));
  442. $insert_id=store_advalvas_group_item($_POST['emailTitle'],$_POST['newContent'],$order,array('GROUP:'.$_SESSION['toolgroup']),$_POST['selectedform']);
  443. }else{
  444. $insert_id=store_advalvas_item($_POST['emailTitle'],$_POST['newContent'],$order,$_POST['selectedform']);
  445. }
  446. store_resources($_SESSION['source_type'],$insert_id);
  447. $_SESSION['select_groupusers']="hide";
  448. $message = get_lang('AnnouncementAdded');
  449. }
  450. /*============================================================
  451. MAIL WHEN USER COMES FROM SURVEY
  452. ======================================================= */
  453. if($_POST['emailsAdd'])
  454. {
  455. $to_email_address =$_POST['emailsAdd'];
  456. $to_email_to = explode(',', $to_email_address);
  457. $to_email = array_unique($to_email_to);
  458. $db_name = $_REQUEST['db_name'];
  459. for($i=0;$i<count($to_email);$i++)
  460. {
  461. $to= trim($to_email[$i]);
  462. $db_name = $_REQUEST['db_name'];
  463. $newContentone=str_replace("#page#","choose_language.php",$newContent);
  464. $newContenttwo=str_replace("#temp#",$template,$newContentone);
  465. $newContentthree=str_replace("#sid#",$surveyid,$newContenttwo);
  466. $newContentfour=str_replace("#mail#",$to,$newContentthree);
  467. $newContentfive=str_replace("#db_name#",$db_name,$newContentfour);
  468. $newContentsix=str_replace("#uid#","",$newContentfive);
  469. 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 ))
  470. {
  471. $subject=stripslashes($emailTitle);
  472. $message=stripslashes($newContentsix);
  473. $sender_name = $_SESSION['_user']['lastName'].' '.$_SESSION['_user']['firstName'];
  474. $email = $_SESSION['_user']['mail'];
  475. $headers="From:$sender_name\r\nReply-to: $email\r\nContent-type: text/html; charset=iso-8859-15";
  476. //@mail($to,$subject,$message,$headers);
  477. //api_send_mail($to,$subject,$message,$headers);
  478. api_mail('',$to,$subject,$message,$sender_name,$email,$headers);
  479. $sql_date="SELECT * FROM $db_name.survey WHERE survey_id='$surveyid'";
  480. $res_date=api_sql_query($sql_date);
  481. $obj_date=mysql_fetch_object($res_date);
  482. $end_date=$obj_date->avail_till;
  483. $table_reminder = Database :: get_main_table(TABLE_MAIN_SURVEY_REMINDER);
  484. if($_REQUEST['reminder']=="1")
  485. {
  486. $time=getdate();
  487. $time = $time['yday'];
  488. $time = $time+7;
  489. $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')";
  490. api_sql_query($sql_insert);
  491. }
  492. else if($_REQUEST['reminder']=="2")
  493. {
  494. $time=getdate();
  495. $time = $time['yday'];
  496. $time = $time+14;
  497. $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')";
  498. api_sql_query($sql_insert);
  499. }
  500. else if($_REQUEST['reminder']=="3")
  501. {
  502. $time=getdate();
  503. $time = $time['yday'];
  504. $time = $time+30;
  505. $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')";
  506. api_sql_query($sql_insert);
  507. }
  508. }
  509. }
  510. }
  511. /*===================================================================
  512. MAIL FUNCTION
  513. ===================================================================*/
  514. if ($_POST['email_ann'] && empty($_POST['onlyThoseMails']))
  515. {
  516. $sent_to=sent_to("announcement", $insert_id);
  517. $userlist = $sent_to['users'];
  518. $grouplist = $sent_to['groups'];
  519. // groepen omzetten in users
  520. if ($grouplist)
  521. {
  522. $grouplist = "'".implode("', '",$grouplist)."'"; //protect individual elements with surrounding quotes
  523. $sql = "SELECT user_id
  524. FROM $tbl_groupUser gu
  525. WHERE gu.group_id IN (".$grouplist.")";
  526. $groupMemberResult = api_sql_query($sql,__FILE__,__LINE__);
  527. if ($groupMemberResult)
  528. {
  529. while ($u = mysql_fetch_array($groupMemberResult))
  530. {
  531. $userlist [] = $u ['user_id']; // complete the user id list ...
  532. }
  533. }
  534. }
  535. if(is_array($userlist))
  536. {
  537. $userlist = "'".implode("', '", array_unique($userlist) )."'";
  538. // send to the created 'userlist'
  539. $sqlmail = "SELECT user_id, lastname, firstname, email
  540. FROM $tbl_user
  541. WHERE user_id IN (".$userlist.")";
  542. }
  543. else if(empty($_POST['not_selected_form']))
  544. {
  545. if(empty($_SESSION['id_session']) || api_get_setting('use_session_mode')=='false')
  546. {
  547. // send to everybody
  548. $sqlmail = "SELECT user.user_id, user.email, user.lastname, user.firstname
  549. FROM $tbl_course_user, $tbl_user
  550. WHERE course_code='".mysql_real_escape_string($_course['sysCode'])."'
  551. AND course_rel_user.user_id = user.user_id";
  552. }
  553. else
  554. {
  555. $sqlmail = "SELECT user.user_id, user.email, user.lastname, user.firstname
  556. FROM $tbl_user
  557. INNER JOIN $tbl_session_course_user
  558. ON $tbl_user.user_id = $tbl_session_course_user.id_user
  559. AND $tbl_session_course_user.course_code = '".$_course['id']."'
  560. AND $tbl_session_course_user.id_session = ".intval($_SESSION['id_session']);
  561. }
  562. }
  563. if($sqlmail!=''){
  564. $result = api_sql_query($sqlmail,__FILE__,__LINE__);
  565. /*=================================================================================
  566. send email one by one to avoid antispam
  567. =================================================================================*/
  568. while ($myrow = mysql_fetch_array($result))
  569. {
  570. /* Header : Bericht van uw lesgever - GES ($_cid)
  571. Body : John Doe (prenom + nom) <john_doe@hotmail.com> (email)
  572. Morgen geen les!! (emailTitle)
  573. Morgen is er geen les, de les wordt geschrapt wegens vergadering (newContent)
  574. */
  575. $emailsubjbericht = api_is_allowed_to_edit() ? get_lang('professorMessage') : get_lang('LearnerMessage');
  576. $emailSubject = $emailsubjbericht. " - ".$_course['official_code'];
  577. $emailSubject = $emailTitle;
  578. $db_name = Database::get_course_table(TABLE_MAIN_SURVEY);
  579. if($surveyid) {
  580. $newContentone=str_replace("#page#","choose_language.php",$newContent);
  581. $newContenttwo=str_replace("#temp#",$template,$newContentone);
  582. $newContentthree=str_replace("#sid#",$surveyid,$newContenttwo);
  583. $newContentfour=str_replace("#mail#",$myrow["email"],$newContentthree);
  584. $newContentfive=str_replace("#db_name#",$db_name,$newContentfour);
  585. $newContentsix=str_replace("#uid#",$myrow["user_id"],$newContentfive);
  586. $message=stripslashes($newContentsix);
  587. $sender_name = $_SESSION['_user']['lastName'].' '.$_SESSION['_user']['firstName'];
  588. $email = $_SESSION['_user']['mail'];
  589. $headers="From:$sender_name\r\nReply-to: $email\r\nContent-type: text/html; charset=iso-8859-15";
  590. //@mail($myrow["email"],stripslashes($emailTitle),$message,$headers);
  591. api_mail('',$myrow["email"],stripslashes($emailTitle),$message,$sender_name,$email);
  592. }
  593. else{
  594. $mail_body = $myrow["lastname"]." ".$myrow["firstname"]." <".$myrow["email"]."><br /> \n\n".stripslashes($emailTitle)."<br />".trim(stripslashes($newContent))." <br /><br />-- <br />";
  595. $mail_body .= $_user['firstName'].' '.$_user['lastName']." ";
  596. $mail_body .= "<".$_user['mail'].">\n";
  597. $mail_body .= $_course['official_code'].' '.$_course['name'];
  598. //set the charset and use it for the encoding of the email - small fix, not really clean (should check the content encoding origin first)
  599. //here we use the encoding used for the webpage where the text is encoded (ISO-8859-1 in this case)
  600. //$to_email_address =$_POST['emailsAdd'];
  601. //$mail_body;
  602. $headers = array();
  603. if(empty($charset)){$charset='ISO-8859-1';}
  604. $headers['Content-Type'] = 'text/html';
  605. $headers['charset'] = $charset;
  606. $mailid=$myrow["email"];
  607. $newmail = api_mail_html($myrow["lastname"].' '.$myrow["firstname"], $myrow["email"], $emailSubject, $mail_body, $_SESSION['_user']['lastName'].' '.$_SESSION['_user']['firstName'], $_SESSION['_user']['mail'],$headers);
  608. }
  609. $sql_date="SELECT * FROM $db_name WHERE survey_id='$surveyid'";
  610. $res_date=api_sql_query($sql_date);
  611. $obj_date=mysql_fetch_object($res_date);
  612. $end_date=$obj_date->avail_till;
  613. $table_reminder = Database :: get_main_table(TABLE_MAIN_SURVEY_REMINDER);
  614. if($_REQUEST['reminder']=="1")
  615. {
  616. $time=getdate();
  617. $time = $time['yday'];
  618. $time = $time+7;
  619. $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')";
  620. api_sql_query($sql);
  621. }
  622. else if($_REQUEST['reminder']=="2")
  623. {
  624. $time=getdate();
  625. $time = $time['yday'];
  626. $time = $time+14;
  627. $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')";
  628. api_sql_query($sql);
  629. }
  630. else if($_REQUEST['reminder']=="3")
  631. {
  632. $time=getdate();
  633. $time = $time['yday'];
  634. $time = $time+30;
  635. $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')";
  636. api_sql_query($sql);
  637. }
  638. }
  639. update_mail_sent($insert_id);
  640. $message = $added_and_sent;
  641. }
  642. } // $email_ann*/
  643. } // isset
  644. // UNSET VARIABLES
  645. unset_session_resources();
  646. unset($form_elements);
  647. $_SESSION['formelements']=null;
  648. $newContent = null;
  649. $emailTitle = null;
  650. unset($emailTitle);
  651. unset($newContent);
  652. unset($content_to_modify);
  653. unset($title_to_modify);
  654. if($_REQUEST['publish_survey'])
  655. {
  656. $surveyid=$_REQUEST['surveyid'];
  657. $cidReq = $_REQUEST['cidReq'];
  658. ?>
  659. <script>
  660. window.location.href="../survey/survey_list.php?<?php echo api_get_cidreq(); ?>&published=published&surveyid=<?php echo $_REQUEST['publish_survey']; ?>";
  661. </script>
  662. <?php
  663. }
  664. } // if $submit Announcement
  665. }
  666. }
  667. /*====================================================
  668. Tool Title
  669. ====================================================*/
  670. if ($_GET['origin'] !== 'learnpath')
  671. {
  672. //api_display_tool_title($nameTools);
  673. Display::display_introduction_section(TOOL_ANNOUNCEMENT, $is_allowed);
  674. }
  675. /*
  676. ==============================================================================
  677. MAIN SECTION
  678. ==============================================================================
  679. */
  680. /*=====================================================================================
  681. MAIN CODE HTML
  682. =====================================================================================*/
  683. // The commands below will change these display settings if they need it
  684. if ($_GET['origin'] !== 'learnpath')
  685. {
  686. echo "\n\n<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
  687. echo "\t<tr>\n";
  688. echo "\t\t<td width=\"20%\" valign=\"top\">\n";
  689. }
  690. /*======================================================================
  691. DISPLAY LEFT COLUMN
  692. ======================================================================*/
  693. if(api_is_allowed_to_edit() OR (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous()) ) // check teacher status
  694. {
  695. if ($_GET['origin'] !== 'learnpath')
  696. {
  697. $sql="SELECT
  698. announcement.*, toolitemproperties.*
  699. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  700. WHERE announcement.id = toolitemproperties.ref
  701. AND toolitemproperties.tool='announcement'
  702. AND toolitemproperties.visibility<>'2'
  703. GROUP BY toolitemproperties.ref
  704. ORDER BY display_order DESC
  705. LIMIT 0,$maximum";
  706. }
  707. }
  708. else // students only get to see the visible announcements
  709. {
  710. if ($_GET['origin'] !== 'learnpath')
  711. {
  712. $group_memberships=GroupManager::get_group_ids($_course['dbName'], $_user['user_id']);
  713. // the user is member of several groups => display personal announcements AND his group announcements AND the general announcements
  714. if (is_array($group_memberships))
  715. {
  716. $sql="SELECT
  717. announcement.*, toolitemproperties.*
  718. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  719. WHERE announcement.id = toolitemproperties.ref
  720. AND toolitemproperties.tool='announcement'
  721. AND toolitemproperties.visibility='1'
  722. AND ( toolitemproperties.to_user_id='".$_user['user_id']."'" .
  723. "OR toolitemproperties.to_group_id IN (0, ".implode(", ", $group_memberships).") )
  724. GROUP BY toolitemproperties.ref
  725. ORDER BY display_order DESC
  726. LIMIT 0,$maximum";
  727. }
  728. // the user is not member of any group
  729. else
  730. {
  731. // this is an identified user => show the general announcements AND his personal announcements
  732. if ($_user['user_id'])
  733. {
  734. $sql="SELECT
  735. announcement.*, toolitemproperties.*
  736. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  737. WHERE announcement.id = toolitemproperties.ref
  738. AND toolitemproperties.tool='announcement'
  739. AND toolitemproperties.visibility='1'
  740. AND ( toolitemproperties.to_user_id='".$_user['user_id']."' OR toolitemproperties.to_group_id='0')
  741. GROUP BY toolitemproperties.ref
  742. ORDER BY display_order DESC
  743. LIMIT 0,$maximum";
  744. }
  745. // the user is not identiefied => show only the general announcements
  746. else
  747. {
  748. $sql="SELECT
  749. announcement.*, toolitemproperties.*
  750. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  751. WHERE announcement.id = toolitemproperties.ref
  752. AND toolitemproperties.tool='announcement'
  753. AND toolitemproperties.visibility='1'
  754. AND toolitemproperties.to_group_id='0'
  755. GROUP BY toolitemproperties.ref
  756. ORDER BY display_order DESC
  757. LIMIT 0,$maximum";
  758. }
  759. }
  760. }
  761. }
  762. $result = api_sql_query($sql,__FILE__,__LINE__);
  763. $announcement_number = mysql_num_rows($result);
  764. /*----------------------------------------------------
  765. ADD ANNOUNCEMENT / DELETE ALL
  766. ----------------------------------------------------*/
  767. if(!$surveyid)
  768. {
  769. if ((api_is_allowed_to_edit() OR (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) and ($_GET['origin'] !== 'learnpath'))
  770. {
  771. echo "<a href='".api_get_self()."?".api_get_cidreq()."&action=add&origin=".$_GET['origin']."'><img src=\"../img/announce_add.gif\"> ".get_lang("AddAnnouncement")."</a><br/>";
  772. }
  773. if (api_is_allowed_to_edit() && $announcement_number > 1)
  774. {
  775. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&action=delete_all\" onclick=\"javascript:if(!confirm('".get_lang("ConfirmYourChoice")."')) return false;\"><img src=\"../img/valves_delete.gif\"/> ".get_lang("AnnouncementDeleteAll")."</a>\n";
  776. } // if announcementNumber > 1
  777. echo "<hr noshade size=\"1\">";
  778. }
  779. /*----------------------------------------------------
  780. ANNOUNCEMENTS LIST
  781. ----------------------------------------------------*/
  782. if(!$surveyid)
  783. {
  784. if ($display_title_list == true)
  785. {
  786. echo "\t\t\t<table>\n";
  787. while ($myrow = mysql_fetch_array($result))
  788. {
  789. $title = $myrow['title'];
  790. echo "\t\t\t\t<tr>\n";
  791. echo "\t\t\t\t\t<td width=\"15%\">\n";
  792. if ($myrow['visibility']==0)
  793. { $class="class=\"invisible\"";}
  794. else
  795. { $class="";}
  796. echo "\t\t\t\t\t\t<a style=\"text-decoration:none\" href=\"announcements.php?".api_get_cidreq()."#".$myrow['id']."\" ".$class.">" . api_trunc_str($title,$length) . "</a>\n";
  797. echo "\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
  798. }
  799. echo "\t\t\t</table>\n";
  800. } // end $display_title_list == true
  801. }
  802. if ($_GET['origin'] !== 'learnpath')
  803. {
  804. echo "\t\t</td>\n";
  805. echo "\t\t<td width=\"20\" background=\"../img/verticalruler.gif\">&nbsp;</td>\n";
  806. // START RIGHT PART
  807. echo "\t\t<td valign=\"top\">\n";
  808. }
  809. /*=======================================
  810. DISPLAY ACTION MESSAGE
  811. =======================================*/
  812. if ($message == true)
  813. {
  814. Display::display_normal_message($message);
  815. $display_announcement_list = true;
  816. $display_form = false;
  817. }
  818. /*==================================================================================
  819. DISPLAY FORM
  820. ==================================================================================*/
  821. if ($display_form == true)
  822. {
  823. $content_to_modify=stripslashes($content_to_modify);
  824. $title_to_modify=stripslashes($title_to_modify);
  825. // DISPLAY ADD ANNOUNCEMENT COMMAND
  826. echo "<form method=\"post\" name=\"f1\" action=\"".api_get_self()."?publish_survey=$surveyid&id=".$_GET['id']."&db_name=$db_name&cidReq=".$_GET['cidReq']."&action=".$_GET['action']."\" style=\"margin:0px;\">\n";
  827. //this variable defines if the course administrator can send a message to a specific user / group
  828. // or not
  829. //echo "sessiewaarde: ".$_SESSION['select_groupusers'];
  830. if(empty($_SESSION['toolgroup'])){
  831. echo "<table><tr><td>";
  832. echo get_lang("SentTo").": ";
  833. echo "</td><td>";
  834. if(isset($_GET['id']) && is_array($to)){
  835. echo '&nbsp;';
  836. }
  837. elseif(isset($_GET['remind_inactive']))
  838. {
  839. $email_ann = '1';
  840. $_SESSION['select_groupusers']="show";
  841. $content_to_modify = sprintf(get_lang('RemindInactiveLearnersMailContent'),api_get_setting('siteName'), 7);
  842. $title_to_modify = sprintf(get_lang('RemindInactiveLearnersMailSubject'),api_get_setting('siteName'));
  843. }
  844. elseif(isset($_GET['remindallinactives']) && $_GET['remindallinactives']=='true')
  845. {
  846. $since = isset($_GET['since']) ? intval($_GET['since']) : 6;
  847. $to = Tracking :: get_inactives_students_in_course($_course['id'],$since, $_SESSION['id_session']);
  848. foreach($to as &$user)
  849. {
  850. $user = 'USER:'.$user;
  851. }
  852. $_SESSION['select_groupusers']="show";
  853. $email_ann = '1';
  854. $content_to_modify = sprintf(get_lang('RemindInactiveLearnersMailContent'),api_get_setting('siteName'),$since);
  855. $title_to_modify = sprintf(get_lang('RemindInactiveLearnersMailSubject'),api_get_setting('siteName'));
  856. //echo '&nbsp;<script type="text/javascript">document.onload = "document.getElementById(\'recipient_list\').style.display=\'block\'";</script>';
  857. }
  858. else{
  859. echo get_lang("Everybody");
  860. }
  861. echo "</td><td>";
  862. echo '<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').'</span>';
  863. echo "</td></tr></table>";
  864. show_to_form($to);
  865. echo "<br /><br />";
  866. if (!isset($announcement_to_modify) ) $announcement_to_modify ="";
  867. if ($announcement_to_modify=='')
  868. {
  869. ($email_ann=='1')?$checked='checked':$checked='';
  870. echo "<input class=\"checkbox\" type=checkbox value=\"1\" name=\"email_ann\" $checked> ".get_lang('EmailOption')," : ",
  871. "<br /><br />";
  872. }
  873. }else{
  874. if (!isset($announcement_to_modify) ) $announcement_to_modify ="";
  875. if ($announcement_to_modify=='')
  876. {
  877. ($email_ann=='1' || !empty($surveyid))?$checked='checked':$checked='';
  878. echo "<input class=\"checkbox\" type=checkbox value=\"1\" name=\"email_ann\" $checked> ".get_lang('EmailOption')," : ".get_lang('MyGroup'),
  879. "<br><br>";
  880. echo '<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>';
  881. show_to_form_group($_SESSION['toolgroup']);
  882. echo '<br><br>';
  883. }
  884. }
  885. if($surveyid){
  886. echo get_lang('EmailAddress').": <input type=\"text\" name=\"emailsAdd\" value=\"".$emails_add."\" size=\"52\">(Comma separated for multiple)<br>";
  887. echo get_lang('OnlyThoseAddresses').": <input type=\"checkbox\" name=\"onlyThoseMails\"><br>";
  888. }
  889. echo get_lang('EmailTitle').": <input type=\"text\" name=\"emailTitle\" value=\"".$title_to_modify."\" size=\"52\"><br />";
  890. unset($title_to_modify);
  891. $title_to_modify = null;
  892. if (!isset($announcement_to_modify) ) $announcement_to_modify ="";
  893. if (!isset($content_to_modify) ) $content_to_modify ="";
  894. if (!isset($title_to_modify)) $title_to_modify = "";
  895. echo "<br />\n<input type=\"hidden\" name=\"id\" value=\"".$announcement_to_modify."\">";
  896. if($surveyid){
  897. $content_to_modify='<br /><a href="'.api_get_path(WEB_CODE_PATH).'/survey/#page#?temp=#temp#&surveyid=#sid#&uid=#uid#&mail=#mail#&db_name=#db_name">'.get_lang('ClickHereToOpenSurvey').'</a><br />
  898. '.get_lang('OrCopyPasteUrl').' <br />
  899. '.api_get_path(WEB_CODE_PATH).'/survey/#page#?temp=#temp#&surveyid=#sid#&uid=#uid#&mail=#mail#&db_name=#db_name&nbsp';
  900. }
  901. //api_disp_html_area('newContent',$content_to_modify,'250px');
  902. require_once(api_get_path(LIBRARY_PATH) . "/fckeditor/fckeditor.php");
  903. $oFCKeditor = new FCKeditor('newContent') ;
  904. $oFCKeditor->BasePath = api_get_path(WEB_PATH) . 'main/inc/lib/fckeditor/' ;
  905. $oFCKeditor->Height = '250';
  906. $oFCKeditor->Width = '100%';
  907. $oFCKeditor->Value = $content_to_modify;
  908. $oFCKeditor->Config['CustomConfigurationsPath'] = api_get_path(REL_PATH)."main/inc/lib/fckeditor/myconfig.js";
  909. $oFCKeditor->ToolbarSet = "Announcements";
  910. $TBL_LANGUAGES = Database::get_main_table(TABLE_MAIN_LANGUAGE);
  911. $sql="SELECT isocode FROM ".$TBL_LANGUAGES." WHERE english_name='".$_SESSION["_course"]["language"]."'";
  912. $result_sql=api_sql_query($sql);
  913. $isocode_language=mysql_result($result_sql,0,0);
  914. $oFCKeditor->Config['DefaultLanguage'] = $isocode_language;
  915. echo $oFCKeditor->CreateHtml();
  916. if(empty($_SESSION['toolgroup'])){
  917. echo '<br /><input type="Submit" name="submitAnnouncement" value="'.get_lang('Ok').'" onclick="selectAll(this.form.elements[3],true)" /><br /><br />';
  918. }
  919. else{
  920. echo '<br /><input type="Submit" name="submitAnnouncement" value="'.get_lang('Ok').'" onclick="selectAll(this.form.elements[4],true)" /><br /><br />';
  921. }
  922. echo '</form><br />';
  923. if((isset($_GET['action']) && isset($_GET['id']) && is_array($to))||isset($_GET['remindallinactives'])||isset($_GET['remind_inactive'])){
  924. echo '<script>document.getElementById(\'recipient_list\').style.display=\'block\';</script>';
  925. }
  926. } // displayform
  927. /*===============================================
  928. DISPLAY ANNOUNCEMENT LIST
  929. ===============================================*/
  930. if ($display_announcement_list && !$surveyid)
  931. {
  932. // 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
  933. $user_id=$_user['user_id'];
  934. if ($_SESSION['user']!==null)
  935. {
  936. $user_id=$_SESSION['user'];
  937. }
  938. if ($_SESSION['group']!==null)
  939. {
  940. $group_id=$_SESSION['group'];
  941. }
  942. //$group_memberships=GroupManager::get_group_ids($_course['dbName'], $_user['user_id']);
  943. $group_memberships=GroupManager::get_group_ids($_course['dbName'],$_user['user_id']);
  944. if (api_is_allowed_to_edit() )
  945. {
  946. // A.1. you are a course admin with a USER filter
  947. // => see only the messages of this specific user + the messages of the group (s)he is member of.
  948. if ($_SESSION['user']!==null)
  949. {
  950. if (is_array($group_memberships))
  951. {
  952. $sql="SELECT
  953. announcement.*, toolitemproperties.*
  954. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  955. WHERE announcement.id = toolitemproperties.ref
  956. AND toolitemproperties.tool='announcement'
  957. AND (toolitemproperties.to_user_id=$user_id OR toolitemproperties.to_group_id IN (0, ".implode(", ", $group_memberships).") )
  958. ORDER BY display_order DESC";
  959. }
  960. else
  961. {
  962. $sql="SELECT
  963. announcement.*, toolitemproperties.*
  964. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  965. WHERE announcement.id = toolitemproperties.ref
  966. AND toolitemproperties.tool='announcement'
  967. AND (toolitemproperties.to_user_id=$user_id OR toolitemproperties.to_group_id='0')
  968. AND toolitemproperties.visibility='1'
  969. ORDER BY display_order DESC";
  970. }
  971. }
  972. // A.2. you are a course admin with a GROUP filter
  973. // => see only the messages of this specific group
  974. elseif ($_SESSION['group']!==null)
  975. {
  976. $sql="SELECT
  977. announcement.*, toolitemproperties.*
  978. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  979. WHERE announcement.id = toolitemproperties.ref
  980. AND toolitemproperties.tool='announcement'
  981. AND (toolitemproperties.to_group_id=$group_id OR toolitemproperties.to_group_id='0')
  982. GROUP BY toolitemproperties.ref
  983. ORDER BY display_order DESC";
  984. }
  985. // A.3 you are a course admin without any group or user filter
  986. else
  987. {
  988. // A.3.a you are a course admin without user or group filter but WITH studentview
  989. // => see all the messages of all the users and groups without editing possibilities
  990. if ($isStudentView=="true")
  991. {
  992. $sql="SELECT
  993. announcement.*, toolitemproperties.*
  994. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  995. WHERE announcement.id = toolitemproperties.ref
  996. AND toolitemproperties.tool='announcement'
  997. AND toolitemproperties.visibility='1'
  998. GROUP BY toolitemproperties.ref
  999. ORDER BY display_order DESC";
  1000. }
  1001. // A.3.a you are a course admin without user or group filter and WTIHOUT studentview (= the normal course admin view)
  1002. // => see all the messages of all the users and groups with editing possibilities
  1003. else
  1004. {
  1005. $sql="SELECT
  1006. announcement.*, toolitemproperties.*
  1007. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  1008. WHERE announcement.id = toolitemproperties.ref
  1009. AND toolitemproperties.tool='announcement'
  1010. AND (toolitemproperties.visibility='0' or toolitemproperties.visibility='1')
  1011. GROUP BY toolitemproperties.ref
  1012. ORDER BY display_order DESC";
  1013. }
  1014. }
  1015. }
  1016. else //STUDENT
  1017. {
  1018. if (is_array($group_memberships))
  1019. {
  1020. $sql="SELECT
  1021. announcement.*, toolitemproperties.*
  1022. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  1023. WHERE announcement.id = toolitemproperties.ref
  1024. AND toolitemproperties.tool='announcement'
  1025. AND (toolitemproperties.to_user_id=$user_id OR toolitemproperties.to_group_id IN (0, ".implode(", ", $group_memberships).") )
  1026. AND toolitemproperties.visibility='1'
  1027. ORDER BY display_order DESC";
  1028. }
  1029. else
  1030. {
  1031. if ($_user['user_id'])
  1032. {
  1033. $sql="SELECT
  1034. announcement.*, toolitemproperties.*
  1035. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  1036. WHERE announcement.id = toolitemproperties.ref
  1037. AND toolitemproperties.tool='announcement'
  1038. AND (toolitemproperties.to_user_id='".$_user['user_id']."' OR toolitemproperties.to_group_id='0')
  1039. AND toolitemproperties.visibility='1'
  1040. ORDER BY display_order DESC";
  1041. }
  1042. else
  1043. {
  1044. $sql="SELECT
  1045. announcement.*, toolitemproperties.*
  1046. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  1047. WHERE announcement.id = toolitemproperties.ref
  1048. AND toolitemproperties.tool='announcement'
  1049. AND toolitemproperties.to_group_id='0'
  1050. AND toolitemproperties.visibility='1'";
  1051. }
  1052. }
  1053. }
  1054. $result = api_sql_query($sql,__FILE__,__LINE__);
  1055. $num_rows = mysql_num_rows($result);
  1056. /*=================================================
  1057. DISPLAY: NO ITEMS
  1058. =================================================*/
  1059. if ($num_rows == 0)
  1060. {
  1061. echo "<table><tr><td>".get_lang('NoAnnouncements')."</td></tr></table>";
  1062. }
  1063. $iterator = 1;
  1064. $bottomAnnouncement = $announcement_number;
  1065. echo "\t\t\t<table width=\"100%\" border=\"1\" cellpadding=\"5\" cellspacing=\"0\" id=\"agenda_list\">\n";
  1066. $displayed=array();
  1067. while ($myrow = mysql_fetch_array($result))
  1068. {
  1069. if (!in_array($myrow['id'], $displayed))
  1070. {
  1071. $title = $myrow['title'];
  1072. $content = $myrow['content'];
  1073. $content = make_clickable($content);
  1074. $content = text_filter($content);
  1075. /*================================================
  1076. DATE
  1077. ================================================*/
  1078. $last_post_datetime = $myrow['end_date'];
  1079. list($last_post_date, $last_post_time) = split(" ", $last_post_datetime);
  1080. list($year, $month, $day) = explode("-", $last_post_date);
  1081. list($hour, $min) = explode(":", $last_post_time);
  1082. $announceDate = mktime((int)$hour, (int)$min, 0, (int)$month, (int)$day, (int)$year);
  1083. // the styles
  1084. if ($myrow['visibility']=='0')
  1085. {
  1086. $style="data_hidden";
  1087. $stylenotbold="datanotbold_hidden";
  1088. $text_style="text_hidden";
  1089. }
  1090. else
  1091. {
  1092. $style="data";
  1093. $stylenotbold="datanotbold";
  1094. $text_style="text";
  1095. }
  1096. echo "\t\t\t\t<tr class=\"".$style."\">";
  1097. /*===================================================================
  1098. THE ICONS
  1099. ===================================================================*/
  1100. echo "\t\t\t\t\t<td>\n";
  1101. // anchoring
  1102. echo "<a name=\"".(int)($myrow["id"])."\"></a>\n";
  1103. // User or group icon
  1104. if ($myrow['to_group_id']!== '0' and $myrow['to_group_id']!== 'NULL')
  1105. {
  1106. echo "\t\t\t\t\t\t<img alt=\"$alt_ug\" src='../img/group.gif'>\n";
  1107. }
  1108. // the email icon
  1109. if ($myrow['email_sent'] == '1')
  1110. {
  1111. echo "\t\t\t\t\t\t<img alt=\"$alt_mail\" src='../img/email.gif'>\n";
  1112. }
  1113. echo "\t\t\t\t\t</td>\n";
  1114. /*==================================================================
  1115. TITLE
  1116. ==================================================================*/
  1117. echo "\t\t\t\t\t<td>".$title."</td>\n";
  1118. /*==================================================================
  1119. SENT TO
  1120. ===================================================================*/
  1121. echo "\t\t\t\t\t<td class=\"".$stylenotbold."\">" . get_lang("SentTo") . " : &nbsp; ";
  1122. $sent_to=sent_to("announcement", $myrow['id']);
  1123. $sent_to_form=sent_to_form($sent_to);
  1124. $user_info=api_get_user_info($myrow['insert_user_id']);
  1125. echo '&nbsp;&nbsp;&nbsp;'.get_lang('By').' : &nbsp;'.$user_info['lastName'].'&nbsp;'.$user_info['firstName'];
  1126. echo "\t\t\t\t\t</td>\n","\t\t\t\t</tr>\n";
  1127. /*=========================================================
  1128. TITLE
  1129. =========================================================*/
  1130. echo "\t\t\t\t<tr>\n",
  1131. "\t\t\t\t\t<td class=\"announcements_datum\" colspan=\"3\">",
  1132. get_lang('AnnouncementPublishedOn')," : ",ucfirst(format_locale_date($dateFormatLong,strtotime($last_post_date))),
  1133. "</td>\n",
  1134. "\t\t\t\t</tr>\n",
  1135. /*=========================================================
  1136. CONTENT
  1137. =========================================================*/
  1138. "\t\t\t\t<tr class=\"$text_style\">\n",
  1139. "\t\t\t\t\t<td colspan=\"3\">\n",
  1140. $content,
  1141. "\t\t\t\t\t</td>\n",
  1142. "\t\t\t\t</tr>\n",
  1143. /*========================================================
  1144. RESOURCES
  1145. ========================================================*/
  1146. "<tr>\n",
  1147. "<td colspan=\"3\">\n";
  1148. if (check_added_resources("Ad_Valvas", $myrow["id"]))
  1149. {
  1150. echo "<i>".get_lang('AddedResources')."</i><br />";
  1151. display_added_resources("Ad_Valvas", $myrow["id"]);
  1152. }
  1153. echo "<br />";
  1154. if(api_is_allowed_to_edit() OR (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous()))
  1155. {
  1156. /*=====================================================================
  1157. SHOW MOD/DEL/VIS FUNCTIONS
  1158. =====================================================================*/
  1159. echo "<table><tr>";
  1160. echo "<td valign=\"top\"><a href=\"".api_get_self()."?".api_get_cidreq()."&action=modify&id=".$myrow['id']."\">",
  1161. "<img src=\"../img/edit.gif\" title=\"",get_lang('Modify'),"\" border=\"0\" align=\"absmiddle\">",
  1162. "</a></td>";
  1163. if (api_is_allowed_to_edit()) echo "<td valign=\"top\"><a href=\"".api_get_self()."?".api_get_cidreq()."&action=delete&id=".$myrow['id']."\" onclick=\"javascript:if(!confirm('".addslashes(htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset))."')) return false;\">",
  1164. "<img src=\"../img/delete.gif\" title=\"",get_lang('Delete'),"\" border=\"0\" align=\"absmiddle\">",
  1165. "</a></td>";
  1166. if ($myrow['visibility']==1)
  1167. {
  1168. $image_visibility="visible";
  1169. }
  1170. else
  1171. {
  1172. $image_visibility="invisible";
  1173. }
  1174. echo "<td valign=\"top\"><a href=\"".api_get_self()."?".api_get_cidreq()."&origin=".$_GET['origin']."&action=showhide&id=".$myrow['id']."\">",
  1175. "<img src=\"../img/".$image_visibility.".gif\" border=\"0\" alt=\"".get_lang('Visible')."\"/></a></td>";
  1176. // DISPLAY MOVE UP COMMAND only if it is not the top announcement
  1177. if($iterator != 1)
  1178. {
  1179. echo "<td valign=\"top\"><a href=\"".api_get_self()."?".api_get_cidreq()."&up=",$myrow["id"],"\">",
  1180. "<img src=../img/up.gif border=0 title=\"".get_lang('Up')."\" align=\"absmiddle\">",
  1181. "</a></td>";
  1182. }
  1183. if($iterator < $bottomAnnouncement)
  1184. {
  1185. echo "<td valign=\"top\"><a href=\"".api_get_self()."?".api_get_cidreq()."&down=".$myrow["id"]."\">",
  1186. "<img src=\"../img/down.gif\" border=\"0\" title=\"".get_lang('Down')."\" align=\"absmiddle\">",
  1187. "</a></td>";
  1188. }
  1189. echo "</tr></table>";
  1190. echo "</td>\n",
  1191. "</tr>\n";
  1192. $iterator ++;
  1193. } // is_allowed_to_edit
  1194. echo "<tr><td width=\"100%\" colspan=\"3\"><a href=\"#top\"><img src=\"../img/top.gif\" border=\"0\" alt=\"To top\" align=\"right\"></a></td></tr>";
  1195. }
  1196. $displayed[]=$myrow['id'];
  1197. } // end while ($myrow = mysql_fetch_array($result))
  1198. echo "</table>";
  1199. } // end: if ($displayAnnoucementList)
  1200. echo "</table>";
  1201. if ($display_specific_announcement) display_announcement($announcement_id);
  1202. /*
  1203. ==============================================================================
  1204. FOOTER
  1205. ==============================================================================
  1206. */
  1207. if ($_GET['origin'] !== 'learnpath')
  1208. {
  1209. //we are not in learnpath tool
  1210. Display::display_footer();
  1211. }
  1212. ?>