<?php //error_reporting(E_ALL); //ini_set("display_errors",1); session_start(); try { //$uid = $_SESSION["usernum"]; $calendar_db = new PDO("mysql:dbname=moneybook", "root", "root", array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')); $calendar_db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $uid = 1; //$calendar_db->quote("qpit2u"); $query_string = "SELECT m.num,m.usernum,m.in_out,t.type,m.amount,m.time,m.detail FROM money_book m JOIN type_book t ON m.type = t.type WHERE m.usernum =" . $uid . " ORDER BY m.num"; $data = $calendar_db->query($query_string); makeXml($data); } catch (PDOException $ex) { print $ex->getMessage(); print "<p>database Error Ocurred</p>"; } ?> <!-- xml coding --> <?php function makeXml($dbObject) { header("Content-Type: application/xml"); $doc = new DomDocument('1.0', 'UTF-8'); $uid = $doc->createElement('uid'); for ($i = 0; $i < $dbObject->rowCount(); $i++) { $result = $dbObject->fetch(); if ($i === 0) { $id = $doc->createAttribute('id'); $id->value = $result['usernum'];
date_default_timezone_set("UTC"); $filename = "output.gpx"; $firstDate = new DateTime("2014-04-01"); $date = new DateTime("2014-05-01"); //$date = new DateTime(); <- for today's date $segments = []; @unlink($filename); while ($date > $firstDate) { $formattedDate = $date->format('Ymd'); $date->sub(new DateInterval("P1D")); echo "Getting segments for {$formattedDate} (total " . count($segments) . ")...\n"; foreach (getSegments($formattedDate) as $s) { array_push($segments, $s); } } file_put_contents($filename, makeXml($segments)); function getSegments($date) { $data = json_decode(file_get_contents("https://api.moves-app.com/api/v1/user/storyline/daily/{$date}?trackPoints=true&access_token=<<INSERT ACCESS TOKEN HERE>>")); return $data[0]->segments; } function makeXml($segments) { $xml = '<?xml version="1.0"?><gpx xmlns="http://www.topografix.com/GPX/1/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <metadata> <link href="http://moves-to-gpx.ppy.sh"> <text>moves-to-gpx</text> </link> </metadata> <trk> <name>outpu</name>';