forked from leonardoxc/leonardoxc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FN_flight.php
715 lines (610 loc) · 22.2 KB
/
FN_flight.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
<?
//************************************************************************
// Leonardo XC Server, http://www.leonardoxc.net
//
// Copyright (c) 2004-2010 by Andreadakis Manolis
//
// This program is free software. You can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License.
//
// $Id: FN_flight.php,v 1.61 2012/06/02 08:40:12 manolis Exp $
//
//************************************************************************
require_once dirname(__FILE__).'/FN_functions.php';
require_once dirname(__FILE__).'/FN_output.php';
require_once dirname(__FILE__).'/CL_flightData.php';
require_once dirname(__FILE__).'/CL_image.php';
require_once dirname(__FILE__).'/CL_pilot.php';
define("ADD_FLIGHT_ERR_YOU_HAVENT_SUPPLIED_A_FLIGHT_FILE",-1);
define("ADD_FLIGHT_ERR_NO_SUCH_FILE",-2);
define("ADD_FLIGHT_ERR_FILE_DOESNT_END_IN_IGC",-3);
define("ADD_FLIGHT_ERR_THIS_ISNT_A_VALID_IGC_FILE",-4);
define("ADD_FLIGHT_ERR_SAME_DATE_FLIGHT",-5);
define("ADD_FLIGHT_ERR_SAME_FILENAME_FLIGHT",-6);
define("ADD_FLIGHT_ERR_DATE_IN_THE_FUTURE",-7);
define("ADD_FLIGHT_ERR_SAME_HASH_FLIGHT",-8);
define("ADD_FLIGHT_ERR_OUTSIDE_SUBMIT_WINDOW",-9);
//------------------- FLIGHT RELATED FUNCTIONS ----------------------------
function addTestFlightFromURL($filename_url) {
//global $flightsAbsPath ;
//$tmpPath=$flightsAbsPath."/-1/tmp";
global $CONF ;
$tmpPath=LEONARDO_ABS_PATH.'/'.$CONF['paths']['tmpigc'];
// if (!is_dir($tmpPath)) makeDir($tmpPath,0755);
$filename_parts=explode("/",$filename_url);
$filename=$filename_parts[count($filename_parts)-1];
$filename_tmp=$tmpPath."/". $filename;
$fp=fopen($filename_tmp,"w");
$lines = file($filename_url);
foreach ($lines as $line) {
fwrite($fp,$line);
}
fclose($fp);
addFlightFromFile($filename_tmp,0,-1, array('private'=>1,'cat'=>-1,'category'=>1) );
}
function checkTrackFileName($filename) {
$suffix=strtolower(substr($filename,-3));
if (in_array($suffix ,array("igc")) ) return 1;
else return 0;
}
function addFlightError($errMsg) {
/*
open_inner_table(_SUBMIT_FLIGHT_ERROR,600);
open_tr();
echo "<br><br><center>";
echo $errMsg;
echo "</center><br><br><br>";
close_inner_table();
*/
echo "<BR><BR><span class='alert'><strong>"._SUBMIT_FLIGHT_ERROR."</strong><br><BR>$errMsg</span>";
exitPage();
}
function submitFlightToServer($serverURL, $username, $passwd, $igcURL, $igcFilename, $private, $cat, $linkURL, $comments, $glider) {
require_once dirname(__FILE__)."/lib/xml_rpc/IXR_Library.inc.php";
$client = new IXR_Client($serverURL);
// $client->debug=true;
// echo "$username, $passwd, $igcURL, $igcFilename, $private, $cat, $linkURL, $comments, $glider #<BR>";
if ( ! $client->query('flights.submit',$username, $passwd, $igcURL, $igcFilename, $private, $cat, $linkURL, $comments, $glider ) ) {
//echo 'submitFlightToServer: Error '.$client->getErrorCode()." -> ".$client->getErrorMessage();
return array(0,$client->getErrorCode(),$client->getErrorMessage());
} else {
$flightID= $client->getResponse();
return array($flightID,'','');
// echo 'Flight was submited with id '.$flightID;
}
// return $flightID;
}
function addFlightFromFile($filename,$calledFromForm,$userIDstr,
// $is_private=0,$gliderCat=-1,$linkURL="",$comments="",$glider="", $category=1,
$argArray=array() ) {
global $CONF_default_cat_add, $CONF_photosPerFlight,$CONF;
global $CONF_NAC_list, $CONF_use_NAC, $CONF_use_validation,$CONF_airspaceChecks ,$CONF_server_id;
global $userID,$CONF_new_flights_submit_window;
global $flightsTable;
set_time_limit (120);
global $CONF_server_id ;
list($thisServerID,$userIDforFlight) = splitServerPilotStr($userIDstr);
if (!$thisServerID) $thisServerID=$CONF_server_id;
require_once dirname(__FILE__).'/CL_actionLogger.php';
$log=new Logger();
$log->userID =$userID+0; // the userId that is logged in , not the one that the flight will be atrributed to
$log->ItemType =1 ; // flight;
$log->ItemID = 0; // 0 at start will fill in later if successfull
$log->ServerItemID = $thisServerID ;
$log->ActionID = 1 ; //1 => add 2 => edit;
$log->ActionXML = '';
$log->Modifier = 0;
$log->ModifierID= 0;
$log->ServerModifierID =0;
$log->Result = 0;
$log->ResultDescription ="";
if (!$filename) {
$log->ResultDescription=getAddFlightErrMsg(ADD_FLIGHT_ERR_YOU_HAVENT_SUPPLIED_A_FLIGHT_FILE,0);
if (!$log->put()) echo "Problem in logger<BR>";
return array(ADD_FLIGHT_ERR_YOU_HAVENT_SUPPLIED_A_FLIGHT_FILE,0);
}
// now is the time to remove bad chars from the filename!
$newFilename=str_replace("'"," ",$filename);
$newFilename=toLatin1($newFilename);
if ($newFilename!=$filename) {
rename($filename,$newFilename);
$filename=$newFilename;
}
if (! is_file ($filename) ) {
$log->ResultDescription=getAddFlightErrMsg(ADD_FLIGHT_ERR_NO_SUCH_FILE,0);
if (!$log->put()) echo "Problem in logger<BR>";
return array(ADD_FLIGHT_ERR_NO_SUCH_FILE,0);
}
if ( strtolower(substr($filename,-4))!=".igc" ) {
$log->ResultDescription=getAddFlightErrMsg(ADD_FLIGHT_ERR_FILE_DOESNT_END_IN_IGC,0);
if (!$log->put()) echo "Problem in logger<BR>";
return array(ADD_FLIGHT_ERR_FILE_DOESNT_END_IN_IGC,0);
}
$tmpIGCPath=$filename;
$flight=new flight();
if ($thisServerID!=$CONF_server_id)
$flight->userServerID=$thisServerID;
$flight->userID=$userIDforFlight;
/*
$flight->cat=$gliderCat;
$flight->private=$is_private;
$flight->category=$category;
$flight->comments=$comments;
$flight->glider=$glider;
$flight->linkURL=$linkURL;
*/
foreach ($argArray as $varName=>$varValue) {
if ($varName=='NACclubID' || $varName=='NACid' || $varName=='comments' ) continue;
$flight->$varName=$varValue;
}
$comments=$argArray['comments'];
if ($comments) {
$flight->commentsNum=1;
}
if ( strtolower(substr($flight->linkURL,0,7)) == "http://" ) $flight->linkURL=substr($flight->linkURL,7);
if ($flight->cat==-1) $flight->cat=$CONF_default_cat_add;
# martin jursa 22.06.2008:
# in case the glider is not given otherwise, try to extract it from the IGC file
if (empty($flight->glider)) {
$flight->glider=extractGlider($lines);
}
// if no brand was given , try to detect
$flight->checkGliderBrand();
// we must cope with some cases here
// 1. more flights in the igc
// 2. garmin saved paths -> zero time difference -> SOLVED!
if ( ! $flight->getFlightFromIGC( $tmpIGCPath ) ) {
$log->ResultDescription=getAddFlightErrMsg(ADD_FLIGHT_ERR_THIS_ISNT_A_VALID_IGC_FILE,0);
if (!$log->put()) echo "Problem in logger<BR>";
return array(ADD_FLIGHT_ERR_THIS_ISNT_A_VALID_IGC_FILE,0);
}
// Compute hash now
$lines=file($tmpIGCPath);
$hash=md5( implode('',$lines) );
$flight->hash=$hash;
unset($lines);
// check for mac newlines -> NOT USED NOW
// we now use auto_detect_line_endings=true;
/*
if ( count ($lines)==1) {
if ($lines[0]=preg_replace("/\r([^\n])/","\r\n\\1",$lines[0])) {
DEBUG('addFlightFromFile',1,"addFlightFromFile: MAC newlines found<BR>");
if (!$handle = fopen($tmpIGCPath, 'w')) {
print "Cannot open file ($filename)";
exit;
}
if (!fwrite($handle, $lines[0])) {
print "Cannot write to file ($filename)";
exit;
}
fclose($handle);
}
}
*/
// echo $flight->DATE ." > ". date("Y-m-d",time()+3600*10) ."<BR>";
// check for dates in the furure
if ( $flight->DATE > date("Y-m-d",time()+3600*10) ) {
@unlink($flight->getIGCFilename(1));
@unlink($tmpIGCPath.".olc");
@unlink($tmpIGCPath);
$log->ResultDescription=getAddFlightErrMsg(ADD_FLIGHT_ERR_DATE_IN_THE_FUTURE,0);
if (!$log->put()) echo "Problem in logger<BR>";
return array(ADD_FLIGHT_ERR_DATE_IN_THE_FUTURE,0);
}
// Two week time limit check - P.Wild
/// Modification martin jursa 08.05.2007 cancel the upload if flight is too old
if ($CONF_new_flights_submit_window>0) {
if (! L_auth::isAdmin($userID) ) {
if ( $flight->DATE < date("Y-m-d", time() - $CONF_new_flights_submit_window*24*3600 ) ) {
@unlink($flight->getIGCFilename(1));
@unlink($tmpIGCPath.".olc");
@unlink($tmpIGCPath);
$log->ResultDescription=getAddFlightErrMsg(ADD_FLIGHT_ERR_OUTSIDE_SUBMIT_WINDOW,0);
if (!$log->put()) echo "Problem in logger<BR>";
return array(ADD_FLIGHT_ERR_OUTSIDE_SUBMIT_WINDOW,0);
}
}
}
// end martin / peter
$sameFilenameID=$flight->findSameFilename( basename($filename) );
if ($sameFilenameID>0) {
if ( $flight->allowDuplicates ) {
while ( is_file($flight->getIGCFilename()) ) {
$flight->filename='_'.$flight->filename;
}
} else {
@unlink($flight->getIGCFilename(1));
@unlink($tmpIGCPath.".olc");
@unlink($tmpIGCPath);
$log->ResultDescription=getAddFlightErrMsg(ADD_FLIGHT_ERR_SAME_FILENAME_FLIGHT,0);
if (!$log->put()) echo "Problem in logger<BR>";
return array(ADD_FLIGHT_ERR_SAME_FILENAME_FLIGHT,$sameFilenameID);
}
}
$sameFlightsArray= $flight->findSameTime();
if (count($sameFlightsArray)>0) {
if ( $flight->allowDuplicates ) { // we allow duplicates if they are from another server
$dupFound=0;
foreach($sameFlightsArray as $k=>$fArr){
if ($fArr['serverID']==$flight->serverID) {// if a same flight from this server is present we dont re-insert
$dupFound=1;
break;
} else { // fill in ids of flights to 'disable'
$disableFlightsList[$fArr['ID']]++;
}
}
} else {
$dupFound=1;
}
if ($dupFound) {
@unlink($flight->getIGCFilename(1));
@unlink($tmpIGCPath.".olc");
@unlink($tmpIGCPath);
$log->ResultDescription=getAddFlightErrMsg(ADD_FLIGHT_ERR_SAME_DATE_FLIGHT,0);
if (!$log->put()) echo "Problem in logger<BR>";
// return array( ADD_FLIGHT_ERR_SAME_DATE_FLIGHT,$sameFlightsArray[0]['serverID'].'_'. $sameFlightsArray[0]['ID']);
return array(ADD_FLIGHT_ERR_SAME_DATE_FLIGHT,$sameFlightsArray[0]['ID']);
} else {
DEBUG("FLIGHT",1,"addFlightFromFile: Duplicate DATE/TIME flight will be inserted<br>");
}
}
$sameFlightsArray= $flight->findSameHash( $hash );
if (count($sameFlightsArray)>0) {
if ( $flight->allowDuplicates ) { // we allow duplicates if they are from another server
//echo "searching in dups ";
//print_r($sameFlightsArray);
$dupFound=0;
$flightPilot= new pilot($flight->userServerID+0,$flight->userID+0);
$flightPilotMapTable=$flightPilot->pilotMapping();
// print_r($flightPilotMapTable);
foreach($sameFlightsArray as $k=>$fArr){
if ($fArr['serverID'] == $flight->serverID ) {// if a same flight from this server is present we dont re-insert
$dupFound=1;
break;
} else {
// check that the existing flight belongs to a pilot that is 'mapped' to
// $flight->userID + $flight->userServerID
if ( ! $flightPilotMapTable[ $fArr['userServerID'] ][ $fArr['userID'] ] ) {
DEBUG("FLIGHT",1,"addFlightFromFile: Same hash from external Server BUT from the pilot was not mapped into local <br>");
// We allow the flight to be submitted but then we must check and disable all duplicates but one
//$dupFound=1;
//break;
}
// fill in ids of flights to 'disable'
$disableFlightsList[$fArr['ID']]++;
}
}
} else {
// echo "no dups allowesd";
$dupFound=1;
}
if ($dupFound) {
@unlink($flight->getIGCFilename(1));
@unlink($tmpIGCPath.".olc");
@unlink($tmpIGCPath);
$log->ResultDescription=getAddFlightErrMsg(ADD_FLIGHT_ERR_SAME_HASH_FLIGHT,0);
if (!$log->put()) echo "Problem in logger<BR>";
return array(ADD_FLIGHT_ERR_SAME_HASH_FLIGHT,$sameFlightsArray[0]['ID']);
} else {
DEBUG("FLIGHT",1,"addFlightFromFile: Duplicate HASH flight will be inserted<br>");
// echo "addFlightFromFile: Duplicate HASH flight will be inserted<br>";
}
}
// print_r($disableFlightsList);
/*
if ( ! $flight->allowDuplicates ) {
$sameHashIDArray=$flight->findSameHash( $hash );
if (count($sameHashIDArray)>0) {
@unlink($flight->getIGCFilename(1));
@unlink($tmpIGCPath.".olc");
@unlink($tmpIGCPath);
$log->ResultDescription=getAddFlightErrMsg(ADD_FLIGHT_ERR_SAME_HASH_FLIGHT,0);
if (!$log->put()) echo "Problem in logger<BR>";
return array(ADD_FLIGHT_ERR_SAME_HASH_FLIGHT,$sameHashIDArray[0]['serverID'].'_'.$sameHashIDArray[0]['ID']);
}
}
*/
//******************************************************
// PASSED ALL TESTS , NOW DO SOME WORK WITH OUR FLIGHT
//******************************************************
// move the flight to corresponding year
$flight->checkDirs();
//$yearPath=$flightsAbsPath."/".$userIDstr."/flights/".$flight->getYear();
//$maps_dir=$flightsAbsPath."/".$userIDstr."/maps/".$flight->getYear();
//$charts_dir=$flightsAbsPath."/".$userIDstr."/charts/".$flight->getYear();
//$photos_dir=$flightsAbsPath."/".$userIDstr."/photos/".$flight->getYear();
//if (!is_dir($yearPath)) mkdir($yearPath,0755);
//if (!is_dir($maps_dir)) mkdir($maps_dir,0755);
//if (!is_dir($charts_dir)) mkdir($charts_dir,0755);
//if (!is_dir($photos_dir)) mkdir($photos_dir,0755);
/**
* Martin Jursa; to avoid error log flooding
*/
if (file_exists($tmpIGCPath)) {
@rename($tmpIGCPath, $flight->getIGCFilename() );
}
// in case an olc file was created too
if (file_exists($tmpIGCPath.".olc")) {
@rename($tmpIGCPath.".olc", $flight->getIGCFilename().".olc" );
}
// these commands seem redundant:
//@unlink($tmpIGCPath.".olc");
//@unlink($tmpIGCPath);
/*old: @rename($tmpIGCPath, $flight->getIGCFilename() );
// in case an olc file was created too
@rename($tmpIGCPath.".olc", $flight->getIGCFilename().".olc" );
@unlink($tmpIGCPath.".olc");
@unlink($tmpIGCPath);
*/
// if we use NACclubs
// get the NACclubID for userID
// and see if the flight is in the current year (as defined in the NAclist array
if ( $CONF_use_NAC ) {
require_once dirname(__FILE__)."/CL_NACclub.php";
list($pilotNACID,$pilotNACclubID)=NACclub::getPilotClub($userIDforFlight);
DEBUG("FLIGHT",1,"addFlightFromFile: pilotNACID:$pilotNACID, pilotNACclubID: $pilotNACclubID<br>");
if ( $CONF_NAC_list[$pilotNACID]['use_clubs'] ) {
DEBUG("FLIGHT",1,"addFlightFromFile: use_clubs is on<br>");
if ( $argArray['NACclubID'] >0 && $argArray['NACid']>0 ) {
$flight->NACclubID=$argArray['NACclubID'];
$flight->NACid=$argArray['NACid'];
DEBUG("FLIGHT",1,"addFlightFromFile: using arguments NACclubID NACid<br>");
} else {
DEBUG("FLIGHT",1,"addFlightFromFile: calculating NACclubID NACid<br>");
// check year -> we only put the club for the current season , so that results for previous seasons cannot be affected
$currSeasonYear=$CONF_NAC_list[$pilotNACID]['current_year'];
DEBUG("FLIGHT",1,"addFlightFromFile: currSeasonYear: $currSeasonYear<br>");
if ($CONF_NAC_list[$pilotNACID]['periodIsNormal']) {
$seasonStart=($currSeasonYear-1)."-12-31";
$seasonEnd=$currSeasonYear."-12-31";
} else {
$seasonStart=($currSeasonYear-1).$CONF_NAC_list[$pilotNACID]['periodStart'];
$seasonEnd=$currSeasonYear.$CONF_NAC_list[$pilotNACID]['periodStart'];
}
DEBUG("FLIGHT",1,"addFlightFromFile: seasonStart:$seasonStart , seasonEnd:$seasonEnd<br>");
if ($flight->DATE > $seasonStart && $flight->DATE <= $seasonEnd ) {
DEBUG("FLIGHT",1,"addFlightFromFile: inside Season !!<br>");
$flight->NACclubID=$pilotNACclubID;
$flight->NACid=$pilotNACID;
}
}
}
}
if ($CONF_use_validation) {
$ok=$flight->validate(0); // dont update DB
}
if ($CONF_airspaceChecks) {
$flight->checkAirspace(0); // dont update DB
}
$flight->putFlightToDB(0);
// now do the photos
if ($calledFromForm) {
require_once dirname(__FILE__)."/CL_flightPhotos.php";
$flightPhotos=new flightPhotos($flight->flightID);
// $flightPhotos->getFromDB();
$j=0;
for($i=0;$i<$CONF_photosPerFlight;$i++) {
$var_name="photo".$i."Filename";
$photoName=$_FILES[$var_name]['name'];
$photoFilename=$_FILES[$var_name]['tmp_name'];
if ( $photoName ) {
if ( CLimage::validJPGfilename($photoName) && CLimage::validJPGfile($photoFilename) ) {
// $newPhotoName=toLatin1($photoName);
// Fix for same photo filenames 2009.02.03
//global $flightsAbsPath;
global $CONF;
$newPhotoName=flightPhotos::getSafeName(
LEONARDO_ABS_PATH.'/'.str_replace("%PILOTID%",$flight->getPilotID(),str_replace("%YEAR%",$flight->getYear(),$CONF['paths']['photos']) ),
$photoName);
//$flightsAbsPath.'/'.$flight->getPilotID()."/photos/".$flight->getYear() ,
//$photoName ) ;
$phNum=$flightPhotos->addPhoto($j,$flight->getPilotID()."/photos/".$flight->getYear(), $newPhotoName,$description);
$photoAbsPath=$flightPhotos->getPhotoAbsPath($j);
if ( move_uploaded_file($photoFilename, $photoAbsPath ) ) {
CLimage::resizeJPG( $CONF['photos']['thumbs']['max_width'],
$CONF['photos']['thumbs']['max_height'],
$photoAbsPath, $photoAbsPath.".icon.jpg",
$CONF['photos']['compression']);
CLimage::resizeJPG(
$CONF['photos']['normal']['max_width'],
$CONF['photos']['normal']['max_height'], $photoAbsPath, $photoAbsPath,
$CONF['photos']['compression']
);
$flight->hasPhotos++;
$j++;
} else { //upload not successfull
$flightPhotos->deletePhoto($j);
}
}
}
}
// also try to get geotag info
$flightPhotos->computeGeoInfo();
} // took care of photos
// tkae care of comments
if ($comments) {
global $lang2isoGoogle,$currentlang;
$flightComments=new flightComments($flight->flightID);
$commentInsertResult=$flightComments->addComment(
array(
'parentID'=>0,
'userID'=>($flight->userID+0),
'userServerID'=>($flight->userServerID+0),
'guestName'=>'',
'guestPass'=>'',
'guestEmail'=>'',
'text'=>$comments,
'languageCode'=>$lang2isoGoogle[$currentlang]
),0);
}
// now is a good time to disable duplicate flights we have found from other servers
// AND are from the same user (using pilot's mapping table to find that out)
global $db;
if (0) {
foreach ($disableFlightsList as $dFlightID=>$num) {
$query="UPDATE $flightsTable SET private = private | 0x02 WHERE ID=$dFlightID ";
$res= $db->sql_query($query);
# Error checking
if($res <= 0){
echo("<H3> Error in query: $query</H3>\n");
}
}
}
//or
$flight->hideSameFlights();
set_time_limit (200);
$flight->computeScore();
$flight->updateTakeoffLanding();
// echo "TakeoffID:".$flight->takeoffID."<BR>";
if ( in_array($flight->takeoffID, $CONF['takeoffs']['private']) ) {
$flight->private=1;
}
$flight->putFlightToDB(1); // update
return array(1,$flight->flightID); // ALL OK;
}
/**
* martin jursa, 22.06.2008
* Extract the glider from the IGC file rows
* @param array $lines
* @return string
*/
function extractGlider($lines) {
$glider='';
if (count($lines)>0) {
foreach ($lines as $line) {
if (strpos($line, 'HOGTYGLIDERTYPE:')!==false) {
$parts=explode(':', $line);
$glider=trim($parts[1]);
break;
}
}
}
return $glider;
}
function getAddFlightErrMsg($result,$flightID) {
$callingURL="http://".$_SERVER['SERVER_NAME'];
if (is_array($flightID) ) {
$flightID=$flightID[0]['ID'];
}
switch ($result) {
case ADD_FLIGHT_ERR_YOU_HAVENT_SUPPLIED_A_FLIGHT_FILE:
$errMsg=_YOU_HAVENT_SUPPLIED_A_FLIGHT_FILE;
break;
case ADD_FLIGHT_ERR_NO_SUCH_FILE:
$errMsg=_NO_SUCH_FILE;
break;
case ADD_FLIGHT_ERR_FILE_DOESNT_END_IN_IGC:
$errMsg=_FILE_DOESNT_END_IN_IGC;
break;
case ADD_FLIGHT_ERR_THIS_ISNT_A_VALID_IGC_FILE:
$errMsg=_THIS_ISNT_A_VALID_IGC_FILE;
break;
case ADD_FLIGHT_ERR_SAME_DATE_FLIGHT:
$errMsg=_THERE_IS_SAME_DATE_FLIGHT."<br><br>"._IF_YOU_WANT_TO_SUBSTITUTE_IT." ".
"<a href='$callingURL".
getLeonardoLink(array('op'=>'show_flight','flightID'=>$flightID)).
"'>"._DELETE_THE_OLD_ONE."</a>";
break;
case ADD_FLIGHT_ERR_SAME_FILENAME_FLIGHT:
$errMsg=_THERE_IS_SAME_FILENAME_FLIGHT."<br><br>"._IF_YOU_WANT_TO_SUBSTITUTE_IT." ".
"<a href='$callingURL".
getLeonardoLink(array('op'=>'show_flight','flightID'=>$flightID)).
"'>"._DELETE_THE_OLD_ONE."</a><br><br>".
_CHANGE_THE_FILENAME;
break;
case ADD_FLIGHT_ERR_SAME_HASH_FLIGHT:
$errMsg=_THERE_IS_SAME_DATE_FLIGHT." (HASH) <br><br>"._IF_YOU_WANT_TO_SUBSTITUTE_IT." ".
"<a href='$callingURL".
getLeonardoLink(array('op'=>'show_flight','flightID'=>$flightID)).
"'>"._DELETE_THE_OLD_ONE."</a>";
break;
case ADD_FLIGHT_ERR_DATE_IN_THE_FUTURE:
$errMsg="The date of the flight is in the future<BR>Please use the Year-month-day not the US Year-day-month format";
break;
case ADD_FLIGHT_ERR_OUTSIDE_SUBMIT_WINDOW:
$errMsg=_OUTSIDE_SUBMIT_WINDOW;
break;
}
return $errMsg;
}
function getClubFlightsID($clubID) {
global $db;
global $clubsFlightsTable ;
$query="SELECT flightID FROM $clubsFlightsTable WHERE clubID=$clubID";
// echo $query;
$res= $db->sql_query($query);
if($res <= 0){
// echo "No flights found for club ID $clubID<BR>";
return array();
}
$flightsID=array();
while ($row = $db->sql_fetchrow($res)) {
array_push($flightsID,$row["flightID"]);
}
return $flightsID;
}
/**
* Martin Jursa 28.5.2008
* Function returning the javascript for form validation for add_flight and add_flight_from_zip
*
* @return string
*/
function getFormValidationJs() {
global $CONF_require_glider, $CONF_addflight_js_validation;
$js='';
if (!empty($CONF_addflight_js_validation)) {
$js="
var ok=true;
var el=document.forms[0].datafile;
if (ok) {
if (el && !el.value) {
el.focus();
alert('"._FLIGHTADD_IGC_MISSING."');
ok=false;
}
}
if (ok) {
el=document.forms[0].zip_datafile;
if (el && !el.value) {
el.focus();
alert('"._FLIGHTADD_IGCZIP_MISSING."');
ok=false;
}
}
if (ok) {
el=document.forms[0].category;
if (el && el.options[el.selectedIndex].value=='0') {
el.focus();
alert('"._FLIGHTADD_CATEGORY_MISSING."');
ok=false;
}
}
";
if (!empty($CONF_require_glider)) {
$js.="
if (ok) {
el=document.forms[0].gliderBrandID;
if (el && el.options[el.selectedIndex].value=='0') {
el.focus();
alert('"._FLIGHTADD_BRAND_MISSING."');
ok=false;
}
}
if (ok) {
el=document.forms[0].glider;
if (!el.value) {
el.focus();
alert('"._FLIGHTADD_GLIDER_MISSING."');
ok=false;
}
}
";
}
$js.="
return ok;
";
}
return $js;
}
?>