legal_add.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Framework\Container;
  4. /**
  5. * Management of legal conditions
  6. * @package chamilo.admin
  7. */
  8. $cidReset = true;
  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. //$form->setConstants(array('sec_token' => $token));
  94. $defaults['sec_token'] = $token;
  95. $form->addElement('header', get_lang('DisplayTermsConditions'));
  96. if (isset($_POST['language'])) {
  97. $form->addElement('static', Security::remove_XSS($_POST['language']));
  98. $form->addElement('hidden', 'language',Security::remove_XSS($_POST['language']));
  99. $form->addHtmlEditor(
  100. 'content',
  101. get_lang('Content'),
  102. true,
  103. false,
  104. array(
  105. 'ToolbarSet' => 'TermsAndConditions',
  106. 'Width' => '100%',
  107. 'Height' => '250',
  108. )
  109. );
  110. $form->addElement('radio', 'type', '', get_lang('HTMLText') ,'0');
  111. $form->addElement('radio', 'type', '', get_lang('PageLink') ,'1');
  112. $form->addElement('textarea', 'changes', get_lang('ExplainChanges'),array('width'=>'20'));
  113. $preview = LegalManager::show_last_condition($term_preview);
  114. if ($term_preview['type']!=-1) {
  115. $preview = LegalManager::replaceTags($preview);
  116. $form->addElement('label', get_lang('Preview'), $preview);
  117. }
  118. // Submit & preview button
  119. $buttons = '<div class="row" align="center">
  120. <div class="formw">
  121. <button type="submit" class="btn btn-default back" name="send" value="back">'.get_lang('Back').'</button>
  122. <button type="submit" class="btn btn-default search" name="send" value="preview">'.get_lang('Preview').'</button>
  123. <button type="submit" class="btn btn-primary save" name="send" value="save">'.get_lang('Save').'</button>
  124. </div>
  125. </div>';
  126. $form->addElement('html',$buttons);
  127. } else {
  128. $form->addElement('select_language', 'language', get_lang('Language'),null,array());
  129. $form->addButtonSearch(get_lang('Load'), 'send');
  130. }
  131. $tool_name = get_lang('AddTermsAndConditions');
  132. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  133. Display :: display_header($tool_name);
  134. echo '<script>
  135. function sendlang(){
  136. //document.addlegal.send.value=\'load\';
  137. document.addlegal.sec_token.value=\''.$token.'\';
  138. document.addlegal.submit();
  139. }
  140. </script>';
  141. // action menu
  142. echo '<div class="actions">';
  143. echo '<a href="'.api_get_path(WEB_CODE_PATH).'admin/legal_list.php">'.
  144. Display::return_icon('search.gif', get_lang('EditTermsAndConditions'), '').get_lang('AllVersions').'</a>';
  145. echo '</div>';
  146. $form->setDefaults($defaults);
  147. $form->display();
  148. Display :: display_footer();