announcements.php 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562
  1. <?php //$Id: announcements.php 20162 2009-04-28 20:41:46Z cfasanando $
  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_announcement(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. $userlist = "'".implode("', '", array_unique($userlist) )."'";
  569. // send to the created 'userlist'
  570. $sqlmail = "SELECT user_id, lastname, firstname, email
  571. FROM $tbl_user
  572. WHERE user_id IN (".$userlist.")";
  573. } else if (empty($_POST['not_selected_form'])) {
  574. if(empty($_SESSION['id_session']) || api_get_setting('use_session_mode')=='false') {
  575. // send to everybody
  576. $sqlmail = "SELECT user.user_id, user.email, user.lastname, user.firstname
  577. FROM $tbl_course_user, $tbl_user
  578. WHERE course_code='".Database::escape_string($_course['sysCode'])."'
  579. AND course_rel_user.user_id = user.user_id";
  580. } else {
  581. $sqlmail = "SELECT user.user_id, user.email, user.lastname, user.firstname
  582. FROM $tbl_user
  583. INNER JOIN $tbl_session_course_user
  584. ON $tbl_user.user_id = $tbl_session_course_user.id_user
  585. AND $tbl_session_course_user.course_code = '".$_course['id']."'
  586. AND $tbl_session_course_user.id_session = ".intval($_SESSION['id_session']);
  587. }
  588. }
  589. if ($sqlmail!='') {
  590. $result = api_sql_query($sqlmail,__FILE__,__LINE__);
  591. /*=================================================================================
  592. send email one by one to avoid antispam
  593. =================================================================================*/
  594. $db_name = Database::get_course_table(TABLE_MAIN_SURVEY);
  595. while ($myrow = Database::fetch_array($result)) {
  596. /* Header : Bericht van uw lesgever - GES ($_cid)
  597. Body : John Doe (prenom + nom) <john_doe@hotmail.com> (email)
  598. Morgen geen les!! (emailTitle)
  599. Morgen is er geen les, de les wordt geschrapt wegens vergadering (newContent)
  600. */
  601. $emailSubject = "[" . $_course['official_code'] . "] " . $emailTitle;
  602. if ($surveyid) {
  603. $newContentone=str_replace("#page#","choose_language.php",$newContent);
  604. $newContenttwo=str_replace("#temp#",$template,$newContentone);
  605. $newContentthree=str_replace("#sid#",$surveyid,$newContenttwo);
  606. $newContentfour=str_replace("#mail#",$myrow["email"],$newContentthree);
  607. $newContentfive=str_replace("#db_name#",$db_name,$newContentfour);
  608. $newContentsix=str_replace("#uid#",$myrow["user_id"],$newContentfive);
  609. $message=stripslashes($newContentsix);
  610. $sender_name = $_SESSION['_user']['lastName'].' '.$_SESSION['_user']['firstName'];
  611. $email = $_SESSION['_user']['mail'];
  612. $headers="From:$sender_name\r\nReply-to: $email\r\nContent-type: text/html; charset=iso-8859-15";
  613. //@mail($myrow["email"],stripslashes($emailTitle),$message,$headers);
  614. api_mail('',$myrow["email"],stripslashes($emailTitle),$message,$sender_name,$email);
  615. } else {
  616. // intro of the email: receiver name and subject
  617. $mail_body = $myrow["lastname"]." ".$myrow["firstname"]."<br />\n".stripslashes($emailTitle)."<br />";
  618. // main part of the email
  619. $mail_body .= trim(stripslashes($newContent));
  620. // signature of email: sender name and course URL after -- line
  621. $mail_body .= "<br />-- <br />";
  622. $mail_body .= $_user['firstName'].' '.$_user['lastName']." \n";
  623. $mail_body .= "<br /> \n<a href=\"".api_get_path(WEB_COURSE_PATH).$_course['id']."\">";
  624. $mail_body .= $_course['official_code'].' '.$_course['name'] . "</a>";
  625. //set the charset and use it for the encoding of the email - small fix, not really clean (should check the content encoding origin first)
  626. //here we use the encoding used for the webpage where the text is encoded (ISO-8859-1 in this case)
  627. //$to_email_address =$_POST['emailsAdd'];
  628. //$mail_body;
  629. $headers = array();
  630. if(empty($charset)){$charset='ISO-8859-1';}
  631. $headers['Content-Type'] = 'text/html';
  632. $headers['charset'] = $charset;
  633. $mailid=$myrow["email"];
  634. $newmail = api_mail_html($myrow["lastname"].' '.$myrow["firstname"], $myrow["email"], stripslashes($emailSubject), $mail_body, $_SESSION['_user']['lastName'].' '.$_SESSION['_user']['firstName'], $_SESSION['_user']['mail'],$headers);
  635. }
  636. $sql_date="SELECT * FROM $db_name WHERE survey_id='$surveyid'";
  637. $res_date=api_sql_query($sql_date, __FILE__, __LINE__);
  638. $obj_date=Database::fetch_object($res_date);
  639. $end_date=$obj_date->avail_till;
  640. $table_reminder = Database :: get_main_table(TABLE_MAIN_SURVEY_REMINDER);
  641. if($_REQUEST['reminder']=="1")
  642. {
  643. $time=getdate();
  644. $time = $time['yday'];
  645. $time = $time+7;
  646. $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')";
  647. api_sql_query($sql, __FILE__, __LINE__);
  648. }
  649. else if($_REQUEST['reminder']=="2")
  650. {
  651. $time=getdate();
  652. $time = $time['yday'];
  653. $time = $time+14;
  654. $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')";
  655. api_sql_query($sql, __FILE__, __LINE__);
  656. }
  657. else if($_REQUEST['reminder']=="3")
  658. {
  659. $time=getdate();
  660. $time = $time['yday'];
  661. $time = $time+30;
  662. $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')";
  663. api_sql_query($sql, __FILE__, __LINE__);
  664. }
  665. }
  666. update_mail_sent($insert_id);
  667. $message = $added_and_sent;
  668. }
  669. } // $email_ann*/
  670. } // isset
  671. // UNSET VARIABLES
  672. unset_session_resources();
  673. unset($form_elements);
  674. $_SESSION['formelements']=null;
  675. $newContent = null;
  676. $emailTitle = null;
  677. unset($emailTitle);
  678. unset($newContent);
  679. unset($content_to_modify);
  680. unset($title_to_modify);
  681. if($_REQUEST['publish_survey'])
  682. {
  683. $surveyid=$_REQUEST['surveyid'];
  684. $cidReq = $_REQUEST['cidReq'];
  685. ?>
  686. <script>
  687. window.location.href="../survey/survey_list.php?<?php echo api_get_cidreq(); ?>&published=published&surveyid=<?php echo $_REQUEST['publish_survey']; ?>";
  688. </script>
  689. <?php
  690. }
  691. } // if $submit Announcement
  692. }
  693. }
  694. /*====================================================
  695. Tool introduction
  696. ====================================================*/
  697. $fck_attribute['Width'] = '100%';
  698. $fck_attribute['Height'] = '300';
  699. $fck_attribute['ToolbarSet'] = 'Introduction';
  700. if (empty($_GET['origin']) || $_GET['origin'] !== 'learnpath')
  701. {
  702. //api_display_tool_title($nameTools);
  703. Display::display_introduction_section(TOOL_ANNOUNCEMENT);
  704. }
  705. $fck_attribute = null; // Clearing this global variable immediatelly after it has been used.
  706. /*
  707. ==============================================================================
  708. MAIN SECTION
  709. ==============================================================================
  710. */
  711. /*=====================================================================================
  712. MAIN CODE HTML
  713. =====================================================================================*/
  714. // The commands below will change these display settings if they need it
  715. /*======================================================================
  716. DISPLAY LEFT COLUMN
  717. ======================================================================*/
  718. if(api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous()) ) // check teacher status
  719. {
  720. /*if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath')
  721. {
  722. $sql="SELECT
  723. announcement.*, toolitemproperties.*
  724. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  725. WHERE announcement.id = toolitemproperties.ref
  726. AND toolitemproperties.tool='announcement'
  727. AND toolitemproperties.visibility<>'2'
  728. AND announcement.session_id IN(0,".intval($_SESSION['id_session']).")
  729. GROUP BY toolitemproperties.ref
  730. ORDER BY display_order DESC
  731. LIMIT 0,$maximum";
  732. }
  733. }
  734. else // students only get to see the visible announcements
  735. {*/
  736. if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath')
  737. {
  738. $group_memberships=GroupManager::get_group_ids($_course['dbName'], $_user['user_id']);
  739. // the user is member of several groups => display personal announcements AND his group announcements AND the general announcements
  740. if (is_array($group_memberships) && count($group_memberships)>0)
  741. {
  742. $sql="SELECT
  743. announcement.*, toolitemproperties.*
  744. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  745. WHERE announcement.id = toolitemproperties.ref
  746. AND toolitemproperties.tool='announcement'
  747. AND toolitemproperties.visibility='1'
  748. AND ( toolitemproperties.to_user_id='".$_user['user_id']."'" .
  749. "OR toolitemproperties.to_group_id IN (0, ".implode(", ", $group_memberships).") )
  750. AND announcement.session_id IN(0,".intval($_SESSION['id_session']).")
  751. GROUP BY toolitemproperties.ref
  752. ORDER BY display_order DESC
  753. LIMIT 0,$maximum";
  754. }
  755. // the user is not member of any group
  756. else
  757. {
  758. // this is an identified user => show the general announcements AND his personal announcements
  759. if ($_user['user_id'])
  760. {
  761. $sql="SELECT
  762. announcement.*, toolitemproperties.*
  763. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  764. WHERE announcement.id = toolitemproperties.ref
  765. AND toolitemproperties.tool='announcement'
  766. AND toolitemproperties.visibility='1'
  767. AND ( toolitemproperties.to_user_id='".$_user['user_id']."' OR toolitemproperties.to_group_id='0')
  768. AND announcement.session_id IN(0,".intval($_SESSION['id_session']).")
  769. GROUP BY toolitemproperties.ref
  770. ORDER BY display_order DESC
  771. LIMIT 0,$maximum";
  772. }
  773. // the user is not identiefied => show only the general announcements
  774. else
  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_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. }
  789. }
  790. }
  791. $result = api_sql_query($sql,__FILE__,__LINE__);
  792. $announcement_number = Database::num_rows($result);
  793. /*----------------------------------------------------
  794. ADD ANNOUNCEMENT / DELETE ALL
  795. ----------------------------------------------------*/
  796. echo '<div class="actions">';
  797. if (!$surveyid) {
  798. 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'))
  799. {
  800. 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>";
  801. }
  802. if (api_is_allowed_to_edit() && $announcement_number > 1)
  803. {
  804. 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";
  805. } // if announcementNumber > 1
  806. }
  807. echo '</div>';
  808. if (empty($_GET['origin']) OR $_GET['origin'] !== 'learnpath') {
  809. echo "\n\n<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
  810. echo "\t<tr>\n";
  811. echo "\t\t<td width=\"20%\" valign=\"top\">\n";
  812. }
  813. /*----------------------------------------------------
  814. ANNOUNCEMENTS LIST
  815. ----------------------------------------------------*/
  816. if (!$surveyid) {
  817. if ($display_title_list == true) {
  818. echo "\t\t\t<table>\n";
  819. while ($myrow = Database::fetch_array($result)) {
  820. $title = $myrow['title'];
  821. echo "\t\t\t\t<tr>\n";
  822. echo "\t\t\t\t\t<td width=\"15%\">\n";
  823. if ($myrow['visibility']==0)
  824. { $class="class=\"invisible\"";}
  825. else
  826. { $class="";}
  827. 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";
  828. echo "\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
  829. }
  830. echo "\t\t\t</table>\n";
  831. } // end $display_title_list == true
  832. }
  833. if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath') {
  834. echo "\t\t</td>\n";
  835. echo "\t\t<td width=\"20\" background=\"../img/verticalruler.gif\">&nbsp;</td>\n";
  836. // START RIGHT PART
  837. echo "\t\t<td valign=\"top\">\n";
  838. }
  839. /*=======================================
  840. DISPLAY ACTION MESSAGE
  841. =======================================*/
  842. if (isset($message) && $message == true) {
  843. Display::display_confirmation_message($message);
  844. $display_announcement_list = true;
  845. $display_form = false;
  846. }
  847. if (!empty($error_message)) {
  848. Display::display_error_message($error_message);
  849. $display_announcement_list = false;
  850. $display_form = true;
  851. }
  852. /*==================================================================================
  853. DISPLAY FORM
  854. ==================================================================================*/
  855. if ($display_form == true) {
  856. $content_to_modify=stripslashes($content_to_modify);
  857. $title_to_modify=stripslashes($title_to_modify);
  858. // DISPLAY ADD ANNOUNCEMENT COMMAND
  859. 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']).'&action='.Security::remove_XSS($_GET['action']).'" style="margin:0px;">'."\n";
  860. if (empty($_GET['id'])) {
  861. $form_name = get_lang('AddAnnouncement');
  862. } else {
  863. $form_name = get_lang('ModifyAnnouncement');
  864. }
  865. echo '<div class="row"><div class="form_header">'.$form_name.'</div></div>';
  866. //this variable defines if the course administrator can send a message to a specific user / group or not
  867. if (empty($_SESSION['toolgroup'])) {
  868. echo ' <div class="row">
  869. <div class="label">'.
  870. 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>
  871. </div>
  872. <div class="formw">';
  873. if (isset($_GET['id']) && is_array($to)) {
  874. echo '&nbsp;';
  875. } elseif (isset($_GET['remind_inactive'])) {
  876. $email_ann = '1';
  877. $_SESSION['select_groupusers']="show";
  878. $content_to_modify = sprintf(get_lang('RemindInactiveLearnersMailContent'),api_get_setting('siteName'), 7);
  879. $title_to_modify = sprintf(get_lang('RemindInactiveLearnersMailSubject'),api_get_setting('siteName'));
  880. } elseif(isset($_GET['remindallinactives']) && $_GET['remindallinactives']=='true') {
  881. $since = isset($_GET['since']) ? intval($_GET['since']) : 6;
  882. $to = Tracking :: get_inactives_students_in_course($_course['id'],$since, $_SESSION['id_session']);
  883. foreach($to as &$user) {
  884. $user = 'USER:'.$user;
  885. }
  886. $_SESSION['select_groupusers']="show";
  887. $email_ann = '1';
  888. $content_to_modify = sprintf(get_lang('RemindInactiveLearnersMailContent'),api_get_setting('siteName'),$since);
  889. $title_to_modify = sprintf(get_lang('RemindInactiveLearnersMailSubject'),api_get_setting('siteName'));
  890. } else {
  891. echo get_lang("Everybody");
  892. }
  893. show_to_form($to);
  894. echo ' </div>
  895. </div>';
  896. if (!isset($announcement_to_modify) ) $announcement_to_modify ='';
  897. if ($announcement_to_modify=='') {
  898. ($email_ann=='1')?$checked='checked':$checked='';
  899. echo ' <div class="row">
  900. <div class="label">
  901. <input class="checkbox" type="checkbox" value="1" name="email_ann" checked>
  902. </div>
  903. <div class="formw">'.get_lang('EmailOption').'
  904. </div>
  905. </div>';
  906. }
  907. }
  908. else
  909. {
  910. if (!isset($announcement_to_modify) ) $announcement_to_modify ="";
  911. if ($announcement_to_modify=='')
  912. {
  913. ($email_ann=='1' || !empty($surveyid))?$checked='checked':$checked='';
  914. echo ' <div class="row">
  915. <div class="label">
  916. <input class="checkbox" type="checkbox" value="1" name="email_ann" '.$checked.'>
  917. </div>
  918. <div class="formw">'.
  919. 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>';
  920. show_to_form_group($_SESSION['toolgroup']);
  921. echo ' </div>
  922. </div>';
  923. }
  924. }
  925. if($surveyid)
  926. {
  927. echo ' <div class="row">
  928. <div class="label">
  929. '.get_lang('EmailAddress').'
  930. </div>
  931. <div class="formw">
  932. <input type="text" name="emailsAdd" value="'.$emails_add.'" size="52">(Comma separated for multiple)
  933. </div>
  934. </div>';
  935. echo ' <div class="row">
  936. <div class="label">
  937. '.get_lang('OnlyThoseAddresses').'
  938. </div>
  939. <div class="formw">
  940. <input type="checkbox" name="onlyThoseMails">
  941. </div>
  942. </div>';
  943. }
  944. // the announcement title
  945. echo ' <div class="row">
  946. <div class="label">
  947. <span class="form_required">*</span> '.get_lang('EmailTitle').'
  948. </div>
  949. <div class="formw">
  950. <input type="text" id="emailTitle" name="emailTitle" value="'.$title_to_modify.'" size="60">
  951. </div>
  952. </div>';
  953. unset($title_to_modify);
  954. $title_to_modify = null;
  955. if (!isset($announcement_to_modify) ) $announcement_to_modify ="";
  956. if (!isset($content_to_modify) ) $content_to_modify ="";
  957. if (!isset($title_to_modify)) $title_to_modify = "";
  958. echo '<input type="hidden" name="id" value="'.$announcement_to_modify.'" />';
  959. if($surveyid){
  960. $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 />
  961. '.get_lang('OrCopyPasteUrl').' <br />
  962. '.api_get_path(WEB_CODE_PATH).'/survey/#page#?temp=#temp#&surveyid=#sid#&uid=#uid#&mail=#mail#&db_name=#db_name&nbsp;';
  963. }
  964. //api_disp_html_area('newContent',$content_to_modify,'250px');
  965. require_once(api_get_path(LIBRARY_PATH) . "/fckeditor/fckeditor.php");
  966. $oFCKeditor = new FCKeditor('newContent') ;
  967. $oFCKeditor->Width = '100%';
  968. $oFCKeditor->Height = '300';
  969. if(!api_is_allowed_to_edit())
  970. {
  971. $oFCKeditor->ToolbarSet = "Announcements_Student";
  972. }
  973. else
  974. {
  975. $oFCKeditor->ToolbarSet = "Announcements";
  976. }
  977. $oFCKeditor->Value = $content_to_modify;
  978. echo $oFCKeditor->CreateHtml();
  979. echo'<br />';
  980. if(empty($_SESSION['toolgroup'])){
  981. echo '<input type="hidden" name="submitAnnouncement" value="OK">';
  982. echo '<button class="save"type="submit" value="'.' '.get_lang('Send').' '.'" onclick="selectAll(this.form.elements[3],true)" >'.get_lang('ButtonPublishAnnouncement').'</button><br /><br />';
  983. }
  984. else{
  985. echo '<input type="hidden" name="submitAnnouncement" value="OK">';
  986. echo '<button class="save"type="submit" value="'.' '.get_lang('Send').' '.'" onclick="selectAll(this.form.elements[4],true)" >'.get_lang('ButtonPublishAnnouncement').'</button><br /><br />';
  987. }
  988. echo '</form><br />';
  989. if((isset($_GET['action']) && isset($_GET['id']) && is_array($to))||isset($_GET['remindallinactives'])||isset($_GET['remind_inactive'])){
  990. echo '<script>document.getElementById(\'recipient_list\').style.display=\'block\';</script>';
  991. }
  992. } // displayform
  993. /*===============================================
  994. DISPLAY ANNOUNCEMENT LIST
  995. ===============================================*/
  996. if ($display_announcement_list && !$surveyid)
  997. {
  998. // 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
  999. $user_id=$_user['user_id'];
  1000. if (isset($_SESSION['user']))
  1001. {
  1002. $user_id=$_SESSION['user'];
  1003. }
  1004. if (isset($_SESSION['group']))
  1005. {
  1006. $group_id=$_SESSION['group'];
  1007. }
  1008. //$group_memberships=GroupManager::get_group_ids($_course['dbName'], $_user['user_id']);
  1009. $group_memberships=GroupManager::get_group_ids($_course['dbName'],$_user['user_id']);
  1010. if (api_is_allowed_to_edit(false,true))
  1011. {
  1012. // A.1. you are a course admin with a USER filter
  1013. // => see only the messages of this specific user + the messages of the group (s)he is member of.
  1014. if (isset($_SESSION['user']))
  1015. {
  1016. if (is_array($group_memberships) && count($group_memberships)>0)
  1017. {
  1018. $sql="SELECT
  1019. announcement.*, toolitemproperties.*
  1020. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  1021. WHERE announcement.id = toolitemproperties.ref
  1022. AND toolitemproperties.tool='announcement'
  1023. AND (toolitemproperties.to_user_id=$user_id OR toolitemproperties.to_group_id IN (0, ".implode(", ", $group_memberships).") )
  1024. AND announcement.session_id IN(0,".intval($_SESSION['id_session']).")
  1025. ORDER BY display_order DESC";
  1026. }
  1027. else
  1028. {
  1029. $sql="SELECT
  1030. announcement.*, toolitemproperties.*
  1031. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  1032. WHERE announcement.id = toolitemproperties.ref
  1033. AND toolitemproperties.tool='announcement'
  1034. AND (toolitemproperties.to_user_id=$user_id OR toolitemproperties.to_group_id='0')
  1035. AND toolitemproperties.visibility='1'
  1036. AND announcement.session_id IN(0,".intval($_SESSION['id_session']).")
  1037. ORDER BY display_order DESC";
  1038. }
  1039. }
  1040. // A.2. you are a course admin with a GROUP filter
  1041. // => see only the messages of this specific group
  1042. elseif (isset($_SESSION['group']))
  1043. {
  1044. $sql="SELECT
  1045. announcement.*, toolitemproperties.*
  1046. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  1047. WHERE announcement.id = toolitemproperties.ref
  1048. AND toolitemproperties.tool='announcement'
  1049. AND (toolitemproperties.to_group_id=$group_id OR toolitemproperties.to_group_id='0')
  1050. AND announcement.session_id IN(0,".intval($_SESSION['id_session']).")
  1051. GROUP BY toolitemproperties.ref
  1052. ORDER BY display_order DESC";
  1053. }
  1054. // A.3 you are a course admin without any group or user filter
  1055. else
  1056. {
  1057. // A.3.a you are a course admin without user or group filter but WITH studentview
  1058. // => see all the messages of all the users and groups without editing possibilities
  1059. if (isset($isStudentView) and $isStudentView=="true")
  1060. {
  1061. $sql="SELECT
  1062. announcement.*, toolitemproperties.*
  1063. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  1064. WHERE announcement.id = toolitemproperties.ref
  1065. AND toolitemproperties.tool='announcement'
  1066. AND toolitemproperties.visibility='1'
  1067. AND announcement.session_id IN(0,".intval($_SESSION['id_session']).")
  1068. GROUP BY toolitemproperties.ref
  1069. ORDER BY display_order DESC";
  1070. }
  1071. // A.3.a you are a course admin without user or group filter and WTIHOUT studentview (= the normal course admin view)
  1072. // => see all the messages of all the users and groups with editing possibilities
  1073. else
  1074. {
  1075. $sql="SELECT
  1076. announcement.*, toolitemproperties.*
  1077. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  1078. WHERE announcement.id = toolitemproperties.ref
  1079. AND toolitemproperties.tool='announcement'
  1080. AND (toolitemproperties.visibility='0' or toolitemproperties.visibility='1')
  1081. AND announcement.session_id IN(0,".intval($_SESSION['id_session']).")
  1082. GROUP BY toolitemproperties.ref
  1083. ORDER BY display_order DESC";
  1084. }
  1085. }
  1086. }
  1087. else //STUDENT
  1088. {
  1089. if (is_array($group_memberships) && count($group_memberships)>0)
  1090. {
  1091. $sql="SELECT
  1092. announcement.*, toolitemproperties.*
  1093. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  1094. WHERE announcement.id = toolitemproperties.ref
  1095. AND toolitemproperties.tool='announcement'
  1096. AND (toolitemproperties.to_user_id=$user_id OR toolitemproperties.to_group_id IN (0, ".implode(", ", $group_memberships).") )
  1097. AND toolitemproperties.visibility='1'
  1098. ORDER BY display_order DESC";
  1099. }
  1100. else
  1101. {
  1102. if ($_user['user_id'])
  1103. {
  1104. $sql="SELECT
  1105. announcement.*, toolitemproperties.*
  1106. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  1107. WHERE announcement.id = toolitemproperties.ref
  1108. AND toolitemproperties.tool='announcement'
  1109. AND (toolitemproperties.to_user_id='".$_user['user_id']."' OR toolitemproperties.to_group_id='0')
  1110. AND toolitemproperties.visibility='1'
  1111. AND announcement.session_id IN(0,".intval($_SESSION['id_session']).")
  1112. ORDER BY display_order DESC";
  1113. }
  1114. else
  1115. {
  1116. $sql="SELECT
  1117. announcement.*, toolitemproperties.*
  1118. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  1119. WHERE announcement.id = toolitemproperties.ref
  1120. AND toolitemproperties.tool='announcement'
  1121. AND toolitemproperties.to_group_id='0'
  1122. AND toolitemproperties.visibility='1'
  1123. AND announcement.session_id IN(0,".intval($_SESSION['id_session']).")";
  1124. }
  1125. }
  1126. }
  1127. $result = api_sql_query($sql,__FILE__,__LINE__);
  1128. $num_rows = Database::num_rows($result);
  1129. /*=================================================
  1130. DISPLAY: NO ITEMS
  1131. =================================================*/
  1132. if ($num_rows == 0)
  1133. {
  1134. echo get_lang('NoAnnouncements');;
  1135. }
  1136. $iterator = 1;
  1137. $bottomAnnouncement = $announcement_number;
  1138. echo "\t\t\t<table width=\"100%\" class=\"data_table\">\n";
  1139. $displayed=array();
  1140. while ($myrow = Database::fetch_array($result))
  1141. {
  1142. if (!in_array($myrow['id'], $displayed))
  1143. {
  1144. $title = $myrow['title'];
  1145. $content = $myrow['content'];
  1146. $content = make_clickable($content);
  1147. $content = text_filter($content);
  1148. /*================================================
  1149. DATE
  1150. ================================================*/
  1151. $last_post_datetime = $myrow['end_date'];
  1152. list($last_post_date, $last_post_time) = split(" ", $last_post_datetime);
  1153. list($year, $month, $day) = explode("-", $last_post_date);
  1154. list($hour, $min) = explode(":", $last_post_time);
  1155. $announceDate = mktime((int)$hour, (int)$min, 0, (int)$month, (int)$day, (int)$year);
  1156. // the styles
  1157. if ($myrow['visibility']=='0')
  1158. {
  1159. $style='invisible';
  1160. }
  1161. else
  1162. {
  1163. $style = '';
  1164. }
  1165. echo "\t\t\t\t<tr class=\"".$style."\">";
  1166. /*===================================================================
  1167. THE ICONS
  1168. ===================================================================*/
  1169. echo "\t\t\t\t\t<th>\n";
  1170. // anchoring
  1171. echo "<a name=\"".(int)($myrow["id"])."\"></a>\n";
  1172. // User or group icon
  1173. if ($myrow['to_group_id']!== '0' and $myrow['to_group_id']!== 'NULL')
  1174. {
  1175. echo "\t\t\t\t\t\t".Display::return_icon('group.gif', get_lang('AnnounceSentToUserSelection'))."\n";
  1176. }
  1177. // the email icon
  1178. if ($myrow['email_sent'] == '1')
  1179. {
  1180. echo "\t\t\t\t\t\t".Display::return_icon('email.gif', get_lang('AnnounceSentByEmail'))."\n";
  1181. }
  1182. echo "\t\t\t\t\t</th>\n";
  1183. /*==================================================================
  1184. TITLE
  1185. ==================================================================*/
  1186. echo "\t\t\t\t\t<th>".$title."</th>\n";
  1187. /*==================================================================
  1188. SENT TO
  1189. ===================================================================*/
  1190. echo "\t\t\t\t\t<th>" . get_lang("SentTo") . " : &nbsp; ";
  1191. $sent_to=sent_to("announcement", $myrow['id']);
  1192. $sent_to_form=sent_to_form($sent_to);
  1193. $user_info=api_get_user_info($myrow['insert_user_id']);
  1194. echo '&nbsp;&nbsp;&nbsp;'.get_lang('By').' : &nbsp;'.$user_info['lastName'].'&nbsp;'.$user_info['firstName'];
  1195. echo "\t\t\t\t\t</th>\n","\t\t\t\t</tr>\n";
  1196. /*=========================================================
  1197. TITLE
  1198. =========================================================*/
  1199. echo "\t\t\t\t<tr class='row_odd'>\n",
  1200. "\t\t\t\t\t<td class=\"announcements_datum\" colspan=\"3\">",
  1201. get_lang('AnnouncementPublishedOn')," : ",ucfirst(format_locale_date($dateFormatLong,strtotime($last_post_date))),
  1202. "</td>\n",
  1203. "\t\t\t\t</tr>\n",
  1204. /*=========================================================
  1205. CONTENT
  1206. =========================================================*/
  1207. "\t\t\t\t<tr class=\"$text_style\">\n",
  1208. "\t\t\t\t\t<td colspan=\"3\">\n",
  1209. $content,
  1210. "\t\t\t\t\t</td>\n",
  1211. "\t\t\t\t</tr>\n",
  1212. /*========================================================
  1213. RESOURCES
  1214. ========================================================*/
  1215. "<tr class='row_odd'>\n",
  1216. "<td colspan=\"3\">\n";
  1217. if (check_added_resources("Ad_Valvas", $myrow["id"]))
  1218. {
  1219. echo "<i>".get_lang('AddedResources')."</i><br />";
  1220. display_added_resources("Ad_Valvas", $myrow["id"]);
  1221. }
  1222. // 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
  1223. 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()))
  1224. {
  1225. /*=====================================================================
  1226. SHOW MOD/DEL/VIS FUNCTIONS
  1227. =====================================================================*/
  1228. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&action=modify&id=".$myrow['id']."\">",
  1229. Display::return_icon('edit.gif', get_lang('Edit')),
  1230. "</a>";
  1231. 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;\">",
  1232. Display::return_icon('delete.gif', get_lang('Delete')),
  1233. "</a>";
  1234. if ($myrow['visibility']==1)
  1235. {
  1236. $image_visibility="visible";
  1237. $alt_visibility=get_lang('Hide');
  1238. }
  1239. else
  1240. {
  1241. $image_visibility="invisible";
  1242. $alt_visibility=get_lang('Visible');
  1243. }
  1244. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&origin=".(!empty($_GET['origin'])?$_GET['origin']:'')."&action=showhide&id=".$myrow['id']."\">",
  1245. Display::return_icon($image_visibility.'.gif', $alt_visibility)."</a>";
  1246. // DISPLAY MOVE UP COMMAND only if it is not the top announcement
  1247. if($iterator != 1)
  1248. {
  1249. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&up=",$myrow["id"],"\">",
  1250. Display::return_icon('up.gif', get_lang('Up')),
  1251. "</a>";
  1252. }
  1253. if($iterator < $bottomAnnouncement)
  1254. {
  1255. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&down=".$myrow["id"]."\">",
  1256. Display::return_icon('down.gif', get_lang('Down')),
  1257. "</a>";
  1258. }
  1259. echo "</td>\n",
  1260. "</tr>\n";
  1261. $iterator ++;
  1262. } // is_allowed_to_edit
  1263. echo "<tr><td width=\"100%\" colspan=\"3\"><a href=\"#top\">".Display::return_icon('top.gif', get_lang('Top'))."</a></td></tr>";
  1264. }
  1265. $displayed[]=$myrow['id'];
  1266. } // end while ($myrow = Database::fetch_array($result))
  1267. echo "</table>";
  1268. } // end: if ($displayAnnoucementList)
  1269. echo "</table>";
  1270. if (!empty($display_specific_announcement)) display_announcement($announcement_id);
  1271. /*
  1272. ==============================================================================
  1273. FOOTER
  1274. ==============================================================================
  1275. */
  1276. if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath')
  1277. {
  1278. //we are not in learnpath tool
  1279. Display::display_footer();
  1280. }
  1281. ?>