All pastes #267990 Raw Edit

Mine

public php v1 · immutable
·published 2006-12-05 07:07 UTC
rendered paste body
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>	<title>ZAAP</title>	<script src="js/prototype.js" type="text/javascript"></script>	<script src="js/scriptaculous.js" type="text/javascript"></script>	<script src="js/unittest.js" type="text/javascript"></script>	<script src="js/tooltip-v0.1.js" type="text/javascript"></script>	<script language="JavaScript">		// check all checkboxes		function checkAll(field) {			for (i = 0; i < field.length; i++) {				field[i].checked = true;			}		}				// uncheck all checkboxes		function uncheckAll(field) {			for (i = 0; i < field.length; i++) {				field[i].checked = false;			}		}	</script>	<link rel="stylesheet" href="style.css" type="text/css" media="screen" />		<?php	session_start();	require "charts.php";	require "functions.php"; // addline(), deletecookie()	require "dbinfo.php";	$defaultcolors = array("",		"5c90b4","ffaa60","6bb06b","d56366","ab8cc7","d5b36a","9ad56a","94d5c3","c78cc6","94c3d5",		"5c90b4","ffaa60","6bb06b","d56366","ab8cc7","d5b36a","9ad56a","94d5c3","c78cc6","94c3d5",		"5c90b4","ffaa60","6bb06b","d56366","ab8cc7","d5b36a","9ad56a","94d5c3","c78cc6","94c3d5");		//////////////////////////////////////////////////// MUST DO FIRST: LINES AND PAGE OPTIONS	// debug options	//if (isset($_GET['debug']) && $_GET['debug'] == "on") {		ini_set('display_errors', 1);		ini_set('error_reporting', 2048);	//}		// if there are no lines, make a line to start fresh	if (!isset($_SESSION['lines'])) {		addline(1,"Line 1",$defaultcolors[1]);		header("Location: ".$_SERVER['REQUEST_URI']);		exit();	}	// check for graphnav	if (isset($_GET['graphnav'])) {		$_SESSION['graphnav'] = $_GET['graphnav'];	} elseif (!isset($_SESSION['graphnav'])) {		$_SESSION['graphnav'] = "1year";	}		// check for showline and showsection	if (isset($_GET['line'])) {		$_SESSION['showline'] = $_GET['line'];		if (isset($_GET['section'])) {			$_SESSION['showsection'] = $_GET['section'];		} elseif (isset($_SESSION['showsection'])) {			unset($_SESSION['showsection']);		}	} elseif (!isset($_SESSION['showline'])) {		$_SESSION['showline'] = $_SESSION['lines'][0]['id'];	}		// should we show or hide details sections by default	if (isset($_GET['collapse'])) {		$_SESSION['collapse'] = $_GET['collapse'];	} elseif (!isset($_SESSION['collapse'])) {		$_SESSION['collapse'] = 1; // default collapse sections	}		// figure out times of displaying	require "timecalc.php";		// hits/uniques/bandwidth	if (isset($_POST['measure'])) {		$_SESSION['measure'] = $_POST['view'];	} elseif (!isset($_SESSION['measure'])) {		$_SESSION['measure'] = "hits"; // default measure is hits	}		//////////////////////////////////////////////////// LINES		// adding a line	if (isset($_POST['addline'])) {		$id = $_POST['id'];		$label = $_POST['label'];		$color = $_POST['color'];		addline($id,$label,$color);		header("Location: /?line=$id");		exit();	}		// deleting a line	if (isset($_GET['deleteline'])) {		$id = $_GET['deleteline'];		deleteline($id);		header("Location: /");		exit();	}		// clear lines button	if (isset($_GET['clear'])) {		if ($_GET['clear'] == "lines") {			foreach($_SESSION['lines'] as $line) {				deleteline($line['id']);			}		}		addline(1,"Line 1",$defaultcolors[1]);		header("Location: /");		exit();	}		// updating which lines are visible	if (isset($_POST['visibilities'])) {		// make all lines invisible		foreach($_SESSION['lines'] as $line) {			$id = $line['id'];			$_SESSION['lines'][$id]['visible'] = 0;		}		// remake cookies		foreach ($_POST as $postkey => $postvalue) {			$e = explode("|", $postkey);			if ($e[0] == "line") {				$id = $exploded[1];				$_SESSION['lines'][$id]['visible'] = 1;			}		}		header("Location: /");		exit();	}		//////////////////////////////////////////////////// DETAIL FILTERING		// filtering results for a specific line	if (isset($_POST['filterdetails'])) {		$lineid = $_POST['line'];		$sectionid = $_POST['section'];		if ($_POST['action'] == "Update Line") {			// set new filtering options			foreach ($_POST as $postkey => $postvalue) {				$e = explode("|", $postkey);				if ($e[0] == "checkbox") {					$checkboxid = $e[1];					$checked = 0; // unchecked until proven guilty					foreach ($_POST as $postkey2 => $postvalue2) {						$e2 = explode("|", $postkey2);						if (($e2[0] == "filter") && ($e2[1] == $checkboxid)) {							$checked = 1;						}					}					$_SESSION['filters'][$lineid][$sectionid][$checkboxid]['checked'] = $checked;				}			}		}		header("Location: /?line=$lineid&section=$sectionid");		exit();	}		//////////////////////////////////////////////////// GET STUFF FROM DATABASE INTO ARRAYS	// some variables for this section	$tablewidth_detailbar = 785;	$tablewidth_details = 600;	$tablewidth_details_withtext = 830;	$detailbarmax = 20; // max number of pieces in detailbar	$querylimit = 20; // limit of results coming from details queries		// populate data arrays for each section	$sectionnames = array("Browser","Result","Entry Page","Referrer","Page","Platform");	$sectionids = array("browser","result","entrypage","referrer","page","platform");	$queries = array(		"SELECT BrowserString as name, Count(*) as value FROM Traffic ",		"SELECT Result as name, Count(*) as value FROM Traffic ",		"SELECT Path as name, Count(*) as value FROM Traffic ", // entrypage		"SELECT Referrer as name, Count(*) as value FROM Traffic ",		"SELECT Path as name, Count(*) as value FROM Traffic ",		"SELECT Platform as name, Count(*) as value FROM Traffic "		);	$queries2 = array(		" GROUP BY BrowserString ORDER BY value DESC ",		" GROUP BY Result ORDER BY value DESC ",		" GROUP BY Path ORDER BY value DESC ", // entrypage		" GROUP BY Referrer ORDER BY value DESC ",		" GROUP BY Path ORDER BY value DESC ",		" GROUP BY Platform ORDER BY value DESC "		);		// get data into arrays for each item of each line	foreach($_SESSION['lines'] as $line) {		$lineid = $line['id'];				// get data for each section		$queryid = 0;		foreach ($sectionids as $sectionid) {			$query = $queries[$queryid];			$query2 = $queries2[$queryid]."LIMIT ".$querylimit;			$querymiddle = ""; // WHERE and AND section						// apply filtering			if (isset($_SESSION['filters'][$lineid])) {				foreach ($_SESSION['filters'][$lineid] as $filtersectionid => $filtersectionid_array) {					if ($filtersectionid != $sectionid) {						foreach ($filtersectionid_array as $filteritem) {							$filteritemid = $filteritem['id'];							$filteritemname = $filteritem['name'];							$filteritemvalue = $filteritem['value'];							// get db column name for this item							if ($filtersectionid == "browser") {								$column = "BrowserString";							} elseif ($filtersectionid == "result") {								$column = "Result";							} elseif ($filtersectionid == "entrypage") {								$column = "Path";							} elseif ($filtersectionid == "referrer") {								$column = "Referrer";							} elseif ($filtersectionid == "page") {								$column = "Path";							} elseif ($filtersectionid == "platform") {								$column = "Platform";							}							// where or and depending							if ($strlen($querymiddle) == 0) {								$querymiddle .= "WHERE";							} else {								$querymiddle .= "AND";							}							$querymiddle .= " ($column != '".mysql_escape_string($filteritemname)."') ";						}					}				}			}			$query = $query . $querymiddle . $query2;			//echo "<br><br>".$query."<br><br>";						$result = $db->query($query);			if (DB::isError($result)){				$_SESSION['lines'][$lineid]['filters'][$sectionid]['results'] = null; // set this section as null if there are no items in it			} else {				// clear results				unset($_SESSION['lines'][$lineid]['filters'][$sectionid]['results']);				// refill results				$x = 0;				while ($row = $result->fetchRow()) {					$filteritemname = $row['name'];					$filteritemid = $x;					$filteritemvalue = $row['value'];					$_SESSION['lines'][$lineid]['filters'][$sectionid]['results'][$x]['name'] = $name;					$_SESSION['lines'][$lineid]['filters'][$sectionid]['results'][$x]['value'] = $value;					$_SESSION['lines'][$lineid]['filters'][$sectionid]['results'][$x]['id'] = $x;					$_SESSION['lines'][$lineid]['filters'][$sectionid]['results'][$x]['checked'] = 1;					$x++;				}			}			$queryid++;		}				// process all the data and calculations for displaying		foreach ($sectionids as $sectionid) {			// calculate all this stuff only if there are even results			if ($_SESSION['lines'][$lineid]['filters'][$sectionid]['results'] != null) {				$_SESSION['lines'][$lineid]['filters'][$sectionid]['detailsratio'] = $tablewidth_details / $_SESSION['lines'][$lineid]['filters'][$sectionid]['results'][0]['value'];				// calculate percents for bars				$_SESSION['lines'][$lineid]['filters'][$sectionid]['total'] = 0;				$_SESSION['lines'][$lineid]['filters'][$sectionid]['total_detailbar'] = 0;				$x = 0;				foreach ($_SESSION['lines'][$lineid]['filters'][$sectionid]['results'] as $result) {					$value = $result['value'];					$_SESSION['lines'][$lineid]['filters'][$sectionid]['total'] += $value;					$x++;					if ($x < $detailbarmax) {						$_SESSION['lines'][$lineid]['filters'][$sectionid]['total_detailbar'] += $value;					} else {						break;					}				}				// get percents and pixel widths				$total = $_SESSION['lines'][$lineid]['filters'][$sectionid]['total'];				$total_detailbar = $_SESSION['lines'][$lineid]['filters'][$sectionid]['total_detailbar'];				$detailsratio = $_SESSION['lines'][$lineid]['filters'][$sectionid]['detailsratio'];				$x = 0;				foreach ($_SESSION['lines'][$lineid]['filters'][$sectionid]['results'] as $result) {					// get some variables					$value = $result['value'];					// now the calculations					$percent = $value / $total;					$_SESSION['lines'][$lineid]['filters'][$sectionid]['results'][$x]['percent'] = $percent;					$percent_detailbar = $value / $total_detailbar;					$_SESSION['lines'][$lineid]['filters'][$sectionid]['results'][$x]['percent_detailbar'] = $percent_detailbar;					$width_detailbar = $percent_detailbar * $tablewidth_detailbar;					$_SESSION['lines'][$lineid]['filters'][$sectionid]['results'][$x]['width_detailbar'] = $width_detailbar;					$width_details = $value * $detailsratio;					$_SESSION['lines'][$lineid]['filters'][$sectionid]['results'][$x]['width_details'] = $width_details;					$x++;				}			}		}	}			?></head><body><div id="wrap"><div id="header">	<h1><a href="index.php">ZAAP</a></h1></div><div id="main">	<!-- first level -->	<div id="measure">		<p>			<form enctype="multipart/form-data" method="post" action="/">			<h2>Measure:</h2> <input type="hidden" name="measure" value="1" />			<select name="view">				<?php				$measurenames = array("Hits","Uniques","Bandwidth");				$measureids = array("hits","uniques","bandwidth");							$x = 0;				foreach ($measurenames as $measurename) {					echo "<option label=\"$measurename\" value=\"$measureids[$x]\" ";					if ($measure == $measureids[$x]) {						echo "SELECTED";					}					echo ">$measurename</option>";					$x++;				}				?>			</select>			<input type="submit" name="action" value="Show"/>			</form>		</p>	</div>	<div id="graph">		<div id="graphnav">			<ul id="navlist">				<?php				$graphnavtabs = array("custom","1day","1week","1month","6months","1year");				$graphnavtabsnames = array("Custom","1 Day","1 Week","1 Month","6 Months","1 Year");								$x = 0;				foreach ($graphnavtabs as $tab) {					echo "<li><a href=\"/?graphnav=$tab\"";					if($graphnav == $tab) { 						echo "class=\"current\"";					}					echo ">$graphnavtabsnames[$x]</a></li>";					$x++;				}				?>			</ul>		</div>		<div id="graphgraph">			<?php echo InsertChart( "charts.swf", "charts_library", "graph.php?graphnav=$graphnav&endtime=$endtime&measure=$measure", 770, 400, "ffffff", true ); ?>		</div>		<div id="graphtimeframe">			<p class="left">				< 12/2/05			</p>			<p class="right">				11/30/06 >			</p>		</div>	</div>	<div id="linelist">		<form enctype="multipart/form-data" method="post" action="/">		<input type="hidden" name="visibilities" value="1" />		<div id="visiblelines">			<h3>Visible Lines</h3>			<div class="pad">				<?php				foreach ($_SESSION['lines'] as $line) {					$color = $line['color'];					$label = $line['label'];					$id = $line['id'];					$visible = $line['visible'];					echo "<input type=\"checkbox\" name=\"line|$id\" ";					if ($visible == "1") {						echo "CHECKED";					}					echo " background=#$color /><span style=\"color:#$color;\">$label</span><br/>";				}							?>			</div>		</div>		<div id="updatevisibility">			<p><input type="submit" name="action" value="Update Visibilities"/></p>		</div>		</form>		<div id="addaline">			<h3>Add a Line</h3>			<div class="pad">				<?php				$counter = $_SESSION['counter'];				?>				<table cellpadding="0" cellspacing="0" border="0">				<form enctype="multipart/form-data" method="post" action="/">				<input type="hidden" name="addline" value="1" />				<input type="hidden" name="id" value="<?php echo $counter; ?>" />				<tr>					<td style="padding-right: 5px;">Label:</td>					<td><input type="text" name="label" size="12" value="Line <?php echo $counter; ?>" /></td>				</tr>				<tr>					<td style="padding-right: 5px;">Color:</td>					<td><input type="text" name="color" size="12" value="<?php echo $defaultcolors[$counter]; ?>" /></td>				</tr>				<tr>					<td></td>					<td style="padding-top: 2px;"><input type="submit" name="action" value="Add Line" /></td>				</tr>				</form>				</table>			</div>		</div>	</div>	<!-- second level -->	<div id="linetabs">		<ul id="navlist">			<?php			// list the lines as tabs, selected one highlighted			$x = 0;			foreach ($_SESSION['lines'] as $line) {				$color = $line['color'];				$id = $line['id'];				$label = $line['label'];				echo "<li>";				echo "<a href=\"/?line=$id\" style=\"background-color:#$color;\" ";				if ($_SESSION['showline'] == $id) { 					echo "class=\"current\"";				}				echo ">".$label."</a>";				echo "<a href=\"/?deleteline=$id\" style=\"background-color:#$color;padding-bottom: 3px; margin-bottom: 0;\" class=\"";				if ($_SESSION['showline'] == $id) { 					echo "current ";				}				echo "deleteline\"><span>x</span></a>";				echo "</li>";				$x++;			}			?>		</ul>	</div>	<div id="linedetails" style="background-color: #<?php echo $_SESSION['lines'][$_SESSION['showline']]['color']; ?>;">		<ul>			<?php			$lineid = $_SESSION['showline'];			$section_x = 0;			foreach ($sectionnames as $sectionname) {				// section specific details				$sectionid = $sectionids[$section_x];				// check if this section should not be hidden				if((isset($_SESSION['showsection']) && ($_SESSION['showsection'] == $sectionid)) || ($_SESSION['collapse'] == 0))) {					$display = "normal";				} else {					$display = "none";				}			?>			<li>				<div class="plusminus">					<a href="#" onClick="new Effect.SlideDown('<?php echo $sectionid; ?>'); return false;">+</a> <a href="#" onClick="new Effect.SlideUp('<?php echo $sectionid; ?>'); return false;">-</a>				</div>				<h3><?php echo $sectionname; ?></h3> 				<div class="detailbar">					<table width="<?php echo $tablewidth_detailbar; ?>" cellpadding="0" cellspacing="0" border="0">					<tr>					<?php					$x = 0;					foreach ($_SESSION['lines'][$lineid]['filters'][$sectionid]['results'] as $result) {						$width = $result['width_details'];						if ($width < 1) {							$width = 1;						}						$value = $result['value'];						$id = $result['id'];						$percent = round($result['percent']*100,2);						$checked = $result['checked'];						echo "<td width=\"".$width."\">";						// tooltip						echo "<div id=\"tooltip-".$id."-".$x."\" style=\"display:none; margin: 5px; background-color: #f0f0f0; padding: 2px; border: 1px solid #777;\">";						echo "$name<br/>";						echo "<b>Value:</b> $value<br/>";						echo "<b>Percent:</b> $percent%<br/>";						echo "<b>Included in Line:</b> ";						if ($checked == 1) {							echo "Yes";						} else {							echo "No";						}						echo "<br/>";						echo "</div>";						// the bar (that activates the tooltip)						echo "<div id=\"bar-".$id."-".$x."\" class=\"bar";						if ($checked == 1) {							echo " checked";						}						echo "\">&nbsp;</a>";						// and now the javascript of the tooltip						echo "<script type=\"text/javascript\">";						echo "var my_tooltip = new Tooltip('bar-".$id."-".$x."','tooltip-".$id."-".$x."')";						echo "</script>";												echo "</td>";						$x++;						if ($x > $detailbarmax) {							break;						}					}					?>					</tr>					</table>				</div>				<?php				$formname = "form_".$lineid."_".$sectionid;				?>				<div id="<?php echo $sectionid; ?>" class="details" style="display: <?php echo $display; ?>;">					<form enctype="multipart/form-data" method="post" name="<?php echo $formname; ?>" action="<?php echo $url_full; ?>">					<input type="hidden" name="filterdetails" value="1" />					<input type="hidden" name="line" value="<?php echo $lineid; ?>" />					<input type="hidden" name="section" value="<?php echo $sectionid; ?>" />					<div class="table">						<table width="<?php echo $tablewidth_details_withtext; ?>" cellpadding="0" cellspacing="0" border="0">							<?php							$x = 0;							foreach ($_SESSION['lines'][$lineid]['filters'][$sectionid]['results'] as $name) {								$value = $result['value'];								$id = $result['id'];								$percent = round($result['percent']*100,2);								$width = $results['width_details'];								$width_negative = $tablewidth_details - $width;								$checked = $result['checked'];								echo "<tr>";								echo "<td width=\"170\">";								echo "<input type=\"hidden\" name=\"checkbox|$id\" value=\"$id\" />"; // BECAUSE FORMS DONT POST UNCHECKED BOXES! GAH!								echo "<input type=\"checkbox\" name=\"filter|$id\" ";								if ($checked == 1) {									echo "CHECKED";								}								echo "/> ".$name."</td>";								echo "<td width=\"45\">".$value."</td>";								echo "<td><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"$tablewidth_details\"><tr><td width=\"$width\"><div class=\"bar\">&nbsp;</div></td><td width=\"$width_negative\" style=\"text-align:left;padding-left:5px;\">$percent%</td></tr></table></td>";								echo "</tr>";								$x++;							}										?>						</table>					</div>					<div class="panel">						<p class="left">							<input type="submit" name="action" value="Update Line" />						</p>						<p class="right">							<input type="button" name="CheckAll" value="Check All"							onClick="checkAll(document.<?php echo $formname; ?>)">							<input type="button" name="UnCheckAll" value="Uncheck All"							onClick="uncheckAll(document.<?php echo $formname; ?>)">						</p>					</div>					</form>				</div>			</li>			<?php 				$section_x++;			} 			?>		</ul>	</div></div><div id="footer">	<p class="left">Info 424 Autumn 2006 - Zach, Adam, Anh</p>	<p class="right">		<?php if ($_SESSION['collapse'] == 1) { ?>			<a href="index.php?collapse=0">Uncollapse Details by Default</a>		<?php } else { ?>			<a href="index.php?collapse=1">Collapse Details by Default</a>		<?php } ?>				 - <a href="index.php?clear=lines">Clear All Lines</a>	</p></div>	</div></body></html>