legal_add.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. if( $form->validate()) {
  18. $check = Security::check_token('post');
  19. if ($check) {
  20. $values = $form->getSubmitValues();
  21. $lang = $values['language'];
  22. //language id
  23. $lang = api_get_language_id($lang);
  24. $type = $values['type'];
  25. $content = $values['content'];
  26. $changes = $values['changes'];
  27. $navigator_info = api_get_navigator();
  28. if ($navigator_info['name']=='Internet Explorer' && $navigator_info['version']=='6') {
  29. if (isset($values['preview'])) {
  30. $submit ='preview';
  31. } elseif (isset($values['save'])) {
  32. $submit ='save';
  33. } elseif (isset($values['back'])) {
  34. $submit ='back';
  35. }
  36. } else {
  37. $submit = $values['send'];
  38. }
  39. $default['content']=$content;
  40. if (isset($values['language'])) {
  41. if($submit=='back') {
  42. header('Location: legal_add.php');
  43. exit;
  44. } elseif($submit=='save') {
  45. $insert_result = LegalManager::add($lang,$content,$type,$changes);
  46. if ($insert_result )
  47. $message = get_lang('TermAndConditionSaved');
  48. else
  49. $message = get_lang('TermAndConditionNotSaved');
  50. Security::clear_token();
  51. $tok = Security::get_token();
  52. header('Location: legal_list.php?action=show_message&message='.urlencode($message).'&sec_token='.$tok);
  53. exit();
  54. } elseif($submit=='preview') {
  55. $defaults['type']=$type;
  56. $defaults['content']=$content;
  57. $defaults['changes']=$changes;
  58. $term_preview = $defaults;
  59. $term_preview['type'] = intval($_POST['type']);
  60. } else {
  61. $my_lang = $_POST['language'];
  62. if (isset($_POST['language'])){
  63. $all_langs = api_get_languages();
  64. if (in_array($my_lang, $all_langs['folder'])){
  65. $language = api_get_language_id($my_lang);
  66. $term_preview = LegalManager::get_last_condition($language);
  67. $defaults = $term_preview;
  68. if (!$term_preview) {
  69. // there are not terms and conditions
  70. $term_preview['type']=-1;
  71. $defaults['type']=0;
  72. }
  73. }
  74. }
  75. }
  76. }
  77. }
  78. }
  79. $form->setDefaults($default);
  80. if(isset($_POST['send'])) {
  81. Security::clear_token();
  82. }
  83. $token = Security::get_token();
  84. $form->addElement('hidden','sec_token');
  85. $form->setConstants(array('sec_token' => $token));
  86. $form->addElement('header', get_lang('DisplayTermsConditions'));
  87. if (isset($_POST['language'])) {
  88. $form->addElement('static', Security::remove_XSS($_POST['language']));
  89. $form->addElement('hidden', 'language',Security::remove_XSS($_POST['language']));
  90. $form->addHtmlEditor('content', get_lang('Content'), true, false, array('ToolbarSet' => 'terms_and_conditions', 'Width' => '100%', 'Height' => '250'));
  91. $form->addElement('radio', 'type', '', get_lang('HTMLText') ,'0');
  92. $form->addElement('radio', 'type', '', get_lang('PageLink') ,'1');
  93. $form->addElement('textarea', 'changes', get_lang('ExplainChanges'),array('width'=>'20'));
  94. $preview = LegalManager::show_last_condition($term_preview);
  95. if ($term_preview['type']!=-1) {
  96. $form->addElement('label', get_lang('Preview'), $preview);
  97. }
  98. // Submit & preview button
  99. $navigator_info = api_get_navigator();
  100. //ie6 fix
  101. if ($navigator_info['name']=='Internet Explorer' && $navigator_info['version']=='6') {
  102. $buttons = '<div class="row" align="center">
  103. <div class="formw">
  104. <input type="submit" name="back" value="'.get_lang('Back').'"/>
  105. <input type="submit" name="preview" value="'.get_lang('Preview').'"/>
  106. <input type="submit" name="save" value="'.get_lang('Save').'"/>
  107. </div>
  108. </div>';
  109. $form->addElement('html',$buttons);
  110. } else {
  111. $buttons = '<div class="row" align="center">
  112. <div class="formw">
  113. <button type="submit" class="back" name="send" value="back">'.get_lang('Back').'</button>
  114. <button type="submit" class="search" name="send" value="preview">'.get_lang('Preview').'</button>
  115. <button type="submit" class="save" name="send" value="save">'.get_lang('Save').'</button>
  116. </div>
  117. </div>';
  118. $form->addElement('html',$buttons);
  119. }
  120. } else {
  121. $form->addElement('select_language', 'language', get_lang('Language'),null,array());
  122. $form->addElement('button', 'send', get_lang('Load'));
  123. }
  124. $tool_name = get_lang('AddTermsAndConditions');
  125. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  126. Display :: display_header($tool_name);
  127. echo '<script>
  128. function sendlang(){
  129. //document.addlegal.send.value=\'load\';
  130. document.addlegal.sec_token.value=\''.$token.'\';
  131. document.addlegal.submit();
  132. }
  133. </script>';
  134. // action menu
  135. echo '<div class="actions">';
  136. 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>';
  137. echo '</div>';
  138. if (isset ($_GET['action'])) {
  139. switch ($_GET['action']) {
  140. case 'show_message' :
  141. Display :: display_normal_message(stripslashes($_GET['message']));
  142. break;
  143. }
  144. }
  145. $form->setDefaults($defaults);
  146. $form->display();
  147. Display :: display_footer();