1: <?php
2: 3: 4: 5: 6:
7: abstract class Turba_Form_ContactBase extends Horde_Form
8: {
9: 10: 11: 12: 13:
14: protected function _addFields(Turba_Object $contact, $useTabs = true)
15: {
16:
17: global $attributes;
18:
19:
20:
21: $actions = array();
22: $map = $contact->driver->map;
23: $fields = array_keys($contact->driver->getCriteria());
24: foreach ($fields as $field) {
25: if (is_array($map[$field])) {
26: foreach ($map[$field]['fields'] as $action_field) {
27: if (!isset($actions[$action_field])) {
28: $actions[$action_field] = array();
29: }
30: $actions[$action_field]['fields'] = $map[$field]['fields'];
31: $actions[$action_field]['format'] = $map[$field]['format'];
32: $actions[$action_field]['target'] = $field;
33: }
34: }
35: }
36:
37:
38: $tabs = $contact->driver->tabs;
39: if (!count($tabs)) {
40: $tabs = array('' => $fields);
41: }
42: $i = 0;
43: foreach ($tabs as $tab => $tab_fields) {
44: if (!empty($tab)) {
45: if ($useTabs) {
46: $this->setSection($i++, $tab);
47: } else {
48: $this->addVariable($tab, '', 'header', false);
49: }
50: }
51: foreach ($tab_fields as $field) {
52: if (!in_array($field, $fields) ||
53: !isset($attributes[$field])) {
54: continue;
55: }
56:
57: $attribute = $attributes[$field];
58: $params = isset($attribute['params']) ? $attribute['params'] : array();
59: $desc = isset($attribute['desc']) ? $attribute['desc'] : null;
60:
61: if (is_array($map[$field])) {
62: $v = $this->addVariable($attribute['label'], 'object[' . $field . ']', $attribute['type'], false, false, $desc, $params);
63: $v->disable();
64: } else {
65: $readonly = isset($attribute['readonly']) ? $attribute['readonly'] : null;
66: $v = $this->addVariable($attribute['label'], 'object[' . $field . ']', $attribute['type'], $attribute['required'], $readonly, $desc, $params);
67:
68: if (!empty($actions[$field])) {
69: $actionfields = array();
70: foreach ($actions[$field]['fields'] as $f) {
71: $actionfields[] = $this->_getId('object[' . $f . ']');
72: }
73: $a = Horde_Form_Action::factory('updatefield',
74: array('format' => $actions[$field]['format'],
75: 'target' => $this->_getId('object[' . $actions[$field]['target'] . ']'),
76: 'fields' => $actionfields));
77: $v->setAction($a);
78: }
79: }
80:
81: if (isset($attribute['default'])) {
82: $v->setDefault($attribute['default']);
83: }
84: }
85: }
86: }
87:
88: 89: 90: 91: 92: 93: 94:
95: protected function _getId($id)
96: {
97: return preg_replace('/[^A-Za-z0-9-_:.]+/', '_', $id);
98: }
99: }
100: