Location: PHPKode > projects > IRMA - Asset Inventory and Job Tracking > irma-1.0.6/includes/pda/classes.php
<?php
/*
 *
 * $Header: /cvsroot/irma/irma/includes/pda/classes.php,v 1.3 2007/10/26 23:37:49 bbaez Exp $
 *
 */
class PDA {

	var $fields	= array();
	var $updates	= array();
	
	function getfromDB ($ID,$templates) {
		
		if ($template) {
                        $table = "templates_pda";
                } else {
                        $table = "pda";
                }

		// Make new database object and fill variables
		$db = new DB;
		$query = "SELECT * FROM $table WHERE (ID = '$ID')";
		if ($result = $db->query($query)) {
			if ($db->num_rows($result)) {
				$data = mysql_fetch_array($result);
				for($i=0; $i < count($data); $i++) {
					list($key,$val) = each($data);
					$this->fields[$key] = $val;
				}
				return true;
			}
		} else {
			return false;
		}
	}

	function updateInDB($updates)  {

		$db = new DB;

		for ($i=0; $i < count($updates); $i++) {
			$query  = "UPDATE pda SET ";
			$query .= $updates[$i];
			$query .= "='";
			$query .= $this->fields[$updates[$i]];
			$query .= "' WHERE ID='";
			$query .= $this->fields["ID"];	
			$query .= "'";
			$result=$db->query($query);
		}
		
	}
	
	function addToDB() {
		
		$db = new DB;

		$this->comments = addslashes($this->comments);
		
		// Build query
		$query = "INSERT INTO pda (";
		for ($i=0; $i < count($this->fields); $i++) {
			list($key,$val) = each($this->fields);
			$fields[$i] = $key;
			$values[$i] = $val;
		}		
		for ($i=0; $i < count($fields); $i++) {
			$query .= $fields[$i];
			if ($i!=count($fields)-1) {
				$query .= ",";
			}
		}
		$query .= ") VALUES (";
		for ($i=0; $i < count($values); $i++) {
			$query .= "'".$values[$i]."'";
			if ($i!=count($values)-1) {
				$query .= ",";
			}
		}
		$query .= ")";

		if ($result=$db->query($query)) {
			return true;
		} else {
			return false;
		}
	}

	function deleteFromDB($ID) {

		$db = new DB;

		$query = "DELETE from pda WHERE ID = '$ID'";
		if ($result = $db->query($query)) {
			// Change type='4' originally, was copied from monitor
			// Changed to 5, not sure if in use already
			// 3 is for printers, 4 is for monitors
			$query2 = "DELETE FROM connect_wire where (end1='$ID' AND type='5')";
			if ($result2 = $db->query($query2)) {
				return true;
			}
		} else {
			return false;
		}
	}

}

class PDADetails {

    var $fields = array();
    var $updates    = array();

    function getfromDB ($pda_id) {

        // Make new database object and fill variables
        $db = new DB;
        $query = "SELECT * FROM type_pda WHERE (pda_id = '$pda_id')";
        if ($result = $db->query($query)) {
            $data = mysql_fetch_array($result);
            for($i=0; $i < count($data); $i++) {
                list($key,$val) = each($data);
                $this->fields[$key] = $val;
            }
            return true;
        } else {
            return false;
        }
    }
}

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