glossary.lib.php 24 KB

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