Location: PHPKode > scripts > CrimeMap > crimemap/activity.php
<?php
/*
 *   Activity.php
 *  
 *   Class encapulating criminal activity and geocoding of locations. 
 *
 *
 *   LICENSE:
 *
 *   Copyright 2005 Matt Kubilus
 *
 *   This file is part of crimemap.
 *
 *   Crimemap is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   Crimemap is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with Crimemap; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */  



@include 'xml-rpc.php';

class activity
{
	var $db = null;
	
	function activity($db)
	{
		$this->db = $db;
	}

	
	function &geocode($address)
	{
		$XMLresult = XMLRPC_request('rpc.geocoder.us', '/service/xmlrpc/RPC2',  
			'geocode', array(XMLRPC_prepare($address)));

	   	$level2 = $XMLresult[1][0];

  		foreach ($level2 as $key => $value) 
		{
			if($key == 'lat')
				$latitude = $value;
			if($key == 'long')
				$longitude = $value;
		}

		return array($latitude, $longitude);
	}

	function addActivity($address, $datetime, $typeid, $userid, $description)
	{
		$result = $this->geocode($address);

		$latitude = $result[0];
		$longitude = $result[1];
			
		$query = "INSERT INTO crimemap_activity VALUES ('', '$address', '$datetime', $typeid, '$userid', $latitude, $longitude, '$description')";
		$this->db->execute($query);

	}

	function showAllActivity()
	{

		$this->db->execute("SELECT address, activityType, datetime, 
				CAST( description AS CHAR( 256 ) ) AS 	description
				FROM crimemap_activity
				INNER JOIN crimemap_activityTypes ON crimemap_activity.activityTypeID = crimemap_activityTypes.activityTypeID
				ORDER BY datetime DESC");
		$result = $this->db->getResults();
		$num = $this->db->getNumRows();

		echo "<p style='text-align:right';><b><center>Most Recent Activity</center></b><br><br>";

		$i=0;
		while ($i < $num) 
		{
			$address=mysql_result($result,$i,"address");
			$datetime=mysql_result($result,$i,"datetime");
			$type=mysql_result($result,$i,"activityType");
			$description=mysql_result($result,$i,"description");
	

			echo "<p><b><br> $address <br></b> $datetime <br> $type <br> $description</p>";

			$i++;
		}

		echo "</p>";
	}	
	function showActivityDetail($activityID)
	{

	}

}


?>
Return current item: CrimeMap