announcements.php 48 KB

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