announcements.inc.php 42 KB

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