index.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Allows anyone to upload synchronization data
  5. * @package chamilo.sincro
  6. * @author Julio Montoya <gugli100@gmail.com>
  7. * @author Yannick Warnier <yannick.warnier@beeznest.com>
  8. */
  9. /**
  10. * Initialization
  11. */
  12. $language_file = 'admin';
  13. $cidReset = true;
  14. require_once '../main/inc/global.inc.php';
  15. $this_section = SECTION_GLOBAL;
  16. //api_protect_admin_script();
  17. //api_protect_global_admin_script();
  18. if (!api_get_multiple_access_url()) {
  19. header('Location: ../index.php');
  20. exit;
  21. }
  22. // Create the form
  23. $form = new FormValidator('add_url');
  24. //
  25. $url_type = 3;
  26. error_log(__LINE__);
  27. if( $form->validate()) {
  28. error_log(__LINE__);
  29. //$check = Security::check_token('post');
  30. //if($check) {
  31. error_log(__LINE__);
  32. $url_array = $form->getSubmitValues();
  33. $url = Security::remove_XSS($url_array['url']);
  34. $description = Security::remove_XSS($url_array['description']);
  35. $active = 0;
  36. $url_id = $url_array['id'];
  37. $url_to_go='index.php';
  38. if ($url_id!='') {
  39. error_log(__LINE__);
  40. //we can't change the status of the url with id=1
  41. if ($url_id==1) {
  42. $active=1;
  43. }
  44. //checking url
  45. if (substr($url,-1)=='/') {
  46. $url.='/';
  47. }
  48. UrlManager::udpate($url_id, $url, $description, $active, $url_array['url_type'], $url_array);
  49. /*
  50. // URL Images
  51. $url_images_dir = api_get_path(SYS_PATH).'custompages/url-images/';
  52. $image_fields = array("url_image_1", "url_image_2", "url_image_3");
  53. foreach ($image_fields as $image_field) {
  54. if ($_FILES[$image_field]['error'] == 0) {
  55. // Hardcoded: only PNG files allowed
  56. if (end(explode('.', $_FILES[$image_field]['name'])) == 'png') {
  57. move_uploaded_file($_FILES[$image_field]['tmp_name'], $url_images_dir.$url_id.'_'.$image_field.'.png');
  58. }
  59. // else fail silently
  60. }
  61. // else fail silently
  62. }
  63. */
  64. $url_to_go='index.php';
  65. $message=get_lang('URLEdited');
  66. } else {
  67. error_log(__LINE__);
  68. $num = UrlManager::url_exist($url);
  69. if ($num == 0) {
  70. //checking url
  71. if (substr($url,-1)=='/') {
  72. $url .= '/';
  73. }
  74. error_log(__LINE__);
  75. UrlManager::add($url, $description, $active, $url_type, $url_array);
  76. $message = get_lang('URLAdded');
  77. $url_to_go='index.php';
  78. } else {
  79. $url_to_go='index.php';
  80. $message = get_lang('URLAlreadyAdded');
  81. }
  82. // URL Images
  83. $url .= (substr($url,-1)=='/') ? '' : '/';
  84. $url_id = UrlManager::get_url_id($url);
  85. /*
  86. $url_images_dir = api_get_path(SYS_PATH).'custompages/url-images/';
  87. $image_fields = array("url_image_1", "url_image_2", "url_image_3");
  88. foreach ($image_fields as $image_field) {
  89. if ($_FILES[$image_field]['error'] == 0) {
  90. // Hardcoded: only PNG files allowed
  91. if (end(explode('.', $_FILES[$image_field]['name'])) == 'png') {
  92. move_uploaded_file($_FILES[$image_field]['tmp_name'], $url_images_dir.$url_id.'_'.$image_field.'.png');
  93. }
  94. // else fail silently
  95. }
  96. // else fail silently
  97. }
  98. */
  99. }
  100. error_log(__LINE__);
  101. Security::clear_token();
  102. $tok = Security::get_token();
  103. header('Location: '.$url_to_go.'?action=show_message&message='.urlencode($message));//.'&sec_token='.$tok);
  104. exit();
  105. // }
  106. } else {
  107. error_log(__LINE__);
  108. /*
  109. if(isset($_POST['submit'])) {
  110. Security::clear_token();
  111. }
  112. $token = Security::get_token();
  113. $form->addElement('hidden','sec_token');
  114. $form->setConstants(array('sec_token' => $token));
  115. */
  116. }
  117. //$form->addRule('url', get_lang('ThisFieldIsRequired'), 'required');
  118. //$form->addRule('url', '', 'maxlength',254);
  119. $form->addElement('text', 'name', get_lang('InstitutionName'));
  120. $form->addElement('text', 'url', get_lang('IPAddress'));
  121. //$form->addElement('text', 'ip', get_lang('IPAddress'));
  122. $form->addElement('hidden', 'latitude', get_lang('Latitude'), array('id' => 'latitude'));
  123. $form->addElement('hidden', 'longitude', get_lang('Longitude'), array('id' => 'longitude'));
  124. $form->addElement('hidden', 'dwn_speed', get_lang('DownloadSpeed'), array('id' => 'dwn_speed_input'));
  125. $form->addElement('hidden', 'up_speed', get_lang('UploadSpeed'), array('id' => 'up_speed_input'));
  126. $form->addElement('hidden', 'delay', get_lang('ConnectionDelay'), array('id' => 'delay_input'));
  127. $form->addElement('text', 'admin_mail', get_lang('AdministratorEmail'));
  128. $form->addElement('text', 'admin_name', get_lang('AdministratorFullname'));
  129. $form->addElement('text', 'admin_phone', get_lang('AdministratorPhone'));
  130. $form->addElement('textarea','description',get_lang('Note'));
  131. //$form->addRule('checkbox', get_lang('ThisFieldIsRequired'), 'required');
  132. //$defaults['url']='http://';
  133. $defaults['url'] = $_SERVER['REMOTE_ADDR'];
  134. //$defaults['admin_mail'] = api_get_setting('emailAdministrator');
  135. //$defaults['admin_name'] = api_get_setting('administratorSurname').', '.api_get_setting('administratorName');
  136. //$defaults['admin_phone'] = api_get_setting('administratorTelephone');
  137. $form->setDefaults($defaults);
  138. $submit_name = get_lang('SentSincroClientData');
  139. if (isset($_GET['url_id'])) {
  140. $url_id = Database::escape_string($_GET['url_id']);
  141. $num_url_id = UrlManager::url_id_exist($url_id);
  142. if($num_url_id != 1) {
  143. header('Location: access_urls.php');
  144. exit();
  145. }
  146. $url_data = UrlManager::get_url_data_from_id($url_id);
  147. $form->addElement('hidden','id',$url_data['id']);
  148. $form->setDefaults($url_data);
  149. $submit_name = get_lang('AddUrl');
  150. }
  151. if (!$_configuration['multiple_access_urls'])
  152. header('Location: index.php');
  153. $tool_name = get_lang('SpeedTest');
  154. //$interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  155. //$interbreadcrumb[] = array ("url" => 'access_urls.php', "name" => get_lang('MultipleAccessURLs'));
  156. /**
  157. * View
  158. */
  159. //<script type="text/javascript" src="jquery-1.3.1.min.js"></script>
  160. //<script type="text/javascript" src="ui.core.min.js"></script>
  161. $htmlHeadXtra[] = <<<EOB
  162. <link rel="stylesheet" href="css/style.css" type="text/css" />
  163. <script type="text/javascript" src="jquery.query-2.0.1.js"></script>
  164. <script type="text/javascript" src="ui.progressbar.min.js"></script>
  165. <script type="text/javascript" src="config.js"></script>
  166. <script type="text/javascript" src="motor.js"></script>
  167. EOB;
  168. Display :: display_header($tool_name);
  169. if (isset ($_GET['action'])) {
  170. switch ($_GET['action']) {
  171. case 'show_message' :
  172. Display :: display_normal_message(stripslashes($_GET['message']));
  173. break;
  174. }
  175. }
  176. // URL Images
  177. /*
  178. $form->addElement('file','url_image_1','URL Image 1 (PNG)');
  179. $form->addElement('file','url_image_2','URL Image 2 (PNG)');
  180. $form->addElement('file','url_image_3','URL Image 3 (PNG)');
  181. */
  182. // Submit button
  183. $form->addElement('style_submit_button', 'submit', $submit_name, array('class'=>"add hidden", 'id' => 'submit_url_button'));
  184. echo '<div class="normal-message">'.get_lang('SpeedTestIntroSection').'</div>';
  185. echo '<div id="pagesincro">';
  186. echo '<div class="form-column">';
  187. $form->display();
  188. echo '</div>';
  189. echo '<div class="anim-column" style="float: right;">';
  190. include 'body.php';
  191. echo '</div>';
  192. echo '</div>';
  193. Display :: display_footer();