Completed
Push — development ( 1b87d2...43bb99 )
by Thomas
06:02
created

htdocs/editcache.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/****************************************************************************
3
 * for license information see LICENSE.md
4
 *  edit a cache listing
5
 *  used template(s): editcache
6
 *  GET/POST Parameter: cacheid
7
 *****************************************************************************/
8
9
use Oc\GeoCache\StatisticPicture;
10
use Oc\Libse\ChildWp\HandlerChildWp;
11
use Oc\Libse\Coordinate\FormatterCoordinate;
12
13
require_once __DIR__ . '/lib/consts.inc.php';
14
$opt['gui'] = GUI_HTML;
15
require_once __DIR__ . '/lib/common.inc.php';
16
17
function getWaypoints($cacheId)
18
{
19
    global $waypointline;
20
    global $waypointlines;
21
    global $nowaypoints;
22
23
    $wpHandler = new HandlerChildWp();
24
    $wayPoints = $wpHandler->getChildWps($cacheId);
25
    $ret = '';
26
27
    if (!empty($wayPoints)) {
28
        $formatter = new FormatterCoordinate();
29
30
        foreach ($wayPoints as $wayPoint) {
31
            $tmpLine = $waypointline;
32
33
            $tmpLine = mb_ereg_replace(
34
                '{wp_image}',
35
                htmlspecialchars($wayPoint['image'], ENT_COMPAT, 'UTF-8'),
36
                $tmpLine
37
            );
38
            $tmpLine = mb_ereg_replace('{wp_type}', htmlspecialchars($wayPoint['name'], ENT_COMPAT, 'UTF-8'), $tmpLine);
39
            $htmlCoordinate = $formatter->formatHtml(
40
                $wayPoint['coordinate'],
41
                '</td></tr><tr><td style="white-space:nowrap">'
42
            );
43
            $tmpLine = mb_ereg_replace('{wp_coordinate}', $htmlCoordinate, $tmpLine);
44
            $tmpLine = mb_ereg_replace(
45
                '{wp_description}',
46
                htmlspecialchars(trim($wayPoint['description']), ENT_COMPAT, 'UTF-8'),
47
                $tmpLine
48
            );
49
            $tmpLine = mb_ereg_replace(
50
                '{wp_show_description}',
51
                mb_ereg_replace('\r\n', '<br />', htmlspecialchars($wayPoint['description'], ENT_COMPAT, 'UTF-8')),
52
                $tmpLine
53
            );
54
            $tmpLine = mb_ereg_replace('{cacheid}', htmlspecialchars($cacheId, ENT_COMPAT, 'UTF-8'), $tmpLine);
55
            $tmpLine = mb_ereg_replace(
56
                '{childid}',
57
                htmlspecialchars($wayPoint['childid'], ENT_COMPAT, 'UTF-8'),
58
                $tmpLine
59
            );
60
61
            $ret .= $tmpLine;
62
        }
63
64
        $ret = mb_ereg_replace('{lines}', $ret, $waypointlines);
65
66
        return $ret;
67
    }
68
69
    return $nowaypoints;
70
}
71
72
//Preprocessing
73
if ($error == false) {
74
    $cache_id = 0;
75
    if (isset($_REQUEST['cacheid'])) {
76
        $cache_id = (int) $_REQUEST['cacheid'];
77
    }
78
79
    if ($usr === false) {
80
        $tplname = 'login';
81
82
        tpl_set_var('username', '');
83
        tpl_set_var('target', 'editcache.php?cacheid=' . urlencode($cache_id));
84
        tpl_set_var('message_start', '');
85
        tpl_set_var('message_end', '');
86
        tpl_set_var('message', $login_required);
87
        tpl_set_var('helplink', helppagelink('login'));
88
    } else {
89
        $cache_rs = sql(
90
            "
91
                SELECT
92
                    `caches`.`uuid`,
93
                    `caches`.`user_id`,
94
                    `caches`.`name`,
95
                    `caches`.`type`,
96
                    `caches`.`size`,
97
                    `caches`.`date_created`,
98
                    `caches`.`date_hidden`,
99
                    `caches`.`date_activate`,
100
                    `caches`.`longitude`,
101
                    `caches`.`latitude`,
102
                    `caches`.`country`,
103
                    `caches`.`terrain`,
104
                    `caches`.`difficulty`,
105
                    `caches`.`desc_languages`,
106
                    `caches`.`status`,
107
                    `caches`.`search_time`,
108
                    `caches`.`way_length`,
109
                    `caches`.`logpw`,
110
                    `caches`.`wp_oc`,
111
                    `caches`.`wp_gc`,
112
                    `caches`.`show_cachelists`,
113
                    `caches`.`protect_old_coords`,
114
                    `caches`.`node`,
115
                    `user`.`username`,
116
                    `stat_caches`.`picture`
117
                FROM `caches`
118
                INNER JOIN `user` ON `caches`.`user_id`=`user`.`user_id`
119
                LEFT JOIN `stat_caches` ON `caches`.`cache_id`=`stat_caches`.`cache_id`
120
                WHERE `caches`.`cache_id`='&1'",
121
            $cache_id
122
        );
123
        $cache_record = sql_fetch_array($cache_rs);
124
        sql_free_result($cache_rs);
125
126
        if ($cache_record !== false) {
127
            if ($cache_record['user_id'] == $usr['userid'] || $login->listingAdmin()) {
128
                $tplname = 'editcache';
129
                tpl_acceptsAndPurifiesHtmlInput();
130
131
                require $stylepath . '/editcache.inc.php';
132
133
                if ($cache_record['node'] != $oc_nodeid) {
134
                    tpl_errorMsg('editcache', $error_wrong_node);
135
                    exit;
136
                }
137
138
                //here we read all used information from the form if submitted, otherwise from DB
139
                $cache_name = trim(isset($_POST['name']) ? trim($_POST['name']) : $cache_record['name']);  // Ocprop
140
                $cache_type = isset($_POST['type']) ? $_POST['type'] : $cache_record['type'];
141
                if (!isset($_POST['size'])) {
142
                    if ($cache_type == 4 || $cache_type == 5) {
143
                        $sel_size = 7;
144
                    } else {
145
                        $sel_size = $cache_record['size'];
146
                    }
147
                } else {
148
                    $sel_size = isset($_POST['size']) ? $_POST['size'] : $cache_record['size'];
149
                }
150
                $cache_hidden_day = isset($_POST['hidden_day']) ? $_POST['hidden_day'] : date(
151
                    'd',
152
                    strtotime($cache_record['date_hidden'])
153
                );  // Ocprop
154
                $cache_hidden_month = isset($_POST['hidden_month']) ? $_POST['hidden_month'] : date(
155
                    'm',
156
                    strtotime($cache_record['date_hidden'])
157
                );  // Ocprop
158
                $cache_hidden_year = isset($_POST['hidden_year']) ? $_POST['hidden_year'] : date(
159
                    'Y',
160
                    strtotime($cache_record['date_hidden'])
161
                );  // Ocprop
162
163
                if (is_null($cache_record['date_activate'])) {
164
                    $cache_activate_day = isset($_POST['activate_day']) ? $_POST['activate_day'] : date('d');
165
                    $cache_activate_month = isset($_POST['activate_month']) ? $_POST['activate_month'] : date('m');
166
                    $cache_activate_year = isset($_POST['activate_year']) ? $_POST['activate_year'] : date('Y');
167
                    $cache_activate_hour = isset($_POST['activate_hour']) ? $_POST['activate_hour'] : date('H');
168
                } else {
169
                    $cache_activate_day = isset($_POST['activate_day']) ? $_POST['activate_day'] : date(
170
                        'd',
171
                        strtotime($cache_record['date_activate'])
172
                    );
173
                    $cache_activate_month = isset($_POST['activate_month']) ? $_POST['activate_month'] : date(
174
                        'm',
175
                        strtotime($cache_record['date_activate'])
176
                    );
177
                    $cache_activate_year = isset($_POST['activate_year']) ? $_POST['activate_year'] : date(
178
                        'Y',
179
                        strtotime($cache_record['date_activate'])
180
                    );
181
                    $cache_activate_hour = isset($_POST['activate_hour']) ? $_POST['activate_hour'] : date(
182
                        'H',
183
                        strtotime($cache_record['date_activate'])
184
                    );
185
                }
186
187
                $cache_difficulty = isset($_POST['difficulty']) ? $_POST['difficulty'] : $cache_record['difficulty'];  // Ocprop
188
                $cache_terrain = isset($_POST['terrain']) ? $_POST['terrain'] : $cache_record['terrain'];  // Ocprop
189
                $cache_country = isset($_POST['country']) ? $_POST['country'] : $cache_record['country'];  // Ocprop
190
                $show_all_countries = isset($_POST['show_all_countries']) ? $_POST['show_all_countries'] : 0;
191
                $listing_modified = isset($_POST['listing_modified']) ? $_POST['listing_modified'] + 0 : 0;
192
                $status = isset($_POST['status']) ? $_POST['status'] : $cache_record['status'];  // Ocprop
193
                $status_old = $cache_record['status'];
194
                $search_time = isset($_POST['search_time']) ? trim($_POST['search_time']) : $cache_record['search_time'];
195
                $way_length = isset($_POST['way_length']) ? trim($_POST['way_length']) : $cache_record['way_length'];
196
197
                if ($status_old == 5 && $status == 5) {
198
                    if (isset($_REQUEST['publish'])) {  // Ocprop; see also res_state_warning.tpl
199
                        $publish = $_REQUEST['publish'];
200 View Code Duplication
                        if (!($publish == 'now' || $publish == 'later' || $publish == 'notnow')) {
201
                            // somebody messed up the POST-data, so we do not publish the cache,
202
                            // since he isn't published right now (status=5)
203
                            $publish = 'notnow';
204
                        }
205
                        if ($publish == 'now') {
206
                            $status = 1;
207
                        }
208
                    } else {
209
                        if (is_null($cache_record['date_activate'])) {
210
                            $publish = 'notnow';
211
                        } else {
212
                            $publish = 'later';
213
                        }
214
                    }
215
                } else {
216
                    $publish = isset($_POST['publish']) ? $_POST['publish'] : 'now';
217 View Code Duplication
                    if (!($publish == 'now' || $publish == 'later' || $publish == 'notnow')) {
218
                        // somebody messed up the POST-data, so the cache has to be published (status<5)
219
                        $publish = 'now';
220
                    }
221
                }
222
223
                $bAdmin = sqlValue("SELECT `admin` FROM `user` WHERE `user_id` = &1", 0, $usr['userid']);
0 ignored issues
show
The call to sqlValue() has too many arguments starting with $usr['userid'].

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
224
225
                if ($status == 7 && ($bAdmin & ADMIN_USER) != ADMIN_USER) {
226
                    $status = $status_old;
227
                }
228
229
                if ($status_old == 7) {  // cache is locked
230
                    // only admins can change status of locked caches
231
                    if (($bAdmin & ADMIN_USER) != ADMIN_USER) {
232
                        // no status change allowed for normal user
233
                        $status = $status_old;
234
                    }
235
                }
236
237
                $search_time = mb_ereg_replace(',', '.', $search_time);
238
                $way_length = mb_ereg_replace(',', '.', $way_length);
239
240 View Code Duplication
                if (mb_strpos($search_time, ':') == mb_strlen($search_time) - 3) {
241
                    $st_hours = mb_substr($search_time, 0, mb_strpos($search_time, ':'));
242
                    $st_minutes = mb_substr($search_time, mb_strlen($st_hours) + 1);
243
244
                    if (is_numeric($st_hours) && is_numeric($st_minutes)) {
245
                        if (($st_minutes >= 0) && ($st_minutes < 60)) {
246
                            $search_time = $st_hours + $st_minutes / 60;
247
                        }
248
                    }
249
                }
250
251
                $log_pw = isset($_POST['log_pw']) ? mb_substr($_POST['log_pw'], 0, 20) : $cache_record['logpw'];
252
                // fix #4356: gc waypoints are frequently copy&pasted with leading spaces
253
                $wp_gc = isset($_POST['wp_gc']) ? strtoupper(trim($_POST['wp_gc'])) : $cache_record['wp_gc'];  // Ocprop
254
                $showlists = isset($_POST['showlists']) ? 1 : $cache_record['show_cachelists'] + 0;
255
                $protect_old_coords = isset($_POST['protect_old_coords']) ? 1 : $cache_record['protect_old_coords'] + 0;
256
257
                // name
258
                $name_not_ok = false;
259
                if ($cache_name == "") {
260
                    $name_not_ok = true;
261
                }
262
263
                if (isset($_POST['latNS'])) {
264
                    //get coords from post-form
265
                    $coords_latNS = $_POST['latNS'];  // Ocprop
266
                    $coords_lonEW = $_POST['lonEW'];  // Ocprop
267
                    $coords_lat_h = trim($_POST['lat_h']);  // Ocprop
268
                    $coords_lon_h = trim($_POST['lon_h']);  // Ocprop
269
                    $coords_lat_min = trim($_POST['lat_min']);  // Ocprop
270
                    $coords_lon_min = trim($_POST['lon_min']);  // Ocprop
271
                } else {
272
                    //get coords from DB
273
                    $coords_lon = $cache_record['longitude'];
274
                    $coords_lat = $cache_record['latitude'];
275
276
                    if ($coords_lon < 0) {
277
                        $coords_lonEW = 'W';
278
                        $coords_lon = -$coords_lon;
279
                    } else {
280
                        $coords_lonEW = 'E';
281
                    }
282
283
                    if ($coords_lat < 0) {
284
                        $coords_latNS = 'S';
285
                        $coords_lat = -$coords_lat;
286
                    } else {
287
                        $coords_latNS = 'N';
288
                    }
289
290
                    $coords_lat_h = floor($coords_lat);
291
                    $coords_lon_h = floor($coords_lon);
292
293
                    $coords_lat_min = sprintf("%02.3f", round(($coords_lat - $coords_lat_h) * 60, 3));
294
                    $coords_lon_min = sprintf("%02.3f", round(($coords_lon - $coords_lon_h) * 60, 3));
295
                }
296
297
                //here we validate the data
298
299
                //coords
300
                $lon_not_ok = false;
301
302
                if (!mb_ereg_match('^[0-9]{1,3}$', $coords_lon_h)) {
303
                    $lon_not_ok = true;
304
                } else {
305
                    $lon_not_ok = (($coords_lon_h >= 0) && ($coords_lon_h < 180)) ? false : true;
306
                }
307
308
                if (is_numeric($coords_lon_min)) {
309
                    // important: use here |=
310
                    $lon_not_ok |= (($coords_lon_min >= 0) && ($coords_lon_min < 60)) ? false : true;
311
                } else {
312
                    $lon_not_ok = true;
313
                }
314
315
                //same with lat
316
                $lat_not_ok = false;
317
318
                if (!mb_ereg_match('^[0-9]{1,3}$', $coords_lat_h)) {
319
                    $lat_not_ok = true;
320
                } else {
321
                    $lat_not_ok = (($coords_lat_h >= 0) && ($coords_lat_h < 180)) ? false : true;
322
                }
323
324
                if (is_numeric($coords_lat_min)) {
325
                    // important: use here |=
326
                    $lat_not_ok |= (($coords_lat_min >= 0) && ($coords_lat_min < 60)) ? false : true;
327
                } else {
328
                    $lat_not_ok = true;
329
                }
330
331
                //check effort
332
                $time_not_ok = true;
333
                tpl_set_var('effort_message', '');
334
                if (is_numeric($search_time) || ($search_time == '')) {
335
                    $time_not_ok = false;
336
                }
337
                if ($time_not_ok) {
338
                    tpl_set_var('effort_message', $time_not_ok_message);
339
                    $error = true;
340
                }
341
                $way_length_not_ok = true;
342
                if (is_numeric($way_length) || ($way_length == '')) {
343
                    $way_length_not_ok = false;
344
                }
345
                if ($way_length_not_ok) {
346
                    tpl_set_var('effort_message', $way_length_not_ok_message);
347
                    $error = true;
348
                }
349
350
                //check GC waypoint
351
                $wpgc_not_ok = $wp_gc != '' && !preg_match("/^(?:GC|CX)[0-9A-Z]{3,6}$/", $wp_gc);
352
                if ($wpgc_not_ok) {
353
                    $error = true;
354
                }
355
356
                //check hidden_since
357
                $hidden_date_not_ok = true;
358
                $hidden_date_mismatch = false;
359
                if (is_numeric($cache_hidden_day) && is_numeric($cache_hidden_month) &&
360
                    is_numeric($cache_hidden_year)
361
                ) {
362
                    $hidden_date_not_ok =
363
                        (checkdate($cache_hidden_month, $cache_hidden_day, $cache_hidden_year) == false);
364
                }
365
                if ($hidden_date_not_ok == false && $publish != 'notnow') {
366
                    $hidden_date = mktime(
367
                        0,
368
                        0,
369
                        0,
370
                        $cache_hidden_month,
371
                        $cache_hidden_day,
372
                        $cache_hidden_year
373
                    );
374
                    if ($status_old != 5) {
375
                        // the cache has already been published
376
                        $publish_date = strtotime(substr($cache_record['date_created'], 0, 10));
377
                    } elseif ($publish == 'later') {
378
                        // Activation hour can be ignored here. This simplifies checking event dates.
379
                        $publish_date = mktime(
380
                            0,
381
                            0,
382
                            0,
383
                            $cache_activate_month,
384
                            $cache_activate_day,
385
                            $cache_activate_year
386
                        );
387
                    } else {
388
                        // the cache is to be published now
389
                        $publish_date = time();
390
                    }
391
                    if (($cache_type == 6 && $hidden_date < $publish_date) ||
392
                        ($cache_type != 6 && $hidden_date > $publish_date)) {
393
                        $hidden_date_mismatch = true;
394
                    }
395
                }
396
397
                //check date_activate
398
                if ($status == 5) {
399
                    $activate_date_not_ok = true;
400
                    if (is_numeric($cache_activate_day) && is_numeric($cache_activate_month) &&
401
                        is_numeric($cache_activate_year) && is_numeric($cache_activate_hour)
402
                    ) {
403
                        $activate_date_not_ok =
404
                            checkdate(
405
                                $cache_activate_month,
406
                                $cache_activate_day,
407
                                $cache_activate_year
408
                            ) == false
409
                            || $cache_activate_hour < 0
410
                            || $cache_activate_hour > 23;
411
                    }
412
                } else {
413
                    $activate_date_not_ok = false;
414
                }
415
416
                //check status and publish options
417
                if (($status == 5 && $publish == 'now') || ($status != 5 && ($publish == 'later' || $publish == 'notnow'))) {
418
                    tpl_set_var('status_message', $status_message);
419
                    $status_not_ok = true;
420
                } else {
421
                    tpl_set_var('status_message', '');
422
                    $status_not_ok = false;
423
                }
424
425
                //check cache size
426
                $size_not_ok = false;
427
                if ($sel_size != 7 && ($cache_type == 4 || $cache_type == 5)) {
428
                    $error = true;
429
                    $size_not_ok = true;
430
                }
431
432
                //difficulty / terrain
433
                $diff_not_ok = false;
434
                tpl_set_var('diff_message', '');
435 View Code Duplication
                if ($cache_difficulty < 2 || $cache_difficulty > 10 || $cache_terrain < 2 || $cache_terrain > 10) {
436
                    tpl_set_var('diff_message', $diff_not_ok_message);
437
                    $error = true;
438
                    $diff_not_ok = true;
439
                }
440
441
                // cache-attributes
442
                $attribs_not_ok = false;
443
                if (isset($_POST['cache_attribs'])) {
444
                    $cache_attribs = mb_split(';', $_POST['cache_attribs']);
445
                } else {
446
                    // get attribs for this cache from db
447
                    $rs = sql("SELECT `attrib_id` FROM `caches_attributes` WHERE `cache_id`='&1'", $cache_id);
448
                    if (mysql_num_rows($rs) > 0) {
449
                        unset($cache_attribs);
450
                        while ($record = sql_fetch_array($rs)) {
451
                            $cache_attribs[] = $record['attrib_id'];
452
                        }
453
                        unset($record);
454
                    } else {
455
                        $cache_attribs = [];
456
                    }
457
                    sql_free_result($rs);
458
                }
459
460 View Code Duplication
                if (in_array(ATTRIB_ID_SAFARI, $cache_attribs) && $cache_type != 4) {
461
                    tpl_set_var('safari_message', $safari_not_allowed_message);
462
                    $error = true;
463
                    $attribs_not_ok = true;
464
                } else {
465
                    tpl_set_var('safari_message', '');
466
                }
467
468
                //try to save to DB?
469
                if (isset($_POST['submit'])) {  // Ocprop
470
                    // all validations ok?
471
                    if (!(
472
                        $hidden_date_not_ok || $hidden_date_mismatch ||
473
                        $lat_not_ok || $lon_not_ok || $name_not_ok ||
474
                        $time_not_ok || $way_length_not_ok || $size_not_ok ||
475
                        $activate_date_not_ok || $status_not_ok || $diff_not_ok ||
476
                        $attribs_not_ok || $wpgc_not_ok
477
                    )
478
                    ) {
479
                        $cache_lat = $coords_lat_h + $coords_lat_min / 60;
480
                        if ($coords_latNS == 'S') {
481
                            $cache_lat = -$cache_lat;
482
                        }
483
484
                        $cache_lon = $coords_lon_h + $coords_lon_min / 60;
485
                        if ($coords_lonEW == 'W') {
486
                            $cache_lon = -$cache_lon;
487
                        }
488
489 View Code Duplication
                        if ($publish == 'now') {
490
                            $activation_date = 'NULL';
491
                        } elseif ($publish == 'later') {
492
                            $status = 5;
493
                            $activation_date =
494
                                "'" . sql_escape(
495
                                    date(
496
                                        'Y-m-d H:i:s',
497
                                        mktime(
498
                                            $cache_activate_hour,
499
                                            0,
500
                                            0,
501
                                            $cache_activate_month,
502
                                            $cache_activate_day,
503
                                            $cache_activate_year
504
                                        )
505
                                    )
506
                                ) . "'";
507
                        } elseif ($publish == 'notnow') {
508
                            $status = 5;
509
                            $activation_date = 'NULL';
510
                        } else {
511
                            // should never happen
512
                            $activation_date = 'NULL';
513
                        }
514
515
                        // check for Ocprop data to ignore
516
                        if ($ocpropping) {
517
                            $rs = sql("SELECT `type`, `size` FROM `caches` WHERE `cache_id`='&1'", $cache_id);
518
                            if ($r = sql_fetch_assoc($rs)) {
519
                                if ($r['type'] == 8 && $cache_type == 7) {
520
                                    $cache_type = 8;
521
                                }
522
                                if ($r['type'] == 10 && $cache_type == 2) {
523
                                    $cache_type = 10;
524
                                }
525
                                if ($r['size'] == 8 && ($sel_size == 1 || $sel_size == 2)) {
526
                                    $sel_size = 8;
527
                                }
528
                            }
529
                            sql_free_result($rs);
530
                        }
531
532
                        // fix showlists setting
533
                        if (!isset($_POST['showlists'])) {
534
                            $showlists = 0;
535
                        }
536
                        if (!isset($_POST['protect_old_coords'])) {
537
                            $protect_old_coords = 0;
538
                        }
539
540
                        // save to DB
541
                        // Status update will trigger touching the last_modified date of all depending records.
542
                        // Status change via editcache.php is no longer available via the user interface,
543
                        // but still used by Ocprop and maybe other tools.
544
                        sql("SET @STATUS_CHANGE_USER_ID='&1'", $usr['userid']);
545
                        sql(
546
                            "UPDATE `caches` SET `name`='&1', `longitude`='&2', `latitude`='&3', `type`='&4', `date_hidden`='&5', `country`='&6', `size`='&7', `difficulty`='&8', `terrain`='&9', `status`='&10', `search_time`='&11', `way_length`='&12', `logpw`='&13', `wp_gc`='&14', `show_cachelists`='&15', `protect_old_coords`='&16', `date_activate` = $activation_date WHERE `cache_id`='&17'",
547
                            $cache_name,
548
                            $cache_lon,
549
                            $cache_lat,
550
                            $cache_type,
551
                            date('Y-m-d', mktime(0, 0, 0, $cache_hidden_month, $cache_hidden_day, $cache_hidden_year)),
552
                            $cache_country,
553
                            $sel_size,
554
                            $cache_difficulty,
555
                            $cache_terrain,
556
                            $status,
557
                            $search_time,
558
                            $way_length,
559
                            $log_pw,
560
                            $wp_gc,
561
                            $showlists,
562
                            $protect_old_coords,
563
                            $cache_id
564
                        );
565
566
                        // send notification on admin intervention
567 View Code Duplication
                        if ($cache_record['user_id'] != $usr['userid'] &&
568
                            $opt['logic']['admin']['listingadmin_notification'] != ''
569
                        ) {
570
                            mail(
571
                                $opt['logic']['admin']['listingadmin_notification'],
572
                                mb_ereg_replace(
573
                                    '{occode}',
574
                                    $cache_record['wp_oc'],
575
                                    mb_ereg_replace(
576
                                        '{username}',
577
                                        $usr['username'],
578
                                        t('Cache listing {occode} has been modified by {username}')
579
                                    )
580
                                ),
581
                                t('The modifications can be checked via vandalism restore function.')
582
                            );
583
                        }
584
585
                        // generate status-change log
586
                        if ($status != $status_old && $status_old != 5) {
587
                            switch ($status) {
588
                                case 1:
589
                                    $logtype = 10;
590
                                    break;
591
                                case 2:
592
                                    $logtype = 11;
593
                                    break;
594
                                case 3:
595
                                    $logtype = 9;
596
                                    break;
597
                                case 6:
598
                                    $logtype = 13;
599
                                    break;
600
                                default:
601
                                    $logtype = 0;  // ???
602
                            }
603
                            if ($logtype > 0) {
604
                                sql(
605
                                    "INSERT INTO `cache_logs` (`node`, `cache_id`, `user_id`, `type`, `date`)
606
                                         VALUES ('&1','&2','&3','&4','&5')",
607
                                    $oc_nodeid,
608
                                    $cache_id,
609
                                    $usr['userid'],
610
                                    $logtype,
611
                                    date('Y-m-d')
612
                                );
613
                                // notifications will be automatically generated
614
                            }
615
                        }
616
617
                        // do not use slave server for the next time ...
618
                        db_slave_exclude();
619
620
                        // update cache attributes
621
                        $attriblist = '999';
622
                        $countCacheAttrIbs = count($cache_attribs);
623
                        for ($i = 0; $i < $countCacheAttrIbs; $i++) {
624
                            if ($cache_attribs[$i] + 0 > 0) {
625
                                sql(
626
                                    "INSERT IGNORE INTO `caches_attributes` (`cache_id`, `attrib_id`)
627
                                     VALUES('&1', '&2')",
628
                                    $cache_id,
629
                                    $cache_attribs[$i] + 0
630
                                );
631
                                $attriblist .= "," . ($cache_attribs[$i] + 0);
632
                            }
633
                        }
634
635
                        sql(
636
                            "DELETE FROM `caches_attributes`
637
                             WHERE `cache_id`='&1'
638
                             AND `attrib_id`
639
                             NOT IN (" . $attriblist . ')',
640
                            // SQL injections in $attriblist prevented by adding 0 above
641
                            $cache_id
642
                        );
643
644
                        StatisticPicture::deleteStatisticPicture($usr['userid']);
645
646
                        //display cache-page
647
                        tpl_redirect('viewcache.php?cacheid=' . urlencode($cache_id));
648
                        // Ocprop: Location:\s*$viewcacheUrl\?cacheid=([0-9]+)
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
649
                        // (s.a. tpl_redirect() in common.inc.php
650
                        exit;
651
                    }
652
                } elseif (isset($_POST['show_all_countries_submit'])) {
653
                    $show_all_countries = 1;
654
                }
655
656
                //here we only set up the template variables
657
658
                //build countrylist
659
                $countriesoptions = '';
660
661
                //check if selected country is in list_default
662 View Code Duplication
                if ($show_all_countries == 0) {
663
                    $rs = sql(
664
                        "SELECT `show` FROM `countries_list_default` WHERE `show`='&1' AND `lang`='&2'",
665
                        $cache_country,
666
                        $locale
667
                    );
668
                    if (mysql_num_rows($rs) == 0) {
669
                        $show_all_countries = 1;
670
                    }
671
                    sql_free_result($rs);
672
                }
673
674
                //get the record
675
                if ($show_all_countries == 0) {
676
                    $rs = sql(
677
                        "SELECT `countries`.`short`, IFNULL(`sys_trans_text`.`text`, `countries`.`name`) AS `name`
678
                         FROM `countries`
679
                         INNER JOIN `countries_list_default`
680
                           ON `countries_list_default`.`show`=`countries`.`short`
681
                         LEFT JOIN `sys_trans`
682
                           ON `countries`.`trans_id`=`sys_trans`.`id`
683
                         LEFT JOIN `sys_trans_text`
684
                           ON `sys_trans`.`id`=`sys_trans_text`.`trans_id`
685
                           AND `sys_trans_text`.`lang`='&1'
686
                         WHERE `countries_list_default`.`lang`='&1'
687
                         ORDER BY `name` ASC",
688
                        $locale
689
                    );
690
                } else {
691
                    $rs = sql(
692
                        "SELECT `countries`.`short`, IFNULL(`sys_trans_text`.`text`, `countries`.`name`) AS `name`
693
                         FROM `countries`
694
                         LEFT JOIN `sys_trans`
695
                           ON `countries`.`trans_id`=`sys_trans`.`id`
696
                         LEFT JOIN `sys_trans_text`
697
                           ON `sys_trans`.`id`=`sys_trans_text`.`trans_id`
698
                         AND `sys_trans_text`.`lang`='&1'
699
                         ORDER BY `name` ASC",
700
                        $locale
701
                    );
702
                }
703
704
                while ($record = sql_fetch_assoc($rs)) {
705
                    $sSelected = ($record['short'] == $cache_country) ? ' selected="selected"' : '';
706
                    $countriesoptions .=
707
                        '<option value="'
708
                        . htmlspecialchars($record['short'], ENT_COMPAT, 'UTF-8')
709
                        . '"' . $sSelected . '>'
710
                        . htmlspecialchars($record['name'], ENT_COMPAT, 'UTF-8')
711
                        . '</option>' . "\n";
712
                }
713
                tpl_set_var('countryoptions', $countriesoptions);
714
                sql_free_result($rs);
715
716
                // cache-attributes
717
                $bBeginLine = true;
718
                $nPrevLineAttrCount = 0;
719
                $nLineAttrCount = 0;
720
721
                $cache_attrib_list = '';
722
                $cache_attrib_array = '';
723
                $cache_attribs_string = '';
724
725
                $rsAttrGroup = sql(
726
                    "SELECT `attribute_groups`.`id`,
727
                            IFNULL(`sys_trans_text`.`text`,
728
                            `attribute_groups`.`name`) AS `name`,
729
                            `attribute_categories`.`color`
730
                     FROM `attribute_groups`
731
                     INNER JOIN `attribute_categories`
732
                       ON `attribute_groups`.`category_id`=`attribute_categories`.`id`
733
                     LEFT JOIN `sys_trans`
734
                       ON `attribute_groups`.`trans_id`=`sys_trans`.`id`
735
                     LEFT JOIN `sys_trans_text`
736
                       ON `sys_trans`.`id`=`sys_trans_text`.`trans_id`
737
                       AND `sys_trans_text`.`lang`='&1'
738
                     ORDER BY `attribute_groups`.`category_id` ASC, `attribute_groups`.`id` ASC",
739
                    $locale
740
                );
741
                while ($rAttrGroup = sql_fetch_assoc($rsAttrGroup)) {
742
                    $group_line = '';
743
744
                    $rs = sql(
745
                        "SELECT `cache_attrib`.`id`,
746
                                IFNULL(`ttname`.`text`, `cache_attrib`.`name`) AS `name`,
747
                                `cache_attrib`.`icon_undef`,
748
                                `cache_attrib`.`icon_large`,
749
                                IFNULL(`ttdesc`.`text`, `cache_attrib`.`html_desc`) AS `html_desc`
750
                         FROM `cache_attrib`
751
                         LEFT JOIN `caches_attributes`
752
                           ON `cache_attrib`.`id`=`caches_attributes`.`attrib_id`
753
                           AND `caches_attributes`.`cache_id`='&2'
754
                         LEFT JOIN `sys_trans` AS `tname`
755
                           ON `cache_attrib`.`trans_id`=`tname`.`id`
756
                           AND `cache_attrib`.`name`=`tname`.`text`
757
                         LEFT JOIN `sys_trans_text` AS `ttname`
758
                           ON `tname`.`id`=`ttname`.`trans_id`
759
                           AND `ttname`.`lang`='&1'
760
                         LEFT JOIN `sys_trans` AS `tdesc`
761
                           ON `cache_attrib`.`html_desc_trans_id`=`tdesc`.`id`
762
                           AND `cache_attrib`.`html_desc`=`tdesc`.`text`
763
                         LEFT JOIN `sys_trans_text` AS `ttdesc`
764
                           ON `tdesc`.`id`=`ttdesc`.`trans_id`
765
                           AND `ttdesc`.`lang`='&1'
766
                         WHERE `cache_attrib`.`group_id`='&3'
767
                         AND NOT IFNULL(`cache_attrib`.`hidden`, 0) = 1
768
                         AND (`cache_attrib`.`selectable`!=0 OR `caches_attributes`.`cache_id`='&2')
769
                         ORDER BY `cache_attrib`.`group_id` ASC, `cache_attrib`.`id` ASC",
770
                        $locale,
771
                        $cache_id,
772
                        $rAttrGroup['id']
773
                    );
774 View Code Duplication
                    while ($record = sql_fetch_array($rs)) {
775
                        $line = $cache_attrib_pic;
776
777
                        $line = mb_ereg_replace('{attrib_id}', $record['id'], $line);
778
                        $line = mb_ereg_replace('{attrib_text}', escape_javascript($record['name']), $line);
779
                        if (in_array($record['id'], $cache_attribs)) {
780
                            $line = mb_ereg_replace('{attrib_pic}', $record['icon_large'], $line);
781
                        } else {
782
                            $line = mb_ereg_replace('{attrib_pic}', $record['icon_undef'], $line);
783
                        }
784
                        $line = mb_ereg_replace('{html_desc}', escape_javascript($record['html_desc']), $line);
785
                        $line = mb_ereg_replace('{name}', escape_javascript($record['name']), $line);
786
                        $line = mb_ereg_replace('{color}', $rAttrGroup['color'], $line);
787
                        $group_line .= $line;
788
                        $nLineAttrCount++;
789
790
                        $line = $cache_attrib_js;
791
                        $line = mb_ereg_replace('{id}', $record['id'], $line);
792
                        if (in_array($record['id'], $cache_attribs)) {
793
                            $line = mb_ereg_replace('{selected}', 1, $line);
794
                        } else {
795
                            $line = mb_ereg_replace('{selected}', 0, $line);
796
                        }
797
                        $line = mb_ereg_replace('{img_undef}', $record['icon_undef'], $line);
798
                        $line = mb_ereg_replace('{img_large}', $record['icon_large'], $line);
799
                        $line = mb_ereg_replace(
800
                            '{conflicting_attribs}',
801
                            implode(',', attribute::getConflictingAttribIds($record['id'])),
802
                            $line
803
                        );
804
                        if ($cache_attrib_array != '') {
805
                            $cache_attrib_array .= ',';
806
                        }
807
                        $cache_attrib_array .= $line;
808
809
                        if (in_array($record['id'], $cache_attribs)) {
810
                            if ($cache_attribs_string != '') {
811
                                $cache_attribs_string .= ';';
812
                            }
813
                            $cache_attribs_string .= $record['id'];
814
                        }
815
                    }
816
                    sql_free_result($rs);
817
818 View Code Duplication
                    if ($group_line != '') {
819
                        $group_img = $cache_attrib_group;
820
                        $group_img = mb_ereg_replace('{color}', $rAttrGroup['color'], $group_img);
821
                        $group_img = mb_ereg_replace('{attribs}', $group_line, $group_img);
822
                        $group_img = mb_ereg_replace(
823
                            '{name}',
824
                            htmlspecialchars($rAttrGroup['name'], ENT_COMPAT, 'UTF-8'),
825
                            $group_img
826
                        );
827
828
                        if ($bBeginLine == true) {
829
                            $cache_attrib_list .= '<div class="attribswide">';
830
                            $bBeginLine = false;
831
                        }
832
833
                        $cache_attrib_list .= $group_img;
834
                        $nPrevLineAttrCount += $nLineAttrCount;
835
836
                        $nLineAttrCount = 0;
837
                    }
838
                }
839
                sql_free_result($rsAttrGroup);
840
                if ($bBeginLine == false) {
841
                    $cache_attrib_list .= '</div>';
842
                }
843
844
                tpl_set_var('cache_attrib_list', $cache_attrib_list);
845
                tpl_set_var('jsattributes_array', $cache_attrib_array);
846
                tpl_set_var('cache_attribs', $cache_attribs_string);
847
848
                //difficulty
849
                $difficulty_options = '';
850 View Code Duplication
                for ($i = 2; $i <= 10; $i++) {
851
                    if ($cache_difficulty == $i) {
852
                        $difficulty_options .= '<option value="' . $i . '" selected="selected">' . $i / 2 . '</option>';
853
                    } else {
854
                        $difficulty_options .= '<option value="' . $i . '">' . $i / 2 . '</option>';
855
                    }
856
                    $difficulty_options .= "\n";
857
                }
858
                tpl_set_var('difficultyoptions', $difficulty_options);
859
860
                //build terrain options
861
                $terrain_options = '';
862 View Code Duplication
                for ($i = 2; $i <= 10; $i++) {
863
                    if ($cache_terrain == $i) {
864
                        $terrain_options .= '<option value="' . $i . '" selected="selected">' . $i / 2 . '</option>';
865
                    } else {
866
                        $terrain_options .= '<option value="' . $i . '">' . $i / 2 . '</option>';
867
                    }
868
                    $terrain_options .= "\n";
869
                }
870
                tpl_set_var('terrainoptions', $terrain_options);
871
872
                //build typeoptions
873
                $types = '';
874
                $rsTypes = sql(
875
                    "SELECT `cache_type`.`id`,
876
                            IFNULL(`sys_trans_text`.`text`,
877
                            `cache_type`.`en`) AS `name`
878
                     FROM `cache_type`
879
                     LEFT JOIN `sys_trans`
880
                       ON `cache_type`.`trans_id`=`sys_trans`.`id`
881
                     LEFT JOIN `sys_trans_text`
882
                       ON `sys_trans`.`id`=`sys_trans_text`.`trans_id`
883
                       AND `sys_trans_text`.`lang`='" . sql_escape($locale) . "'
884
                     ORDER BY `cache_type`.`ordinal` ASC"
885
                );
886 View Code Duplication
                while ($rType = sql_fetch_assoc($rsTypes)) {
887
                    $sSelected = ($rType['id'] == $cache_type) ? ' selected="selected"' : '';
888
                    $types .=
889
                        '<option value="' . $rType['id'] . '"' . $sSelected . '>'
890
                        . htmlspecialchars($rType['name'], ENT_COMPAT, 'UTF-8')
891
                        . '</option>';
892
                }
893
                sql_free_result($rsTypes);
894
                tpl_set_var('typeoptions', $types);
895
896
                //build sizeoptions
897
                $sizes = '';
898
                $rsSizes = sql(
899
                    "SELECT `cache_size`.`id`,
900
                            IFNULL(`sys_trans_text`.`text`, `cache_size`.`name`) AS `name`
901
                     FROM `cache_size`
902
                     LEFT JOIN `sys_trans`
903
                       ON `cache_size`.`trans_id`=`sys_trans`.`id`
904
                     LEFT JOIN `sys_trans_text`
905
                       ON `sys_trans`.`id`=`sys_trans_text`.`trans_id`
906
                       AND `sys_trans_text`.`lang`='" . sql_escape($locale) . "'
907
                     ORDER BY `cache_size`.`ordinal` ASC"
908
                );
909 View Code Duplication
                while ($rSize = sql_fetch_assoc($rsSizes)) {
910
                    $sSelected = ($rSize['id'] == $sel_size) ? ' selected="selected"' : '';
911
                    $sizes .=
912
                        '<option value="' . $rSize['id'] . '"' . $sSelected . '>'
913
                        . htmlspecialchars($rSize['name'], ENT_COMPAT, 'UTF-8')
914
                        . '</option>';
915
                }
916
                sql_free_result($rsSizes);
917
                tpl_set_var('sizeoptions', $sizes);
918
919
                //Cachedescs
920
                $desclangs = mb_split(',', $cache_record['desc_languages']);
921
                $cache_descs = '';
922
                $gc_com_refs = false;
923
                foreach ($desclangs as $desclang) {
924
                    if (count($desclangs) > 1) {
925
                        $remove_url =
926
                            'removedesc.php?cacheid=' . urlencode($cache_id)
927
                            . '&desclang=' . urlencode($desclang);
928
                        $removedesc =
929
                            '&nbsp;[<a href="'
930
                            . htmlspecialchars($remove_url, ENT_COMPAT, 'UTF-8')
931
                            . '" onclick="testListingModified(this)" >' . $remove . '</a>]';
932
                    } else {
933
                        $removedesc = '';
934
                    }
935
936
                    $resp = sql(
937
                        "SELECT `desc` FROM `cache_desc` WHERE `cache_id`='&1' AND `language`='&2'",
938
                        $cache_id,
939
                        $desclang
940
                    );
941
                    $row = sql_fetch_array($resp);
942
                    if (mb_strpos($row['desc'], "http://img.groundspeak.com/") !== false) {
943
                        $gc_com_refs = true;
944
                    }
945
                    sql_free_result($resp);
946
947
                    $edit_url = 'editdesc.php?cacheid=' . urlencode($cache_id) . '&desclang=' . urlencode($desclang);
948
949
                    $cache_descs .=
950
                        '<tr><td colspan="2">'
951
                        . htmlspecialchars(db_LanguageFromShort($desclang), ENT_COMPAT, 'UTF-8')
952
                        . ' [<a href="' . htmlspecialchars($edit_url, ENT_COMPAT, 'UTF-8')
953
                        . '" onclick="testListingModified(this)" >' . $edit . '</a>]'
954
                        . $removedesc . '</td></tr>';
955
                }
956
                tpl_set_var('cache_descs', $cache_descs);
957
958
                if ($gc_com_refs) {
959
                    tpl_set_var('gc_com_refs_start', '');
960
                    tpl_set_var('gc_com_refs_end', '');
961
                } else {
962
                    tpl_set_var('gc_com_refs_start', '<!--');
963
                    tpl_set_var('gc_com_refs_end', '-->');
964
                }
965
966
                //Status
967
                $statusoptions = '';
968
                if ($status_old != 7) {
969
                    $rsStatus = sql(
970
                        "SELECT `cache_status`.`id`,
971
                                IFNULL(`sys_trans_text`.`text`,
972
                                `cache_status`.`name`) AS `name`
973
                         FROM `cache_status`
974
                         LEFT JOIN `sys_trans`
975
                           ON `cache_status`.`trans_id`=`sys_trans`.`id`
976
                         LEFT JOIN `sys_trans_text`
977
                           ON `sys_trans`.`id`=`sys_trans_text`.`trans_id`
978
                           AND `sys_trans_text`.`lang`='" . sql_escape($locale) . "'
979
                         WHERE `cache_status`.`id` NOT IN (4, 5, 7)
980
                           OR `cache_status`.`id`='" . sql_escape($status_old + 0) . "'
981
                         ORDER BY `cache_status`.`id` ASC"
982
                    );
983 View Code Duplication
                    while ($rStatus = sql_fetch_assoc($rsStatus)) {
984
                        $sSelected = ($rStatus['id'] == $status) ? ' selected="selected"' : '';
985
                        if ($sSelected != '' || $status_old == 5) {
986
                            $statusoptions .=
987
                                '<option value="'
988
                                . htmlspecialchars($rStatus['id'], ENT_COMPAT, 'UTF-8')
989
                                . '"' . $sSelected . '>'
990
                                . htmlspecialchars($rStatus['name'], ENT_COMPAT, 'UTF-8')
991
                                . '</option>';
992
                        }
993
                    }
994
                    sql_free_result($rsStatus);
995
                } else {
996
                    $statusoptions .=
997
                        '<option value="7" selected="selected">'
998
                        . htmlspecialchars(t("Locked, invisible"), ENT_COMPAT, 'UTF-8')
999
                        . '</option>';
1000
                }
1001
                tpl_set_var('statusoptions', $statusoptions);
1002
                $statuschange_a_msg =  mb_ereg_replace('%1', $cache_id, $status_change_a);
1003
                $statuschange_msg =  mb_ereg_replace('{a}', $statuschange_a_msg, $status_change);
1004
                tpl_set_var('statuschange', $status_old == 5 ? '' : $statuschange_msg);
1005
1006
                // show activation form?
1007
                if ($status_old == 5) {  // status = not yet published
1008
                    $tmp = $activation_form;
1009
1010
                    $tmp = mb_ereg_replace(
1011
                        '{activate_day}',
1012
                        htmlspecialchars($cache_activate_day, ENT_COMPAT, 'UTF-8'),
1013
                        $tmp
1014
                    );
1015
                    $tmp = mb_ereg_replace(
1016
                        '{activate_month}',
1017
                        htmlspecialchars($cache_activate_month, ENT_COMPAT, 'UTF-8'),
1018
                        $tmp
1019
                    );
1020
                    $tmp = mb_ereg_replace(
1021
                        '{activate_year}',
1022
                        htmlspecialchars($cache_activate_year, ENT_COMPAT, 'UTF-8'),
1023
                        $tmp
1024
                    );
1025
                    $tmp = mb_ereg_replace('{publish_now_checked}', ($publish == 'now') ? 'checked' : '', $tmp);
1026
                    $tmp = mb_ereg_replace('{publish_later_checked}', ($publish == 'later') ? 'checked' : '', $tmp);
1027
                    $tmp = mb_ereg_replace('{publish_notnow_checked}', ($publish == 'notnow') ? 'checked' : '', $tmp);
1028
1029
                    $activation_hours = '';
1030 View Code Duplication
                    for ($i = 0; $i <= 23; $i++) {
1031
                        if ($cache_activate_hour == $i) {
1032
                            $activation_hours .= '<option value="' . $i . '" selected="selected">' . $i . '</option>';
1033
                        } else {
1034
                            $activation_hours .= '<option value="' . $i . '">' . $i . '</option>';
1035
                        }
1036
                        $activation_hours .= "\n";
1037
                    }
1038
                    $tmp = mb_ereg_replace('{activation_hours}', $activation_hours, $tmp);
1039
1040
                    if ($activate_date_not_ok) {
1041
                        $tmp = mb_ereg_replace('{activate_on_message}', $date_message, $tmp);
1042
                    } else {
1043
                        $tmp = mb_ereg_replace('{activate_on_message}', '', $tmp);
1044
                    }
1045
1046
                    tpl_set_var('activation_form', $tmp);
1047
                } else {
1048
                    tpl_set_var('activation_form', '');
1049
                }
1050
1051
                if ($cache_record['picture'] > 0) {
1052
                    $pictures = '';
1053
                    $rspictures = sql(
1054
                        "SELECT `url`, `title`, `uuid`
1055
                         FROM `pictures`
1056
                         WHERE `object_id` = '&1'
1057
                         AND `object_type` = 2
1058
                         ORDER BY `seq`",
1059
                        $cache_id
1060
                    );
1061
1062
                    $countRsPictures = mysql_num_rows($rspictures);
1063
                    for ($i = 0; $i < $countRsPictures; $i++) {
1064
                        $tmpline = ($i == 0 ? $pictureline0 : $pictureline);
1065
                        $pic_record = sql_fetch_array($rspictures);
1066
1067
                        $tmpline = mb_ereg_replace(
1068
                            '{link}',
1069
                            htmlspecialchars($pic_record['url'], ENT_COMPAT, 'UTF-8'),
1070
                            $tmpline
1071
                        );
1072
                        $tmpline = mb_ereg_replace(
1073
                            '{title}',
1074
                            htmlspecialchars($pic_record['title'], ENT_COMPAT, 'UTF-8'),
1075
                            $tmpline
1076
                        );
1077
                        $tmpline = mb_ereg_replace(
1078
                            '{uuid}',
1079
                            htmlspecialchars($pic_record['uuid'], ENT_COMPAT, 'UTF-8'),
1080
                            $tmpline
1081
                        );
1082
1083
                        $pictures .= $tmpline;
1084
                    }
1085
1086
                    $pictures = mb_ereg_replace('{lines}', $pictures, $picturelines);
1087
                    mysql_free_result($rspictures);
1088
                    tpl_set_var('pictures', $pictures);
1089
                } else {
1090
                    tpl_set_var('pictures', $nopictures);
1091
                }
1092
                tpl_set_var('gc_com_msg2', mb_ereg_replace('%1', $opt['page']['sitename'], $gc_com_msg2));
1093
1094
                tpl_set_var('waypoints', getWaypoints($cache_id));
1095
1096
                tpl_set_var('cacheid', htmlspecialchars($cache_id, ENT_COMPAT, 'UTF-8'));
1097
                tpl_set_var('name', htmlspecialchars($cache_name, ENT_COMPAT, 'UTF-8'));
1098
1099
                tpl_set_var('ownername', htmlspecialchars($cache_record['username'], ENT_COMPAT, 'UTF-8'));
1100
1101
                tpl_set_var('date_day', htmlspecialchars($cache_hidden_day, ENT_COMPAT, 'UTF-8'));
1102
                tpl_set_var('date_month', htmlspecialchars($cache_hidden_month, ENT_COMPAT, 'UTF-8'));
1103
                tpl_set_var('date_year', htmlspecialchars($cache_hidden_year, ENT_COMPAT, 'UTF-8'));
1104
1105
                tpl_set_var('selLatN', ($coords_latNS == 'N') ? ' selected="selected"' : '');
1106
                tpl_set_var('selLatS', ($coords_latNS == 'S') ? ' selected="selected"' : '');
1107
                tpl_set_var('selLonE', ($coords_lonEW == 'E') ? ' selected="selected"' : '');
1108
                tpl_set_var('selLonW', ($coords_lonEW == 'W') ? ' selected="selected"' : '');
1109
                tpl_set_var('lat_h', htmlspecialchars($coords_lat_h, ENT_COMPAT, 'UTF-8'));
1110
                tpl_set_var('lat_min', htmlspecialchars($coords_lat_min, ENT_COMPAT, 'UTF-8'));
1111
                tpl_set_var('lon_h', htmlspecialchars($coords_lon_h, ENT_COMPAT, 'UTF-8'));
1112
                tpl_set_var('lon_min', htmlspecialchars($coords_lon_min, ENT_COMPAT, 'UTF-8'));
1113
1114
                tpl_set_var('name_message', ($name_not_ok == true) ? $name_message : '');
1115
                tpl_set_var('lon_message', ($lon_not_ok == true) ? $coords_message : '');
1116
                tpl_set_var('lat_message', ($lat_not_ok == true) ? $coords_message : '');
1117
                if ($hidden_date_mismatch == true) {
1118
                    if ($cache_type == 6) {
1119
                        tpl_set_var('date_message', $event_before_publish_message);
1120
                    } else {
1121
                        tpl_set_var('date_message', $hide_after_publish_message);
1122
                    }
1123
                } else {
1124
                    tpl_set_var('date_message', ($hidden_date_not_ok == true) ? $date_message : '');
1125
                }
1126
                tpl_set_var('size_message', ($size_not_ok == true) ? $sizemismatch_message : '');
1127
                tpl_set_var('wpgc_message', ($wpgc_not_ok == true) ? $bad_wpgc_message : '');
1128
1129
                if ($lon_not_ok || $lat_not_ok || $hidden_date_not_ok || $name_not_ok) {
1130
                    tpl_set_var('general_message', $error_general);
1131
                } else {
1132
                    tpl_set_var('general_message', '');
1133
                }
1134
1135
                tpl_set_var('cacheid_urlencode', htmlspecialchars(urlencode($cache_id), ENT_COMPAT, 'UTF-8'));
1136
                tpl_set_var(
1137
                    'cacheuuid_urlencode',
1138
                    htmlspecialchars(urlencode($cache_record['uuid']), ENT_COMPAT, 'UTF-8')
1139
                );
1140
                tpl_set_var('show_all_countries', $show_all_countries);
1141
                tpl_set_var('show_all_countries_submit', ($show_all_countries == 0) ? $all_countries_submit : '');
1142
                tpl_set_var('listing_modified', $listing_modified);
1143
                tpl_set_var('savealert', $savealert);
1144
1145
                $st_hours = floor($search_time);
1146
                $st_minutes = sprintf('%02.0F', ($search_time - $st_hours) * 60);
1147
1148
                tpl_set_var('search_time', $st_hours . ':' . $st_minutes);
1149
1150
                tpl_set_var('way_length', $way_length);
1151
                tpl_set_var('log_pw', htmlspecialchars($log_pw, ENT_COMPAT, 'UTF-8'));
1152
                tpl_set_var('wp_gc', htmlspecialchars($wp_gc, ENT_COMPAT, 'UTF-8'));
1153
                tpl_set_var('showlists_checked', $showlists ? 'checked="checked"' : '');
1154
                tpl_set_var('protectcoords_checked', $protect_old_coords ? 'checked="checked"' : '');
1155
1156
                tpl_set_var('reset', $reset);  // obsolete
1157
                tpl_set_var('submit', $submit);
1158
            }
1159
        }
1160
    }
1161
}
1162
1163
//make the template and send it out
1164
tpl_BuildTemplate();
1165