<?php

  class Form_Catagory extends QuickForm_Multi
  {
    function Form_Catagory($formName = 'catagory', $method = 'post', $target = '_self', $attributes = null)
    {
          $this->HTML_QuickForm($formName, $method, '', $target, $attributes);
    }
    
    function buildForm()
    {
        if (!$this->_mode)
        {
            $this->addElement('header',    null, 'No Mode Set');
            $this->addElement('static',    null, null,  'You must set a mode using the setMode() function');
            return;
        }
      
        if ($this->_mode == HTML_QUICKFORM_ADD)
        {
            $this->addElement('header',   null,  'Add Catagory');
        }
        elseif ($this->_mode == HTML_QUICKFORM_EDIT)
        {
            $this->addElement('header',   null,  'Edit Catagory');
        }
        elseif ($this->_mode == HTML_QUICKFORM_VIEW)
        {
            $this->addElement('header',   null,  'View Catagory');
        }

        $this->addElement('hidden',     'Id');     
        $this->addElement('text',       'Name',         'Name:');
        $this->addElement('textarea',   'Description',  'Description:');
        
        if (($this->_mode == HTML_QUICKFORM_EDIT) && $this->_defaultValues['Image'])
        {
            $this->addElement('static',     'Picture',  'Image:');
            $this->addElement('static',     '','','Uploading a new picture will overwrite the existing image');
        }
 
        if ($this->_mode == HTML_QUICKFORM_ADD)
        {
            $this->addElement('file',       'Image',      'Image:');
            $this->addElement('submit',     'add',        'Add Catagory');
        }
        elseif ($this->_mode == HTML_QUICKFORM_EDIT)
        {
            $this->addElement('file',       'Image');
            $this->addElement('submit',     'save',       'Save Catagory');
        }
        elseif ($this->_mode == HTML_QUICKFORM_VIEW)
        {
            $this->freeze();
            $this->addElement('static',     'Picture',    'Image:');
            $this->addElement('submit',     'edit',       'Edit Catagory');
        }
 
        $this->_formbuilt = true;
    }
    
    function _modifyDefaults()
    {
        if ($this->_defaultValues['Image'])
        {
          $this->setDefaults(array('Picture'=>'<img src="' . $this->_defaultValues['Image'] . '" />'));
        }
    }
  }
?>
