index.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php //$id: $
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.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. require_once api_get_path(LIBRARY_PATH).'sortabletable.class.php';
  13. require_once api_get_path(LIBRARY_PATH).'glossary.lib.php';
  14. // the section (tabs)
  15. $this_section=SECTION_COURSES;
  16. // notice for unauthorized people.
  17. api_protect_course_script(true);
  18. // including additional libraries
  19. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  20. // additional javascript
  21. $htmlHeadXtra[] = GlossaryManager::javascript_glossary();
  22. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.js" type="text/javascript" language="javascript"></script>'; //jQuery
  23. $htmlHeadXtra[] = '<script type="text/javascript">
  24. function setFocus(){
  25. $("#glossary_title").focus();
  26. }
  27. $(document).ready(function () {
  28. setFocus();
  29. });
  30. </script>';
  31. // setting the tool constants
  32. $tool = TOOL_GLOSSARY;
  33. // tracking
  34. event_access_tool(TOOL_GLOSSARY);
  35. // displaying the header
  36. if (isset($_GET['action']) && ($_GET['action'] == 'addglossary' || $_GET['action'] == 'edit_glossary')) {
  37. $tool='GlossaryManagement';
  38. $interbreadcrumb[] = array ("url"=>"index.php", "name"=> get_lang('ToolGlossary'));
  39. }
  40. Display::display_header(get_lang(ucfirst($tool)));
  41. // Tool introduction
  42. Display::display_introduction_section(TOOL_GLOSSARY);
  43. if ($_GET['action'] == 'changeview' AND in_array($_GET['view'],array('list','table'))) {
  44. $_SESSION['glossary_view'] = $_GET['view'];
  45. } else {
  46. if (!isset($_SESSION['glossary_view'])) {
  47. $_SESSION['glossary_view'] = 'table';//Default option
  48. }
  49. }
  50. if (api_is_allowed_to_edit(null,true)) {
  51. // Adding a glossary
  52. if (isset($_GET['action']) && $_GET['action'] == 'addglossary') {
  53. // initiate the object
  54. $form = new FormValidator('glossary','post', api_get_self().'?action='.Security::remove_XSS($_GET['action']));
  55. // settting the form elements
  56. $form->addElement('header', '', get_lang('TermAddNew'));
  57. $form->addElement('text', 'glossary_title', get_lang('TermName'), array('size'=>'95', 'id'=>'glossary_title'));
  58. //$form->applyFilter('glossary_title', 'html_filter');
  59. $form->addElement('html_editor', 'glossary_comment', get_lang('TermDefinition'), null, array('ToolbarSet' => 'Glossary', 'Width' => '100%', 'Height' => '300'));
  60. $form->addElement('style_submit_button', 'SubmitGlossary', get_lang('TermAddButton'), 'class="save"');
  61. // setting the rules
  62. $form->addRule('glossary_title',get_lang('ThisFieldIsRequired'), 'required');
  63. // The validation or display
  64. if ($form->validate()) {
  65. $check = Security::check_token('post');
  66. if ($check) {
  67. $values = $form->exportValues();
  68. GlossaryManager::save_glossary($values);
  69. }
  70. Security::clear_token();
  71. GlossaryManager::display_glossary();
  72. } else {
  73. $token = Security::get_token();
  74. $form->addElement('hidden','sec_token');
  75. $form->setConstants(array('sec_token' => $token));
  76. $form->display();
  77. }
  78. } else if (isset($_GET['action']) && $_GET['action'] == 'edit_glossary' && is_numeric($_GET['glossary_id'])) { // Editing a glossary
  79. // initiate the object
  80. $form = new FormValidator('glossary','post', api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&glossary_id='.Security::remove_XSS($_GET['glossary_id']));
  81. // settting the form elements
  82. $form->addElement('header', '', get_lang('TermEdit'));
  83. $form->addElement('hidden', 'glossary_id');
  84. $form->addElement('text', 'glossary_title', get_lang('TermName'),array('size'=>'100'));
  85. //$form->applyFilter('glossary_title', 'html_filter');
  86. $form->addElement('html_editor', 'glossary_comment', get_lang('TermDefinition'), null, array('ToolbarSet' => 'Glossary', 'Width' => '100%', 'Height' => '300'));
  87. $form->addElement('style_submit_button', 'SubmitGlossary', get_lang('TermUpdateButton'), 'class="save"');
  88. // setting the defaults
  89. $defaults = GlossaryManager::get_glossary_information(Security::remove_XSS($_GET['glossary_id']));
  90. $form->setDefaults($defaults);
  91. // setting the rules
  92. $form->addRule('glossary_title', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
  93. // The validation or display
  94. if ($form->validate()) {
  95. $check = Security::check_token('post');
  96. if ($check) {
  97. $values = $form->exportValues();
  98. GlossaryManager::update_glossary($values);
  99. }
  100. Security::clear_token();
  101. GlossaryManager::display_glossary();
  102. } else {
  103. $token = Security::get_token();
  104. $form->addElement('hidden','sec_token');
  105. $form->setConstants(array('sec_token' => $token));
  106. $form->display();
  107. }
  108. } else if (isset($_GET['action']) && $_GET['action'] == 'delete_glossary' && is_numeric($_GET['glossary_id'])) {// deleting a glossary
  109. GlossaryManager::delete_glossary(Security::remove_XSS($_GET['glossary_id']));
  110. GlossaryManager::display_glossary();
  111. } else if (isset($_GET['action']) && $_GET['action'] == 'moveup' && is_numeric($_GET['glossary_id'])) { // moving a glossary term up
  112. GlossaryManager::move_glossary('up',$_GET['glossary_id']);
  113. GlossaryManager::display_glossary();
  114. } else if (isset($_GET['action']) && $_GET['action'] == 'movedown' && is_numeric($_GET['glossary_id'])) {// moving a glossary term up
  115. GlossaryManager::move_glossary('down',$_GET['glossary_id']);
  116. GlossaryManager::display_glossary();
  117. } else {
  118. GlossaryManager::display_glossary();
  119. }
  120. } else {
  121. GlossaryManager::display_glossary();
  122. }
  123. // footer
  124. Display::display_footer();