function GetIncidentsByDay($date, $agencyShortName) { dprint("GetIncidentsByDay() Start."); try { $db = new DatabaseTool(); if ($date == "") { $date = date("Y-m-d"); } if ($agencyShortName == "") { // create the query $query = 'SELECT itemid,event,address,pubdate,pubtime,status,itemid,scrapedatetime,agencyid,fulladdress,lat,lng,zipcode FROM incidents WHERE pubdate = ? ORDER BY pubtime DESC'; $mysqli = $db->Connect(); $stmt = $mysqli->prepare($query); $stmt->bind_param("s", $date); // bind the varibale } else { $agencyManager = new AgencyManager(); $agency = $agencyManager->GetAgencyFromShortName($agencyShortName); // create the query $query = 'SELECT itemid,event,address,pubdate,pubtime,status,itemid,scrapedatetime,agencyid,fulladdress,lat,lng,zipcode FROM incidents WHERE agencyid = ? AND pubdate = ? ORDER BY pubtime DESC'; $mysqli = $db->Connect(); $stmt = $mysqli->prepare($query); $stmt->bind_param("is", $agency->agencyid, $date); // bind the varibale } $results = $db->Execute($stmt); // create an array to put our results into $incidents = array(); $ids = array(); foreach ($results as $result) { if (!in_array($result['itemid'], $ids)) { $incident = new Incident(); // pull the information from the row $incident->event = $result['event']; $incident->address = $result['address']; $incident->pubdate = $result['pubdate']; $incident->pubtime = $result['pubtime']; $incident->status = $result['status']; $incident->itemid = $result['itemid']; $incident->scrapedatetime = $result['scrapedatetime']; $incident->agencyid = $result['agencyid']; $incident->fulladdress = $result['fulladdress']; $incident->lat = $result['lat']; $incident->lng = $result['lng']; $incident->zipcode = $result['zipcode']; $incidents[] = $incident; $ids[] = $result['itemid']; } } // close our DB connection $db->Close($mysqli, $stmt); } catch (Exception $e) { dprint("Caught exception: " . $e->getMessage()); } dprint("GetIncidentsByDay() Done."); return $incidents; }
function GetLocationsByDay($date, $agencyShortName) { dprint("GetLocationsByDay() Start."); try { $db = new DatabaseTool(); if ($date == "") { $date = date("Y-m-d"); } if ($agencyShortName == "") { // create the query $query = 'SELECT DISTINCT itemid,event,fulladdress,lat,lng,pubdate,pubtime,agencies.longname AS agencyname FROM incidents JOIN agencies ON incidents.agencyid = agencies.agencyid WHERE pubdate = ? AND lat <> "" AND lng <> "" GROUP BY itemid ORDER BY pubtime DESC'; $mysqli = $db->Connect(); $stmt = $mysqli->prepare($query); $stmt->bind_param("s", $date); // bind the varibale } else { $agencyManager = new AgencyManager(); $agency = $agencyManager->GetAgencyFromShortName($agencyShortName); // create the query $query = 'SELECT DISTINCT itemid,event,fulladdress,lat,lng,pubdate,pubtime,agencies.longname AS agencyname FROM incidents JOIN agencies ON incidents.agencyid = agencies.agencyid WHERE incidents.agencyid = ? AND pubdate = ? AND lat <> "" AND lng <> "" GROUP BY itemid ORDER BY pubtime DESC'; $mysqli = $db->Connect(); $stmt = $mysqli->prepare($query); $stmt->bind_param("is", $agency->agencyid, $date); // bind the varibale } $results = $db->Execute($stmt); // create an array to put our results into $incidents = array(); // decode the rows foreach ($results as $result) { $incident = (object) array('itemid' => $result['itemid'], 'event' => $result['event'], 'fulladdress' => $result['fulladdress'], 'lat' => $result['lat'], 'lng' => $result['lng'], 'publishdate' => $result['pubdate'], 'publishtime' => $result['pubtime'], 'agencyname' => $result['agencyname']); $incidents[] = $incident; } // close our DB connection $db->Close($mysqli, $stmt); } catch (Exception $e) { dprint("Caught exception: " . $e->getMessage()); } dprint("GetLocationsByDay() Done."); return $incidents; }
<?php require_once "./tools/AgencyManager.class.php"; require_once "./tools/Agency.class.php"; require_once "./tools/IncidentManager.class.php"; require_once "./tools/Incident.class.php"; // get the agency we are viewing $agencyshortname = $_GET['agency']; // TODO: sanity check this // create an instance of our agency manager object $agencyManager = new AgencyManager(); // create an instance of our incident manager $incidentManager = new IncidentManager(); // get agency information using the shortname passed in by the user $agency = $agencyManager->GetAgencyFromShortName($agencyshortname); // get the last 25 incidents this agency has seen $incidents = $incidentManager->GetIncidentsByAgencyID($agency->agencyid, 25); // note: 25 here is the number of incidents to return // do some decode if we haven't decoded the 4 letter code yet //if( $agency->longname == "" ) // $agency->longname = "- unknown -"; // get the current year $year = date("Y"); // get todays date for later use $todaysdate = date("Y-m-d"); // get the total number of calls for todays date $todaystotalcalls = $incidentManager->GetIncidentCountByAgencyIDAndDate($agency->agencyid, $todaysdate); // get the total number of calls for this year for this agency //$totalcalls = $agencyManager->GetTotalIncidentsByAgencyID($agency->agencyid, $year); echo '<A HREF="javascript:history.back()">< Back</a><br><br>';
$agencyManager = new AgencyManager(); // display links to go to previous day and next day echo '<div class="yesterdaylink">'; echo '<a href="incidents.php?date=' . $yesterday . '">Incidents for ' . date("l F j, Y", strtotime($yesterday)) . '</a>'; echo '</div>'; if ($date != date("Y-m-d")) { echo '<div class="tomorrowlink">'; echo '<a href="incidents.php?date=' . $tommorrow . '">Incidents for ' . date("l F j, Y", strtotime($tommorrow)) . '</a>'; echo '</div>'; } echo '<br><br>'; echo '<div>'; echo '<br>'; echo '<center><h2>Incidents for ' . date("l F j, Y", strtotime($date)) . '</h2></center>'; if ($agencyShortName != "") { $targetAgency = $agencyManager->GetAgencyFromShortName($agencyShortName); echo '<br/><center><h2>Displaying Incidents only for <i style="color: darkred;">' . $targetAgency->longname . '</i></h2></center>'; } echo '<center>'; echo '<br>'; echo '<a href="stats.php?date=' . $date . '">See Stats For ' . date("l F j, Y", strtotime($date)) . '</a>'; echo '</center>'; echo '</div>'; // // MAP // echo '</br>'; echo '<div id="mapwrapper" class="mapwrapper">'; echo '<div id="map" class="map" style="width: 500px; height: 400px;"></div>'; echo '<div id="mapsettings" class="mapsettings"></div>'; echo '<div class="clear"></div>';