1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15:
16:
17: class Sesha_Forms_Stock extends Horde_Form {
18:
19: 20: 21: 22: 23:
24: function __construct($vars)
25: {
26:
27: parent::__construct($vars);
28: $sesha_driver = $GLOBALS['injector']->getInstance('Sesha_Factory_Driver')->create();
29:
30:
31: $this->setButtons(_("Save Item"));
32: $this->addHidden('', 'actionId', 'text', true);
33:
34:
35: $cat = array();
36: $categories = $sesha_driver->getCategories();
37: foreach ($categories as $c) {
38: $cat[$c['category_id']] = $c['category'];
39: }
40:
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:
49:
50:
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:
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:
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:
102: $action = Horde_Form_Action::factory('submit');
103: $categoryVar->setAction($action);
104: $categoryVar->setOption('trackchange', true);
105: }
106: }
107: