announcements.php 58 KB

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