예제 #1
0
 function getLocalTime($id)
 {
     global $objDatabase;
     $locations = new Locations();
     $sql = "SELECT * FROM cometobservations WHERE id = \"{$id}\"";
     $run = $objDatabase->selectRecordset($sql);
     $get = $run->fetch(PDO::FETCH_OBJ);
     if ($get) {
         $date = $get->date;
         $time = $get->time;
         $loc = $get->locationid;
         if ($loc) {
             $date = sscanf($date, "%4d%2d%2d");
             $timezone = $locations->getLocationPropertyFromId($loc, 'timezone');
             $dateTimeZone = new DateTimeZone($timezone);
             $datestr = sprintf("%02d", $date[1]) . "/" . sprintf("%02d", $date[2]) . "/" . $date[0];
             $dateTime = new DateTime($datestr, $dateTimeZone);
             // Geeft tijdsverschil terug in seconden
             $timedifference = $dateTimeZone->getOffset($dateTime);
             $timedifference = $timedifference / 3600.0;
             if ($time < 0) {
                 return $time;
             }
             $time = sscanf(sprintf("%04d", $time), "%2d%2d");
             $hours = $time[0] + (int) $timedifference;
             $minutes = $time[1];
             // We are converting from UT to local time -> we should add the time difference!
             $timedifferenceminutes = ($timedifference - (int) $timedifference) * 60;
             $minutes = $minutes + $timedifferenceminutes;
             if ($minutes < 0) {
                 $hours = $hours - 1;
                 $minutes = $minutes + 60;
             } else {
                 if ($minutes > 60) {
                     $hours = $hours + 1;
                     $minutes = $minutes - 60;
                 }
             }
             if ($hours < 0) {
                 $hours = $hours + 24;
             }
             if ($hours >= 24) {
                 $hours = $hours - 24;
             }
             $time = $hours * 100 + $minutes;
         }
     }
     return $time;
 }
