announcements.php 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484
  1. <?php //$Id: announcements.php 12263 2007-05-03 13:34:40Z elixir_julian $
  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 ($_GET['user'] or $_GET['group'])
  188. {
  189. $_SESSION['user']=$_GET['user'];
  190. $_SESSION['group']=$_GET['group'];
  191. }
  192. if ($_GET['user']=="none" or $_GET['group']=="none")
  193. {
  194. api_session_unregister("user");
  195. api_session_unregister("group");
  196. }
  197. if ($_GET['isStudentView']=="false")
  198. {
  199. api_session_unregister("user");
  200. api_session_unregister("group");
  201. }
  202. */
  203. if(!empty($_GET['toolgroup'])){
  204. if($_GET['toolgroup'] == strval(intval($_GET['toolgroup']))){ //check is integer
  205. $toolgroup = $_GET['toolgroup'];
  206. $_SESSION['select_groupusers'] = 'hide';
  207. }else{
  208. $toolgroup = 0;
  209. }
  210. api_session_register("toolgroup");
  211. }
  212. /*
  213. -----------------------------------------------------------
  214. Sessions
  215. -----------------------------------------------------------
  216. */
  217. if ($_SESSION['formelements'] and $_GET['originalresource'] == 'no')
  218. {
  219. $form_elements = $_SESSION['formelements'];
  220. $title_to_modify = $form_elements['emailTitle'];
  221. $content_to_modify = $form_elements['newContent'];
  222. $announcement_to_modify = $form_elements['id'];
  223. $to = $form_elements['to'];
  224. //load_edit_users('announcement',$announcement_to_modify);
  225. $email_ann = $form_elements['emailoption'];
  226. }
  227. /*
  228. -----------------------------------------------------------
  229. Survey
  230. -----------------------------------------------------------
  231. */
  232. $surveyid=$_REQUEST['publish_survey'];
  233. $cidReq=$_REQUEST['cidReq'];
  234. if($surveyid)
  235. {
  236. $db_name=$_REQUEST['db_name'];
  237. $sql_temp = "SELECT * FROM $db_name.survey WHERE survey_id='$surveyid'";
  238. $res_temp = api_sql_query($sql_temp, __FILE__, __LINE__);
  239. $obj=@mysql_fetch_object($res_temp);
  240. $template=$obj->template;
  241. }
  242. if($surveyid)
  243. {
  244. $interbreadcrumb[] = array ("url" => "../survey/survey_list.php?cidReq=$cidReq", "name" => get_lang('Survey'));
  245. $nameTools = get_lang('PublishSurvey');
  246. }
  247. else
  248. $nameTools = get_lang('Announcement');
  249. $nameTools12 = get_lang('PublishSurvey');
  250. /*
  251. -----------------------------------------------------------
  252. Learning path & css
  253. -----------------------------------------------------------
  254. */
  255. // showing the header if we are not in the learning path, if we are in
  256. // the learning path, we do not include the banner so we have to explicitly
  257. // include the stylesheet, which is normally done in the header
  258. if ($_GET['origin'] !== 'learnpath')
  259. {
  260. //we are not in the learning path
  261. Display::Display_header($nameTools,"Announcements");
  262. }
  263. else
  264. {
  265. //we are in the learning path, only display central data and change css
  266. $display_title_list = false;
  267. $display_announcement_list = false;
  268. $display_specific_announcement = true;
  269. $announcement_id = $_REQUEST['ann_id'];
  270. ?> <link rel="stylesheet" type="text/css" href="<?php echo $clarolineRepositoryWeb ?>css/default.css">
  271. <!-- css file for announcements -->
  272. <link href="../css/announcements.css" rel="stylesheet" type="text/css">
  273. <?php
  274. }
  275. // inserting an anchor (top) so one can jump back to the top of the page
  276. echo "<a name=\"top\"></a>";
  277. /*=============================================
  278. ACTION HANDLING
  279. =============================================*/
  280. if (api_is_allowed_to_edit() OR api_get_course_setting('allow_user_edit_announcement'))
  281. {
  282. /*
  283. -----------------------------------------------------------
  284. Change visibility of announcement
  285. -----------------------------------------------------------
  286. */
  287. // $_GET['isStudentView']<>"false" is added to prevent that the visibility
  288. // is changed after you do the following:
  289. // change visibility -> studentview -> course manager view
  290. if ($_GET['isStudentView']<>"false")
  291. {
  292. if (isset($_GET['id']) AND $_GET['id'] AND isset($_GET['action']) AND $_GET['action']=="showhide")
  293. {
  294. $id=intval(addslashes($_GET['id']));
  295. change_visibility(TOOL_ANNOUNCEMENT,$id);
  296. $message = get_lang("Visible");
  297. }
  298. }
  299. /*
  300. -----------------------------------------------------------
  301. Delete announcement
  302. -----------------------------------------------------------
  303. */
  304. if ($_GET['action']=="delete" AND isset($_GET['id']))
  305. {
  306. //api_sql_query("DELETE FROM $tbl_announcement WHERE id='$delete'",__FILE__,__LINE__);
  307. $id=intval(addslashes($_GET['id']));
  308. // tooledit : visibility = 2 : only visibile for platform administrator
  309. api_sql_query("UPDATE $tbl_item_property SET visibility='2' WHERE tool='".TOOL_ANNOUNCEMENT."' and ref='".$id."'",__FILE__,__LINE__);
  310. delete_added_resource("Ad_Valvas", $delete);
  311. $id = null;
  312. $emailTitle = null;
  313. $newContent = null;
  314. $message = get_lang("AnnouncementDeleted");
  315. }
  316. /*
  317. -----------------------------------------------------------
  318. Delete all announcements
  319. -----------------------------------------------------------
  320. */
  321. if ($_GET['action']=="delete_all")
  322. {
  323. //api_sql_query("DELETE FROM $tbl_announcement",__FILE__,__LINE__);
  324. api_sql_query("UPDATE $tbl_item_property SET visibility='2' WHERE tool='".TOOL_ANNOUNCEMENT."'",__FILE__,__LINE__);
  325. delete_all_resources_type("Ad_Valvas");
  326. $id = null;
  327. $emailTitle = null;
  328. $newContent = null;
  329. $message = get_lang("AnnouncementDeletedAll");
  330. }
  331. /*
  332. -----------------------------------------------------------
  333. Modify announcement
  334. -----------------------------------------------------------
  335. */
  336. if ($_GET['action']=="modify" AND isset($_GET['id']))
  337. {
  338. $display_form = true;
  339. // RETRIEVE THE CONTENT OF THE ANNOUNCEMENT TO MODIFY
  340. $id = intval(addslashes($_GET['id']));
  341. $sql="SELECT * FROM $tbl_announcement WHERE id='$id'";
  342. $result = api_sql_query($sql,__FILE__,__LINE__);
  343. $myrow = mysql_fetch_array($result);
  344. if ($myrow)
  345. {
  346. $announcement_to_modify = $myrow['id'];
  347. $content_to_modify = $myrow['content'];
  348. $title_to_modify = $myrow['title'];
  349. if ($originalresource!=="no") // and !addresources)
  350. {
  351. //unset_session_resources();
  352. edit_added_resources("Ad_Valvas", $announcement_to_modify);
  353. $to=load_edit_users("announcement", $announcement_to_modify);
  354. }
  355. $display_announcement_list = false;
  356. }
  357. if ($to=="everyone" OR !empty($_SESSION['toolgroup']))
  358. {
  359. $_SESSION['select_groupusers']="hide";
  360. }
  361. else
  362. {
  363. $_SESSION['select_groupusers']="show";
  364. }
  365. }
  366. /*
  367. -----------------------------------------------------------
  368. Move announcement up/down
  369. -----------------------------------------------------------
  370. */
  371. if ($_GET['down'])
  372. {
  373. $thisAnnouncementId = intval($_GET['down']);
  374. $sortDirection = "DESC";
  375. }
  376. if ($_GET['up'])
  377. {
  378. $thisAnnouncementId = intval($_GET['up']);
  379. $sortDirection = "ASC";
  380. }
  381. if ($sortDirection)
  382. {
  383. if (!in_array(trim(strtoupper($sortDirection)), array('ASC', 'DESC')))
  384. {
  385. $sortDirection='ASC';
  386. }
  387. $my_sql = "SELECT announcement.id, announcement.display_order " .
  388. "FROM $tbl_announcement announcement, " .
  389. "$tbl_item_property itemproperty " .
  390. "WHERE itemproperty.ref=announcement.id " .
  391. "AND itemproperty.tool='".TOOL_ANNOUNCEMENT."' " .
  392. "AND itemproperty.visibility<>2 " .
  393. "ORDER BY display_order $sortDirection";
  394. $result = api_sql_query($my_sql,__FILE__,__LINE__);
  395. while (list ($announcementId, $announcementOrder) = mysql_fetch_row($result))
  396. {
  397. // STEP 2 : FOUND THE NEXT ANNOUNCEMENT ID AND ORDER.
  398. // COMMIT ORDER SWAP ON THE DB
  399. if (isset ($thisAnnouncementOrderFound) && $thisAnnouncementOrderFound == true)
  400. {
  401. $nextAnnouncementId = $announcementId;
  402. $nextAnnouncementOrder = $announcementOrder;
  403. api_sql_query("UPDATE $tbl_announcement " .
  404. "SET display_order = '$nextAnnouncementOrder' " .
  405. "WHERE id = '$thisAnnouncementId'",__FILE__,__LINE__);
  406. api_sql_query("UPDATE $tbl_announcement " .
  407. "SET display_order = '$thisAnnouncementOrder' " .
  408. "WHERE id = '$nextAnnouncementId.'",__FILE__,__LINE__);
  409. break;
  410. }
  411. // STEP 1 : FIND THE ORDER OF THE ANNOUNCEMENT
  412. if ($announcementId == $thisAnnouncementId)
  413. {
  414. $thisAnnouncementOrder = $announcementOrder;
  415. $thisAnnouncementOrderFound = true;
  416. }
  417. }
  418. // show message
  419. $message = get_lang('AnnouncementMoved');
  420. }
  421. /*
  422. -----------------------------------------------------------
  423. Submit announcement
  424. -----------------------------------------------------------
  425. */
  426. if (api_is_allowed_to_edit() OR api_get_course_setting('allow_user_edit_announcement'))
  427. {
  428. $emailTitle=$_POST['emailTitle'];
  429. $newContent=$_POST['newContent'];
  430. $submitAnnouncement=isset($_POST['submitAnnouncement'])?$_POST['submitAnnouncement']:0;
  431. $id=intval($_POST['id']);
  432. if ($submitAnnouncement)
  433. {
  434. if(isset($id)&&$id) // there is an Id => the announcement already exists => update mode
  435. {
  436. $edit_id = edit_advalvas_item($id,$emailTitle,$newContent,$_POST['selectedform']);
  437. if(!$delete)
  438. {
  439. update_added_resources("Ad_Valvas", $id);
  440. }
  441. $message = get_lang('AnnouncementModified');
  442. }
  443. else //insert mode
  444. {
  445. if(!$surveyid){
  446. $result = api_sql_query("SELECT MAX(display_order) FROM $tbl_announcement",__FILE__,__LINE__);
  447. list($orderMax) = mysql_fetch_row($result);
  448. $order = $orderMax + 1;
  449. if(!empty($_SESSION['toolgroup'])){
  450. $insert_id=store_advalvas_item($_POST['emailTitle'],$_POST['newContent'],$order,array('GROUP:'.$_SESSION['toolgroup']));
  451. }else{
  452. $insert_id=store_advalvas_item($_POST['emailTitle'],$_POST['newContent'],$order,$_POST['selectedform']);
  453. }
  454. store_resources($_SESSION['source_type'],$insert_id);
  455. $_SESSION['select_groupusers']="hide";
  456. $message = get_lang('AnnouncementAdded');
  457. }
  458. /*============================================================
  459. MAIL WHEN USER COMES FROM SURVEY
  460. ======================================================= */
  461. if($_POST['emailsAdd'])
  462. {
  463. $to_email_address =$_POST['emailsAdd'];
  464. $to_email_to = explode(',', $to_email_address);
  465. $to_email = array_unique($to_email_to);
  466. $db_name = $_REQUEST['db_name'];
  467. for($i=0;$i<count($to_email);$i++)
  468. {
  469. $to= trim($to_email[$i]);
  470. $db_name = $_REQUEST['db_name'];
  471. $newContentone=str_replace("#page#","choose_language.php",$newContent);
  472. $newContenttwo=str_replace("#temp#",$template,$newContentone);
  473. $newContentthree=str_replace("#sid#",$surveyid,$newContenttwo);
  474. $newContentfour=str_replace("#mail#",$to,$newContentthree);
  475. $newContentfive=str_replace("#db_name#",$db_name,$newContentfour);
  476. $newContentsix=str_replace("#uid#","",$newContentfive);
  477. 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 ))
  478. {
  479. $subject=stripslashes($emailTitle);
  480. $message=stripslashes($newContentsix);
  481. $sender_name = $_SESSION['_user']['lastName'].' '.$_SESSION['_user']['firstName'];
  482. $email = $_SESSION['_user']['mail'];
  483. $headers="From:$sender_name\r\nReply-to: $email\r\nContent-type: text/html; charset=iso-8859-15";
  484. //@mail($to,$subject,$message,$headers);
  485. //api_send_mail($to,$subject,$message,$headers);
  486. api_mail('',$to,$subject,$message,$sender_name,$email,$headers);
  487. $sql_date="SELECT * FROM $db_name.survey WHERE survey_id='$surveyid'";
  488. $res_date=api_sql_query($sql_date);
  489. $obj_date=mysql_fetch_object($res_date);
  490. $end_date=$obj_date->avail_till;
  491. $table_reminder = Database :: get_main_table(TABLE_MAIN_SURVEY_REMINDER);
  492. if($_REQUEST['reminder']=="1")
  493. {
  494. $time=getdate();
  495. $time = $time['yday'];
  496. $time = $time+7;
  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']=="2")
  501. {
  502. $time=getdate();
  503. $time = $time['yday'];
  504. $time = $time+14;
  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. else if($_REQUEST['reminder']=="3")
  509. {
  510. $time=getdate();
  511. $time = $time['yday'];
  512. $time = $time+30;
  513. $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')";
  514. api_sql_query($sql_insert);
  515. }
  516. }
  517. }
  518. }
  519. /*===================================================================
  520. MAIL FUNCTION
  521. ===================================================================*/
  522. if (empty($_POST['onlyThoseMails']))
  523. {
  524. $sent_to=sent_to("announcement", $insert_id);
  525. $userlist = $sent_to['users'];
  526. $grouplist = $sent_to['groups'];
  527. // groepen omzetten in users
  528. if ($grouplist)
  529. {
  530. $grouplist = "'".implode("', '",$grouplist)."'"; //protect individual elements with surrounding quotes
  531. $sql = "SELECT user_id
  532. FROM $tbl_groupUser gu
  533. WHERE gu.group_id IN (".$grouplist.")";
  534. $groupMemberResult = api_sql_query($sql,__FILE__,__LINE__);
  535. if ($groupMemberResult)
  536. {
  537. while ($u = mysql_fetch_array($groupMemberResult))
  538. {
  539. $userlist [] = $u [user_id]; // complete the user id list ...
  540. }
  541. }
  542. }
  543. if(is_array($userlist))
  544. {
  545. $userlist = "'".implode("', '", array_unique($userlist) )."'";
  546. // send to the created 'userlist'
  547. $sqlmail = "SELECT user_id, lastname, firstname, email
  548. FROM $tbl_user
  549. WHERE user_id IN (".$userlist.")";
  550. }
  551. else if(empty($_POST['not_selected_form']))
  552. {
  553. // send to everybody
  554. $sqlmail = "SELECT user.user_id, user.email, user.lastname, user.firstname
  555. FROM $tbl_course_user, $tbl_user
  556. WHERE course_code='".mysql_real_escape_string($_course['sysCode'])."'
  557. AND course_rel_user.user_id = user.user_id";
  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 = $_REQUEST['db_name'];
  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.survey 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. else{
  833. echo get_lang("Everybody");
  834. }
  835. echo "</td><td>";
  836. 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>';
  837. echo "</td></tr></table>";
  838. show_to_form($to);
  839. echo "<br /><br />";
  840. if (!isset($announcement_to_modify) ) $announcement_to_modify ="";
  841. if ($announcement_to_modify=='')
  842. {
  843. /*($email_ann=='1')?$checked='checked':$checked='';
  844. echo "<input class=\"checkbox\" type=checkbox value=\"1\" name=\"email_ann\" $checked> ".get_lang('EmailOption')," : ",
  845. "<br /><br />";*/
  846. }
  847. }else{
  848. if (!isset($announcement_to_modify) ) $announcement_to_modify ="";
  849. if ($announcement_to_modify=='')
  850. {
  851. //($email_ann=='1' || !empty($surveyid))?$checked='checked':$checked='';
  852. //echo "<input class=\"checkbox\" type=checkbox value=\"1\" name=\"email_ann\" $checked> ".get_lang('EmailOption')," : ".get_lang('MyGroup'),
  853. //"<br><br>";
  854. }
  855. }
  856. if($surveyid){
  857. echo get_lang('EmailAddress').": <input type=\"text\" name=\"emailsAdd\" value=\"".$emails_add."\" size=\"52\">(Comma separated for multiple)<br>";
  858. echo get_lang('OnlyThoseAddresses').": <input type=\"checkbox\" name=\"onlyThoseMails\"><br>";
  859. }
  860. echo get_lang('EmailTitle').": <input type=\"text\" name=\"emailTitle\" value=\"".$title_to_modify."\" size=\"52\"><br />";
  861. unset($title_to_modify);
  862. $title_to_modify = null;
  863. if (!isset($announcement_to_modify) ) $announcement_to_modify ="";
  864. if (!isset($content_to_modify) ) $content_to_modify ="";
  865. if (!isset($title_to_modify)) $title_to_modify = "";
  866. echo "<br />\n<input type=\"hidden\" name=\"id\" value=\"".$announcement_to_modify."\">";
  867. if($surveyid){
  868. $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 />
  869. '.get_lang('OrCopyPasteUrl').' <br />
  870. '.api_get_path(WEB_CODE_PATH).'/survey/#page#?temp=#temp#&surveyid=#sid#&uid=#uid#&mail=#mail#&db_name=#db_name&nbsp';
  871. }
  872. //api_disp_html_area('newContent',$content_to_modify,'250px');
  873. require_once(api_get_path(LIBRARY_PATH) . "/fckeditor/fckeditor.php");
  874. $oFCKeditor = new FCKeditor('newContent') ;
  875. $oFCKeditor->BasePath = api_get_path(WEB_PATH) . 'main/inc/lib/fckeditor/' ;
  876. $oFCKeditor->Height = '250';
  877. $oFCKeditor->Width = '100%';
  878. $oFCKeditor->Value = $content_to_modify;
  879. $oFCKeditor->Config['CustomConfigurationsPath'] = api_get_path(REL_PATH)."main/inc/lib/fckeditor/myconfig.js";
  880. $oFCKeditor->ToolbarSet = "Announcements";
  881. $TBL_LANGUAGES = Database::get_main_table(TABLE_MAIN_LANGUAGE);
  882. $sql="SELECT isocode FROM ".$TBL_LANGUAGES." WHERE english_name='".$_SESSION["_course"]["language"]."'";
  883. $result_sql=api_sql_query($sql);
  884. $isocode_language=mysql_result($result_sql,0,0);
  885. $oFCKeditor->Config['DefaultLanguage'] = $isocode_language;
  886. echo $oFCKeditor->CreateHtml();
  887. /*echo "<br /><table>",
  888. "<tr>",
  889. "<td colspan=7>";
  890. if ($_SESSION['select_groupusers']=="show")
  891. {
  892. show_addresource_button("onClick=\"selectAll(this.form.elements[4],true)\"");
  893. }
  894. else
  895. {
  896. show_addresource_button();
  897. }
  898. // sessies
  899. $form_elements=$_SESSION['formelements'];
  900. echo "</td>",
  901. "</tr>";
  902. if ($_SESSION['addedresource']){
  903. if(!$surveyid){
  904. echo "<tr>";
  905. echo "<td colspan='7'>";
  906. echo display_resources(0);
  907. $test=$_SESSION['addedresource'];
  908. echo "</td></tr>";
  909. }
  910. }
  911. echo "</table>";*/
  912. ?>
  913. <br /><input type="Submit" name="submitAnnouncement" value="<?php echo get_lang('Ok') ?>" onclick="selectAll(this.form.elements[3],true)" /><br /><br />
  914. <?php
  915. "</form><br />\n";
  916. if(isset($_GET['action']) && isset($_GET['id']) && is_array($to)){
  917. echo '<script>document.getElementById(\'recipient_list\').style.display=\'block\';</script>';
  918. }
  919. } // displayform
  920. /*===============================================
  921. DISPLAY ANNOUNCEMENT LIST
  922. ===============================================*/
  923. if ($display_announcement_list && !$surveyid)
  924. {
  925. // 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
  926. $user_id=$_user['user_id'];
  927. if ($_SESSION['user']!==null)
  928. {
  929. $user_id=$_SESSION['user'];
  930. }
  931. if ($_SESSION['group']!==null)
  932. {
  933. $group_id=$_SESSION['group'];
  934. }
  935. //$group_memberships=GroupManager::get_group_ids($_course['dbName'], $_user['user_id']);
  936. $group_memberships=GroupManager::get_group_ids($_course['dbName'],$_user['user_id']);
  937. if (api_is_allowed_to_edit() OR api_get_course_setting('allow_user_edit_announcement'))
  938. {
  939. // A.1. you are a course admin with a USER filter
  940. // => see only the messages of this specific user + the messages of the group (s)he is member of.
  941. if ($_SESSION['user']!==null)
  942. {
  943. if (is_array($group_memberships))
  944. {
  945. $sql="SELECT
  946. announcement.*, toolitemproperties.*
  947. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  948. WHERE announcement.id = toolitemproperties.ref
  949. AND toolitemproperties.tool='announcement'
  950. AND (toolitemproperties.to_user_id=$user_id OR toolitemproperties.to_group_id IN (0, ".implode(", ", $group_memberships).") )
  951. ORDER BY display_order DESC";
  952. }
  953. else
  954. {
  955. $sql="SELECT
  956. announcement.*, toolitemproperties.*
  957. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  958. WHERE announcement.id = toolitemproperties.ref
  959. AND toolitemproperties.tool='announcement'
  960. AND (toolitemproperties.to_user_id=$user_id OR toolitemproperties.to_group_id='0')
  961. AND toolitemproperties.visibility='1'
  962. ORDER BY display_order DESC";
  963. }
  964. }
  965. // A.2. you are a course admin with a GROUP filter
  966. // => see only the messages of this specific group
  967. elseif ($_SESSION['group']!==null)
  968. {
  969. $sql="SELECT
  970. announcement.*, toolitemproperties.*
  971. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  972. WHERE announcement.id = toolitemproperties.ref
  973. AND toolitemproperties.tool='announcement'
  974. AND (toolitemproperties.to_group_id=$group_id OR toolitemproperties.to_group_id='0')
  975. GROUP BY toolitemproperties.ref
  976. ORDER BY display_order DESC";
  977. }
  978. // A.3 you are a course admin without any group or user filter
  979. else
  980. {
  981. // A.3.a you are a course admin without user or group filter but WITH studentview
  982. // => see all the messages of all the users and groups without editing possibilities
  983. if ($isStudentView=="true")
  984. {
  985. $sql="SELECT
  986. announcement.*, toolitemproperties.*
  987. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  988. WHERE announcement.id = toolitemproperties.ref
  989. AND toolitemproperties.tool='announcement'
  990. AND toolitemproperties.visibility='1'
  991. GROUP BY toolitemproperties.ref
  992. ORDER BY display_order DESC";
  993. }
  994. // A.3.a you are a course admin without user or group filter and WTIHOUT studentview (= the normal course admin view)
  995. // => see all the messages of all the users and groups with editing possibilities
  996. else
  997. {
  998. $sql="SELECT
  999. announcement.*, toolitemproperties.*
  1000. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  1001. WHERE announcement.id = toolitemproperties.ref
  1002. AND toolitemproperties.tool='announcement'
  1003. AND (toolitemproperties.visibility='0' or toolitemproperties.visibility='1')
  1004. GROUP BY toolitemproperties.ref
  1005. ORDER BY display_order DESC";
  1006. }
  1007. }
  1008. }
  1009. else //STUDENT
  1010. {
  1011. if (is_array($group_memberships))
  1012. {
  1013. $sql="SELECT
  1014. announcement.*, toolitemproperties.*
  1015. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  1016. WHERE announcement.id = toolitemproperties.ref
  1017. AND toolitemproperties.tool='announcement'
  1018. AND (toolitemproperties.to_user_id=$user_id OR toolitemproperties.to_group_id IN (0, ".implode(", ", $group_memberships).") )
  1019. AND toolitemproperties.visibility='1'
  1020. ORDER BY display_order DESC";
  1021. }
  1022. else
  1023. {
  1024. if ($_user['user_id'])
  1025. {
  1026. $sql="SELECT
  1027. announcement.*, toolitemproperties.*
  1028. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  1029. WHERE announcement.id = toolitemproperties.ref
  1030. AND toolitemproperties.tool='announcement'
  1031. AND (toolitemproperties.to_user_id='".$_user['user_id']."' OR toolitemproperties.to_group_id='0')
  1032. AND toolitemproperties.visibility='1'
  1033. ORDER BY display_order DESC";
  1034. }
  1035. else
  1036. {
  1037. $sql="SELECT
  1038. announcement.*, toolitemproperties.*
  1039. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  1040. WHERE announcement.id = toolitemproperties.ref
  1041. AND toolitemproperties.tool='announcement'
  1042. AND toolitemproperties.to_group_id='0'
  1043. AND toolitemproperties.visibility='1'";
  1044. }
  1045. }
  1046. }
  1047. $result = api_sql_query($sql,__FILE__,__LINE__);
  1048. $num_rows = mysql_num_rows($result);
  1049. /*=================================================
  1050. DISPLAY: NO ITEMS
  1051. =================================================*/
  1052. if ($num_rows == 0)
  1053. {
  1054. echo "<table><tr><td>".get_lang('NoAnnouncements')."</td></tr></table>";
  1055. }
  1056. $iterator = 1;
  1057. $bottomAnnouncement = $announcement_number;
  1058. echo "\t\t\t<table width=\"100%\" border=\"1\" cellpadding=\"5\" cellspacing=\"0\" id=\"agenda_list\">\n";
  1059. $displayed=array();
  1060. while ($myrow = mysql_fetch_array($result))
  1061. {
  1062. if (!in_array($myrow['id'], $displayed))
  1063. {
  1064. $title = $myrow['title'];
  1065. $content = $myrow['content'];
  1066. $content = make_clickable($content);
  1067. $content = text_filter($content);
  1068. /*================================================
  1069. DATE
  1070. ================================================*/
  1071. $last_post_datetime = $myrow['end_date'];
  1072. list($last_post_date, $last_post_time) = split(" ", $last_post_datetime);
  1073. list($year, $month, $day) = explode("-", $last_post_date);
  1074. list($hour, $min) = explode(":", $last_post_time);
  1075. $announceDate = mktime($hour, $min, 0, $month, $day, $year);
  1076. // the styles
  1077. if ($myrow['visibility']=='0')
  1078. {
  1079. $style="data_hidden";
  1080. $stylenotbold="datanotbold_hidden";
  1081. $text_style="text_hidden";
  1082. }
  1083. else
  1084. {
  1085. $style="data";
  1086. $stylenotbold="datanotbold";
  1087. $text_style="text";
  1088. }
  1089. echo "\t\t\t\t<tr class=\"".$style."\">";
  1090. /*===================================================================
  1091. THE ICONS
  1092. ===================================================================*/
  1093. echo "\t\t\t\t\t<td>\n";
  1094. // anchoring
  1095. echo "<a name=\"".(int)($myrow["id"])."\"></a>\n";
  1096. // User or group icon
  1097. if ($myrow['to_group_id']!== '0' and $myrow['to_group_id']!== 'NULL')
  1098. {
  1099. echo "\t\t\t\t\t\t<img alt=\"$alt_ug\" src='../img/group.gif'>\n";
  1100. }
  1101. // the email icon
  1102. if ($myrow['email_sent'] == '1')
  1103. {
  1104. echo "\t\t\t\t\t\t<img alt=\"$alt_mail\" src='../img/email.gif'>\n";
  1105. }
  1106. echo "\t\t\t\t\t</td>\n";
  1107. /*==================================================================
  1108. TITLE
  1109. ==================================================================*/
  1110. echo "\t\t\t\t\t<td>".$title."</td>\n";
  1111. /*==================================================================
  1112. SENT TO
  1113. ===================================================================*/
  1114. echo "\t\t\t\t\t<td class=\"".$stylenotbold."\">" . get_lang("SentTo") . " : &nbsp; ";
  1115. $sent_to=sent_to("announcement", $myrow['id']);
  1116. // echo $myrow['id'];
  1117. $sent_to_form=sent_to_form($sent_to);
  1118. echo $sent_to_form,
  1119. "\t\t\t\t\t</td>\n",
  1120. "\t\t\t\t</tr>\n";
  1121. /*=========================================================
  1122. TITLE
  1123. =========================================================*/
  1124. echo "\t\t\t\t<tr>\n",
  1125. "\t\t\t\t\t<td class=\"announcements_datum\" colspan=\"3\">",
  1126. get_lang('AnnouncementPublishedOn')," : ",ucfirst(format_locale_date($dateFormatLong,strtotime($last_post_date))),
  1127. "</td>\n",
  1128. "\t\t\t\t</tr>\n",
  1129. /*=========================================================
  1130. CONTENT
  1131. =========================================================*/
  1132. "\t\t\t\t<tr class=\"$text_style\">\n",
  1133. "\t\t\t\t\t<td colspan=\"3\">\n",
  1134. $content,
  1135. "\t\t\t\t\t</td>\n",
  1136. "\t\t\t\t</tr>\n",
  1137. /*========================================================
  1138. RESOURCES
  1139. ========================================================*/
  1140. "<tr>\n",
  1141. "<td colspan=\"3\">\n";
  1142. if (check_added_resources("Ad_Valvas", $myrow["id"]))
  1143. {
  1144. echo "<i>".get_lang('AddedResources')."</i><br />";
  1145. display_added_resources("Ad_Valvas", $myrow["id"]);
  1146. }
  1147. echo "<br />";
  1148. if(api_is_allowed_to_edit())
  1149. {
  1150. /*=====================================================================
  1151. SHOW MOD/DEL/VIS FUNCTIONS
  1152. =====================================================================*/
  1153. echo "<table><tr>";
  1154. echo "<td valign=\"top\"><a href=\"".api_get_self()."?".api_get_cidreq()."&action=modify&id=".$myrow['id']."\">",
  1155. "<img src=\"../img/edit.gif\" title=\"",get_lang('Modify'),"\" border=\"0\" align=\"absmiddle\">",
  1156. "</a></td>";
  1157. 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')))."')) return false;\">",
  1158. "<img src=\"../img/delete.gif\" title=\"",get_lang('Delete'),"\" border=\"0\" align=\"absmiddle\">",
  1159. "</a></td>";
  1160. if ($myrow['visibility']==1)
  1161. {
  1162. $image_visibility="visible";
  1163. }
  1164. else
  1165. {
  1166. $image_visibility="invisible";
  1167. }
  1168. echo "<td valign=\"top\"><a href=\"".api_get_self()."?".api_get_cidreq()."&origin=".$_GET['origin']."&action=showhide&id=".$myrow['id']."\">",
  1169. "<img src=\"../img/".$image_visibility.".gif\" border=\"0\" alt=\"".get_lang('Visible')."\"/></a></td>";
  1170. // DISPLAY MOVE UP COMMAND only if it is not the top announcement
  1171. if($iterator != 1)
  1172. {
  1173. echo "<td valign=\"top\"><a href=\"".api_get_self()."?".api_get_cidreq()."&up=",$myrow["id"],"\">",
  1174. "<img src=../img/up.gif border=0 title=\"".get_lang('Up')."\" align=\"absmiddle\">",
  1175. "</a></td>";
  1176. }
  1177. if($iterator < $bottomAnnouncement)
  1178. {
  1179. echo "<td valign=\"top\"><a href=\"".api_get_self()."?".api_get_cidreq()."&down=".$myrow["id"]."\">",
  1180. "<img src=\"../img/down.gif\" border=\"0\" title=\"".get_lang('Down')."\" align=\"absmiddle\">",
  1181. "</a></td>";
  1182. }
  1183. echo "</tr></table>";
  1184. echo "</td>\n",
  1185. "</tr>\n";
  1186. $iterator ++;
  1187. } // is_allowed_to_edit
  1188. 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>";
  1189. }
  1190. $displayed[]=$myrow['id'];
  1191. } // end while ($myrow = mysql_fetch_array($result))
  1192. echo "</table>";
  1193. } // end: if ($displayAnnoucementList)
  1194. echo "</table>";
  1195. if ($display_specific_announcement) display_announcement($announcement_id);
  1196. /*
  1197. ==============================================================================
  1198. FOOTER
  1199. ==============================================================================
  1200. */
  1201. if ($_GET['origin'] !== 'learnpath')
  1202. {
  1203. //we are not in learnpath tool
  1204. Display::display_footer();
  1205. }
  1206. ?>