Location: PHPKode > projects > IRMA - Asset Inventory and Job Tracking > irma-1.0.6/includes/support-contracts/classes.php
<?php

class SupportContract {

    var $support_contract_id = 0;
    var $description = '';
    var $vendor_id = 0;
    var $support_supplier_id = 0;
    var $start_date = '';
    var $end_date = '';
    var $comments = '';

    var $supplier_contacts = array();
    var $technician_contacts = array();
    var $contract_contacts = array();
    var $supplier = null;
    
    function getfromDB($id) {

        $this->support_contract_id = $id;

        $db = new DB;

        $sql = <<<EOF
SELECT
    support_contract_id, description, vendor_id,
    support_supplier_id, start_date, end_date, comments
FROM
    support_contract
WHERE
    (support_contract_id = {$id})
EOF;

        $rs = $db->query($sql);

        if (! $rs) {
            return false;
        }

        $this->support_contract_id = 
            $db->result($rs, 0, 'support_contract_id');
        $this->description = 
            stripslashes($db->result($rs, 0, 'description'));
        $this->vendor_id = $db->result($rs, 0, 'vendor_id');
        $this->support_supplier_id = 
            $db->result($rs, 0, 'support_supplier_id');
        $this->start_date = $db->result($rs, 0, 'start_date');
        $this->end_date = $db->result($rs, 0, 'end_date');
        $this->comments = stripslashes($db->result($rs, 0, 'comments'));
        
        return true;

    }

    function addToDB() {    

        $comments = addslashes($this->comments);
        $description = addslashes($this->description);
        
        $db = new DB;

        $sql = <<<EOF
INSERT INTO
    support_contract (description,
                      vendor_id, 
                      support_supplier_id,
                      start_date, 
                      end_date, 
                      comments)
    VALUES (
        '{$description}',
         {$this->vendor_id},
         {$this->support_supplier_id},
        '{$this->start_date}',
        '{$this->end_date}',
        '{$comments}'
    )
EOF;

        return ($result = $db->query($sql)) ? true : false;
    }
    
    function updateInDB($field_names)  {

        $db = new DB;

        // Which fields need quotes
        $nq = array();
        $nq['description'] = 1;
        $nq['vendor_id'] = 0;
        $nq['support_supplier_id'] = 0;
        $nq['start_date'] = 1;
        $nq['end_date'] = 1;
        $nq['comments'] = 1;

        foreach ($field_names as $name) {

            $value = $this->$name;

            if ($nq[$name] == 1) {
                $value = "'{$value}'";
            }

            $query = <<<EOF
UPDATE 
    support_contract
SET 
    {$name} = {$value}
WHERE
    support_contract_id = {$this->support_contract_id}
EOF;
            $result = $db->query($query);
        }
        
    }

    function deleteFromDB($id) {

        $db = new DB;

    }
}

class SupportSupplier {
    
    var $support_supplier_id = 0;
    var $name     = '';
    var $address  = '';
    var $phone    = '';
    var $fax      = '';
    var $comments = '';

    function getfromDB($support_supplier_id) {

        $this->support_supplier_id = $support_supplier_id;

        $db = new DB;

        $sql = <<<EOF
SELECT 
    support_supplier_id,
    name,
    address,
    phone,
    fax,
    comments
FROM 
    support_supplier
WHERE
    support_supplier_id = {$support_supplier_id}
EOF;
    
        $rs = $db->query($sql);

        if (! $rs) {
             print $db->error();
             return false;
        }

        $this->support_supplier_id = 
            $db->result($rs, 0, 'support_supplier_id');
        $this->name = $db->result($rs, 0, 'name');
        $this->address = stripslashes($db->result($rs, 0, 'address'));
        $this->phone = $db->result($rs, 0, 'phone');
        $this->fax = $db->result($rs, 0, 'fax');
        $this->comments = stripslashes($db->result($rs, 0, 'comments'));

        return true;

    }

    function addToDB() {    

        $this->comments = addslashes($this->comments);
        $this->address = addslashes($this->address);
    
        $db = new DB;
        $query = <<<EOF
INSERT INTO 
    support_supplier(name, address, phone, fax, comments)
    VALUES (
        '{$this->name}',
        '{$this->address}',
        '{$this->phone}',
        '{$this->fax}',
        '{$comments}'
    )
EOF;

        return ($result = $db->query($query)) ? true : $db->error();

    }

    function updateInDB($field_names)  {

        $db = new DB;

        // Which fields need quotes
        $nq = array();
        $nq['name'] = 1;
        $nq['address'] = 1;
        $nq['phone'] = 1;
        $nq['fax'] = 1;
        $nq['comments'] = 1;

        foreach ($field_names as $name) {

            $value = $this->$name;

            if ($name == 'address' || $name == 'comments') {
                $value = addslashes($value);
            }

            if ($nq[$name] == 1) {
                $value = "'{$value}'";
            }

            $query = <<<EOF
UPDATE 
    support_supplier
SET 
    {$name} = {$value}
WHERE
    support_supplier_id = {$this->support_supplier_id}
EOF;
            $result = $db->query($query);
        }
        
    }

    function deleteFromDB($id) {

        $sql = "DELETE from support_supplier where " .
               "support_supplier_id = {$id}";

        $db = new DB;

        return $db->query($sql);

    }

