legal_add.php 5.2 KB

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