Completed
Push — 16.1 ( 592c74...b502d4 )
by Ralf
43:09 queued 19:16
created
api/src/Etemplate/Widget/Customfields.php 2 patches
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -42,12 +42,12 @@  discard block
 block discarded – undo
42 42
 		'date'     => 'Date',
43 43
 		'date-time'=> 'Date+Time',
44 44
 		'select-account' => 'Select account',
45
-		'button'   => 'Button',         // button to execute javascript
45
+		'button'   => 'Button', // button to execute javascript
46 46
 		'url'      => 'Url',
47 47
 		'url-email'=> 'EMail',
48 48
 		'url-phone'=> 'Phone number',
49 49
 		'htmlarea' => 'Formatted Text (HTML)',
50
-		'link-entry' => 'Select entry',         // should be last type, as the individual apps get added behind
50
+		'link-entry' => 'Select entry', // should be last type, as the individual apps get added behind
51 51
 	);
52 52
 
53 53
 	/**
@@ -86,24 +86,24 @@  discard block
 block discarded – undo
86 86
 	 * @param string $cname
87 87
 	 * @param array $expand values for keys 'c', 'row', 'c_', 'row_', 'cont'
88 88
 	 */
89
-	public function beforeSendToClient($cname, array $expand=null)
89
+	public function beforeSendToClient($cname, array $expand = null)
90 90
 	{
91 91
 		// No name, no way to get parameters client-side.
92
-		if(!$this->id) $this->id = self::GLOBAL_ID;
92
+		if (!$this->id) $this->id = self::GLOBAL_ID;
93 93
 
94 94
 		$form_name = self::form_name($cname, $this->id, $expand);
95 95
 
96 96
 		// Store properties at top level, so all customfield widgets can share
97
-		if($this->attrs['app'])
97
+		if ($this->attrs['app'])
98 98
 		{
99 99
 			$app = $this->attrs['app'];
100 100
 		}
101 101
 		else
102 102
 		{
103
-			$app =& $this->getElementAttribute(self::GLOBAL_VALS, 'app');
104
-			if($this->getElementAttribute($form_name, 'app'))
103
+			$app = & $this->getElementAttribute(self::GLOBAL_VALS, 'app');
104
+			if ($this->getElementAttribute($form_name, 'app'))
105 105
 			{
106
-				$app =& $this->getElementAttribute($form_name, 'app');
106
+				$app = & $this->getElementAttribute($form_name, 'app');
107 107
 			}
108 108
 			else
109 109
 			{
@@ -112,21 +112,21 @@  discard block
 block discarded – undo
112 112
 			}
113 113
 		}
114 114
 
115
-		if($this->getElementAttribute($form_name, 'customfields'))
115
+		if ($this->getElementAttribute($form_name, 'customfields'))
116 116
 		{
117
-			$customfields =& $this->getElementAttribute($form_name, 'customfields');
117
+			$customfields = & $this->getElementAttribute($form_name, 'customfields');
118 118
 		}
119
-		elseif($app)
119
+		elseif ($app)
120 120
 		{
121 121
 			// Checking creates it even if it wasn't there
122 122
 			unset(self::$request->modifications[$form_name]['customfields']);
123
-			$customfields =& $this->getElementAttribute(self::GLOBAL_VALS, 'customfields');
123
+			$customfields = & $this->getElementAttribute(self::GLOBAL_VALS, 'customfields');
124 124
 		}
125 125
 
126
-		if(!$app)
126
+		if (!$app)
127 127
 		{
128
-			$app =& $this->setElementAttribute(self::GLOBAL_VALS, 'app', $GLOBALS['egw_info']['flags']['currentapp']);
129
-			$customfields =& $this->setElementAttribute(self::GLOBAL_VALS, 'customfields', Api\Storage\Customfields::get($app));
128
+			$app = & $this->setElementAttribute(self::GLOBAL_VALS, 'app', $GLOBALS['egw_info']['flags']['currentapp']);
129
+			$customfields = & $this->setElementAttribute(self::GLOBAL_VALS, 'customfields', Api\Storage\Customfields::get($app));
130 130
 		}
131 131
 
132 132
 		// if we are in the etemplate editor or the app has no cf's, load the cf's from the app the tpl belongs too
@@ -134,29 +134,29 @@  discard block
 block discarded – undo
134 134
 			($GLOBALS['egw_info']['flags']['currentapp'] == 'etemplate' || !$this->attrs['customfields']) || !isset($customfields))
135 135
 		{
136 136
 			// app changed
137
-			$customfields =& Api\Storage\Customfields::get($app);
137
+			$customfields = & Api\Storage\Customfields::get($app);
138 138
 		}
139 139
 		// Filter fields
140
-		if($this->attrs['field-names'])
140
+		if ($this->attrs['field-names'])
141 141
 		{
142 142
 			$fields_name = explode(',', $this->attrs['field-names']);
143
-			foreach($fields_name as &$f)
143
+			foreach ($fields_name as &$f)
144 144
 			{
145 145
 				if ($f[0] == "!")
146 146
 				{
147
-					$f= substr($f,1);
148
-					$negate_fields[]= $f;
147
+					$f = substr($f, 1);
148
+					$negate_fields[] = $f;
149 149
 				}
150
-				$field_filters []= $f;
150
+				$field_filters [] = $f;
151 151
 			}
152 152
 		}
153 153
 
154 154
 		$fields = $customfields;
155 155
 
156
-		$use_private = self::expand_name($this->attrs['use-private'],0,0,'','',self::$cont);
157
-		$this->attrs['sub-type'] = self::expand_name($this->attrs['sub-type'],0,0,'','',self::$cont);
156
+		$use_private = self::expand_name($this->attrs['use-private'], 0, 0, '', '', self::$cont);
157
+		$this->attrs['sub-type'] = self::expand_name($this->attrs['sub-type'], 0, 0, '', '', self::$cont);
158 158
 
159
-		foreach((array)$fields as $key => $field)
159
+		foreach ((array)$fields as $key => $field)
160 160
 		{
161 161
 			// remove private or non-private cf's, if only one kind should be displayed
162 162
 			if ((string)$use_private !== '' && (boolean)$field['private'] != (boolean)$use_private)
@@ -165,44 +165,44 @@  discard block
 block discarded – undo
165 165
 			}
166 166
 
167 167
 			// Remove filtered fields
168
-			if($field_filters && in_array($key, $negate_fields) && in_array($key, $field_filters))
168
+			if ($field_filters && in_array($key, $negate_fields) && in_array($key, $field_filters))
169 169
 			{
170 170
 				unset($fields[$key]);
171 171
 			}
172 172
 
173 173
 			// Rmove fields for none private cutomfields when name refers to a single custom field
174 174
 			$matches = null;
175
-			if (($pos=strpos($form_name,self::$prefix)) !== false &&
176
-			preg_match($preg = '/'.self::$prefix.'([^\]]+)/',$form_name,$matches) && !isset($fields[$name=$matches[1]]))
175
+			if (($pos = strpos($form_name, self::$prefix)) !== false &&
176
+			preg_match($preg = '/'.self::$prefix.'([^\]]+)/', $form_name, $matches) && !isset($fields[$name = $matches[1]]))
177 177
 			{
178 178
 				unset($fields[$key]);
179 179
 			}
180 180
 		}
181 181
 		// check if name refers to a single custom field --> show only that
182 182
 		$matches = null;
183
-		if (($pos=strpos($form_name,self::$prefix)) !== false && // allow the prefixed name to be an array index too
184
-			preg_match($preg = '/'.self::$prefix.'([^\]]+)/',$form_name,$matches) && isset($fields[$name=$matches[1]]))
183
+		if (($pos = strpos($form_name, self::$prefix)) !== false && // allow the prefixed name to be an array index too
184
+			preg_match($preg = '/'.self::$prefix.'([^\]]+)/', $form_name, $matches) && isset($fields[$name = $matches[1]]))
185 185
 		{
186 186
 			$fields = array($name => $fields[$name]);
187 187
 			$value = array(self::$prefix.$name => $value);
188 188
 			$form_name = self::$prefix.$name;
189 189
 		}
190 190
 
191
-		if(!is_array($fields)) $fields = array();
192
-		switch($type = $this->type)
191
+		if (!is_array($fields)) $fields = array();
192
+		switch ($type = $this->type)
193 193
 		{
194 194
 			case 'customfields-types':
195
-				foreach(self::$cf_types as $lname => $label)
195
+				foreach (self::$cf_types as $lname => $label)
196 196
 				{
197 197
 					$sel_options[$lname] = lang($label);
198
-					$fields_with_vals[]=$lname;
198
+					$fields_with_vals[] = $lname;
199 199
 				}
200 200
 				$link_types = array_intersect_key(Api\Link::app_list('query'), Api\Link::app_list('title'));
201 201
 				// Explicitly add in filemanager, which does not support query or title
202 202
 				$link_types['filemanager'] = lang('filemanager');
203 203
 
204 204
 				ksort($link_types);
205
-				foreach($link_types as $lname => $label)
205
+				foreach ($link_types as $lname => $label)
206 206
 				{
207 207
 					$sel_options[$lname] = '- '.$label;
208 208
 				}
@@ -210,32 +210,32 @@  discard block
 block discarded – undo
210 210
 				self::$transformation['type'][$type]['no_lang'] = true;
211 211
 				return parent::beforeSendToClient($cname, $expand);
212 212
 			case 'customfields-list':
213
-				foreach(array_reverse($fields) as $lname => $field)
213
+				foreach (array_reverse($fields) as $lname => $field)
214 214
 				{
215 215
 					if (!empty($this->attrs['sub-type']) && !empty($field['type2']) &&
216
-						strpos(','.$field['type2'].',',','.$field['type2'].',') === false) continue;    // not for our content type//
216
+						strpos(','.$field['type2'].',', ','.$field['type2'].',') === false) continue; // not for our content type//
217 217
 					if (isset($value[self::$prefix.$lname]) && $value[self::$prefix.$lname] !== '') //break;
218 218
 					{
219
-						$fields_with_vals[]=$lname;
219
+						$fields_with_vals[] = $lname;
220 220
 					}
221 221
 					//$stop_at_field = $name;
222 222
 				}
223 223
 				break;
224 224
 			default:
225
-				foreach(array_reverse($fields) as $lname => $field)
225
+				foreach (array_reverse($fields) as $lname => $field)
226 226
 				{
227
-					$fields_with_vals[]=$lname;
227
+					$fields_with_vals[] = $lname;
228 228
 				}
229 229
 		}
230 230
 		// need to encode values/select-options to keep their order
231
-		foreach($customfields as &$data)
231
+		foreach ($customfields as &$data)
232 232
 		{
233 233
 			if (!empty($data['values']))
234 234
 			{
235 235
 				Select::fix_encoded_options($data['values']);
236 236
 			}
237 237
 		}
238
-		if($fields != $customfields)
238
+		if ($fields != $customfields)
239 239
 		{
240 240
 			// This widget has different settings from global
241 241
 			$this->setElementAttribute($form_name, 'customfields', $fields);
@@ -247,14 +247,14 @@  discard block
 block discarded – undo
247 247
 		parent::beforeSendToClient($cname, $expand);
248 248
 
249 249
 		// Re-format date custom fields from Y-m-d
250
-		$field_settings =& self::get_array(self::$request->modifications, "{$this->id}[customfields]",true);
250
+		$field_settings = & self::get_array(self::$request->modifications, "{$this->id}[customfields]", true);
251 251
 		if (true) $field_settings = array();
252 252
 		$link_types = Api\Link::app_list();
253
-		foreach($fields as $fname => $field)
253
+		foreach ($fields as $fname => $field)
254 254
 		{
255 255
 			// Run beforeSendToClient for each field
256 256
 			$widget = $this->_widget($fname, $field);
257
-			if(method_exists($widget, 'beforeSendToClient'))
257
+			if (method_exists($widget, 'beforeSendToClient'))
258 258
 			{
259 259
 				$widget->beforeSendToClient($this->id == self::GLOBAL_ID ? '' : $this->id, $expand);
260 260
 			}
@@ -271,13 +271,13 @@  discard block
 block discarded – undo
271 271
 	protected function _widget($fname, array $field)
272 272
 	{
273 273
 		static $link_types = null;
274
-		if (!isset($link_types)) $link_types = Api\Link::app_list ();
274
+		if (!isset($link_types)) $link_types = Api\Link::app_list();
275 275
 
276 276
 		$type = $field['type'];
277 277
 		// Link-tos needs to change from appname to link-to
278
-		if($link_types[$field['type']])
278
+		if ($link_types[$field['type']])
279 279
 		{
280
-			if($type == 'filemanager')
280
+			if ($type == 'filemanager')
281 281
 			{
282 282
 				$type = 'vfs-upload';
283 283
 			}
@@ -293,18 +293,18 @@  discard block
 block discarded – undo
293 293
 		$widget->set_attrs($xml);
294 294
 		
295 295
 		// some type-specific (default) attributes
296
-		switch($type)
296
+		switch ($type)
297 297
 		{
298 298
 			case 'date':
299 299
 			case 'date-time':
300 300
 				$widget->attrs['dataformat'] = $type == 'date' ? 'Y-m-d' : 'Y-m-d H:i:s';
301
-				if($field['values']['min']) $widget->attrs['min'] = $field['values']['min'];
302
-				if($field['values']['max']) $widget->attrs['min'] = $field['values']['max'];
301
+				if ($field['values']['min']) $widget->attrs['min'] = $field['values']['min'];
302
+				if ($field['values']['max']) $widget->attrs['min'] = $field['values']['max'];
303 303
 				break;
304 304
 
305 305
 			case 'vfs-upload':
306
-				$widget->attrs['path'] = $field['app'] . ':' .
307
-					self::expand_name('$cont['.Api\Link::get_registry($field['app'],'view_id').']',0,0,0,0,self::$request->content).
306
+				$widget->attrs['path'] = $field['app'].':'.
307
+					self::expand_name('$cont['.Api\Link::get_registry($field['app'], 'view_id').']', 0, 0, 0, 0, self::$request->content).
308 308
 					':'.$field['label'];
309 309
 				break;
310 310
 
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
 	 * @param array $content
364 364
 	 * @param array &$validated=array() validated content
365 365
 	 */
366
-	public function validate($cname, array $expand, array $content, &$validated=array())
366
+	public function validate($cname, array $expand, array $content, &$validated = array())
367 367
 	{
368 368
 		if ($this->id)
369 369
 		{
@@ -379,14 +379,14 @@  discard block
 block discarded – undo
379 379
 		// if we have no id / use self::GLOBAL_ID, we have to set $value_in in global namespace for regular widgets validation to find
380 380
 		if (!$this->id) $content = array_merge($content, $value_in);
381 381
 		//error_log(__METHOD__."($cname, ...) form_name=$form_name, use-private={$this->attrs['use-private']}, value_in=".array2string($value_in));
382
-		$customfields =& $this->getElementAttribute(self::GLOBAL_VALS, 'customfields');
383
-		if(is_array($value_in))
382
+		$customfields = & $this->getElementAttribute(self::GLOBAL_VALS, 'customfields');
383
+		if (is_array($value_in))
384 384
 		{
385
-			foreach(array_keys($value_in) as $field)
385
+			foreach (array_keys($value_in) as $field)
386 386
 			{
387
-				$field_settings = $customfields[$fname=substr($field,1)];
387
+				$field_settings = $customfields[$fname = substr($field, 1)];
388 388
 
389
-				if ((string)$this->attrs['use-private'] !== '' &&	// are only (non-)private fields requested
389
+				if ((string)$this->attrs['use-private'] !== '' && // are only (non-)private fields requested
390 390
 					(boolean)$field_settings['private'] != ($this->attrs['use-private'] != '0'))
391 391
 				{
392 392
 					continue;
@@ -404,8 +404,8 @@  discard block
 block discarded – undo
404 404
 				// widget has no validate method, eg. is only displaying stuff --> nothing to validate
405 405
 				if (!method_exists($widget, 'validate')) continue;
406 406
 				$widget->validate($form_name != self::GLOBAL_ID ? $form_name : $cname, $expand, $content, $validated);
407
-				$field_name = $this->id[0] == self::$prefix && $customfields[substr($this->id,1)] ? $this->id : self::form_name($form_name != self::GLOBAL_ID ? $form_name : $cname, $field);
408
-				$valid =& self::get_array($validated, $field_name, true);
407
+				$field_name = $this->id[0] == self::$prefix && $customfields[substr($this->id, 1)] ? $this->id : self::form_name($form_name != self::GLOBAL_ID ? $form_name : $cname, $field);
408
+				$valid = & self::get_array($validated, $field_name, true);
409 409
 
410 410
 				if (is_array($valid)) $valid = implode(',', $valid);
411 411
 				// NULL is valid for most fields, but not custom fields due to backend handling
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
 		elseif ($this->type == 'customfields-types')
418 418
 		{
419 419
 			// Transformation doesn't handle validation
420
-			$valid =& self::get_array($validated, $this->id ? $form_name : $field, true);
420
+			$valid = & self::get_array($validated, $this->id ? $form_name : $field, true);
421 421
 			if (true) $valid = $value_in;
422 422
 			//error_log(__METHOD__."() $form_name $field: ".array2string($value).' --> '.array2string($value));
423 423
 		}
Please login to merge, or discard this patch.
Braces   +57 added lines, -14 removed lines patch added patch discarded remove patch
@@ -89,7 +89,10 @@  discard block
 block discarded – undo
89 89
 	public function beforeSendToClient($cname, array $expand=null)
90 90
 	{
91 91
 		// No name, no way to get parameters client-side.
92
-		if(!$this->id) $this->id = self::GLOBAL_ID;
92
+		if(!$this->id)
93
+		{
94
+			$this->id = self::GLOBAL_ID;
95
+		}
93 96
 
94 97
 		$form_name = self::form_name($cname, $this->id, $expand);
95 98
 
@@ -188,7 +191,10 @@  discard block
 block discarded – undo
188 191
 			$form_name = self::$prefix.$name;
189 192
 		}
190 193
 
191
-		if(!is_array($fields)) $fields = array();
194
+		if(!is_array($fields))
195
+		{
196
+			$fields = array();
197
+		}
192 198
 		switch($type = $this->type)
193 199
 		{
194 200
 			case 'customfields-types':
@@ -213,11 +219,18 @@  discard block
 block discarded – undo
213 219
 				foreach(array_reverse($fields) as $lname => $field)
214 220
 				{
215 221
 					if (!empty($this->attrs['sub-type']) && !empty($field['type2']) &&
216
-						strpos(','.$field['type2'].',',','.$field['type2'].',') === false) continue;    // not for our content type//
217
-					if (isset($value[self::$prefix.$lname]) && $value[self::$prefix.$lname] !== '') //break;
222
+						strpos(','.$field['type2'].',',','.$field['type2'].',') === false)
223
+					{
224
+						continue;
225
+					}
226
+					// not for our content type//
227
+					if (isset($value[self::$prefix.$lname]) && $value[self::$prefix.$lname] !== '')
228
+					{
229
+						//break;
218 230
 					{
219 231
 						$fields_with_vals[]=$lname;
220 232
 					}
233
+					}
221 234
 					//$stop_at_field = $name;
222 235
 				}
223 236
 				break;
@@ -248,7 +261,10 @@  discard block
 block discarded – undo
248 261
 
249 262
 		// Re-format date custom fields from Y-m-d
250 263
 		$field_settings =& self::get_array(self::$request->modifications, "{$this->id}[customfields]",true);
251
-		if (true) $field_settings = array();
264
+		if (true)
265
+		{
266
+			$field_settings = array();
267
+		}
252 268
 		$link_types = Api\Link::app_list();
253 269
 		foreach($fields as $fname => $field)
254 270
 		{
@@ -271,7 +287,10 @@  discard block
 block discarded – undo
271 287
 	protected function _widget($fname, array $field)
272 288
 	{
273 289
 		static $link_types = null;
274
-		if (!isset($link_types)) $link_types = Api\Link::app_list ();
290
+		if (!isset($link_types))
291
+		{
292
+			$link_types = Api\Link::app_list ();
293
+		}
275 294
 
276 295
 		$type = $field['type'];
277 296
 		// Link-tos needs to change from appname to link-to
@@ -298,8 +317,14 @@  discard block
 block discarded – undo
298 317
 			case 'date':
299 318
 			case 'date-time':
300 319
 				$widget->attrs['dataformat'] = $type == 'date' ? 'Y-m-d' : 'Y-m-d H:i:s';
301
-				if($field['values']['min']) $widget->attrs['min'] = $field['values']['min'];
302
-				if($field['values']['max']) $widget->attrs['min'] = $field['values']['max'];
320
+				if($field['values']['min'])
321
+				{
322
+					$widget->attrs['min'] = $field['values']['min'];
323
+				}
324
+				if($field['values']['max'])
325
+				{
326
+					$widget->attrs['min'] = $field['values']['max'];
327
+				}
303 328
 				break;
304 329
 
305 330
 			case 'vfs-upload':
@@ -316,7 +341,10 @@  discard block
 block discarded – undo
316 341
 				break;
317 342
 
318 343
 			default:
319
-				if (substr($type, 0, 7) !== 'select-' && $type != 'ajax_select') break;
344
+				if (substr($type, 0, 7) !== 'select-' && $type != 'ajax_select')
345
+				{
346
+					break;
347
+				}
320 348
 				// fall-through for all select-* widgets
321 349
 			case 'select':
322 350
 				$widget->attrs['multiple'] = $field['rows'] > 1;
@@ -377,7 +405,10 @@  discard block
 block discarded – undo
377 405
 		$all_readonly = $this->is_readonly($cname, $form_name);
378 406
 		$value_in = self::get_array($content, $form_name);
379 407
 		// if we have no id / use self::GLOBAL_ID, we have to set $value_in in global namespace for regular widgets validation to find
380
-		if (!$this->id) $content = array_merge($content, $value_in);
408
+		if (!$this->id)
409
+		{
410
+			$content = array_merge($content, $value_in);
411
+		}
381 412
 		//error_log(__METHOD__."($cname, ...) form_name=$form_name, use-private={$this->attrs['use-private']}, value_in=".array2string($value_in));
382 413
 		$customfields =& $this->getElementAttribute(self::GLOBAL_VALS, 'customfields');
383 414
 		if(is_array($value_in))
@@ -402,15 +433,24 @@  discard block
 block discarded – undo
402 433
 				// run validation method of widget implementing this custom field
403 434
 				$widget = $this->_widget($fname, $field_settings);
404 435
 				// widget has no validate method, eg. is only displaying stuff --> nothing to validate
405
-				if (!method_exists($widget, 'validate')) continue;
436
+				if (!method_exists($widget, 'validate'))
437
+				{
438
+					continue;
439
+				}
406 440
 				$widget->validate($form_name != self::GLOBAL_ID ? $form_name : $cname, $expand, $content, $validated);
407 441
 				$field_name = $this->id[0] == self::$prefix && $customfields[substr($this->id,1)] ? $this->id : self::form_name($form_name != self::GLOBAL_ID ? $form_name : $cname, $field);
408 442
 				$valid =& self::get_array($validated, $field_name, true);
409 443
 
410
-				if (is_array($valid)) $valid = implode(',', $valid);
444
+				if (is_array($valid))
445
+				{
446
+					$valid = implode(',', $valid);
447
+				}
411 448
 				// NULL is valid for most fields, but not custom fields due to backend handling
412 449
 				// See so_sql_cf->save()
413
-				if (is_null($valid)) $valid = false;
450
+				if (is_null($valid))
451
+				{
452
+					$valid = false;
453
+				}
414 454
 				//error_log(__METHOD__."() $field_name: ".array2string($value).' --> '.array2string($valid));
415 455
 			}
416 456
 		}
@@ -418,7 +458,10 @@  discard block
 block discarded – undo
418 458
 		{
419 459
 			// Transformation doesn't handle validation
420 460
 			$valid =& self::get_array($validated, $this->id ? $form_name : $field, true);
421
-			if (true) $valid = $value_in;
461
+			if (true)
462
+			{
463
+				$valid = $value_in;
464
+			}
422 465
 			//error_log(__METHOD__."() $form_name $field: ".array2string($value).' --> '.array2string($value));
423 466
 		}
424 467
 	}
Please login to merge, or discard this patch.