glossary.lib.php 25 KB

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