1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16:
17: class Ulaform_Block_Form extends Horde_Core_Block {
18:
19: public function __construct($app, $params = array())
20: {
21: parent::__construct($app, $params);
22:
23: $this->_name = _("Show Form");
24: }
25:
26: protected function _params()
27: {
28:
29: $params['form_id'] = array('name' => _("Form"),
30: 'type' => 'enum',
31: 'values' => array());
32:
33: try {
34: $forms = $GLOBALS['injector']->getInstance('Ulaform_Factory_Driver')->create()->getAvailableForms();
35: foreach ($forms as $form) {
36: $params['form_id']['values'][$form['form_id']] = $form['form_name'];
37: }
38: } catch (Ulaform_Exception $e) {}
39:
40: return $params;
41: }
42:
43: protected function _title()
44: {
45: global $registry;
46: $html = Horde::link(Horde::url($registry->getInitialPage(), true)) . $registry->get('name') . '</a>';
47: return $html;
48: }
49:
50: protected function _content()
51: {
52: $vars = Horde_Variables::getDefaultVariables();
53: $formname = $vars->get('formname');
54: $done = false;
55:
56: $form = new Horde_Form($vars);
57: $fields = $GLOBALS['injector']->getInstance('Ulaform_Factory_Driver')->create()->getFields($this->_params['form_id']);
58: foreach ($fields as $field) {
59:
60: if ($field['field_type'] == 'link' ||
61: $field['field_type'] == 'enum' ||
62: $field['field_type'] == 'multienum' ||
63: $field['field_type'] == 'radio' ||
64: $field['field_type'] == 'set' ||
65: $field['field_type'] == 'sorter') {
66: $field['field_params']['values'] = Ulaform::getStringlistArray($field['field_params']['values']);
67: }
68:
69:
70: $form->addVariable($field['field_label'], $field['field_name'], $field['field_type'], $field['field_required'], $field['field_readonly'], $field['field_desc'], $field['field_params']);
71: }
72:
73: if ($formname) {
74: $form->validate($vars);
75:
76: if ($form->isValid() && $formname) {
77: $form->getInfo($vars, $info);
78: $info['form_id'] = $this->_params['form_id'];
79:
80: try {
81: $submit = $GLOBALS['ulaform_driver']->submitForm($info);
82: $GLOBALS['notification']->push(_("Form submitted successfully."), 'horde.success');
83: $done = true;
84: } catch (Horde_Exception $e) {
85: $GLOBALS['notification']->push(sprintf(_("Error submitting form. %s."), $e->getMessage()), 'horde.error');
86: }
87: }
88: }
89:
90: 91:
92: $render_type = ($done) ? 'renderInactive' : 'renderActive';
93:
94:
95: $renderer = new Horde_Form_Renderer();
96: $renderer->showHeader(false);
97: Horde::startBuffer();
98: $form->$render_type($renderer, $vars, Horde::selfUrl(true), 'post');
99: return Horde::endBuffer();
100: }
101:
102: }
103: