announcements.php 51 KB

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