announcements.php 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535
  1. <?php //$Id: announcements.php 2009-11-13 18:56:45Z aportugal $
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @author Frederik Vermeire <frederik.vermeire@pandora.be>, UGent Internship
  5. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: code cleaning
  6. * @abstract The task of the internship was to integrate the 'send messages to specific users' with the
  7. * Announcements tool and also add the resource linker here. The database also needed refactoring
  8. * as there was no title field (the title was merged into the content field)
  9. * @package dokeos.announcements
  10. * @todo make AWACS out of the configuration settings
  11. * @todo this file is 1200+ lines without any functions -> needs to be split into
  12. * multiple functions
  13. */
  14. /*
  15. ==============================================================================
  16. INIT SECTION
  17. ==============================================================================
  18. */
  19. // name of the language file that needs to be included
  20. $language_file[] = 'announcements';
  21. $language_file[] = 'group';
  22. $language_file[] = 'survey';
  23. // use anonymous mode when accessing this course tool
  24. $use_anonymous = true;
  25. // setting the global file that gets the general configuration, the databases, the languages, ...
  26. require_once '../inc/global.inc.php';
  27. $this_section=SECTION_COURSES;
  28. $nameTools = get_lang('ToolAnnouncement');
  29. //session
  30. if(isset($_GET['id_session'])) {
  31. $_SESSION['id_session'] = intval($_GET['id_session']);
  32. }
  33. /* ------------ ACCESS RIGHTS ------------ */
  34. // notice for unauthorized people.
  35. api_protect_course_script();
  36. /*
  37. -----------------------------------------------------------
  38. Constants and variables
  39. -----------------------------------------------------------
  40. */
  41. // Configuration settings
  42. $display_announcement_list = true;
  43. $display_form = false;
  44. $display_title_list = true;
  45. // Maximum title messages to display
  46. $maximum = '12';
  47. // Length of the titles
  48. $length = '36';
  49. // Database Table Definitions
  50. $tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  51. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  52. $tbl_courses = Database::get_main_table(TABLE_MAIN_COURSE);
  53. $tbl_sessions = Database::get_main_table(TABLE_MAIN_SESSION);
  54. $tbl_session_course_user= Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  55. $tbl_group = Database::get_course_table(TABLE_GROUP);
  56. $tbl_groupUser = Database::get_course_table(TABLE_GROUP_USER);
  57. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
  58. $tbl_announcement_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
  59. $tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
  60. /*
  61. -----------------------------------------------------------
  62. Resource linker
  63. -----------------------------------------------------------
  64. */
  65. $_SESSION['source_type']="Ad_Valvas";
  66. include('../resourcelinker/resourcelinker.inc.php');
  67. if (!empty($_POST['addresources'])) // When the "Add Resource" button is clicked we store all the form data into a session
  68. {
  69. include('announcements.inc.php');
  70. $form_elements= array ('emailTitle'=>stripslashes($emailTitle), 'newContent'=>stripslashes($newContent), 'id'=>$id, 'to'=>$selectedform, 'emailoption'=>$email_ann);
  71. $_SESSION['formelements']=$form_elements;
  72. if($id) // this is to correctly handle edits
  73. {
  74. $action="edit";
  75. }else
  76. {
  77. $action="add";
  78. }
  79. // ============== //
  80. // 7 = Ad_Valvas //
  81. // ============== //
  82. if($surveyid)
  83. {
  84. header("Location: ../resourcelinker/resourcelinker.php?source_id=7&action=$action&id=$id&originalresource=no&publish_survey=$surveyid&db_name=$db_name&cidReq=$cidReq");
  85. exit;
  86. }
  87. else
  88. {
  89. header("Location: ../resourcelinker/resourcelinker.php?source_id=7&action=$action&id=$id&originalresource=no");
  90. exit;
  91. }
  92. exit;
  93. }
  94. /*
  95. -----------------------------------------------------------
  96. Tracking
  97. -----------------------------------------------------------
  98. */
  99. event_access_tool(TOOL_ANNOUNCEMENT);
  100. /*
  101. -----------------------------------------------------------
  102. Libraries
  103. -----------------------------------------------------------
  104. */
  105. $lib = api_get_path(LIBRARY_PATH); //avoid useless function calls
  106. require_once($lib.'groupmanager.lib.php');
  107. require_once('announcements.inc.php');
  108. require_once($lib.'mail.lib.inc.php');
  109. require_once($lib.'debug.lib.inc.php');
  110. require_once($lib.'tracking.lib.php');
  111. require_once($lib.'fckeditor/fckeditor.php');
  112. require_once($lib.'fileUpload.lib.php');
  113. /*
  114. -----------------------------------------------------------
  115. POST TO
  116. -----------------------------------------------------------
  117. */
  118. $safe_emailTitle = $_POST['emailTitle'];
  119. $safe_newContent = $_POST['newContent'];
  120. if (!empty($_POST['To']))
  121. {
  122. if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) {
  123. api_not_allowed();
  124. }
  125. $display_form = true;
  126. $form_elements = array ('emailTitle'=>$safe_emailTitle, 'newContent'=>$safe_newContent, 'id'=>Security::remove_XSS($_POST['id']), 'emailoption'=>Security::remove_XSS($_POST['email_ann']));
  127. $_SESSION['formelements'] = $form_elements;
  128. $form_elements = $_SESSION['formelements'];
  129. $title_to_modify = $form_elements["emailTitle"];
  130. $content_to_modify = $form_elements["newContent"];
  131. $announcement_to_modify = $form_elements["id"];
  132. }
  133. /*
  134. -----------------------------------------------------------
  135. Show/hide user/group form
  136. -----------------------------------------------------------
  137. */
  138. $setting_select_groupusers = true;
  139. if (empty($_POST['To']) and !$_SESSION['select_groupusers'])
  140. {
  141. $_SESSION['select_groupusers'] = "hide";
  142. }
  143. $select_groupusers_status=$_SESSION['select_groupusers'];
  144. if (!empty($_POST['To']) and ($select_groupusers_status=="hide"))
  145. {
  146. $_SESSION['select_groupusers'] = "show";
  147. }
  148. if (!empty($_POST['To']) and ($select_groupusers_status=="show"))
  149. {
  150. $_SESSION['select_groupusers'] = "hide";
  151. }
  152. /*
  153. -----------------------------------------------------------
  154. Action handling
  155. -----------------------------------------------------------
  156. */
  157. // display the form
  158. if (((!empty($_GET['action']) && $_GET['action'] == 'add') && $_GET['origin'] == "") || (!empty($_GET['action']) && $_GET['action'] == 'edit') || !empty($_POST['To']))
  159. {
  160. if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) {
  161. api_not_allowed();
  162. }
  163. $display_form = true;
  164. }
  165. // clear all resources
  166. if ((empty($originalresource) || ($originalresource!=='no')) and (!empty($action) && $action=='add'))
  167. {
  168. $_SESSION['formelements']=null;
  169. //unset($_SESSION['formelements']);
  170. unset_session_resources();
  171. }
  172. /*
  173. -----------------------------------------------------------
  174. Javascript
  175. -----------------------------------------------------------
  176. */
  177. $htmlHeadXtra[] = to_javascript();
  178. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.js" type="text/javascript" language="javascript"></script>'; //jQuery
  179. $htmlHeadXtra[] = '<script type="text/javascript">
  180. function setFocus(){
  181. $("#emailTitle").focus();
  182. }
  183. $(document).ready(function () {
  184. setFocus();
  185. });
  186. </script>';
  187. /*
  188. -----------------------------------------------------------
  189. Filter user/group
  190. -----------------------------------------------------------
  191. */
  192. if(!empty($_GET['toolgroup'])){
  193. if($_GET['toolgroup'] == strval(intval($_GET['toolgroup']))){ //check is integer
  194. $toolgroup = $_GET['toolgroup'];
  195. $_SESSION['select_groupusers'] = 'hide';
  196. }else{
  197. $toolgroup = 0;
  198. }
  199. api_session_register("toolgroup");
  200. }
  201. /*
  202. -----------------------------------------------------------
  203. Sessions
  204. -----------------------------------------------------------
  205. */
  206. $ctok = $_SESSION['sec_token'];
  207. $stok = Security::get_token();
  208. if (!empty($_SESSION['formelements']) and !empty($_GET['originalresource']) and $_GET['originalresource'] == 'no')
  209. {
  210. $form_elements = $_SESSION['formelements'];
  211. $title_to_modify = $form_elements['emailTitle'];
  212. $content_to_modify = $form_elements['newContent'];
  213. $announcement_to_modify = $form_elements['id'];
  214. $to = $form_elements['to'];
  215. //load_edit_users('announcement',$announcement_to_modify);
  216. $email_ann = $form_elements['emailoption'];
  217. }
  218. if(!empty($_GET['remind_inactive']))
  219. {
  220. $to[] = 'USER:'.intval($_GET['remind_inactive']);
  221. }
  222. /*
  223. -----------------------------------------------------------
  224. Survey
  225. -----------------------------------------------------------
  226. */
  227. $surveyid = 0;
  228. if(!empty($_REQUEST['publish_survey']))
  229. {
  230. $surveyid=Database::escape_string(Security::remove_XSS($_REQUEST['publish_survey']));
  231. }
  232. $cidReq=Database::escape_string($_REQUEST['cidReq']);
  233. if($surveyid)
  234. {
  235. $db_name=Database::escape_string($_REQUEST['db_name']);
  236. $sql_temp = "SELECT * FROM $db_name.survey WHERE survey_id='$surveyid'";
  237. $res_temp = Database::query($sql_temp);
  238. $obj=@Database::fetch_object($res_temp);
  239. $template=$obj->template;
  240. }
  241. if (!empty($_SESSION['toolgroup'])){
  242. $_clean_toolgroup=intval($_SESSION['toolgroup']);
  243. $group_properties = GroupManager :: get_group_properties($_clean_toolgroup);
  244. $interbreadcrumb[] = array ("url" => "../group/group.php", "name" => get_lang('Groups'));
  245. $interbreadcrumb[] = array ("url"=>"../group/group_space.php?gidReq=".$_clean_toolgroup, "name"=> get_lang('GroupSpace').' ('.$group_properties['name'].')');
  246. } else {
  247. if($surveyid) {
  248. $interbreadcrumb[] = array ("url" => "../survey/survey_list.php?cidReq=$cidReq", "name" => get_lang('ToolSurvey'));
  249. $nameTools = get_lang('PublishSurvey');
  250. } else {
  251. $nameTools = get_lang('ToolAnnouncement');
  252. $nameTools12 = get_lang('PublishSurvey');
  253. }
  254. }
  255. /*
  256. -----------------------------------------------------------
  257. Learning path & css
  258. -----------------------------------------------------------
  259. */
  260. // showing the header if we are not in the learning path, if we are in
  261. // the learning path, we do not include the banner so we have to explicitly
  262. // include the stylesheet, which is normally done in the header
  263. if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath')
  264. {
  265. //we are not in the learning path
  266. Display::Display_header($nameTools,"Announcements");
  267. } else {
  268. //we are in the learning path, only display central data and change css
  269. $display_title_list = false;
  270. $display_announcement_list = false;
  271. $display_specific_announcement = true;
  272. $announcement_id = $_REQUEST['ann_id'];
  273. ?> <link rel="stylesheet" type="text/css" href="<?php echo api_get_path(WEB_CODE_PATH).'css/'.$my_style; ?>/default.css">
  274. <!-- css file for announcements -->
  275. <link href="../css/<?php echo $my_style; ?>/announcements.css" rel="stylesheet" type="text/css">
  276. <?php
  277. }
  278. // inserting an anchor (top) so one can jump back to the top of the page
  279. echo "<a name=\"top\"></a>";
  280. /*=============================================
  281. ACTION HANDLING
  282. =============================================*/
  283. if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) {
  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. if (isset($_GET['id']) AND $_GET['id'] AND isset($_GET['action']) AND $_GET['action']=="showhide") {
  294. if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) {
  295. api_not_allowed();
  296. }
  297. $id=intval($_GET['id']);
  298. if (!api_is_course_coach() || api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $id)) {
  299. if ($ctok == $_GET['sec_token']) {
  300. change_visibility_announcement(TOOL_ANNOUNCEMENT,$id);
  301. $message = get_lang("VisibilityChanged");
  302. }
  303. }
  304. }
  305. }
  306. /*
  307. -----------------------------------------------------------
  308. Delete announcement
  309. -----------------------------------------------------------
  310. */
  311. if (!empty($_GET['action']) AND $_GET['action']=='delete' AND isset($_GET['id'])) {
  312. //Database::query("DELETE FROM $tbl_announcement WHERE id='$delete'");
  313. $id=intval(addslashes($_GET['id']));
  314. if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) {
  315. api_not_allowed();
  316. }
  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. Database::query("UPDATE $tbl_item_property SET visibility='2' WHERE tool='".TOOL_ANNOUNCEMENT."' and ref='".$id."'");
  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. //Database::query("DELETE FROM $tbl_announcement");
  336. if (api_is_allowed_to_edit()) {
  337. Database::query("UPDATE $tbl_item_property SET visibility='2' WHERE tool='".TOOL_ANNOUNCEMENT."'");
  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. if (api_get_session_id()!=0 && api_is_allowed_to_session_edit(false,true)==false) {
  352. api_not_allowed();
  353. }
  354. $display_form = true;
  355. // RETRIEVE THE CONTENT OF THE ANNOUNCEMENT TO MODIFY
  356. $id = intval($_GET['id']);
  357. if (!api_is_course_coach() || api_is_element_in_the_session(TOOL_ANNOUNCEMENT, $id)) {
  358. $sql="SELECT * FROM $tbl_announcement WHERE id='$id'";
  359. $rs = Database::query($sql);
  360. $myrow = Database::fetch_array($rs);
  361. $last_id = $id;
  362. $edit_attachment = edit_announcement_attachment_file($last_id, $_FILES['user_upload'], $file_comment);
  363. if ($myrow) {
  364. $announcement_to_modify = $myrow['id'];
  365. $content_to_modify = $myrow['content'];
  366. $title_to_modify = $myrow['title'];
  367. if ($originalresource!=="no") {
  368. //unset_session_resources();
  369. edit_added_resources("Ad_Valvas", $announcement_to_modify);
  370. $to=load_edit_users("announcement", $announcement_to_modify);
  371. }
  372. $display_announcement_list = false;
  373. }
  374. if ($to=="everyone" OR !empty($_SESSION['toolgroup'])) {
  375. $_SESSION['select_groupusers']="hide";
  376. } else {
  377. $_SESSION['select_groupusers']="show";
  378. }
  379. }
  380. }
  381. /*
  382. -----------------------------------------------------------
  383. Move announcement up/down
  384. -----------------------------------------------------------
  385. */
  386. if ($ctok == $_GET['sec_token']) {
  387. if (!empty($_GET['down'])) {
  388. $thisAnnouncementId = intval($_GET['down']);
  389. $sortDirection = "DESC";
  390. }
  391. if (!empty($_GET['up'])) {
  392. $thisAnnouncementId = intval($_GET['up']);
  393. $sortDirection = "ASC";
  394. }
  395. }
  396. if (!empty($sortDirection)) {
  397. if (!in_array(trim(strtoupper($sortDirection)), array('ASC', 'DESC'))) {
  398. $sortDirection='ASC';
  399. }
  400. $my_sql = "SELECT announcement.id, announcement.display_order " .
  401. "FROM $tbl_announcement announcement, " .
  402. "$tbl_item_property itemproperty " .
  403. "WHERE itemproperty.ref=announcement.id " .
  404. "AND itemproperty.tool='".TOOL_ANNOUNCEMENT."' " .
  405. "AND itemproperty.visibility<>2 " .
  406. "ORDER BY display_order $sortDirection";
  407. $result = Database::query($my_sql);
  408. while (list ($announcementId, $announcementOrder) = Database::fetch_row($result)) {
  409. // STEP 2 : FOUND THE NEXT ANNOUNCEMENT ID AND ORDER.
  410. // COMMIT ORDER SWAP ON THE DB
  411. if (isset ($thisAnnouncementOrderFound) && $thisAnnouncementOrderFound == true) {
  412. $nextAnnouncementId = $announcementId;
  413. $nextAnnouncementOrder = $announcementOrder;
  414. Database::query("UPDATE $tbl_announcement " .
  415. "SET display_order = '$nextAnnouncementOrder' " .
  416. "WHERE id = '$thisAnnouncementId'");
  417. Database::query("UPDATE $tbl_announcement " .
  418. "SET display_order = '$thisAnnouncementOrder' " .
  419. "WHERE id = '$nextAnnouncementId.'");
  420. break;
  421. }
  422. // STEP 1 : FIND THE ORDER OF THE ANNOUNCEMENT
  423. if ($announcementId == $thisAnnouncementId) {
  424. $thisAnnouncementOrder = $announcementOrder;
  425. $thisAnnouncementOrderFound = true;
  426. }
  427. }
  428. // show message
  429. $message = get_lang('AnnouncementMoved');
  430. }
  431. /*
  432. -----------------------------------------------------------
  433. Submit announcement
  434. -----------------------------------------------------------
  435. */
  436. //if (api_is_allowed_to_edit(false,true) OR (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) {
  437. $emailTitle=(!empty($_POST['emailTitle'])?$safe_emailTitle:'');
  438. $newContent=(!empty($_POST['newContent'])?$safe_newContent:'');
  439. $submitAnnouncement=isset($_POST['submitAnnouncement'])?$_POST['submitAnnouncement']:0;
  440. $id = 0;
  441. if (!empty($_POST['id'])) {
  442. $id=intval($_POST['id']);
  443. }
  444. if ($submitAnnouncement && empty($emailTitle)) {
  445. $error_message = get_lang('TitleIsRequired');
  446. $content_to_modify = $newContent;
  447. } else if ($submitAnnouncement) {
  448. if (isset($id)&&$id) {
  449. // there is an Id => the announcement already exists => update mode
  450. if ($ctok == $_POST['sec_token']) {
  451. $file_comment = $_POST['file_comment'];
  452. $file = $_FILES['user_upload'];
  453. $edit_id = edit_advalvas_item($id,$emailTitle,$newContent,$_POST['selectedform'],$file,$file_comment);
  454. if (!$delete) {
  455. update_added_resources("Ad_Valvas", $id);
  456. }
  457. $message = get_lang('AnnouncementModified');
  458. }
  459. } else {
  460. //insert mode
  461. if ($ctok == $_POST['sec_token']) {
  462. if (!$surveyid) {
  463. $result = Database::query("SELECT MAX(display_order) FROM $tbl_announcement WHERE session_id=".intval($_SESSION['id_session'])." OR session_id=0");
  464. list($orderMax) = Database::fetch_row($result);
  465. $order = $orderMax + 1;
  466. $file = $_FILES['user_upload'];
  467. $file_comment = $_POST['file_comment'];
  468. if (!empty($_SESSION['toolgroup'])) {
  469. $insert_id=store_advalvas_group_item($safe_emailTitle,$safe_newContent,$order,array('GROUP:'.$_SESSION['toolgroup']),$_POST['selectedform'],$file,$file_comment);
  470. } else {
  471. $insert_id=store_advalvas_item($safe_emailTitle,$safe_newContent,$order,$_POST['selectedform'],$file,$file_comment);
  472. }
  473. store_resources($_SESSION['source_type'],$insert_id);
  474. $_SESSION['select_groupusers']="hide";
  475. $message = get_lang('AnnouncementAdded');
  476. }
  477. /*============================================================
  478. MAIL WHEN USER COMES FROM SURVEY
  479. ======================================================= */
  480. if ($_POST['emailsAdd']) {
  481. $to_email_address =$_POST['emailsAdd'];
  482. $to_email_to = explode(',', $to_email_address);
  483. $to_email = array_unique($to_email_to);
  484. $db_name = $_REQUEST['db_name'];
  485. for ($i=0;$i<count($to_email);$i++) {
  486. $to= trim($to_email[$i]);
  487. $db_name = $_REQUEST['db_name'];
  488. $newContentone=str_replace("#page#","choose_language.php",$newContent);
  489. $newContenttwo=str_replace("#temp#",$template,$newContentone);
  490. $newContentthree=str_replace("#sid#",$surveyid,$newContenttwo);
  491. $newContentfour=str_replace("#mail#",$to,$newContentthree);
  492. $newContentfive=str_replace("#db_name#",$db_name,$newContentfour);
  493. $newContentsix=str_replace("#uid#","",$newContentfive);
  494. 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 )) {
  495. $subject=stripslashes($emailTitle);
  496. $message=stripslashes($newContentsix);
  497. $sender_name = api_get_person_name($_SESSION['_user']['lastName'], $_SESSION['_user']['firstName'], null, PERSON_NAME_EMAIL_ADDRESS);
  498. $email = $_SESSION['_user']['mail'];
  499. $headers="From:$sender_name\r\nReply-to: $email";
  500. //@mail($to,$subject,$message,$headers);
  501. //api_send_mail($to,$subject,$message,$headers);
  502. @api_mail('',$to,$subject,$message,$sender_name,$email,$headers);
  503. $sql_date="SELECT * FROM $db_name.survey WHERE survey_id='$surveyid'";
  504. $res_date=Database::query($sql_date);
  505. $obj_date=Database::fetch_object($res_date);
  506. $end_date=$obj_date->avail_till;
  507. $table_reminder = Database :: get_main_table(TABLE_MAIN_SURVEY_REMINDER); // TODO: To be checked. TABLE_MAIN_SURVEY_REMINDER has not been defined.
  508. if ($_REQUEST['reminder']=="1") {
  509. $time=getdate();
  510. $time = $time['yday'];
  511. $time = $time+7;
  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. Database::query($sql_insert);
  514. } else if ($_REQUEST['reminder']=="2") {
  515. $time=getdate();
  516. $time = $time['yday'];
  517. $time = $time+14;
  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. Database::query($sql_insert);
  520. } else if($_REQUEST['reminder']=="3") {
  521. $time=getdate();
  522. $time = $time['yday'];
  523. $time = $time+30;
  524. $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')";
  525. Database::query($sql_insert);
  526. }
  527. }
  528. }
  529. }
  530. /*===================================================================
  531. MAIL FUNCTION
  532. ===================================================================*/
  533. if ($_POST['email_ann'] && empty($_POST['onlyThoseMails'])) {
  534. $sent_to=sent_to("announcement", $insert_id);
  535. $userlist = $sent_to['users'];
  536. $grouplist = $sent_to['groups'];
  537. // groepen omzetten in users
  538. if ($grouplist) {
  539. $grouplist = "'".implode("', '",$grouplist)."'"; //protect individual elements with surrounding quotes
  540. $sql = "SELECT user_id
  541. FROM $tbl_groupUser gu
  542. WHERE gu.group_id IN (".$grouplist.")";
  543. $groupMemberResult = Database::query($sql);
  544. if ($groupMemberResult) {
  545. while ($u = Database::fetch_array($groupMemberResult)) {
  546. $userlist [] = $u ['user_id']; // complete the user id list ...
  547. }
  548. }
  549. }
  550. if (is_array($userlist)) {
  551. $userlist = "'".implode("', '", array_unique($userlist) )."'";
  552. // send to the created 'userlist'
  553. $sqlmail = "SELECT user_id, lastname, firstname, email
  554. FROM $tbl_user
  555. WHERE user_id IN (".$userlist.")";
  556. } else if (empty($_POST['not_selected_form'])) {
  557. if(empty($_SESSION['id_session']) || api_get_setting('use_session_mode')=='false') {
  558. // send to everybody
  559. $sqlmail = "SELECT user.user_id, user.email, user.lastname, user.firstname
  560. FROM $tbl_course_user, $tbl_user
  561. WHERE course_code='".Database::escape_string($_course['sysCode'])."'
  562. AND course_rel_user.user_id = user.user_id AND relation_type <>".COURSE_RELATION_TYPE_RRHH." ";
  563. } else {
  564. $sqlmail = "SELECT user.user_id, user.email, user.lastname, user.firstname
  565. FROM $tbl_user
  566. INNER JOIN $tbl_session_course_user
  567. ON $tbl_user.user_id = $tbl_session_course_user.id_user
  568. AND $tbl_session_course_user.course_code = '".$_course['id']."'
  569. AND $tbl_session_course_user.id_session = ".intval($_SESSION['id_session']);
  570. }
  571. }
  572. if ($sqlmail != '') {
  573. $rs_mail = Database::query($sqlmail);
  574. /*=================================================================================
  575. send email one by one to avoid antispam
  576. =================================================================================*/
  577. $db_name = Database::get_course_table(TABLE_MAIN_SURVEY);
  578. while ($myrow = Database::fetch_array($rs_mail)) {
  579. /* Header : Bericht van uw lesgever - GES ($_cid)
  580. Body : John Doe (prenom + nom) <john_doe@hotmail.com> (email)
  581. Morgen geen les!! (emailTitle)
  582. Morgen is er geen les, de les wordt geschrapt wegens vergadering (newContent)
  583. */
  584. $emailSubject = "[" . $_course['official_code'] . "] " . $emailTitle;
  585. if ($surveyid) {
  586. $newContentone=str_replace("#page#","choose_language.php",$newContent);
  587. $newContenttwo=str_replace("#temp#",$template,$newContentone);
  588. $newContentthree=str_replace("#sid#",$surveyid,$newContenttwo);
  589. $newContentfour=str_replace("#mail#",$myrow["email"],$newContentthree);
  590. $newContentfive=str_replace("#db_name#",$db_name,$newContentfour);
  591. $newContentsix=str_replace("#uid#",$myrow["user_id"],$newContentfive);
  592. $message=stripslashes($newContentsix);
  593. $sender_name = api_get_person_name($_SESSION['_user']['lastName'], $_SESSION['_user']['firstName'], null, PERSON_NAME_EMAIL_ADDRESS);
  594. $email = $_SESSION['_user']['mail'];
  595. $headers="From:$sender_name\r\nReply-to: $email";
  596. //@mail($myrow["email"],stripslashes($emailTitle),$message,$headers);
  597. @api_mail('',$myrow["email"],stripslashes($emailTitle),$message,$sender_name,$email);
  598. } else {
  599. // intro of the email: receiver name and subject
  600. $mail_body = api_get_person_name($myrow["lastname"], $myrow["firstname"], null, PERSON_NAME_EMAIL_ADDRESS)."<br />\n".stripslashes($emailTitle)."<br />";
  601. // make a change for absolute url
  602. $newContent = str_replace('src=\"../../','src=\"'.api_get_path(WEB_PATH).'', $newContent);
  603. // main part of the email
  604. $mail_body .= trim(stripslashes($newContent));
  605. // signature of email: sender name and course URL after -- line
  606. $mail_body .= "<br />-- <br />";
  607. $mail_body .= api_get_person_name($_user['firstName'], $_user['lastName'], null, PERSON_NAME_EMAIL_ADDRESS)." \n";
  608. $mail_body .= "<br /> \n<a href=\"".api_get_path(WEB_COURSE_PATH).$_course['id']."\">";
  609. $mail_body .= $_course['official_code'].' '.$_course['name'] . "</a>";
  610. $recipient_name = api_get_person_name($myrow["firstname"], $myrow["lastname"], null, PERSON_NAME_EMAIL_ADDRESS);
  611. $mailid = $myrow["email"];
  612. $sender_name = api_get_person_name($_SESSION['_user']['firstName'], $_SESSION['_user']['lastName'], null, PERSON_NAME_EMAIL_ADDRESS);
  613. $sender_email = $_SESSION['_user']['mail'];
  614. // send attachment file
  615. $data_file = array();
  616. $sql = 'SELECT path, filename FROM '.$tbl_announcement_attachment.' WHERE announcement_id = "'.$insert_id.'"';
  617. $rs_attach = Database::query($sql);
  618. if (Database::num_rows($rs_attach) > 0) {
  619. $row_attach = Database::fetch_array($rs_attach);
  620. $path_attach = api_get_path(SYS_COURSE_PATH).$_course['path'].'/upload/announcements/'.$row_attach['path'];
  621. $filename_attach = $row_attach['filename'];
  622. $data_file = array('path' => $path_attach,'filename' => $filename_attach);
  623. }
  624. @api_mail_html($recipient_name, $mailid, stripslashes($emailSubject), $mail_body, $sender_name, $sender_email, null, $data_file);
  625. }
  626. $sql_date="SELECT * FROM $db_name WHERE survey_id='$surveyid'";
  627. $res_date=Database::query($sql_date);
  628. $obj_date=Database::fetch_object($res_date);
  629. $end_date=$obj_date->avail_till;
  630. $table_reminder = Database :: get_main_table(TABLE_MAIN_SURVEY_REMINDER); // TODO: To be checked. TABLE_MAIN_SURVEY_REMINDER has not been defined.
  631. if ($_REQUEST['reminder']=="1") {
  632. $time=getdate();
  633. $time = $time['yday'];
  634. $time = $time+7;
  635. $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')";
  636. Database::query($sql);
  637. } else if ($_REQUEST['reminder']=="2") {
  638. $time=getdate();
  639. $time = $time['yday'];
  640. $time = $time+14;
  641. $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')";
  642. Database::query($sql);
  643. } else if ($_REQUEST['reminder']=="3") {
  644. $time=getdate();
  645. $time = $time['yday'];
  646. $time = $time+30;
  647. $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')";
  648. Database::query($sql);
  649. }
  650. }
  651. update_mail_sent($insert_id);
  652. $message = $added_and_sent;
  653. }
  654. } // $email_ann*/
  655. } // end condition token
  656. } // isset
  657. // UNSET VARIABLES
  658. unset_session_resources();
  659. unset($form_elements);
  660. $_SESSION['formelements']=null;
  661. $newContent = null;
  662. $emailTitle = null;
  663. unset($emailTitle);
  664. unset($newContent);
  665. unset($content_to_modify);
  666. unset($title_to_modify);
  667. if($_REQUEST['publish_survey']) {
  668. $surveyid=$_REQUEST['surveyid'];
  669. $cidReq = $_REQUEST['cidReq'];
  670. ?>
  671. <script>
  672. window.location.href="../survey/survey_list.php?<?php echo api_get_cidreq(); ?>&published=published&surveyid=<?php echo Security::remove_XSS($_REQUEST['publish_survey']); ?>";
  673. </script>
  674. <?php
  675. }
  676. } // if $submit Announcement
  677. }
  678. /*====================================================
  679. Tool introduction
  680. ====================================================*/
  681. if (empty($_GET['origin']) || $_GET['origin'] !== 'learnpath') {
  682. //api_display_tool_title($nameTools);
  683. Display::display_introduction_section(TOOL_ANNOUNCEMENT);
  684. }
  685. /*
  686. ==============================================================================
  687. MAIN SECTION
  688. ==============================================================================
  689. */
  690. /* DISPLAY LEFT COLUMN */
  691. //condition for the session
  692. $session_id = api_get_session_id();
  693. $condition_session = api_get_session_condition($session_id);
  694. if(api_is_allowed_to_edit(false,true)) {
  695. // check teacher status
  696. if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath') {
  697. $sql="SELECT
  698. announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
  699. FROM $tbl_announcement announcement, $tbl_item_property ip
  700. WHERE announcement.id = ip.ref
  701. AND ip.tool='announcement'
  702. AND ip.visibility<>'2'
  703. $condition_session
  704. GROUP BY ip.ref
  705. ORDER BY display_order DESC
  706. LIMIT 0,$maximum";
  707. }
  708. } else {
  709. // students only get to see the visible announcements
  710. if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath') {
  711. $group_memberships=GroupManager::get_group_ids($_course['dbName'], $_user['user_id']);
  712. if ((api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) {
  713. $cond_user_id = " AND (ip.lastedit_user_id = '".api_get_user_id()."' OR ( ip.to_user_id='".$_user['user_id']."'" .
  714. "OR ip.to_group_id IN (0, ".implode(", ", $group_memberships)."))) ";
  715. } else {
  716. $cond_user_id = " AND ( ip.to_user_id='".$_user['user_id']."'" .
  717. "OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).")) ";
  718. }
  719. // the user is member of several groups => display personal announcements AND his group announcements AND the general announcements
  720. if (is_array($group_memberships) && count($group_memberships)>0) {
  721. $sql="SELECT
  722. announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
  723. FROM $tbl_announcement announcement, $tbl_item_property ip
  724. WHERE announcement.id = ip.ref
  725. AND ip.tool='announcement'
  726. AND ip.visibility='1'
  727. $cond_user_id
  728. $condition_session
  729. GROUP BY ip.ref
  730. ORDER BY display_order DESC
  731. LIMIT 0,$maximum";
  732. } else {
  733. // the user is not member of any group
  734. // this is an identified user => show the general announcements AND his personal announcements
  735. if ($_user['user_id']) {
  736. if ((api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) {
  737. $cond_user_id = " AND (ip.lastedit_user_id = '".api_get_user_id()."' OR ( ip.to_user_id='".$_user['user_id']."' OR ip.to_group_id='0')) ";
  738. } else {
  739. $cond_user_id = " AND ( ip.to_user_id='".$_user['user_id']."' OR ip.to_group_id='0') ";
  740. }
  741. $sql="SELECT
  742. announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
  743. FROM $tbl_announcement announcement, $tbl_item_property ip
  744. WHERE announcement.id = ip.ref
  745. AND ip.tool='announcement'
  746. AND ip.visibility='1'
  747. $cond_user_id
  748. $condition_session
  749. GROUP BY ip.ref
  750. ORDER BY display_order DESC
  751. LIMIT 0,$maximum";
  752. } else {
  753. if (api_get_course_setting('allow_user_edit_announcement')) {
  754. $cond_user_id = " AND (ip.lastedit_user_id = '".api_get_user_id()."' OR ip.to_group_id='0') ";
  755. } else {
  756. $cond_user_id = " AND ip.to_group_id='0' ";
  757. }
  758. // the user is not identiefied => show only the general announcements
  759. $sql="SELECT
  760. announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
  761. FROM $tbl_announcement announcement, $tbl_item_property ip
  762. WHERE announcement.id = ip.ref
  763. AND ip.tool='announcement'
  764. AND ip.visibility='1'
  765. AND ip.to_group_id='0'
  766. $condition_session
  767. GROUP BY ip.ref
  768. ORDER BY display_order DESC
  769. LIMIT 0,$maximum";
  770. }
  771. }
  772. }
  773. }
  774. $result = Database::query($sql);
  775. $announcement_number = Database::num_rows($result);
  776. /*----------------------------------------------------
  777. ADD ANNOUNCEMENT / DELETE ALL
  778. ----------------------------------------------------*/
  779. if (!$surveyid) {
  780. $show_actions = false;
  781. 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')) {
  782. echo '<div class="actions">';
  783. 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>";
  784. $show_actions = true;
  785. }
  786. if (api_is_allowed_to_edit() && $announcement_number > 1) {
  787. if (!$show_actions)
  788. echo '<div class="actions">';
  789. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&action=delete_all\" onclick=\"javascript:if(!confirm('".get_lang("ConfirmYourChoice")."')) return false;\">".Display::return_icon('valvesdelete.gif',get_lang('AnnouncementDeleteAll')).get_lang('AnnouncementDeleteAll')."</a>\n"; } // if announcementNumber > 1
  790. if ($show_actions)
  791. echo '</div>';
  792. }
  793. if (empty($_GET['origin']) OR $_GET['origin'] !== 'learnpath') {
  794. echo "\n\n<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
  795. echo "\t<tr>\n";
  796. echo "\t\t<td width=\"20%\" valign=\"top\">\n";
  797. }
  798. /*----------------------------------------------------
  799. ANNOUNCEMENTS LIST
  800. ----------------------------------------------------*/
  801. if (!$surveyid) {
  802. if ($display_title_list == true) {
  803. echo "\t\t\t<table>\n";
  804. while ($myrow = Database::fetch_array($result)) {
  805. $title = $myrow['title'];
  806. $title = Security::remove_XSS($title);
  807. echo "\t\t\t\t<tr>\n";
  808. echo "\t\t\t\t\t<td width=\"15%\">\n";
  809. if ($myrow['visibility']==0) {
  810. $class="class=\"invisible\"";
  811. } else {
  812. $class="";
  813. }
  814. //validation when belongs to a session
  815. $session_img = api_get_session_image($myrow['session_id'], $_user['status']);
  816. echo "\t\t\t\t\t\t".Display::return_icon('lp_announcement.png', api_convert_and_format_date($myrow['end_date'], DATE_FORMAT_LONG), array('align' => 'absmiddle', 'Width' => '10', 'Height' => '10'))." <a style=\"text-decoration:none\" href=\"announcements.php?".api_get_cidreq()."#".$myrow['id']."\" ".$class.">" . api_trunc_str($title, $length) . "</a>\n" . $session_img;
  817. echo "\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
  818. }
  819. echo "\t\t\t</table>\n";
  820. } // end $display_title_list == true
  821. }
  822. if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath') {
  823. echo "\t\t</td>\n";
  824. echo "\t\t<td width=\"20\" background=\"../img/verticalruler.gif\">&nbsp;</td>\n";
  825. // START RIGHT PART
  826. echo "\t\t<td valign=\"top\">\n";
  827. }
  828. /*=======================================
  829. DISPLAY ACTION MESSAGE
  830. =======================================*/
  831. if (isset($message) && $message == true) {
  832. Display::display_confirmation_message($message);
  833. $display_announcement_list = true;
  834. $display_form = false;
  835. }
  836. if (!empty($error_message)) {
  837. Display::display_error_message($error_message);
  838. $display_announcement_list = false;
  839. $display_form = true;
  840. }
  841. /*==================================================================================
  842. DISPLAY FORM
  843. ==================================================================================*/
  844. if ($display_form == true) {
  845. $content_to_modify = stripslashes($content_to_modify);
  846. $title_to_modify = stripslashes($title_to_modify);
  847. // DISPLAY ADD ANNOUNCEMENT COMMAND
  848. echo '<form method="post" name="f1" enctype = "multipart/form-data" 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";
  849. if (empty($_GET['id'])) {
  850. $form_name = get_lang('AddAnnouncement');
  851. } else {
  852. $form_name = get_lang('ModifyAnnouncement');
  853. }
  854. echo '<div class="row"><div class="form_header">'.$form_name.'</div></div>';
  855. //this variable defines if the course administrator can send a message to a specific user / group or not
  856. if (empty($_SESSION['toolgroup'])) {
  857. echo ' <div class="row">
  858. <div class="label">'.
  859. 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>
  860. </div>
  861. <div class="formw">';
  862. if (isset($_GET['id']) && is_array($to)) {
  863. echo '&nbsp;';
  864. } elseif (isset($_GET['remind_inactive'])) {
  865. $email_ann = '1';
  866. $_SESSION['select_groupusers']="show";
  867. $content_to_modify = sprintf(get_lang('RemindInactiveLearnersMailContent'),api_get_setting('siteName'), 7);
  868. $title_to_modify = sprintf(get_lang('RemindInactiveLearnersMailSubject'),api_get_setting('siteName'));
  869. } elseif (isset($_GET['remindallinactives']) && $_GET['remindallinactives']=='true') {
  870. // we want to remind inactive users. The $_GET['since'] parameter determines which users have to be warned (i.e the users who have been inactive for x days or more
  871. $since = isset($_GET['since']) ? intval($_GET['since']) : 6;
  872. // getting the users who have to be reminded
  873. $to = Tracking :: get_inactives_students_in_course($_course['id'],$since, $_SESSION['id_session']);
  874. // setting the variables for the form elements: the users who need to receive the message
  875. foreach($to as &$user) {
  876. $user = 'USER:'.$user;
  877. }
  878. // setting the variables for the form elements: the 'visible to' form element has to be expanded
  879. $_SESSION['select_groupusers']="show";
  880. // setting the variables for the form elements: the message has to be sent by email
  881. $email_ann = '1';
  882. // setting the variables for the form elements: the title of the email
  883. $title_to_modify = sprintf(get_lang('RemindInactiveLearnersMailSubject'),api_get_setting('siteName'),' > ',$_course['name']);
  884. // setting the variables for the form elements: the message of the email
  885. $content_to_modify = sprintf(get_lang('RemindInactiveLearnersMailContent'),api_get_setting('siteName'),' > ',$_course['name'],$since);
  886. // when we want to remind the users who have never been active then we have a different subject and content for the announcement
  887. if ($_GET['since'] == 'never') {
  888. $title_to_modify = get_lang('NoActivityYetTitle');
  889. $content_to_modify = get_lang('NoActivityYetContent');
  890. }
  891. } else {
  892. echo get_lang("Everybody");
  893. }
  894. show_to_form($to);
  895. echo ' </div>
  896. </div>';
  897. if (!isset($announcement_to_modify) ) $announcement_to_modify ='';
  898. if ($announcement_to_modify=='') {
  899. ($email_ann=='1')?$checked='checked':$checked='';
  900. echo ' <div class="row">
  901. <div class="label">
  902. <input class="checkbox" type="checkbox" value="1" name="email_ann" checked>
  903. </div>
  904. <div class="formw">'.get_lang('EmailOption').'
  905. </div>
  906. </div>';
  907. }
  908. } else {
  909. if (!isset($announcement_to_modify) ) {
  910. $announcement_to_modify ="";
  911. }
  912. if ($announcement_to_modify=='') {
  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').'&nbsp;&nbsp;<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></div>';
  922. }
  923. }
  924. if ($surveyid) {
  925. echo ' <div class="row">
  926. <div class="label">
  927. '.get_lang('EmailAddress').'
  928. </div>
  929. <div class="formw">
  930. <input type="text" name="emailsAdd" value="'.Security::remove_XSS($emails_add).'" size="52">(Comma separated for multiple)
  931. </div>
  932. </div>';
  933. echo ' <div class="row">
  934. <div class="label">
  935. '.get_lang('OnlyThoseAddresses').'
  936. </div>
  937. <div class="formw">
  938. <input type="checkbox" name="onlyThoseMails">
  939. </div>
  940. </div>';
  941. }
  942. // the announcement title
  943. echo ' <div class="row">
  944. <div id="msg_error" style="display:none;color:red;margin-left:20%"></div>
  945. <div class="label">
  946. <span class="form_required">*</span> '.get_lang('EmailTitle').'
  947. </div>
  948. <div class="formw">
  949. <input type="text" id="emailTitle" name="emailTitle" value="'.Security::remove_XSS($title_to_modify).'" size="60">
  950. </div>
  951. </div>';
  952. unset($title_to_modify);
  953. $title_to_modify = null;
  954. if (!isset($announcement_to_modify) ) $announcement_to_modify ="";
  955. if (!isset($content_to_modify) ) $content_to_modify ="";
  956. if (!isset($title_to_modify)) $title_to_modify = "";
  957. echo '<input type="hidden" name="id" value="'.$announcement_to_modify.'" />';
  958. if ($surveyid) {
  959. $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 />
  960. '.get_lang('OrCopyPasteUrl').' <br />
  961. '.api_get_path(WEB_CODE_PATH).'/survey/#page#?temp=#temp#&surveyid=#sid#&uid=#uid#&mail=#mail#&db_name=#db_name&nbsp;';
  962. }
  963. $oFCKeditor = new FCKeditor('newContent') ;
  964. $oFCKeditor->Width = '100%';
  965. $oFCKeditor->Height = '300';
  966. if(!api_is_allowed_to_edit()) {
  967. $oFCKeditor->ToolbarSet = "AnnouncementsStudent";
  968. } else {
  969. $oFCKeditor->ToolbarSet = "Announcements";
  970. }
  971. $oFCKeditor->Value = $content_to_modify;
  972. echo $oFCKeditor->CreateHtml();
  973. //File attachment
  974. echo ' <div style="float:left; padding:5px 5px;" >
  975. <div class="label">
  976. <a href="javascript://" onclick="return plus_attachment();"><span id="plus"><img style="vertical-align:middle;" src="../img/div_show.gif" alt="" />&nbsp;'.get_lang('AddAnAttachment').'</span></a>
  977. </div>
  978. <div class="formw">
  979. <table id="options" style="display: none;">
  980. <tr>
  981. <td colspan="2">
  982. <label for="file_name">'.get_lang('FileName').'&nbsp;</label>
  983. <input type="file" name="user_upload"/>
  984. </td>
  985. </tr>
  986. <tr>
  987. <td colspan="2">
  988. <label for="comment">'.get_lang('FileComment').'</label><br />
  989. <textarea name="file_comment" rows ="4" cols = "34" ></textarea>
  990. </td>
  991. </tr>
  992. </table>
  993. </div>
  994. </div>';
  995. echo'<br />';
  996. if (empty($_SESSION['toolgroup'])) {
  997. echo '<input type="hidden" name="submitAnnouncement" value="OK">';
  998. echo '<input type="hidden" name="sec_token" value="'.$stok.'" />';
  999. echo '<button class="save" type="button" value="'.' '.get_lang('Send').' '.'" onclick="selectAll(this.form.elements[3],true)" >'.get_lang('ButtonPublishAnnouncement').'</button><br /><br />';
  1000. } else {
  1001. echo '<input type="hidden" name="submitAnnouncement" value="OK">';
  1002. echo '<input type="hidden" name="sec_token" value="'.$stok.'" />';
  1003. echo '<button class="save" type="button" value="'.' '.get_lang('Send').' '.'" onclick="selectAll(this.form.elements[4],true)" >'.get_lang('ButtonPublishAnnouncement').'</button><br /><br />';
  1004. }
  1005. echo '</form><br />';
  1006. if ((isset($_GET['action']) && isset($_GET['id']) && is_array($to))||isset($_GET['remindallinactives'])||isset($_GET['remind_inactive'])) {
  1007. echo '<script>document.getElementById(\'recipient_list\').style.display=\'block\';</script>';
  1008. }
  1009. } // displayform
  1010. /*===============================================
  1011. DISPLAY ANNOUNCEMENT LIST
  1012. ===============================================*/
  1013. if ($display_announcement_list && !$surveyid) {
  1014. // 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
  1015. $user_id=$_user['user_id'];
  1016. if (isset($_SESSION['user'])) {
  1017. $user_id=$_SESSION['user'];
  1018. }
  1019. if (isset($_SESSION['group'])) {
  1020. $group_id=$_SESSION['group'];
  1021. }
  1022. //$group_memberships=GroupManager::get_group_ids($_course['dbName'], $_user['user_id']);
  1023. $group_memberships=GroupManager::get_group_ids($_course['dbName'],$_user['user_id']);
  1024. if (api_is_allowed_to_edit(false,true)) {
  1025. // A.1. you are a course admin with a USER filter
  1026. // => see only the messages of this specific user + the messages of the group (s)he is member of.
  1027. if (isset($_SESSION['user'])) {
  1028. if (is_array($group_memberships) && count($group_memberships)>0) {
  1029. $sql="SELECT
  1030. announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
  1031. FROM $tbl_announcement announcement, $tbl_item_property ip
  1032. WHERE announcement.id = ip.ref
  1033. AND ip.tool='announcement'
  1034. AND (ip.to_user_id=$user_id OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") )
  1035. $condition_session
  1036. ORDER BY display_order DESC";
  1037. } else {
  1038. $sql="SELECT
  1039. announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
  1040. FROM $tbl_announcement announcement, $tbl_item_property ip
  1041. WHERE announcement.id = ip.ref
  1042. AND ip.tool='announcement'
  1043. AND (ip.to_user_id=$user_id OR ip.to_group_id='0')
  1044. AND ip.visibility='1'
  1045. $condition_session
  1046. ORDER BY display_order DESC";
  1047. }
  1048. } elseif (isset($_SESSION['group'])) {
  1049. // A.2. you are a course admin with a GROUP filter
  1050. // => see only the messages of this specific group
  1051. $sql="SELECT
  1052. announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
  1053. FROM $tbl_announcement announcement, $tbl_item_property ip
  1054. WHERE announcement.id = ip.ref
  1055. AND ip.tool='announcement'
  1056. AND (ip.to_group_id=$group_id OR ip.to_group_id='0')
  1057. $condition_session
  1058. GROUP BY ip.ref
  1059. ORDER BY display_order DESC";
  1060. } else {
  1061. // A.3 you are a course admin without any group or user filter
  1062. // A.3.a you are a course admin without user or group filter but WITH studentview
  1063. // => see all the messages of all the users and groups without editing possibilities
  1064. if (isset($isStudentView) and $isStudentView=="true") {
  1065. $sql="SELECT
  1066. announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
  1067. FROM $tbl_announcement announcement, $tbl_item_property ip
  1068. WHERE announcement.id = ip.ref
  1069. AND ip.tool='announcement'
  1070. AND ip.visibility='1'
  1071. $condition_session
  1072. GROUP BY ip.ref
  1073. ORDER BY display_order DESC";
  1074. } else {
  1075. // A.3.a you are a course admin without user or group filter and WTIHOUT studentview (= the normal course admin view)
  1076. // => see all the messages of all the users and groups with editing possibilities
  1077. $sql="SELECT
  1078. announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
  1079. FROM $tbl_announcement announcement, $tbl_item_property ip
  1080. WHERE announcement.id = ip.ref
  1081. AND ip.tool='announcement'
  1082. AND (ip.visibility='0' or ip.visibility='1')
  1083. $condition_session
  1084. GROUP BY ip.ref
  1085. ORDER BY display_order DESC";
  1086. }
  1087. }
  1088. } else {
  1089. //STUDENT
  1090. if (is_array($group_memberships) && count($group_memberships)>0) {
  1091. if ((api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) {
  1092. $cond_user_id = " AND (ip.lastedit_user_id = '".api_get_user_id()."' OR (ip.to_user_id=$user_id OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).") )) ";
  1093. } else {
  1094. $cond_user_id = " AND (ip.to_user_id=$user_id OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).")) ";
  1095. }
  1096. $sql="SELECT
  1097. announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
  1098. FROM $tbl_announcement announcement, $tbl_item_property ip
  1099. WHERE announcement.id = ip.ref
  1100. AND ip.tool='announcement'
  1101. $cond_user_id
  1102. $condition_session
  1103. AND ip.visibility='1'
  1104. ORDER BY display_order DESC";
  1105. } else {
  1106. if ($_user['user_id']) {
  1107. if ((api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) {
  1108. $cond_user_id = " AND (ip.lastedit_user_id = '".api_get_user_id()."' OR (ip.to_user_id='".$_user['user_id']."' OR ip.to_group_id='0')) ";
  1109. } else {
  1110. $cond_user_id = " AND (ip.to_user_id='".$_user['user_id']."' OR ip.to_group_id='0') ";
  1111. }
  1112. $sql="SELECT
  1113. announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
  1114. FROM $tbl_announcement announcement, $tbl_item_property ip
  1115. WHERE announcement.id = ip.ref
  1116. AND ip.tool='announcement'
  1117. $cond_user_id
  1118. $condition_session
  1119. AND ip.visibility='1'
  1120. AND announcement.session_id IN(0,".intval($_SESSION['id_session']).")
  1121. ORDER BY display_order DESC";
  1122. } else {
  1123. if ((api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) {
  1124. $cond_user_id = " AND (ip.lastedit_user_id = '".api_get_user_id()."' OR ip.to_group_id='0' ) ";
  1125. } else {
  1126. $cond_user_id = " AND ip.to_group_id='0' ";
  1127. }
  1128. $sql="SELECT
  1129. announcement.*, ip.visibility, ip.to_group_id, ip.insert_user_id
  1130. FROM $tbl_announcement announcement, $tbl_item_property ip
  1131. WHERE announcement.id = ip.ref
  1132. AND ip.tool='announcement'
  1133. $cond_user_id
  1134. $condition_session
  1135. AND ip.visibility='1'
  1136. AND announcement.session_id IN(0,".intval($_SESSION['id_session']).")";
  1137. }
  1138. }
  1139. }
  1140. $result = Database::query($sql);
  1141. $num_rows = Database::num_rows($result);
  1142. /*=================================================
  1143. DISPLAY: NO ITEMS
  1144. =================================================*/
  1145. if ($num_rows == 0) {
  1146. echo get_lang('NoAnnouncements');;
  1147. }
  1148. $iterator = 1;
  1149. $bottomAnnouncement = $announcement_number;
  1150. echo "\t\t\t<table width=\"100%\" class=\"data_table\">\n";
  1151. $displayed=array();
  1152. while ($myrow = Database::fetch_array($result)) {
  1153. if (!in_array($myrow['id'], $displayed)) {
  1154. $title = $myrow['title'];
  1155. $content = $myrow['content'];
  1156. $content = make_clickable($content);
  1157. $content = text_filter($content);
  1158. /* DATE */
  1159. $last_post_datetime = $myrow['end_date'];
  1160. list($last_post_date, $last_post_time) = split(" ", $last_post_datetime);
  1161. list($year, $month, $day) = explode("-", $last_post_date);
  1162. list($hour, $min) = explode(":", $last_post_time);
  1163. $announceDate = mktime((int)$hour, (int)$min, 0, (int)$month, (int)$day, (int)$year);
  1164. // the styles
  1165. if ($myrow['visibility']=='0') {
  1166. $style='invisible';
  1167. } else {
  1168. $style = '';
  1169. }
  1170. echo "\t\t\t\t<tr class=\"".$style."\">";
  1171. /* THE ICONS */
  1172. echo "\t\t\t\t\t<th>\n";
  1173. // anchoring
  1174. echo "<a name=\"".(int)($myrow["id"])."\"></a>\n";
  1175. // User or group icon
  1176. if ($myrow['to_group_id']!== '0' and $myrow['to_group_id']!== 'NULL') {
  1177. echo "\t\t\t\t\t\t".Display::return_icon('group.gif', get_lang('AnnounceSentToUserSelection'))."\n";
  1178. }
  1179. // the email icon
  1180. if ($myrow['email_sent'] == '1') {
  1181. echo "\t\t\t\t\t\t".Display::return_icon('email.gif', get_lang('AnnounceSentByEmail'))."\n";
  1182. }
  1183. echo "\t\t\t\t\t</th>\n";
  1184. /* TITLE */
  1185. echo "\t\t\t\t\t<th>".Security::remove_XSS($title)."</th>\n";
  1186. echo "\t\t\t\t\t<th>" . get_lang("SentTo") . " : &nbsp; ";
  1187. $sent_to=sent_to("announcement", $myrow['id']);
  1188. $sent_to_form=sent_to_form($sent_to);
  1189. $user_info=api_get_user_info($myrow['insert_user_id']);
  1190. echo '&nbsp;&nbsp;&nbsp;'.get_lang('By').' : &nbsp;'.str_replace(' ', '&nbsp;', api_get_person_name($user_info['firstName'], $user_info['lastName']));
  1191. echo "\t\t\t\t\t</th>\n","\t\t\t\t</tr>\n";
  1192. echo "\t\t\t\t<tr class='row_odd'>\n\t\t\t\t\t<td class=\"announcements_datum\" colspan=\"3\">";
  1193. echo get_lang('AnnouncementPublishedOn')," : ", api_convert_and_format_date($last_post_datetime, DATE_FORMAT_LONG, date_default_timezone_get());
  1194. echo "</td>\n\t\t\t\t</tr>\n";
  1195. /* CONTENT */
  1196. echo "\t\t\t\t<tr class=\"$text_style\">\n\t\t\t\t\t<td colspan=\"3\">\n";
  1197. echo $content."\t\t\t\t\t</td>\n\t\t\t\t</tr>\n";
  1198. /* RESOURCES */
  1199. echo "<tr class='row_odd'>\n<td colspan=\"3\">\n";
  1200. if (check_added_resources("Ad_Valvas", $myrow["id"])) {
  1201. echo "<i>".get_lang('AddedResources')."</i><br />";
  1202. display_added_resources("Ad_Valvas", $myrow["id"]);
  1203. }
  1204. // 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
  1205. 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())) {
  1206. /* SHOW MOD/DEL/VIS FUNCTIONS */
  1207. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&action=modify&id=".$myrow['id']."\">",
  1208. Display::return_icon('edit.gif', get_lang('Edit')),
  1209. "</a>";
  1210. if (api_is_allowed_to_edit(false,true)) {
  1211. 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;\">",
  1212. Display::return_icon('delete.gif', get_lang('Delete')),
  1213. "</a>";
  1214. }
  1215. if ($myrow['visibility']==1) {
  1216. $image_visibility="visible";
  1217. $alt_visibility=get_lang('Hide');
  1218. } else {
  1219. $image_visibility="invisible";
  1220. $alt_visibility=get_lang('Visible');
  1221. }
  1222. 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."\">".
  1223. Display::return_icon($image_visibility.'.gif', $alt_visibility)."</a>";
  1224. // DISPLAY MOVE UP COMMAND only if it is not the top announcement
  1225. if ($iterator != 1) {
  1226. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&up=".$myrow["id"]."&sec_token=".$stok."\">",
  1227. Display::return_icon('up.gif', get_lang('Up'))."</a>";
  1228. }
  1229. if ($iterator < $bottomAnnouncement) {
  1230. echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&down=".$myrow["id"]."&sec_token=".$stok."\">".
  1231. Display::return_icon('down.gif', get_lang('Down'))."</a>";
  1232. }
  1233. //delete attachment file
  1234. if($_GET['action'] == 'delete') {
  1235. $id = $_GET['id_attach'];
  1236. delete_announcement_attachment_file($id);
  1237. }
  1238. // show attachment list
  1239. $attachment_list = array();
  1240. $attachment_list = get_attachment($myrow['id']);
  1241. if (count($attachment_list)>0) {
  1242. $realname=$attachment_list['path'];
  1243. $user_filename=$attachment_list['filename'];
  1244. $full_file_name = 'download.php?file='.$realname;
  1245. echo '<br/>';
  1246. echo '<br/>';
  1247. echo Display::return_icon('attachment.gif',get_lang('Attachment'));
  1248. echo '<a href="'.$full_file_name.'';
  1249. echo ' "> '.$user_filename.' </a>';
  1250. echo '<span class="forum_attach_comment" >'.$attachment_list['comment'].'</span>';
  1251. if (api_is_allowed_to_edit()) {
  1252. echo '&nbsp;&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&action=delete&id_attach='.$attachment_list['id'].'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset)).'\')) return false;">'.Display::return_icon('delete.gif',get_lang('Delete')).'</a><br />';
  1253. }
  1254. }
  1255. echo "</td>\n</tr>\n";
  1256. $iterator ++;
  1257. } else { // end of is_allowed_to_edit
  1258. //students view
  1259. // show attachment list
  1260. $attachment_list = array();
  1261. $attachment_list = get_attachment($myrow['id']);
  1262. if (count($attachment_list)>0) {
  1263. $realname=$attachment_list['path'];
  1264. $user_filename=$attachment_list['filename'];
  1265. $full_file_name = 'download.php?file='.$realname;
  1266. echo '<br/>';
  1267. echo '<br/>';
  1268. echo Display::return_icon('attachment.gif',get_lang('Attachment'));
  1269. echo '<a href="'.$full_file_name.'';
  1270. echo ' "> '.$user_filename.' </a>';
  1271. echo '<span class="forum_attach_comment" >'.$attachment_list['comment'].'</span>';
  1272. }
  1273. }
  1274. echo "<tr><td width=\"100%\" colspan=\"3\"><a href=\"#top\">".Display::return_icon('top.gif', get_lang('Top'))."</a></td></tr>";
  1275. }
  1276. $displayed[]=$myrow['id'];
  1277. } // end while ($myrow = Database::fetch_array($result))
  1278. echo "</table>";
  1279. } // end: if ($displayAnnoucementList)
  1280. echo "</table>";
  1281. if (!empty($display_specific_announcement)) display_announcement($announcement_id);
  1282. /*
  1283. ==============================================================================
  1284. FOOTER
  1285. ==============================================================================
  1286. */
  1287. if (empty($_GET['origin']) or $_GET['origin'] !== 'learnpath') {
  1288. //we are not in learnpath tool
  1289. Display::display_footer();
  1290. }
  1291. ?>