예제 #2
0
 public function rssObservations()
 {
     global $objObservation, $objInstrument, $objLocation, $objPresentations, $objObserver, $baseURL, $objUtil;
     $dom = new DomDocument('1.0', 'US-ASCII');
     // add root fcga -> The header
     $rssInfo = $dom->createElement('rss');
     $rssDom = $dom->appendChild($rssInfo);
     $attr = $dom->createAttribute("version");
     $rssInfo->appendChild($attr);
     $attrText = $dom->createTextNode("2.0");
     $attr->appendChild($attrText);
     $attr = $dom->createAttribute("xmlns:content");
     $rssInfo->appendChild($attr);
     $attrText = $dom->createTextNode("http://purl.org/rss/1.0/modules/content/");
     $attr->appendChild($attrText);
     $attr = $dom->createAttribute("xmlns:dc");
     $rssInfo->appendChild($attr);
     $attrText = $dom->createTextNode("http://purl.org/dc/elements/1.1/");
     $attr->appendChild($attrText);
     $attr = $dom->createAttribute("xmlns:atom");
     $rssInfo->appendChild($attr);
     $attrText = $dom->createTextNode("http://www.w3.org/2005/Atom");
     $attr->appendChild($attrText);
     // add root - <channel>
     $channelDom = $rssDom->appendChild($dom->createElement('channel'));
     // add root - <channel> - <title>
     $titleDom = $channelDom->appendChild($dom->createElement('title'));
     $titleDom->appendChild($dom->createTextNode("DeepskyLog"));
     // add root - <channel> - <description>
     $descDom = $channelDom->appendChild($dom->createElement('description'));
     $descDom->appendChild($dom->createTextNode("DeepskyLog - visual deepsky and comets observations"));
     // add root - <channel> - <atom>
     $atomDom = $channelDom->appendChild($dom->createElement('atom:link'));
     $attr = $dom->createAttribute("href");
     $atomDom->appendChild($attr);
     $attrText = $dom->createTextNode($baseURL . "observations.rss");
     $attr->appendChild($attrText);
     $attr = $dom->createAttribute("rel");
     $atomDom->appendChild($attr);
     $attrText = $dom->createTextNode("self");
     $attr->appendChild($attrText);
     $attr = $dom->createAttribute("type");
     $atomDom->appendChild($attr);
     $attrText = $dom->createTextNode("application/rss+xml");
     $attr->appendChild($attrText);
     // add root - <channel> - <link>
     $linkDom = $channelDom->appendChild($dom->createElement('link'));
     $linkDom->appendChild($dom->createTextNode("http://www.deepskylog.org/"));
     $theDate = date('r');
     // add root - <channel> - <link>
     $lbdDom = $channelDom->appendChild($dom->createElement('lastBuildDate'));
     $lbdDom->appendChild($dom->createTextNode($theDate));
     // Get the new deepsky observations of the last month
     $theDate = date('Ymd', strtotime('-1 month'));
     $_GET['minyear'] = substr($theDate, 0, 4);
     $_GET['minmonth'] = substr($theDate, 4, 2);
     $_GET['minday'] = substr($theDate, 6, 2);
     $query = array("catalog" => '%', "mindate" => $objUtil->checkGetDate('minyear', 'minmonth', 'minday'));
     $result = $objObservation->getObservationFromQuery($query, 'A');
     while (list($key, $value) = each($result)) {
         // add root - <channel> - <item>
         $itemDom = $channelDom->appendChild($dom->createElement('item'));
         $titleDom = $itemDom->appendChild($dom->createElement('title'));
         $titleDom->appendChild($dom->createTextNode($value['observername'] . " : " . $value['objectname'] . " with " . htmlspecialchars_decode($objInstrument->getInstrumentPropertyFromId($value['instrumentid'], 'name')) . " from " . $objLocation->getLocationPropertyFromId($objObservation->getDsObservationProperty($value['observationid'], 'locationid'), 'name')));
         $linkDom = $itemDom->appendChild($dom->createElement('link'));
         $linkDom->appendChild($dom->createCDATASection($baseURL . "index.php?indexAction=detail_observation&observation=" . $value['observationid'] . "&QobsKey=0&dalm=D"));
         $descDom = $itemDom->appendChild($dom->createElement('description'));
         $descDom->appendChild($dom->createCDATASection($objPresentations->br2nl(utf8_encode($value['observationdescription']))));
         $authorDom = $itemDom->appendChild($dom->createElement('dc:creator'));
         $authorDom->appendChild($dom->createCDATASection($value['observername']));
         $guidDom = $itemDom->appendChild($dom->createElement('guid'));
         $guidDom->appendChild($dom->createTextNode("deepsky" . $value['observationid']));
         $attr = $dom->createAttribute("isPermaLink");
         $guidDom->appendChild($attr);
         $attrText = $dom->createTextNode("false");
         $attr->appendChild($attrText);
         $pubDateDom = $itemDom->appendChild($dom->createElement('pubDate'));
         date_default_timezone_set('UTC');
         $time = -999;
         $obs = $objObservation->getAllInfoDsObservation($value['observationid']);
         $time = $obs['time'];
         if ($time >= "0") {
             $hour = (int) ($time / 100);
             $minute = $time - 100 * $hour;
         } else {
             $hour = 0;
             $minute = 0;
         }
         $date = $value['observationdate'];
         $year = substr($date, 0, 4);
         $month = substr($date, 4, 2);
         $day = substr($date, 6, 2);
         $pubDateDom->appendChild($dom->createTextNode(date("r", mktime($hour, $minute, 0, $month, $day, $year))));
     }
     include_once "cometobjects.php";
     include_once "observers.php";
     include_once "instruments.php";
     include_once "locations.php";
     include_once "cometobservations.php";
     include_once "icqmethod.php";
     include_once "icqreferencekey.php";
     global $instDir, $objCometObject;
     $objects = new CometObjects();
     $observer = new Observers();
     $instrument = new Instruments();
     $observation = new CometObservations();
     $location = new Locations();
     $util = $this;
     $ICQMETHODS = new ICQMETHOD();
     $ICQREFERENCEKEYS = new ICQREFERENCEKEY();
     $cometsResult = $observation->getObservationFromQuery($query);
     while (list($key, $value) = each($cometsResult)) {
         $objectname = $objCometObject->getName($observation->getObjectId($value));
         // add root - <channel> - <item>
         $itemDom = $channelDom->appendChild($dom->createElement('item'));
         $title = htmlspecialchars_decode($objectname);
         // Location and instrument
         if ($observation->getLocationId($value) != 0 && $observation->getLocationId($value) != 1) {
             $title = $title . " from " . htmlspecialchars_decode($location->getLocationPropertyFromId($observation->getLocationId($value), 'name'));
         }
         if ($observation->getInstrumentId($value) != 0) {
             $title = $title . " with " . htmlspecialchars_decode($instrument->getInstrumentPropertyFromId($observation->getInstrumentId($value), 'name'));
         }
         $titleDom = $itemDom->appendChild($dom->createElement('title'));
         $titleDom->appendChild($dom->createTextNode($title));
         $linkDom = $itemDom->appendChild($dom->createElement('link'));
         $linkDom->appendChild($dom->createCDATASection($baseURL . "index.php?indexAction=comets_detail_observation&observation=" . $value));
         // Description
         $description = $observation->getDescription($value);
         if (strcmp($description, "") != 0) {
             $descDom = $itemDom->appendChild($dom->createElement('description'));
             $descDom->appendChild($dom->createCDATASection($objPresentations->br2nl(utf8_encode($description))));
         } else {
             $descDom = $itemDom->appendChild($dom->createElement('description'));
             $descDom->appendChild($dom->createCDATASection(""));
         }
         $observerid = $observation->getObserverId($value);
         $observername = $observer->getObserverProperty($observerid, 'firstname') . " " . $observer->getObserverProperty($observerid, 'name');
         $authorDom = $itemDom->appendChild($dom->createElement('dc:creator'));
         $authorDom->appendChild($dom->createCDATASection($observername));
         $guidDom = $itemDom->appendChild($dom->createElement('guid'));
         $guidDom->appendChild($dom->createTextNode("comet" . $value));
         $attr = $dom->createAttribute("isPermaLink");
         $guidDom->appendChild($attr);
         $attrText = $dom->createTextNode("false");
         $attr->appendChild($attrText);
         $pubDateDom = $itemDom->appendChild($dom->createElement('pubDate'));
         date_default_timezone_set('UTC');
         $date = sscanf($observation->getLocalDate($value), "%4d%2d%2d");
         $time = $observation->getLocalTime($value);
         $hour = (int) ($time / 100);
         $minute = $time - $hour * 100;
         $pubDateDom->appendChild($dom->createTextNode(date("r", mktime($hour, $minute, 0, $date[1], $date[2], $date[0]))));
     }
     // generate xml
     $dom->formatOutput = true;
     // set the formatOutput attribute of
     // domDocument to true
     // save XML as string or file
     $test1 = $dom->saveXML();
     // put string in test1
     print $test1;
 }
