access_url_edit.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Create or edit access urls and branches
  5. * @package chamilo.admin
  6. * @author Julio Montoya <gugli100@gmail.com>
  7. * @author Yannick Warnier <yannick.warnier@beeznest.com>
  8. */
  9. $language_file = 'admin';
  10. $cidReset = true;
  11. ////require_once '../inc/global.inc.php';
  12. $this_section = SECTION_PLATFORM_ADMIN;
  13. api_protect_global_admin_script();
  14. if (!api_get_multiple_access_url()) {
  15. header('Location: index.php');
  16. exit;
  17. }
  18. // Create the form
  19. $form = new FormValidator('add_url');
  20. if ($form->validate()) {
  21. $check = Security::check_token('post');
  22. if ($check) {
  23. $url_array = $form->getSubmitValues();
  24. $url = Security::remove_XSS($url_array['url']);
  25. $description = Security::remove_XSS($url_array['description']);
  26. $active = intval($url_array['active']);
  27. $url_id = $url_array['id'];
  28. $url_to_go='access_urls.php';
  29. if ($url_id != '') {
  30. //we can't change the status of the url with id=1
  31. if ($url_id == 1) {
  32. $active = 1;
  33. }
  34. //checking url
  35. if (substr($url, strlen($url)-1, strlen($url)) == '/') {
  36. UrlManager::update($url_id, $url, $description, $active);
  37. } else {
  38. UrlManager::update($url_id, $url.'/', $description, $active);
  39. }
  40. // URL Images
  41. $url_images_dir = api_get_path(SYS_PATH).'custompages/url-images/';
  42. $image_fields = array("url_image_1", "url_image_2", "url_image_3");
  43. foreach ($image_fields as $image_field) {
  44. if ($_FILES[$image_field]['error'] == 0) {
  45. // Hardcoded: only PNG files allowed
  46. if (end(explode('.', $_FILES[$image_field]['name'])) == 'png') {
  47. move_uploaded_file(
  48. $_FILES[$image_field]['tmp_name'],
  49. $url_images_dir.$url_id.'_'.$image_field.'.png'
  50. );
  51. }
  52. // else fail silently
  53. }
  54. // else fail silently
  55. }
  56. $url_to_go='access_urls.php';
  57. $message=get_lang('URLEdited');
  58. } else {
  59. $num = UrlManager::url_exist($url);
  60. if ($num == 0) {
  61. //checking url
  62. if (substr($url, strlen($url)-1, strlen($url))=='/') {
  63. UrlManager::add($url, $description, $active);
  64. } else {
  65. //create
  66. UrlManager::add($url.'/', $description, $active);
  67. }
  68. $message = get_lang('URLAdded');
  69. $url_to_go='access_urls.php';
  70. } else {
  71. $url_to_go='access_url_edit.php';
  72. $message = get_lang('URLAlreadyAdded');
  73. }
  74. // URL Images
  75. $url .= (substr($url,strlen($url)-1, strlen($url))=='/') ? '' : '/';
  76. $url_id = UrlManager::get_url_id($url);
  77. $url_images_dir = api_get_path(SYS_PATH).'custompages/url-images/';
  78. $image_fields = array("url_image_1", "url_image_2", "url_image_3");
  79. foreach ($image_fields as $image_field) {
  80. if ($_FILES[$image_field]['error'] == 0) {
  81. // Hardcoded: only PNG files allowed
  82. if (end(explode('.', $_FILES[$image_field]['name'])) == 'png') {
  83. move_uploaded_file($_FILES[$image_field]['tmp_name'], $url_images_dir.$url_id.'_'.$image_field.'.png');
  84. }
  85. // else fail silently
  86. }
  87. // else fail silently
  88. }
  89. }
  90. Security::clear_token();
  91. $tok = Security::get_token();
  92. header('Location: '.$url_to_go.'?action=show_message&message='.urlencode($message).'&sec_token='.$tok);
  93. exit();
  94. }
  95. } else {
  96. if(isset($_POST['submit'])) {
  97. Security::clear_token();
  98. }
  99. $token = Security::get_token();
  100. $form->addElement('hidden','sec_token');
  101. $form->setConstants(array('sec_token' => $token));
  102. }
  103. $form->addElement('text','url', get_lang('URLIP'), array('class'=>'span6'));
  104. $form->addRule('url', get_lang('ThisFieldIsRequired'), 'required');
  105. $form->addRule('url', '', 'maxlength',254);
  106. $types = array(
  107. 1=>get_lang('AccessURL'),
  108. 2=>get_lang('SincroServer'),
  109. 3=>get_lang('SincroClient'),
  110. );
  111. $form->addElement('select', 'url_type', get_lang('Type'), $types);
  112. $form->addElement('textarea','description',get_lang('Description'));
  113. //the first url with id = 1 will be always active
  114. if (isset($_GET['url_id']) && $_GET['url_id'] != 1) {
  115. $form->addElement('checkbox','active', null, get_lang('Active'));
  116. }
  117. //$form->addRule('checkbox', get_lang('ThisFieldIsRequired'), 'required');
  118. $defaults['url']='http://';
  119. $form->setDefaults($defaults);
  120. $submit_name = get_lang('AddUrl');
  121. if (isset($_GET['url_id'])) {
  122. $url_id = Database::escape_string($_GET['url_id']);
  123. $num_url_id = UrlManager::url_id_exist($url_id);
  124. if($num_url_id != 1) {
  125. header('Location: access_urls.php');
  126. exit();
  127. }
  128. $url_data = UrlManager::get_url_data_from_id($url_id);
  129. $form->addElement('hidden','id',$url_data['id']);
  130. $form->setDefaults($url_data);
  131. $submit_name = get_lang('AddUrl');
  132. }
  133. if (!api_is_multiple_url_enabled()) {
  134. header('Location: index.php');
  135. exit;
  136. }
  137. $tool_name = get_lang('AddUrl');
  138. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  139. $interbreadcrumb[] = array ("url" => 'access_urls.php', "name" => get_lang('MultipleAccessURLs'));
  140. Display :: display_header($tool_name);
  141. if (isset ($_GET['action'])) {
  142. switch ($_GET['action']) {
  143. case 'show_message' :
  144. Display :: display_normal_message(stripslashes($_GET['message']));
  145. break;
  146. }
  147. }
  148. // URL Images
  149. $form->addElement('file','url_image_1','URL Image 1 (PNG)');
  150. $form->addElement('file','url_image_2','URL Image 2 (PNG)');
  151. $form->addElement('file','url_image_3','URL Image 3 (PNG)');
  152. // Submit button
  153. $form->addElement('style_submit_button', 'submit', $submit_name, 'class="add"');
  154. $form->display();