announcements.inc.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. <?php //$Id: announcements.inc.php 9246 2006-09-25 13:24:53Z bmol $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2005 Dokeos S.A.
  6. Copyright (c) various contributors
  7. For a full list of contributors, see "credits.txt".
  8. The full license can be read in "license.txt".
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13. See the GNU General Public License for more details.
  14. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  15. Mail: info@dokeos.com
  16. ==============================================================================
  17. */
  18. /**
  19. ==============================================================================
  20. * Include file with functions for the announcements module.
  21. * @package dokeos.announcements
  22. ==============================================================================
  23. */
  24. /*
  25. ==============================================================================
  26. DISPLAY FUNCTIONS
  27. ==============================================================================
  28. */
  29. /**
  30. * displays one specific announcement
  31. * @param $announcement_id, the id of the announcement you want to display
  32. * @todo remove globals
  33. * @todo more security checking
  34. */
  35. function display_announcement($announcement_id)
  36. {
  37. global $_uid, $dateFormatLong;
  38. $tbl_announcement = Database::get_course_table('announcement');
  39. $tbl_item_property = Database::get_course_table('item_property');
  40. if ($_uid)
  41. {
  42. $sql_query = " SELECT announcement.*, toolitemproperties.*
  43. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  44. WHERE announcement.id = toolitemproperties.ref
  45. AND announcement.id = '$announcement_id'
  46. AND toolitemproperties.tool='announcement'
  47. AND (toolitemproperties.to_user_id=$_uid OR toolitemproperties.to_group_id='0')
  48. AND toolitemproperties.visibility='1'
  49. ORDER BY display_order DESC";
  50. }
  51. else
  52. {
  53. $sql_query = " SELECT announcement.*, toolitemproperties.*
  54. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  55. WHERE announcement.id = toolitemproperties.ref
  56. AND announcement.id = '$announcement_id'
  57. AND toolitemproperties.tool='announcement'
  58. AND toolitemproperties.to_group_id='0'
  59. AND toolitemproperties.visibility='1'";
  60. }
  61. $sql_result = api_sql_query($sql_query,__FILE__,__LINE__);
  62. $result = mysql_fetch_array($sql_result);
  63. $title = $result['title'];
  64. $content = $result['content'];
  65. $content = make_clickable($content);
  66. $content = text_filter($content);
  67. $last_post_datetime = $myrow['temps'];// post time format datetime de mysql
  68. list($last_post_date, $last_post_time) = split(" ", $last_post_datetime);
  69. echo "<table height=\"100\" width=\"100%\" border=\"1\" cellpadding=\"5\" cellspacing=\"0\" id=\"agenda_list\">\n";
  70. echo "<tr class=\"data\"><td>" . $title . "</td></tr>\n";
  71. echo "<tr><td class=\"announcements_datum\">" . get_lang('AnnouncementPublishedOn') . " : " . ucfirst(format_locale_date($dateFormatLong,strtotime($last_post_date) ) ) . "</td></tr>\n";
  72. echo "<tr class=\"text\"><td>$content</td></tr>\n";
  73. echo "</table>";
  74. }
  75. /*======================================
  76. SHOW_TO_FORM
  77. ======================================*/
  78. /**
  79. * this function shows the form for sending a message to a specific group or user.
  80. */
  81. function show_to_form($to_already_selected)
  82. {
  83. $user_list=get_course_users();
  84. $group_list=get_course_groups();
  85. echo "\n<table>\n";
  86. echo "\t<tr>\n";
  87. // the form containing all the groups and all the users of the course
  88. echo "\t\t<td>\n";
  89. construct_not_selected_select_form($group_list,$user_list,$to_already_selected);
  90. echo "\t\t</td>\n";
  91. // the buttons for adding or removing groups/users
  92. echo "\n\t\t<td valign=\"middle\">\n";
  93. echo "\t\t<input type=\"button\" ",
  94. "onClick=\"move(this.form.elements[1],this.form.elements[4])\" ", // 7 & 4 : fonts
  95. "value=\" >> \">",
  96. "\n\t\t<p>&nbsp;</p>",
  97. "\n\t\t<input type=\"button\"",
  98. "onClick=\"move(this.form.elements[4],this.form.elements[1])\" ",
  99. "value=\" << \">";
  100. echo "\t\t</td>\n";
  101. echo "\n\t\t<td>\n";
  102. // the form containing the selected groups and users
  103. construct_selected_select_form($group_list,$user_list,$to_already_selected);
  104. echo "\t\t</td>\n";
  105. echo "\t</tr>\n";
  106. echo "</table>";
  107. }
  108. /*===========================================
  109. CONSTRUCT_NOT_SELECT_SELECT_FORM
  110. ===========================================*/
  111. /**
  112. * this function shows the form for sending a message to a specific group or user.
  113. */
  114. function construct_not_selected_select_form($group_list=null, $user_list=null,$to_already_selected)
  115. {
  116. echo "\t\t<select name=\"not_selected_form[]\" size=5 style=\"width:200px\" multiple>\n";
  117. // adding the groups to the select form
  118. if ($group_list)
  119. {
  120. foreach($group_list as $this_group)
  121. {
  122. if (!in_array("GROUP:".$this_group[id],$to_already_selected)) // $to_already_selected is the array containing the groups (and users) that are already selected
  123. {
  124. echo "\t\t<option value=\"GROUP:".$this_group[id]."\">",
  125. "G: ",$this_group[name]," - " . $this_group[userNb] . " " . get_lang('Users') .
  126. "</option>\n";
  127. }
  128. }
  129. // a divider
  130. echo "\t\t<option value=\"\">---------------------------------------------------------</option>\n";
  131. }
  132. // adding the individual users to the select form
  133. foreach($user_list as $this_user)
  134. {
  135. if (!in_array("USER:".$this_user[uid],$to_already_selected)) // $to_already_selected is the array containing the users (and groups) that are already selected
  136. {
  137. echo "\t\t<option value=\"USER:",$this_user[uid],"\">",
  138. "",$this_user[lastName]," ",$this_user[firstName],
  139. "</option>\n";
  140. }
  141. }
  142. echo "\t\t</select>\n";
  143. }
  144. /*==========================================
  145. CONSTRUCT_SELECTED_SELECT_FORM
  146. ==========================================*/
  147. /**
  148. * this function shows the form for sending a message to a specific group or user.
  149. */
  150. function construct_selected_select_form($group_list=null, $user_list=null,$to_already_selected)
  151. {
  152. // we separate the $to_already_selected array (containing groups AND users into
  153. // two separate arrays
  154. if (is_array($groupuser))
  155. {
  156. $groupuser=separate_users_groups($to_already_selected);
  157. }
  158. $groups_to_already_selected=$groupuser['groups'];
  159. $users_to_already_selected=$groupuser['users'];
  160. // we load all the groups and all the users into a reference array that we use to search the name of the group / user
  161. $ref_array_groups=get_course_groups();
  162. $ref_array_users=get_course_users();
  163. // we construct the form of the already selected groups / users
  164. echo "\t\t<select name=\"selectedform[]\" size=\"5\" multiple style=\"width:200px\" width=\"200px\">";
  165. foreach($to_already_selected as $groupuser)
  166. {
  167. list($type,$id)=explode(":",$groupuser);
  168. if ($type=="GROUP")
  169. {
  170. echo "\t\t<option value=\"".$groupuser."\">G: ".$ref_array_groups[$id]['name']."</option>";
  171. }
  172. else
  173. {
  174. echo "\t\t<option value=\"".$groupuser."\">".$ref_array_users[$id]['lastName']." ".$ref_array_users[$id]['firstName']."</option>";
  175. }
  176. }
  177. echo "</select>\n";
  178. }
  179. /*
  180. ==============================================================================
  181. DATA FUNCTIONS
  182. ==============================================================================
  183. */
  184. /**
  185. * this function gets all the users of the course,
  186. * including users from linked courses
  187. */
  188. function get_course_users()
  189. {
  190. //this would return only the users from real courses:
  191. //$user_list = CourseManager::get_user_list_from_course_code(api_get_course_id());
  192. $user_list = CourseManager::get_real_and_linked_user_list(api_get_course_id());
  193. return $user_list;
  194. }
  195. /**
  196. * this function gets all the groups of the course,
  197. * not including linked courses
  198. */
  199. function get_course_groups()
  200. {
  201. $new_group_list = CourseManager::get_group_list_of_course(api_get_course_id());
  202. return $new_group_list;
  203. }
  204. /*======================================
  205. LOAD_EDIT_USERS
  206. ======================================*/
  207. /**
  208. * This tools loads all the users and all the groups who have received
  209. * a specific item (in this case an announcement item)
  210. */
  211. function load_edit_users($tool, $id)
  212. {
  213. global $_course;
  214. global $tbl_item_property;
  215. $sql="SELECT * FROM $tbl_item_property WHERE tool='$tool' AND ref='$id'";
  216. $result=api_sql_query($sql,__FILE__,__LINE__) or die (mysql_error());
  217. while ($row=mysql_fetch_array($result))
  218. {
  219. $to_group=$row['to_group_id'];
  220. switch ($to_group)
  221. {
  222. // it was send to one specific user
  223. case null:
  224. $to[]="USER:".$row['to_user_id'];
  225. break;
  226. // it was sent to everyone
  227. case 0:
  228. return "everyone";
  229. exit;
  230. break;
  231. default:
  232. $to[]="GROUP:".$row['to_group_id'];
  233. }
  234. }
  235. return $to;
  236. }
  237. /*======================================
  238. USER_GROUP_FILTER_JAVASCRIPT
  239. ======================================*/
  240. /**
  241. * returns the javascript for setting a filter
  242. * this goes into the $htmlHeadXtra[] array
  243. */
  244. function user_group_filter_javascript()
  245. {
  246. return "<script language=\"JavaScript\" type=\"text/JavaScript\">
  247. <!--
  248. function jumpMenu(targ,selObj,restore)
  249. {
  250. eval(targ+\".location='\"+selObj.options[selObj.selectedIndex].value+\"'\");
  251. if (restore) selObj.selectedIndex=0;
  252. }
  253. //-->
  254. </script>
  255. ";
  256. }
  257. /*======================================
  258. TO_JAVASCRIPT
  259. ========================================*/
  260. /**
  261. * returns all the javascript that is required for easily
  262. * setting the target people/groups
  263. * this goes into the $htmlHeadXtra[] array
  264. */
  265. function to_javascript()
  266. {
  267. return "<script type=\"text/javascript\" language=\"JavaScript\">
  268. <!-- Begin javascript menu swapper
  269. function move(fbox, tbox)
  270. {
  271. var arrFbox = new Array();
  272. var arrTbox = new Array();
  273. var arrLookup = new Array();
  274. var i;
  275. for (i = 0; i < tbox.options.length; i++)
  276. {
  277. arrLookup[tbox.options[i].text] = tbox.options[i].value;
  278. arrTbox[i] = tbox.options[i].text;
  279. }
  280. var fLength = 0;
  281. var tLength = arrTbox.length;
  282. for(i = 0; i < fbox.options.length; i++)
  283. {
  284. arrLookup[fbox.options[i].text] = fbox.options[i].value;
  285. if (fbox.options[i].selected && fbox.options[i].value != \"\")
  286. {
  287. arrTbox[tLength] = fbox.options[i].text;
  288. tLength++;
  289. }
  290. else
  291. {
  292. arrFbox[fLength] = fbox.options[i].text;
  293. fLength++;
  294. }
  295. }
  296. arrFbox.sort();
  297. arrTbox.sort();
  298. fbox.length = 0;
  299. tbox.length = 0;
  300. var c;
  301. for(c = 0; c < arrFbox.length; c++)
  302. {
  303. var no = new Option();
  304. no.value = arrLookup[arrFbox[c]];
  305. no.text = arrFbox[c];
  306. fbox[c] = no;
  307. }
  308. for(c = 0; c < arrTbox.length; c++)
  309. {
  310. var no = new Option();
  311. no.value = arrLookup[arrTbox[c]];
  312. no.text = arrTbox[c];
  313. tbox[c] = no;
  314. }
  315. }
  316. function validate()
  317. {
  318. var f = document.new_calendar_item;
  319. f.submit();
  320. return true;
  321. }
  322. function selectAll(cbList,bSelect,showwarning)
  323. {
  324. if (cbList.length < 1) {
  325. alert(\"".get_lang('Send2All')."\");
  326. return;
  327. }
  328. for (var i=0; i<cbList.length; i++)
  329. cbList[i].selected = cbList[i].checked = bSelect
  330. }
  331. function reverseAll(cbList)
  332. {
  333. for (var i=0; i<cbList.length; i++)
  334. {
  335. cbList[i].checked = !(cbList[i].checked)
  336. cbList[i].selected = !(cbList[i].selected)
  337. }
  338. }
  339. // End -->
  340. </script>";
  341. }
  342. /*======================================
  343. SENT_TO_FORM
  344. ======================================*/
  345. /**
  346. * constructs the form to display all the groups and users the message has been sent to
  347. * input: $sent_to_array is a 2 dimensional array containing the groups and the users
  348. * the first level is a distinction between groups and users:
  349. * $sent_to_array['groups'] * and $sent_to_array['users']
  350. * $sent_to_array['groups'] (resp. $sent_to_array['users']) is also an array
  351. * containing all the id's of the groups (resp. users) who have received this message.
  352. * @author Patrick Cool <patrick.cool@>
  353. */
  354. function sent_to_form($sent_to_array)
  355. {
  356. // we find all the names of the groups
  357. $group_names=get_course_groups();
  358. count($sent_to_array);
  359. // we count the number of users and the number of groups
  360. if (isset($sent_to_array['users']))
  361. {
  362. $number_users=count($sent_to_array['users']);
  363. }
  364. else
  365. {
  366. $number_users=0;
  367. }
  368. if (isset($sent_to_array['groups']))
  369. {
  370. $number_groups=count($sent_to_array['groups']);
  371. }
  372. else
  373. {
  374. $number_groups=0;
  375. }
  376. $total_numbers=$number_users+$number_groups;
  377. // starting the form if there is more than one user/group
  378. if ($total_numbers >1)
  379. {
  380. $output="<select name=\"sent to\">\n";
  381. $output.="<option>".get_lang("SentTo")."</option>";
  382. // outputting the name of the groups
  383. if (is_array($sent_to_array['groups']))
  384. {
  385. foreach ($sent_to_array['groups'] as $group_id)
  386. {
  387. $output.="\t<option value=\"\">G: ".$group_names[$group_id]['name']."</option>\n";
  388. }
  389. }
  390. if (isset($sent_to_array['users']))
  391. {
  392. if (is_array($sent_to_array['users']))
  393. {
  394. foreach ($sent_to_array['users'] as $user_id)
  395. {
  396. $user_info=api_get_user_info($user_id);
  397. $output.="\t<option value=\"\">".$user_info['lastName']." ".$user_info['firstName']."</option>\n";
  398. }
  399. }
  400. }
  401. // ending the form
  402. $output.="</select>\n";
  403. }
  404. else // there is only one user/group
  405. {
  406. if (is_array($sent_to_array['users']))
  407. {
  408. $user_info=api_get_user_info($sent_to_array['users'][0]);
  409. echo $user_info['lastName']." ".$user_info['firstName'];
  410. }
  411. if (is_array($sent_to_array['groups']) and $sent_to_array['groups'][0]!==0)
  412. {
  413. $group_id=$sent_to_array['groups'][0];
  414. echo $group_names[$group_id]['name'];
  415. }
  416. if (is_array($sent_to_array['groups']) and $sent_to_array['groups'][0]==0)
  417. {
  418. echo get_lang("Everybody");
  419. }
  420. }
  421. echo $output;
  422. }
  423. /*======================================
  424. SEPARATE_USERS_GROUPS
  425. ======================================*/
  426. /**
  427. * This function separates the users from the groups
  428. * users have a value USER:XXX (with XXX the dokeos id
  429. * groups have a value GROUP:YYY (with YYY the group id)
  430. */
  431. function separate_users_groups($to)
  432. {
  433. foreach($to as $to_item)
  434. {
  435. list($type, $id) = explode(':', $to_item);
  436. switch($type)
  437. {
  438. case 'GROUP':
  439. $grouplist[] =$id;
  440. break;
  441. case 'USER':
  442. $userlist[] =$id;
  443. break;
  444. }
  445. }
  446. $send_to['groups']=$grouplist;
  447. $send_to['users']=$userlist;
  448. return $send_to;
  449. }
  450. /*======================================
  451. SENT_TO()
  452. ======================================*/
  453. /**
  454. * returns all the users and all the groups a specific announcement item
  455. * has been sent to
  456. */
  457. function sent_to($tool, $id)
  458. {
  459. global $_course;
  460. global $tbl_item_property;
  461. $sql="SELECT * FROM $tbl_item_property WHERE tool='$tool' AND ref='".$id."'";
  462. $result = api_sql_query($sql,__FILE__,__LINE__);
  463. while ($row=mysql_fetch_array($result))
  464. {
  465. // if to_group_id is null then it is sent to a specific user
  466. // if to_group_id = 0 then it is sent to everybody
  467. if (!is_null($row['to_group_id']))
  468. {
  469. $sent_to_group[]=$row['to_group_id'];
  470. }
  471. // if to_user_id <> 0 then it is sent to a specific user
  472. if ($row['to_user_id'] <> 0)
  473. {
  474. $sent_to_user[]=$row['to_user_id'];
  475. }
  476. }
  477. if (isset($sent_to_group))
  478. {
  479. $sent_to['groups']=$sent_to_group;
  480. }
  481. if (isset($sent_to_user))
  482. {
  483. $sent_to['users']=$sent_to_user;
  484. }
  485. return $sent_to;
  486. }
  487. /*===================================================
  488. CHANGE_VISIBILITY($tool,$id)
  489. =================================================*/
  490. /**
  491. * This functions swithes the visibility a course resource
  492. * using the visibility field in 'item_property'
  493. * values: 0 = invisibility for
  494. */
  495. function change_visibility($tool,$id)
  496. {
  497. global $_course;
  498. global $tbl_item_property;
  499. $sql="SELECT * FROM $tbl_item_property WHERE tool='$tool' AND ref='$id'";
  500. $result=api_sql_query($sql,__FILE__,__LINE__) or die (mysql_error());
  501. $row=mysql_fetch_array($result);
  502. if ($row['visibility']=='1')
  503. {
  504. $sql_visibility="UPDATE $tbl_item_property SET visibility='0' WHERE tool='$tool' AND ref='$id'";
  505. }
  506. else
  507. {
  508. $sql_visibility="UPDATE $tbl_item_property SET visibility='1' WHERE tool='$tool' AND ref='$id'";
  509. }
  510. $result=api_sql_query($sql_visibility,__FILE__,__LINE__) or die (mysql_error());
  511. }
  512. /*====================================================
  513. STORE_ADVALVAS_ITEM
  514. ====================================================*/
  515. function store_advalvas_item($emailTitle,$newContent, $order, $to)
  516. {
  517. global $_course;
  518. global $nameTools;
  519. global $_uid;
  520. global $tbl_announcement;
  521. global $tbl_item_property;
  522. // store in the table announcement
  523. $sql = "INSERT INTO $tbl_announcement SET content = '$newContent', title = '$emailTitle', end_date = NOW(), display_order ='$order'";
  524. $result = api_sql_query($sql,__FILE__,__LINE__) or die (mysql_error());
  525. $last_id= mysql_insert_id();
  526. // store in item_property (first the groups, then the users
  527. if (!is_null($to)) // !is_null($to): when no user is selected we send it to everyone
  528. {
  529. $send_to=separate_users_groups($to);
  530. // storing the selected groups
  531. if (is_array($send_to['groups']))
  532. {
  533. foreach ($send_to['groups'] as $group)
  534. {
  535. api_item_property_update($_course, TOOL_ANNOUNCEMENT, $last_id, "AnnouncementAdded", $_uid, $group);
  536. }
  537. }
  538. // storing the selected users
  539. if (is_array($send_to['users']))
  540. {
  541. foreach ($send_to['users'] as $user)
  542. {
  543. api_item_property_update($_course, TOOL_ANNOUNCEMENT, $last_id, "AnnouncementAdded", $_uid, '', $user);
  544. }
  545. }
  546. }
  547. else // the message is sent to everyone, so we set the group to 0
  548. {
  549. api_item_property_update($_course, TOOL_ANNOUNCEMENT, $last_id, "AnnouncementAdded", $_uid, '0');
  550. }
  551. return $last_id;
  552. }
  553. /*==================================================
  554. EDIT_VALVAS_ITEM
  555. ==================================================*/
  556. /**
  557. * This function stores the announcement Item in the table announcement
  558. * and updates the item_property also
  559. */
  560. function edit_advalvas_item($id,$emailTitle,$newContent,$to)
  561. {
  562. global $_course;
  563. global $nameTools;
  564. global $_uid;
  565. global $tbl_announcement;
  566. global $tbl_item_property;
  567. // store the modifications in the table announcement
  568. $sql = "UPDATE $tbl_announcement SET content='$newContent', title = '$emailTitle' WHERE id='$id'";
  569. $result = api_sql_query($sql,__FILE__,__LINE__) or die (mysql_error());
  570. // we remove everything from item_property for this
  571. $sql_delete="DELETE FROM $tbl_item_property WHERE ref='$id' AND tool='announcement'";
  572. $result = api_sql_query($sql_delete,__FILE__,__LINE__) or die (mysql_error());
  573. // store in item_property (first the groups, then the users
  574. if (!is_null($to)) // !is_null($to): when no user is selected we send it to everyone
  575. {
  576. $send_to=separate_users_groups($to);
  577. // storing the selected groups
  578. if (is_array($send_to['groups']))
  579. {
  580. foreach ($send_to['groups'] as $group)
  581. {
  582. api_item_property_update($_course, TOOL_ANNOUNCEMENT, $id, "AnnouncementUpdated", $_uid, $group);
  583. }
  584. }
  585. // storing the selected users
  586. if (is_array($send_to['users']))
  587. {
  588. foreach ($send_to['users'] as $user)
  589. {
  590. api_item_property_update($_course, TOOL_ANNOUNCEMENT, $id, "AnnouncementUpdated", $_uid, '', $user);
  591. }
  592. }
  593. }
  594. else // the message is sent to everyone, so we set the group to 0
  595. {
  596. api_item_property_update($_course, TOOL_ANNOUNCEMENT, $id, "AnnouncementUpdated", $_uid, '0');
  597. }
  598. }
  599. /*
  600. ==============================================================================
  601. MAIL FUNCTIONS
  602. ==============================================================================
  603. */
  604. /**
  605. * Sends an announcement by email to a list of users.
  606. * Emails are sent one by one to try to avoid antispam.
  607. */
  608. function send_announcement_email($user_list, $course_code, $_course, $mail_title, $mail_content)
  609. {
  610. foreach ($user_list as $this_user)
  611. {
  612. /* Header : Bericht van uw lesgever - GES ($course_code) - Morgen geen les! ($mail_title)
  613. Body : John Doe (prenom + nom) <john_doe@hotmail.com> (email)
  614. Morgen geen les! ($mail_title)
  615. Morgen is er geen les, de les wordt geschrapt wegens vergadering (newContent)
  616. */
  617. $mail_subject = get_lang('professorMessage').' - '.$_course['official_code'].' - '.$mail_title;
  618. $mail_body = '['.$_course['official_code'].'] - ['.$_course['name']."]\n";
  619. $mail_body .= $this_user['lastname'].' '.$this_user['firstname'].' <'.$this_user["email"]."> \n\n".stripslashes($mail_title)."\n\n".trim(stripslashes(html_entity_decode(strip_tags(str_replace(array('<p>','</p>','<br />'),array('',"\n","\n"),$mail_content)))))." \n\n-- \n";
  620. $mail_body .= $_user['firstName'].' '.$_user['lastName'].' ';
  621. $mail_body .= '<'.$_user['mail'].">\n";
  622. $mail_body .= $_course['official_code'].' '.$_course['name'];
  623. //set the charset and use it for the encoding of the email - small fix, not really clean (should check the content encoding origin first)
  624. //here we use the encoding used for the webpage where the text is encoded (ISO-8859-1 in this case)
  625. if(empty($charset)){$charset='ISO-8859-1';}
  626. $encoding = 'Content-Type: text/plain; charset='. $charset;
  627. $newmail = api_mail($this_user['lastname'].' '.$this_user['firstname'], $this_user['email'], $mail_subject, $mail_body, $_SESSION['_user']['lastName'].' '.$_SESSION['_user']['firstName'], $_SESSION['_user']['mail'], $encoding);
  628. }
  629. }
  630. function update_mail_sent($insert_id)
  631. {
  632. global $_course;
  633. global $tbl_announcement;
  634. // store the modifications in the table tbl_annoucement
  635. $sql = "UPDATE $tbl_announcement SET email_sent='1' WHERE id='$insert_id'";
  636. api_sql_query($sql,__FILE__,__LINE__);
  637. }