forked from leonardoxc/leonardoxc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FN_pilot.php
712 lines (599 loc) · 22.5 KB
/
FN_pilot.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
<?
//************************************************************************
// Leonardo XC Server, https://github.com/leonardoxc/leonardoxc
//
// 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_pilot.php,v 1.55 2012/06/02 08:40:12 manolis Exp $
//
//************************************************************************
require_once dirname(__FILE__)."/CL_image.php";
//------------------- PILOT RELATED FUNCTIONS ----------------------------
function getPilotID($userServerID,$userID) {
if ($userServerID) $extra_prefix=$userServerID.'_';
else $extra_prefix='';
return $extra_prefix.$userID;
}
function getPilotList($clubID=0) {
global $db;
global $flightsTable;
global $clubsPilotsTable, $pilotsTable ;
global $nativeLanguage,$currentlang,$opMode;
if ($clubID) {
$query="SELECT *, $clubsPilotsTable.pilotID as userID , $clubsPilotsTable.pilotServerID as userServerID
FROM $clubsPilotsTable, $pilotsTable
WHERE $clubsPilotsTable.pilotID=$pilotsTable.pilotID
AND $clubsPilotsTable.pilotServerID=$pilotsTable.serverID AND $clubsPilotsTable.clubID=$clubID";
} else {
$query="SELECT DISTINCT userID, userServerID FROM $flightsTable ";
}
// echo $query;
$res= $db->sql_query($query);
if($res <= 0){
echo "ERROR in selecting pilots";
// echo $query;
return array( array (),array () );
}
$pilots=array();
$pilotsID=array();
while ($row = $db->sql_fetchrow($res)) {
$name = getPilotRealName($row["userID"],$row["userServerID"],0,2);
$name=strtoupper(substr($name,0,1)).substr($name,1);
$pnames[($row["userServerID"]+0).'_'.$row["userID"]]=$name;
}
if (!empty($pnames)) {
asort($pnames);
foreach($pnames as $userID=>$name) {
array_push($pilots,$name );
array_push($pilotsID,$userID);
}
}
return array($pilots,$pilotsID);
}
function getUsedGliders($userID,$serverID=0) {
global $db;
global $flightsTable;
$query="SELECT glider,gliderBrandID,gliderCertCategory,cat,category from $flightsTable WHERE userID=$userID AND userServerID=$serverID AND ( glider <> '' OR gliderBrandID <>0 ) GROUP BY gliderBrandID,glider,gliderCertCategory,cat,category ORDER BY DATE DESC ";
// echo $query;
$res= $db->sql_query($query);
if($res <= 0){
return array ();
}
$gliders=array();
while ($row = $db->sql_fetchrow($res)) {
array_push($gliders,
array($row['gliderBrandID'],$row['glider'],$row['gliderCertCategory'],$row['cat'],$row['category']) );
}
return $gliders;
}
function transliterate($str,$enc) {
// see this for hebraic-chinisee
// http://www.derickrethans.nl/translit.php
global $CONF_use_utf;
if ($enc=='gb2312') {
// echo "#### $str $enc ##";
if (! $CONF_use_utf ) {
require_once dirname(__FILE__)."/lib/ConvertCharset/convert_gb2312.php";
return gb2312_to_latin($str);
} else {
if ( substr( phpversion(),0,1 ) >=5 ) {
require_once dirname(__FILE__)."/lib/ConvertCharset/chinese/charset.class.php";
$gb2312_str= Charset::convert($str,'utf-8','gb2312');
$str2=Charset::PinYin($gb2312_str,'gb2312');
// echo "^gb2312_str : $gb2312_str ^ ";
// echo "^str2: $str2 ^ ";
return $str2;
} else {
return $str;
}
}
}
require_once dirname(__FILE__)."/lib/ConvertCharset/ConvertCharset.class.php";
require_once dirname(__FILE__)."/lib/utf8_to_ascii/utf8_to_ascii.php";
// if $CONF_use_utf it means the $str is already in utf
// so translitarate it directly
if ($CONF_use_utf) return utf8_to_ascii($str);
$NewEncoding = new ConvertCharset;
$str_utf8 = $NewEncoding->Convert($str, $enc, "utf-8", $Entities);
return utf8_to_ascii($str_utf8);
}
function getPilotInfo($pilotIDview,$serverID) {
global $db,$pilotsTable,$opMode;
global $currentlang,$nativeLanguage,$langEncodings,$lang2iso,$langEncodings;
global $countries,$langEncodings;
global $CONF_use_leonardo_names,$PREFS,$CONF,$CONF_server_id;
$query="SELECT Sex,Birthdate,LastName,FirstName,LastNameEn,FirstNameEn,countryCode,CIVL_ID,serverID
FROM $pilotsTable WHERE pilotID=$pilotIDview AND serverID=$serverID ";
$res= $db->sql_query($query);
// echo $query;
// Get real name from leonardo_pilots
//
// we must make sure the name can be displayed in the $currentlang encoding
//
if ($res) {
$pilot = $db->sql_fetchrow($res);
if (!$pilot) return array('','','','','',-1);
$firstName=$pilot['FirstName'];
$lastName=$pilot['LastName'];
$firstNameEn=$pilot['FirstNameEn'];
$lastNameEn=$pilot['LastNameEn'];
$pilotCountry=strtolower($pilot['countryCode']);
$Sex=$pilot['Sex'];
$Birthdate=$pilot['Birthdate'];
$CIVL_ID=$pilot['CIVL_ID'];
if ( strlen($lastName)>1 && ($CONF_use_leonardo_names || $langEncodings[$currentlang]==$langEncodings[$nativeLanguage]) ) { // always return real name
// we have some info on how to tranlitarate
// and the currentlang is not the native lang of the pilot.
$pilotLang="";
if ($pilotCountry && !countryHasLang($pilotCountry,$currentlang) ) {
if ( ($pilotLang=array_search($pilotCountry,$lang2iso)) === NULL )
$pilotLang=$nativeLanguage;
//echo $pilotLang."#".$pilotCountry."$";
}
// if all else fails translitarate using the nativeLangauge
if (!$pilotCountry && !$pilotLang && $langEncodings[$nativeLanguage]!=$langEncodings[$currentlang]) $pilotLang=$nativeLanguage;
// echo ">$realName ".$pilotLang."#".$pilotCountry."$<br>";
$enc=$langEncodings[$pilotLang];
if ($enc) {
$firstName=transliterate($firstName,$enc);
$lastName=transliterate($lastName,$enc);
}
//echo $realName."@";
// else return as is.
return array($lastName,$firstName,$pilotCountry,$Sex,$Birthdate,$CIVL_ID);
}
/*
if (strlen ($realName)>1) && $currentlang==$nativeLanguage) { // else realname is no good
if ($getAlsoCountry ) return getNationalityDescription($pilot['countryCode'],1,0)."$realName";
else return $realName;
}*/
}
// we dont have a local user , return !
if ($serverID!=0 && $serverID!=$CONF_server_id ) {
return array('','','','','',0);
}
if ($opMode==1) { // phpNuke
$res= $db->sql_query("SELECT username,name FROM ".$CONF['userdb']['users_table']." WHERE ".$CONF['userdb']['user_id_field']."=".$pilotIDview );
if ($res) {
$row= $db->sql_fetchrow($res);
if ($currentlang!=$nativeLanguage) {
$realName=$row["username"];
} else {
if ($row["name"]!='') $realName=$row["name"];
else $realName=$row["username"];
}
$str=$realName;
}
} else { // phpBB
$res= $db->sql_query("SELECT ".$CONF['userdb']['user_real_name_field']." FROM ".$CONF['userdb']['users_table']." WHERE ".$CONF['userdb']['user_id_field']."=".$pilotIDview );
if ($res) {
$row= $db->sql_fetchrow($res);
$realName=$row[$CONF['userdb']['user_real_name_field']];
$str=$realName;
// we have some info on how to tranlitarate
// and the currentlang is not the native lang of the pilot.
$pilotLang="";
if ($pilotCountry && !countryHasLang($pilotCountry,$currentlang) ) {
if ( ($pilotLang=array_search($pilotCountry,$lang2iso)) === NULL )
$pilotLang=$nativeLanguage;
//echo $pilotLang."#".$pilotCountry."$";
}
// if all else fails translitarate using the nativeLangauge
if (!$pilotCountry && !$pilotLang && $langEncodings[$nativeLanguage]!=$langEncodings[$currentlang]) $pilotLang=$nativeLanguage;
// echo ">".$pilotLang."#".$pilotCountry."$";
$enc=$langEncodings[$pilotLang];
if ($enc) $str=transliterate($str,$enc);
//echo $realName."@";
// else return as is.
}
}
list($lastName,$firstName)=split(" ",$str,2);
return array($lastName,$firstName,$pilotCountry,$Sex,$Birthdate,$CIVL_ID);
}
function getPilotInfoEn($pilotIDview,$serverID) {
global $db,$pilotsTable,$opMode;
global $currentlang,$nativeLanguage,$langEncodings,$lang2iso,$langEncodings;
global $countries,$langEncodings;
global $CONF_use_leonardo_names,$PREFS,$CONF,$CONF_server_id;
$query="SELECT Sex,Birthdate,LastName,FirstName,LastNameEn,FirstNameEn,countryCode,CIVL_ID,serverID
FROM $pilotsTable WHERE pilotID=$pilotIDview AND serverID=$serverID ";
$res= $db->sql_query($query);
// echo $query;
// Get real name from leonardo_pilots
// we must make sure the name can be displayed in the $currentlang encoding
//
if ($res) {
$pilot = $db->sql_fetchrow($res);
if (!$pilot) return array('','','','','','','',-1);
$firstName=$pilot['FirstName'];
$lastName=$pilot['LastName'];
$firstNameEn=$pilot['FirstNameEn'];
$lastNameEn=$pilot['LastNameEn'];
$pilotCountry=strtolower($pilot['countryCode']);
$Sex=$pilot['Sex'];
$Birthdate=$pilot['Birthdate'];
$CIVL_ID=$pilot['CIVL_ID'];
if ( $lastName || $lastNameEn || $firstName || $firstNameEn) {
if (!$lastName) $lastName=$lastNameEn;
if (!$lastNameEn) $lastNameEn=$lastName;
if (!$firstName) $firstName=$firstNameEn;
if (!$firstNameEn) $firstNameEn=$firstName;
return array($lastName,$firstName,$lastNameEn,$firstNameEn,$pilotCountry,$Sex,$Birthdate,$CIVL_ID);
}
}
// we dont have a local user , return !
if ($serverID!=0 && $serverID!=$CONF_server_id ) {
return array('','','','','','','',0);
}
if (1) { // phpBB
$res= $db->sql_query("SELECT ".$CONF['userdb']['user_real_name_field']." FROM ".$CONF['userdb']['users_table']." WHERE ".$CONF['userdb']['user_id_field']."=".$pilotIDview );
if ($res) {
$row= $db->sql_fetchrow($res);
$realName=$row[$CONF['userdb']['user_real_name_field']];
$str=$realName;
// we have some info on how to tranlitarate
// and the currentlang is not the native lang of the pilot.
$pilotLang="";
if ($pilotCountry && !countryHasLang($pilotCountry,$currentlang) ) {
if ( ($pilotLang=array_search($pilotCountry,$lang2iso)) === NULL )
$pilotLang=$nativeLanguage;
//echo $pilotLang."#".$pilotCountry."$";
}
// if all else fails translitarate using the nativeLangauge
if (!$pilotCountry && !$pilotLang && $langEncodings[$nativeLanguage]!=$langEncodings[$currentlang]) $pilotLang=$nativeLanguage;
// echo ">".$pilotLang."#".$pilotCountry."$";
$enc=$langEncodings[$pilotLang];
if ($enc) $str=transliterate($str,$enc);
//echo $realName."@";
// else return as is.
}
}
list($lastName,$firstName)=split(" ",$str,2);
return array($lastName,$firstName,$lastName,$firstName,$pilotCountry,$Sex,$Birthdate,$CIVL_ID);
}
function getExternalLinkIconStr($serverID,$linkURL='',$typeOfLink=1) {
// $typeOfLink=1 img, 0->none, 2->text (*)
global $CONF,$CONF_server_id,$moduleRelPath;
if ( !$serverID || $serverID==$CONF_server_id || $typeOfLink==0 ||
$CONF['servers']['list'][$serverID]['treat_flights_as_local'] ) return '';
else if ($typeOfLink==1) return leoHtml::img("icon_link.gif",0,0,'',_External_Entry." $linkURL",'icons1 flagIcon');
else if ($typeOfLink==2) return " (*)";
else if ($typeOfLink==3) {
return leoHtml::img("icon_link.gif",0,0,'',_External_Entry." $linkURL",'icons1 flagIcon');
}
}
function getPilotRealName($pilotIDview,$serverID,$getAlsoCountry=0,$getAlsoExternalIndicator=1,$gender=1) {
global $db,$pilotsTable,$opMode;
global $currentlang,$nativeLanguage,$langEncodings,$lang2iso,$langEncodings;
global $countries,$langEncodings;
global $CONF_use_leonardo_names,$PREFS,$CONF,$moduleRelPath;
# martin jursa may 2008:
# make the function error-tolerant, in case $pilotIDview is submitted in the form [serverid]_[userid]
if (strpos($pilotIDview, '_')!==false) {
$parts=explode('_', $pilotIDview);
$pilotIDview=$parts[1];
$serverID=$parts[0];
}
if ($PREFS->nameOrder==1) {
$nOrder="CONCAT(FirstName,' ',LastName)";
$nOrderEn="CONCAT(FirstNameEn,' ',LastNameEn)";
} else {
$nOrder="CONCAT(LastName,' ',FirstName)";
$nOrderEn="CONCAT(LastNameEn,' ',FirstNameEn)";
}
$query="SELECT $nOrder as realName ,$nOrderEn as realNameEn, countryCode,serverID,Sex FROM $pilotsTable WHERE pilotID=$pilotIDview AND serverID=$serverID";
$res= $db->sql_query($query);
// echo $query;
// Get real name from leonardo_pilots
//
// we must make sure the name can be displayed in the $currentlang encoding
//
if ($res) {
$pilot = $db->sql_fetchrow($res);
$realName=$pilot['realName'];
$realNameEn=$pilot['realNameEn'];
$pilotCountry=strtolower($pilot['countryCode']);
if ( strlen($realName)>1 && ($CONF_use_leonardo_names || $langEncodings[$currentlang]==$langEncodings[$nativeLanguage]) ) { // always return real name
$str=$realName;
// we have some info on how to tranlitarate
// and the currentlang is not the native lang of the pilot.
$pilotLang="";
if ($pilotCountry && !countryHasLang($pilotCountry,$currentlang) ) {
if ( ($pilotLang=array_search($pilotCountry,$lang2iso)) === NULL )
$pilotLang=$nativeLanguage;
//echo $pilotLang."#".$pilotCountry."$";
}
// if all else fails translitarate using the nativeLangauge
if (!$pilotCountry && !$pilotLang && $langEncodings[$nativeLanguage]!=$langEncodings[$currentlang]) $pilotLang=$nativeLanguage;
// echo ">$realName#$pilotLang#$pilotCountry#<br>";
$enc=$langEncodings[$pilotLang];
if ($enc) {
if ( strlen($realNameEn)>1 ) {
$str=$realNameEn;
} else {
$str=transliterate($str,$enc);
}
}
//echo $realName."@";
// else return as is.
if ($getAlsoCountry ) $str=getNationalityDescription($pilot['countryCode'],1,0).$str;
if ($gender==1 && strtoupper($pilot['Sex'])=='F' && $getAlsoCountry) {
// the $getAlsoCountry will prevent putting the F symbol in sync-log
$str.=leoHtml::img("icon_female_small.gif",0,0,'absmiddle','','icons1');
}
$str=$str.getExternalLinkIconStr($serverID,'',$getAlsoExternalIndicator);
return $str;
}
/*
if (strlen ($realName)>1) && $currentlang==$nativeLanguage) { // else realname is no good
if ($getAlsoCountry ) return getNationalityDescription($pilot['countryCode'],1,0)."$realName";
else return $realName;
}*/
}
if ($opMode==1) { // phpNuke
$res= $db->sql_query("SELECT username,name FROM ".$CONF['userdb']['users_table']." WHERE ".$CONF['userdb']['user_id_field']."=".$pilotIDview );
if ($res) {
$row= $db->sql_fetchrow($res);
if ($currentlang!=$nativeLanguage) {
$realName=$row["username"];
} else {
if ($row["name"]!='') $realName=$row["name"];
else $realName=$row["username"];
}
$str=$realName;
}
} else { // phpBB
$res= $db->sql_query("SELECT ".$CONF['userdb']['user_real_name_field']." FROM ".$CONF['userdb']['users_table']." WHERE ".$CONF['userdb']['user_id_field']."=".$pilotIDview );
if ($res) {
$row= $db->sql_fetchrow($res);
$realName=$row[$CONF['userdb']['user_real_name_field']];
$str=$realName;
// we have some info on how to tranlitarate
// and the currentlang is not the native lang of the pilot.
$pilotLang="";
if ($pilotCountry && !countryHasLang($pilotCountry,$currentlang) ) {
if ( ($pilotLang=array_search($pilotCountry,$lang2iso)) === NULL )
$pilotLang=$nativeLanguage;
//echo $pilotLang."#".$pilotCountry."$";
}
// if all else fails translitarate using the nativeLangauge
if (!$pilotCountry && !$pilotLang && $langEncodings[$nativeLanguage]!=$langEncodings[$currentlang]) $pilotLang=$nativeLanguage;
// echo "($str)>".$pilotLang."#".$pilotCountry."$";
$enc=$langEncodings[$pilotLang];
if ($enc) {
if (strlen($realNameEn)>1) {
$str=$realNameEn;
} else {
$str=transliterate($str,$enc);
}
}
//echo $realName."@";
// else return as is.
}
}
$str.=getExternalLinkIconStr($serverID,'',$getAlsoExternalIndicator);
if ($getAlsoCountry ) $str=getNationalityDescription($pilot['countryCode'],1,0).$str;
if ($gender==1 && strtoupper($pilot['Sex'])=='F' && $getAlsoCountry) { // the $getAlsoCountry will prevent putting the F symbol in sync-log
$str.=leoHtml::img("icon_female_small.gif",0,0,'absmiddle','','icons1');
}
return $str;
}
function getPilotPhotoRelFilename($serverID,$pilotID,$icon=0) {
global $moduleRelPath,$CONF;
if ($icon) $suffix="icon.jpg";
else $suffix=".jpg";
if ($serverID) $pilotID=$serverID.'_'.$pilotID;
return moduleRelPath().'/'.str_replace("%PILOTID%",$pilotID,$CONF['paths']['pilot'] ).'/PilotPhoto'.$suffix;
//return moduleRelPath()."/flights/".$pilotID."/PilotPhoto".$suffix;
}
function getPilotPhotoFilename($serverID,$pilotID,$icon=0) {
//global $flightsAbsPath;
global $CONF;
if ($icon) $suffix="icon.jpg";
else $suffix=".jpg";
if ($serverID) $pilotID=$serverID.'_'.$pilotID;
return LEONARDO_ABS_PATH.'/'.str_replace("%PILOTID%",$pilotID,$CONF['paths']['pilot'] ).'/PilotPhoto'.$suffix;
//return $flightsAbsPath."/".$pilotID."/PilotPhoto".$suffix;
}
function checkPilotPhoto($serverID,$pilotID) {
$normalImagePath=getPilotPhotoFilename($serverID,$pilotID,0);
$thumbImagePath=getPilotPhotoFilename($serverID,$pilotID,1);
if (!is_file($thumbImagePath) && is_file($normalImagePath) ) { // create icon
CLimage::resizeJPG(150,150,$normalImagePath , $thumbImagePath , 15);
}
}
function getPilotStatsRelFilename($pilotID,$num) {
global $moduleRelPath,$CONF;
return moduleRelPath().'/'.str_replace("%PILOTID%",$pilotID,$CONF['paths']['pilot'] )."/PilotStats_$num.png";
//return $moduleRelPath."/flights/".$pilotID."/PilotStats_$num.png";
}
function getPilotStatsFilename($pilotID,$num) {
//global $flightsAbsPath;
global $CONF;
return LEONARDO_ABS_PATH.'/'.str_replace("%PILOTID%",$pilotID,$CONF['paths']['pilot'] )."/PilotStats_$num.png";
// return $flightsAbsPath."/".$pilotID."/PilotStats_$num.png";
}
function getNationalityDescription($cCode,$img=1,$text=1) {
global $moduleRelPath,$countries;
$cCode=strtolower($cCode);
if (strlen($cCode) !=2) {
$cCode='unknown';
$str='unknown';
} else {
$str=$countries[strtoupper($cCode)];
}
if ($img) {
$imgStr=leoHtml::img("$cCode.gif",0,0,'absmiddle',$str,'fl');
}
if ($text) $textStr=$str;
return "$imgStr$textStr";
}
/**
* Modification Martin Jursa 26.04.2007
* Support for disabled added
*
* @param string $cCode
* @param bool $disabled
* @return string
*/
function getNationalityDropDown($cCode, $disabled=false) {
global $countries;
asort($countries);
$disabled_attr=$disabled ? ' disabled' : '';
$str="<select name='countriesList' $disabled_attr>";
$str.="<option value=''></option>\n";
foreach ($countries as $countrycode=>$countryName) {
if ( strtolower($countrycode)==strtolower($cCode) ) $sel=" selected";
else $sel="";
$str.="<option value='$countrycode' $sel>$countryName</option>\n";
}
$str.='</Select>';
return $str;
}
/**
* Martin Jursa 26.04.2007
*
* @param string $sex
* @param bool $disabled
* @return string
*/
function getSexDropDown($sex, $disabled=false) {
$disabled_attr=$disabled ? ' disabled' : '';
if ($sex!='M' && $sex!='F') $sex='';
$str="<select name='Sex' $disabled_attr>\n";
$values=array(''=>'', 'M'=>_Male_short, 'F'=>_Female_short);
foreach ($values as $value=>$desc) {
$selected=$sex==$value ? ' selected ' : '';
$str.="<option value='$value' $selected>$desc</option>\n";
}
$str.='</select>
';
return $str;
}
function getPilotSexString($sex,$icon=true){
global $moduleRelPath;
if ($sex=='M') $str=_Male_short;
else if ($sex=='F') $str=_Female_short;
if ($icon) {
if ($sex=='M') $str="<img src='$moduleRelPath/img/icon_male.gif' border=0 align='absmiddle'> ".$str;
else if ($sex=='F') $str=leoHtml::img("icon_female_small.gif",0,0,'absmiddle','','icons1').$str;
}
return $str;
}
/**
* Martin Jursa 26.04.2007
* Save email and password to user table if the respective options are set
* returns a resultmessage
*
* @param int $userID
* @param string $newEmail
* @param string $newPassword
* @param string $newPasswordConfirmation
* @return string
*/
function saveLoginData($userID, $newEmail, $newPassword, $newPasswordConfirmation) {
global $db;
global $CONF_edit_login;
global $CONF_edit_email;
global $CONF_password_minlength;
global $CONF;
$goodmsgs=array();
$errmsgs=array();
if (! $CONF['userdb']['edit']['enabled'] ) {
$errmsgs[]='saveLoginData requires turning on CONF["userdb"]["edit"]["enabled"].';
}elseif (empty($userID)) {
$errmsgs[]='UserID is missing; cannot update login data.';
}else {
if ($CONF['userdb']['edit']['edit_email'] && $newEmail!='#same_as_old#leonardo#' ) {
if (empty($newEmail)) {
$errmsgs[]=_EmailEmpty;
}else {
$saved=false;
$email=emailChecked($newEmail);
if ($email=='') {
$errmsgs[]=_EmailInvalid;
}else {
if ( LeoUser::changeEmail($userID,$email) >0 ) {
$saved=true;
$goodmsgs[]=_EmailSaved;
} else {
$errmsgs[]=_EmailSaveProblem;
}
/*
$sql='UPDATE '.$CONF['userdb']['users_table']." SET user_email='$email' WHERE user_id=$userID";
$res=$db->sql_query($sql);
if($res<=0){
$errmsgs[]=_EmailSaveProblem;
}else {
//$goodmsgs[]=_EmailSaved;
$saved=true;
}
*/
}
if (!$saved) $errmsgs[]=_EmailNotSaved;
}
}
$newPassword=trim($newPassword);
$newPasswordConfirmation=trim($newPasswordConfirmation);
if ($CONF['userdb']['edit']['edit_password'] && $newPassword ) {
$saved=false;
$passwordMinLength=!empty($CONF['userdb']['edit']['password_minlength']) ? $CONF['userdb']['edit']['password_minlength'] : 4;
if ($newPasswordConfirmation=='') {
$errmsgs[]=_PwdConfEmpty;
}elseif (strlen($newPassword)<$passwordMinLength) {
$pwdMsg=sprintf(_PwdTooShort, $passwordMinLength);
$errmsgs[]=$pwdMsg;
}elseif ($newPassword!=$newPasswordConfirmation) {
$errmsgs[]=_PwdAndConfDontMatch;
}else {
if ( LeoUser::changePassword($userID,$newPassword) > 0 ) {
$saved=true;
$goodmsgs[]=_PwdChanged;
} else {
$errmsgs[]=_PwdChangeProblem;
}
/*
$pwd=md5($newPassword);
$sql='UPDATE '.$CONF['userdb']['users_table']." SET user_password='$pwd' WHERE user_id=$userID";
$res=$db->sql_query($sql);
if($res<=0){
$errmsgs[]=_PwdChangeProblem;
}else {
$goodmsgs[]=_PwdChanged;
$saved=true;
}
*/
}
if (!$saved) $errmsgs[]=_PwdNotChanged;
}
}
$message='';
if (count($goodmsgs)>0) {
$message.='<span class="ok">'.implode('<br>', $goodmsgs).'</span>';
}
if (count($errmsgs)>0) {
$message.='<span class="alert">'.implode('<br>', $errmsgs).'</span>';
}
return $message;
}
/**
* martin jursa 2007
* Checking email address and returning an empty string if invalid
*
* @param string $email
* @return string
*/
function emailChecked($email) {
$retVal='';
$email=strtolower(trim($email));
$pattern="^[-_a-z0-9]+([-\\._a-z0-9]+)*@([-_a-z0-9]+[\\.]+)+([a-z]{2,4})$";
if (ereg($pattern, $email)) {
$retVal=$email;
}
return $retVal;
}
?>