index.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. <?php //$id: $
  2. /* For licensing terms, see /dokeos_license.txt */
  3. /**
  4. * @package dokeos.glossary
  5. * @author Christian Fasanando, initial version
  6. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium, refactoring and tighter integration in Dokeos
  7. */
  8. // name of the language file that needs to be included
  9. $language_file = array('glossary');
  10. // including the global dokeos file
  11. require_once('../inc/global.inc.php');
  12. // the section (tabs)
  13. $this_section=SECTION_COURSES;
  14. // notice for unauthorized people.
  15. api_protect_course_script(true);
  16. // including additional libraries
  17. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  18. // additional javascript
  19. $htmlHeadXtra[] = javascript_glossary();
  20. // setting the tool constants
  21. $tool = TOOL_GLOSSARY;
  22. // tracking
  23. event_access_tool(TOOL_GLOSSARY);
  24. // displaying the header
  25. if (isset($_GET['action']) && ($_GET['action'] == 'addglossary' || $_GET['action'] == 'edit_glossary')) {
  26. $tool='GlossaryManagement';
  27. $interbreadcrumb[] = array ("url"=>"index.php", "name"=> get_lang('Glossary'));
  28. }
  29. Display::display_header(get_lang(ucfirst($tool)));
  30. // Tool introduction
  31. Display::display_introduction_section(TOOL_GLOSSARY);
  32. if ($_GET['action'] == 'changeview' AND in_array($_GET['view'],array('list','table'))) {
  33. $_SESSION['glossary_view'] = $_GET['view'];
  34. } else {
  35. if (!isset($_SESSION['glossary_view'])) {
  36. $_SESSION['glossary_view'] = 'table';//Default option
  37. }
  38. }
  39. if (api_is_allowed_to_edit(null,true)) {
  40. // Adding a glossary
  41. if (isset($_GET['action']) && $_GET['action'] == 'addglossary') {
  42. // initiate the object
  43. $form = new FormValidator('glossary','post', api_get_self().'?action='.Security::remove_XSS($_GET['action']));
  44. // settting the form elements
  45. $form->addElement('header', '', get_lang('TermAddNew'));
  46. $form->addElement('text', 'glossary_title', get_lang('TermName'), array('size'=>'95'));
  47. //$form->applyFilter('glossary_title', 'html_filter');
  48. $form->addElement('html_editor', 'glossary_comment', get_lang('TermDefinition'), null, array('ToolbarSet' => 'Glossary', 'Width' => '100%', 'Height' => '300'));
  49. $form->addElement('style_submit_button', 'SubmitGlossary', get_lang('TermAddButton'), 'class="save"');
  50. // setting the rules
  51. $form->addRule('glossary_title', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
  52. // The validation or display
  53. if ($form->validate()) {
  54. $check = Security::check_token('post');
  55. if ($check) {
  56. $values = $form->exportValues();
  57. save_glossary($values);
  58. }
  59. Security::clear_token();
  60. display_glossary();
  61. } else {
  62. $token = Security::get_token();
  63. $form->addElement('hidden','sec_token');
  64. $form->setConstants(array('sec_token' => $token));
  65. $form->display();
  66. }
  67. } else if (isset($_GET['action']) && $_GET['action'] == 'edit_glossary' && is_numeric($_GET['glossary_id'])) { // Editing a glossary
  68. // initiate the object
  69. $form = new FormValidator('glossary','post', api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&glossary_id='.Security::remove_XSS($_GET['glossary_id']));
  70. // settting the form elements
  71. $form->addElement('header', '', get_lang('TermEdit'));
  72. $form->addElement('hidden', 'glossary_id');
  73. $form->addElement('text', 'glossary_title', get_lang('TermName'),array('size'=>'100'));
  74. //$form->applyFilter('glossary_title', 'html_filter');
  75. $form->addElement('html_editor', 'glossary_comment', get_lang('TermDefinition'), null, array('ToolbarSet' => 'Glossary', 'Width' => '100%', 'Height' => '300'));
  76. $form->addElement('style_submit_button', 'SubmitGlossary', get_lang('TermUpdateButton'), 'class="save"');
  77. // setting the defaults
  78. $defaults = get_glossary_information(Security::remove_XSS($_GET['glossary_id']));
  79. $form->setDefaults($defaults);
  80. // setting the rules
  81. $form->addRule('glossary_title', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
  82. // The validation or display
  83. if ($form->validate()) {
  84. $check = Security::check_token('post');
  85. if ($check) {
  86. $values = $form->exportValues();
  87. update_glossary($values);
  88. }
  89. Security::clear_token();
  90. display_glossary();
  91. } else {
  92. $token = Security::get_token();
  93. $form->addElement('hidden','sec_token');
  94. $form->setConstants(array('sec_token' => $token));
  95. $form->display();
  96. }
  97. } else if (isset($_GET['action']) && $_GET['action'] == 'delete_glossary' && is_numeric($_GET['glossary_id'])) {// deleting a glossary
  98. delete_glossary(Security::remove_XSS($_GET['glossary_id']));
  99. display_glossary();
  100. } else if (isset($_GET['action']) && $_GET['action'] == 'moveup' && is_numeric($_GET['glossary_id'])) { // moving a glossary term up
  101. move_glossary('up',$_GET['glossary_id']);
  102. display_glossary();
  103. } else if (isset($_GET['action']) && $_GET['action'] == 'movedown' && is_numeric($_GET['glossary_id'])) {// moving a glossary term up
  104. move_glossary('down',$_GET['glossary_id']);
  105. display_glossary();
  106. } else {
  107. display_glossary();
  108. }
  109. } else {
  110. display_glossary();
  111. }
  112. // footer
  113. Display::display_footer();
  114. /**
  115. * This functions stores the glossary in the database
  116. *
  117. * @param unknown_type $values
  118. *
  119. * @author Christian Fasanando <christian.fasanando@dokeos.com>
  120. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
  121. * @version januari 2009, dokeos 1.8.6
  122. */
  123. function save_glossary($values)
  124. {
  125. // Database table definition
  126. $t_glossary = Database :: get_course_table(TABLE_GLOSSARY);
  127. // get the maximum display order of all the glossary items
  128. $max_glossary_item = get_max_glossary_item();
  129. // session_id
  130. $session_id = api_get_session_id();
  131. // check if the glossary term already exists
  132. if (glossary_exists($values['glossary_title']))
  133. {
  134. // display the feedback message
  135. Display::display_error_message('GlossaryTermAlreadyExistsYouShouldEditIt');
  136. } else {
  137. $sql = "INSERT INTO $t_glossary (name, description, display_order, session_id)
  138. VALUES(
  139. '".Database::escape_string(Security::remove_XSS($values['glossary_title']))."',
  140. '".Database::escape_string(Security::remove_XSS(stripslashes(api_html_entity_decode($values['glossary_comment'])),COURSEMANAGERLOWSECURITY))."',
  141. '".(int)($max_glossary_item + 1)."',
  142. '".Database::escape_string($session_id)."'
  143. )";
  144. $result = Database::query($sql, __FILE__, __LINE__);
  145. $id = Database::insert_id();
  146. if ($id>0) {
  147. //insert into item_property
  148. api_item_property_update(api_get_course_info(), TOOL_GLOSSARY, $id, 'GlossaryAdded', api_get_user_id());
  149. }
  150. $_SESSION['max_glossary_display'] = get_max_glossary_item();
  151. // display the feedback message
  152. Display::display_confirmation_message(get_lang('TermAdded'));
  153. }
  154. }
  155. /**
  156. * update the information of a glossary term in the database
  157. *
  158. * @param array $values an array containing all the form elements
  159. *
  160. * @author Christian Fasanando <christian.fasanando@dokeos.com>
  161. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
  162. * @version januari 2009, dokeos 1.8.6
  163. */
  164. function update_glossary($values)
  165. {
  166. // Database table definition
  167. $t_glossary = Database :: get_course_table(TABLE_GLOSSARY);
  168. // check if the glossary term already exists
  169. if (glossary_exists($values['glossary_title'],$values['glossary_id']))
  170. {
  171. // display the feedback message
  172. Display::display_error_message('GlossaryTermAlreadyExistsYouShouldEditIt');
  173. }
  174. else
  175. {
  176. $sql = "UPDATE $t_glossary SET
  177. name = '".Database::escape_string(Security::remove_XSS($values['glossary_title']))."',
  178. description = '".Database::escape_string(Security::remove_XSS(stripslashes(api_html_entity_decode($values['glossary_comment'])),COURSEMANAGERLOWSECURITY))."'
  179. WHERE glossary_id = ".Database::escape_string($values['glossary_id']);
  180. $result = Database::query($sql, __FILE__, __LINE__);
  181. //update glossary into item_property
  182. api_item_property_update(api_get_course_info(), TOOL_GLOSSARY, Database::escape_string($values['glossary_id']), 'GlossaryUpdated', api_get_user_id());
  183. // display the feedback message
  184. Display::display_confirmation_message(get_lang('TermUpdated'));
  185. }
  186. }
  187. /**
  188. * Get the maximum display order of the glossary item
  189. *
  190. * @author Christian Fasanando <christian.fasanando@dokeos.com>
  191. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
  192. * @version januari 2009, dokeos 1.8.6
  193. */
  194. function get_max_glossary_item()
  195. {
  196. // Database table definition
  197. $t_glossary = Database :: get_course_table(TABLE_GLOSSARY);
  198. $get_max = "SELECT MAX(display_order) FROM $t_glossary";
  199. $res_max = Database::query($get_max, __FILE__, __LINE__);
  200. $dsp=0;
  201. $row = Database::fetch_array($res_max);
  202. return $row[0];
  203. }
  204. /**
  205. * check if the glossary term exists or not
  206. *
  207. * @param unknown_type $term
  208. * @param unknown_type $not_id
  209. * @return unknown
  210. *
  211. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
  212. * @version januari 2009, dokeos 1.8.6
  213. */
  214. function glossary_exists($term,$not_id='')
  215. {
  216. // Database table definition
  217. $t_glossary = Database :: get_course_table(TABLE_GLOSSARY);
  218. $sql = "SELECT name FROM $t_glossary WHERE name = '".Database::escape_string($term)."'";
  219. if ($not_id<>'')
  220. {
  221. $sql .= " AND glossary_id <> '".Database::escape_string($not_id)."'";
  222. }
  223. $result = Database::query($sql,__FILE__,__LINE__);
  224. $count = Database::num_rows($result);
  225. if ($count > 0)
  226. {
  227. return true;
  228. }
  229. else
  230. {
  231. return false;
  232. }
  233. }
  234. /**
  235. * get all the information about one specific glossary term
  236. *
  237. * @param unknown_type $glossary_id
  238. * @return unknown
  239. *
  240. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
  241. * @version januari 2009, dokeos 1.8.6
  242. */
  243. function get_glossary_information($glossary_id)
  244. {
  245. // Database table definition
  246. $t_glossary = Database :: get_course_table(TABLE_GLOSSARY);
  247. $t_item_propery = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  248. $sql = "SELECT g.glossary_id AS glossary_id,
  249. g.name AS glossary_title,
  250. g.description AS glossary_comment,
  251. g.display_order AS glossary_display_order
  252. FROM $t_glossary g, $t_item_propery ip
  253. WHERE g.glossary_id = ip.ref
  254. AND tool = '".TOOL_GLOSSARY."'
  255. AND g.glossary_id = '".Database::escape_string($glossary_id)."' ";
  256. $result = Database::query($sql, __FILE__, __LINE__);
  257. return Database::fetch_array($result);
  258. }
  259. /**
  260. * Delete a glossary term (and re-order all the others)
  261. *
  262. * @param integer $glossary_id the id of the glossary
  263. *
  264. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
  265. * @version januari 2009, dokeos 1.8.6
  266. */
  267. function delete_glossary($glossary_id)
  268. {
  269. // Database table definition
  270. $t_glossary = Database :: get_course_table(TABLE_GLOSSARY);
  271. $sql = "DELETE FROM $t_glossary WHERE glossary_id='".Database::escape_string($glossary_id)."'";
  272. $result = Database::query($sql, __FILE__, __LINE__);
  273. //update item_property (delete)
  274. api_item_property_update(api_get_course_info(), TOOL_GLOSSARY, Database::escape_string($glossary_id), 'delete', api_get_user_id());
  275. // reorder the remaining terms
  276. reorder_glossary();
  277. $_SESSION['max_glossary_display'] = get_max_glossary_item();
  278. Display::display_confirmation_message(get_lang('TermDeleted'));
  279. }
  280. /**
  281. * This is the main function that display the list or the table with all the glossary terms
  282. *
  283. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
  284. * @version januari 2009, dokeos 1.8.6
  285. */
  286. function display_glossary()
  287. {
  288. // action links
  289. echo '<div class="actions" style="margin-bottom:10px">';
  290. if (api_is_allowed_to_edit(null,true))
  291. {
  292. echo '<a href="index.php?'.api_get_cidreq().'&action=addglossary&msg=add">'.Display::return_icon('filenew.gif',get_lang('TermAddNew')).get_lang('TermAddNew').'</a>';
  293. }
  294. if ((isset($_SESSION['glossary_view']) && $_SESSION['glossary_view'] == 'table') or (!isset($_SESSION['glossary_view']))){
  295. echo '<a href="index.php?'.api_get_cidreq().'&action=changeview&view=list">'.Display::return_icon('view_list.gif',get_lang('ListView')).get_lang('ListView').'</a>';
  296. } else {
  297. echo '<a href="index.php?'.api_get_cidreq().'&action=changeview&view=table">'.Display::return_icon('view_table.gif',get_lang('TableView')).get_lang('TableView').'</a>';
  298. }
  299. echo '</div>';
  300. if (!$_SESSION['glossary_view'] OR $_SESSION['glossary_view'] == 'table')
  301. {
  302. $table = new SortableTable('glossary', 'get_number_glossary_terms', 'get_glossary_data',0);
  303. $table->set_header(0, get_lang('DisplayOrder'), true);
  304. $table->set_header(1, get_lang('TermName'), true);
  305. $table->set_header(2, get_lang('TermDefinition'), true);
  306. $table->set_header(3, get_lang('CreationDate'), false);
  307. $table->set_header(4, get_lang('UpdateDate'), false);
  308. if (api_is_allowed_to_edit(null,true)) {
  309. $table->set_header(5, get_lang('Actions'), false);
  310. $table->set_column_filter(5, 'actions_filter');
  311. }
  312. $table->display();
  313. }
  314. if ($_SESSION['glossary_view'] == 'list')
  315. {
  316. display_glossary_list();
  317. }
  318. }
  319. /**
  320. * display the glossary terms in a list
  321. *
  322. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
  323. * @version januari 2009, dokeos 1.8.6
  324. */
  325. function display_glossary_list()
  326. {
  327. $glossary_data = get_glossary_data(0,1000,0,ASC);
  328. foreach($glossary_data as $key=>$glossary_item)
  329. {
  330. echo '<div class="sectiontitle">'.$glossary_item[1].'</div>';
  331. echo '<div class="sectioncomment">'.$glossary_item[2].'</div>';
  332. if (api_is_allowed_to_edit(null,true)) {
  333. echo '<div>'.actions_filter($glossary_item[5], '',$glossary_item).'</div>';
  334. }
  335. }
  336. }
  337. /**
  338. * Get the number of glossary terms
  339. *
  340. * @return unknown
  341. *
  342. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
  343. * @version januari 2009, dokeos 1.8.6
  344. */
  345. function get_number_glossary_terms()
  346. {
  347. // Database table definition
  348. $t_glossary = Database :: get_course_table(TABLE_GLOSSARY);
  349. $sql = "SELECT count(glossary_id) as total FROM $t_glossary";
  350. $res = Database::query($sql, __FILE__, __LINE__);
  351. $obj = Database::fetch_object($res);
  352. return $obj->total;
  353. }
  354. /**
  355. * get all the data of the glossary
  356. *
  357. * @param unknown_type $from
  358. * @param unknown_type $number_of_items
  359. * @param unknown_type $column
  360. * @param unknown_type $direction
  361. * @return unknown
  362. *
  363. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
  364. * @version januari 2009, dokeos 1.8.6
  365. */
  366. function get_glossary_data($from, $number_of_items, $column, $direction)
  367. {
  368. // Database table definition
  369. $t_glossary = Database :: get_course_table(TABLE_GLOSSARY);
  370. $t_item_propery = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  371. if (api_is_allowed_to_edit(null,true)) {
  372. $col5 = ", glossary.glossary_id as col5";
  373. } else {
  374. $col5 = " ";
  375. }
  376. //condition for the session
  377. $session_id = api_get_session_id();
  378. $condition_session = api_get_session_condition($session_id);
  379. $sql = "SELECT
  380. glossary.display_order as col0,
  381. glossary.name as col1,
  382. glossary.description as col2,
  383. ip.insert_date as col3,
  384. ip.lastedit_date as col4
  385. $col5,
  386. glossary.session_id as session_id
  387. FROM $t_glossary glossary, $t_item_propery ip
  388. WHERE glossary.glossary_id = ip.ref
  389. AND tool = '".TOOL_GLOSSARY."' $condition_session";
  390. $sql .= " ORDER BY col$column $direction ";
  391. $sql .= " LIMIT $from,$number_of_items";
  392. $res = Database::query($sql, __FILE__, __LINE__);
  393. $return = array();
  394. $array = array();
  395. while ($data = Database::fetch_array($res)) {
  396. $array[0] = $data[0];
  397. //validacion when belongs to a session
  398. $session_img = api_get_session_image($data['session_id'], $_user['status']);
  399. $array[1] = $data[1] . $session_img;
  400. if (!$_SESSION['glossary_view'] || $_SESSION['glossary_view'] == 'table') {
  401. $array[2] = str_replace(array('<p>','</p>'),array('','<br />'),$data[2]);
  402. } else {
  403. $array[2] = $data[2];
  404. }
  405. $array[3] = $data[3];
  406. $array[4] = $data[4];
  407. if (api_is_allowed_to_edit(null,true)) {
  408. $array[5] = $data[5];
  409. }
  410. $return[] = $array;
  411. }
  412. return $return;
  413. }
  414. /**
  415. * Enter description here...
  416. *
  417. * @param unknown_type $glossary_id
  418. * @param unknown_type $url_params
  419. * @param unknown_type $row
  420. * @return unknown
  421. *
  422. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
  423. * @version januari 2009, dokeos 1.8.6
  424. */
  425. function actions_filter($glossary_id,$url_params,$row)
  426. {
  427. if (!$_SESSION['max_glossary_display'] OR $_SESSION['max_glossary_display'] == '')
  428. {
  429. $_SESSION['max_glossary_display'] = get_max_glossary_item();
  430. }
  431. if (empty($_GET['glossary_column'])) {
  432. if ($row[0] > 1)
  433. {
  434. $return .= '<a href="'.api_get_self().'?action=moveup&amp;glossary_id='.$row[5].'">'.Display::return_icon('up.gif', get_lang('Up')).'</a>';
  435. }
  436. else
  437. {
  438. $return .= Display::return_icon('up_na.gif','&nbsp;');
  439. }
  440. if ($row[0] < $_SESSION['max_glossary_display'])
  441. {
  442. $return .= '<a href="'.api_get_self().'?action=movedown&amp;glossary_id='.$row[5].'">'.Display::return_icon('down.gif',get_lang('Down')).'</a>';
  443. }
  444. else
  445. {
  446. $return .= Display::return_icon('down_na.gif','&nbsp;');
  447. }
  448. }
  449. $return .= '<a href="'.api_get_self().'?action=edit_glossary&amp;glossary_id='.$row[5].'&msg=edit">'.Display::return_icon('edit.gif',get_lang('Edit')).'</a>';
  450. $glossary_data = get_glossary_information($row[5]);
  451. $glossary_term = $glossary_data['glossary_title'];
  452. $return .= '<a href="'.api_get_self().'?action=delete_glossary&amp;glossary_id='.$row[5].'" onclick="return confirmation(\''.$glossary_term.'\');">'.Display::return_icon('delete.gif', get_lang('Delete')).'</a>';
  453. return $return;
  454. }
  455. /**
  456. * a little bit of javascript to display a prettier warning when deleting a term
  457. *
  458. * @return unknown
  459. *
  460. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
  461. * @version januari 2009, dokeos 1.8.6
  462. */
  463. function javascript_glossary()
  464. {
  465. return "<script type=\"text/javascript\">
  466. function confirmation (name)
  467. {
  468. if (confirm(\" ". get_lang("TermConfirmDelete") ." \"+ name + \" ?\"))
  469. {return true;}
  470. else
  471. {return false;}
  472. }
  473. </script>";
  474. }
  475. /**
  476. * Enter description here...
  477. *
  478. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
  479. * @version januari 2009, dokeos 1.8.6
  480. */
  481. function reorder_glossary()
  482. {
  483. // Database table definition
  484. $t_glossary = Database :: get_course_table(TABLE_GLOSSARY);
  485. $sql = "SELECT * FROM $t_glossary ORDER by display_order ASC";
  486. $res = Database::query($sql, __FILE__, __LINE__);
  487. $i = 1;
  488. while ($data = Database::fetch_array($res))
  489. {
  490. $sql_reorder = "UPDATE $t_glossary SET display_order = $i WHERE glossary_id = '".Database::escape_string($data['glossary_id'])."'";
  491. Database::query($sql_reorder, __FILE__, __LINE__);
  492. $i++;
  493. }
  494. }
  495. /**
  496. * Enter description here...
  497. *
  498. * @param unknown_type $direction
  499. * @param unknown_type $glossary_id
  500. *
  501. * @author Patrick Cool <patrick.cool@ugent.be>, Ghent University, Belgium
  502. * @version januari 2009, dokeos 1.8.6
  503. */
  504. function move_glossary($direction, $glossary_id)
  505. {
  506. // Database table definition
  507. $t_glossary = Database :: get_course_table(TABLE_GLOSSARY);
  508. // sort direction
  509. if ($direction == 'up')
  510. {
  511. $sortorder = 'DESC';
  512. }
  513. else
  514. {
  515. $sortorder = 'ASC';
  516. }
  517. $sql = "SELECT * FROM $t_glossary ORDER BY display_order $sortorder";
  518. $res = Database::query($sql, __FILE__, __LINE__);
  519. while ($row = Database::fetch_array($res))
  520. {
  521. if ($found == true and empty($next_id))
  522. {
  523. $next_id = $row['glossary_id'];
  524. $next_display_order = $row['display_order'];
  525. }
  526. if ($row['glossary_id'] == $glossary_id)
  527. {
  528. $current_id = $glossary_id;
  529. $current_display_order = $row['display_order'];
  530. $found = true;
  531. }
  532. }
  533. $sql1 = "UPDATE $t_glossary SET display_order = '".Database::escape_string($next_display_order)."' WHERE glossary_id = '".Database::escape_string($current_id)."'";
  534. $sql2 = "UPDATE $t_glossary SET display_order = '".Database::escape_string($current_display_order)."' WHERE glossary_id = '".Database::escape_string($next_id)."'";
  535. $res = Database::query($sql1, __FILE__, __LINE__);
  536. $res = Database::query($sql2, __FILE__, __LINE__);
  537. Display::display_confirmation_message(get_lang('TermMoved'));
  538. }