glossary.lib.php 24 KB

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