access_url_edit.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. if (!$_configuration['multiple_access_urls']) {
  13. header('Location: index.php');
  14. }
  15. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  16. require_once api_get_path(LIBRARY_PATH).'security.lib.php';
  17. require_once api_get_path(LIBRARY_PATH).'urlmanager.lib.php';
  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. //checking url
  34. if (substr($url,strlen($url)-1, strlen($url))=='/') {
  35. UrlManager::udpate($url_id, $url, $description, $active);
  36. } else {
  37. UrlManager::udpate($url_id, $url.'/', $description, $active);
  38. }
  39. $url_to_go='access_urls.php';
  40. $message=get_lang('URLEdited');
  41. } else {
  42. $num = UrlManager::url_exist($url);
  43. if ($num == 0) {
  44. //checking url
  45. if (substr($url,strlen($url)-1, strlen($url))=='/') {
  46. UrlManager::add($url, $description, $active);
  47. } else {
  48. //create
  49. UrlManager::add($url.'/', $description, $active);
  50. }
  51. $message = get_lang('URLAdded');
  52. $url_to_go='access_urls.php';
  53. } else {
  54. $url_to_go='access_url_edit.php';
  55. $message = get_lang('URLAlreadyAdded');
  56. }
  57. }
  58. Security::clear_token();
  59. $tok = Security::get_token();
  60. header('Location: '.$url_to_go.'?action=show_message&message='.urlencode($message).'&sec_token='.$tok);
  61. exit();
  62. }
  63. } else {
  64. if(isset($_POST['submit'])) {
  65. Security::clear_token();
  66. }
  67. $token = Security::get_token();
  68. $form->addElement('hidden','sec_token');
  69. $form->setConstants(array('sec_token' => $token));
  70. }
  71. $form->addElement('text','url',get_lang('URL'),array('size'=>'30'));
  72. $form->addRule('url', get_lang('ThisFieldIsRequired'), 'required');
  73. $form->addRule('url', '', 'maxlength',254);
  74. $form->addElement('textarea','description',get_lang('Description'));
  75. //the first url with id = 1 will be always active
  76. if ($_GET['url_id'] != 1) {
  77. $form->addElement('checkbox','active',get_lang('Active'));
  78. }
  79. //$form->addRule('checkbox', get_lang('ThisFieldIsRequired'), 'required');
  80. $defaults['url']='http://';
  81. $form->setDefaults($defaults);
  82. $submit_name = get_lang('Add');
  83. if (isset($_GET['url_id'])) {
  84. $url_id = Database::escape_string($_GET['url_id']);
  85. $num_url_id = UrlManager::url_id_exist($url_id);
  86. if($num_url_id != 1) {
  87. header('Location: access_urls.php');
  88. exit();
  89. }
  90. $url_data = UrlManager::get_url_data_from_id($url_id);
  91. $form->addElement('hidden','id',$url_data['id']);
  92. $form->setDefaults($url_data);
  93. $submit_name = get_lang('Edit');
  94. }
  95. if (!$_configuration['multiple_access_urls'])
  96. header('Location: index.php');
  97. $tool_name = get_lang('AddUrl');
  98. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  99. $interbreadcrumb[] = array ("url" => 'access_urls.php', "name" => get_lang('MultipleAccessURLs'));
  100. Display :: display_header($tool_name);
  101. if (isset ($_GET['action'])) {
  102. switch ($_GET['action']) {
  103. case 'show_message' :
  104. Display :: display_normal_message(stripslashes($_GET['message']));
  105. break;
  106. }
  107. }
  108. // Submit button
  109. $form->addElement('style_submit_button', 'submit', $submit_name, 'class="add"');
  110. $form->display();