legal_add.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Management of legal conditions
  5. * @package chamilo.admin
  6. */
  7. $cidReset = true;
  8. require_once __DIR__.'/../inc/global.inc.php';
  9. $this_section = SECTION_PLATFORM_ADMIN;
  10. api_protect_admin_script();
  11. if (api_get_setting('allow_terms_conditions') !== 'true') {
  12. api_not_allowed(true);
  13. }
  14. // Create the form
  15. $form = new FormValidator('addlegal');
  16. $defaults = array();
  17. $term_preview = array(
  18. 'type' => 0,
  19. 'content' => '',
  20. 'changes' => ''
  21. );
  22. if ($form->validate()) {
  23. $check = Security::check_token('post');
  24. if ($check) {
  25. $values = $form->getSubmitValues();
  26. $lang = $values['language'];
  27. //language id
  28. $lang = api_get_language_id($lang);
  29. if (isset($values['type'])) {
  30. $type = $values['type'];
  31. } else {
  32. $type = 0;
  33. }
  34. if (isset($values['content'])) {
  35. $content = $values['content'];
  36. } else {
  37. $content = '';
  38. }
  39. if (isset($values['changes'])) {
  40. $changes = $values['changes'];
  41. } else {
  42. $changes = '';
  43. }
  44. $submit = $values['send'];
  45. $default['content'] = $content;
  46. if (isset($values['language'])) {
  47. if ($submit == 'back') {
  48. header('Location: legal_add.php');
  49. exit;
  50. } elseif ($submit == 'save') {
  51. $insert_result = LegalManager::add($lang, $content, $type, $changes);
  52. if ($insert_result) {
  53. $message = get_lang('TermAndConditionSaved');
  54. } else {
  55. $message = get_lang('TermAndConditionNotSaved');
  56. }
  57. Security::clear_token();
  58. $tok = Security::get_token();
  59. Display::addFlash(Display::return_message($message));
  60. header('Location: legal_list.php?sec_token='.$tok);
  61. exit();
  62. } elseif ($submit == 'preview') {
  63. $defaults['type'] = $type;
  64. $defaults['content'] = $content;
  65. $defaults['changes'] = $changes;
  66. $term_preview = $defaults;
  67. $term_preview['type'] = intval($_POST['type']);
  68. } else {
  69. $my_lang = $_POST['language'];
  70. if (isset($_POST['language'])) {
  71. $all_langs = api_get_languages();
  72. if (in_array($my_lang, $all_langs['folder'])) {
  73. $language = api_get_language_id($my_lang);
  74. $term_preview = LegalManager::get_last_condition($language);
  75. $defaults = $term_preview;
  76. if (!$term_preview) {
  77. // there are not terms and conditions
  78. $term_preview['type'] = -1;
  79. $defaults['type'] = 0;
  80. }
  81. }
  82. }
  83. }
  84. }
  85. }
  86. }
  87. $form->setDefaults($defaults);
  88. if (isset($_POST['send'])) {
  89. Security::clear_token();
  90. }
  91. $token = Security::get_token();
  92. $form->addElement('hidden', 'sec_token');
  93. $defaults['sec_token'] = $token;
  94. $form->addElement('header', get_lang('DisplayTermsConditions'));
  95. if (isset($_POST['language'])) {
  96. $form->addElement('static', Security::remove_XSS($_POST['language']));
  97. $form->addElement('hidden', 'language', Security::remove_XSS($_POST['language']));
  98. $form->addHtmlEditor(
  99. 'content',
  100. get_lang('Content'),
  101. true,
  102. false,
  103. array('ToolbarSet' => 'terms_and_conditions', 'Width' => '100%', 'Height' => '250')
  104. );
  105. $form->addElement('radio', 'type', '', get_lang('HTMLText'), '0');
  106. $form->addElement('radio', 'type', '', get_lang('PageLink'), '1');
  107. $form->addElement('textarea', 'changes', get_lang('ExplainChanges'), array('width' => '20'));
  108. $preview = LegalManager::show_last_condition($term_preview);
  109. if ($term_preview['type'] != -1) {
  110. $preview = LegalManager::replaceTags($preview);
  111. $form->addElement('label', get_lang('Preview'), $preview);
  112. }
  113. // Submit & preview button
  114. $buttons = '<div class="row" align="center">
  115. <div class="formw">
  116. <button type="submit" class="btn btn-default back" name="send" value="back">'.get_lang('Back').'</button>
  117. <button type="submit" class="btn btn-default search" name="send" value="preview">'.get_lang('Preview').'</button>
  118. <button type="submit" class="btn btn-primary save" name="send" value="save">'.get_lang('Save').'</button>
  119. </div>
  120. </div>';
  121. $form->addElement('html', $buttons);
  122. } else {
  123. $form->addSelectLanguage('language', get_lang('Language'), null, array());
  124. $form->addButtonSearch(get_lang('Load'), 'send');
  125. }
  126. $tool_name = get_lang('AddTermsAndConditions');
  127. $interbreadcrumb[] = array("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  128. Display :: display_header($tool_name);
  129. echo '<script>
  130. function sendlang(){
  131. document.addlegal.sec_token.value=\''.$token.'\';
  132. document.addlegal.submit();
  133. }
  134. </script>';
  135. // action menu
  136. echo '<div class="actions">';
  137. echo '<a href="'.api_get_path(WEB_CODE_PATH).'admin/legal_list.php">'.
  138. Display::return_icon('search.gif', get_lang('EditTermsAndConditions'), '').get_lang('AllVersions').'</a>';
  139. echo '</div>';
  140. $form->setDefaults($defaults);
  141. $form->display();
  142. Display :: display_footer();