announcements.php 53 KB

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