コード例 #1
0
ファイル: ocxml11.php プロジェクト: kojoty/opencaching-pl
function startXmlSession($sModifiedSince, $bCache, $bCachedesc, $bCachelog, $bUser, $bPicture, $bRemovedObject, $bPictureFromCachelog, $selection)
{
    global $rootpath;
    // session anlegen
    XDb::xSql('INSERT INTO `xmlsession` (`last_use`, `modified_since`, `date_created`)
        VALUES (NOW(), ?, NOW())', date('Y-m-d H:i:s', strtotime($sModifiedSince)));
    $sessionid = XDb::xLastInsertId();
    $recordcount['caches'] = 0;
    $recordcount['cachedescs'] = 0;
    $recordcount['cachelogs'] = 0;
    $recordcount['users'] = 0;
    $recordcount['pictures'] = 0;
    $recordcount['removedobjects'] = 0;
    if ($selection['type'] == 0) {
        // ohne selection
        if ($bCache == 1) {
            $stmt = XDb::xSql("INSERT INTO xmlsession_data (`session_id`, `object_type`, `object_id`)\n                SELECT {$sessionid}, 2, `cache_id` FROM `caches`\n                WHERE `last_modified` >= ? AND `status`!=5 AND `status`!=6 AND `status`!=4", $sModifiedSince);
            $recordcount['caches'] = XDb::xNumRows($stmt);
        }
        if ($bCachedesc == 1) {
            $stmt = XDb::xSql("INSERT INTO `xmlsession_data` (`session_id`, `object_type`, `object_id`)\n                 SELECT {$sessionid}, 3, `cache_desc`.`id`\n                 FROM `cache_desc` INNER JOIN `caches` ON `cache_desc`.`cache_id`=`caches`.`cache_id`\n                 WHERE `cache_desc`.`last_modified` >= ? AND `caches`.`status`!=5\n                    AND `status`!=6 AND `status`!=4", $sModifiedSince);
            $recordcount['cachedescs'] = XDb::xNumRows($stmt);
        }
        if ($bCachelog == 1) {
            $stmt = XDb::xSql("INSERT INTO `xmlsession_data` (`session_id`, `object_type`, `object_id`)\n                 SELECT {$sessionid}, 1, `cache_logs`.`id`\n                 FROM `cache_logs` INNER JOIN `caches` ON `cache_logs`.`cache_id`=`caches`.`cache_id`\n                 WHERE `cache_logs`.`last_modified` >= ? AND `caches`.`status`!=5\n                    AND `status`!=6 AND `status`!=4 AND `cache_logs`.`deleted`=0", $sModifiedSince);
            $recordcount['cachelogs'] = XDb::xNumRows($stmt);
        }
        if ($bUser == 1) {
            $stmt = XDb::xSql("INSERT INTO `xmlsession_data` (`session_id`, `object_type`, `object_id`)\n                 SELECT {$sessionid}, 4, `user_id` FROM `user` WHERE `last_modified` >= ? ", $sModifiedSince);
            $recordcount['users'] = XDb::xNumRows($stmt);
        }
        if ($bPicture == 1) {
            $stmt = XDb::xSql("INSERT INTO `xmlsession_data` (`session_id`, `object_type`, `object_id`)\n                 SELECT {$sessionid}, 6, `pictures`.`id`\n                 FROM `pictures`\n                    INNER JOIN `caches` ON `pictures`.`object_type`=2\n                        AND `pictures`.`object_id`=`caches`.`cache_id`\n                 WHERE `pictures`.`last_modified` >= ?\n                    AND `caches`.`status`!=5 AND `status`!=6 AND `status`!=4\n                 UNION DISTINCT\n                 SELECT {$sessionid}, 6, `pictures`.`id`\n                 FROM `pictures`\n                    INNER JOIN `cache_logs` ON `pictures`.`object_type`=1\n                        AND `pictures`.`object_id`=`cache_logs`.`id`\n                    INNER JOIN `caches` ON `cache_logs`.`cache_id`=`caches`.`cache_id`\n                 WHERE `pictures`.`last_modified` >= ?\n                    AND `caches`.`status`!=5 AND `status`!=6 AND `caches`.`status`!=4\n                    AND `cache_logs`.`deleted`=0", $sModifiedSince, $sModifiedSince);
            $recordcount['pictures'] = XDb::xNumRows($stmt);
        }
        if ($bRemovedObject == 1) {
            $stmt = XDb::xSql("INSERT INTO `xmlsession_data` (`session_id`, `object_type`, `object_id`)\n                 SELECT {$sessionid}, 7, `id` FROM `removed_objects`\n                 WHERE `removed_date` >= ? ", $sModifiedSince);
            $recordcount['removedobjects'] = XDb::xNumRows($stmt);
        }
    } else {
        $qWhere = '';
        $qHaving = '';
        if ($selection['type'] == 1) {
            XDb::xSql("CREATE TEMPORARY TABLE `tmpxmlSesssionCaches` (`cache_id` int(11), PRIMARY KEY (`cache_id`)) ENGINE=MEMORY\n                 SELECT DISTINCT `cache_countries`.`cache_id`\n                 FROM `caches`, `cache_countries`\n                 WHERE `caches`.`cache_id`=`cache_countries`.`cache_id` AND `cache_countries`.`country`= ?\n                    AND `caches`.`status`!=5 AND `status`!=6 AND `status`!=4", $selection['country']);
        } else {
            if ($selection['type'] == 2) {
                require_once $rootpath . 'lib/search.inc.php';
                XDb::xSql('CREATE TEMPORARY TABLE `tmpxmlSesssionCaches` (`cache_id` int(11), `distance` double, KEY (`cache_id`)) ENGINE=MEMORY
                 SELECT `cache_coordinates`.`cache_id`,' . getSqlDistanceFormula($selection['lon'], $selection['lat'], $selection['distance'], 'cache_coordinates') . ' `distance`
                 FROM `caches`, `cache_coordinates`
                 WHERE `cache_coordinates`.`cache_id`=`caches`.`cache_id` AND `caches`.`status`!=5
                     AND `status`!=6 AND `status`!=4
                     AND `cache_coordinates`.`latitude` > ' . getMinLat($selection['lon'], $selection['lat'], $selection['distance']) . '
                     AND `cache_coordinates`.`latitude` < ' . getMaxLat($selection['lon'], $selection['lat'], $selection['distance']) . '
                     AND `cache_coordinates`.`longitude` >' . getMinLon($selection['lon'], $selection['lat'], $selection['distance']) . '
                     AND `cache_coordinates`.`longitude` < ' . getMaxLon($selection['lon'], $selection['lat'], $selection['distance']) . '
                 HAVING `distance` < ' . ($selection['distance'] + 0));
            } else {
                if ($selection['type'] == 3) {
                    XDb::xSql("CREATE TEMPORARY TABLE `tmpxmlSesssionCaches` (`cache_id` int(11), PRIMARY KEY (`cache_id`)) ENGINE=MEMORY\n                 SELECT " . $selection['cacheid'] . " AS cache_id");
                }
            }
        }
        if ($bCache == 1) {
            $stmt = XDb::xSql("INSERT INTO `xmlsession_data` (`session_id`, `object_type`, `object_id`)\n                 SELECT DISTINCT {$sessionid}, 2, `tmpxmlSesssionCaches`.`cache_id`\n                 FROM `tmpxmlSesssionCaches`, `caches`\n                 WHERE `tmpxmlSesssionCaches`.`cache_id`=`caches`.`cache_id`\n                     AND `caches`.`last_modified` >= ? ", $sModifiedSince);
            $recordcount['caches'] = XDb::xNumRows($stmt);
        }
        if ($bCachedesc == 1) {
            $stmt = XDb::xSql("INSERT INTO `xmlsession_data` (`session_id`, `object_type`, `object_id`)\n                 SELECT DISTINCT {$sessionid}, 3, `cache_desc`.`id`\n                 FROM `cache_desc`, `tmpxmlSesssionCaches`\n                 WHERE `cache_desc`.`cache_id`=`tmpxmlSesssionCaches`.`cache_id`\n                     AND `cache_desc`.`last_modified` >= ? ", $sModifiedSince);
            $recordcount['cachedescs'] = XDb::xNumRows($stmt);
        }
        if ($bCachelog == 1) {
            $stmt = XDb::xSql("INSERT INTO `xmlsession_data` (`session_id`, `object_type`, `object_id`)\n                 SELECT DISTINCT {$sessionid}, 1, `cache_logs`.`id`\n                 FROM `cache_logs`, `tmpxmlSesssionCaches`\n                 WHERE `cache_logs`.`deleted`=0\n                     AND `cache_logs`.`cache_id`=`tmpxmlSesssionCaches`.`cache_id`\n                     AND `cache_logs`.`last_modified` >= ? ", $sModifiedSince);
            $recordcount['cachelogs'] = XDb::xNumRows($stmt);
        }
        if ($bPicture == 1) {
            // cachebilder
            $stmt = XDb::xSql("INSERT INTO `xmlsession_data` (`session_id`, `object_type`, `object_id`)\n                 SELECT DISTINCT {$sessionid}, 6, `pictures`.`id`\n                 FROM `pictures`, `tmpxmlSesssionCaches`\n                 WHERE `pictures`.`object_id`=`tmpxmlSesssionCaches`.`cache_id`\n                     AND `pictures`.`object_type`=2\n                     AND `pictures`.`last_modified` >= ? ", $sModifiedSince);
            $recordcount['pictures'] = XDb::xNumRows($stmt);
            // bilder von logs
            if ($bPictureFromCachelog == 1) {
                $stmt = XDb::xSql("INSERT INTO `xmlsession_data` (`session_id`, `object_type`, `object_id`)\n                     SELECT DISTINCT {$sessionid}, 6, `pictures`.id\n                     FROM `pictures` , `cache_logs`, `tmpxmlSesssionCaches`\n                     WHERE `tmpxmlSesssionCaches`.`cache_id`=`cache_logs`.`cache_id`\n                         AND `cache_logs`.`deleted`=0\n                         AND `pictures`.`object_type`=1\n                         AND `pictures`.`object_id`=`cache_logs`.`id`\n                         AND `pictures`.`last_modified` >= ? ", $sModifiedSince);
                $recordcount['pictures'] += XDb::xNumRows($stmt);
            }
        }
        if ($bRemovedObject == 1) {
            $stmt = XDb::xSql("INSERT INTO `xmlsession_data` (`session_id`, `object_type`, `object_id`)\n                 SELECT DISTINCT {$sessionid}, 7, `id`\n                 FROM `removed_objects`\n                 WHERE `removed_date` >= ? ", $sModifiedSince);
            $recordcount['removedobjects'] = XDb::xNumRows($stmt);
        }
    }
    XDb::xSql('UPDATE `xmlsession` SET `caches`= ?, `cachedescs`= ?, `cachelogs`= ?, `users`= ?, `pictures`= ?, `removedobjects`= ?
        WHERE `id`= ? LIMIT 1', $recordcount['caches'], $recordcount['cachedescs'], $recordcount['cachelogs'], $recordcount['users'], $recordcount['pictures'], $recordcount['removedobjects'], $sessionid);
    return $sessionid;
}
コード例 #2
0
ファイル: log.php プロジェクト: kojoty/opencaching-pl
     $descMode == 3 ? $dmde_2 = 1 : ($dmde_2 = 0);
     // This query INSERT cache_log entry ONLY IF such entry NOT EXISTS
     XDb::xSql("INSERT INTO `cache_logs` (\n                                `cache_id`, `user_id`, `type`, `date`, `text`,\n                                `text_html`, `text_htmledit`, `date_created`, `last_modified`,\n                                `uuid`, `node`)\n                            SELECT ?, ?, ?, ?, ?, ? ,? ,NOW(), NOW(), ?, ?\n                            FROM  `cache_logs`\n                            WHERE NOT EXISTS (\n                                SELECT * FROM `cache_logs`\n                                WHERE `type`=1 AND `user_id` = ?\n                                    AND `cache_id` = ?\n                                    AND `deleted` = '0')\n                            LIMIT 1", $cache_id, $usr['userid'], $log_type, $log_date, $log_text, $dmde_1, $dmde_2, $log_uuid, $oc_nodeid, $usr['userid'], $cache_id);
 } else {
     XDb::xSql("INSERT INTO `cache_logs` (`cache_id`, `user_id`, `type`, `date`, `text`, `text_html`,\n                                         `text_htmledit`, `date_created`, `last_modified`, `uuid`, `node`)\n                            VALUES ( ?, ?, ?, ?, ?, ?, ?, NOW(), NOW(), ?, ?)", $cache_id, $usr['userid'], $log_type, $log_date, $log_text, 1, 1, $log_uuid, $oc_nodeid);
 }
 // mobline by Łza (mobile caches)
 // insert to database.
 // typ kesza mobilna 8, typ logu == 4
 if ($log_type == 4 && $cache_type == 8) {
     // typ logu 4 - przeniesiona
     $doNotUpdateCoordinates = false;
     ini_set('display_errors', 1);
     // error_reporting(E_ALL);
     // id of last SQL entery
     $last_id_4_mobile_moved = XDb::xLastInsertId();
     // converting from HH MM.MMM to DD.DDDDDD
     $wspolrzedneNS = $wsp_NS_st + round($wsp_NS_min, 3) / 60;
     if ($wybor_NS == 'S') {
         $wspolrzedneNS = -$wspolrzedneNS;
     }
     $wspolrzedneWE = $wsp_WE_st + round($wsp_WE_min, 3) / 60;
     if ($wybor_WE == 'W') {
         $wspolrzedneWE = -$wspolrzedneWE;
     }
     // if it is first log "cache mooved" then move start coordinates from table caches
     // to table cache_moved and create log type cache_moved, witch description
     // "depart point" or something like this.
     $is_any_cache_movedlog = XDb::xMultiVariableQueryValue("SELECT COUNT(*) FROM `cache_moved` WHERE `cache_id` = :1 ", 0, $cache_id);
     if ($is_any_cache_movedlog == 0) {
         $tmp_move_query = XDb::xSql("SELECT `user_id`, `longitude`, `latitude`, `date_hidden` FROM `caches` WHERE `cache_id` = ? ", $cache_id);
コード例 #3
0
ファイル: newcache.php プロジェクト: kojoty/opencaching-pl
         $activation_column = ' ';
     } elseif ($publish == 'later') {
         $sel_status = 5;
         $activation_date = date('Y-m-d H:i:s', mktime($activate_hour, 0, 0, $activate_month, $activate_day, $activate_year));
     } elseif ($publish == 'notnow') {
         $sel_status = 5;
         $activation_date = null;
     } else {
         // should never happen
         $activation_date = null;
     }
 }
 $cache_uuid = create_uuid();
 //add record to caches table
 XDb::xSql("INSERT INTO `caches` SET\n                        `cache_id` = '', `user_id` = ?, `name` = ?, `longitude` = ?, `latitude` = ?, `last_modified` = NOW(),\n                        `date_created` = NOW(), `type` = ?, `status` = ?, `country` = ?, `date_hidden` = ?, `date_activate` = ?,\n                        `founds` = 0, `notfounds` = 0, `watcher` = 0, `notes` = 0, `last_found` = NULL, `size` = ?, `difficulty` = ?,\n                        `terrain` = ?, `uuid` = ?, `logpw` = ?, `search_time` = ?, `way_length` = ?, `wp_gc` = ?,\n                        `wp_nc` = ?, `wp_ge` = ?, `wp_tc` = ?, `node` = ? ", $usr['userid'], $name, $longitude, $latitude, $sel_type, $sel_status, $sel_country, date('Y-m-d', $hidden_date), $activation_date, $sel_size, $difficulty, $terrain, $cache_uuid, $log_pw, $search_time, $way_length, $wp_gc, $wp_nc, $wp_ge, $wp_tc, $oc_nodeid);
 $cache_id = XDb::xLastInsertId();
 // insert cache_location
 $code1 = $sel_country;
 $eLang = XDb::xEscape($lang);
 $adm1 = XDb::xMultiVariableQueryValue("SELECT `countries`.{$eLang} FROM `countries`\n                                    WHERE `countries`.`short`= :1 ", 0, $code1);
 // check if selected country has no districts, then use $default_region
 if ($sel_region == -1) {
     $sel_region = $default_region;
 }
 if ($sel_region != "0") {
     $code3 = $sel_region;
     $adm3 = XDb::xMultiVariableQueryValue("SELECT `name` FROM `nuts_codes`\n                        WHERE `code`= :1 ", 0, $sel_region);
 } else {
     $code3 = null;
     $adm3 = null;
 }
コード例 #4
0
ファイル: search.php プロジェクト: kojoty/opencaching-pl
     $options['cachedifficulty_1'] = isset($_REQUEST['cachedifficulty_1']) ? $_REQUEST['cachedifficulty_1'] : '';
     $options['cachedifficulty_2'] = isset($_REQUEST['cachedifficulty_2']) ? $_REQUEST['cachedifficulty_2'] : '';
     $options['cacheterrain_1'] = isset($_REQUEST['cacheterrain_1']) ? $_REQUEST['cacheterrain_1'] : '';
     $options['cacheterrain_2'] = isset($_REQUEST['cacheterrain_2']) ? $_REQUEST['cacheterrain_2'] : '';
     $options['cacherating'] = isset($_REQUEST['cacherating']) ? $_REQUEST['cacherating'] : 0;
     if ($options['showresult'] != 0) {
         //save the search-options in the database
         if (isset($options['queryid']) && isset($options['userid'])) {
             if ($options['userid'] != 0) {
                 $sqlstr = "UPDATE `queries` SET `options`= :1, `last_queried`=NOW() WHERE `id`= :2 AND `user_id`= :3";
                 $dbc->multiVariableQuery($sqlstr, serialize($options), $options['queryid'], $options['userid']);
             }
         } else {
             XDb::xSql('INSERT INTO `queries` (`user_id`, `options`, `uuid`, `last_queried`)
                     VALUES (0, ?, UUID(), NOW())', serialize($options));
             $options['queryid'] = XDb::xLastInsertId();
         }
     } else {
         $options['queryid'] = 0;
     }
 }
 set_cookie_setting('lastqueryid', $options['queryid']);
 //remove old queries (after 1 hour without use)
 $removedate = date('Y-m-d H:i:s', time() - 3600);
 $sqlstr = "DELETE FROM `queries` WHERE `last_queried` < :1 AND `user_id`=0";
 $dbc->multiVariableQuery($sqlstr, $removedate);
 //prepare output
 if (!isset($options['showresult'])) {
     $options['showresult'] = '0';
 }
 if ($options['showresult'] == 1) {