1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: class Ulaform {
16:
17: static public function getActionInfo($action)
18: {
19: static $info = array();
20: if (isset($info[$action])) {
21: return $info[$action];
22: }
23:
24: $class = 'Ulaform_Action_' . $action;
25: $info[$action] = call_user_func(array($class, 'getInfo'));
26:
27: return $info[$action];
28: }
29:
30: static public function getActionParams($action)
31: {
32: static $params = array();
33: if (isset($params[$action])) {
34: return $params[$action];
35: }
36:
37: $class = 'Ulaform_Action_' . $action;
38: $params[$action] = call_user_func(array($class, 'getParams'));
39:
40: return $params[$action];
41: }
42:
43: 44: 45: 46: 47:
48: static public function getFieldTypes()
49: {
50: static $available_fields = array();
51: if (!empty($available_fields)) {
52: return $available_fields;
53: }
54:
55:
56: $fields = self::getFieldTypesArray();
57:
58:
59: foreach ($fields as $field_type => $info) {
60: $available_fields[$field_type] = $info['name'];
61: }
62:
63:
64: asort($available_fields);
65:
66: return $available_fields;
67: }
68:
69: 70: 71: 72: 73:
74: static public function getFieldTypesArray()
75: {
76: static $fields_array = array();
77: if (!empty($fields_array)) {
78: return $fields_array;
79: }
80:
81:
82: $classes = get_declared_classes();
83:
84:
85: foreach ($classes as $class) {
86: if (strtolower(substr($class, 0, 16)) == 'horde_form_type_') {
87: $field_type = substr($class, 16);
88: 89:
90: if ($field_type == 'invalid') {
91: continue;
92: }
93: $fields_array[$field_type] = @call_user_func(array('Horde_Form_Type_' . $field_type, 'about'));
94: }
95: }
96:
97: return $fields_array;
98: }
99:
100: static public function getFieldParams($field_type)
101: {
102: $fields = self::getFieldTypesArray();
103:
104:
105: if (!isset($fields[$field_type]['params'])) {
106: return array();
107: }
108:
109: return $fields[$field_type]['params'];
110: }
111:
112: static public function getStringlistArray($string)
113: {
114: $string = str_replace("'", "\'", $string);
115: $values = explode(',', $string);
116:
117: foreach ($values as $value) {
118: $value = trim($value);
119: $value_array[$value] = $value;
120: }
121:
122: return $value_array;
123: }
124:
125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137:
138: static public function checkPermissions($in, $filter, $permission = Horde_Perms::READ, $key = null)
139: {
140: static $permsCache;
141:
142: $admin = $GLOBALS['registry']->isAdmin();
143:
144: if ($admin) {
145: return $in;
146: }
147:
148: $out = array();
149: $userID = $GLOBALS['registry']->getAuth();
150: switch ($filter) {
151:
152: case 'form':
153: if (is_array($in)) {
154: $id = serialize($in);
155: } else {
156: $id = $in;
157: $in = array($in);
158: }
159:
160: if (isset($permsCache[$id][$permission])) {
161: return $permsCache[$id][$permission];
162: }
163:
164: foreach ($in as $form_id => $form) {
165: if (!is_null($key)) {
166: $form_id = $form[$key];
167: }
168: if ($GLOBALS['perms']->hasPermission('ulaform:forms:' . $form_id, $userID, $permission)) {
169:
170: $permsCache[$form_id][$permission] = true;
171: $out[$form_id] = $form;
172: }
173: }
174: $permsCache[$id][$permission] = $out;
175: break;
176:
177: default:
178:
179: $out = false;
180: }
181:
182: return $out;
183: }
184:
185: }
186: