announcements.inc.php 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Include file with functions for the announcements module.
  5. * @package chamilo.announcements
  6. * @todo use OOP
  7. */
  8. /**
  9. * @author jmontoya
  10. *
  11. */
  12. class AnnouncementManager
  13. {
  14. public function __construct()
  15. {
  16. }
  17. public static function get_tags()
  18. {
  19. return array('((user_name))', '((teacher_name))', '((teacher_email))', '((course_title))', '((course_link))');
  20. }
  21. public static function parse_content($content, $course_code)
  22. {
  23. $reader_info = api_get_user_info(api_get_user_id());
  24. $course_info = api_get_course_info($course_code);
  25. $teacher_list = CourseManager::get_teacher_list_from_course_code($course_info['code']);
  26. $teacher_name = '';
  27. if (!empty($teacher_list)) {
  28. foreach ($teacher_list as $teacher_data) {
  29. $teacher_name = api_get_person_name($teacher_data['firstname'], $teacher_data['lastname']);
  30. $teacher_email = $teacher_data['email'];
  31. break;
  32. }
  33. }
  34. $course_link = api_get_course_url();
  35. $data['username'] = $reader_info['username'];
  36. $data['teacher_name'] = $teacher_name;
  37. $data['teacher_email'] = $teacher_email;
  38. $data['course_title'] = $course_info['name'];
  39. $data['course_link'] = Display::url($course_link, $course_link);
  40. $content = str_replace(self::get_tags(), $data, $content);
  41. return $content;
  42. }
  43. /**
  44. * Gets all announcements from a course
  45. * @param string course db
  46. * @param int session id
  47. * @return array html with the content and count of announcements or false otherwise
  48. */
  49. public static function get_all_annoucement_by_course($course_info, $session_id = 0)
  50. {
  51. $session_id = intval($session_id);
  52. $course_id = $course_info['real_id'];
  53. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
  54. $tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
  55. $sql = "SELECT DISTINCT announcement.id, announcement.title, announcement.content
  56. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  57. WHERE announcement.id = toolitemproperties.ref AND
  58. toolitemproperties.tool='announcement' AND
  59. announcement.session_id = '$session_id' AND
  60. announcement.c_id = $course_id AND
  61. toolitemproperties.c_id = $course_id
  62. ORDER BY display_order DESC";
  63. $rs = Database::query($sql);
  64. $num_rows = Database::num_rows($rs);
  65. $result = array();
  66. if ($num_rows > 0) {
  67. $list = array();
  68. while ($row = Database::fetch_array($rs)) {
  69. $list[] = $row;
  70. }
  71. return $list;
  72. }
  73. return false;
  74. }
  75. /**
  76. * This functions swithes the visibility a course resource
  77. * using the visibility field in 'item_property'
  78. * @param array the course array
  79. * @param int ID of the element of the corresponding type
  80. * @return bool False on failure, True on success
  81. */
  82. public static function change_visibility_announcement($_course, $id)
  83. {
  84. $session_id = api_get_session_id();
  85. $item_visibility = api_get_item_visibility($_course, TOOL_ANNOUNCEMENT, $id, $session_id);
  86. if ($item_visibility == '1') {
  87. api_item_property_update($_course, TOOL_ANNOUNCEMENT, $id, 'invisible', api_get_user_id());
  88. } else {
  89. api_item_property_update($_course, TOOL_ANNOUNCEMENT, $id, 'visible', api_get_user_id());
  90. }
  91. return true;
  92. }
  93. /**
  94. * Deletes an announcement
  95. * @param array the course array
  96. * @param int the announcement id
  97. */
  98. public static function delete_announcement($_course, $id)
  99. {
  100. api_item_property_update($_course, TOOL_ANNOUNCEMENT, $id, 'delete', api_get_user_id());
  101. }
  102. /**
  103. * Deletes all announcements by course
  104. * @param array the course array
  105. */
  106. public static function delete_all_announcements($_course)
  107. {
  108. $announcements = self::get_all_annoucement_by_course($_course, api_get_session_id());
  109. foreach ($announcements as $annon) {
  110. api_item_property_update($_course, TOOL_ANNOUNCEMENT, $annon['id'], 'delete', api_get_user_id());
  111. }
  112. }
  113. /**
  114. * Displays one specific announcement
  115. * @param $announcement_id, the id of the announcement you want to display
  116. */
  117. public static function display_announcement($announcement_id)
  118. {
  119. if ($announcement_id != strval(intval($announcement_id))) {
  120. return false;
  121. }
  122. global $charset;
  123. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
  124. $tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
  125. $course_id = api_get_course_int_id();
  126. if (api_is_allowed_to_edit(false, true) || (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous())) {
  127. $sql_query = " SELECT announcement.*, toolitemproperties.*
  128. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  129. WHERE announcement.id = toolitemproperties.ref
  130. AND announcement.id = '$announcement_id'
  131. AND toolitemproperties.tool='announcement' AND
  132. announcement.c_id = $course_id AND
  133. toolitemproperties.c_id = $course_id
  134. ORDER BY display_order DESC";
  135. } else {
  136. $group_list = GroupManager::get_group_ids($course_id, api_get_user_id());
  137. if (empty($group_list)) {
  138. $group_list[] = 0;
  139. }
  140. $visibility_condition = " toolitemproperties.visibility='1'";
  141. if (GroupManager::is_tutor_of_group(api_get_user_id(), api_get_group_id())) {
  142. $visibility_condition = " toolitemproperties.visibility IN ('0', '1') ";
  143. }
  144. if (api_get_user_id() != 0) {
  145. $sql_query = " SELECT announcement.*, toolitemproperties.*
  146. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  147. WHERE
  148. announcement.id = toolitemproperties.ref AND
  149. announcement.id = '$announcement_id' AND
  150. toolitemproperties.tool='announcement' AND
  151. (toolitemproperties.to_user_id='".api_get_user_id()."' OR toolitemproperties.to_group_id IN ('0', '".implode("', '", $group_list)."')) AND
  152. $visibility_condition AND
  153. announcement.c_id = $course_id AND
  154. toolitemproperties.c_id = $course_id
  155. ORDER BY display_order DESC";
  156. } else {
  157. $sql_query = " SELECT announcement.*, toolitemproperties.*
  158. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  159. WHERE
  160. announcement.id = toolitemproperties.ref AND
  161. announcement.id = '$announcement_id' AND
  162. toolitemproperties.tool='announcement' AND
  163. toolitemproperties.to_group_id='0' AND
  164. toolitemproperties.visibility='1' AND
  165. announcement.c_id = $course_id AND
  166. toolitemproperties.c_id = $course_id";
  167. }
  168. }
  169. $sql_result = Database::query($sql_query);
  170. if (Database::num_rows($sql_result) > 0) {
  171. $result = Database::fetch_array($sql_result, 'ASSOC');
  172. $title = $result['title'];
  173. $content = self::parse_content($result['content'], api_get_course_id());
  174. echo "<table height=\"100\" width=\"100%\" cellpadding=\"5\" cellspacing=\"0\" class=\"data_table\">";
  175. echo "<tr><td><h2>".$title."</h2></td></tr>";
  176. if (self::user_can_edit_announcement()) {
  177. $modify_icons = "<a href=\"".api_get_self()."?".api_get_cidreq()."&action=modify&id=".$announcement_id."\">".Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL)."</a>";
  178. if ($result['visibility'] == 1) {
  179. $image_visibility = "visible";
  180. $alt_visibility = get_lang('Hide');
  181. } else {
  182. $image_visibility = "invisible";
  183. $alt_visibility = get_lang('Visible');
  184. }
  185. global $stok;
  186. $modify_icons .= "<a href=\"".api_get_self()."?".api_get_cidreq()."&origin=".(!empty($_GET['origin']) ? Security::remove_XSS($_GET['origin']) : '')."&action=showhide&id=".$announcement_id."&sec_token=".$stok."\">".
  187. Display::return_icon($image_visibility.'.png', $alt_visibility, '', ICON_SIZE_SMALL)."</a>";
  188. if (self::user_can_edit_announcement()) {
  189. $modify_icons .= "<a href=\"".api_get_self()."?".api_get_cidreq()."&action=delete&id=".$announcement_id."&sec_token=".$stok."\" onclick=\"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset))."')) return false;\">".
  190. Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).
  191. "</a>";
  192. }
  193. echo "<tr><th style='text-align:right'>$modify_icons</th></tr>";
  194. }
  195. echo "<tr><td>$content</td></tr>";
  196. echo "<tr><td class=\"announcements_datum\">".get_lang('LastUpdateDate')." : ".api_convert_and_format_date($result['insert_date'], DATE_TIME_FORMAT_LONG)."</td></tr>";
  197. // User or group icon
  198. $sent_to_icon = '';
  199. if ($result['to_group_id'] !== '0' and $result['to_group_id'] !== 'NULL') {
  200. $sent_to_icon = Display::return_icon('group.gif', get_lang('AnnounceSentToUserSelection'));
  201. }
  202. $sent_to = self::sent_to('announcement', $announcement_id);
  203. $sent_to_form = self::sent_to_form($sent_to);
  204. echo Display::tag('td', get_lang('SentTo').' : '.$sent_to_form, array('class' => 'announcements_datum'));
  205. $attachment_list = self::get_attachment($announcement_id);
  206. if (count($attachment_list) > 0) {
  207. echo "<tr><td>";
  208. $realname = $attachment_list['path'];
  209. $user_filename = $attachment_list['filename'];
  210. $full_file_name = 'download.php?file='.$realname;
  211. echo '<br/>';
  212. echo Display::return_icon('attachment.gif', get_lang('Attachment'));
  213. echo '<a href="'.$full_file_name.' "> '.$user_filename.' </a>';
  214. echo ' - <span class="forum_attach_comment" >'.$attachment_list['comment'].'</span>';
  215. if (api_is_allowed_to_edit(false, true)) {
  216. echo Display::url(Display::return_icon('delete.png', get_lang('Delete'), '', 16), api_get_self()."?".api_get_cidreq()."&action=delete_attachment&id_attach=".$attachment_list['id']."&sec_token=".$stok);
  217. }
  218. echo '</td></tr>';
  219. }
  220. echo "</table>";
  221. } else {
  222. return false;
  223. }
  224. }
  225. public static function get_last_announcement_order()
  226. {
  227. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
  228. $course_id = api_get_course_int_id();
  229. $sql_max = "SELECT MAX(display_order) FROM $tbl_announcement WHERE c_id = $course_id ";
  230. $res_max = Database::query($sql_max);
  231. $order = 0;
  232. if (Database::num_rows($res_max)) {
  233. $row_max = Database::fetch_array($res_max);
  234. $order = intval($row_max[0]) + 1;
  235. }
  236. return $order;
  237. }
  238. /**
  239. * Store an announcement in the database (including its attached file if any)
  240. * @param string Announcement title (pure text)
  241. * @param string Content of the announcement (can be HTML)
  242. * @param int Display order in the list of announcements
  243. * @param array Array of users and groups to send the announcement to
  244. * @param array uploaded file $_FILES
  245. * @param string Comment describing the attachment
  246. * @return int false on failure, ID of the announcement on success
  247. */
  248. public static function add_announcement($emailTitle, $newContent, $sent_to, $file = array(), $file_comment = null, $end_date = null)
  249. {
  250. global $_course;
  251. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
  252. // filter data
  253. $emailTitle = Database::escape_string($emailTitle);
  254. $newContent = Database::escape_string($newContent);
  255. if (empty($end_date)) {
  256. $end_date = api_get_utc_datetime();
  257. } else {
  258. $end_date = Database::escape_string($end_date);
  259. }
  260. $course_id = api_get_course_int_id();
  261. $order = self::get_last_announcement_order();
  262. // store in the table announcement
  263. $sql = "INSERT INTO $tbl_announcement SET
  264. c_id = '$course_id',
  265. content = '$newContent',
  266. title = '$emailTitle',
  267. end_date = '$end_date',
  268. display_order = '$order',
  269. session_id = ".api_get_session_id();
  270. $result = Database::query($sql);
  271. if ($result === false) {
  272. return false;
  273. } else {
  274. //Store the attach file
  275. $last_id = Database::insert_id();
  276. if (!empty($file)) {
  277. self::add_announcement_attachment_file($last_id, $file_comment, $_FILES['user_upload']);
  278. }
  279. // store in item_property (first the groups, then the users
  280. if (!is_null($sent_to)) {
  281. // !is_null($sent_to): when no user is selected we send it to everyone
  282. $send_to = self::separate_users_groups($sent_to);
  283. // storing the selected groups
  284. if (is_array($send_to['groups'])) {
  285. foreach ($send_to['groups'] as $group) {
  286. api_item_property_update($_course, TOOL_ANNOUNCEMENT, $last_id, "AnnouncementAdded", api_get_user_id(), $group);
  287. }
  288. }
  289. // storing the selected users
  290. if (is_array($send_to['users'])) {
  291. foreach ($send_to['users'] as $user) {
  292. api_item_property_update($_course, TOOL_ANNOUNCEMENT, $last_id, "AnnouncementAdded", api_get_user_id(), '', $user);
  293. }
  294. }
  295. } else {
  296. // the message is sent to everyone, so we set the group to 0
  297. api_item_property_update($_course, TOOL_ANNOUNCEMENT, $last_id, "AnnouncementAdded", api_get_user_id(), '0');
  298. }
  299. return $last_id;
  300. }
  301. }
  302. /*
  303. STORE ANNOUNCEMENT GROUP ITEM
  304. */
  305. public static function add_group_announcement($emailTitle, $newContent, $to, $to_users, $file = array(), $file_comment = '')
  306. {
  307. global $_course;
  308. // database definitions
  309. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
  310. $emailTitle = Database::escape_string($emailTitle);
  311. $newContent = Database::escape_string($newContent);
  312. $order = self::get_last_announcement_order();
  313. $now = api_get_utc_datetime();
  314. $course_id = api_get_course_int_id();
  315. // store in the table announcement
  316. $sql = "INSERT INTO $tbl_announcement SET
  317. c_id = '$course_id',
  318. content = '$newContent',
  319. title = '$emailTitle',
  320. end_date = '$now',
  321. display_order = '$order',
  322. session_id = ".api_get_session_id();
  323. $result = Database::query($sql);
  324. if ($result === false) {
  325. return false;
  326. }
  327. //store the attach file
  328. $last_id = Database::insert_id();
  329. if (!empty($file)) {
  330. self::add_announcement_attachment_file($last_id, $file_comment, $file);
  331. }
  332. // store in item_property (first the groups, then the users
  333. if (!isset($to_users)) {
  334. $send_to = self::separate_users_groups($to);
  335. // storing the selected groups
  336. if (is_array($send_to['groups'])) {
  337. foreach ($send_to['groups'] as $group) {
  338. api_item_property_update($_course, TOOL_ANNOUNCEMENT, $last_id, "AnnouncementAdded", api_get_user_id(), $group);
  339. }
  340. }
  341. } else {
  342. // the message is sent to everyone, so we set the group to 0
  343. // storing the selected users
  344. if (is_array($to_users)) {
  345. foreach ($to_users as $user) {
  346. api_item_property_update($_course, TOOL_ANNOUNCEMENT, $last_id, "AnnouncementAdded", api_get_user_id(), api_get_group_id(), $user);
  347. }
  348. }
  349. }
  350. return $last_id;
  351. }
  352. /*
  353. EDIT ANNOUNCEMENT
  354. */
  355. /**
  356. * This function stores the announcement item in the announcement table
  357. * and updates the item_property table
  358. *
  359. * @param int id of the announcement
  360. * @param string email
  361. * @param string content
  362. * @param array users that will receive the announcement
  363. * @param mixed attachment
  364. * @param string file comment
  365. *
  366. */
  367. public static function edit_announcement($id, $emailTitle, $newContent, $to, $file = array(), $file_comment = '')
  368. {
  369. global $_course;
  370. $course_id = api_get_course_int_id();
  371. $tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
  372. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
  373. $emailTitle = Database::escape_string($emailTitle);
  374. $newContent = Database::escape_string($newContent);
  375. $id = intval($id);
  376. // store the modifications in the table announcement
  377. $sql = "UPDATE $tbl_announcement SET content = '$newContent', title = '$emailTitle' WHERE c_id = $course_id AND id='$id'";
  378. $result = Database::query($sql);
  379. // save attachment file
  380. $row_attach = self::get_attachment($id);
  381. $id_attach = intval($row_attach['id']);
  382. if (!empty($file)) {
  383. if (empty($id_attach)) {
  384. self::add_announcement_attachment_file($id, $file_comment, $file);
  385. } else {
  386. self::edit_announcement_attachment_file($id_attach, $file, $file_comment);
  387. }
  388. }
  389. // we remove everything from item_property for this
  390. $sql_delete = "DELETE FROM $tbl_item_property WHERE c_id = $course_id AND ref='$id' AND tool='announcement'";
  391. $result = Database::query($sql_delete);
  392. // store in item_property (first the groups, then the users
  393. if (!is_null($to)) {
  394. // !is_null($to): when no user is selected we send it to everyone
  395. $send_to = self::separate_users_groups($to);
  396. // storing the selected groups
  397. if (is_array($send_to['groups'])) {
  398. foreach ($send_to['groups'] as $group) {
  399. api_item_property_update($_course, TOOL_ANNOUNCEMENT, $id, "AnnouncementUpdated", api_get_user_id(), $group);
  400. }
  401. }
  402. // storing the selected users
  403. if (is_array($send_to['users'])) {
  404. foreach ($send_to['users'] as $user) {
  405. api_item_property_update($_course, TOOL_ANNOUNCEMENT, $id, "AnnouncementUpdated", api_get_user_id(), 0, $user);
  406. }
  407. }
  408. } else {
  409. // the message is sent to everyone, so we set the group to 0
  410. api_item_property_update($_course, TOOL_ANNOUNCEMENT, $id, "AnnouncementUpdated", api_get_user_id(), '0');
  411. }
  412. }
  413. /*
  414. MAIL FUNCTIONS
  415. */
  416. public static function update_mail_sent($insert_id)
  417. {
  418. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
  419. if ($insert_id != strval(intval($insert_id))) {
  420. return false;
  421. }
  422. $insert_id = Database::escape_string($insert_id);
  423. $course_id = api_get_course_int_id();
  424. // store the modifications in the table tbl_annoucement
  425. $sql = "UPDATE $tbl_announcement SET email_sent='1' WHERE c_id = $course_id AND id='$insert_id'";
  426. Database::query($sql);
  427. }
  428. /**
  429. * Gets all announcements from a user by course
  430. * @param string course db
  431. * @param int user id
  432. * @return array html with the content and count of announcements or false otherwise
  433. */
  434. public static function get_all_annoucement_by_user_course($course_code, $user_id)
  435. {
  436. $course_info = api_get_course_info($course_code);
  437. $course_id = $course_info['real_id'];
  438. if (empty($user_id)) {
  439. return false;
  440. }
  441. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
  442. $tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
  443. if (!empty($user_id) && is_numeric($user_id)) {
  444. $user_id = intval($user_id);
  445. $sql = "SELECT DISTINCT announcement.title, announcement.content
  446. FROM $tbl_announcement announcement, $tbl_item_property toolitemproperties
  447. WHERE
  448. announcement.c_id = $course_id AND
  449. toolitemproperties.c_id = $course_id AND
  450. announcement.id = toolitemproperties.ref AND
  451. toolitemproperties.tool='announcement' AND
  452. (toolitemproperties.insert_user_id='$user_id' AND (toolitemproperties.to_group_id='0' OR toolitemproperties.to_group_id is null))
  453. AND toolitemproperties.visibility='1'
  454. AND announcement.session_id = 0
  455. ORDER BY display_order DESC";
  456. $rs = Database::query($sql);
  457. $num_rows = Database::num_rows($rs);
  458. $content = '';
  459. $i = 0;
  460. $result = array();
  461. if ($num_rows > 0) {
  462. while ($myrow = Database::fetch_array($rs)) {
  463. $content.= '<strong>'.$myrow['title'].'</strong><br /><br />';
  464. $content.= $myrow['content'];
  465. $i++;
  466. }
  467. $result['content'] = $content;
  468. $result['count'] = $i;
  469. return $result;
  470. }
  471. return false;
  472. }
  473. return false;
  474. }
  475. /*
  476. SHOW_TO_FORM
  477. */
  478. /**
  479. * this function shows the form for sending a message to a specific group or user.
  480. */
  481. public static function show_to_form($to_already_selected)
  482. {
  483. $user_list = self::get_course_users();
  484. $group_list = self::get_course_groups();
  485. if ($to_already_selected == '' || $to_already_selected == 'everyone') {
  486. $to_already_selected = array();
  487. }
  488. echo "<table id=\"recipient_list\" style=\"display: none;\">";
  489. echo '<tr>';
  490. // the form containing all the groups and all the users of the course
  491. echo '<td>';
  492. echo "<strong>".get_lang('Users')."</strong><br />";
  493. self::construct_not_selected_select_form($group_list, $user_list, $to_already_selected);
  494. echo "</td>";
  495. // the buttons for adding or removing groups/users
  496. echo '<td valign="middle">';
  497. echo '<button class="arrowr" type="button" onClick="javascript: move(this.form.elements[0], this.form.elements[3])" onClick="javascript: move(this.form.elements[0], this.form.elements[3])"></button>';
  498. echo '<br /> <br />';
  499. echo '<button class="arrowl" type="button" onClick="javascript: move(this.form.elements[3], this.form.elements[0])" onClick="javascript: move(this.form.elements[3], this.form.elements[0])"></button>';
  500. echo "</td>";
  501. echo "<td>";
  502. // the form containing the selected groups and users
  503. echo "<strong>".get_lang('DestinationUsers')."</strong><br />";
  504. self::construct_selected_select_form($group_list, $user_list, $to_already_selected);
  505. echo "</td>";
  506. echo "</tr>";
  507. echo "</table>";
  508. }
  509. /**
  510. * this function shows the form for sending a message to a specific group or user.
  511. */
  512. public static function show_to_form_group($group_id)
  513. {
  514. echo "<table id=\"recipient_list\" style=\"display: none;\">";
  515. echo "<tr>";
  516. echo "<td>";
  517. echo "<select name=\"not_selected_form[]\" size=5 class=\"span4\" multiple>";
  518. $group_users = GroupManager::get_subscribed_users($group_id);
  519. foreach ($group_users as $user) {
  520. echo '<option value="'.$user['user_id'].'" title="'.sprintf(get_lang('LoginX'), $user['username']).'" >'.api_get_person_name($user['firstname'], $user['lastname']).'</option>';
  521. }
  522. echo '</select>';
  523. echo "</td>";
  524. // the buttons for adding or removing groups/users
  525. echo "<td valign=\"middle\">";
  526. echo '<button class="arrowr" type="button" onClick="javascript: move(this.form.elements[1], this.form.elements[4])" onClick="javascript: move(this.form.elements[1], this.form.elements[4])"></button>';
  527. echo '<br /> <br />';
  528. echo '<button class="arrowl" type="button" onClick="javascript: move(this.form.elements[4], this.form.elements[1])" onClick="javascript: move(this.form.elements[4], this.form.elements[1])"></button>';
  529. echo "</td>";
  530. echo "<td>";
  531. echo "<select id=\"selectedform\" name=\"selectedform[]\" size=5 class=\"span4\" multiple>";
  532. echo '</select>';
  533. echo "</td>";
  534. echo "</tr>";
  535. echo "</table>";
  536. }
  537. /*
  538. CONSTRUCT_NOT_SELECT_SELECT_FORM
  539. */
  540. /**
  541. * this function shows the form for sending a message to a specific group or user.
  542. */
  543. public static function construct_not_selected_select_form($group_list = null, $user_list = null, $to_already_selected)
  544. {
  545. echo '<select name="not_selected_form[]" size="7" class="span4" multiple>';
  546. // adding the groups to the select form
  547. if ($group_list) {
  548. foreach ($group_list as $this_group) {
  549. if (is_array($to_already_selected)) {
  550. 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
  551. $user_label = ($this_group['userNb'] > 0) ? get_lang('Users') : get_lang('LowerCaseUser');
  552. $user_disabled = ($this_group['userNb'] > 0) ? "" : "disabled=disabled";
  553. echo "<option $user_disabled value=\"GROUP:".$this_group['id']."\">",
  554. "G: ", $this_group['name'], " - ".$this_group['userNb']." ".$user_label.
  555. "</option>";
  556. }
  557. }
  558. }
  559. // a divider
  560. echo "<option value=\"\">---------------------------------------------------------</option>";
  561. }
  562. // adding the individual users to the select form
  563. if ($user_list) {
  564. foreach ($user_list as $this_user) {
  565. if (is_array($to_already_selected)) {
  566. if (!in_array("USER:".$this_user['user_id'], $to_already_selected)) { // $to_already_selected is the array containing the users (and groups) that are already selected
  567. echo "<option value=\"USER:".$this_user['user_id']."\" title='".sprintf(get_lang('LoginX'), $this_user['username'])."'>",
  568. "", api_get_person_name($this_user['firstname'], $this_user['lastname']),
  569. "</option>";
  570. }
  571. }
  572. }
  573. }
  574. echo "</select>";
  575. }
  576. /*
  577. CONSTRUCT_SELECTED_SELECT_FORM
  578. */
  579. /**
  580. * this function shows the form for sending a message to a specific group or user.
  581. */
  582. public static function construct_selected_select_form($group_list = null, $user_list = null, $to_already_selected)
  583. {
  584. // we separate the $to_already_selected array (containing groups AND users into
  585. // two separate arrays
  586. $groupuser = array();
  587. if (is_array($to_already_selected)) {
  588. $groupuser = self::separate_users_groups($to_already_selected);
  589. }
  590. $groups_to_already_selected = $groupuser['groups'];
  591. $users_to_already_selected = $groupuser['users'];
  592. // we load all the groups and all the users into a reference array that we use to search the name of the group / user
  593. $ref_array_groups = self::get_course_groups();
  594. $ref_array_users = self::get_course_users();
  595. // we construct the form of the already selected groups / users
  596. echo '<select id="selectedform" name="selectedform[]" size="7" multiple class="span4">';
  597. if (is_array($to_already_selected)) {
  598. foreach ($to_already_selected as $groupuser) {
  599. list($type, $id) = explode(":", $groupuser);
  600. if ($type == "GROUP") {
  601. echo "<option value=\"".$groupuser."\">G: ".$ref_array_groups[$id]['name']."</option>";
  602. } else {
  603. foreach ($ref_array_users as $key => $value) {
  604. if ($value['user_id'] == $id) {
  605. echo "<option value=\"".$groupuser."\" title='".sprintf(get_lang('LoginX'), $value['username'])."'>".api_get_person_name($value['firstname'], $value['lastname'])."</option>";
  606. break;
  607. }
  608. }
  609. }
  610. }
  611. } else {
  612. if ($to_already_selected == 'everyone') {
  613. // adding the groups to the select form
  614. if (is_array($ref_array_groups)) {
  615. foreach ($ref_array_groups as $this_group) {
  616. //api_display_normal_message("group " . $thisGroup[id] . $thisGroup[name]);
  617. if (!is_array($to_already_selected) || !in_array("GROUP:".$this_group['id'], $to_already_selected)) { // $to_already_selected is the array containing the groups (and users) that are already selected
  618. echo "<option value=\"GROUP:".$this_group['id']."\">",
  619. "G: ", $this_group['name'], " &ndash; ".$this_group['userNb']." ".get_lang('Users').
  620. "</option>";
  621. }
  622. }
  623. }
  624. // adding the individual users to the select form
  625. foreach ($ref_array_users as $this_user) {
  626. if (!is_array($to_already_selected) || !in_array("USER:".$this_user['user_id'], $to_already_selected)) { // $to_already_selected is the array containing the users (and groups) that are already selected
  627. echo "<option value=\"USER:", $this_user['user_id'], "\" title='".sprintf(get_lang('LoginX'), $user['username'])."'>",
  628. "", api_get_person_name($this_user['firstname'], $this_user['lastname']),
  629. "</option>";
  630. }
  631. }
  632. }
  633. }
  634. echo "</select>";
  635. }
  636. /*
  637. DATA FUNCTIONS
  638. */
  639. /**
  640. * Returns announcement info from its id
  641. *
  642. * @param type $course_id
  643. * @param type $annoucement_id
  644. * @return array
  645. */
  646. public static function get_by_id($course_id, $annoucement_id)
  647. {
  648. $annoucement_id = intval($annoucement_id);
  649. $course_id = $course_id ? intval($course_id) : api_get_course_int_id();
  650. $tbl_announcement = Database::get_course_table(TABLE_ANNOUNCEMENT);
  651. $tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
  652. $sql = "SELECT DISTINCT announcement.id, announcement.title, announcement.content
  653. FROM $tbl_announcement announcement INNER JOIN $tbl_item_property toolitemproperties
  654. ON announcement.id = toolitemproperties.ref AND
  655. announcement.c_id = $course_id AND
  656. toolitemproperties.c_id = $course_id
  657. WHERE toolitemproperties.tool='announcement' AND
  658. announcement.id = $annoucement_id";
  659. $result = Database::query($sql);
  660. if (Database::num_rows($result)) {
  661. return Database::fetch_array($result);
  662. }
  663. return array();
  664. }
  665. /**
  666. * this function gets all the users of the course,
  667. * including users from linked courses
  668. * @todo deprecate this function, use CourseManager class
  669. */
  670. public static function get_course_users()
  671. {
  672. //this would return only the users from real courses:
  673. $session_id = api_get_session_id();
  674. if ($session_id != 0) {
  675. $user_list = CourseManager::get_real_and_linked_user_list(api_get_course_id(), true, $session_id);
  676. } else {
  677. $user_list = CourseManager::get_real_and_linked_user_list(api_get_course_id(), false, 0);
  678. }
  679. return $user_list;
  680. }
  681. /**
  682. * this function gets all the groups of the course,
  683. * not including linked courses
  684. */
  685. public static function get_course_groups()
  686. {
  687. $session_id = api_get_session_id();
  688. if ($session_id != 0) {
  689. $new_group_list = CourseManager::get_group_list_of_course(api_get_course_id(), $session_id, 1);
  690. } else {
  691. $new_group_list = CourseManager::get_group_list_of_course(api_get_course_id(), 0, 1);
  692. }
  693. return $new_group_list;
  694. }
  695. /*
  696. *
  697. LOAD_EDIT_USERS
  698. */
  699. /**
  700. * This tools loads all the users and all the groups who have received
  701. * a specific item (in this case an announcement item)
  702. */
  703. public static function load_edit_users($tool, $id)
  704. {
  705. $tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
  706. $tool = Database::escape_string($tool);
  707. $id = Database::escape_string($id);
  708. $course_id = api_get_course_int_id();
  709. $sql = "SELECT * FROM $tbl_item_property WHERE c_id = $course_id AND tool='$tool' AND ref='$id'";
  710. $result = Database::query($sql);
  711. while ($row = Database::fetch_array($result)) {
  712. $to_group = $row['to_group_id'];
  713. switch ($to_group) {
  714. // it was send to one specific user
  715. case null:
  716. $to[] = "USER:".$row['to_user_id'];
  717. break;
  718. // it was sent to everyone
  719. case 0:
  720. return "everyone";
  721. exit;
  722. break;
  723. default:
  724. $to[] = "GROUP:".$row['to_group_id'];
  725. }
  726. }
  727. return $to;
  728. }
  729. /*
  730. USER_GROUP_FILTER_JAVASCRIPT
  731. */
  732. /**
  733. * returns the javascript for setting a filter
  734. * this goes into the $htmlHeadXtra[] array
  735. */
  736. public static function user_group_filter_javascript()
  737. {
  738. return "<script language=\"JavaScript\" type=\"text/JavaScript\">
  739. <!--
  740. function jumpMenu(targ,selObj,restore)
  741. {
  742. eval(targ+\".location='\"+selObj.options[selObj.selectedIndex].value+\"'\");
  743. if (restore) selObj.selectedIndex=0;
  744. }
  745. //-->
  746. </script>";
  747. }
  748. /*
  749. TO_JAVASCRIPT
  750. */
  751. /**
  752. * returns all the javascript that is required for easily
  753. * setting the target people/groups
  754. * this goes into the $htmlHeadXtra[] array
  755. */
  756. public static function to_javascript()
  757. {
  758. $www = api_get_path(WEB_PATH);
  759. /*
  760. * Do not allow this kind of behaviour. js minifieds should be manage by the template class or assetic or whatever see #4757 for more info
  761. if (api_get_setting('server_type') == 'test') {
  762. $src = $www . 'main/announcements/resources/js/main.js';
  763. } else {
  764. $src = $www . 'main/announcements/resources/js/main.min.js';
  765. } */
  766. $src = $www.'main/announcements/resources/js/main.js';
  767. $result = Javascript::tag($src);
  768. $root = Chamilo::url();
  769. $code = "var www = '$root';\n";
  770. $code .= Javascript::get_lang('FieldRequired', 'Send2All', 'AddAnAttachment', 'Everybody');
  771. $result .= Javascript::tag_code($code);
  772. return $result;
  773. }
  774. /*
  775. SENT_TO_FORM
  776. */
  777. /**
  778. * constructs the form to display all the groups and users the message has been sent to
  779. * input: $sent_to_array is a 2 dimensional array containing the groups and the users
  780. * the first level is a distinction between groups and users:
  781. * $sent_to_array['groups'] * and $sent_to_array['users']
  782. * $sent_to_array['groups'] (resp. $sent_to_array['users']) is also an array
  783. * containing all the id's of the groups (resp. users) who have received this message.
  784. * @author Patrick Cool <patrick.cool@>
  785. */
  786. public static function sent_to_form($sent_to_array)
  787. {
  788. // we find all the names of the groups
  789. $group_names = self::get_course_groups();
  790. // we count the number of users and the number of groups
  791. if (isset($sent_to_array['users'])) {
  792. $number_users = count($sent_to_array['users']);
  793. } else {
  794. $number_users = 0;
  795. }
  796. if (isset($sent_to_array['groups'])) {
  797. $number_groups = count($sent_to_array['groups']);
  798. } else {
  799. $number_groups = 0;
  800. }
  801. $total_numbers = $number_users + $number_groups;
  802. // starting the form if there is more than one user/group
  803. $output = array();
  804. if ($total_numbers > 1) {
  805. // outputting the name of the groups
  806. if (is_array($sent_to_array['groups'])) {
  807. foreach ($sent_to_array['groups'] as $group_id) {
  808. $output[] = $group_names[$group_id]['name'];
  809. }
  810. }
  811. if (isset($sent_to_array['users'])) {
  812. if (is_array($sent_to_array['users'])) {
  813. foreach ($sent_to_array['users'] as $user_id) {
  814. $user_info = api_get_user_info($user_id);
  815. $output[] = $user_info['complete_name_with_username'];
  816. }
  817. }
  818. }
  819. } else {
  820. // there is only one user/group
  821. if (isset($sent_to_array['users']) and is_array($sent_to_array['users'])) {
  822. $user_info = api_get_user_info($sent_to_array['users'][0]);
  823. $output[] = api_get_person_name($user_info['firstname'], $user_info['lastname']);
  824. }
  825. if (isset($sent_to_array['groups']) and is_array($sent_to_array['groups']) and isset($sent_to_array['groups'][0]) and $sent_to_array['groups'][0] !== 0) {
  826. $group_id = $sent_to_array['groups'][0];
  827. $output[] = "&nbsp;".$group_names[$group_id]['name'];
  828. }
  829. if (empty($sent_to_array['groups']) and empty($sent_to_array['users'])) {
  830. $output[] = "&nbsp;".get_lang('Everybody');
  831. }
  832. }
  833. if (!empty($output)) {
  834. $output = array_filter($output);
  835. if (count($output) > 0) {
  836. $output = implode(', ', $output);
  837. }
  838. return $output;
  839. }
  840. }
  841. /*
  842. SEPARATE_USERS_GROUPS
  843. */
  844. /**
  845. * This function separates the users from the groups
  846. * users have a value USER:XXX (with XXX the dokeos id
  847. * groups have a value GROUP:YYY (with YYY the group id)
  848. * @param array Array of strings that define the type and id of each destination
  849. * @return array Array of groups and users (each an array of IDs)
  850. */
  851. public static function separate_users_groups($to)
  852. {
  853. $grouplist = array();
  854. $userlist = array();
  855. foreach ($to as $to_item) {
  856. list($type, $id) = explode(':', $to_item);
  857. switch ($type) {
  858. case 'GROUP':
  859. $grouplist[] = intval($id);
  860. break;
  861. case 'USER':
  862. $userlist[] = intval($id);
  863. break;
  864. }
  865. }
  866. $send_to['groups'] = $grouplist;
  867. $send_to['users'] = $userlist;
  868. return $send_to;
  869. }
  870. /*
  871. SENT_TO()
  872. */
  873. /**
  874. * Returns all the users and all the groups a specific announcement item
  875. * has been sent to
  876. * @param string The tool (announcement, agenda, ...)
  877. * @param int ID of the element of the corresponding type
  878. * @return array Array of users and groups to whom the element has been sent
  879. */
  880. public static function sent_to($tool, $id)
  881. {
  882. global $tbl_item_property;
  883. $tool = Database::escape_string($tool);
  884. $id = intval($id);
  885. $sent_to_group = array();
  886. $sent_to = array();
  887. $course_id = api_get_course_int_id();
  888. $sql = "SELECT to_group_id, to_user_id FROM $tbl_item_property WHERE c_id = $course_id AND tool = '$tool' AND ref=".$id;
  889. $result = Database::query($sql);
  890. while ($row = Database::fetch_array($result)) {
  891. // if to_group_id is null then it is sent to a specific user
  892. // if to_group_id = 0 then it is sent to everybody
  893. if (empty($row['to_user_id'])) {
  894. if ($row['to_group_id'] != 0) {
  895. $sent_to_group[] = $row['to_group_id'];
  896. }
  897. }
  898. // if to_user_id <> 0 then it is sent to a specific user
  899. if ($row['to_user_id'] <> 0) {
  900. $sent_to_user[] = $row['to_user_id'];
  901. }
  902. }
  903. if (isset($sent_to_group)) {
  904. $sent_to['groups'] = $sent_to_group;
  905. }
  906. if (isset($sent_to_user)) {
  907. $sent_to['users'] = $sent_to_user;
  908. }
  909. return $sent_to;
  910. }
  911. /* ATTACHMENT FUNCTIONS */
  912. /**
  913. * Show a list with all the attachments according to the post's id
  914. * @param int announcement id
  915. * @return array with the post info
  916. * @author Arthur Portugal
  917. * @version November 2009, dokeos 1.8.6.2
  918. */
  919. public static function get_attachment($announcement_id)
  920. {
  921. $tbl_announcement_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
  922. $announcement_id = intval($announcement_id);
  923. $course_id = api_get_course_int_id();
  924. $row = array();
  925. $sql = 'SELECT id, path, filename, comment FROM '.$tbl_announcement_attachment.'
  926. WHERE c_id = '.$course_id.' AND announcement_id = '.$announcement_id.'';
  927. $result = Database::query($sql);
  928. if (Database::num_rows($result) != 0) {
  929. $row = Database::fetch_array($result, 'ASSOC');
  930. }
  931. return $row;
  932. }
  933. /**
  934. * This function add a attachment file into announcement
  935. * @param int announcement id
  936. * @param string file comment
  937. * @param array uploaded file $_FILES
  938. * @return int -1 if failed, 0 if unknown (should not happen), 1 if success
  939. */
  940. public static function add_announcement_attachment_file($announcement_id, $file_comment, $file)
  941. {
  942. global $_course;
  943. $tbl_announcement_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
  944. $return = 0;
  945. $announcement_id = intval($announcement_id);
  946. $course_id = api_get_course_int_id();
  947. if (is_array($file) && $file['error'] == 0) {
  948. $courseDir = $_course['path'].'/upload/announcements'; // TODO: This path is obsolete. The new document repository scheme should be kept in mind here.
  949. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  950. $updir = $sys_course_path.$courseDir;
  951. // Try to add an extension to the file if it hasn't one
  952. $new_file_name = add_ext_on_mime(stripslashes($file['name']), $file['type']);
  953. // user's file name
  954. $file_name = $file['name'];
  955. if (!filter_extension($new_file_name)) {
  956. $return = -1;
  957. Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
  958. } else {
  959. $new_file_name = uniqid('');
  960. $new_path = $updir.'/'.$new_file_name;
  961. $result = @move_uploaded_file($file['tmp_name'], $new_path);
  962. $safe_file_comment = Database::escape_string($file_comment);
  963. $safe_file_name = Database::escape_string($file_name);
  964. $safe_new_file_name = Database::escape_string($new_file_name);
  965. // Storing the attachments if any
  966. $sql = "INSERT INTO $tbl_announcement_attachment (c_id, filename, comment, path, announcement_id, size) VALUES
  967. ($course_id, '$safe_file_name', '$file_comment', '$safe_new_file_name' , '$announcement_id', '".intval($file['size'])."' )";
  968. Database::query($sql);
  969. $return = 1;
  970. }
  971. }
  972. return $return;
  973. }
  974. /**
  975. * This function edit a attachment file into announcement
  976. * @param int attach id
  977. * @param array uploaded file $_FILES
  978. * @param string file comment
  979. * @return int
  980. */
  981. public static function edit_announcement_attachment_file($id_attach, $file, $file_comment)
  982. {
  983. global $_course;
  984. $tbl_announcement_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
  985. $return = 0;
  986. $course_id = api_get_course_int_id();
  987. if (is_array($file) && $file['error'] == 0) {
  988. $courseDir = $_course['path'].'/upload/announcements'; // TODO: This path is obsolete. The new document repository scheme should be kept in mind here.
  989. $sys_course_path = api_get_path(SYS_COURSE_PATH);
  990. $updir = $sys_course_path.$courseDir;
  991. // Try to add an extension to the file if it hasn't one
  992. $new_file_name = add_ext_on_mime(stripslashes($file['name']), $file['type']);
  993. // user's file name
  994. $file_name = $file ['name'];
  995. if (!filter_extension($new_file_name)) {
  996. $return - 1;
  997. Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
  998. } else {
  999. $new_file_name = uniqid('');
  1000. $new_path = $updir.'/'.$new_file_name;
  1001. $result = @move_uploaded_file($file['tmp_name'], $new_path);
  1002. $safe_file_comment = Database::escape_string($file_comment);
  1003. $safe_file_name = Database::escape_string($file_name);
  1004. $safe_new_file_name = Database::escape_string($new_file_name);
  1005. $id_attach = intval($id_attach);
  1006. $sql = "UPDATE $tbl_announcement_attachment SET filename = '$safe_file_name', comment = '$safe_file_comment', path = '$safe_new_file_name', size ='".intval($file['size'])."'
  1007. WHERE c_id = $course_id AND id = '$id_attach'";
  1008. $result = Database::query($sql);
  1009. if ($result === false) {
  1010. $return = -1;
  1011. Display :: display_error_message(get_lang('UplUnableToSaveFile'));
  1012. } else {
  1013. $return = 1;
  1014. }
  1015. }
  1016. }
  1017. return $return;
  1018. }
  1019. /**
  1020. * This function delete a attachment file by id
  1021. * @param integer attachment file Id
  1022. *
  1023. */
  1024. public static function delete_announcement_attachment_file($id)
  1025. {
  1026. $tbl_announcement_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
  1027. $id = intval($id);
  1028. $course_id = api_get_course_int_id();
  1029. $sql = "DELETE FROM $tbl_announcement_attachment WHERE c_id = $course_id AND id = $id";
  1030. Database::query($sql);
  1031. // update item_property
  1032. //api_item_property_update($_course, 'announcement_attachment', $id,'AnnouncementAttachmentDeleted', api_get_user_id());
  1033. }
  1034. public static function send_email($annoucement_id)
  1035. {
  1036. $email = AnnouncementEmail::create(null, $annoucement_id);
  1037. $email->send();
  1038. }
  1039. public static function user_can_edit_announcement() {
  1040. $group_id = api_get_group_id();
  1041. return api_is_allowed_to_edit(false, true) OR
  1042. (api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous()) OR
  1043. (!empty($group_id) AND GroupManager::user_has_access(api_get_user_id(), $group_id, GroupManager::GROUP_TOOL_ANNOUNCEMENT) AND GroupManager::is_tutor_of_group(api_get_user_id(), $group_id));
  1044. }
  1045. }
  1046. //end class