Location: PHPKode > projects > TraffStats > TraffStats-0.11.3/includes/statsgraphform.inc.php
<?php
/*
 * generate statsgraph-form
 * $Id: statsgraphform.inc.php,v 1.10 2008-03-17 18:21:48 zerwes Exp $
 * package: traffstats
 * (c) Klaus Zerwes zero-sys.net
 */


$debug->filestart(__FILE__);


if(!isset($traffstats) || !is_a($traffstats, "traffstats")){
	die (__FILE__." requires object traffstats");
}
if(!isset($displaytable)){
	die(__FILE__." requires displaytable");
}


//$debug->debugarray($_SESSION, "SESSION_AT_STARTOF_".__FILE__);




$grapselecttable = new table();
$grapselecttable->setstyle_table(array(
	"style"=>"padding:5px; margin-top:10px;"
));

$grapselecttableheader = array();
$tr = $grapselecttable->newtr();
for($i=1; $i<=3; $i++){
	$grapselecttableheader[] = $language->translate("statsgrapselect_".$i);
	$selarr = array();
    foreach ($_SESSION["statsgraph"]["s_".$i] as $ifacekey) {
    	if(!array_key_exists($ifacekey, $traffstats->_ifacestring)){
    		/*echo "<pre>";
    		echo "SESSION[statsgraph]:\n";
			var_dump($_SESSION["statsgraph"]);
			echo "traffstats->_ifacestring\n";
			var_dump($traffstats->_ifacestring);
    		echo "</pre>";*/
    		die("missing iface '$ifacekey' in traffstats->_ifacestring!");
    	}
    	$selarr[$ifacekey] = $traffstats->_ifacestring[$ifacekey];
    }
    $ep = htmlhelper::array2select("s_".$i."[]", $selarr, array(), false, false, false);
	$html->element("multiple", "multiple", $ep);
	$html->element("size", "6", $ep);
	$html->element("class", "statsforminputelement", $ep);
	$html->element("style", "width: 350px;", $ep);
	$grapselecttable->settd($html->get_element($ep), $tr);
}
$grapselecttable->setstyle_td(array("style"=>"text-align: center;padding:2px;"), $tr);

$grapselecttable->sethead($grapselecttableheader);
unset($grapselecttableheader);



// move buttons
$butarr = array();
$but = $html->new_form_element("button", "move12", $language->translate("move12"));
$html->element("onclick","movegraphiface(1,2)",$but);
$html->form_element("class", "statspagesubmitbut", $but);
$butarr[] = $html->get_element($but);

$but = $html->new_form_element("button", "move23", $language->translate("move23"));
$html->element("onclick","movegraphiface(2,3)",$but);
$html->form_element("class", "statspagesubmitbut", $but);
$butarr[] = $html->get_element($but);

$but = $html->new_form_element("button", "move31", $language->translate("move31"));
$html->element("onclick","movegraphiface(3,1)",$but);
$html->form_element("class", "statspagesubmitbut", $but);
$butarr[] = $html->get_element($but);

$tr = $grapselecttable->settr($butarr);
$grapselecttable->setstyle_td(array("style"=>"text-align: center;"), $tr);

$butarr = array();
$but = $html->new_form_element("button", "move13", $language->translate("move13"));
$html->element("onclick","movegraphiface(1,3)",$but);
$html->form_element("class", "statspagesubmitbut", $but);
$butarr[] = $html->get_element($but);

$but = $html->new_form_element("button", "move21", $language->translate("move21"));
$html->element("onclick","movegraphiface(2,1)",$but);
$html->form_element("class", "statspagesubmitbut", $but);
$butarr[] = $html->get_element($but);

$but = $html->new_form_element("button", "move32", $language->translate("move32"));
$html->element("onclick","movegraphiface(3,2)",$but);
$html->form_element("class", "statspagesubmitbut", $but);
$butarr[] = $html->get_element($but);

$tr = $grapselecttable->settr($butarr);
$grapselecttable->setstyle_td(array("style"=>"text-align: center;"), $tr);



$tr = $grapselecttable->newtr();
for($i=1; $i<=3; $i++){
	$ep = htmlhelper::array2select("h_".$i, $handlearr, $_SESSION["statsgraph"]["h_".$i], false, false, false);
	$html->element("class", "statsforminputelement", $ep);
	$td = $grapselecttable->settd(
		$language->translate("howtohandleselect")
		." ".$language->translate("statsgrapselect_".$i)
		."<br />".$html->get_element($ep), $tr);
		$grapselecttable->setstyle_td(array("style"=>"text-align: center; padding-top: 5px;"), $tr, $td);
}

// button for viewgraph
$but = $html->new_form_element("button", "viewgraph", $language->translate("viewgraph"));
$html->element("onclick","openGraphWindow()",$but);
$html->form_element("class", "statspagesubmitbut", $but);
$tr = $grapselecttable->newtr();
$td = $grapselecttable->settd($html->get_element($but), $tr);
$grapselecttable->setstyle_td(
	array(
		"colspan"=>3, 
		"style"=>"padding-top:10px; text-align: center;"
	), $tr, $td);


// js stuff
$html->js->jsadd(core::php_array_2_js($traffstats->_ifacestring, "ifacestring"));
$html->js->jsadd(core::php_array_2_js(array(1=>array(),2=>array(),3=>array()), "graphhost"));
$html->js->jsadd("
	function sendform() {
		for(var f=1; f<=3; f++){
			var theSel = 's_'+f+'[]';
			for ( var i=0; i<document.forms[the_form_name].elements[theSel].length; i++ ) {
				document.forms[the_form_name].elements[theSel].options[i].selected = true;
			}
		}
	}
	function movegraphiface(selFrom, moveTo){
		var theTargetSel = 's_'+moveTo+'[]';
		graphhost[moveTo] = new Array();
		for ( var j=0; j<document.forms[the_form_name].elements[theTargetSel].length; j++ ) {
			graphhost[moveTo].push(document.forms[the_form_name].elements[theTargetSel].options[j].value);
		}
		var theSel = 's_'+selFrom+'[]';
		graphhost[selFrom] = new Array();
		for ( var i=0; i<document.forms[the_form_name].elements[theSel].length; i++ ) {
			if ( document.forms[the_form_name].elements[theSel].options[i].selected == true ) {
				graphhost[moveTo].push(document.forms[the_form_name].elements[theSel].options[i].value);
			}else{
				graphhost[selFrom].push(document.forms[the_form_name].elements[theSel].options[i].value);
			}
		}
		rebuildFromArr(selFrom);
		resortArr(moveTo);
		rebuildFromArr(moveTo);
	}
	function rebuildFromArr(arrIndex){
		var theSel = 's_'+arrIndex+'[]';
		document.forms[the_form_name].elements[theSel].length = null;
		for (var i=0;i<graphhost[arrIndex].length;i++){
			var newOpt = new Option (ifacestring[graphhost[arrIndex][i]], graphhost[arrIndex][i], false, false);
			document.forms[the_form_name].elements[theSel].options[document.forms[the_form_name].elements[theSel].length] = newOpt;
		}
	}
	function resortArr(arrIndex){
		var resortedArr = new Array();
		for(var i in ifacestring ){
			for(var j=0;j<graphhost[arrIndex].length;j++){
				if(i==graphhost[arrIndex][j]){
					resortedArr.push(i);
				}
			}
		}
		graphhost[arrIndex] = new Array();
		graphhost[arrIndex] = resortedArr;
	}
	function openGraphWindow(){
		var getParamIfacesString = '';
		for(var f=1; f<=3; f++){
			var theSel = 's_'+f+'[]';
			var theHandle = 'h_'+f;
			if (document.forms[the_form_name].elements[theHandle].options[".(count($handlearr)-1)."].selected == true){
				continue;
			}
			if(document.forms[the_form_name].elements[theSel].length == 0){
				continue;
			}
			if(getParamIfacesString.length > 0){
				getParamIfacesString += '&';
			}
			getParamIfacesString += theHandle+'='+document.forms[the_form_name].elements[theHandle].selectedIndex;
			for ( var i=0; i<document.forms[the_form_name].elements[theSel].length; i++ ) {
				getParamIfacesString += '&';
				getParamIfacesString += theSel+'='+document.forms[the_form_name].elements[theSel].options[i].value;
			}
		}
		if(getParamIfacesString.length > 0){
			var URIParams = '".TRAFFSTATS__GRAPHGENERATE."?' + getParamIfacesString;
			pwin = window.open(URIParams,'".ZEROSYS__PROJECTNAME."','width=1030,height=700,left=0,top=0,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no');
			pwin.focus();
		} else {
			alert('".$language->translate("nothingtodisplayingraph")."');
		}
	}
	");




// add grapselecttable to displaytable
$displaytable->settr(array($html->hr(null, true)));
$tr = $displaytable->settr(array($language->translate("graphtable")));
$displaytable->setstyle_td(array("style"=>"font-size: 11pt; font-weight:bold; padding-top:5px; padding-bottom:5px;"), $tr);
$displaytable->settr(array($grapselecttable->gethtml(false)));

//$debug->debugarray($_SESSION, "SESSION_AT_ENDOF_".__FILE__);

$debug->fileend(__FILE__);

?>
Return current item: TraffStats