Location: PHPKode > projects > IRMA - Asset Inventory and Job Tracking > irma-1.0.6/includes/pda/functions.php
<?php
/*
 *
 * $Header: /cvsroot/irma/irma/includes/pda/functions.php,v 1.3 2007/10/26 23:37:49 bbaez Exp $
 *
 */
function searchFormPDA() {
	// Print Search Form
	
	GLOBAL $cfg_install, $cfg_layout, $layout, $lang;

	$option["ID"]				= $lang["pda"][0];
	$option["username"]			= $lang["pda"][1];
	$option["manufacturer"]		= $lang["pda"][2];
	$option["model"]			= $lang["pda"][3];
	$option["part_number"]		= $lang["pda"][4];
	$option["os"]				= $lang["pda"][5]	;
	$option["osver"]			= $lang["pda"][6];
	$option["serial"]			= $lang["pda"][7];
	$option["comments"]			= $lang["pda"][8];
	$option["date_mod"]			= $lang["pda"][9];
	
	/* Search by Location
	echo "<form method=get action=\"".$cfg_install["root"]."/pda/pda-search.php\">\n";
	echo "<center><table border=0 width=90%>\n";
	echo "<tr><th colspan=2><b>".$lang["search"][5].":</b></th></tr>\n";
	echo "<tr bgcolor=".$cfg_layout["tab_bg_1"].">\n";
	echo "<td align=center>\n";
		dropdown( "dropdown_locations",  "contains");
	echo "<input type=hidden name=field value=location>&nbsp;\n";
	echo $lang["search"][6];
	echo "&nbsp;<select name=sort size=1>\n";
	reset($option);
	for ($i=0; $i < count($option); $i++) {
		list($key,$val) = each ($option);
		echo "<option value=$key>$val\n";
	}
	echo "</select>\n";
	echo "<input type=hidden name=phrasetype value=exact>\n";
	echo "</td><td width=80 align=center bgcolor=".$cfg_layout["tab_bg_2"].">\n";
	echo "<input type=submit value=\"".$lang["buttons"][1]."\">\n";
	echo "</td></tr></table></form></center>\n";
	*/
	echo "<form method=get action=\"".$cfg_install["root"]."/pda/pda-search.php\">\n";
	echo "<center><table border=0 width=90%>\n";
	echo "<tr><th colspan=2><b>".$lang["search"][0].":</b></th></tr>\n";
	echo "<tr bgcolor=".$cfg_layout["tab_bg_1"].">\n";
	echo "<td align=center>\n";
	echo "<select name=\"field\" size=1>\n";
	reset($option);
	for ($i=0; $i < count($option); $i++) {
		list($key,$val) = each ($option);
		echo "<option value=$key>$val\n";
	}
	echo "</select>&nbsp;\n";
	echo $lang["search"][1];
	echo "&nbsp;<select name=phrasetype>\n";
	echo "<option value=contains>".$lang["search"][2]."</option>\n";
	echo "<option value=exact>".$lang["search"][3]."</option>\n";
	echo "</select>\n";
	echo "<input type=text size=5 name=\"contains\">\n"; 
	echo "&nbsp;";
	echo $lang["search"][4];
	echo "&nbsp;<select name=sort size=1>\n";
	reset($option);
	for ($i=0; $i < count($option); $i++) {
		list($key,$val) = each ($option);
		echo "<option value=$key>$val\n";
	}
	echo "</select> \n";
	echo "</td><td width=80 align=center bgcolor=".$cfg_layout["tab_bg_2"].">\n";
	echo "<input type=submit value=\"".$lang["buttons"][0]."\">\n";
	echo "</td></tr></table></center></form>\n";
}


function showPDAList($target,$username,$field,$phrasetype,$contains,$sort,$order,$start) {

	// Lists PDAs

	GLOBAL $cfg_install, $cfg_layout, $cfg_features, $lang;

	// Build query
	if ($phrasetype == "contains") {
		$where = "($field LIKE '%".$contains."%')";
	} else {
		$where = "($field LIKE '".$contains."')";
	}
	if (!$start) {
		$start = 0;
	}
	if (!$order) {
		$order = "ASC";
	}
	$query = "SELECT * FROM pda WHERE $where ORDER BY $sort $order";

	// Get it from database	
	$db = new DB;
	if ($result = $db->query($query)) {
		$numrows= $db->num_rows($result);

		// Limit the result, if no limit applies, use prior result
		if ($numrows>$cfg_features["list_limit"]) {
			$query_limit = "SELECT * FROM pda WHERE $where ORDER BY $sort $order LIMIT $start,".$cfg_features["list_limit"]." ";
			$result_limit = $db->query($query_limit);
			$numrows_limit = $db->num_rows($result_limit);
		} else {
			$numrows_limit = $numrows;
			$result_limit = $result;
		}
		

		if ($numrows_limit>0) {
			// Produce headline
			echo "<center><table border=0><tr>\n";

			// Username
			echo "<th>";
			if ($sort=="username") {
				echo "&middot;&nbsp;";
			}
			echo "<a href=\"$target?field=$field&phrasetype=$phrasetype&contains=$contains&sort=username&order=ASC&start=$start\">";
			echo $lang["pda"][1]."</th>\n";

			// Manufacturer			
			echo "<th>";
			if ($sort=="manufacturer") {
				echo "&middot;&nbsp;";
			}
			echo "<a href=\"$target?field=$field&phrasetype=$phrasetype&contains=$contains&sort=location&order=ASC&start=$start\">";
			echo $lang["pda"][2]."</th>\n";

			// Model
			echo "<th>";
			if ($sort=="model") {
				echo "&middot;&nbsp;";
			}
			echo "<a href=\"$target?field=$field&phrasetype=$phrasetype&contains=$contains&sort=type&order=ASC&start=$start\">";
			echo $lang["pda"][3]."</th>\n";

			// Part Number		
			echo "<th>";
			if ($sort=="part_number") {
				echo "&middot;&nbsp;";
			}
			echo "<a href=\"$target?field=$field&phrasetype=$phrasetype&contains=$contains&sort=date_mod&order=DESC&start=$start\">";
			echo $lang["pda"][4]."</th>\n";

			// OS
			echo "<th>";
			if ($sort=="os") {
				echo "&middot;&nbsp;";
			}
			echo "<a href=\"$target?field=$field&phrasetype=$phrasetype&contains=$contains&sort=contact&order=ASC&start=$start\">";
			echo $lang["pda"][5]."</th>\n";

			echo "</tr>\n";

			for ($i=0; $i < $numrows_limit; $i++) {
				$ID = $db->result($result_limit, $i, "ID");
				$pda = new PDA;
				$pda->getfromDB($ID,0);
				echo "<tr bgcolor=\"".$cfg_layout["tab_bg_2"]."\">\n";
				echo "<td><b>";
				echo "<a href=\"".$cfg_install["root"]."/pda/pda-info-form.php?ID=$ID\">";
				echo $pda->fields["username"]." (".$pda->fields["ID"].")";
				echo "</b></a></td>\n";
				echo "<td>".$pda->fields["manufacturer"]."</td>\n";
				echo "<td>".$pda->fields["model"]."</td>\n";
				echo "<td>".$pda->fields["part_number"]."</td>\n";
				echo "<td>".$pda->fields["os"]."</td>\n";
				echo "</tr>\n";
			}

			// Close Table
			echo "</table></center>\n";

			// Pager
			$parameters="field=$field&phrasetype=$phrasetype&contains=$contains&sort=$sort&order=$order";
			printPager($start,$numrows,$target,$parameters);

		} else {
			echo "<center><b>".$lang["pda"][17]."</b></center>\n";
			echo "<hr noshade>\n";
			searchFormPDA();
		}
	}
}


function showPDAForm($template,$target,$ID) {

	GLOBAL $cfg_install, $cfg_layout, $lang;

	$pda = new PDA;

	echo "<center><form method=post action=\"$target\">\n";
	echo "<table border=0 cellpadding=2>\n";
	echo "<tr><th colspan=2><b>\n";
	if ($ID=="") {
		echo $lang["pda"][10].":";
	} else {
		$pda->getfromDB($ID,$template);
		echo $lang["pda"][11]." ID $ID:";
	}		
	echo "</b></th></tr>\n";
	
	echo "<tr><td bgcolor=".$cfg_layout["tab_bg_1"]." valign=top>\n";

	echo "<table cellpadding=0 cellspacing=0 border=0>\n";

	echo "<tr><td>".$lang['setup']['cost_center'].":       </td>";
        echo "<td>\n";
                dropdownValue('dropdown_cost_center', 'cost_center', $pda->fields['cost_center']);
        echo "</td><TD></TD></tr>\n";

	echo "<tr><td>".$lang["pda"][1].":	</td>\n";
	echo "<td><input type=text name=username value=\"".$pda->fields["username"]."\" size=10></td>\n";
	echo "</tr>\n";

	echo "<tr><td>".$lang["pda"][12].":	</td>\n";
	echo "<td><input type=text name=contact size=12 value=\"".$pda->fields["contact"]."\"></td>\n";
	echo "</tr>\n";

	echo "<tr><td>".$lang["pda"][7].":</td>\n";
        echo "<td><input type=text size=15 name=serial value=\"".$pda->fields["serial"]."\"></td>";
        echo "<TD></TD>\n";
        echo "</tr>\n";

	echo "</table>\n";

	echo "</td>\n";	
	echo "<td bgcolor=".$cfg_layout["tab_bg_1"]." valign=top>\n";

	echo "<table cellpadding=0 cellspacing=0 border=0\n";

	echo "<tr><td>".$lang["pda"][2].":      </td><td>\n";
                dropdownValue("dropdown_manufacturer", "manufacturer", $pda->fields['manufacturer']);
        echo "</TD><TD>\n";

	echo "<tr><td>".$lang["pda"]['model'].": 	</td><td>\n";
		dropdownValue("dropdown_pda_model", "model", $pda->fields['model']);
    	echo "</TD><TD>\n";
	echo "</TD></tr>\n";

	echo "<tr><td>".$lang["pda"]['part_number'].":      </td><td>\n";
                dropdownValue("dropdown_pda_part_number", "part_number", $pda->fields['part_number']);
        echo "</TD><TD>\n";
        echo "</TD></tr>\n";

	echo "<tr><td>".$lang["pda"][5].":      </td><td>\n";
                dropdownValue("dropdown_pda_os", "os", $pda->fields['os']);
        echo "</TD><TD>\n";

	echo "<tr><td>".$lang["pda"][6].":      </td><td>\n";
                dropdownValue("dropdown_pda_osver", "osver", $pda->fields['osver']);
        echo "</TD><TD>\n";
/*
	echo "<tr><td>".$lang["pda"][21].":</td>";
	echo "<td><input type=text size=2 name=size value=\"".$pda->fields["size"]."\">\"</td>";
	echo "</tr>";

		echo "<tr><td>".$lang["pda"][18].": </td><td>";

		// micro?
		echo "<table border=0 cellpadding=2 cellspacing=0><tr>";
		echo "<td>";
		if ($pda->fields["flags_micro"] == 1) {
			echo "<input type=checkbox name=flags_micro value=1 checked>";
		} else {
			echo "<input type=checkbox name=flags_micro value=1>";
		}
		echo "</td><td>".$lang["pda"][14]."</td>";
		echo "</tr></table>";

		// speakers?
		echo "<table border=0 cellpadding=2 cellspacing=0><tr>";
		echo "<td>";
		if ($pda->fields["flags_speaker"] == 1) {
			echo "<input type=checkbox name=flags_speaker value=1 checked>";
		} else {
			echo "<input type=checkbox name=flags_speaker value=1>";
		}
		echo "</td><td>".$lang["pda"][15]."</td>";
		echo "</tr></table>";

		// sub-d?
		echo "<table border=0 cellpadding=2 cellspacing=0><tr>";
		echo "<td>";
		if ($pda->fields["flags_subd"] == 1) {
			echo "<input type=checkbox name=flags_subd value=1 checked>";
		} else {
			echo "<input type=checkbox name=flags_subd value=1>";
		}
		echo "</td><td>".$lang["pda"][19]."</td>";
		echo "</tr></table>";

		// bnc?
		echo "<table border=0 cellpadding=2 cellspacing=0><tr>";
		echo "<td>";
		if ($pda->fields["flags_bnc"] == 1) {
			echo "<input type=checkbox name=flags_bnc value=1 checked>";
		} else {
			echo "<input type=checkbox name=flags_bnc value=1>";
		}
		echo "</td><td>".$lang["pda"][20]."</td>";
		echo "</tr></table>";

		echo "</td></tr>";
*/

	echo "</table>\n";
	echo "</td>\n";	
	echo "</tr>\n";
	echo "<tr>\n";
	echo "<td bgcolor=".$cfg_layout["tab_bg_1"]." valign=top colspan=2>\n";

	echo "<table width=100% cellpadding=0 cellspacing=0 border=0><tr><td valign=top>\n";
	echo $lang["pda"][8].":	</td>\n";
	echo "<td align=center><textarea cols=35 rows=4 name=comments wrap=soft>".$pda->fields["comments"]."</textarea>\n";
	echo "</td></tr></table>\n";

	echo "</td>\n";
	echo "</tr>\n";
	
	if ($ID=='' || $template!='') {

		echo "<tr>\n";
		echo "<td bgcolor=".$cfg_layout["tab_bg_2"]." valign=top colspan=2>\n";
		echo "<center><input type=submit name=add value=\"".$lang["buttons"][8]."\"></center>\n";
		echo "</td>\n";
		echo "</form></tr>\n";

		echo "</table></center>\n";

	} else {

		echo "<tr>\n";
		echo "<td bgcolor=".$cfg_layout["tab_bg_2"]." valign=top>\n";
		echo "<input type=hidden name=ID value=\"$ID\">\n";
		echo "<center><input type=submit name=update value=\"".$lang["buttons"][7]."\"></center>\n";
		echo "</td></form>\n\n";
		
		// No more delete button
		//echo "<form action=\"$target\" method=post>\n";
		echo "<td bgcolor=".$cfg_layout["tab_bg_2"]." valign=top>\n";
		//echo "<input type=hidden name=ID value=\"$ID\">\n";
		//echo "<center><input type=submit name=delete value=\"".$lang["buttons"][6]."\"></center>";
		echo "</td>\n";
		echo "</form></tr>\n";

		echo "</table></center>\n";
		// Using 5 for type, but not sure if in use already
		showConnect($target,$ID,5);
	}
}


function updatePDA($input) {
	// Update a monitor in the database

	$pda = new PDA;
	$pda->getFromDB($input["ID"],'');

	// set new date and make sure it gets updated
	$updates[0]= "date_mod";
	$pda->fields["date_mod"] = date("Y-m-d H:i:s");

	// Pop off the last two attributes, no longer needed
	$null=array_pop($input);
	$null=array_pop($input);
	
	// Get all flags and fill with 0 if unchecked in form
	for ($i=0; $i < count($pda->fields); $i++) {
		list($key,$val) = each($pda->fields);
		if (eregi("\.*flag\.*",$key)) {
			if (!$input[$key]) {
				$input[$key]=0;
			}
		}
	}

	// Fill the update-array with changes
	$x=1;
	for ($i=0; $i < count($input); $i++) {
		list($key,$val) = each($input);
		if ($pda->fields[$key] != $input[$key]) {
			$pda->fields[$key] = $input[$key];
			$updates[$x] = $key;
			$x++;
		}
	}

	$pda->updateInDB($updates);

}

function addPDA($input) {
	// Add Monitor, nasty hack until we get PHP4-array-functions

	$pda = new PDA;

	// dump status
	$null = array_pop($input);
	
	// fill array for update
	for ($i=0; $i < count($input); $i++) {
		list($key,$val) = each($input);
		if ($pda->fields[$key] != $input[$key]) {
			$pda->fields[$key] = $input[$key];
		}
	}

	$pda->addToDB();

}

function deletePDA($input) {
	// Delete PDA
	
	$pda = new PDA;
	$pda->deleteFromDB($input["ID"]);
	
} 	

?>
Return current item: IRMA - Asset Inventory and Job Tracking