access_url_edit.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2009 Dokeos SPRL
  6. Copyright (c) 2009 Julio Montoya Armas <gugli100@gmail.com>
  7. For a full list of contributors, see "credits.txt".
  8. The full license can be read in "license.txt".
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13. See the GNU General Public License for more details.
  14. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  15. Mail: info@dokeos.com
  16. ==============================================================================
  17. */
  18. /**
  19. ==============================================================================
  20. * @package dokeos.admin
  21. ==============================================================================
  22. */
  23. $language_file = 'admin';
  24. $cidReset = true;
  25. require ('../inc/global.inc.php');
  26. $this_section = SECTION_PLATFORM_ADMIN;
  27. api_protect_admin_script();
  28. if (!$_configuration['multiple_access_urls'])
  29. header('Location: index.php');
  30. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  31. require_once (api_get_path(LIBRARY_PATH).'security.lib.php');
  32. require_once (api_get_path(LIBRARY_PATH).'urlmanager.lib.php');
  33. // Create the form
  34. $form = new FormValidator('add_url');
  35. if( $form->validate()) {
  36. $check = Security::check_token('post');
  37. if($check) {
  38. $url_array = $form->getSubmitValues();
  39. $url = Security::remove_XSS($url_array['url']);
  40. $description = Security::remove_XSS($url_array['description']);
  41. $active = intval($url_array['active']);
  42. $url_id = $url_array['id'];
  43. $url_to_go='access_urls.php';
  44. if ($url_id!='') {
  45. //we can't change the status of the url with id=1
  46. if ($url_id==1)
  47. $active=1;
  48. //checking url
  49. if (substr($url,strlen($url)-1, strlen($url))=='/') {
  50. UrlManager::udpate($url_id, $url, $description, $active);
  51. } else {
  52. UrlManager::udpate($url_id, $url.'/', $description, $active);
  53. }
  54. $url_to_go='access_urls.php';
  55. $message=get_lang('URLEdited');
  56. } else {
  57. $num = UrlManager::url_exist($url);
  58. if ($num == 0) {
  59. //checking url
  60. if (substr($url,strlen($url)-1, strlen($url))=='/') {
  61. UrlManager::add($url, $description, $active);
  62. } else {
  63. //create
  64. UrlManager::add($url.'/', $description, $active);
  65. }
  66. $message = get_lang('URLAdded');
  67. $url_to_go='access_urls.php';
  68. } else {
  69. $url_to_go='access_url_edit.php';
  70. $message = get_lang('URLAlreadyAdded');
  71. }
  72. }
  73. Security::clear_token();
  74. $tok = Security::get_token();
  75. header('Location: '.$url_to_go.'?action=show_message&message='.urlencode($message).'&sec_token='.$tok);
  76. exit();
  77. }
  78. }
  79. else
  80. {
  81. if(isset($_POST['submit'])) {
  82. Security::clear_token();
  83. }
  84. $token = Security::get_token();
  85. $form->addElement('hidden','sec_token');
  86. $form->setConstants(array('sec_token' => $token));
  87. }
  88. $form->addElement('text','url',get_lang('URL'),array('size'=>'30'));
  89. $form->addRule('url', get_lang('ThisFieldIsRequired'), 'required');
  90. $form->addRule('url', '', 'maxlength',254);
  91. $form->addElement('textarea','description',get_lang('Description'));
  92. $form->addElement('checkbox','active',get_lang('Active'));
  93. $form->addRule('checkbox', get_lang('ThisFieldIsRequired'), 'required');
  94. $defaults['url']='http://';
  95. $form->setDefaults($defaults);
  96. $submit_name = get_lang('Add');
  97. if (isset($_GET['url_id']))
  98. {
  99. $url_id = Database::escape_string($_GET['url_id']);
  100. $num_url_id = UrlManager::url_id_exist($url_id);
  101. if($num_url_id != 1)
  102. {
  103. header('Location: access_urls.php');
  104. exit();
  105. }
  106. $url_data = UrlManager::get_url_data_from_id($url_id);
  107. $form->addElement('hidden','id',$url_data['id']);
  108. $form->setDefaults($url_data);
  109. $submit_name = get_lang('Edit');
  110. }
  111. if (!$_configuration['multiple_access_urls'])
  112. header('Location: index.php');
  113. $tool_name = get_lang('AddUrl');
  114. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  115. $interbreadcrumb[] = array ("url" => 'access_urls.php', "name" => get_lang('MultipleAccessURLs'));
  116. Display :: display_header($tool_name);
  117. if (isset ($_GET['action']))
  118. {
  119. switch ($_GET['action'])
  120. {
  121. case 'show_message' :
  122. Display :: display_normal_message(stripslashes($_GET['message']));
  123. break;
  124. }
  125. }
  126. // Submit button
  127. $form->addElement('submit', 'submit', $submit_name);
  128. $form->display();
  129. ?>