1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: class Ulaform_Driver {
16:
17: 18: 19: 20: 21:
22: protected $_params = array();
23:
24: protected $_driver;
25:
26: 27: 28: 29: 30:
31: public function __construct($params)
32: {
33: $this->_params = $params;
34: $this->_driver = $GLOBALS['injector']->getInstance('Ulaform_Factory_Driver')->create();
35: }
36:
37: 38: 39: 40: 41: 42:
43: public function getFormsList()
44: {
45: $forms = $this->_driver->getForms();
46:
47: $forms_list = array();
48: $i = 0;
49: foreach ($forms as $form) {
50: $forms_list[$i]['id'] = $form['form_id'];
51: $forms_list[$i]['del_url'] = Horde::url('delete.php')->add('form_id', $form['form_id']);
52: $forms_list[$i]['edit_url'] = Horde::url('edit.php')->add('form_id', $form['form_id']);
53: $forms_list[$i]['preview_url'] = Horde::url('display.php')->add('form_id', $form['form_id']);
54: $forms_list[$i]['html_url'] = Horde::url('genhtml.php')->add('form_id', $form['form_id']);
55: $forms_list[$i]['view_url'] = Horde::url('fields.php')->add('form_id', $form['form_id']);
56: $forms_list[$i]['name'] = $form['form_name'];
57: $forms_list[$i]['action'] = $form['form_action'];
58: $forms_list[$i]['onsubmit'] = $form['form_onsubmit'];
59: $i++;
60: }
61:
62: return $forms_list;
63: }
64:
65: 66: 67: 68: 69: 70: 71: 72: 73:
74: public function getFieldsList($form_id)
75: {
76: $form = $this->_driver->getForm($form_id);
77: $fields = $this->_driver->getFields($form_id);
78:
79: $fields_list = array();
80: $i = 0;
81: foreach ($fields as $field) {
82: $url_params = array('form_id' => $form_id,
83: 'field_id' => $field['field_id']);
84: $fields_list[$i] = array(
85: 'del_url' => Horde::url('deletefield.php')->add($url_params),
86: 'edit_url' => Horde::url('fields.php')->add($url_params),
87: 'id' => $field['field_id'],
88: 'name' => $field['field_name'],
89: 'label' => $field['field_label'],
90: 'type' => $field['field_type'],
91: 'required' => $field['field_required'] ? _("Yes") : _("No"),
92: 'readonly' => $field['field_readonly'] ? _("Yes") : _("No"));
93: $i++;
94: }
95:
96: return $fields_list;
97: }
98:
99: 100: 101: 102: 103: 104: 105: 106: 107: 108:
109: public function getFieldsArray($form_id)
110: {
111: $form = $this->_driver->getForm($form_id);
112: $fields = $this->_driver->getFields($form_id);
113:
114: $fields_array = array();
115: foreach ($fields as $field) {
116: $fields_array[$field['field_id']] = $field['field_name'];
117: }
118:
119: return $fields_array;
120: }
121:
122: public function getField($form_id, $field_id)
123: {
124: $field = $this->_driver->getFields($form_id, $field_id);
125:
126:
127: if (isset($field[0])) {
128: return $field[0];
129: }
130:
131: return $field;
132: }
133:
134: public function submitForm($form_data)
135: {
136: $form = $this->_driver->getForm($form_data['form_id']);
137: $fields = $this->_driver->getFields($form_data['form_id']);
138:
139: $action = $GLOBALS['injector']->getInstance('Ulaform_Factory_Action')->create($form['form_action']);
140:
141: return $action->doAction($form['form_params'], $form_data, $fields);
142: }
143:
144: public function hasPermission($perm = Horde_Perms::SHOW, $form_id = null)
145: {
146: $perms = $GLOBALS['injector']->getInstance('Horde_Perms');
147: if (!$perms->exists('ulaform:forms:' . $form_id)) {
148: return ($perm & Horde_Perms::DELETE) ? false : true;
149: }
150:
151: return $perms->hasPermission('ulaform:forms', $GLOBALS['registry']->getAuth(), $perm) ||
152: $perms->hasPermission('ulaform:forms:' . $form_id, $GLOBALS['registry']->getAuth(), $perm);
153: }
154:
155: }
156: