Location: PHPKode > projects > SWG Resource Tracker > distro/upload/viewlocations.php
<?php

/*
 *	SWG Resource Tracker
 *	Copyright (C) 2004 Enigma
 *
 *	This program 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.
 *	
 *	This program 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 this program; if not, write to the Free Software
 *	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

$idx = new ViewLocations();

class ViewLocations
{
	var $output = "";
	function ViewLocations()
	{
		global $DB, $display, $filter, $equation;
		
		$display['title'] = "Resource Tracker - View Locations";

		//Get all the required files loaded...
		require("filter.php");
		
		
		//Some arrays to match stuff to...
		$months = array(31,28,31,30,31,30,31,31,30,31,31,31);
		$planets = array("Corellia", "Dantooine", "Dathomir", "Endor", "Lok", "Naboo", "Rori", "Talus", "Tatooine", "Yavin 4");
		
		
		//Figure out a datestamp for N days ago
		$oldstamp = mktime() - 86400 * AUTO_TRIM;
		
		//Clear all old entries in the resources table
		$query = "UPDATE `locations` SET `visible`=0 WHERE `date` <= FROM_UNIXTIME($oldstamp) + 0";
		$DB->query($query);
		
		//Get all the resources
		//$dir = array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
		$planet = (isset($_REQUEST['planet']) ? $_REQUEST['planet'] : -1);
		
		$dir = !$_REQUEST['dir'];
		
		$query = "SELECT %c%, %e%, l.*, r.*, g.`long_name`, g.`id` AS `owner`, UNIX_TIMESTAMP(l.date) AS utime, c.`cur_id` FROM `locations` AS l, `resources` as r, `current` AS c LEFT JOIN `categories` AS g ON r.`category`=g.`id` WHERE l.`resource`=r.`id` AND l.`visible`=1 AND c.`resource`=r.`id` AND l.`planet`=c.`planet`";
			
		$query .= " ORDER BY l.`planet` ASC, %s%";
		
		$query = getQuery($query);
			
		$DB->query($query);
		$results = $DB->fetchall();
		
		
		//Print the filter box
		$this->output .= "<iframe src=\"filterbox.php?act=view\" name=\"filter\" height=\"150\" width=\"100%\">Sorry, your browser does not support this feature</iframe><br /><br />";
		
		if (count($results) == 0)
		{
			$this->output .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"ltb\">
							<tr>
								<td class=\"rbb\">No resources found.</td>
							</tr>
						</table>";
		}
		else
		{
			//Add each resource
			$x = -1;
					
			$this->output .= "<p><a href=\"{$baseurl}?act=add\">Add an Entry</a></p>
			<script language=\"javascript\" type=\"text/javascript\">
				function doSort(col, dir, planet)
				{
					document.sorts.sort.value = col;
					document.sorts.dir.value = dir;
					document.sorts.planet.value = planet;
					document.sorts.submit();
				}
			</script>
			<form name=\"sorts\" action=\"{$baseurl}\" method=\"get\">";
			
			for ($i = 0; $i < count($results); $i++)
			{
				if ($x != $results[$i]['planet'])
				{
					if ($x != -1)
						$this->output .= "</table><br />\n\n";
					
					$pl = $results[$i]['planet'];
					$this->output .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"ltb\" align=\"center\" width=\"100%\">
							<tr>
								<th class=\"rbb\" colspan=\"17\"><h2>{$planets[$results[$i]['planet']]}</h2></th>
							</tr>
							<tr>
								<th class=\"rbb\"><a href=\"javascript:doSort('name', {$dir}, $pl)\">Resource</a></th>
								<th class=\"rbb\">Geographical Location</th>
								<th class=\"rbb\"><a href=\"javascript:doSort('conc', {$dir}, $pl)\">Concentration</a></th>
								<th class=\"rbb\"><a href=\"javascript:doSort('cat', {$dir}, $pl)\">Category</a></th>
								<th class=\"rbb\"><a href=\"javascript:doSort('er', {$dir}, $pl)\">ER</a></th>
								<th class=\"rbb\"><a href=\"javascript:doSort('cr', {$dir}, $pl)\">CR</a></th>
								<th class=\"rbb\"><a href=\"javascript:doSort('cd', {$dir}, $pl)\">CD</a></th>
								<th class=\"rbb\"><a href=\"javascript:doSort('dr', {$dir}, $pl)\">DR</a></th>
								<th class=\"rbb\"><a href=\"javascript:doSort('fl', {$dir}, $pl)\">FL</a></th>
								<th class=\"rbb\"><a href=\"javascript:doSort('hr', {$dir}, $pl)\">HR</a></th>
								<th class=\"rbb\"><a href=\"javascript:doSort('ma', {$dir}, $pl)\">MA</a></th>
								<th class=\"rbb\"><a href=\"javascript:doSort('pe', {$dir}, $pl)\">PE</a></th>
								<th class=\"rbb\"><a href=\"javascript:doSort('oq', {$dir}, $pl)\">OQ</a></th>
								<th class=\"rbb\"><a href=\"javascript:doSort('sr', {$dir}, $pl)\">SR</a></th>
								<th class=\"rbb\"><a href=\"javascript:doSort('ut', {$dir}, $pl)\">UT</a></th>
								<th class=\"rbb\"><a href=\"javascript:doSort('calc', {$dir}, $pl)\">Calc</a></th>
								<th class=\"rbb\"><a href=\"javascript:doSort('date', {$dir}, $pl)\">Date Added</a></th>
							</tr>";
				}
						
				$item = $results[$i];
				
				
				$cat = $item['category'];
				$category = $item['long_name'];
				
				//Parse the datestamp to display in a usable format
				$date = array();
				ereg("([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})", $item['date'], $date);
				list($null, $year, $month, $day, $hour, $min, $sec) = $date;
				
				$difference = dayDiff(time(), $item['utime']);
						
				if ($difference > 1)
				{
					$dstring = "($difference days ago)";
				}
				else if ($difference == 1)
				{
					$dstring = "(Yesterday)";
				}
				else
					$dstring = "(Today)";
				
				//Caculate the differece
				$now = time();
				$diff = $now - $results[$i]['utime'];
				
				$days = floor($diff / 86400);
				$diff -= ($days * 86400);
				
				$hours = floor($diff / 3600);
				$diff -= ($hours * 3600);
				
				$mins = floor($diff / 60);
				
				$datestring = "";
				
				if ($days > 1)
					$datestring .= "{$days} days ";
				else if ($days == 1)
					$datestring .= "{$days} day ";
				
				if ($days == 0)
				{
					if ($hours > 1)
						$datestring .= "{$hours} hours ";
					else if ($hours == 1)
						$datestring .= "{$hours} hour ";
				}
					
				if ($hours == 0 && $days == 0)
				{
					if ($mins > 1)
						$datestring .= "{$mins} minutes ";
					else if ($mins == 1)
						$datestring .= "{$mins} minute ";
					else
					{
						$datestring .= "{$diff} seconds";
					}
				}
				
				$resource = $results[$i]['name'];
				
				if (LOGGED_IN)
				{
					$addinv = "<a href=\"{$baseurl}?act=addinventory&amp;CODE=1&amp;search=" . urlencode($resource) . "\"><img src=\"add_inventory.png\" alt=\"+\" /></a> ";
					$watch = "<a href=\"{$baseurl}?act=favorites&amp;addwatched={$results[$i]['cur_id']}\"><img src=\"add_watched.png\" alt=\"w\" /></a> ";
				}
				
				//Create the row for the item
		
				$this->output .= "<tr class=\"resource\">
						<td class=\"rbb\"><div><div class=\"fl\">{$item['name']} (<a href=\"{$baseurl}?act=tree&amp;resource={$results[$i]['resource']}\">Edit</a>)</div><div class=\"fr\">{$addinv}<a href=\"{$baseurl}?act=usage&amp;c={$results[$i]['owner']}\"><img src=\"usage.png\" alt=\"u\" /></a> {$watch}<a href=\"{$baseurl}?act=current&amp;CODE=3&amp;id={$results[$i]['cur_id']}\" onclick=\"return confirm('Mark $resource unavailable?')\"><img src=\"unavailable.png\" alt=\"x\" /></a></div></div></td>
						<td class=\"rbb\"><a href=\"{$baseurl}?act=places&amp;coords={$item['location']}&amp;planet={$results[$i]['planet']}\">{$item['location']}</a></td>
						<td class=\"rbb\">{$item['concentration']}</td>
						<td class=\"rbb\"><a href=\"{$baseurl}?act=tree&amp;parent={$cat}&amp;hl={$item['resource']}\">$category</a></td>
						<td class=\"rbb\">" . colorize($item['ER'], 0, $item['eER']) . "</td>
						<td class=\"rbb\">" . colorize($item['CR'], 0, $item['eCR']) . "</td>
						<td class=\"rbb\">" . colorize($item['CD'], 0, $item['eCD']) . "</td>
						<td class=\"rbb\">" . colorize($item['DR'], 0, $item['eDR']) . "</td>
						<td class=\"rbb\">" . colorize($item['FL'], 0, $item['eFL']) . "</td>
						<td class=\"rbb\">" . colorize($item['HR'], 0, $item['eHR']) . "</td>
						<td class=\"rbb\">" . colorize($item['MA'], 0, $item['eMA']) . "</td>
						<td class=\"rbb\">" . colorize($item['PE'], 0, $item['ePE']) . "</td>
						<td class=\"rbb\">" . colorize($item['OQ'], 0, $item['eOQ']) . "</td>
						<td class=\"rbb\">" . colorize($item['SR'], 0, $item['eSR']) . "</td>
						<td class=\"rbb\">" . colorize($item['UT'], 0, $item['eUT']) . "</td>
						<td class=\"rbb\">" . colorize($item['calc'], 100) . "</td>
						<td class=\"rbb\">{$datestring}</td>
					</tr>\n";
				$x = $results[$i]['planet'];
			}
			
			$this->output .= "</table>
			<input type=\"hidden\" name=\"sort\" value=\"\" />
			<input type=\"hidden\" name=\"dir\" value=\"\" />
			<input type=\"hidden\" name=\"planet\" value=\"\" />
			<input type=\"hidden\" name=\"act\" value=\"view\" />
			</form>";
		}
		
		
		
		$display['output'] = $this->output;
	}
	
	
}
?>
Return current item: SWG Resource Tracker