    function getAllSuppliers() {

        $suppliers = array();

        $db = new DB;

        $sql = <<<EOF
SELECT
    support_supplier_id as id
FROM
    support_supplier
ORDER BY
    name
EOF;

        $result = $db->query($sql);

        for ($i = 0; $i < $db->numrows($result); $i++) {
            $supplier = new SupportSupplier();
            $supplier->getFromDB($db->result($result, $i, 'id'));
            array_push($suppliers, $supplier);
        }

        return $suppliers;

    }
    
}

class SupportPOC {
    
    var $support_poc_id = 0;
    var $name           = '';
    var $type           = '';
    var $fax            = '';
    var $cell           = '';
    var $email          = '';
    var $comments       = '';
    var $parent_table   = '';
    var $parent_id      = 0;

    function getfromDB($support_supplier_id) {

        $this->support_supplier_id = $support_supplier_id;

        $db = new DB;

        $sql = <<<EOF
SELECT 
    support_supplier_id,
    name,
    address,
    phone,
    fax,
    parent_id,
    parent_table,
    comments
FROM 
    support_supplier
WHERE
    support_supplier_id = {$support_supplier_id}
EOF;
    
        $rs = $db->query($query);

        if (! $rs) {
            return false;
        }

        $this->support_supplier_id = 
            $db->result($rs,0, 'support_supplier_id');
        $this->name = $db->result($rs, 0, 'name');
        $this->address = $db->result($rs, 0, 'address');
        $this->phone = $db->result($rs, 0, 'phone');
        $this->fax = $db->result($rs, 0, 'fax');
        $this->parent_id = $db->result($rs, 0, 'parent_id');
        $this->parent_table = $db->result($rs, 0, 'parent_table');
        $this->comments = stripslashes($db->result($rs, 0, 'comments'));

        return true;

    }

    function addToDB() {    

        $this->comments = addslashes($this->comments);
    
        $db = new DB;

        $query = <<<EOF
INSERT INTO 
    support_supplier(name, address, phone, fax, parent_id, parent_table, comments)
    VALUES (
        '{$this->name}',
        '{$this->address}',
        '{$this->phone}',
        '{$this->fax}',
         {$this->parent_id},
        '{$this->parent_table}',
        '{$comments}'
    )
EOF;

        return ($result = $db->query($query)) ? true : false;

    }

    function updateInDB($field_names)  {

        $db = new DB;

        // Which fields need quotes
        $nq = array();
        $nq['name'] = 1;
        $nq['address'] = 1;
        $nq['phone'] = 1;
        $nq['fax'] = 1;
        $nq['comments'] = 1;
        $nq['parent_table'] = 1;

        foreach ($field_names as $name) {

            $value = $this->$name;

            if ($nq[$name] == 1) {
                $value = "'{$value}'";
            }

            $query = <<<EOF
UPDATE 
    support_supplier
SET 
    {$name} = {$value}
WHERE
    support_supplier_id = {$this->support_supplier_id}
EOF;
            $result = $db->query($query);
        }
        
    }

    function deleteFromDB($id) {

        $db = new DB;

    }
    
}

// Ties together a support contract, supplier SLA, and piece of
// physical inventory

class SupportTargetLink {
    
    var $support_target_link_id = 0;
    var $target_type = "";
    var $target_id = 0;
    var $support_contract_id = 0;
    var $support_level_id = 0;

    function getFromDB($support_target_link_id) {

        $this->support_target_link_id = $support_target_link_id;

        $db = new DB;

        $sql = <<<EOF
SELECT 
    support_target_link_id,
    target_type,
    target_id,
    support_contract_id,
    support_level_id
FROM 
    support_target_link
WHERE
    support_target_link_id = {$support_target_link_id}
EOF;
    
        $rs = $db->query($query);

        if (! $rs) {
            return false;
        }

        $this->support_target_link_id = 
            $db->result($rs, 0, 'support_target_link_id');
        $this->target_type = $db->result($rs, 0, 'target_type');
        $this->target_id = $db->result($rs, 0, 'target_id');
        $this->support_contract_id = 
            $db->result($rs, 0, 'support_contract_id');
        $this->support_level_id = $db->result($rs, 0, 'support_level_id');

        return true;

    }

    function addToDB() {    

        $db = new DB;

        $query = <<<EOF
INSERT INTO 
    support_level(target_type,
                  target_id,
                  support_contract_id,
                  support_level_id)
    VALUES (
        '{$this->target_type}',
         {$this->target_id},
         {$this->support_contract_id},
         {$this->support_level_id}
    )
EOF;

        return ($result = $db->query($query)) ? true : false;

    }

    function updateInDB($field_names)  {

        $db = new DB;

        // Which fields need quotes
        $nq = array();
        $nq['target_type'] = 1;
        $nq['target_id'] = 0;
        $nq['support_contract_id'] = 0;
        $nq['support_level_id'] = 0;

        foreach ($field_names as $name) {

            $value = $this->$name;

            if ($nq[$name] == 1) {
                $value = "'{$value}'";
            }

            $query = <<<EOF
UPDATE 
    support_target_link
SET 
    {$name} = {$value}
WHERE
    support_target_link_id = {$this->support_target_link_id}
EOF;
            $result = $db->query($query);
        }
        
    }
    

    function deleteFromDB($id) {

        $db = new DB;

    }

}

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