PageRenderTime 26ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/submit_track.php

http://airscore.googlecode.com/
PHP | 331 lines | 323 code | 8 blank | 0 comment | 10 complexity | 61543f85ec8976d443b79fe55df184d4 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. require 'authorisation.php';
  3. require 'format.php';
  4. require 'hc.php';
  5. $comPk = reqival('comPk');
  6. $embed = reqsval('embed');
  7. $link = db_connect();
  8. $offerall = 0;
  9. if ($comPk < 2)
  10. {
  11. $offerall = 1;
  12. $comPk=1;
  13. }
  14. $comUnixTo = time();
  15. $query = "select *, unix_timestamp(comDateTo) as comUnixTo from tblCompetition where comPk=$comPk";
  16. $result = mysql_query($query) or die('Query failed: ' . mysql_error());
  17. $title = 'highcloud.net';
  18. $comContact = '';
  19. if ($row=mysql_fetch_array($result))
  20. {
  21. $title = $row['comName'];
  22. $comType = $row['comType'];
  23. $comClass = $row['comClass'];
  24. $comContact = $row['comContact'];
  25. $comUnixTo = $row['comUnixTo'];
  26. }
  27. if ($comContact == '')
  28. {
  29. $comContact = 'your competition organiser';
  30. }
  31. if (array_key_exists('foo', $_REQUEST))
  32. {
  33. $fh = fopen("/tmp/submit24", "w");
  34. foreach ($_REQUEST as $k=>$v)
  35. {
  36. fwrite($fh, "key=$k, value$v\n");
  37. }
  38. fclose($fh);
  39. echo "<title>Track Accepted</title>\n";
  40. $id = accept_track($comUnixTo, $comContact);
  41. redirect("tracklog_map.php?trackid=$id&comPk=$comPk&ok=1");
  42. exit(0);
  43. }
  44. if ($embed == '')
  45. {
  46. hcheader($title, 1, "");
  47. echo "<div id=\"content\">";
  48. echo "<div id=\"text\">";
  49. }
  50. else
  51. {
  52. echo "<html><head>";
  53. echo "<link HREF=\"$embed\" REL=\"stylesheet\" TYPE=\"text/css\">\n";
  54. echo "</head><body><div id=\"track_submit\">\n";
  55. }
  56. ?>
  57. <h1>Tracklog Submission</h1>
  58. Download your GPS track from your GPS using one of the free
  59. programs shown on the right. Then you're ready to upload the
  60. .IGC file created to this website using the form here!
  61. <br><br>
  62. <?php
  63. function upload_track($file,$pilPk,$contact)
  64. {
  65. # Let the Perl program do it!
  66. $out = '';
  67. $retv = 0;
  68. $traPk = 0;
  69. exec(BINDIR . "igcreader.pl $file $pilPk", $out, $retv);
  70. if ($retv)
  71. {
  72. echo "<b>Failed to upload your track, it appears to have been submitted previously.</b><br>\n";
  73. echo "Contact $contact if this was a valid track.<br>\n";
  74. foreach ($out as $txt)
  75. {
  76. echo "$txt<br>\n";
  77. }
  78. echo "</div></body></html>\n";
  79. exit(0);
  80. }
  81. foreach ($out as $row)
  82. {
  83. if (substr_compare("traPk=6", $row, 0, 6) == 0)
  84. {
  85. $traPk = 0 + substr($row, 6);
  86. break;
  87. }
  88. }
  89. return $traPk;
  90. }
  91. function task_score($traPk)
  92. {
  93. # Let the Perl program do it!
  94. $out = '';
  95. $retv = 0;
  96. exec(BINDIR . "track_verify_sr.pl $traPk", $out, $retv);
  97. return $retv;
  98. }
  99. function accept_track($until, $contact)
  100. {
  101. //$file = addslashes($_REQUEST['userfile']);
  102. $hgfa = addslashes($_REQUEST['hgfanum']);
  103. $name = strtolower($_REQUEST['lastname']);
  104. $route = reqival('route');
  105. $comid = reqival('comid');
  106. $link = db_connect();
  107. $query = "select pilPk, pilHGFA from tblPilot where pilLastName='$name'";
  108. $result = mysql_query($query) or die('Query failed: ' . mysql_error());
  109. $member = 0;
  110. while ($row=mysql_fetch_array($result))
  111. {
  112. if ($hgfa == $row['pilHGFA'])
  113. {
  114. $pilPk = $row['pilPk'];
  115. $member = 1;
  116. }
  117. }
  118. if (time() > ($until + 7*24*3600))
  119. {
  120. echo "<b>The submission period for tracks has closed ($until).</b><br>\n";
  121. echo "Contact $contact if you're having an access problem.<br>\n";
  122. echo "</div></body></html>\n";
  123. exit(0);
  124. }
  125. if ($member == 0)
  126. {
  127. echo "<b>Only registered pilot may submit tracks.</b><br>\n";
  128. echo "Contact $contact if you're having an access problem.<br>\n";
  129. echo "</div></body></html>\n";
  130. exit(0);
  131. }
  132. // Copy the upload so I can use it later ..
  133. $dte = date("Y-m-d_Hms");
  134. $yr = date("Y");
  135. $copyname = FILEDIR . $yr . "/" . $name . "_" . $hgfa . "_" . $dte;
  136. copy($_FILES['userfile']['tmp_name'], $copyname);
  137. chmod($copyname, 0644);
  138. // Process the file
  139. $maxPk = upload_track($_FILES['userfile']['tmp_name'], $pilPk, $comContact);
  140. $tasPk = 'null';
  141. $tasType = '';
  142. $comType = '';
  143. $turnpoints = '';
  144. if ($route > 0)
  145. {
  146. $tasPk = $route;
  147. }
  148. else
  149. {
  150. $query = "select T.tasPk, T.tasTaskType, C.comType from tblTask T, tblTrack TL, tblCompetition C where C.comPk=T.comPk and T.comPk=$comid and TL.traPk=$maxPk and TL.traStart > date_sub(T.tasDate, interval C.comTimeOffset hour) and TL.traStart < date_add(T.tasDate, interval (24-C.comTimeOffset) hour)";
  151. $result = mysql_query($query) or die('Query failed: ' . mysql_error());
  152. if (mysql_num_rows($result) > 0)
  153. {
  154. $tasPk=mysql_result($result,0,0);
  155. $tasType=mysql_result($result,0,1);
  156. $comType=mysql_result($result,0,2);
  157. }
  158. }
  159. $query = "insert into tblComTaskTrack (comPk,tasPk,traPk) values ($comid,$tasPk,$maxPk)";
  160. $result = mysql_query($query) or die('ComTaskTrack failed: ' . mysql_error());
  161. $out = '';
  162. $retv = 0;
  163. if ($tasPk != 'null')
  164. {
  165. $turnpoints = '3';
  166. if ($tasType == 'free')
  167. {
  168. $turnpoints = '0';
  169. }
  170. exec(BINDIR . "optimise_flight.pl $maxPk $tasPk $turnpoints", $out, $retv);
  171. }
  172. else
  173. {
  174. if ($comType == 'Free')
  175. {
  176. $turnpoints = '0';
  177. exec(BINDIR . "optimise_flight.pl $maxPk 0 $turnpoints", $out, $retv);
  178. }
  179. else
  180. {
  181. echo "optimise_flight.pl $maxPk<br>";
  182. exec(BINDIR . "optimise_flight.pl $maxPk", $out, $retv);
  183. }
  184. }
  185. if ($retv)
  186. {
  187. echo "<b>Failed to optimise your track correctly.</b><br>\n";
  188. echo "Contact $contact if this was a valid track.<br>\n";
  189. foreach ($out as $txt)
  190. {
  191. echo "$txt<br>\n";
  192. }
  193. echo "</div></body></html>\n";
  194. exit(0);
  195. }
  196. $glider = addslashes($_REQUEST['glider']);
  197. $dhv = addslashes($_REQUEST['dhv']);
  198. $query = "update tblTrack set traGlider='$glider', traDHV='$dhv' where traPk=$maxPk";
  199. $result = mysql_query($query) or die('Update tblTrack failed: ' . mysql_error());
  200. if ($tasPk != 'null')
  201. {
  202. if ($tasType == 'speedrun' || $tasType == 'race' || $tasType =='speedrun-interval')
  203. {
  204. task_score($maxPk);
  205. }
  206. elseif ($tasType == 'airgain')
  207. {
  208. exec(BINDIR . "airgain_verify.pl $maxPk $comid $tasPk", $out, $retv);
  209. }
  210. }
  211. return $maxPk;
  212. }
  213. echo "<form enctype=\"multipart/form-data\" action=\"submit_track.php?comPk=$comPk\" method=\"post\">";
  214. echo '
  215. <input type="hidden" name="MAX_FILE_SIZE" value="1000000000">
  216. ';
  217. $igcarr = array();
  218. if ($offerall)
  219. {
  220. $comps = array();
  221. $query = "select * from tblCompetition where curdate() < date_add(comDateTo, interval 3 day)";
  222. $result = mysql_query($query) or die('Query failed: ' . mysql_error());
  223. while($row = mysql_fetch_array($result))
  224. {
  225. $comName = $row['comName'];
  226. $compid = $row['comPk'];
  227. $comps[$comName] = $compid;
  228. }
  229. $igcarr[] = array('Competition', fselect('comid', $comPk, $comps));
  230. }
  231. else
  232. {
  233. echo("<input type=\"hidden\" name=\"comid\" value=\"$comPk\">");
  234. }
  235. if ($comType == 'Route')
  236. {
  237. $query = "select * from tblTask where comPk=$comPk";
  238. $result = mysql_query($query) or die('Route query failed: ' . mysql_error());
  239. $routes = array();
  240. while($row = mysql_fetch_array($result))
  241. {
  242. $routes[] = $row['tasName'];
  243. }
  244. //echo '</td><td>';
  245. $igcarr[] = array('Route', fselect('route', $comPk, $routes));
  246. }
  247. $igcarr[] = array('Send IGC file', "<input name=\"userfile\" type=\"file\">");
  248. $igcarr[] = array('HGFA Number', "<input name=\"hgfanum\" type=\"text\">");
  249. $igcarr[] = array('Last Name', "<input name=\"lastname\" type=\"text\">");
  250. if ($comClass == 'PG')
  251. {
  252. $classarr = fselect('dhv', 'competition', array('novice' => '1', 'fun' => '1/2', 'sports' => '2', 'serial' => '2/3', 'competition' => 'competition' ));
  253. }
  254. elseif ($comClass == 'HG')
  255. {
  256. $classarr = fselect('dhv', 'open', array('floater' => 'floater', 'kingpost' => 'kingpost', 'open' => 'open', 'rigid' => 'rigid' ));
  257. }
  258. else
  259. {
  260. $classarr = fselect('dhv', '2', array('pg-novice' => '1', 'pg-fun' => '1/2', 'pg-sport' => '2', 'pg-serial' => '2/3', 'pg-comp' => 'competition', 'hg-floater' => 'floater', 'hg-kingpost' => 'kingpost', 'hg-open' => 'open', 'hg-rigid' => 'rigid' ));
  261. }
  262. $igcarr[] = array('Glider', '<input name="glider" type="text">', $classarr);
  263. echo ftable($igcarr, '', '', '');
  264. echo '<br><center><input type="submit" name="foo" value="Send Tracklog"></center>';
  265. if ($embed == '')
  266. {
  267. echo "</div>";
  268. echo "<div id=\"sideBar\">";
  269. echo "<h1>GPS Downloaders</h1>";
  270. $gpsarr = array(
  271. "<a href=\"http://www.gethome.no/stein.sorensen/body_gpsdump.htm\">GPSDump</a>",
  272. "<a href=\"http://flighttrack.sourceforge.net/\">FlightTrack (MacOS X)</a>",
  273. "<a href=\"http://www.gpsbabel.org/\">GPS Babel</a>",
  274. "<b><a href=\"http://www.freethinker.com/iphone/livetrack24/index.html\">Livetrack 24 (*iOS*)</a></b>",
  275. );
  276. echo fnl($gpsarr);
  277. hcopencomps($link);
  278. hcclosedcomps($link);
  279. echo "</div>";
  280. hcimage($link,$comPk);
  281. hcfooter();
  282. echo "</div>";
  283. }
  284. else
  285. {
  286. echo "</div>";
  287. }
  288. mysql_close($link);
  289. echo "</body></html>\n";
  290. ?>