forked from leonardoxc/leonardoxc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCL_actionLogger.php
287 lines (220 loc) · 6.11 KB
/
CL_actionLogger.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
<?
// require_once ABS_INCLUDE_PATH."include.db.php";
/*
transactionID autoincrement
actionTime the tm of the action
userID - the user that commits the action
effectiveUserID - the user for whom the action is taken
ItemType - on an item that is of type :
1 => flight
2 => pilot
4 => waypoint
8 => NAC / club / group
16=> League / event
32=> Area ( group of waypoints )
ItemID - the item
ServerItemID - the server of the item -> those 2 define an item in the distributed DB network
ActionID - what the user does
1 => add
2 => edit
4 => delete
8 => Score (flight only)
16 => Create charts (flight only)
32 => Create Map (flight only)
64 =>
128=>
256=>
512=>
ActionXML - XML that describes the action so it
can be reproduced later/in another server
Modifier
0=> nothing special
1=> Club ( ie user adds pilot to club )
2=> League / event ( ie user adds flight to event )
4=> Area ( ie user adds waypoint to area )
ModifierID - ie clubId of LeagueID
ServerModifierID - the server on which the the extra item resides
Result
0=> Problem (initial)
1=> OK
2=> Pending
Result Description - if any furthe info needs to logged (ie in cae of error)
--------------------------------------------------------------
Moderation
0=> not needed
1=> needs aproval
2=>
4=>
Moderation Result
0=> Pending Approve
1=> Approved
2=> Not Approved
ModerationTime
ModerationUserID - the user that aproved /disapproved
Moderation Comments
--------------------------------------------------------------
Distribution:
- if we are a slave - propagation will be to the master only
- if we are the MASTER we must propagate to all slaves. Not many cases this will happen
Distribution
0=> no action needed
1=> propagation needed and pending
sourceServerID
destServerID
direction - client to Server OR server to client
excludeServer the ids of the servers to exclude when acting as a master .
common use is to exclude the clinet that propagated info to us
DistributionResult
0=> pending
1=> propagation successfull
2=> propagation failed - final
DistributionTime the time that the propagation occured
--------------------------------------------------------------
ObjectBefore -> blog serialized class
ObjectAfter ->blog serialized class
*/
$other_typesIDs=array(
1=>"News"
);
$actionIDs=array(
1=>"Login",
2=>"Logout",
4=>"23",
8=>"Credits",
32=>"Payment",
64=>"3",
128 =>"Add Comp",
256 =>"Add Task",
512 =>"Add News",
1024=>"Delete Comp",
2048=>"Delete Task",
4096=>"Delete News",
8192=>"Edit Comp",
16384=>"Edit Task",
32768=>"Edit News",
);
$itemTypes=array(
1 => "Flight",
2 => "Pilot",
4 => "Waypoint",
8 => "NAC / Club / Group",
16=> "League / Event ",
32=> "Area ",
);
$actionTypes=array(
1 => "Add",
2 => "Edit",
4 => "Delete",
8 => "Score (flight only)",
16 => "Create charts (flight only)",
32 => "Create Map (flight only)",
);
class Logger {
var $transactionID ;
var $actionTime ;
var $userID ;
var $effectiveUserID ;
var $ItemType;
var $ItemID ;
var $ServerItemID ;
var $ActionID ;
var $ActionXML;
var $Modifier;
var $ModifierID ;
var $ServerModifierID ;
var $Result ;
var $ResultDescription ;
function Logger() {
}
function getItemDescription($it) {
global $itemTypes;
return $itemTypes[$it];
}
function getActionDescription($act) {
global $actionTypes;
return $actionTypes[$act];
}
function deleteLogsFromDB($type){
global $db, $logTable;
if ($type) $where_clause=" WHERE ItemType=$type ";
$query = "DELETE from $logTable $where_clause";
// echo $query;
$res = $db->sql_query($query);
if ($res) return 1;
else {
echo "Problem in deleting log entries from DB $query<br>";
return 0;
}
}
function put(){
global $db, $logTable, $userID;
$this->ActionXML=addslashes($this->ActionXML);
$DBvars=array( 'actionTime', 'userID', 'effectiveUserID',
'ItemType', 'ItemID', 'ServerItemID', 'ActionID', 'ActionXML',
'Modifier', 'ModifierID', 'ServerModifierID', 'Result', 'ResultDescription' );
$this->actionTime=time();
$this->effectiveUserID=$userID;
foreach ($DBvars as $varName) {
$vars_list.="$varName,";
$values_list.="'".addslashes ($this->$varName)."',";
}
$vars_list=substr($vars_list,0,-1);
$values_list=substr($values_list,0,-1);
$query = "INSERT into $logTable ($vars_list ) VALUES ($values_list)";
// echo $query;
$res = $db->sql_query($query);
if ($res) return $db->sql_nextid();
else {
echo "Problem in inserting log entry into DB $query<br>";
return 0;
}
return 1;
}
function get($user_id,$comp_id,$task_id,$other_id,$other_type,$action,$action_cat){
global $db, $logTable;
$DBvars=array('user_id','comp_id','task_id','other_id','other_type','action','action_cat','time','details','status','ip','effective_user_id');
//construct query
$wc=" (1=1) ";
if ($user_id) $wc.=" AND user_id=$user_id ";
if ($comp_id) $wc.=" AND comp_id=$comp_id ";
if ($task_id) $wc.=" AND task_id=$task_id ";
if ($other_id) $wc.=" AND other_id=$other_id ";
if ($other_type) $wc.=" AND other_type=$other_type ";
if ($action) $wc.=" AND action=$action ";
if ($action_cat) $wc.=" AND action_cat=$action_cat ";
$query = "select * from $logTable WHERE $wc ORDER BY time DESC";
$res = $db->sql_query($query);
if (!$res) {
echo "Problem in geting log from DB $query<br>";
return 0;
}
$i=0;
while ($row=$db->sql_fetchrow($res)) {
foreach($DBvars as $DBvar) $ret[$i][$DBvar]=$row[$DBvar];
$i++;
}
return $ret;
}
function actionByName($actionID) {
global $actionIDs;
return $actionIDs[$actionID];
}
function actionByID($actionName) {
global $actionIDs;
return array_search($actionName, $actionIDs);
}
function otherByName($other_type_id) {
global $other_typesIDs;
return $other_typesIDs[$$other_type_id];
}
function otherByID($otherName) {
global $other_typesIDs;
return array_search($otherName, $other_typesIDs);
}
function formatTime($time) {
return date("Y/m/d H:i:s",$time);
// preg_match("/(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/",$time,$parts);
// return $parts[1]."/".$parts[2]."/".$parts[3]." ".$parts[4].":".$parts[5].":".$parts[6];
}
} // end of class
?>