forked from leonardoxc/leonardoxc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CL_NACclub.php
204 lines (182 loc) · 6.22 KB
/
CL_NACclub.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
<?
//************************************************************************
// 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: CL_NACclub.php,v 1.10 2010/04/14 18:58:51 manolis Exp $
//
//************************************************************************
class NACclub {
var $ID;
var $name;
var $intName;
var $description;
var $intDescription;
var $countryCode;
var $NAC_ID;
var $location;
var $intLocation;
var $link;
var $cat;
var $valuesArray;
var $gotValues;
function NACclub() {
}
function getPilotClub($userID) {
global $db,$NACclubsTable,$pilotsTable;
$query="SELECT NACclubID,NACid FROM $pilotsTable WHERE pilotID=$userID AND serverID=0";
$res= $db->sql_query($query);
//echo $query;
if($res <= 0){
echo "Error getting club for pilot<BR>";
return 0;
}
if ( $row=$db->sql_fetchrow($res) )
return array($row['NACid'],$row['NACclubID']);
else return 0;
}
/**
* Get Array of clubID=>clubName
* Modification Martin Jursa, 22.05.2007: Option $withFlightsOnly to limit array to clubs having submitted flights
*
* @param int $NAC_ID
* @param bool $withFlightsOnly
* @return array
*/
function getClubs($NAC_ID, $withFlightsOnly=false) {
global $db,$NACclubsTable;
if ($withFlightsOnly) {
global $flightsTable;
$query="SELECT clubID, clubName
FROM $NACclubsTable c
INNER JOIN $flightsTable f ON f.NACid=c.NAC_ID AND f.NACclubID=c.clubID
WHERE c.NAC_ID=$NAC_ID
GROUP BY clubID, clubName
ORDER BY clubName";
}else {
$query="SELECT * FROM $NACclubsTable WHERE NAC_ID=$NAC_ID ORDER BY clubName";
}
$res= $db->sql_query($query);
// echo $query;
if($res <= 0){
echo "Error getting NAC clubs from DB<BR>";
return;
}
$NACclubList=array();
while ($row=$db->sql_fetchrow($res)) {
$NACclubList[$row['clubID']]=$row['clubName'];
}
return $NACclubList;
}
function getClubName($NAC_ID,$clubID){
global $db,$NACclubsTable;
$query="SELECT clubName FROM $NACclubsTable WHERE NAC_ID=$NAC_ID AND clubID=$clubID ";
$res= $db->sql_query($query);
//echo $query;
if($res <= 0){
echo "Error getting NAC club from DB<BR>";
return;
}
if ($row=$db->sql_fetchrow($res)) return $row['clubName'];
else return "";
}
/* OLD
function updatePilotFlights($pilotID, $NAC_ID, $NACclubID, $year=0) {
global $db, $flightsTable, $NACclubsTable, $CONF_NAC_list;
if ($NAC_ID==0) return 1;
$where_clause=" WHERE ";
if (!$year) $year=$CONF_NAC_list[$NAC_ID]['current_year'];
if ( $CONF_NAC_list[$NAC_ID]['periodIsNormal']) { // league start and end on 1/1
$where_clause.=" DATE >='".$year."-01-01' AND DATE <= '".$year."-12-31'";
} else {
$where_clause.=" DATE >='".($year-1).$CONF_NAC_list[$NAC_ID]['periodStart']."' AND DATE < '".$year.$CONF_NAC_list[$NAC_ID]['periodStart']."'";
}
// Martin Jursa 18.05.2007: Save the NACid too
$query="UPDATE $flightsTable SET NACclubID=$NACclubID, NACid=$NAC_ID $where_clause AND userID=$pilotID";
// echo $query;
$res= $db->sql_query($query);
if($res <= 0){
echo "Error updating NACclub to flights table for pilot $pilotID<BR>";
// echo $query;
return 0;
}
return 1;
}
*/
/**
* New version 27/5/2008 by Martin Jursa
* Taking into account the configuration settings for each NAC-Club:
* If club_change_period_active==false you can change the club in the pilot profile but the flights won't follow
* Special handling of NACid=0: flights with NACid=0 get changed even if club_change_period_active is false
*
*
* @param int $pilotID
* @param int $newNACid
* @param int $newNACclubID
*/
function updatePilotFlights($pilotID, $newNACid, $newNACclubID) {
global $db, $flightsTable, $NACclubsTable, $CONF_NAC_list;
$now=time();
$currYear=date('Y');
$NACInfos=array();
$minSeasonStart=$currYear.'-01-01';
$maxSeasonEnd=($currYear+1).'-01-01';
foreach ($CONF_NAC_list as $NACid=>$NACconf) {
$periodStart=!empty($NACconf['periodIsNormal']) || empty($NACconf['periodStart']) ? '-01-01' : $NACconf['periodStart'];
$SeasonStart=$currYear.$periodStart;
$ts=strtotime($SeasonStart);
if ($ts>$now) {
$SeasonStart=($currYear-1).$periodStart;
$SeasonEnd=($currYear).$periodStart;
}else {
$SeasonEnd=($currYear+1).$periodStart;
}
if ($SeasonStart<$minSeasonStart) $minSeasonStart=$SeasonStart;
if ($SeasonEnd>$maxSeasonEnd) $maxSeasonEnd=$SeasonEnd;
$NACInfos[$NACid]['SeasonStart']=$SeasonStart;
$NACInfos[$NACid]['SeasonEnd']=$SeasonEnd;
$NACInfos[$NACid]['UseClubs']=empty($NACconf['use_clubs']) ? 0 : 1;
$NACInfos[$NACid]['AllowChangeClub']=empty($NACconf['club_change_period_active']) ? 0 : 1;
}
# virtual NAC to handle NACid==0
$NACInfos[0]=array('SeasonStart'=>$minSeasonStart, 'SeasonEnd'=>$maxSeasonEnd, 'AllowChangeClub'=>1, 'UseClubs'=>1);
$allNACs=array_keys($NACInfos);
if (!in_array($newNACid, $allNACs)) return ;
if ($NACInfos[$newNACid]['UseClubs']==0) $newNACclubID=0;
$newSeasonStart=$NACInfos[$newNACid]['SeasonStart'];
$newSeasonEnd=$NACInfos[$newNACid]['SeasonEnd'];
$flightsClauses=array();
foreach ($NACInfos as $NACid=>$Info) {
if ($Info['AllowChangeClub']) {
$flightsClause="NACid=$NACid";
$flightsClause.=" AND DATE>='".$Info['SeasonStart']."' AND DATE<'".$Info['SeasonEnd']."'";
$flightsClause.=" AND DATE>='$newSeasonStart'";
$flightsClause.=" AND DATE<'$newSeasonEnd'";
$flightsClauses[]='('.$flightsClause.')';
}
}
$flightsClause=implode(' OR ', $flightsClauses);
$generalClause="userID=$pilotID AND userServerID=0 AND (NACclubID<>$newNACclubID OR NACid<>$newNACid)";
$where_clause="($generalClause) AND ($flightsClause)";
$query="UPDATE $flightsTable
SET NACclubID=$newNACclubID, NACid=$newNACid
WHERE
$where_clause ";
//echo $query;
$res= $db->sql_query($query);
if(!$res){
echo "Error updating NACclub to flights table for pilot $pilotID<BR>";
}else {
$count=$db->sql_affectedrows($res);
if ($count>0) {
echo '<b>'.$count.' flights updated</b><BR>';
}
}
}
}
?>