announcements.inc.php 43 KB

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