access_url_edit.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. * @author Julio Montoya <gugli100@gmail.com>
  6. */
  7. $language_file = 'admin';
  8. $cidReset = true;
  9. require_once '../inc/global.inc.php';
  10. $this_section = SECTION_PLATFORM_ADMIN;
  11. //api_protect_admin_script();
  12. api_protect_global_admin_script();
  13. if (!api_get_multiple_access_url()) {
  14. header('Location: index.php');
  15. exit;
  16. }
  17. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  18. require_once api_get_path(LIBRARY_PATH).'security.lib.php';
  19. require_once api_get_path(LIBRARY_PATH).'urlmanager.lib.php';
  20. // Create the form
  21. $form = new FormValidator('add_url');
  22. if( $form->validate()) {
  23. $check = Security::check_token('post');
  24. if($check) {
  25. $url_array = $form->getSubmitValues();
  26. $url = Security::remove_XSS($url_array['url']);
  27. $description = Security::remove_XSS($url_array['description']);
  28. $active = intval($url_array['active']);
  29. $url_id = $url_array['id'];
  30. $url_to_go='access_urls.php';
  31. if ($url_id!='') {
  32. //we can't change the status of the url with id=1
  33. if ($url_id==1)
  34. $active=1;
  35. //checking url
  36. if (substr($url,strlen($url)-1, strlen($url))=='/') {
  37. UrlManager::udpate($url_id, $url, $description, $active);
  38. } else {
  39. UrlManager::udpate($url_id, $url.'/', $description, $active);
  40. }
  41. $url_to_go='access_urls.php';
  42. $message=get_lang('URLEdited');
  43. } else {
  44. $num = UrlManager::url_exist($url);
  45. if ($num == 0) {
  46. //checking url
  47. if (substr($url,strlen($url)-1, strlen($url))=='/') {
  48. UrlManager::add($url, $description, $active);
  49. } else {
  50. //create
  51. UrlManager::add($url.'/', $description, $active);
  52. }
  53. $message = get_lang('URLAdded');
  54. $url_to_go='access_urls.php';
  55. } else {
  56. $url_to_go='access_url_edit.php';
  57. $message = get_lang('URLAlreadyAdded');
  58. }
  59. }
  60. Security::clear_token();
  61. $tok = Security::get_token();
  62. header('Location: '.$url_to_go.'?action=show_message&message='.urlencode($message).'&sec_token='.$tok);
  63. exit();
  64. }
  65. } else {
  66. if(isset($_POST['submit'])) {
  67. Security::clear_token();
  68. }
  69. $token = Security::get_token();
  70. $form->addElement('hidden','sec_token');
  71. $form->setConstants(array('sec_token' => $token));
  72. }
  73. $form->addElement('text','url',get_lang('URL'),array('size'=>'30'));
  74. $form->addRule('url', get_lang('ThisFieldIsRequired'), 'required');
  75. $form->addRule('url', '', 'maxlength',254);
  76. $form->addElement('textarea','description',get_lang('Description'));
  77. //the first url with id = 1 will be always active
  78. if ($_GET['url_id'] != 1) {
  79. $form->addElement('checkbox','active',get_lang('Active'));
  80. }
  81. //$form->addRule('checkbox', get_lang('ThisFieldIsRequired'), 'required');
  82. $defaults['url']='http://';
  83. $form->setDefaults($defaults);
  84. $submit_name = get_lang('AddUrl');
  85. if (isset($_GET['url_id'])) {
  86. $url_id = Database::escape_string($_GET['url_id']);
  87. $num_url_id = UrlManager::url_id_exist($url_id);
  88. if($num_url_id != 1) {
  89. header('Location: access_urls.php');
  90. exit();
  91. }
  92. $url_data = UrlManager::get_url_data_from_id($url_id);
  93. $form->addElement('hidden','id',$url_data['id']);
  94. $form->setDefaults($url_data);
  95. $submit_name = get_lang('AddUrl');
  96. }
  97. if (!$_configuration['multiple_access_urls'])
  98. header('Location: index.php');
  99. $tool_name = get_lang('AddUrl');
  100. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  101. $interbreadcrumb[] = array ("url" => 'access_urls.php', "name" => get_lang('MultipleAccessURLs'));
  102. Display :: display_header($tool_name);
  103. if (isset ($_GET['action'])) {
  104. switch ($_GET['action']) {
  105. case 'show_message' :
  106. Display :: display_normal_message(stripslashes($_GET['message']));
  107. break;
  108. }
  109. }
  110. // Submit button
  111. $form->addElement('style_submit_button', 'submit', $submit_name, 'class="add"');
  112. $form->display();