]> git.openstreetmap.org Git - nominatim.git/blob - lib/log.php
Collapse two log tables into one.
[nominatim.git] / lib / log.php
1 <?php
2
3         function logStart(&$oDB, $sType = '', $sQuery = '', $aLanguageList = array())
4         {
5                 $aStartTime = explode('.',microtime(true));
6                 if (!$aStartTime[1]) $aStartTime[1] = '0';
7
8                 $hLog = array(
9                                 date('Y-m-d H:i:s',$aStartTime[0]).'.'.$aStartTime[1],
10                                 $_SERVER["REMOTE_ADDR"],
11                                 $_SERVER['QUERY_STRING'],
12                                 $sQuery
13                         );
14
15                 if (CONST_Log_DB)
16                 {
17                         $sSQL = 'insert into new_query_log (type,starttime,query,ipaddress,useragent,language,format,searchterm)';
18                         $sSQL .= ' values ('.getDBQuoted($sType).','.getDBQuoted($hLog[0]).','.getDBQuoted($hLog[2]);
19                         $sSQL .= ','.getDBQuoted($hLog[1]).','.getDBQuoted($_SERVER['HTTP_USER_AGENT']).','.getDBQuoted(join(',',$aLanguageList)).','.getDBQuoted($_GET['format']).','.getDBQuoted($hLog[3]).')';
20                         $oDB->query($sSQL);
21                 }
22
23                 if (CONST_Log_File && CONST_Log_File_ReverseLog != '') {
24                 if ($sType == 'reverse')
25                 {
26                         $aStartTime = explode('.',$hLog[0]);
27                         file_put_contents(CONST_Log_File_ReverseLog,
28                                 $aStartTime[0].','.$aStartTime[1].','.
29                                 php_uname('n').','.
30                                 '"'.addslashes(isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:'').'",'.
31                                 '"'.addslashes($hLog[1]).'",'.
32                                 $_GET['lat'].','.
33                                 $_GET['lon'].','.
34                                 $_GET['zoom'].','.
35                                 '"'.addslashes($_SERVER['HTTP_USER_AGENT']).'",'.
36                                 '"'.addslashes($_GET['format']).'"'."\n",
37                         FILE_APPEND);
38                 }
39                 }
40
41                 return $hLog;
42         }
43
44         function logEnd(&$oDB, $hLog, $iNumResults)
45         {
46                 $aEndTime = explode('.',microtime(true));
47                 if (!$aEndTime[1]) $aEndTime[1] = '0';
48                 $sEndTime = date('Y-m-d H:i:s',$aEndTime[0]).'.'.$aEndTime[1];
49
50                 if (CONST_Log_DB)
51                 {
52                         $sSQL = 'update new_query_log set endtime = '.getDBQuoted($sEndTime).', results = '.$iNumResults;
53                         $sSQL .= ' where starttime = '.getDBQuoted($hLog[0]);
54                         $sSQL .= ' and ipaddress = '.getDBQuoted($hLog[1]);
55                         $sSQL .= ' and query = '.getDBQuoted($hLog[2]);
56                         $oDB->query($sSQL);
57                 }
58
59                 if (CONST_Log_File && CONST_Log_File_SearchLog != '') {
60                 $aStartTime = explode('.',$hLog[0]);
61                 file_put_contents(CONST_Log_File_SearchLog,
62                                 $aStartTime[0].','.$aStartTime[1].','.
63                                 php_uname('n').','.
64                                 '"'.addslashes(isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:'').'",'.
65                                 '"'.addslashes($hLog[1]).'",'.
66                                 '"'.addslashes($hLog[3]).'",'.
67                                 '"'.addslashes($_SERVER['HTTP_USER_AGENT']).'",'.
68                                 '"'.addslashes($_GET['format']).'",'.
69                                 $iNumResults."\n",
70                         FILE_APPEND);
71                 }
72
73         }