index.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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',null,null,null,array('onLoad'=>'load();', 'onunload'=>'GUnload();'));
  24. //$form = new FormValidator('add_url');
  25. $form = new FormValidator('form_mapa', null, null, null, array('onsubmit'=>'showAddress(this.address.value, this.zoom.value=parseFloat(this.zoom.value)); return false'));
  26. $url_type = 3;
  27. error_log(__LINE__);
  28. if( $form->validate()) {
  29. error_log(__LINE__);
  30. //$check = Security::check_token('post');
  31. //if($check) {
  32. error_log(__LINE__);
  33. $url_array = $form->getSubmitValues();
  34. $url = Security::remove_XSS($url_array['url']);
  35. $description = Security::remove_XSS($url_array['description']);
  36. $active = 0;
  37. $url_id = $url_array['id'];
  38. $url_to_go='index.php';
  39. if ($url_id!='') {
  40. error_log(__LINE__);
  41. //we can't change the status of the url with id=1
  42. if ($url_id==1) {
  43. $active=1;
  44. }
  45. //checking url
  46. if (substr($url,-1)=='/') {
  47. $url.='/';
  48. }
  49. UrlManager::udpate($url_id, $url, $description, $active, $url_array['url_type'], $url_array);
  50. /*
  51. // URL Images
  52. $url_images_dir = api_get_path(SYS_PATH).'custompages/url-images/';
  53. $image_fields = array("url_image_1", "url_image_2", "url_image_3");
  54. foreach ($image_fields as $image_field) {
  55. if ($_FILES[$image_field]['error'] == 0) {
  56. // Hardcoded: only PNG files allowed
  57. if (end(explode('.', $_FILES[$image_field]['name'])) == 'png') {
  58. move_uploaded_file($_FILES[$image_field]['tmp_name'], $url_images_dir.$url_id.'_'.$image_field.'.png');
  59. }
  60. // else fail silently
  61. }
  62. // else fail silently
  63. }
  64. */
  65. $url_to_go='index.php';
  66. $message=get_lang('URLEdited');
  67. } else {
  68. error_log(__LINE__);
  69. $num = UrlManager::url_exist($url);
  70. if ($num == 0) {
  71. //checking url
  72. if (substr($url,-1)=='/') {
  73. $url .= '/';
  74. }
  75. error_log(__LINE__);
  76. UrlManager::add($url, $description, $active, $url_type, $url_array);
  77. $message = get_lang('URLAdded');
  78. $url_to_go='index.php';
  79. } else {
  80. $url_to_go='index.php';
  81. $message = get_lang('URLAlreadyAdded');
  82. }
  83. // URL Images
  84. $url .= (substr($url,-1)=='/') ? '' : '/';
  85. $url_id = UrlManager::get_url_id($url);
  86. /*
  87. $url_images_dir = api_get_path(SYS_PATH).'custompages/url-images/';
  88. $image_fields = array("url_image_1", "url_image_2", "url_image_3");
  89. foreach ($image_fields as $image_field) {
  90. if ($_FILES[$image_field]['error'] == 0) {
  91. // Hardcoded: only PNG files allowed
  92. if (end(explode('.', $_FILES[$image_field]['name'])) == 'png') {
  93. move_uploaded_file($_FILES[$image_field]['tmp_name'], $url_images_dir.$url_id.'_'.$image_field.'.png');
  94. }
  95. // else fail silently
  96. }
  97. // else fail silently
  98. }
  99. */
  100. }
  101. error_log(__LINE__);
  102. Security::clear_token();
  103. $tok = Security::get_token();
  104. header('Location: '.$url_to_go.'?action=show_message&message='.urlencode($message));//.'&sec_token='.$tok);
  105. exit();
  106. // }
  107. } else {
  108. error_log(__LINE__);
  109. /*
  110. if(isset($_POST['submit'])) {
  111. Security::clear_token();
  112. }
  113. $token = Security::get_token();
  114. $form->addElement('hidden','sec_token');
  115. $form->setConstants(array('sec_token' => $token));
  116. */
  117. }
  118. //$form->addRule('url', get_lang('ThisFieldIsRequired'), 'required');
  119. //$form->addRule('url', '', 'maxlength',254);
  120. $form->addElement('text', 'name', get_lang('InstitutionName'));
  121. $form->addElement('text', 'url', get_lang('IPAddress'));
  122. //$form->addElement('text', 'ip', get_lang('IPAddress'));
  123. $form->addElement('hidden', 'latitude', get_lang('Latitude'), array('id' => 'latitude'));
  124. $form->addElement('hidden', 'longitude', get_lang('Longitude'), array('id' => 'longitude'));
  125. $form->addElement('hidden', 'zoom', 15);
  126. $html = '
  127. <div style="width: 350px; border-width: 1px; border-style: solid; border-color: #979797; padding:8px 8px 8px 8px;">
  128. <div id="map" style="width: 350px; height: 350px"></div></div>
  129. ';
  130. $form->addElement('html',$html);
  131. $form->addElement('hidden', 'dwn_speed', get_lang('DownloadSpeed'), array('id' => 'dwn_speed_input'));
  132. $form->addElement('hidden', 'up_speed', get_lang('UploadSpeed'), array('id' => 'up_speed_input'));
  133. $form->addElement('hidden', 'delay', get_lang('ConnectionDelay'), array('id' => 'delay_input'));
  134. $form->addElement('text', 'admin_mail', get_lang('AdministratorEmail'));
  135. $form->addElement('text', 'admin_name', get_lang('AdministratorFullname'));
  136. $form->addElement('text', 'admin_phone', get_lang('AdministratorPhone'));
  137. $form->addElement('textarea','description',get_lang('Note'));
  138. //$form->addRule('checkbox', get_lang('ThisFieldIsRequired'), 'required');
  139. //$defaults['url']='http://';
  140. $defaults['url'] = $_SERVER['REMOTE_ADDR'];
  141. //$defaults['admin_mail'] = api_get_setting('emailAdministrator');
  142. //$defaults['admin_name'] = api_get_setting('administratorSurname').', '.api_get_setting('administratorName');
  143. //$defaults['admin_phone'] = api_get_setting('administratorTelephone');
  144. $form->setDefaults($defaults);
  145. $submit_name = get_lang('SentSincroClientData');
  146. if (isset($_GET['url_id'])) {
  147. $url_id = Database::escape_string($_GET['url_id']);
  148. $num_url_id = UrlManager::url_id_exist($url_id);
  149. if($num_url_id != 1) {
  150. header('Location: access_urls.php');
  151. exit();
  152. }
  153. $url_data = UrlManager::get_url_data_from_id($url_id);
  154. $form->addElement('hidden','id',$url_data['id']);
  155. $form->setDefaults($url_data);
  156. $submit_name = get_lang('AddUrl');
  157. }
  158. if (!$_configuration['multiple_access_urls'])
  159. header('Location: index.php');
  160. $tool_name = get_lang('SpeedTest');
  161. //$interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  162. //$interbreadcrumb[] = array ("url" => 'access_urls.php', "name" => get_lang('MultipleAccessURLs'));
  163. /**
  164. * View
  165. */
  166. //<script type="text/javascript" src="jquery-1.3.1.min.js"></script>
  167. //<script type="text/javascript" src="ui.core.min.js"></script>
  168. //<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAGAEGVZIXwwutieHF4QOL4RRpYoRN0FKJQ7RZd_AzeNEq2PLjZhR3W4-qrIA2KyJ0hRw-barmpbORVQ" type="text/javascript"></script>
  169. $htmlHeadXtra[] = <<<EOB
  170. <link rel="stylesheet" href="css/style.css" type="text/css" />
  171. <script type="text/javascript" src="jquery.query-2.0.1.js"></script>
  172. <script type="text/javascript" src="ui.progressbar.min.js"></script>
  173. <script type="text/javascript" src="config.js"></script>
  174. <script type="text/javascript" src="motor.js"></script>
  175. <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=AIzaSyC7n899gO-g5r7r2cxx_E3fU8Xi7T33BLo" type="text/javascript"></script>
  176. <script>
  177. var map = null;
  178. var geocoder = null;
  179. $(window).load(function () {
  180. if (GBrowserIsCompatible()) { // Abre LLAVE 2.
  181. map = new GMap2(document.getElementById("map"));
  182. map.setCenter(new GLatLng(-10.9755,-74.9757), 6);
  183. map.addControl(new GSmallMapControl());
  184. map.addControl(new GMapTypeControl());
  185. geocoder = new GClientGeocoder();
  186. //---------------------------------//
  187. // MARCADOR AL HACER CLICK
  188. GEvent.addListener(map, "click",
  189. function(marker, point) {
  190. if (marker) {
  191. null;
  192. } else {
  193. map.clearOverlays();
  194. var marcador = new GMarker(point);
  195. map.addOverlay(marcador);
  196. $('#latitude').val(point.y);
  197. $('#longitude').val(point.x);
  198. }
  199. }
  200. );
  201. //---------------------------------//
  202. // FIN MARCADOR AL HACER CLICK
  203. //---------------------------------//
  204. } // Cierra LLAVE 1.
  205. });
  206. </script>
  207. EOB;
  208. Display :: display_header($tool_name);
  209. if (isset ($_GET['action'])) {
  210. switch ($_GET['action']) {
  211. case 'show_message' :
  212. Display :: display_normal_message(stripslashes($_GET['message']));
  213. break;
  214. }
  215. }
  216. // URL Images
  217. /*
  218. $form->addElement('file','url_image_1','URL Image 1 (PNG)');
  219. $form->addElement('file','url_image_2','URL Image 2 (PNG)');
  220. $form->addElement('file','url_image_3','URL Image 3 (PNG)');
  221. */
  222. // Submit button
  223. $form->addElement('style_submit_button', 'submit', $submit_name, array('class'=>"add hidden", 'id' => 'submit_url_button'));
  224. echo '<div class="normal-message">'.get_lang('SpeedTestIntroSection').'</div>';
  225. echo '<div id="pagesincro">';
  226. echo '<div class="form-column">';
  227. $form->display();
  228. echo '</div>';
  229. echo '<div class="anim-column" style="float: right;">';
  230. include 'body.php';
  231. echo '</div>';
  232. echo '</div>';
  233. Display :: display_footer();