synchro.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. * @todo replace this folder with a controller
  12. */
  13. $language_file = 'admin';
  14. $cidReset = true;
  15. require_once '../main/inc/global.inc.php';
  16. $this_section = SECTION_GLOBAL;
  17. //api_protect_admin_script();
  18. //api_protect_global_admin_script();
  19. if (!api_get_multiple_access_url()) {
  20. header('Location: ../index.php');
  21. exit;
  22. }
  23. // Create the form
  24. $form = new FormValidator('add_url');
  25. //
  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', 'dwn_speed', get_lang('DownloadSpeed'), array('id' => 'dwn_speed_input'));
  126. $form->addElement('hidden', 'up_speed', get_lang('UploadSpeed'), array('id' => 'up_speed_input'));
  127. $form->addElement('hidden', 'delay', get_lang('ConnectionDelay'), array('id' => 'delay_input'));
  128. $form->addElement('text', 'admin_mail', get_lang('AdministratorEmail'));
  129. $form->addElement('text', 'admin_name', get_lang('AdministratorFullname'));
  130. $form->addElement('text', 'admin_phone', get_lang('AdministratorPhone'));
  131. $form->addElement('textarea','description',get_lang('Note'));
  132. //$form->addRule('checkbox', get_lang('ThisFieldIsRequired'), 'required');
  133. //$defaults['url']='http://';
  134. $defaults['url'] = $_SERVER['REMOTE_ADDR'];
  135. //$defaults['admin_mail'] = api_get_setting('emailAdministrator');
  136. //$defaults['admin_name'] = api_get_setting('administratorSurname').', '.api_get_setting('administratorName');
  137. //$defaults['admin_phone'] = api_get_setting('administratorTelephone');
  138. $form->setDefaults($defaults);
  139. $submit_name = get_lang('SentSincroClientData');
  140. if (isset($_GET['url_id'])) {
  141. $url_id = Database::escape_string($_GET['url_id']);
  142. $num_url_id = UrlManager::url_id_exist($url_id);
  143. if($num_url_id != 1) {
  144. header('Location: access_urls.php');
  145. exit();
  146. }
  147. $url_data = UrlManager::get_url_data_from_id($url_id);
  148. $form->addElement('hidden','id',$url_data['id']);
  149. $form->setDefaults($url_data);
  150. $submit_name = get_lang('AddUrl');
  151. }
  152. if (!$_configuration['multiple_access_urls'])
  153. header('Location: index.php');
  154. $tool_name = get_lang('SpeedTest');
  155. //$interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  156. //$interbreadcrumb[] = array ("url" => 'access_urls.php', "name" => get_lang('MultipleAccessURLs'));
  157. /**
  158. * View
  159. */
  160. //<script type="text/javascript" src="jquery-1.3.1.min.js"></script>
  161. //<script type="text/javascript" src="ui.core.min.js"></script>
  162. $htmlHeadXtra[] = <<<EOB
  163. <link rel="stylesheet" href="css/style.css" type="text/css" />
  164. <script type="text/javascript" src="jquery.query-2.0.1.js"></script>
  165. <script type="text/javascript" src="ui.progressbar.min.js"></script>
  166. <script type="text/javascript" src="config.js"></script>
  167. <script type="text/javascript" src="motor.js"></script>
  168. EOB;
  169. Display :: display_header($tool_name);
  170. if (isset ($_GET['action'])) {
  171. switch ($_GET['action']) {
  172. case 'show_message' :
  173. Display :: display_normal_message(stripslashes($_GET['message']));
  174. break;
  175. }
  176. }
  177. // URL Images
  178. /*
  179. $form->addElement('file','url_image_1','URL Image 1 (PNG)');
  180. $form->addElement('file','url_image_2','URL Image 2 (PNG)');
  181. $form->addElement('file','url_image_3','URL Image 3 (PNG)');
  182. */
  183. // Submit button
  184. $form->addElement('style_submit_button', 'submit', $submit_name, array('class'=>"add hidden", 'id' => 'submit_url_button'));
  185. echo '<div class="normal-message">'.get_lang('SpeedTestIntroSection').'</div>';
  186. echo '<div id="pagesincro">';
  187. echo '<div class="form-column">';
  188. $form->display();
  189. echo '</div>';
  190. echo '<div class="anim-column" style="float: right;">';
  191. include 'body.php';
  192. echo '</div>';
  193. echo '</div>';
  194. Display :: display_footer();