index.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. // The language file that needs to be included.
  9. $language_file = array('glossary');
  10. // Including the global initialization 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. // Notification 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 javascripts.
  20. $htmlHeadXtra[] = GlossaryManager::javascript_glossary();
  21. $htmlHeadXtra[] = '<script type="text/javascript">
  22. function setFocus(){
  23. $("#glossary_title").focus();
  24. }
  25. $(document).ready(function () {
  26. setFocus();
  27. });
  28. </script>';
  29. // setting the tool constants
  30. $tool = TOOL_GLOSSARY;
  31. // Tracking
  32. event_access_tool(TOOL_GLOSSARY);
  33. // Displaying the header
  34. if (isset($_GET['action']) && ($_GET['action'] == 'addglossary' || $_GET['action'] == 'edit_glossary')) {
  35. $tool='GlossaryManagement';
  36. $interbreadcrumb[] = array ("url"=>"index.php", "name"=> get_lang('ToolGlossary'));
  37. }
  38. Display::display_header(get_lang(ucfirst($tool)));
  39. // Tool introduction
  40. Display::display_introduction_section(TOOL_GLOSSARY);
  41. if (isset($_GET['action']) && $_GET['action'] == 'changeview' AND in_array($_GET['view'],array('list','table'))) {
  42. $_SESSION['glossary_view'] = $_GET['view'];
  43. } else {
  44. if (!isset($_SESSION['glossary_view'])) {
  45. $_SESSION['glossary_view'] = 'table';//Default option
  46. }
  47. }
  48. if (api_is_allowed_to_edit(null, true)) {
  49. // Adding a glossary
  50. if (isset($_GET['action']) && $_GET['action'] == 'addglossary') {
  51. // initiate the object
  52. $form = new FormValidator('glossary','post', api_get_self().'?action='.Security::remove_XSS($_GET['action']));
  53. // settting the form elements
  54. $form->addElement('header', '', get_lang('TermAddNew'));
  55. $form->addElement('text', 'glossary_title', get_lang('TermName'), array('size'=>'80', 'id'=>'glossary_title'));
  56. //$form->applyFilter('glossary_title', 'html_filter');
  57. $form->addElement('html_editor', 'glossary_comment', get_lang('TermDefinition'), null, array('ToolbarSet' => 'Glossary', 'Width' => '90%', 'Height' => '300'));
  58. $form->addElement('style_submit_button', 'SubmitGlossary', get_lang('TermAddButton'), 'class="save"');
  59. // setting the rules
  60. $form->addRule('glossary_title',get_lang('ThisFieldIsRequired'), 'required');
  61. // The validation or display
  62. if ($form->validate()) {
  63. $check = Security::check_token('post');
  64. if ($check) {
  65. $values = $form->exportValues();
  66. GlossaryManager::save_glossary($values);
  67. }
  68. Security::clear_token();
  69. GlossaryManager::display_glossary();
  70. } else {
  71. $token = Security::get_token();
  72. $form->addElement('hidden','sec_token');
  73. $form->setConstants(array('sec_token' => $token));
  74. $form->display();
  75. }
  76. } else if (isset($_GET['action']) && $_GET['action'] == 'edit_glossary' && is_numeric($_GET['glossary_id'])) { // Editing a glossary
  77. // initiate the object
  78. $form = new FormValidator('glossary','post', api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&glossary_id='.Security::remove_XSS($_GET['glossary_id']));
  79. // settting the form elements
  80. $form->addElement('header', '', get_lang('TermEdit'));
  81. $form->addElement('hidden', 'glossary_id');
  82. $form->addElement('text', 'glossary_title', get_lang('TermName'),array('size'=>'80'));
  83. //$form->applyFilter('glossary_title', 'html_filter');
  84. $form->addElement('html_editor', 'glossary_comment', get_lang('TermDefinition'), null, array('ToolbarSet' => 'Glossary', 'Width' => '90%', 'Height' => '300'));
  85. $element = $form->addElement('text', 'insert_date', get_lang('CreationDate'),array('size'=>'100'));
  86. $element ->freeze();
  87. $element = $form->addElement('text', 'update_date', get_lang('UpdateDate'),array('size'=>'100'));
  88. $element ->freeze();
  89. $form->addElement('style_submit_button', 'SubmitGlossary', get_lang('TermUpdateButton'), 'class="save"');
  90. // setting the defaults
  91. $glossary_data = GlossaryManager::get_glossary_information($_GET['glossary_id']);
  92. // Date treatment for timezones
  93. if (!empty($glossary_data['insert_date']) && $glossary_data['insert_date'] != '0000-00-00 00:00:00:') {
  94. $glossary_data['insert_date'] = api_get_local_time($glossary_data['insert_date']);
  95. } else {
  96. $glossary_data['insert_date'] = '';
  97. }
  98. if (!empty($glossary_data['update_date']) && $glossary_data['update_date'] != '0000-00-00 00:00:00:') {
  99. $glossary_data['update_date'] = api_get_local_time($glossary_data['update_date']);
  100. } else {
  101. $glossary_data['update_date'] = '';
  102. }
  103. $form->setDefaults($glossary_data);
  104. // setting the rules
  105. $form->addRule('glossary_title', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
  106. // The validation or display
  107. if ($form->validate()) {
  108. $check = Security::check_token('post');
  109. if ($check) {
  110. $values = $form->exportValues();
  111. GlossaryManager::update_glossary($values);
  112. }
  113. Security::clear_token();
  114. GlossaryManager::display_glossary();
  115. } else {
  116. $token = Security::get_token();
  117. $form->addElement('hidden', 'sec_token');
  118. $form->setConstants(array('sec_token' => $token));
  119. $form->display();
  120. }
  121. } else if (isset($_GET['action']) && $_GET['action'] == 'delete_glossary' && is_numeric($_GET['glossary_id'])) {// deleting a glossary
  122. GlossaryManager::delete_glossary(Security::remove_XSS($_GET['glossary_id']));
  123. GlossaryManager::display_glossary();
  124. } else if (isset($_GET['action']) && $_GET['action'] == 'moveup' && is_numeric($_GET['glossary_id'])) { // moving a glossary term up
  125. GlossaryManager::move_glossary('up',$_GET['glossary_id']);
  126. GlossaryManager::display_glossary();
  127. } else if (isset($_GET['action']) && $_GET['action'] == 'movedown' && is_numeric($_GET['glossary_id'])) { // moving a glossary term down
  128. GlossaryManager::move_glossary('down',$_GET['glossary_id']);
  129. GlossaryManager::display_glossary();
  130. } else {
  131. GlossaryManager::display_glossary();
  132. }
  133. } else {
  134. GlossaryManager::display_glossary();
  135. }
  136. // Footer
  137. Display::display_footer();