Overview

Packages

  • None
  • Sesha

Classes

  • Horde_Core_UI_VarRenderer_Stockedit_Html
  • Sesha
  • Sesha_Api
  • Sesha_Driver
  • Sesha_Driver_Sql
  • Sesha_Exception
  • Sesha_Forms_Category
  • Sesha_Forms_CategoryDelete
  • Sesha_Forms_CategoryList
  • Sesha_Forms_Property
  • Sesha_Forms_PropertyDelete
  • Sesha_Forms_PropertyList
  • Sesha_Forms_Search
  • Sesha_Forms_Stock
  • Sesha_Forms_Type_Client
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * This class is the Stock form that will be responsible for displaying and
  4:  * editing stock entries in the Sesha application.
  5:  *
  6:  * Copyright 2004-2007 Andrew Coleman <mercury@appisolutions.net>
  7:  * Copyright 2004-2011 Horde LLC (http://www.horde.org/)
  8:  *
  9:  * See the enclosed file COPYING for license information (GPL). If you
 10:  * did not receive this file, see http://www.horde.org/licenses/gpl.
 11:  *
 12:  * @author  Andrew Coleman <mercury@appisolutions.net>
 13:  * @since   Sesha 1
 14:  * @package Sesha
 15:  */
 16: 
 17: class Sesha_Forms_Stock extends Horde_Form {
 18: 
 19:     /**
 20:      * The default constructor for the StockForm class.
 21:      *
 22:      * @param Horde_Variables $vars  The default variables to use.
 23:      */
 24:     function __construct($vars)
 25:     {
 26: 
 27:         parent::__construct($vars);
 28:         $sesha_driver = $GLOBALS['injector']->getInstance('Sesha_Factory_Driver')->create();
 29: 
 30:         // Buttons and hidden configuration
 31:         $this->setButtons(_("Save Item"));
 32:         $this->addHidden('', 'actionId', 'text', true);
 33: 
 34:         // Prepare the categories
 35:         $cat = array();
 36:         $categories = $sesha_driver->getCategories();
 37:         foreach ($categories as $c) {
 38:             $cat[$c['category_id']] = $c['category'];
 39:         }
 40:         // Get the list of selected categories
 41:         $categoryIds = array();
 42:         $t = $vars->get('category_id');
 43:         if (!is_array($t)) {
 44:             $t = array($t);
 45:         }
 46:         $categoryIds = array_merge($categoryIds, $t);
 47: 
 48:         // The stock ID should only be editable if you are adding a new item;
 49:         // otherwise let the user know what the stock_id is, and then make a
 50:         // read-only required hidden variable
 51:         if ($vars->get('actionId') == 'add_stock') {
 52:             $this->addVariable(_("Stock ID"), 'stock_id', 'int', false, false);
 53:         } else {
 54:             $this->addVariable(_("Stock ID"), 'stock_id', 'int', false, true);
 55:             $this->addHidden('', 'stock_id', 'int', true, true);
 56:         }
 57:         // Basic variables for any stock item
 58:         $this->addVariable(_("Name"), 'stock_name', 'text', false, false);
 59:         if (!count($cat)) {
 60:             $fieldtype = 'invalid';
 61:             $cat = _("No categories are currently configured. Click 'Admin' (above) to add some.");
 62:         } else {
 63:             $fieldtype = 'multienum';
 64:         }
 65:         $categoryVar = $this->addVariable(_("Category"), 'category_id',
 66:                                            $fieldtype, true, false, null,
 67:                                            array($cat));
 68: 
 69:         // Set the variables already stored in the Driver, if applicable
 70:         foreach ($categoryIds as $categoryId) {
 71:             try {
 72:                 $properties = $sesha_driver->getPropertiesForCategories($categoryId);
 73:             } catch (Sesha_Exception $e) {
 74:                 throw new Sesha_Exception($e);
 75:             }
 76: 
 77:             foreach ($properties as $property) {
 78:                 $fieldname   = 'property[' . $property['property_id'] . ']';
 79:                 $fieldtitle  = $property['property'];
 80:                 $fielddesc   = $property['description'];
 81:                 if (!empty($property['unit'])) {
 82:                     if (!empty($fielddesc)) {
 83:                         $fielddesc .= ' -- ';
 84:                     }
 85:                     $fielddesc .= _("Unit: ") . $property['unit'];
 86:                 }
 87:                 $fieldtype   = $property['datatype'];
 88:                 $fieldparams = array();
 89:                 if (is_array($property['parameters'])) {
 90:                     $fieldparams = $property['parameters'];
 91:                     if (in_array($fieldtype, array('link', 'enum', 'multienum', 'mlenum', 'radio', 'set', 'sorter'))) {
 92:                         $fieldparams['values'] = Sesha::getStringlistArray($fieldparams['values']);
 93:                     }
 94:                 }
 95:                 $this->addVariable($fieldtitle, $fieldname, $fieldtype,
 96:                                     false, false, $fielddesc, $fieldparams);
 97:             }
 98:         }
 99:         $this->addVariable(_("Note"), 'note', 'longtext', false);
100: 
101:         // Default action
102:         $action = Horde_Form_Action::factory('submit');
103:         $categoryVar->setAction($action);
104:         $categoryVar->setOption('trackchange', true);
105:     }
106: }
107: 
API documentation generated by ApiGen