index.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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).'sortabletable.class.php';
  13. require_once api_get_path(LIBRARY_PATH).'glossary.lib.php';
  14. // The section (tabs).
  15. $this_section = SECTION_COURSES;
  16. // Notification 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 javascripts.
  21. $htmlHeadXtra[] = GlossaryManager::javascript_glossary();
  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. $element = $form->addElement('text', 'insert_date', get_lang('CreationDate'),array('size'=>'100'));
  87. $element ->freeze();
  88. $element = $form->addElement('text', 'update_date', get_lang('UpdateDate'),array('size'=>'100'));
  89. $element ->freeze();
  90. $form->addElement('style_submit_button', 'SubmitGlossary', get_lang('TermUpdateButton'), 'class="save"');
  91. // setting the defaults
  92. $glossary_data = GlossaryManager::get_glossary_information($_GET['glossary_id']);
  93. // Date treatment for timezones
  94. if (!empty($glossary_data['insert_date']) && $glossary_data['insert_date'] != '0000-00-00 00:00:00:') {
  95. $glossary_data['insert_date'] = api_get_local_time($glossary_data['insert_date'] , null, date_default_timezone_get());
  96. } else {
  97. $glossary_data['insert_date'] = '';
  98. }
  99. if (!empty($glossary_data['update_date']) && $glossary_data['update_date'] != '0000-00-00 00:00:00:') {
  100. $glossary_data['update_date'] = api_get_local_time($glossary_data['update_date'] , null, date_default_timezone_get());
  101. } else {
  102. $glossary_data['update_date'] = '';
  103. }
  104. $form->setDefaults($glossary_data);
  105. // setting the rules
  106. $form->addRule('glossary_title', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
  107. // The validation or display
  108. if ($form->validate()) {
  109. $check = Security::check_token('post');
  110. if ($check) {
  111. $values = $form->exportValues();
  112. GlossaryManager::update_glossary($values);
  113. }
  114. Security::clear_token();
  115. GlossaryManager::display_glossary();
  116. } else {
  117. $token = Security::get_token();
  118. $form->addElement('hidden', 'sec_token');
  119. $form->setConstants(array('sec_token' => $token));
  120. $form->display();
  121. }
  122. } else if (isset($_GET['action']) && $_GET['action'] == 'delete_glossary' && is_numeric($_GET['glossary_id'])) {// deleting a glossary
  123. GlossaryManager::delete_glossary(Security::remove_XSS($_GET['glossary_id']));
  124. GlossaryManager::display_glossary();
  125. } else if (isset($_GET['action']) && $_GET['action'] == 'moveup' && is_numeric($_GET['glossary_id'])) { // moving a glossary term up
  126. GlossaryManager::move_glossary('up',$_GET['glossary_id']);
  127. GlossaryManager::display_glossary();
  128. } else if (isset($_GET['action']) && $_GET['action'] == 'movedown' && is_numeric($_GET['glossary_id'])) { // moving a glossary term down
  129. GlossaryManager::move_glossary('down',$_GET['glossary_id']);
  130. GlossaryManager::display_glossary();
  131. } else {
  132. GlossaryManager::display_glossary();
  133. }
  134. } else {
  135. GlossaryManager::display_glossary();
  136. }
  137. // Footer
  138. Display::display_footer();