announcements.php 49 KB

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