<?php
defined('VSIGN') or die("Sorry, you are not allowed to directly access this page.<br /> Please press the back button in your browser.");

class Resolution extends Data
{
    /**
     * Adds a resolution
     * @param <type> $resolution
     * @param <type> $width
     * @param <type> $height
     * @return <type>
     */
    public function Add($resolution, $width, $height)
    {
        $db =& $this->db;
        
        $SQL = "INSERT INTO resolution (resolution, width, height) VALUES ('%s', %d, %d)";
        $SQL = sprintf($SQL, $db->escape_string($resolution), $width, $height);

        if(!$db->query($SQL))
        {
            trigger_error($db->error());
            $this->SetError(25000, 'Cannot add this resolution.');

            return false;
        }

        return true;
    }

    /**
     * Edits a resolution
     * @param <type> $resolutionID
     * @param <type> $resolution
     * @param <type> $width
     * @param <type> $height
     * @return <type>
     */
    public function Edit($resolutionID, $resolution, $width, $height)
    {
        $db =& $this->db;

        $SQL = "UPDATE resolution SET resolution = '%s', width = %d, height = %d WHERE resolutionID = %d ";
        $SQL = sprintf($SQL, $db->escape_string($resolution), $width, $height, $resolutionID);

        if(!$db->query($SQL))
        {
            trigger_error($db->error());
            $this->SetError(25000, 'Cannot edit this resolution.');

            return false;
        }

        return true;
    }

    /**
     * Deletes a Resolution
     * @param <type> $resolutionID
     * @return <type>
     */
    public function Delete($resolutionID)
    {
        $db =& $this->db;

        $SQL = "DELETE FROM resolution WHERE resolutionID = %d";
        $SQL = sprintf($SQL, $resolutionID);

        if(!$db->query($SQL))
        {
            trigger_error($db->error());
            $this->SetError(25000, 'Cannot delete this resolution.');

            return false;
        }

        return true;
    }
}
?>