announcements.php 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567
  1. <?php //$Id: announcements.php 18101 2009-01-31 21:22:15Z derrj $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2008 Dokeos SPRL
  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, rue du Corbeau, 108, 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 (!empty($_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 (!empty($_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 (empty($_POST['To']) and !$_SESSION['select_groupusers'])
  151. {
  152. $_SESSION['select_groupusers']="hide";
  153. }
  154. $select_groupusers_status=$_SESSION['select_groupusers'];
  155. if (!empty($_POST['To']) and ($select_groupusers_status=="hide"))
  156. {
  157. $_SESSION['select_groupusers']="show";
  158. }
  159. if (!empty($_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 (((!empty($_GET['action']) && $_GET['action'] == 'add') && $_GET['origin'] == "") || (!empty($_GET['action']) && $_GET['action'] == 'edit') || !empty($_POST['To']))
  170. {
  171. $display_form = true;
  172. }
  173. // clear all resources
  174. if ((empty($originalresource) || ($originalresource!=='no')) and (!empty($action) && $action=='add'))
  175. {
  176. $_SESSION['formelements']=null;
  177. //unset($_SESSION['formelements']);
  178. unset_session_resources();
  179. }
  180. /*
  181. -----------------------------------------------------------
  182. Javascript
  183. -----------------------------------------------------------
  184. */
  185. $htmlHeadXtra[] = to_javascript();
  186. /*
  187. -----------------------------------------------------------
  188. Filter user/group
  189. -----------------------------------------------------------
  190. */
  191. if(!empty($_GET['toolgroup'])){
  192. if($_GET['toolgroup'] == strval(intval($_GET['toolgroup']))){ //check is integer
  193. $toolgroup = $_GET['toolgroup'];
  194. $_SESSION['select_groupusers'] = 'hide';
  195. }else{
  196. $toolgroup = 0;
  197. }
  198. api_session_register("toolgroup");
  199. }
  200. /*
  201. -----------------------------------------------------------
  202. Sessions
  203. -----------------------------------------------------------
  204. */
  205. if (!empty($_SESSION['formelements']) and !empty($_GET['originalresource']) and $_GET['originalresource'] == 'no')
  206. {
  207. $form_elements = $_SESSION['formelements'];
  208. $title_to_modify = $form_elements['emailTitle'];
  209. $content_to_modify = $form_elements['newContent'];
  210. $announcement_to_modify = $form_elements['id'];
  211. $to = $form_elements['to'];
  212. //load_edit_users('announcement',$announcement_to_modify);
  213. $email_ann = $form_elements['emailoption'];
  214. }
  215. if(!empty($_GET['remind_inactive']))
  216. {
  217. $to[] = 'USER:'.intval($_GET['remind_inactive']);
  218. }
  219. /*
  220. -----------------------------------------------------------
  221. Survey
  222. -----------------------------------------------------------
  223. */
  224. $surveyid = 0;
  225. if(!empty($_REQUEST['publish_survey']))
  226. {
  227. $surveyid=Database::escape_string($_REQUEST['publish_survey']);
  228. }
  229. $cidReq=Database::escape_string($_REQUEST['cidReq']);
  230. if($surveyid)
  231. {
  232. $db_name=Database::escape_string($_REQUEST['db_name']);
  233. $sql_temp = "SELECT * FROM $db_name.survey WHERE survey_id='$surveyid'";
  234. $res_temp = api_sql_query($sql_temp, __FILE__, __LINE__);
  235. $obj=@Database::fetch_object($res_temp);
  236. $template=$obj->template;
  237. }
  238. if (!empty($_SESSION['toolgroup'])){
  239. $_clean['toolgroup']=(int)$_SESSION['toolgroup'];
  240. $group_properties = GroupManager :: get_group_properties($_clean['toolgroup']);
  241. $interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups'));
  242. $interbreadcrumb[] = array ("url"=>"../group/group_space.php?gidReq=".$_SESSION['toolgroup'], "name"=> get_lang('GroupSpace').' ('.$group_properties['name'].')');
  243. } else {
  244. if($surveyid) {
  245. $interbreadcrumb[] = array ("url" => "../survey/survey_list.php?cidReq=$cidReq", "name" => get_lang('Survey'));
  246. $nameTools = get_lang('PublishSurvey');
  247. }else {
  248. $nameTools = get_lang('Announcement');
  249. $nameTools12 = get_lang('PublishSurvey');
  250. }
  251. }
  252. /*
  253. -----------------------------------------------------------
  254. Learning path & css
  255. -----------------------------------------------------------
  256. */
  257. // showing the header if we are not in the learning path, if we are in
  258. // the learning path, we do not include the banner so we have to explicitly
  259. // include the stylesheet, which is normally done in the header
  260. if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath')
  261. {
  262. //we are not in the learning path
  263. Display::Display_header($nameTools,"Announcements");
  264. }
  265. else
  266. {
  267. //we are in the learning path, only display central data and change css
  268. $display_title_list = false;
  269. $display_announcement_list = false;
  270. $display_specific_announcement = true;
  271. $announcement_id = $_REQUEST['ann_id'];
  272. ?> <link rel="stylesheet" type="text/css" href="<?php echo $clarolineRepositoryWeb ?>css/default.css">
  273. <!-- css file for announcements -->
  274. <link href="../css/announcements.css" rel="stylesheet" type="text/css">
  275. <?php
  276. }
  277. // inserting an anchor (top) so one can jump back to the top of the page
  278. echo "<a name=\"top\"></a>";
  279. /*=============================================
  280. ACTION HANDLING
  281. =============================================*/
  282. if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous()))
  283. {
  284. /*
  285. -----------------------------------------------------------
  286. Change visibility of announcement
  287. -----------------------------------------------------------
  288. */
  289. // $_GET['isStudentView']<>"false" is added to prevent that the visibility
  290. // is changed after you do the following:
  291. // change visibility -> studentview -> course manager view
  292. if (!isset($_GET['isStudentView']) || $_GET['isStudentView']!='false')
  293. {
  294. if (isset($_GET['id']) AND $_GET['id'] AND isset($_GET['action']) AND $_GET['action']=="showhide")
  295. {
  296. $id=intval(addslashes($_GET['id']));
  297. if(!api_is_course_coach() || api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $id))
  298. {
  299. change_visibility(TOOL_ANNOUNCEMENT,$id);
  300. $message = get_lang("VisibilityChanged");
  301. }
  302. }
  303. }
  304. /*
  305. -----------------------------------------------------------
  306. Delete announcement
  307. -----------------------------------------------------------
  308. */
  309. if (!empty($_GET['action']) AND $_GET['action']=='delete' AND isset($_GET['id']))
  310. {
  311. //api_sql_query("DELETE FROM $tbl_announcement WHERE id='$delete'",__FILE__,__LINE__);
  312. $id=intval(addslashes($_GET['id']));
  313. if(!api_is_course_coach() || api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $id))
  314. {
  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. -----------------------------------------------------------
  326. Delete all announcements
  327. -----------------------------------------------------------
  328. */
  329. if (!empty($_GET['action']) and $_GET['action']=='delete_all')
  330. {
  331. //api_sql_query("DELETE FROM $tbl_announcement",__FILE__,__LINE__);
  332. if(api_is_allowed_to_edit())
  333. {
  334. api_sql_query("UPDATE $tbl_item_property SET visibility='2' WHERE tool='".TOOL_ANNOUNCEMENT."'",__FILE__,__LINE__);
  335. delete_all_resources_type("Ad_Valvas");
  336. $id = null;
  337. $emailTitle = null;
  338. $newContent = null;
  339. $message = get_lang("AnnouncementDeletedAll");
  340. }
  341. }
  342. /*
  343. -----------------------------------------------------------
  344. Modify announcement
  345. -----------------------------------------------------------
  346. */
  347. if (!empty($_GET['action']) and $_GET['action']=='modify' AND isset($_GET['id']))
  348. {
  349. $display_form = true;
  350. // RETRIEVE THE CONTENT OF THE ANNOUNCEMENT TO MODIFY
  351. $id = intval(addslashes($_GET['id']));
  352. if(!api_is_course_coach() || api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $id))
  353. {
  354. $sql="SELECT * FROM $tbl_announcement WHERE id='$id'";
  355. $result = api_sql_query($sql,__FILE__,__LINE__);
  356. $myrow = Database::fetch_array($result);
  357. if ($myrow)
  358. {
  359. $announcement_to_modify = $myrow['id'];
  360. $content_to_modify = $myrow['content'];
  361. $title_to_modify = $myrow['title'];
  362. if ($originalresource!=="no") // and !addresources)
  363. {
  364. //unset_session_resources();
  365. edit_added_resources("Ad_Valvas", $announcement_to_modify);
  366. $to=load_edit_users("announcement", $announcement_to_modify);
  367. }
  368. $display_announcement_list = false;
  369. }
  370. if ($to=="everyone" OR !empty($_SESSION['toolgroup']))
  371. {
  372. $_SESSION['select_groupusers']="hide";
  373. }
  374. else
  375. {
  376. $_SESSION['select_groupusers']="show";
  377. }
  378. }
  379. }
  380. /*
  381. -----------------------------------------------------------
  382. Move announcement up/down
  383. -----------------------------------------------------------
  384. */
  385. if (!empty($_GET['down']))
  386. {
  387. $thisAnnouncementId = intval($_GET['down']);
  388. $sortDirection = "DESC";
  389. }
  390. if (!empty($_GET['up']))
  391. {
  392. $thisAnnouncementId = intval($_GET['up']);
  393. $sortDirection = "ASC";
  394. }
  395. if (!empty($sortDirection))
  396. {
  397. if (!in_array(trim(strtoupper($sortDirection)), array('ASC', 'DESC')))
  398. {
  399. $sortDirection='ASC';
  400. }
  401. $my_sql = "SELECT announcement.id, announcement.display_order " .
  402. "FROM $tbl_announcement announcement, " .
  403. "$tbl_item_property itemproperty " .
  404. "WHERE itemproperty.ref=announcement.id " .
  405. "AND itemproperty.tool='".TOOL_ANNOUNCEMENT."' " .
  406. "AND itemproperty.visibility<>2 " .
  407. "ORDER BY display_order $sortDirection";
  408. $result = api_sql_query($my_sql,__FILE__,__LINE__);
  409. while (list ($announcementId, $announcementOrder) = Database::fetch_row($result))
  410. {
  411. // STEP 2 : FOUND THE NEXT ANNOUNCEMENT ID AND ORDER.
  412. // COMMIT ORDER SWAP ON THE DB
  413. if (isset ($thisAnnouncementOrderFound) && $thisAnnouncementOrderFound == true)
  414. {
  415. $nextAnnouncementId = $announcementId;
  416. $nextAnnouncementOrder = $announcementOrder;
  417. api_sql_query("UPDATE $tbl_announcement " .
  418. "SET display_order = '$nextAnnouncementOrder' " .
  419. "WHERE id = '$thisAnnouncementId'",__FILE__,__LINE__);
  420. api_sql_query("UPDATE $tbl_announcement " .
  421. "SET display_order = '$thisAnnouncementOrder' " .
  422. "WHERE id = '$nextAnnouncementId.'",__FILE__,__LINE__);
  423. break;
  424. }
  425. // STEP 1 : FIND THE ORDER OF THE ANNOUNCEMENT
  426. if ($announcementId == $thisAnnouncementId)
  427. {
  428. $thisAnnouncementOrder = $announcementOrder;
  429. $thisAnnouncementOrderFound = true;
  430. }
  431. }
  432. // show message
  433. $message = get_lang('AnnouncementMoved');
  434. }
  435. /*
  436. -----------------------------------------------------------
  437. Submit announcement
  438. -----------------------------------------------------------
  439. */
  440. if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous()))
  441. {
  442. $emailTitle=(!empty($_POST['emailTitle'])?$_POST['emailTitle']:'');
  443. $newContent=(!empty($_POST['newContent'])?$_POST['newContent']:'');
  444. $submitAnnouncement=isset($_POST['submitAnnouncement'])?$_POST['submitAnnouncement']:0;
  445. $id = 0;
  446. if(!empty($_POST['id']))
  447. {
  448. $id=intval($_POST['id']);
  449. }
  450. if($submitAnnouncement && empty($emailTitle))
  451. {
  452. $error_message = get_lang('TitleIsRequired');
  453. $content_to_modify = $newContent;
  454. }
  455. else if ($submitAnnouncement)
  456. {
  457. if(isset($id)&&$id) // there is an Id => the announcement already exists => update mode
  458. {
  459. $edit_id = edit_advalvas_item($id,$emailTitle,$newContent,$_POST['selectedform']);
  460. if(!$delete)
  461. {
  462. update_added_resources("Ad_Valvas", $id);
  463. }
  464. $message = get_lang('AnnouncementModified');
  465. }
  466. else //insert mode
  467. {
  468. if(!$surveyid){
  469. $result = api_sql_query("SELECT MAX(display_order) FROM $tbl_announcement WHERE session_id=".intval($_SESSION['id_session'])." OR session_id=0",__FILE__,__LINE__);
  470. list($orderMax) = Database::fetch_row($result);
  471. $order = $orderMax + 1;
  472. if(!empty($_SESSION['toolgroup'])){
  473. //$insert_id=store_advalvas_item($_POST['emailTitle'],$_POST['newContent'],$order,array('GROUP:'.$_SESSION['toolgroup']));
  474. $insert_id=store_advalvas_group_item($_POST['emailTitle'],$_POST['newContent'],$order,array('GROUP:'.$_SESSION['toolgroup']),$_POST['selectedform']);
  475. }else{
  476. $insert_id=store_advalvas_item($_POST['emailTitle'],$_POST['newContent'],$order,$_POST['selectedform']);
  477. }
  478. store_resources($_SESSION['source_type'],$insert_id);
  479. $_SESSION['select_groupusers']="hide";
  480. $message = get_lang('AnnouncementAdded');
  481. }
  482. /*============================================================
  483. MAIL WHEN USER COMES FROM SURVEY
  484. ======================================================= */
  485. if($_POST['emailsAdd'])
  486. {
  487. $to_email_address =$_POST['emailsAdd'];
  488. $to_email_to = explode(',', $to_email_address);
  489. $to_email = array_unique($to_email_to);
  490. $db_name = $_REQUEST['db_name'];
  491. for($i=0;$i<count($to_email);$i++)
  492. {
  493. $to= trim($to_email[$i]);
  494. $db_name = $_REQUEST['db_name'];
  495. $newContentone=str_replace("#page#","choose_language.php",$newContent);
  496. $newContenttwo=str_replace("#temp#",$template,$newContentone);
  497. $newContentthree=str_replace("#sid#",$surveyid,$newContenttwo);
  498. $newContentfour=str_replace("#mail#",$to,$newContentthree);
  499. $newContentfive=str_replace("#db_name#",$db_name,$newContentfour);
  500. $newContentsix=str_replace("#uid#","",$newContentfive);
  501. 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 ))
  502. {
  503. $subject=stripslashes($emailTitle);
  504. $message=stripslashes($newContentsix);
  505. $sender_name = $_SESSION['_user']['lastName'].' '.$_SESSION['_user']['firstName'];
  506. $email = $_SESSION['_user']['mail'];
  507. $headers="From:$sender_name\r\nReply-to: $email\r\nContent-type: text/html; charset=iso-8859-15";
  508. //@mail($to,$subject,$message,$headers);
  509. //api_send_mail($to,$subject,$message,$headers);
  510. api_mail('',$to,$subject,$message,$sender_name,$email,$headers);
  511. $sql_date="SELECT * FROM $db_name.survey WHERE survey_id='$surveyid'";
  512. $res_date=api_sql_query($sql_date, __FILE__, __LINE__);
  513. $obj_date=Database::fetch_object($res_date);
  514. $end_date=$obj_date->avail_till;
  515. $table_reminder = Database :: get_main_table(TABLE_MAIN_SURVEY_REMINDER);
  516. if($_REQUEST['reminder']=="1")
  517. {
  518. $time=getdate();
  519. $time = $time['yday'];
  520. $time = $time+7;
  521. $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')";
  522. api_sql_query($sql_insert, __FILE__, __LINE__);
  523. }
  524. else if($_REQUEST['reminder']=="2")
  525. {
  526. $time=getdate();
  527. $time = $time['yday'];
  528. $time = $time+14;
  529. $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')";
  530. api_sql_query($sql_insert, __FILE__, __LINE__);
  531. }
  532. else if($_REQUEST['reminder']=="3")
  533. {
  534. $time=getdate();
  535. $time = $time['yday'];
  536. $time = $time+30;
  537. $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')";
  538. api_sql_query($sql_insert, __FILE__, __LINE__);
  539. }
  540. }
  541. }
  542. }
  543. /*===================================================================
  544. MAIL FUNCTION
  545. ===================================================================*/
  546. if ($_POST['email_ann'] && empty($_POST['onlyThoseMails']))
  547. {
  548. $sent_to=sent_to("announcement", $insert_id);
  549. $userlist = $sent_to['users'];
  550. $grouplist = $sent_to['groups'];
  551. // groepen omzetten in users
  552. if ($grouplist)
  553. {
  554. $grouplist = "'".implode("', '",$grouplist)."'"; //protect individual elements with surrounding quotes
  555. $sql = "SELECT user_id
  556. FROM $tbl_groupUser gu
  557. WHERE gu.group_id IN (".$grouplist.")";
  558. $groupMemberResult = api_sql_query($sql,__FILE__,__LINE__);
  559. if ($groupMemberResult)
  560. {
  561. while ($u = Database::fetch_array($groupMemberResult))
  562. {
  563. $userlist [] = $u ['user_id']; // complete the user id list ...
  564. }
  565. }
  566. }
  567. if(is_array($userlist))
  568. {
  569. $userlist = "'".implode("', '", array_unique($userlist) )."'";
  570. // send to the created 'userlist'
  571. $sqlmail = "SELECT user_id, lastname, firstname, email
  572. FROM $tbl_user
  573. WHERE user_id IN (".$userlist.")";
  574. }
  575. else if(empty($_POST['not_selected_form']))
  576. {
  577. if(empty($_SESSION['id_session']) || api_get_setting('use_session_mode')=='false')
  578. {
  579. // send to everybody
  580. $sqlmail = "SELECT user.user_id, user.email, user.lastname, user.firstname
  581. FROM $tbl_course_user, $tbl_user
  582. WHERE course_code='".Database::escape_string($_course['sysCode'])."'
  583. AND course_rel_user.user_id = user.user_id";
  584. }
  585. else
  586. {
  587. $sqlmail = "SELECT user.user_id, user.email, user.lastname, user.firstname
  588. FROM $tbl_user
  589. INNER JOIN $tbl_session_course_user
  590. ON $tbl_user.user_id = $tbl_session_course_user.id_user
  591. AND $tbl_session_course_user.course_code = '".$_course['id']."'
  592. AND $tbl_session_course_user.id_session = ".intval($_SESSION['id_session']);
  593. }
  594. }
  595. if($sqlmail!='')
  596. {
  597. $result = api_sql_query($sqlmail,__FILE__,__LINE__);
  598. /*=================================================================================
  599. send email one by one to avoid antispam
  600. =================================================================================*/
  601. while ($myrow = Database::fetch_array($result))
  602. {
  603. /* Header : Bericht van uw lesgever - GES ($_cid)
  604. Body : John Doe (prenom + nom) <john_doe@hotmail.com> (email)
  605. Morgen geen les!! (emailTitle)
  606. Morgen is er geen les, de les wordt geschrapt wegens vergadering (newContent)
  607. */
  608. $emailSubject = "[" . $_course['official_code'] . "] " . $emailTitle;
  609. $db_name = Database::get_course_table(TABLE_MAIN_SURVEY);
  610. if($surveyid)
  611. {
  612. $newContentone=str_replace("#page#","choose_language.php",$newContent);
  613. $newContenttwo=str_replace("#temp#",$template,$newContentone);
  614. $newContentthree=str_replace("#sid#",$surveyid,$newContenttwo);
  615. $newContentfour=str_replace("#mail#",$myrow["email"],$newContentthree);
  616. $newContentfive=str_replace("#db_name#",$db_name,$newContentfour);
  617. $newContentsix=str_replace("#uid#",$myrow["user_id"],$newContentfive);
  618. $message=stripslashes($newContentsix);
  619. $sender_name = $_SESSION['_user']['lastName'].' '.$_SESSION['_user']['firstName'];
  620. $email = $_SESSION['_user']['mail'];
  621. $headers="From:$sender_name\r\nReply-to: $email\r\nContent-type: text/html; charset=iso-8859-15";
  622. //@mail($myrow["email"],stripslashes($emailTitle),$message,$headers);
  623. api_mail('',$myrow["email"],stripslashes($emailTitle),$message,$sender_name,$email);
  624. }
  625. else
  626. {
  627. // intro of the email: receiver name and subject
  628. $mail_body = $myrow["lastname"]." ".$myrow["firstname"]."<br />\n".stripslashes($emailTitle)."<br />";
  629. // main part of the email
  630. $mail_body .= trim(stripslashes($newContent));
  631. // signature of email: sender name and course URL after -- line
  632. $mail_body .= "<br />-- <br />";
  633. $mail_body .= $_user['firstName'].' '.$_user['lastName']." \n";
  634. $mail_body .= "<br /> \n<a href=\"".api_get_path(WEB_COURSE_PATH).$_course['id']."\">";
  635. $mail_body .= $_course['official_code'].' '.$_course['name'] . "</a>";
  636. //set the charset and use it for the encoding of the email - small fix, not really clean (should check the content encoding origin first)
  637. //here we use the encoding used for the webpage where the text is encoded (ISO-8859-1 in this case)
  638. //$to_email_address =$_POST['emailsAdd'];
  639. //$mail_body;
  640. $headers = array();
  641. if(empty($charset)){$charset='ISO-8859-1';}
  642. $headers['Content-Type'] = 'text/html';
  643. $headers['charset'] = $charset;
  644. $mailid=$myrow["email"];
  645. $newmail = api_mail_html($myrow["lastname"].' '.$myrow["firstname"], $myrow["email"], stripslashes($emailSubject), $mail_body, $_SESSION['_user']['lastName'].' '.$_SESSION['_user']['firstName'], $_SESSION['_user']['mail'],$headers);
  646. }
  647. $sql_date="SELECT * FROM $db_name WHERE survey_id='$surveyid'";
  648. $res_date=api_sql_query($sql_date, __FILE__, __LINE__);
  649. $obj_date=Database::fetch_object($res_date);
  650. $end_date=$obj_date->avail_till;
  651. $table_reminder = Database :: get_main_table(TABLE_MAIN_SURVEY_REMINDER);
  652. if($_REQUEST['reminder']=="1")
  653. {
  654. $time=getdate();
  655. $time = $time['yday'];
  656. $time = $time+7;
  657. $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')";
  658. api_sql_query($sql, __FILE__, __LINE__);
  659. }
  660. else if($_REQUEST['reminder']=="2")
  661. {
  662. $time=getdate();
  663. $time = $time['yday'];
  664. $time = $time+14;
  665. $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')";
  666. api_sql_query($sql, __FILE__, __LINE__);
  667. }
  668. else if($_REQUEST['reminder']=="3")
  669. {
  670. $time=getdate();
  671. $time = $time['yday'];
  672. $time = $time+30;
  673. $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')";
  674. api_sql_query($sql, __FILE__, __LINE__);
  675. }
  676. }
  677. update_mail_sent($insert_id);
  678. $message = $added_and_sent;
  679. }
  680. } // $email_ann*/
  681. } // isset
  682. // UNSET VARIABLES
  683. unset_session_resources();
  684. unset($form_elements);
  685. $_SESSION['formelements']=null;
  686. $newContent = null;
  687. $emailTitle = null;
  688. unset($emailTitle);
  689. unset($newContent);
  690. unset($content_to_modify);
  691. unset($title_to_modify);
  692. if($_REQUEST['publish_survey'])
  693. {
  694. $surveyid=$_REQUEST['surveyid'];
  695. $cidReq = $_REQUEST['cidReq'];
  696. ?>
  697. <script>
  698. window.location.href="../survey/survey_list.php?<?php echo api_get_cidreq(); ?>&published=published&surveyid=<?php echo $_REQUEST['publish_survey']; ?>";
  699. </script>
  700. <?php
  701. }
  702. } // if $submit Announcement
  703. }
  704. }
  705. /*====================================================
  706. Tool Title
  707. ====================================================*/
  708. $fck_attribute['Width'] = '100%';
  709. $fck_attribute['Height'] = '400';
  710. $fck_attribute['ToolbarSet'] = 'Full';
  711. $fck_attribute['Config']['InDocument'] = false;
  712. $fck_attribute['Config']['CreateDocumentWebDir'] = api_get_path('WEB_COURSE_PATH').api_get_course_path().'/document/';
  713. $fck_attribute['Config']['CreateDocumentDir'] = '../../courses/'.api_get_course_path().'/document/';
  714. $fck_attribute['Config']['BaseHref'] = api_get_path('WEB_COURSE_PATH').api_get_course_path().'/';
  715. if (empty($_GET['origin']) || $_GET['origin'] !== 'learnpath')
  716. {
  717. //api_display_tool_title($nameTools);
  718. Display::display_introduction_section(TOOL_ANNOUNCEMENT);
  719. }
  720. $fck_attribute = null; // Clearing this global variable immediatelly after it has been used.
  721. /*
  722. ==============================================================================
  723. MAIN SECTION
  724. ==============================================================================
  725. */
  726. /*=====================================================================================
  727. MAIN CODE HTML
  728. =====================================================================================*/
  729. // The commands below will change these display settings if they need it
  730. /*======================================================================
  731. DISPLAY LEFT COLUMN
  732. ======================================================================*/
  733. if(api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous()) ) // check teacher status
  734. {
  735. if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath')
  736. {
  737. $sql="SELECT
  738. announcement.*, toolitemproperties.*
  739. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  740. WHERE announcement.id = toolitemproperties.ref
  741. AND toolitemproperties.tool='announcement'
  742. AND toolitemproperties.visibility<>'2'
  743. AND announcement.session_id IN(0,".intval($_SESSION['id_session']).")
  744. GROUP BY toolitemproperties.ref
  745. ORDER BY display_order DESC
  746. LIMIT 0,$maximum";
  747. }
  748. }
  749. else // students only get to see the visible announcements
  750. {
  751. if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath')
  752. {
  753. $group_memberships=GroupManager::get_group_ids($_course['dbName'], $_user['user_id']);
  754. // the user is member of several groups => display personal announcements AND his group announcements AND the general announcements
  755. if (is_array($group_memberships) && count($group_memberships)>0)
  756. {
  757. $sql="SELECT
  758. announcement.*, toolitemproperties.*
  759. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  760. WHERE announcement.id = toolitemproperties.ref
  761. AND toolitemproperties.tool='announcement'
  762. AND toolitemproperties.visibility='1'
  763. AND ( toolitemproperties.to_user_id='".$_user['user_id']."'" .
  764. "OR toolitemproperties.to_group_id IN (0, ".implode(", ", $group_memberships).") )
  765. AND announcement.session_id IN(0,".intval($_SESSION['id_session']).")
  766. GROUP BY toolitemproperties.ref
  767. ORDER BY display_order DESC
  768. LIMIT 0,$maximum";
  769. }
  770. // the user is not member of any group
  771. else
  772. {
  773. // this is an identified user => show the general announcements AND his personal announcements
  774. if ($_user['user_id'])
  775. {
  776. $sql="SELECT
  777. announcement.*, toolitemproperties.*
  778. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  779. WHERE announcement.id = toolitemproperties.ref
  780. AND toolitemproperties.tool='announcement'
  781. AND toolitemproperties.visibility='1'
  782. AND ( toolitemproperties.to_user_id='".$_user['user_id']."' OR toolitemproperties.to_group_id='0')
  783. AND announcement.session_id IN(0,".intval($_SESSION['id_session']).")
  784. GROUP BY toolitemproperties.ref
  785. ORDER BY display_order DESC
  786. LIMIT 0,$maximum";
  787. }
  788. // the user is not identiefied => show only the general announcements
  789. else
  790. {
  791. $sql="SELECT
  792. announcement.*, toolitemproperties.*
  793. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  794. WHERE announcement.id = toolitemproperties.ref
  795. AND toolitemproperties.tool='announcement'
  796. AND toolitemproperties.visibility='1'
  797. AND toolitemproperties.to_group_id='0'
  798. AND announcement.session_id IN(0,".intval($_SESSION['id_session']).")
  799. GROUP BY toolitemproperties.ref
  800. ORDER BY display_order DESC
  801. LIMIT 0,$maximum";
  802. }
  803. }
  804. }
  805. }
  806. $result = api_sql_query($sql,__FILE__,__LINE__);
  807. $announcement_number = Database::num_rows($result);
  808. /*----------------------------------------------------
  809. ADD ANNOUNCEMENT / DELETE ALL
  810. ----------------------------------------------------*/
  811. echo '<div class="actions">';
  812. if(!$surveyid)
  813. {
  814. if ((api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) and (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath'))
  815. {
  816. echo "<a href='".api_get_self()."?".api_get_cidreq()."&action=add&origin=".(empty($_GET['origin'])?'':$_GET['origin'])."'>".Display::return_icon('announce_add.gif',get_lang('AddAnnouncement')).get_lang('AddAnnouncement')."</a>";
  817. }
  818. if (api_is_allowed_to_edit() && $announcement_number > 1)
  819. {
  820. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&action=delete_all\" onclick=\"javascript:if(!confirm('".get_lang("ConfirmYourChoice")."')) return false;\">".Display::return_icon('valves_delete.gif',get_lang('AnnouncementDeleteAll')).get_lang('AnnouncementDeleteAll')."</a>\n";
  821. } // if announcementNumber > 1
  822. }
  823. echo '</div>';
  824. if (empty($_GET['origin']) OR $_GET['origin'] !== 'learnpath')
  825. {
  826. echo "\n\n<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
  827. echo "\t<tr>\n";
  828. echo "\t\t<td width=\"20%\" valign=\"top\">\n";
  829. }
  830. /*----------------------------------------------------
  831. ANNOUNCEMENTS LIST
  832. ----------------------------------------------------*/
  833. if(!$surveyid)
  834. {
  835. if ($display_title_list == true)
  836. {
  837. echo "\t\t\t<table>\n";
  838. while ($myrow = Database::fetch_array($result))
  839. {
  840. $title = $myrow['title'];
  841. echo "\t\t\t\t<tr>\n";
  842. echo "\t\t\t\t\t<td width=\"15%\">\n";
  843. if ($myrow['visibility']==0)
  844. { $class="class=\"invisible\"";}
  845. else
  846. { $class="";}
  847. 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";
  848. echo "\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
  849. }
  850. echo "\t\t\t</table>\n";
  851. } // end $display_title_list == true
  852. }
  853. if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath')
  854. {
  855. echo "\t\t</td>\n";
  856. echo "\t\t<td width=\"20\" background=\"../img/verticalruler.gif\">&nbsp;</td>\n";
  857. // START RIGHT PART
  858. echo "\t\t<td valign=\"top\">\n";
  859. }
  860. /*=======================================
  861. DISPLAY ACTION MESSAGE
  862. =======================================*/
  863. if (isset($message) && $message == true)
  864. {
  865. Display::display_normal_message($message);
  866. $display_announcement_list = true;
  867. $display_form = false;
  868. }
  869. if(!empty($error_message))
  870. {
  871. Display::display_error_message($error_message);
  872. $display_announcement_list = false;
  873. $display_form = true;
  874. }
  875. /*==================================================================================
  876. DISPLAY FORM
  877. ==================================================================================*/
  878. if ($display_form == true)
  879. {
  880. $content_to_modify=stripslashes($content_to_modify);
  881. $title_to_modify=stripslashes($title_to_modify);
  882. // DISPLAY ADD ANNOUNCEMENT COMMAND
  883. 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";
  884. //this variable defines if the course administrator can send a message to a specific user / group
  885. // or not
  886. //echo "sessiewaarde: ".$_SESSION['select_groupusers'];
  887. if(empty($_SESSION['toolgroup'])){
  888. echo "<table><tr><td>";
  889. echo get_lang("SentTo").": ";
  890. echo "</td><td>";
  891. if(isset($_GET['id']) && is_array($to)){
  892. echo '&nbsp;';
  893. }
  894. elseif(isset($_GET['remind_inactive']))
  895. {
  896. $email_ann = '1';
  897. $_SESSION['select_groupusers']="show";
  898. $content_to_modify = sprintf(get_lang('RemindInactiveLearnersMailContent'),api_get_setting('siteName'), 7);
  899. $title_to_modify = sprintf(get_lang('RemindInactiveLearnersMailSubject'),api_get_setting('siteName'));
  900. }
  901. elseif(isset($_GET['remindallinactives']) && $_GET['remindallinactives']=='true')
  902. {
  903. $since = isset($_GET['since']) ? intval($_GET['since']) : 6;
  904. $to = Tracking :: get_inactives_students_in_course($_course['id'],$since, $_SESSION['id_session']);
  905. foreach($to as &$user)
  906. {
  907. $user = 'USER:'.$user;
  908. }
  909. $_SESSION['select_groupusers']="show";
  910. $email_ann = '1';
  911. $content_to_modify = sprintf(get_lang('RemindInactiveLearnersMailContent'),api_get_setting('siteName'),$since);
  912. $title_to_modify = sprintf(get_lang('RemindInactiveLearnersMailSubject'),api_get_setting('siteName'));
  913. //echo '&nbsp;<script type="text/javascript">document.onload = "document.getElementById(\'recipient_list\').style.display=\'block\'";</script>';
  914. }
  915. else{
  916. echo get_lang("Everybody");
  917. }
  918. echo "</td><td>";
  919. 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>';
  920. echo "</td></tr></table>";
  921. show_to_form($to);
  922. echo "<br /><br />";
  923. if (!isset($announcement_to_modify) ) $announcement_to_modify ="";
  924. if ($announcement_to_modify=='')
  925. {
  926. ($email_ann=='1')?$checked='checked':$checked='';
  927. echo "<input class=\"checkbox\" type=checkbox value=\"1\" name=\"email_ann\" $checked> ".get_lang('EmailOption')," : ",
  928. "<br /><br />";
  929. }
  930. }else{
  931. if (!isset($announcement_to_modify) ) $announcement_to_modify ="";
  932. if ($announcement_to_modify=='')
  933. {
  934. ($email_ann=='1' || !empty($surveyid))?$checked='checked':$checked='';
  935. echo "<input class=\"checkbox\" type=checkbox value=\"1\" name=\"email_ann\" $checked> ".get_lang('EmailOption')," : ".get_lang('MyGroup'),
  936. "<br><br>";
  937. 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>';
  938. show_to_form_group($_SESSION['toolgroup']);
  939. echo '<br><br>';
  940. }
  941. }
  942. if($surveyid){
  943. echo get_lang('EmailAddress').": <input type=\"text\" name=\"emailsAdd\" value=\"".$emails_add."\" size=\"52\">(Comma separated for multiple)<br>";
  944. echo get_lang('OnlyThoseAddresses').": <input type=\"checkbox\" name=\"onlyThoseMails\"><br>";
  945. }
  946. echo "<div id='msg_error' style='display:none;color:red'></div>";
  947. echo "<label style='color:red;font-size:14pt'>*</label>&nbsp;".get_lang('EmailTitle').": <input type=\"text\" id=\"emailTitle\" name=\"emailTitle\" value=\"".$title_to_modify."\" size=\"52\" onfocus=\"document.getElementById('msg_error').style.display='none';\"><br />";
  948. unset($title_to_modify);
  949. $title_to_modify = null;
  950. if (!isset($announcement_to_modify) ) $announcement_to_modify ="";
  951. if (!isset($content_to_modify) ) $content_to_modify ="";
  952. if (!isset($title_to_modify)) $title_to_modify = "";
  953. echo "<br />\n<input type=\"hidden\" name=\"id\" value=\"".$announcement_to_modify."\">";
  954. if($surveyid){
  955. $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 />
  956. '.get_lang('OrCopyPasteUrl').' <br />
  957. '.api_get_path(WEB_CODE_PATH).'/survey/#page#?temp=#temp#&surveyid=#sid#&uid=#uid#&mail=#mail#&db_name=#db_name&nbsp;';
  958. }
  959. //api_disp_html_area('newContent',$content_to_modify,'250px');
  960. require_once(api_get_path(LIBRARY_PATH) . "/fckeditor/fckeditor.php");
  961. $oFCKeditor = new FCKeditor('newContent') ;
  962. $oFCKeditor->BasePath = api_get_path(WEB_PATH) . 'main/inc/lib/fckeditor/' ;
  963. $oFCKeditor->Height = '250';
  964. $oFCKeditor->Width = '100%';
  965. $oFCKeditor->Value = $content_to_modify;
  966. if(api_get_setting('advanced_filemanager'))
  967. {
  968. $oFCKeditor->Config['CustomConfigurationsPath'] = api_get_path(REL_PATH)."main/inc/lib/fckeditor/myconfig_afm.js";
  969. }
  970. else
  971. {
  972. $oFCKeditor->Config['CustomConfigurationsPath'] = api_get_path(REL_PATH)."main/inc/lib/fckeditor/myconfig.js";
  973. }
  974. $oFCKeditor->ToolbarSet = "Announcements";
  975. $TBL_LANGUAGES = Database::get_main_table(TABLE_MAIN_LANGUAGE);
  976. $sql="SELECT isocode FROM ".$TBL_LANGUAGES." WHERE english_name='".$_SESSION["_course"]["language"]."'";
  977. $result_sql=api_sql_query($sql, __FILE__, __LINE__);
  978. $isocode_language=Database::result($result_sql,0,0);
  979. $oFCKeditor->Config['DefaultLanguage'] = $isocode_language;
  980. echo $oFCKeditor->CreateHtml();
  981. if(empty($_SESSION['toolgroup'])){
  982. echo '<input type="hidden" name="submitAnnouncement" value="OK">';
  983. echo '<br /><input type="button" value="'.' '.get_lang('Ok').' '.'" onclick="selectAll(this.form.elements[3],true)" /><br /><br />';
  984. }
  985. else{
  986. echo '<input type="hidden" name="submitAnnouncement" value="OK">';
  987. echo '<br /><input type="button" value="'.' '.get_lang('Ok').' '.'" onclick="selectAll(this.form.elements[4],true)" /><br /><br />';
  988. }
  989. echo '</form><br />';
  990. if((isset($_GET['action']) && isset($_GET['id']) && is_array($to))||isset($_GET['remindallinactives'])||isset($_GET['remind_inactive'])){
  991. echo '<script>document.getElementById(\'recipient_list\').style.display=\'block\';</script>';
  992. }
  993. } // displayform
  994. /*===============================================
  995. DISPLAY ANNOUNCEMENT LIST
  996. ===============================================*/
  997. if ($display_announcement_list && !$surveyid)
  998. {
  999. // 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
  1000. $user_id=$_user['user_id'];
  1001. if (isset($_SESSION['user']))
  1002. {
  1003. $user_id=$_SESSION['user'];
  1004. }
  1005. if (isset($_SESSION['group']))
  1006. {
  1007. $group_id=$_SESSION['group'];
  1008. }
  1009. //$group_memberships=GroupManager::get_group_ids($_course['dbName'], $_user['user_id']);
  1010. $group_memberships=GroupManager::get_group_ids($_course['dbName'],$_user['user_id']);
  1011. if (api_is_allowed_to_edit(false,true))
  1012. {
  1013. // A.1. you are a course admin with a USER filter
  1014. // => see only the messages of this specific user + the messages of the group (s)he is member of.
  1015. if (isset($_SESSION['user']))
  1016. {
  1017. if (is_array($group_memberships) && count($group_memberships)>0)
  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 announcement.session_id IN(0,".intval($_SESSION['id_session']).")
  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_user_id=$user_id OR toolitemproperties.to_group_id='0')
  1036. AND toolitemproperties.visibility='1'
  1037. AND announcement.session_id IN(0,".intval($_SESSION['id_session']).")
  1038. ORDER BY display_order DESC";
  1039. }
  1040. }
  1041. // A.2. you are a course admin with a GROUP filter
  1042. // => see only the messages of this specific group
  1043. elseif (isset($_SESSION['group']))
  1044. {
  1045. $sql="SELECT
  1046. announcement.*, toolitemproperties.*
  1047. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  1048. WHERE announcement.id = toolitemproperties.ref
  1049. AND toolitemproperties.tool='announcement'
  1050. AND (toolitemproperties.to_group_id=$group_id OR toolitemproperties.to_group_id='0')
  1051. AND announcement.session_id IN(0,".intval($_SESSION['id_session']).")
  1052. GROUP BY toolitemproperties.ref
  1053. ORDER BY display_order DESC";
  1054. }
  1055. // A.3 you are a course admin without any group or user filter
  1056. else
  1057. {
  1058. // A.3.a you are a course admin without user or group filter but WITH studentview
  1059. // => see all the messages of all the users and groups without editing possibilities
  1060. if (isset($isStudentView) and $isStudentView=="true")
  1061. {
  1062. $sql="SELECT
  1063. announcement.*, toolitemproperties.*
  1064. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  1065. WHERE announcement.id = toolitemproperties.ref
  1066. AND toolitemproperties.tool='announcement'
  1067. AND toolitemproperties.visibility='1'
  1068. AND announcement.session_id IN(0,".intval($_SESSION['id_session']).")
  1069. GROUP BY toolitemproperties.ref
  1070. ORDER BY display_order DESC";
  1071. }
  1072. // A.3.a you are a course admin without user or group filter and WTIHOUT studentview (= the normal course admin view)
  1073. // => see all the messages of all the users and groups with editing possibilities
  1074. else
  1075. {
  1076. $sql="SELECT
  1077. announcement.*, toolitemproperties.*
  1078. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  1079. WHERE announcement.id = toolitemproperties.ref
  1080. AND toolitemproperties.tool='announcement'
  1081. AND (toolitemproperties.visibility='0' or toolitemproperties.visibility='1')
  1082. AND announcement.session_id IN(0,".intval($_SESSION['id_session']).")
  1083. GROUP BY toolitemproperties.ref
  1084. ORDER BY display_order DESC";
  1085. }
  1086. }
  1087. }
  1088. else //STUDENT
  1089. {
  1090. if (is_array($group_memberships) && count($group_memberships)>0)
  1091. {
  1092. $sql="SELECT
  1093. announcement.*, toolitemproperties.*
  1094. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  1095. WHERE announcement.id = toolitemproperties.ref
  1096. AND toolitemproperties.tool='announcement'
  1097. AND (toolitemproperties.to_user_id=$user_id OR toolitemproperties.to_group_id IN (0, ".implode(", ", $group_memberships).") )
  1098. AND toolitemproperties.visibility='1'
  1099. ORDER BY display_order DESC";
  1100. }
  1101. else
  1102. {
  1103. if ($_user['user_id'])
  1104. {
  1105. $sql="SELECT
  1106. announcement.*, toolitemproperties.*
  1107. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  1108. WHERE announcement.id = toolitemproperties.ref
  1109. AND toolitemproperties.tool='announcement'
  1110. AND (toolitemproperties.to_user_id='".$_user['user_id']."' OR toolitemproperties.to_group_id='0')
  1111. AND toolitemproperties.visibility='1'
  1112. AND announcement.session_id IN(0,".intval($_SESSION['id_session']).")
  1113. ORDER BY display_order DESC";
  1114. }
  1115. else
  1116. {
  1117. $sql="SELECT
  1118. announcement.*, toolitemproperties.*
  1119. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  1120. WHERE announcement.id = toolitemproperties.ref
  1121. AND toolitemproperties.tool='announcement'
  1122. AND toolitemproperties.to_group_id='0'
  1123. AND toolitemproperties.visibility='1'
  1124. AND announcement.session_id IN(0,".intval($_SESSION['id_session']).")";
  1125. }
  1126. }
  1127. }
  1128. $result = api_sql_query($sql,__FILE__,__LINE__);
  1129. $num_rows = Database::num_rows($result);
  1130. /*=================================================
  1131. DISPLAY: NO ITEMS
  1132. =================================================*/
  1133. if ($num_rows == 0)
  1134. {
  1135. echo get_lang('NoAnnouncements');;
  1136. }
  1137. $iterator = 1;
  1138. $bottomAnnouncement = $announcement_number;
  1139. echo "\t\t\t<table width=\"100%\" class=\"data_table\">\n";
  1140. $displayed=array();
  1141. while ($myrow = Database::fetch_array($result))
  1142. {
  1143. if (!in_array($myrow['id'], $displayed))
  1144. {
  1145. $title = $myrow['title'];
  1146. $content = $myrow['content'];
  1147. $content = make_clickable($content);
  1148. $content = text_filter($content);
  1149. /*================================================
  1150. DATE
  1151. ================================================*/
  1152. $last_post_datetime = $myrow['end_date'];
  1153. list($last_post_date, $last_post_time) = split(" ", $last_post_datetime);
  1154. list($year, $month, $day) = explode("-", $last_post_date);
  1155. list($hour, $min) = explode(":", $last_post_time);
  1156. $announceDate = mktime((int)$hour, (int)$min, 0, (int)$month, (int)$day, (int)$year);
  1157. // the styles
  1158. if ($myrow['visibility']=='0')
  1159. {
  1160. $style='invisible';
  1161. }
  1162. else
  1163. {
  1164. $style = '';
  1165. }
  1166. echo "\t\t\t\t<tr class=\"".$style."\">";
  1167. /*===================================================================
  1168. THE ICONS
  1169. ===================================================================*/
  1170. echo "\t\t\t\t\t<th>\n";
  1171. // anchoring
  1172. echo "<a name=\"".(int)($myrow["id"])."\"></a>\n";
  1173. // User or group icon
  1174. if ($myrow['to_group_id']!== '0' and $myrow['to_group_id']!== 'NULL')
  1175. {
  1176. echo "\t\t\t\t\t\t".Display::return_icon('group.gif', $alt_ug)."\n";
  1177. }
  1178. // the email icon
  1179. if ($myrow['email_sent'] == '1')
  1180. {
  1181. echo "\t\t\t\t\t\t".Display::return_icon('email.gif', $alt_mail)."\n";
  1182. }
  1183. echo "\t\t\t\t\t</th>\n";
  1184. /*==================================================================
  1185. TITLE
  1186. ==================================================================*/
  1187. echo "\t\t\t\t\t<th>".$title."</th>\n";
  1188. /*==================================================================
  1189. SENT TO
  1190. ===================================================================*/
  1191. echo "\t\t\t\t\t<th>" . get_lang("SentTo") . " : &nbsp; ";
  1192. $sent_to=sent_to("announcement", $myrow['id']);
  1193. $sent_to_form=sent_to_form($sent_to);
  1194. $user_info=api_get_user_info($myrow['insert_user_id']);
  1195. echo '&nbsp;&nbsp;&nbsp;'.get_lang('By').' : &nbsp;'.$user_info['lastName'].'&nbsp;'.$user_info['firstName'];
  1196. echo "\t\t\t\t\t</th>\n","\t\t\t\t</tr>\n";
  1197. /*=========================================================
  1198. TITLE
  1199. =========================================================*/
  1200. echo "\t\t\t\t<tr class='row_odd'>\n",
  1201. "\t\t\t\t\t<td class=\"announcements_datum\" colspan=\"3\">",
  1202. get_lang('AnnouncementPublishedOn')," : ",ucfirst(format_locale_date($dateFormatLong,strtotime($last_post_date))),
  1203. "</td>\n",
  1204. "\t\t\t\t</tr>\n",
  1205. /*=========================================================
  1206. CONTENT
  1207. =========================================================*/
  1208. "\t\t\t\t<tr class=\"$text_style\">\n",
  1209. "\t\t\t\t\t<td colspan=\"3\">\n",
  1210. $content,
  1211. "\t\t\t\t\t</td>\n",
  1212. "\t\t\t\t</tr>\n",
  1213. /*========================================================
  1214. RESOURCES
  1215. ========================================================*/
  1216. "<tr class='row_odd'>\n",
  1217. "<td colspan=\"3\">\n";
  1218. if (check_added_resources("Ad_Valvas", $myrow["id"]))
  1219. {
  1220. echo "<i>".get_lang('AddedResources')."</i><br />";
  1221. display_added_resources("Ad_Valvas", $myrow["id"]);
  1222. }
  1223. // we can edit if : we are the teacher OR the element belongs to the session we are coaching OR the option to allow users to edit is on
  1224. if(api_is_allowed_to_edit() OR (api_is_course_coach() && api_is_element_in_the_session(TOOL_ANNOUNCEMENT,$myrow['id'])) OR (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous()))
  1225. {
  1226. /*=====================================================================
  1227. SHOW MOD/DEL/VIS FUNCTIONS
  1228. =====================================================================*/
  1229. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&action=modify&id=".$myrow['id']."\">",
  1230. Display::return_icon('edit.gif', get_lang('Edit')),
  1231. "</a>";
  1232. if (api_is_allowed_to_edit(false,true)) echo "<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;\">",
  1233. Display::return_icon('delete.gif', get_lang('Delete')),
  1234. "</a>";
  1235. if ($myrow['visibility']==1)
  1236. {
  1237. $image_visibility="visible";
  1238. $alt_visibility=get_lang('Invisible');
  1239. }
  1240. else
  1241. {
  1242. $image_visibility="invisible";
  1243. $alt_visibility=get_lang('Visible');
  1244. }
  1245. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&origin=".(!empty($_GET['origin'])?$_GET['origin']:'')."&action=showhide&id=".$myrow['id']."\">",
  1246. Display::return_icon($image_visibility.'.gif', $alt_visibility)."</a>";
  1247. // DISPLAY MOVE UP COMMAND only if it is not the top announcement
  1248. if($iterator != 1)
  1249. {
  1250. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&up=",$myrow["id"],"\">",
  1251. Display::return_icon('up.gif', get_lang('Up')),
  1252. "</a>";
  1253. }
  1254. if($iterator < $bottomAnnouncement)
  1255. {
  1256. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&down=".$myrow["id"]."\">",
  1257. Display::return_icon('down.gif', get_lang('Down')),
  1258. "</a>";
  1259. }
  1260. echo "</td>\n",
  1261. "</tr>\n";
  1262. $iterator ++;
  1263. } // is_allowed_to_edit
  1264. echo "<tr><td width=\"100%\" colspan=\"3\"><a href=\"#top\">".Display::return_icon('top.gif', get_lang('Top'))."</a></td></tr>";
  1265. }
  1266. $displayed[]=$myrow['id'];
  1267. } // end while ($myrow = Database::fetch_array($result))
  1268. echo "</table>";
  1269. } // end: if ($displayAnnoucementList)
  1270. echo "</table>";
  1271. if (!empty($display_specific_announcement)) display_announcement($announcement_id);
  1272. /*
  1273. ==============================================================================
  1274. FOOTER
  1275. ==============================================================================
  1276. */
  1277. if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath')
  1278. {
  1279. //we are not in learnpath tool
  1280. Display::display_footer();
  1281. }
  1282. ?>