glossary.lib.php 24 KB

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