index.php 5.6 KB

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