-
Notifications
You must be signed in to change notification settings - Fork 33
/
my_logs.php
191 lines (162 loc) · 8.32 KB
/
my_logs.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
<?php
use src\Models\GeoCache\GeoCacheLog;
use src\Utils\Database\XDb;
use src\Utils\Text\Formatter;
use src\Models\ApplicationContainer;
//include template handling
require_once(__DIR__.'/lib/common.inc.php');
//user logged in?
$loggedUser = ApplicationContainer::GetAuthorizedUser();
if (!$loggedUser) {
$target = urlencode(tpl_get_current_page());
tpl_redirect('login.php?target='.$target);
exit;
}
if (isset($_REQUEST['userid'])) {
$user_id = $_REQUEST['userid'];
tpl_set_var('userid', $user_id);
} else {
//no param userid - display data for currently logged user
$user_id = $loggedUser->getUserId();
tpl_set_var('userid', $user_id);
}
$logTypes = GeoCacheLog::logTypesArray();
if (isset($_REQUEST['logtypes'])) {
$logTypes = array_intersect($logTypes, explode(',', $_REQUEST['logtypes']));
}
$logTypesCondition = "cache_logs.type IN (" . implode(',', $logTypes) . ")";
//get the news
$tplname = 'my_logs';
tpl_set_var('latest_logs_cache', tr('latest_logs'));
require(__DIR__.'/src/Views/newlogs.inc.php');
$username = XDb::xMultiVariableQueryValue(
"SELECT username FROM user WHERE user_id= :1 LIMIT 1", '', $user_id);
tpl_set_var('username', htmlspecialchars($username));
$LOGS_PER_PAGE = 50;
$PAGES_LISTED = 10;
$total_logs = XDb::xMultiVariableQueryValue(
"SELECT count(id) FROM cache_logs, caches WHERE `cache_logs`.`cache_id`=`caches`.`cache_id`
AND `cache_logs`.`deleted`=0
AND ".$logTypesCondition."
AND `caches`.`status` != 4
AND `caches`.`status` != 5
AND `caches`.`status` != 6
AND `cache_logs`.`user_id`= :1 ", 0, $user_id);
$pages = "";
$total_pages = ceil($total_logs / $LOGS_PER_PAGE);
if (!isset($_GET['start']) || intval($_GET['start']) < 0 || intval($_GET['start']) > $total_logs) {
$start = 0;
} else {
$start = intval($_GET['start']);
}
$startat = max(0, floor((($start / $LOGS_PER_PAGE) + 1) / $PAGES_LISTED) * $PAGES_LISTED);
$logsPage = 'my_logs.php?userid='.$user_id;
if (array_diff(GeoCacheLog::logTypesArray(), $logTypes)) {
$logsPage .= '&logtypes='.implode(',',$logTypes);
}
$logsPage .= '&start=';
if (($start / $LOGS_PER_PAGE) + 1 >= $PAGES_LISTED) {
$pages .= '<a href="'.$logsPage.max(0,
($startat - $PAGES_LISTED - 1) * $LOGS_PER_PAGE).'">{first_img}</a> ';
} else {
$pages .= "{first_img_inactive} ";
}
for ($i = max(1, $startat); $i < min($startat + $PAGES_LISTED, $total_pages + 1); $i++) {
$page_number = ($i - 1) * $LOGS_PER_PAGE;
if ($page_number == $start) {
$pages .= '<b>';
}
$pages .= '<a href="'.$logsPage.$page_number.'">'.$i.'</a> ';
if ($page_number == $start) {
$pages .= '</b>';
}
}
if ($total_pages >= $startat + $PAGES_LISTED) {
$pages .= '<a href="'.$logsPage.(($i - 1) * $LOGS_PER_PAGE).'">{last_img}</a> ';
} else {
$pages .= '{last_img_inactive}';
}
$dateOrderSql =
$user_id == $loggedUser->getUserId()
? '`cache_logs`.`date` DESC, `cache_logs`.`date_created` DESC'
: '`cache_logs`.`date_created` DESC, `cache_logs`.`date` DESC';
$rs = XDb::xSql(
"SELECT `cache_logs`.`id`
FROM `cache_logs`, `caches`
WHERE `cache_logs`.`cache_id`=`caches`.`cache_id`
AND `cache_logs`.`deleted`=0
AND ".$logTypesCondition."
AND `caches`.`status` != 4
AND `caches`.`status` != 5
AND `caches`.`status` != 6
AND `cache_logs`.`user_id`= ?
ORDER BY ".$dateOrderSql.", `cache_logs`.`id` DESC
LIMIT ".intval($start).", ".intval($LOGS_PER_PAGE), $user_id);
$log_ids = array();
while ($record = XDb::xFetchArray($rs)) {
$log_ids[] = $record['id'];
}
XDb::xFreeResults($rs);
$file_content = '';
if (!empty($log_ids)) {
$rs = XDb::xSql(
"SELECT cache_logs.id, cache_logs.cache_id AS cache_id, cache_logs.type AS log_type, cache_logs.date AS log_date,
cache_logs.text AS log_text, caches.user_id AS cache_owner,
caches.name AS cache_name, user.username AS user_name, cache_logs.user_id AS luser_id,
caches.wp_oc AS wp_name, caches.type AS cache_type, cache_type.icon_small AS cache_icon_small,
log_types.icon_small AS icon_small,
IF(ISNULL(`cache_rating`.`cache_id`), 0, 1) AS `recommended`,COUNT(gk_item.id) AS geokret_in
FROM ((cache_logs INNER JOIN caches ON (caches.cache_id = cache_logs.cache_id)))
INNER JOIN user ON (cache_logs.user_id = user.user_id)
INNER JOIN log_types ON (cache_logs.type = log_types.id)
INNER JOIN cache_type ON (caches.type = cache_type.id)
LEFT JOIN `cache_rating` ON `cache_logs`.`cache_id`=`cache_rating`.`cache_id`
AND `cache_logs`.`user_id`=`cache_rating`.`user_id`
LEFT JOIN gk_item_waypoint ON gk_item_waypoint.wp = caches.wp_oc
LEFT JOIN gk_item ON gk_item.id = gk_item_waypoint.id
AND gk_item.stateid<>1 AND gk_item.stateid<>4 AND gk_item.typeid<>2 AND gk_item.stateid !=5
WHERE cache_logs.deleted=0 AND cache_logs.id IN ( ".implode(',', $log_ids)." ) AND `cache_logs`.`user_id`= ? AND ".$logTypesCondition."
GROUP BY cache_logs.id
ORDER BY ".$dateOrderSql.", `cache_logs`.`id` DESC",
$user_id);
while ($log_record = XDb::xFetchArray($rs)) {
//hide log type "COG comment" behind 'ordinary' users, displya all logs for admins
if (!(($log_record['log_type'] == 12) && (!$loggedUser->hasOcTeamRole()))) {
$file_content .= '<tr>';
$file_content .= '<td style="width: 70px;">'.htmlspecialchars(
Formatter::date($log_record['log_date']), ENT_COMPAT, 'UTF-8'
).'</td>';
if ($log_record['geokret_in'] != '0') {
$file_content .= '<td width="26"> <img src="images/gk.png" border="0" alt="" title="GeoKret" /></td>';
} else {
$file_content .= '<td width="26"> </td>';
}
//$rating_picture
if ($log_record['recommended'] == 1 && $log_record['log_type'] == 1) {
$file_content .= '<td width="22"><img src="images/rating-star.png" border="0" alt=""/></td>';
} else {
$file_content .= '<td width="22"> </td>';
}
$file_content .= '<td width="22"><img src="/images/'.$log_record['icon_small'].'" border="0" alt="" /></td>';
$file_content .= '<td width="22"><a class="links" href="viewcache.php?cacheid='.$log_record['cache_id'].'"><img src="/images/'.$log_record['cache_icon_small'].'" border="0" alt=""/></a></td>';
$file_content .= '<td><b><a class="links" href="viewlogs.php?logid='.htmlspecialchars($log_record['id'],
ENT_COMPAT, 'UTF-8').'" onmouseover="Tip(\'';
$file_content .= '<b>'.htmlspecialchars($log_record['user_name']).'</b>:<br>';
$file_content .= GeoCacheLog::cleanLogTextForToolTip($log_record['log_text']);
$file_content .= '\', PADDING,5, WIDTH,280,SHADOW,true)" onmouseout="UnTip()">'.htmlspecialchars($log_record['cache_name'],
ENT_COMPAT, 'UTF-8').'</a></b></td>';
$file_content .= '<td> </td>';
$file_content .= "</tr>";
} // end of COG comments hidding
}
$pages = mb_ereg_replace('{last_img}', $last_img, $pages);
$pages = mb_ereg_replace('{first_img}', $first_img, $pages);
$pages = mb_ereg_replace('{first_img_inactive}', $first_img_inactive, $pages);
$pages = mb_ereg_replace('{last_img_inactive}', $last_img_inactive, $pages);
} else {
$pages = '';
}
tpl_set_var('file_content', $file_content);
tpl_set_var('pages', $pages);
//make the template and send it out
tpl_BuildTemplate();