glossary.lib.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This library provides functions for the glossary tool.
  5. * Include/require it in your code to use its functionality.
  6. * @package chamilo.library
  7. */
  8. /**
  9. * Class
  10. * @package chamilo.library
  11. */
  12. class GlossaryManager {
  13. /**
  14. * Get all glossary terms
  15. * @author Isaac Flores <isaac.flores@dokeos.com>
  16. * @return Array Contain glossary terms
  17. */
  18. public static function get_glossary_terms () {
  19. global $course;
  20. $glossary_data = array();
  21. $glossary_table = Database::get_course_table(TABLE_GLOSSARY);
  22. $session_id = intval($session_id);
  23. $sql_filter = api_get_session_condition($session_id);
  24. $course_id = api_get_course_int_id();
  25. $sql = "SELECT glossary_id as id, name, description FROM $glossary_table WHERE c_id = $course_id $sql_filter";
  26. $rs = Database::query($sql);
  27. while ($row = Database::fetch_array($rs)) {
  28. $glossary_data[] = $row;
  29. }
  30. return $glossary_data;
  31. }
  32. /**
  33. * Get glossary term by glossary id
  34. * @author Isaac Flores <florespaz@bidsoftperu.com>
  35. * @param Integer The glossary id
  36. * @return String The glossary description
  37. */
  38. public static function get_glossary_term_by_glossary_id ($glossary_id) {
  39. global $course;
  40. $glossary_table = Database::get_course_table(TABLE_GLOSSARY);
  41. $course_id = api_get_course_int_id();
  42. $sql = "SELECT description FROM $glossary_table WHERE c_id = $course_id AND glossary_id =".Database::escape_string($glossary_id);
  43. $rs=Database::query($sql);
  44. if (Database::num_rows($rs) > 0) {
  45. $row = Database::fetch_array($rs);
  46. return $row['description'];
  47. } else {
  48. return '';
  49. }
  50. }
  51. /**
  52. * Get glossary term by glossary id
  53. * @author Isaac Flores <florespaz_isaac@hotmail.com>
  54. * @param String The glossary term name
  55. * @return String The glossary description
  56. */
  57. public static function get_glossary_term_by_glossary_name ($glossary_name) {
  58. global $course;
  59. $glossary_table = Database::get_course_table(TABLE_GLOSSARY);
  60. $session_id = intval($session_id);
  61. $course_id = api_get_course_int_id();
  62. $sql_filter = api_get_session_condition($session_id);
  63. $sql = 'SELECT description FROM '.$glossary_table.' WHERE c_id = '.$course_id.' AND name LIKE trim("'.Database::escape_string($glossary_name).'")'.$sql_filter;
  64. $rs = Database::query($sql);
  65. if (Database::num_rows($rs) > 0) {
  66. $row = Database::fetch_array($rs);
  67. return $row['description'];
  68. } else {
  69. return '';
  70. }
  71. }
  72. /**
  73. * This functions stores the glossary in the database
  74. *
  75. * @param array Array of title + description (glossary_title => $title, glossary_comment => $comment)
  76. * @return mixed Term id on success, false on failure
  77. * @author Christian Fasanando <christian.fasanando@dokeos.com>
  78. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
  79. * @version januari 2009, dokeos 1.8.6
  80. */
  81. function save_glossary($values, $message = true) {
  82. if (!is_array($values) or !isset($values['glossary_title'])) {
  83. return false;
  84. }
  85. // Database table definition
  86. $t_glossary = Database :: get_course_table(TABLE_GLOSSARY);
  87. // get the maximum display order of all the glossary items
  88. $max_glossary_item = GlossaryManager::get_max_glossary_item();
  89. // session_id
  90. $session_id = api_get_session_id();
  91. // check if the glossary term already exists
  92. if (GlossaryManager::glossary_exists($values['glossary_title'])) {
  93. // display the feedback message
  94. if ($message)
  95. Display::display_error_message(get_lang('GlossaryTermAlreadyExistsYouShouldEditIt'));
  96. return false;
  97. } else {
  98. $sql = "INSERT INTO $t_glossary (c_id, name, description, display_order, session_id)
  99. VALUES(
  100. ".api_get_course_int_id().",
  101. '".Database::escape_string($values['glossary_title'])."',
  102. '".Database::escape_string($values['glossary_comment'])."',
  103. '".(int)($max_glossary_item + 1)."',
  104. '".Database::escape_string($session_id)."'
  105. )";
  106. $result = Database::query($sql);
  107. if ($result === false) { return false; }
  108. $id = Database::insert_id();
  109. //insert into item_property
  110. api_item_property_update(api_get_course_info(), TOOL_GLOSSARY, $id, 'GlossaryAdded', api_get_user_id());
  111. $_SESSION['max_glossary_display'] = GlossaryManager::get_max_glossary_item();
  112. // display the feedback message
  113. if ($message)
  114. Display::display_confirmation_message(get_lang('TermAdded'));
  115. return $id;
  116. }
  117. }
  118. /**
  119. * update the information of a glossary term in the database
  120. *
  121. * @param array $values an array containing all the form elements
  122. * @return boolean True on success, false on failure
  123. * @author Christian Fasanando <christian.fasanando@dokeos.com>
  124. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
  125. * @version januari 2009, dokeos 1.8.6
  126. */
  127. function update_glossary($values, $message = true) {
  128. // Database table definition
  129. $t_glossary = Database :: get_course_table(TABLE_GLOSSARY);
  130. $course_id = api_get_course_int_id();
  131. // check if the glossary term already exists
  132. if (GlossaryManager::glossary_exists($values['glossary_title'],$values['glossary_id'])) {
  133. // display the feedback message
  134. if ($message)
  135. Display::display_error_message(get_lang('GlossaryTermAlreadyExistsYouShouldEditIt'));
  136. return false;
  137. } else {
  138. $sql = "UPDATE $t_glossary SET
  139. name = '".Database::escape_string($values['glossary_title'])."',
  140. description = '".Database::escape_string($values['glossary_comment'])."'
  141. WHERE c_id = $course_id AND glossary_id = ".Database::escape_string($values['glossary_id']);
  142. $result = Database::query($sql);
  143. if ($result === false) { return false; }
  144. //update glossary into item_property
  145. api_item_property_update(api_get_course_info(), TOOL_GLOSSARY, Database::escape_string($values['glossary_id']), 'GlossaryUpdated', api_get_user_id());
  146. // display the feedback message
  147. if ($message)
  148. Display::display_confirmation_message(get_lang('TermUpdated'));
  149. }
  150. return true;
  151. }
  152. /**
  153. * Get the maximum display order of the glossary item
  154. * @return integer Maximum glossary display order
  155. * @author Christian Fasanando <christian.fasanando@dokeos.com>
  156. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
  157. * @version januari 2009, dokeos 1.8.6
  158. */
  159. function get_max_glossary_item() {
  160. // Database table definition
  161. $t_glossary = Database :: get_course_table(TABLE_GLOSSARY);
  162. $course_id = api_get_course_int_id();
  163. $get_max = "SELECT MAX(display_order) FROM $t_glossary WHERE c_id = $course_id ";
  164. $res_max = Database::query($get_max);
  165. if (Database::num_rows($res_max)==0) {
  166. return 0;
  167. }
  168. $row = Database::fetch_array($res_max);
  169. if (!empty($row[0])) {
  170. return $row[0];
  171. }
  172. return 0;
  173. }
  174. /**
  175. * check if the glossary term exists or not
  176. *
  177. * @param string Term to look for
  178. * @param integer ID to counter-check if the term exists with this ID as well (optional)
  179. * @return bool True if term exists
  180. *
  181. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
  182. * @version januari 2009, dokeos 1.8.6
  183. */
  184. function glossary_exists($term,$not_id='') {
  185. // Database table definition
  186. $t_glossary = Database :: get_course_table(TABLE_GLOSSARY);
  187. $course_id = api_get_course_int_id();
  188. $sql = "SELECT name FROM $t_glossary WHERE c_id = $course_id AND name = '".Database::escape_string($term)."'";
  189. if ($not_id<>'') {
  190. $sql .= " AND glossary_id <> '".Database::escape_string($not_id)."'";
  191. }
  192. $result = Database::query($sql);
  193. $count = Database::num_rows($result);
  194. if ($count > 0) {
  195. return true;
  196. } else {
  197. return false;
  198. }
  199. }
  200. /**
  201. * Get one specific glossary term data
  202. *
  203. * @param integer ID of the flossary term
  204. * @return mixed Array(glossary_id,glossary_title,glossary_comment,glossary_display_order) or false on error
  205. *
  206. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
  207. */
  208. static function get_glossary_information($glossary_id) {
  209. // Database table definition
  210. $t_glossary = Database :: get_course_table(TABLE_GLOSSARY);
  211. $t_item_propery = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  212. if (empty($glossary_id)) { return false; }
  213. $sql = "SELECT g.glossary_id as glossary_id,
  214. g.name as glossary_title,
  215. g.description as glossary_comment,
  216. g.display_order as glossary_display_order,
  217. ip.insert_date as insert_date,
  218. ip.lastedit_date as update_date,
  219. g.session_id
  220. FROM $t_glossary g, $t_item_propery ip
  221. WHERE g.glossary_id = ip.ref AND
  222. tool = '".TOOL_GLOSSARY."' AND
  223. g.glossary_id = '".intval($glossary_id)."' AND
  224. g.c_id = ".api_get_course_int_id()." AND
  225. ip.c_id = ".api_get_course_int_id()."
  226. ";
  227. $result = Database::query($sql);
  228. if ($result === false || Database::num_rows($result) != 1) {
  229. return false;
  230. }
  231. return Database::fetch_array($result);
  232. }
  233. /**
  234. * Delete a glossary term (and re-order all the others)
  235. *
  236. * @param integer The id of the glossary term to delete
  237. * @return bool True on success, false on failure
  238. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
  239. * @version januari 2009, dokeos 1.8.6
  240. */
  241. function delete_glossary($glossary_id, $message = true) {
  242. // Database table definition
  243. $t_glossary = Database :: get_course_table(TABLE_GLOSSARY);
  244. $course_id = api_get_course_int_id();
  245. if (empty($glossary_id)) { return false; }
  246. $sql = "DELETE FROM $t_glossary WHERE c_id = $course_id AND glossary_id='".Database::escape_string($glossary_id)."'";
  247. $result = Database::query($sql);
  248. if ($result === false or Database::affected_rows() < 1) { return false; }
  249. //update item_property (delete)
  250. api_item_property_update(api_get_course_info(), TOOL_GLOSSARY, Database::escape_string($glossary_id), 'delete', api_get_user_id());
  251. // reorder the remaining terms
  252. GlossaryManager::reorder_glossary();
  253. $_SESSION['max_glossary_display'] = GlossaryManager::get_max_glossary_item();
  254. if ($message)
  255. Display::display_confirmation_message(get_lang('TermDeleted'));
  256. return true;
  257. }
  258. /**
  259. * This is the main function that displays the list or the table with all
  260. * the glossary terms
  261. * @param string View ('table' or 'list'). Optional parameter. Defaults to 'table' and prefers glossary_view from the session by default.
  262. * @return void
  263. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
  264. * @version januari 2009, dokeos 1.8.6
  265. */
  266. static function display_glossary($view = 'table') {
  267. // This function should always be called with the corresponding
  268. // parameter for view type. Meanwhile, use this cheap trick.
  269. if (empty($_SESSION['glossary_view'])) {
  270. $_SESSION['glossary_view'] = $view;
  271. }
  272. // action links
  273. echo '<div class="actions">';
  274. if (api_is_allowed_to_edit(null,true)) {
  275. echo '<a href="index.php?'.api_get_cidreq().'&action=addglossary&msg=add">'.Display::return_icon('new_glossary_term.png',get_lang('TermAddNew'),'','32').'</a>';
  276. }
  277. echo '<a href="index.php?'.api_get_cidreq().'&action=export">'.Display::return_icon('export_csv.png',get_lang('ExportGlossaryAsCSV'),'','32').'</a>';
  278. if (api_is_allowed_to_edit(null,true)) {
  279. echo '<a href="index.php?'.api_get_cidreq().'&action=import">'.Display::return_icon('import_csv.png',get_lang('ImportGlossary'),'','32').'</a>';
  280. }
  281. echo '<a href="index.php?'.api_get_cidreq().'&action=export_to_pdf">'.Display::return_icon('pdf.png',get_lang('ExportToPDF'),'', ICON_SIZE_MEDIUM).'</a>';
  282. if ((isset($_SESSION['glossary_view']) && $_SESSION['glossary_view'] == 'table') or (!isset($_SESSION['glossary_view']))){
  283. echo '<a href="index.php?'.api_get_cidreq().'&action=changeview&view=list">'.Display::return_icon('view_detailed.png',get_lang('ListView'),'','32').'</a>';
  284. } else {
  285. echo '<a href="index.php?'.api_get_cidreq().'&action=changeview&view=table">'.Display::return_icon('view_text.png',get_lang('TableView'),'','32').'</a>';
  286. }
  287. echo '</div>';
  288. if (!$_SESSION['glossary_view'] OR $_SESSION['glossary_view'] == 'table') {
  289. $table = new SortableTable('glossary', array('GlossaryManager','get_number_glossary_terms'), array('GlossaryManager','get_glossary_data'),0);
  290. //$table->set_header(0, '', false);
  291. $table->set_header(0, get_lang('TermName'), true);
  292. $table->set_header(1, get_lang('TermDefinition'), true);
  293. if (api_is_allowed_to_edit(null,true)) {
  294. $table->set_header(2, get_lang('Actions'), false, 'width=90px', array('class' => 'td_actions'));
  295. $table->set_column_filter(2, array('GlossaryManager','actions_filter'));
  296. }
  297. $table->display();
  298. }
  299. if ($_SESSION['glossary_view'] == 'list') {
  300. GlossaryManager::display_glossary_list();
  301. }
  302. }
  303. /**
  304. * Display the glossary terms in a list
  305. * @return bool True
  306. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
  307. * @version januari 2009, dokeos 1.8.6
  308. */
  309. function display_glossary_list() {
  310. $glossary_data = self::get_glossary_data(0,1000,0,'ASC');
  311. foreach($glossary_data as $key=>$glossary_item) {
  312. echo '<div class="sectiontitle">'.$glossary_item[0].'</div>';
  313. echo '<div class="sectioncomment">'.$glossary_item[1].'</div>';
  314. if (api_is_allowed_to_edit(null,true)) {
  315. echo '<div>'.self::actions_filter($glossary_item[2], '',$glossary_item).'</div>';
  316. }
  317. }
  318. return true;
  319. }
  320. /**
  321. * Get the number of glossary terms in the course (or course+session)
  322. * @param int Session ID filter (optional)
  323. * @return integer Count of glossary terms
  324. *
  325. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
  326. * @version januari 2009, dokeos 1.8.6
  327. */
  328. static function get_number_glossary_terms($session_id=0) {
  329. // Database table definition
  330. $t_glossary = Database :: get_course_table(TABLE_GLOSSARY);
  331. $course_id = api_get_course_int_id();
  332. $session_id = intval($session_id);
  333. $sql_filter = api_get_session_condition($session_id, true, true);
  334. $sql = "SELECT count(glossary_id) as total FROM $t_glossary WHERE c_id = $course_id $sql_filter";
  335. $res = Database::query($sql);
  336. if ($res === false) { return 0; }
  337. $obj = Database::fetch_object($res);
  338. return $obj->total;
  339. }
  340. /**
  341. * Get all the data of a glossary
  342. *
  343. * @param integer From which item
  344. * @param integer Number of items to collect
  345. * @param string Name of column on which to order
  346. * @param string Whether to sort in ascending (ASC) or descending (DESC)
  347. * @return unknown
  348. *
  349. * @author Patrick Cool <patrick.cool@ugent.be>
  350. * @author Julio Montoya fixing this function, adding intvals
  351. * @version januari 2009, dokeos 1.8.6
  352. */
  353. static function get_glossary_data($from, $number_of_items, $column, $direction) {
  354. global $_user;
  355. // Database table definition
  356. $t_glossary = Database :: get_course_table(TABLE_GLOSSARY);
  357. $t_item_propery = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  358. if (api_is_allowed_to_edit(null,true)) {
  359. $col2 = " glossary.glossary_id as col2, ";
  360. } else {
  361. $col2 = " ";
  362. }
  363. //condition for the session
  364. $session_id = api_get_session_id();
  365. $condition_session = api_get_session_condition($session_id, true, true);
  366. $column = intval($column);
  367. if (!in_array($direction,array('DESC', 'ASC'))) {
  368. $direction = 'ASC';
  369. }
  370. $from = intval($from);
  371. $number_of_items = intval($number_of_items);
  372. $sql = "SELECT glossary.name as col0,
  373. glossary.description as col1,
  374. $col2
  375. glossary.session_id as session_id
  376. FROM $t_glossary glossary, $t_item_propery ip
  377. WHERE glossary.glossary_id = ip.ref AND
  378. tool = '".TOOL_GLOSSARY."' $condition_session AND
  379. glossary.c_id = ".api_get_course_int_id()." AND
  380. ip.c_id = ".api_get_course_int_id()."
  381. ORDER BY col$column $direction
  382. LIMIT $from,$number_of_items";
  383. $res = Database::query($sql);
  384. $return = array();
  385. $array = array();
  386. while ($data = Database::fetch_array($res)) {
  387. //validacion when belongs to a session
  388. $session_img = api_get_session_image($data['session_id'], $_user['status']);
  389. $array[0] = $data[0] . $session_img;
  390. if (!$_SESSION['glossary_view'] || $_SESSION['glossary_view'] == 'table') {
  391. $array[1] = str_replace(array('<p>','</p>'),array('','<br />'),$data[1]);
  392. } else {
  393. $array[1] = $data[1];
  394. }
  395. if (api_is_allowed_to_edit(null,true)) {
  396. // Date treatment for timezones
  397. /*if (!empty($data[2]) && $data[2] != '0000-00-00 00:00:00:') {
  398. $array[2] = api_get_local_time($data[2], null, date_default_timezone_get());
  399. }
  400. if (!empty($data[3]) && $data[3] != '0000-00-00 00:00:00:') {
  401. $array[3] = api_get_local_time($data[3], null, date_default_timezone_get());
  402. }*/
  403. $array[2] = $data[2];
  404. }
  405. $return[] = $array;
  406. }
  407. return $return;
  408. }
  409. /**
  410. * Update action icons column
  411. *
  412. * @param integer $glossary_id
  413. * @param array Parameters to use to affect links
  414. * @param array The line of results from a query on the glossary table
  415. * @return string HTML string for the action icons columns
  416. *
  417. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
  418. * @version januari 2009, dokeos 1.8.6
  419. */
  420. static function actions_filter($glossary_id, $url_params, $row) {
  421. $glossary_id = $row[2];
  422. $return = '<a href="'.api_get_self().'?action=edit_glossary&amp;glossary_id='.$glossary_id.'&'.api_get_cidreq().'&msg=edit">'.Display::return_icon('edit.png',get_lang('Edit'),'',22).'</a>';
  423. $glossary_data = GlossaryManager::get_glossary_information($glossary_id);
  424. $glossary_term = $glossary_data['glossary_title'];
  425. if (api_is_allowed_to_edit(null, true)) {
  426. if ($glossary_data['session_id'] == api_get_session_id()) {
  427. $return .= '<a href="'.api_get_self().'?action=delete_glossary&amp;glossary_id='.$glossary_id.'&'.api_get_cidreq().'" onclick="return confirmation(\''.$glossary_term.'\');">'.Display::return_icon('delete.png', get_lang('Delete'),'',22).'</a>';
  428. } else {
  429. $return = get_lang('EditionNotAvailableFromSession');
  430. }
  431. }
  432. return $return;
  433. }
  434. /**
  435. * a little bit of javascript to display a prettier warning when deleting a term
  436. *
  437. * @return string HTML string including JavaScript
  438. *
  439. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
  440. * @version januari 2009, dokeos 1.8.6
  441. */
  442. static function javascript_glossary() {
  443. return "<script type=\"text/javascript\">
  444. function confirmation (name) {
  445. if (confirm(\" ". get_lang("TermConfirmDelete") ." \"+ name + \" ?\"))
  446. {return true;}
  447. else
  448. {return false;}
  449. }
  450. </script>";
  451. }
  452. /**
  453. * Re-order glossary
  454. *
  455. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
  456. * @version januari 2009, dokeos 1.8.6
  457. */
  458. function reorder_glossary() {
  459. // Database table definition
  460. $t_glossary = Database :: get_course_table(TABLE_GLOSSARY);
  461. $course_id = api_get_course_int_id();
  462. $sql = "SELECT * FROM $t_glossary WHERE c_id = $course_id ORDER by display_order ASC";
  463. $res = Database::query($sql);
  464. $i = 1;
  465. while ($data = Database::fetch_array($res)) {
  466. $sql_reorder = "UPDATE $t_glossary SET display_order = $i
  467. WHERE c_id = $course_id AND glossary_id = '".Database::escape_string($data['glossary_id'])."'";
  468. Database::query($sql_reorder);
  469. $i++;
  470. }
  471. }
  472. /**
  473. * Move a glossary term
  474. *
  475. * @param unknown_type $direction
  476. * @param unknown_type $glossary_id
  477. *
  478. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
  479. * @version januari 2009, dokeos 1.8.6
  480. */
  481. function move_glossary($direction, $glossary_id, $message = true) {
  482. // Database table definition
  483. $t_glossary = Database :: get_course_table(TABLE_GLOSSARY);
  484. // sort direction
  485. if ($direction == 'up') {
  486. $sortorder = 'DESC';
  487. } else {
  488. $sortorder = 'ASC';
  489. }
  490. $course_id = api_get_course_int_id();
  491. $sql = "SELECT * FROM $t_glossary WHERE c_id = $course_id ORDER BY display_order $sortorder";
  492. $res = Database::query($sql);
  493. $found = false;
  494. while ($row = Database::fetch_array($res)) {
  495. if ($found && empty($next_id)) {
  496. $next_id = $row['glossary_id'];
  497. $next_display_order = $row['display_order'];
  498. }
  499. if ($row['glossary_id'] == $glossary_id) {
  500. $current_id = $glossary_id;
  501. $current_display_order = $row['display_order'];
  502. $found = true;
  503. }
  504. }
  505. $sql1 = "UPDATE $t_glossary SET display_order = '".Database::escape_string($next_display_order)."' WHERE c_id = $course_id AND glossary_id = '".Database::escape_string($current_id)."'";
  506. $sql2 = "UPDATE $t_glossary SET display_order = '".Database::escape_string($current_display_order)."' WHERE c_id = $course_id AND glossary_id = '".Database::escape_string($next_id)."'";
  507. $res = Database::query($sql1);
  508. $res = Database::query($sql2);
  509. if ($message)
  510. Display::display_confirmation_message(get_lang('TermMoved'));
  511. }
  512. static function export_to_pdf() {
  513. $data = GlossaryManager::get_glossary_data(0, GlossaryManager::get_number_glossary_terms(api_get_session_id()), 0, 'ASC');
  514. $html = '<html><body>';
  515. $html .= '<h2>'.get_lang('Glossary').'</h2><hr><br><br>';
  516. foreach ($data as $item) {
  517. $term = $item[0];
  518. $description = $item[1];
  519. $html .= '<h4>'.$term.'</h4><p>'.$description.'<p><hr>';
  520. }
  521. $html .= '</body></html>';
  522. $course_code = api_get_course_id();
  523. $pdf = new PDF();
  524. //$pdf->set_custom_header($title);
  525. /*$css_file = api_get_path(SYS_CODE_PATH).'css/print.css';
  526. if (file_exists($css_file)) {
  527. $css = @file_get_contents($css_file);
  528. } else {
  529. $css = '';
  530. }*/
  531. $pdf->content_to_pdf($html, $css, get_lang('Glossary').'_'.$course_code, $course_code);
  532. }
  533. }