$inIndex = true;
require_once "../lib/setup/databaseInfo.php";
require_once "../lib/database.php";
require_once "../lib/locations.php";
date_default_timezone_set('UTC');
$objDatabase = new Database();
$objLocation = new Locations();
print "Database update will correct all the bad locations.<br />\n";
$locationsToCheck = $objDatabase->selectRecordsetArray("SELECT id FROM locations where checked=\"1\"", 'id');
print sizeof($locationsToCheck);
print "<br />";
if (sizeof($locationsToCheck) > 0) {
    foreach ($locationsToCheck as $location) {
        print $location['id'] . "<br />";
        // We adapt the timezone, elevation and country
        $latitude = $objLocation->getLocationPropertyFromId($location['id'], "latitude");
        $longitude = $objLocation->getLocationPropertyFromId($location['id'], "longitude");
        $url = "https://maps.googleapis.com/maps/api/timezone/json?location=" . $latitude . "," . $longitude . "&timestamp=0";
        $json = file_get_contents($url);
        $obj = json_decode($json);
        if ($obj->status == "OK") {
            $objLocation->setLocationProperty($location['id'], "timezone", $obj->timeZoneId);
            // Get the elevation
            $url = "https://maps.googleapis.com/maps/api/elevation/json?locations=" . $latitude . "," . $longitude;
            $json = file_get_contents($url);
            $obj = json_decode($json);
            if ($obj->status == "OK") {
                $results = $obj->results[0];
                $objLocation->setLocationProperty($location['id'], "elevation", (int) $results->elevation);
                // Get the country
                $url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" . $latitude . "," . $longitude . "&language=en&key=AIzaSyDGQJvhs1ItqmrFfYPRrh3vNpBzNbWntis";