legal_add.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Management of legal conditions
  5. * @package chamilo.admin
  6. */
  7. /**
  8. * Code
  9. */
  10. $cidReset = true;
  11. require_once '../inc/global.inc.php';
  12. $this_section = SECTION_PLATFORM_ADMIN;
  13. api_protect_admin_script();
  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. $navigator_info = api_get_navigator();
  45. if ($navigator_info['name']=='Internet Explorer' && $navigator_info['version']=='6') {
  46. if (isset($values['preview'])) {
  47. $submit ='preview';
  48. } elseif (isset($values['save'])) {
  49. $submit ='save';
  50. } elseif (isset($values['back'])) {
  51. $submit ='back';
  52. }
  53. } else {
  54. $submit = $values['send'];
  55. }
  56. $default['content'] = $content;
  57. if (isset($values['language'])) {
  58. if ($submit == 'back') {
  59. header('Location: legal_add.php');
  60. exit;
  61. } elseif ($submit == 'save') {
  62. $insert_result = LegalManager::add($lang, $content, $type, $changes);
  63. if ($insert_result ) {
  64. $message = get_lang('TermAndConditionSaved');
  65. } else {
  66. $message = get_lang('TermAndConditionNotSaved');
  67. }
  68. Security::clear_token();
  69. $tok = Security::get_token();
  70. header('Location: legal_list.php?action=show_message&message='.urlencode($message).'&sec_token='.$tok);
  71. exit();
  72. } elseif ($submit=='preview') {
  73. $defaults['type'] = $type;
  74. $defaults['content'] = $content;
  75. $defaults['changes'] = $changes;
  76. $term_preview = $defaults;
  77. $term_preview['type'] = intval($_POST['type']);
  78. } else {
  79. $my_lang = $_POST['language'];
  80. if (isset($_POST['language'])){
  81. $all_langs = api_get_languages();
  82. if (in_array($my_lang, $all_langs['folder'])){
  83. $language = api_get_language_id($my_lang);
  84. $term_preview = LegalManager::get_last_condition($language);
  85. $defaults = $term_preview;
  86. if (!$term_preview) {
  87. // there are not terms and conditions
  88. $term_preview['type']=-1;
  89. $defaults['type']=0;
  90. }
  91. }
  92. }
  93. }
  94. }
  95. }
  96. }
  97. $form->setDefaults($defaults);
  98. if (isset($_POST['send'])) {
  99. Security::clear_token();
  100. }
  101. $token = Security::get_token();
  102. $form->addElement('hidden','sec_token');
  103. //$form->setConstants(array('sec_token' => $token));
  104. $defaults['sec_token'] = $token;
  105. $form->addElement('header', get_lang('DisplayTermsConditions'));
  106. if (isset($_POST['language'])) {
  107. $form->addElement('static', Security::remove_XSS($_POST['language']));
  108. $form->addElement('hidden', 'language',Security::remove_XSS($_POST['language']));
  109. $form->addHtmlEditor('content', get_lang('Content'), true, false, array('ToolbarSet' => 'terms_and_conditions', 'Width' => '100%', 'Height' => '250'));
  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. $form->addElement('label', get_lang('Preview'), $preview);
  116. }
  117. // Submit & preview button
  118. $navigator_info = api_get_navigator();
  119. //ie6 fix
  120. if ($navigator_info['name']=='Internet Explorer' && $navigator_info['version']=='6') {
  121. $buttons = '<div class="row" align="center">
  122. <div class="formw">
  123. <input type="submit" name="back" value="'.get_lang('Back').'"/>
  124. <input type="submit" name="preview" value="'.get_lang('Preview').'"/>
  125. <input type="submit" name="save" value="'.get_lang('Save').'"/>
  126. </div>
  127. </div>';
  128. $form->addElement('html',$buttons);
  129. } else {
  130. $buttons = '<div class="row" align="center">
  131. <div class="formw">
  132. <button type="submit" class="back" name="send" value="back">'.get_lang('Back').'</button>
  133. <button type="submit" class="search" name="send" value="preview">'.get_lang('Preview').'</button>
  134. <button type="submit" class="save" name="send" value="save">'.get_lang('Save').'</button>
  135. </div>
  136. </div>';
  137. $form->addElement('html',$buttons);
  138. }
  139. } else {
  140. $form->addElement('select_language', 'language', get_lang('Language'),null,array());
  141. $form->addElement('button', 'send', get_lang('Load'));
  142. }
  143. $tool_name = get_lang('AddTermsAndConditions');
  144. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  145. Display :: display_header($tool_name);
  146. echo '<script>
  147. function sendlang(){
  148. //document.addlegal.send.value=\'load\';
  149. document.addlegal.sec_token.value=\''.$token.'\';
  150. document.addlegal.submit();
  151. }
  152. </script>';
  153. // action menu
  154. echo '<div class="actions">';
  155. echo '<a href="'.api_get_path(WEB_CODE_PATH).'admin/legal_list.php">'.Display::return_icon('search.gif',get_lang('EditTermsAndConditions'),'').get_lang('AllVersions').'</a>';
  156. echo '</div>';
  157. if (isset ($_GET['action'])) {
  158. switch ($_GET['action']) {
  159. case 'show_message' :
  160. Display :: display_normal_message(stripslashes($_GET['message']));
  161. break;
  162. }
  163. }
  164. $form->setDefaults($defaults);
  165. $form->display();
  166. Display :: display_footer();