glossary.lib.php 25 KB

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