Completed
Push — 14.2 ( d71938...419162 )
by Klaus
49:07 queued 19:00
created
etemplate/inc/class.etemplate_widget_url.inc.php 2 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -52,7 +52,6 @@
 block discarded – undo
52 52
 	 * @param array $expand values for keys 'c', 'row', 'c_', 'row_', 'cont'
53 53
 	 * @param array $content
54 54
 	 * @param array &$validated=array() validated content
55
-	 * @param array $expand=array values for keys 'c', 'row', 'c_', 'row_', 'cont'
56 55
 	 */
57 56
 	public function validate($cname, array $expand, array $content, &$validated=array())
58 57
 	{
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 	 * @param array &$validated=array() validated content
55 55
 	 * @param array $expand=array values for keys 'c', 'row', 'c_', 'row_', 'cont'
56 56
 	 */
57
-	public function validate($cname, array $expand, array $content, &$validated=array())
57
+	public function validate($cname, array $expand, array $content, &$validated = array())
58 58
 	{
59 59
 		$form_name = self::form_name($cname, $this->id, $expand);
60 60
 
@@ -64,12 +64,12 @@  discard block
 block discarded – undo
64 64
 
65 65
 			if ((string)$value === '' && $this->attrs['needed'])
66 66
 			{
67
-				self::set_validation_error($form_name,lang('Field must not be empty !!!'),'');
67
+				self::set_validation_error($form_name, lang('Field must not be empty !!!'), '');
68 68
 				return;
69 69
 			}
70 70
 			elseif ((string)$value != '' && !isset($this->attrs['preg']))
71 71
 			{
72
-				switch($this->type)
72
+				switch ($this->type)
73 73
 				{
74 74
 					case 'url':
75 75
 						// if no protocol given eg. "www.egroupware.org" prepend "http://" for validation
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 						}
80 80
 						$url_valid = filter_var($value, FILTER_VALIDATE_URL) ||
81 81
 							// Remove intl chars & check again, but if it passes we'll keep the original
82
-							filter_var(preg_replace('/[^[:print:]]/','',$value), FILTER_VALIDATE_URL);
82
+							filter_var(preg_replace('/[^[:print:]]/', '', $value), FILTER_VALIDATE_URL);
83 83
 						//error_log(__METHOD__."() filter_var(value=".array2string($value).", FILTER_VALIDATE_URL)=".array2string(filter_var($value, FILTER_VALIDATE_URL))." --> url_valid=".array2string($url_valid));
84 84
 						// remove http:// validation prefix again
85 85
 						if ($missing_protocol)
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 						}
89 89
 						if (!$url_valid)
90 90
 						{
91
-							self::set_validation_error($form_name,lang("'%1' has an invalid format !!!",$value),'');
91
+							self::set_validation_error($form_name, lang("'%1' has an invalid format !!!", $value), '');
92 92
 							return;
93 93
 						}
94 94
 						break;
@@ -98,19 +98,19 @@  discard block
 block discarded – undo
98 98
 				}
99 99
 			}
100 100
 
101
-			$valid =& self::get_array($validated, $form_name, true);
101
+			$valid = & self::get_array($validated, $form_name, true);
102 102
 
103
-			if ((int) $this->attrs['maxlength'] > 0 && strlen($value) > (int) $this->attrs['maxlength'])
103
+			if ((int)$this->attrs['maxlength'] > 0 && strlen($value) > (int)$this->attrs['maxlength'])
104 104
 			{
105
-				$value = substr($value,0,(int) $this->attrs['maxlength']);
105
+				$value = substr($value, 0, (int)$this->attrs['maxlength']);
106 106
 			}
107
-			if ($this->attrs['preg'] && !preg_match($this->attrs['preg'],$value))
107
+			if ($this->attrs['preg'] && !preg_match($this->attrs['preg'], $value))
108 108
 			{
109
-				switch($this->type)
109
+				switch ($this->type)
110 110
 				{
111 111
 					default:
112 112
 						//error_log("preg_match('{$this->attrs['preg']}', '$value')=".array2string(preg_match($this->attrs['preg'], $value)));
113
-						self::set_validation_error($form_name,lang("'%1' has an invalid format !!!",$value)/*." !preg_match('$this->attrs[preg]', '$value')"*/,'');
113
+						self::set_validation_error($form_name, lang("'%1' has an invalid format !!!", $value)/*." !preg_match('$this->attrs[preg]', '$value')"*/, '');
114 114
 						break;
115 115
 				}
116 116
 			}
Please login to merge, or discard this patch.
etemplate/inc/class.etemplate_widget_vfs.inc.php 4 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -230,6 +230,7 @@
 block discarded – undo
230 230
 	* If the entry is not yet created, the file information is stored into the widget's value.
231 231
 	* When the form is submitted, the information for all files uploaded is available in the returned
232 232
 	* $content array and the application should deal with the file.
233
+	* @return string
233 234
 	*/
234 235
 	public static function store_file($path, $file)
235 236
 	{
Please login to merge, or discard this patch.
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -224,13 +224,13 @@
 block discarded – undo
224 224
 	}
225 225
 
226 226
 	/**
227
-	* Ajax callback to receive an incoming file
228
-	*
229
-	* The incoming file is automatically placed into the appropriate VFS location.
230
-	* If the entry is not yet created, the file information is stored into the widget's value.
231
-	* When the form is submitted, the information for all files uploaded is available in the returned
232
-	* $content array and the application should deal with the file.
233
-	*/
227
+	 * Ajax callback to receive an incoming file
228
+	 *
229
+	 * The incoming file is automatically placed into the appropriate VFS location.
230
+	 * If the entry is not yet created, the file information is stored into the widget's value.
231
+	 * When the form is submitted, the information for all files uploaded is available in the returned
232
+	 * $content array and the application should deal with the file.
233
+	 */
234 234
 	public static function store_file($path, $file)
235 235
 	{
236 236
 		$name = $_REQUEST['widget_id'];
Please login to merge, or discard this patch.
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -21,8 +21,8 @@  discard block
 block discarded – undo
21 21
 	// Legacy option for vfs-upload
22 22
 	protected $legacy_options = "mime";
23 23
 
24
-	public function __construct($xml='') {
25
-		if($xml) parent::__construct($xml);
24
+	public function __construct($xml = '') {
25
+		if ($xml) parent::__construct($xml);
26 26
 	}
27 27
 
28 28
 	/**
@@ -31,38 +31,38 @@  discard block
 block discarded – undo
31 31
 	 */
32 32
 	public function beforeSendToClient($cname, $expand = array())
33 33
 	{
34
-		if($this->type == 'vfs-upload')
34
+		if ($this->type == 'vfs-upload')
35 35
 		{
36 36
 			$form_name = self::form_name($cname, $this->id, $expand ? $expand : array('cont'=>self::$request->content));
37 37
 
38 38
 			// ID maps to path - check there for any existing files
39
-			list($app,$id,$relpath) = explode(':',$this->id,3);
40
-			if($app && $id)
39
+			list($app, $id, $relpath) = explode(':', $this->id, 3);
40
+			if ($app && $id)
41 41
 			{
42
-				if(!is_numeric($id))
42
+				if (!is_numeric($id))
43 43
 				{
44
-					$_id = self::expand_name($id,0,0,0,0,self::$request->content);
45
-					if($_id != $id)
44
+					$_id = self::expand_name($id, 0, 0, 0, 0, self::$request->content);
45
+					if ($_id != $id)
46 46
 					{
47 47
 						$id = $_id;
48 48
 						$form_name = "$app:$id:$relpath";
49 49
 					}
50 50
 				}
51
-				$value =& self::get_array(self::$request->content, $form_name, true);
52
-				$path = egw_link::vfs_path($app,$id,'',true);
51
+				$value = & self::get_array(self::$request->content, $form_name, true);
52
+				$path = egw_link::vfs_path($app, $id, '', true);
53 53
 				if (!empty($relpath)) $path .= '/'.$relpath;
54 54
 
55 55
 				if (true) $value = array();
56 56
 
57 57
 				// Single file, already existing
58
-				if (substr($path,-1) != '/' && egw_vfs::file_exists($path) && !egw_vfs::is_dir($path))
58
+				if (substr($path, -1) != '/' && egw_vfs::file_exists($path) && !egw_vfs::is_dir($path))
59 59
 				{
60 60
 					$value = $path;
61 61
 				}
62 62
 				else if (substr($path, -1) == '/' && egw_vfs::is_dir($path))
63 63
 				{
64 64
 					$value = egw_vfs::scandir($path);
65
-					foreach($value as &$file)
65
+					foreach ($value as &$file)
66 66
 					{
67 67
 						$file = egw_vfs::stat("$path$file");
68 68
 					}
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 	public static function ajax_upload()
75 75
 	{
76 76
 		parent::ajax_upload();
77
-		foreach($_FILES as $file)
77
+		foreach ($_FILES as $file)
78 78
 		{
79 79
 			self::store_file($field, $file);
80 80
 		}
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 	{
88 88
 		$request_id = urldecode($_REQUEST['request_id']);
89 89
 		$widget_id = $_REQUEST['widget_id'];
90
-		if(!self::$request = etemplate_request::read($request_id))
90
+		if (!self::$request = etemplate_request::read($request_id))
91 91
 		{
92 92
 			$error = lang("Could not read session");
93 93
 		}
@@ -147,10 +147,10 @@  discard block
 block discarded – undo
147 147
 	static function fix_html_dragins($app, $id, array $links, &$html)
148 148
 	{
149 149
 		$replace = $remove_dir = array();
150
-		foreach($links as $link)
150
+		foreach ($links as $link)
151 151
 		{
152 152
 			$matches = null;
153
-			if (is_array($link) && preg_match('|^'.preg_quote(egw_vfs::PREFIX,'|').'('.preg_quote(self::get_temp_dir($app, ''), '|').'[^/]+)/|', $link['id']['tmp_name'], $matches))
153
+			if (is_array($link) && preg_match('|^'.preg_quote(egw_vfs::PREFIX, '|').'('.preg_quote(self::get_temp_dir($app, ''), '|').'[^/]+)/|', $link['id']['tmp_name'], $matches))
154 154
 			{
155 155
 				$replace[substr($link['id']['tmp_name'], strlen(egw_vfs::PREFIX))] =
156 156
 					egw_link::vfs_path($app, $id, egw_vfs::basename($link['id']['tmp_name']), true);
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 		{
163 163
 			$html = strtr($old = $html, $replace);
164 164
 			// remove all dirs
165
-			foreach($remove_dir as $dir)
165
+			foreach ($remove_dir as $dir)
166 166
 			{
167 167
 				egw_vfs::remove($dir);
168 168
 			}
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
 	 * @param string $postfix =null default random id
178 178
 	 * @return string vfs path
179 179
 	 */
180
-	static function get_temp_dir($app, $postfix=null)
180
+	static function get_temp_dir($app, $postfix = null)
181 181
 	{
182 182
 		if (!isset($postfix)) $postfix = md5(time().session_id());
183 183
 
@@ -197,15 +197,15 @@  discard block
 block discarded – undo
197 197
 		$name = $path;
198 198
 
199 199
 		// Find real path
200
-		if($path[0] != '/')
200
+		if ($path[0] != '/')
201 201
 		{
202 202
 			$path = self::get_vfs_path($path);
203 203
 		}
204 204
 		$filename = $file['name'];
205
-		if (substr($path,-1) != '/')
205
+		if (substr($path, -1) != '/')
206 206
 		{
207 207
 			// add extension to path
208
-			$parts = explode('.',$filename);
208
+			$parts = explode('.', $filename);
209 209
 			if (($extension = array_pop($parts)) && mime_magic::ext2mime($extension))       // really an extension --> add it to path
210 210
 			{
211 211
 				$path .= '.'.$extension;
@@ -215,14 +215,14 @@  discard block
 block discarded – undo
215 215
 		{
216 216
 			$path .= egw_vfs::encodePathComponent($filename);
217 217
 		}
218
-		if (!egw_vfs::file_exists($dir = egw_vfs::dirname($path)) && !egw_vfs::mkdir($dir,null,STREAM_MKDIR_RECURSIVE))
218
+		if (!egw_vfs::file_exists($dir = egw_vfs::dirname($path)) && !egw_vfs::mkdir($dir, null, STREAM_MKDIR_RECURSIVE))
219 219
 		{
220
-			self::set_validation_error($name,lang('Error create parent directory %1!',egw_vfs::decodePath($dir)));
220
+			self::set_validation_error($name, lang('Error create parent directory %1!', egw_vfs::decodePath($dir)));
221 221
 			return false;
222 222
 		}
223
-		if (!copy($file['tmp_name'],egw_vfs::PREFIX.$path))
223
+		if (!copy($file['tmp_name'], egw_vfs::PREFIX.$path))
224 224
 		{
225
-			self::set_validation_error($name,lang('Error copying uploaded file to vfs!'));
225
+			self::set_validation_error($name, lang('Error copying uploaded file to vfs!'));
226 226
 			return false;
227 227
 		}
228 228
 
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 	 * @param array $content
242 242
 	 * @param array &$validated=array() validated content
243 243
 	 */
244
-	public function validate($cname, array $expand, array $content, &$validated=array())
244
+	public function validate($cname, array $expand, array $content, &$validated = array())
245 245
 	{
246 246
 		// do not validate, as it would overwrite preserved values with null!
247 247
 		if (in_array($this->type, array('vfs-size', 'vfs-uid', 'vfs-gid', 'vfs', 'vfs-mime')))
@@ -250,12 +250,12 @@  discard block
 block discarded – undo
250 250
 		}
251 251
 		$form_name = self::form_name($cname, $this->id, $expand);
252 252
 		$value = $value_in = self::get_array($content, $form_name);
253
-		$valid =& self::get_array($validated, $form_name, true);
253
+		$valid = & self::get_array($validated, $form_name, true);
254 254
 
255
-		switch($this->type)
255
+		switch ($this->type)
256 256
 		{
257 257
 			case 'vfs-upload':
258
-				if(!is_array($value)) $value = array();
258
+				if (!is_array($value)) $value = array();
259 259
 				/* Check & skip files that made it asyncronously
260 260
 				list($app,$id,$relpath) = explode(':',$this->id,3);
261 261
 		//...
@@ -274,16 +274,16 @@  discard block
 block discarded – undo
274 274
 	 */
275 275
 	public static function get_vfs_path($path)
276 276
 	{
277
-		list($app,$id,$relpath) = explode(':',$path,3);
277
+		list($app, $id, $relpath) = explode(':', $path, 3);
278 278
 		if (empty($id) || $id == 'undefined')
279 279
 		{
280
-			static $tmppath = array();      // static var, so all vfs-uploads get created in the same temporary dir
281
-			if (!isset($tmppath[$app])) $tmppath[$app] = self::get_temp_dir ($app);
280
+			static $tmppath = array(); // static var, so all vfs-uploads get created in the same temporary dir
281
+			if (!isset($tmppath[$app])) $tmppath[$app] = self::get_temp_dir($app);
282 282
 			$path = $tmppath[$app];
283 283
 		}
284 284
 		else
285 285
 		{
286
-			$path = egw_link::vfs_path($app,$id,'',true);
286
+			$path = egw_link::vfs_path($app, $id, '', true);
287 287
 		}
288 288
 		if (!empty($relpath)) $path .= '/'.$relpath;
289 289
 		return $path;
Please login to merge, or discard this patch.
Braces   +42 added lines, -11 removed lines patch added patch discarded remove patch
@@ -21,8 +21,12 @@  discard block
 block discarded – undo
21 21
 	// Legacy option for vfs-upload
22 22
 	protected $legacy_options = "mime";
23 23
 
24
-	public function __construct($xml='') {
25
-		if($xml) parent::__construct($xml);
24
+	public function __construct($xml='')
25
+	{
26
+		if($xml)
27
+		{
28
+			parent::__construct($xml);
29
+		}
26 30
 	}
27 31
 
28 32
 	/**
@@ -50,9 +54,15 @@  discard block
 block discarded – undo
50 54
 				}
51 55
 				$value =& self::get_array(self::$request->content, $form_name, true);
52 56
 				$path = egw_link::vfs_path($app,$id,'',true);
53
-				if (!empty($relpath)) $path .= '/'.$relpath;
57
+				if (!empty($relpath))
58
+				{
59
+					$path .= '/'.$relpath;
60
+				}
54 61
 
55
-				if (true) $value = array();
62
+				if (true)
63
+				{
64
+					$value = array();
65
+				}
56 66
 
57 67
 				// Single file, already existing
58 68
 				if (substr($path,-1) != '/' && egw_vfs::file_exists($path) && !egw_vfs::is_dir($path))
@@ -155,7 +165,10 @@  discard block
 block discarded – undo
155 165
 				$replace[substr($link['id']['tmp_name'], strlen(egw_vfs::PREFIX))] =
156 166
 					egw_link::vfs_path($app, $id, egw_vfs::basename($link['id']['tmp_name']), true);
157 167
 
158
-				if (!in_array($matches[1], $remove_dir)) $remove_dir[] = $matches[1];
168
+				if (!in_array($matches[1], $remove_dir))
169
+				{
170
+					$remove_dir[] = $matches[1];
171
+				}
159 172
 			}
160 173
 		}
161 174
 		if ($replace)
@@ -179,7 +192,10 @@  discard block
 block discarded – undo
179 192
 	 */
180 193
 	static function get_temp_dir($app, $postfix=null)
181 194
 	{
182
-		if (!isset($postfix)) $postfix = md5(time().session_id());
195
+		if (!isset($postfix))
196
+		{
197
+			$postfix = md5(time().session_id());
198
+		}
183 199
 
184 200
 		return '/home/'.$GLOBALS['egw_info']['user']['account_lid'].'/.tmp/'.$app.'_'.$postfix;
185 201
 	}
@@ -206,10 +222,13 @@  discard block
 block discarded – undo
206 222
 		{
207 223
 			// add extension to path
208 224
 			$parts = explode('.',$filename);
209
-			if (($extension = array_pop($parts)) && mime_magic::ext2mime($extension))       // really an extension --> add it to path
225
+			if (($extension = array_pop($parts)) && mime_magic::ext2mime($extension))
226
+			{
227
+				// really an extension --> add it to path
210 228
 			{
211 229
 				$path .= '.'.$extension;
212 230
 			}
231
+			}
213 232
 		}
214 233
 		else    // multiple upload with dir given (trailing slash)
215 234
 		{
@@ -255,7 +274,10 @@  discard block
 block discarded – undo
255 274
 		switch($this->type)
256 275
 		{
257 276
 			case 'vfs-upload':
258
-				if(!is_array($value)) $value = array();
277
+				if(!is_array($value))
278
+				{
279
+					$value = array();
280
+				}
259 281
 				/* Check & skip files that made it asyncronously
260 282
 				list($app,$id,$relpath) = explode(':',$this->id,3);
261 283
 		//...
@@ -266,7 +288,10 @@  discard block
 block discarded – undo
266 288
 				parent::validate($cname, $content, $validated);
267 289
 				break;
268 290
 		}
269
-		if (true) $valid = $value;
291
+		if (true)
292
+		{
293
+			$valid = $value;
294
+		}
270 295
 	}
271 296
 
272 297
 	/**
@@ -278,14 +303,20 @@  discard block
 block discarded – undo
278 303
 		if (empty($id) || $id == 'undefined')
279 304
 		{
280 305
 			static $tmppath = array();      // static var, so all vfs-uploads get created in the same temporary dir
281
-			if (!isset($tmppath[$app])) $tmppath[$app] = self::get_temp_dir ($app);
306
+			if (!isset($tmppath[$app]))
307
+			{
308
+				$tmppath[$app] = self::get_temp_dir ($app);
309
+			}
282 310
 			$path = $tmppath[$app];
283 311
 		}
284 312
 		else
285 313
 		{
286 314
 			$path = egw_link::vfs_path($app,$id,'',true);
287 315
 		}
288
-		if (!empty($relpath)) $path .= '/'.$relpath;
316
+		if (!empty($relpath))
317
+		{
318
+			$path .= '/'.$relpath;
319
+		}
289 320
 		return $path;
290 321
 	}
291 322
 }
Please login to merge, or discard this patch.
etemplate/inc/class.historylog_widget.inc.php 3 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -58,6 +58,7 @@
 block discarded – undo
58 58
 	 *
59 59
 	 * @param mixed &$value value / existing content, can be modified
60 60
 	 * @param array &$cell array with the widget, can be modified for ui-independent widgets
61
+	 * @param etemplate $tmpl
61 62
 	 * @return boolean true if extra label is allowed, false otherwise
62 63
 	 */
63 64
 	private function pre_process_helper(&$value, &$cell, $tmpl)
Please login to merge, or discard this patch.
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -70,24 +70,24 @@  discard block
 block discarded – undo
70 70
 		//echo $value.'/'.$cell['size']; _debug_array(self::$status_widgets);
71 71
 		$type = isset(self::$status_widgets[$cell['size']]) ? self::$status_widgets[$cell['size']] : 'label';
72 72
 		$options = '';
73
-		if (!is_array($type) && strpos($type,':') !== false)
73
+		if (!is_array($type) && strpos($type, ':') !== false)
74 74
 		{
75
-			list($type,$options) = explode(':',$type,2);
75
+			list($type, $options) = explode(':', $type, 2);
76 76
 		}
77 77
 		// For all select-cats, show missing entries as IDs
78
-		if($type == 'select-cat')
78
+		if ($type == 'select-cat')
79 79
 		{
80
-			list($rows,$type1,$type2,$type3,$type4,$type5,$type6) = explode(',',$options);
80
+			list($rows, $type1, $type2, $type3, $type4, $type5, $type6) = explode(',', $options);
81 81
 			$type6 = 2;
82
-			$options = implode(',',array($rows,$type1,$type2,$type3,$type4,$type5,$type6));
82
+			$options = implode(',', array($rows, $type1, $type2, $type3, $type4, $type5, $type6));
83 83
 		}
84
-		$cell = boetemplate::empty_cell($type,$cell['name'],array('readonly' => true,'size' => $options));
84
+		$cell = boetemplate::empty_cell($type, $cell['name'], array('readonly' => true, 'size' => $options));
85 85
 		// display unsupported iCal properties, which have multiple values or attributes, or multiple components
86 86
 		if ($type === 'label' && $value[1] === ':' && ($values = unserialize($value)))
87 87
 		{
88 88
 			if (isset($values['values']))
89 89
 			{
90
-				foreach((array)$values['params'] as $name => $val)
90
+				foreach ((array)$values['params'] as $name => $val)
91 91
 				{
92 92
 					$values['values'][] = $name.': '.$val;
93 93
 				}
@@ -97,28 +97,28 @@  discard block
 block discarded – undo
97 97
 		}
98 98
 		elseif (is_array($type))
99 99
 		{
100
-			list($t) = explode(':',$type[0]);
101
-			if (isset($type[0]) &&	// numeric indexed array --> multiple values of 1:N releation
100
+			list($t) = explode(':', $type[0]);
101
+			if (isset($type[0]) && // numeric indexed array --> multiple values of 1:N releation
102 102
 				$tmpl->widgetExists($t))
103 103
 			{
104 104
 				$cell['type'] = 'vbox';
105 105
 				$cell['size'] = '0,,0,0';
106
-				$value = explode(bo_tracking::ONE2N_SEPERATOR,$value);
107
-				foreach($type as $n => $t)
106
+				$value = explode(bo_tracking::ONE2N_SEPERATOR, $value);
107
+				foreach ($type as $n => $t)
108 108
 				{
109 109
 					$opt = '';
110
-					if(is_array($t))
110
+					if (is_array($t))
111 111
 					{
112 112
 						$sel_options = $t;
113 113
 						$t = 'select';
114 114
 					}
115 115
 					else
116 116
 					{
117
-						list($t,$opt) = explode(':',$t);
117
+						list($t, $opt) = explode(':', $t);
118 118
 					}
119
-					$child = boetemplate::empty_cell($t,$cell['name']."[$n]",array('readonly' => true,'no_lang' => true,'size' => $opt));
119
+					$child = boetemplate::empty_cell($t, $cell['name']."[$n]", array('readonly' => true, 'no_lang' => true, 'size' => $opt));
120 120
 					$child['sel_options'] = $sel_options;
121
-					boetemplate::add_child($cell,$child);
121
+					boetemplate::add_child($cell, $child);
122 122
 					unset($sel_options);
123 123
 					unset($child);
124 124
 				}
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 	 * @param etemplate $tmpl reference to the template we belong too
151 151
 	 * @return boolean true if extra label is allowed, false otherwise
152 152
 	 */
153
-	function pre_process($name,&$value,&$cell,&$readonlys,&$extension_data,$tmpl)
153
+	function pre_process($name, &$value, &$cell, &$readonlys, &$extension_data, $tmpl)
154 154
 	{
155 155
 		switch ($cell['type'])
156 156
 		{
@@ -164,30 +164,30 @@  discard block
 block discarded – undo
164 164
 		$filter = is_array($value) ? $value['filter'] : array();
165 165
 
166 166
 		$historylog = new historylog($app);
167
-		if (!$id || method_exists($historylog,'search'))
167
+		if (!$id || method_exists($historylog, 'search'))
168 168
 		{
169 169
 			$value = $id ? $historylog->search($filter ? array('history_record_id'=>$id) + $filter : $id, 'history_id', 'DESC', self::MAX_DISPLAY) : false;
170 170
 		}
171 171
 		unset($historylog);
172 172
 
173 173
 		$tpl = new etemplate;
174
-		$tpl->init('*** generated fields for historylog','','',0,'',0,0);	// make an empty template
174
+		$tpl->init('*** generated fields for historylog', '', '', 0, '', 0, 0); // make an empty template
175 175
 		// keep the editor away from the generated tmpls
176 176
 		$tpl->no_onclick = true;
177 177
 
178 178
 		// header rows
179
-		$tpl->new_cell(1,'label','Date');
180
-		$tpl->new_cell(1,'label','User');
181
-		$tpl->new_cell(1,'label','Changed');
182
-		$tpl->new_cell(1,'label','New value');
183
-		$tpl->new_cell(1,'label','Old value');
179
+		$tpl->new_cell(1, 'label', 'Date');
180
+		$tpl->new_cell(1, 'label', 'User');
181
+		$tpl->new_cell(1, 'label', 'Changed');
182
+		$tpl->new_cell(1, 'label', 'New value');
183
+		$tpl->new_cell(1, 'label', 'Old value');
184 184
 
185 185
 		$status = 'status';
186 186
 		// allow to set a diffent name for status (field-name), eg. because status is already used for something else
187 187
 		if (!empty($cell['size']) && isset($tmpl->sel_options[$cell['size']]) && is_array($value))
188 188
 		{
189 189
 			$status = $cell['size'];
190
-			foreach($value as &$row)
190
+			foreach ($value as &$row)
191 191
 			{
192 192
 				$row[$status] = $row['status'];
193 193
 			}
@@ -198,16 +198,16 @@  discard block
 block discarded – undo
198 198
 		$tmpl->sel_options[$status]['user_agent_action'] = lang('User-agent & action');
199 199
 
200 200
 		// adding custom fields automatically to status-widgets, no need for each app to do that
201
-		foreach(config::get_customfields($app,true) as $cf_name => $cf_data)
201
+		foreach (config::get_customfields($app, true) as $cf_name => $cf_data)
202 202
 		{
203 203
 			// add cf label, if not set by app
204 204
 			if (!isset($tmpl->sel_options[$status]['#'.$cf_name]))
205 205
 			{
206 206
 				$tmpl->sel_options[$status]['#'.$cf_name] = lang($cf_data['label']);
207 207
 			}
208
-			if (isset(self::$status_widgets['#'.$cf_name])) continue;	// app set a status widget --> use that
208
+			if (isset(self::$status_widgets['#'.$cf_name])) continue; // app set a status widget --> use that
209 209
 
210
-			if(!is_array($cf_data['values']) || !$cf_data['values'])
210
+			if (!is_array($cf_data['values']) || !$cf_data['values'])
211 211
 			{
212 212
 				if (isset($GLOBALS['egw_info']['apps'][$cf_data['type']]))
213 213
 				{
@@ -218,11 +218,11 @@  discard block
 block discarded – undo
218 218
 					self::$status_widgets['#'.$cf_name] = $cf_data['type'] != 'text' ? $cf_data['type'] : 'label';
219 219
 				}
220 220
 			}
221
-			elseif($cf_data['values']['@'])
221
+			elseif ($cf_data['values']['@'])
222 222
 			{
223 223
 				self::$status_widgets['#'.$cf_name] = egw_customfields::get_options_from_file($cf_data['values']['@']);
224 224
 			}
225
-			elseif(count($cf_data['values']))
225
+			elseif (count($cf_data['values']))
226 226
 			{
227 227
 				self::$status_widgets['#'.$cf_name] = $cf_data['values'];
228 228
 			}
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
 		if ($value)	// autorepeated data-row only if there is data
232 232
 		{
233 233
 			// add "labels" for unsupported iCal properties, we just remove the '##' prefix
234
-			foreach($value as &$row)
234
+			foreach ($value as &$row)
235 235
 			{
236 236
 				if ($row['status'][0] == '#' && $row['status'][1] == '#' &&
237 237
 					isset($tmpl->sel_options[$status]) && !isset($tmpl->sel_options[$status][$row['status']]))
@@ -240,32 +240,32 @@  discard block
 block discarded – undo
240 240
 				}
241 241
 			}
242 242
 
243
-			$tpl->new_cell(2,'date-time','','${row}[user_ts]',array('readonly' => true));
244
-			$tpl->new_cell(2,'select-account','','${row}[owner]',array('readonly' => true));
243
+			$tpl->new_cell(2, 'date-time', '', '${row}[user_ts]', array('readonly' => true));
244
+			$tpl->new_cell(2, 'select-account', '', '${row}[owner]', array('readonly' => true));
245 245
 
246 246
 
247 247
 			// if $sel_options[status] is set, use them and a readonly selectbox
248 248
 			if (isset($tmpl->sel_options[$status]))
249 249
 			{
250
-				$tpl->new_cell(2,'select','','${row}['.$status.']',array('readonly' => true));
250
+				$tpl->new_cell(2, 'select', '', '${row}['.$status.']', array('readonly' => true));
251 251
 			}
252 252
 			else
253 253
 			{
254
-				$tpl->new_cell(2,'label','','${row}[status]',array('no_lang' => true));
254
+				$tpl->new_cell(2, 'label', '', '${row}[status]', array('no_lang' => true));
255 255
 			}
256 256
 			// if $value[status-widgets] is set, use them together with the historylog-helper
257 257
 			// to display new_ & old_value in the specified widget, otherwise use a label
258 258
 			if (self::$status_widgets)
259 259
 			{
260
-				$tpl->new_cell(2,'historylog-helper','','${row}[new_value]',array('size' => '$row_cont[status]','no_lang' => true,'readonly' => true));
261
-				$tpl->new_cell(2,'historylog-helper','','${row}[old_value]',array('size' => '$row_cont[status]','no_lang' => true,'readonly' => true));
260
+				$tpl->new_cell(2, 'historylog-helper', '', '${row}[new_value]', array('size' => '$row_cont[status]', 'no_lang' => true, 'readonly' => true));
261
+				$tpl->new_cell(2, 'historylog-helper', '', '${row}[old_value]', array('size' => '$row_cont[status]', 'no_lang' => true, 'readonly' => true));
262 262
 			}
263 263
 			else
264 264
 			{
265
-				$tpl->new_cell(2,'label','','${row}[new_value]',array('no_lang' => true));
266
-				$tpl->new_cell(2,'label','','${row}[old_value]',array('no_lang' => true));
265
+				$tpl->new_cell(2, 'label', '', '${row}[new_value]', array('no_lang' => true));
266
+				$tpl->new_cell(2, 'label', '', '${row}[old_value]', array('no_lang' => true));
267 267
 			}
268
-			array_unshift($value,false);	// addjust index to start with 1, as we have a header-row
268
+			array_unshift($value, false); // addjust index to start with 1, as we have a header-row
269 269
 		}
270 270
 		$tpl->data[0] = array(
271 271
 			'c1' => 'th',
@@ -278,6 +278,6 @@  discard block
 block discarded – undo
278 278
 		$cell['name'] = $tpl->name;
279 279
 		$cell['obj'] = &$tpl;
280 280
 
281
-		return True;	// extra Label is ok
281
+		return True; // extra Label is ok
282 282
 	}
283 283
 }
Please login to merge, or discard this patch.
Braces   +13 added lines, -3 removed lines patch added patch discarded remove patch
@@ -134,7 +134,10 @@  discard block
 block discarded – undo
134 134
 		{
135 135
 			$value = egw_time::server2user($value);
136 136
 		}
137
-		if ($cell['type'] == 'label') $cell['no_lang'] = 'true';
137
+		if ($cell['type'] == 'label')
138
+		{
139
+			$cell['no_lang'] = 'true';
140
+		}
138 141
 
139 142
 		return true;
140 143
 	}
@@ -205,7 +208,11 @@  discard block
 block discarded – undo
205 208
 			{
206 209
 				$tmpl->sel_options[$status]['#'.$cf_name] = lang($cf_data['label']);
207 210
 			}
208
-			if (isset(self::$status_widgets['#'.$cf_name])) continue;	// app set a status widget --> use that
211
+			if (isset(self::$status_widgets['#'.$cf_name]))
212
+			{
213
+				continue;
214
+			}
215
+			// app set a status widget --> use that
209 216
 
210 217
 			if(!is_array($cf_data['values']) || !$cf_data['values'])
211 218
 			{
@@ -228,7 +235,9 @@  discard block
 block discarded – undo
228 235
 			}
229 236
 		}
230 237
 
231
-		if ($value)	// autorepeated data-row only if there is data
238
+		if ($value)
239
+		{
240
+			// autorepeated data-row only if there is data
232 241
 		{
233 242
 			// add "labels" for unsupported iCal properties, we just remove the '##' prefix
234 243
 			foreach($value as &$row)
@@ -237,6 +246,7 @@  discard block
 block discarded – undo
237 246
 					isset($tmpl->sel_options[$status]) && !isset($tmpl->sel_options[$status][$row['status']]))
238 247
 				{
239 248
 					$tmpl->sel_options[$status][$row['status']] = substr($row['status'], 2);
249
+		}
240 250
 				}
241 251
 			}
242 252
 
Please login to merge, or discard this patch.
etemplate/inc/class.link_widget.inc.php 5 patches
Doc Comments   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 	 * @param array &$readonlys names of widgets as key, to be made readonly
116 116
 	 * @param mixed &$extension_data data the extension can store persisten between pre- and post-process
117 117
 	 * @param object &$tmpl reference to the template we belong too
118
-	 * @return boolean true if extra label is allowed, false otherwise
118
+	 * @return null|boolean true if extra label is allowed, false otherwise
119 119
 	 */
120 120
 	function pre_process($name,&$value,&$cell,&$readonlys,&$extension_data,&$tmpl)
121 121
 	{
@@ -706,6 +706,7 @@  discard block
 block discarded – undo
706 706
 
707 707
 	/**
708 708
 	*	Get sub-types for the current application
709
+	* @param etemplate $tpl
709 710
 	*/
710 711
 	private static function get_sub_types($cell, &$value, &$tpl) {
711 712
 		// Get sub-types
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -705,8 +705,8 @@
 block discarded – undo
705 705
 	}
706 706
 
707 707
 	/**
708
-	*	Get sub-types for the current application
709
-	*/
708
+	 *	Get sub-types for the current application
709
+	 */
710 710
 	private static function get_sub_types($cell, &$value, &$tpl) {
711 711
 		// Get sub-types
712 712
 		if($value['options-app']) {
Please login to merge, or discard this patch.
Switch Indentation   +260 added lines, -260 removed lines patch added patch discarded remove patch
@@ -147,331 +147,331 @@
 block discarded – undo
147 147
 		}
148 148
 		switch ($cell['type'])
149 149
 		{
150
-		case 'link':
151
-			$cell['readonly'] = True;	// set it readonly to NOT call our post_process function
152
-			$extension_data = null;
153
-			$cell['no_lang'] = 1;
154
-			$link = $target = $popup = '';
155
-			if (!is_array($value) && $value && isset($GLOBALS['egw_info']['apps'][$cell['size']]))
156
-			{
157
-				$value = array(
158
-					'id' => $value,
159
-					'app' => $cell['size'],
160
-				);
161
-				$cell['size'] = '';
162
-			}
163
-			if ($value['app'] && $value['id'])
164
-			{
165
-				$view = egw_link::view($value['app'],$value['id']);
166
-				$link = $view['menuaction']; unset($view['menuaction']);
167
-				foreach($view as $var => $val)
150
+			case 'link':
151
+				$cell['readonly'] = True;	// set it readonly to NOT call our post_process function
152
+				$extension_data = null;
153
+				$cell['no_lang'] = 1;
154
+				$link = $target = $popup = '';
155
+				if (!is_array($value) && $value && isset($GLOBALS['egw_info']['apps'][$cell['size']]))
168 156
 				{
169
-					$link .= '&'.$var.'='.$val;
157
+					$value = array(
158
+						'id' => $value,
159
+						'app' => $cell['size'],
160
+					);
161
+					$cell['size'] = '';
170 162
 				}
171
-				if (isset($value['extra_args']))
163
+				if ($value['app'] && $value['id'])
172 164
 				{
173
-					foreach($value['extra_args'] as $var => $val)
165
+					$view = egw_link::view($value['app'],$value['id']);
166
+					$link = $view['menuaction']; unset($view['menuaction']);
167
+					foreach($view as $var => $val)
174 168
 					{
175 169
 						$link .= '&'.$var.'='.$val;
176 170
 					}
171
+					if (isset($value['extra_args']))
172
+					{
173
+						foreach($value['extra_args'] as $var => $val)
174
+						{
175
+							$link .= '&'.$var.'='.$val;
176
+						}
177
+					}
178
+					if (!($popup = egw_link::is_popup($value['app'],'view')) &&
179
+						etemplate::$request->output_mode == 2)	// we are in a popup
180
+					{
181
+						$target = '_blank';
182
+					}
183
+					if (!$cell['help'])
184
+					{
185
+						$cell['help'] = $value['help'];
186
+						$cell['no_lang'] = 2;
187
+					}
177 188
 				}
178
-				if (!($popup = egw_link::is_popup($value['app'],'view')) &&
179
-					etemplate::$request->output_mode == 2)	// we are in a popup
189
+				elseif (!$value['title'])
180 190
 				{
181
-					$target = '_blank';
191
+					$cell = $tmpl->empty_cell();
192
+					$cell['readonly'] = True;	// set it readonly to NOT call our post_process function
193
+					$extension_data = null;
194
+					return;
182 195
 				}
183
-				if (!$cell['help'])
196
+				$cell['type'] = 'label';
197
+				//  size: [b[old]][i[talic]],[link],[activate_links],[label_for],[link_target],[link_popup_size],[link_title]
198
+				list($cell['size']) = explode(',',$cell['size']);
199
+				// Pass link through framework's handler
200
+				if(!$popup) $link = str_replace(',','%2C',egw::link('/index.php?menuaction='.$link,false,$value['app']));
201
+				$cell['size'] .= ','.$link.',,,'.$target.','.$popup.','.$value['extra_title'];
202
+				$value = $value['title'] ? $value['title'] : egw_link::title($value['app'],$value['id']);
203
+				return true;
204
+
205
+			case 'link-string':
206
+				$str = '';
207
+				if ($value && !is_array($value) && $cell['size'])
184 208
 				{
185
-					$cell['help'] = $value['help'];
186
-					$cell['no_lang'] = 2;
209
+					$value = array('to_id' => $value);
210
+					list($value['to_app'],$value['only_app']) = explode(',',$cell['size']);
187 211
 				}
188
-			}
189
-			elseif (!$value['title'])
190
-			{
191
-				$cell = $tmpl->empty_cell();
192
-				$cell['readonly'] = True;	// set it readonly to NOT call our post_process function
193
-				$extension_data = null;
194
-				return;
195
-			}
196
-			$cell['type'] = 'label';
197
-			//  size: [b[old]][i[talic]],[link],[activate_links],[label_for],[link_target],[link_popup_size],[link_title]
198
-			list($cell['size']) = explode(',',$cell['size']);
199
-			// Pass link through framework's handler
200
-			if(!$popup) $link = str_replace(',','%2C',egw::link('/index.php?menuaction='.$link,false,$value['app']));
201
-			$cell['size'] .= ','.$link.',,,'.$target.','.$popup.','.$value['extra_title'];
202
-			$value = $value['title'] ? $value['title'] : egw_link::title($value['app'],$value['id']);
203
-			return true;
204
-
205
-		case 'link-string':
206
-			$str = '';
207
-			if ($value && !is_array($value) && $cell['size'])
208
-			{
209
-				$value = array('to_id' => $value);
210
-				list($value['to_app'],$value['only_app']) = explode(',',$cell['size']);
211
-			}
212
-			if ($value['to_id'] && $value['to_app'])
213
-			{
214
-				$value = egw_link::get_links($value['to_app'], $value['to_id'], $only_app = $value['only_app'],
215
-					'link_lastmod DESC', true, $value['show_deleted'], self::LIMIT_LINKS);
216
-				if ($only_app)
212
+				if ($value['to_id'] && $value['to_app'])
217 213
 				{
218
-					foreach($value as $key => $id)
214
+					$value = egw_link::get_links($value['to_app'], $value['to_id'], $only_app = $value['only_app'],
215
+						'link_lastmod DESC', true, $value['show_deleted'], self::LIMIT_LINKS);
216
+					if ($only_app)
219 217
 					{
220
-						$value[$key] = array(
221
-							'id'  => $id,
222
-							'app' => $only_app,
223
-						);
218
+						foreach($value as $key => $id)
219
+						{
220
+							$value[$key] = array(
221
+								'id'  => $id,
222
+								'app' => $only_app,
223
+							);
224
+						}
224 225
 					}
225 226
 				}
226
-			}
227
-			if (is_array($value))
228
-			{
229
-				foreach ($value as $link)
227
+				if (is_array($value))
230 228
 				{
231
-					$str .= ($str !== '' ? ', ' : '') . self::link2a_href($link,$help);
229
+					foreach ($value as $link)
230
+					{
231
+						$str .= ($str !== '' ? ', ' : '') . self::link2a_href($link,$help);
232
+					}
232 233
 				}
233
-			}
234
-			$cell['type'] = 'html';
235
-			$cell['readonly'] = True;	// set it readonly to NOT call our post_process function
236
-			$extension_data = null;
237
-			$value = $str;
238
-			return True;
234
+				$cell['type'] = 'html';
235
+				$cell['readonly'] = True;	// set it readonly to NOT call our post_process function
236
+				$extension_data = null;
237
+				$value = $str;
238
+				return True;
239 239
 
240
-		case 'link-add':
241
-			$apps = egw_link::app_list($type == 'link-add' ? 'add_app' : 'query');
242
-			if (!$apps || !$value['to_id'] || is_array($value['to_id']))	// cant do an add without apps or already created entry
243
-			{
244
-				$cell = $tmpl->empty_cell();
245
-				return;
246
-			}
247
-			asort($apps);	// sort them alphabetic
248
-			$value['options-add_app'] = array();
249
-			foreach($apps as $app => $label)
250
-			{
251
-				$link = $GLOBALS['egw']->link('/index.php',egw_link::add($app,$value['to_app'],$value['to_id'])+
252
-					(is_array($value['extra']) ? $value['extra'] : array()));
253
-				if (($popup = egw_link::is_popup($app,'add')))
240
+			case 'link-add':
241
+				$apps = egw_link::app_list($type == 'link-add' ? 'add_app' : 'query');
242
+				if (!$apps || !$value['to_id'] || is_array($value['to_id']))	// cant do an add without apps or already created entry
254 243
 				{
255
-					list($w,$h) = explode('x',$popup);
256
-					$action = "window.open('$link','_blank','width=$w,height=$h,location=no,menubar=no,toolbar=no,scrollbars=yes,status=yes');";
244
+					$cell = $tmpl->empty_cell();
245
+					return;
257 246
 				}
258
-				else
247
+				asort($apps);	// sort them alphabetic
248
+				$value['options-add_app'] = array();
249
+				foreach($apps as $app => $label)
259 250
 				{
260
-					$action = "location.href = '$link';";
251
+					$link = $GLOBALS['egw']->link('/index.php',egw_link::add($app,$value['to_app'],$value['to_id'])+
252
+						(is_array($value['extra']) ? $value['extra'] : array()));
253
+					if (($popup = egw_link::is_popup($app,'add')))
254
+					{
255
+						list($w,$h) = explode('x',$popup);
256
+						$action = "window.open('$link','_blank','width=$w,height=$h,location=no,menubar=no,toolbar=no,scrollbars=yes,status=yes');";
257
+					}
258
+					else
259
+					{
260
+						$action = "location.href = '$link';";
261
+					}
262
+					$value['options-add_app'][$action] = $label;
263
+					// modify add_app default to the action used as value
264
+					if (isset($value['add_app']) && $app == $value['add_app']) $value['add_app'] = $action;
261 265
 				}
262
-				$value['options-add_app'][$action] = $label;
263
-				// modify add_app default to the action used as value
264
-				if (isset($value['add_app']) && $app == $value['add_app']) $value['add_app'] = $action;
265
-			}
266
-			$tpl = new etemplate('etemplate.link_widget.add');
267
-			break;
266
+				$tpl = new etemplate('etemplate.link_widget.add');
267
+				break;
268 268
 
269
-		case 'link-to':
270
-			$GLOBALS['egw_info']['flags']['include_xajax'] = true;
271
-			if ($value['search_label'] && $extension_data['search_label'] != $value['search_label']) $value['search_label'] = lang($value['search_label']);
272
-			$extension_data = $value;
273
-			$tpl = new etemplate('etemplate.link_widget.to');
274
-			if ($value['link_label']) $tpl->set_cell_attribute('create','label',$value['link_label']);
275
-			if ($value['search_label']) $tpl->set_cell_attribute('search','label',$value['search_label']);
269
+			case 'link-to':
270
+				$GLOBALS['egw_info']['flags']['include_xajax'] = true;
271
+				if ($value['search_label'] && $extension_data['search_label'] != $value['search_label']) $value['search_label'] = lang($value['search_label']);
272
+				$extension_data = $value;
273
+				$tpl = new etemplate('etemplate.link_widget.to');
274
+				if ($value['link_label']) $tpl->set_cell_attribute('create','label',$value['link_label']);
275
+				if ($value['search_label']) $tpl->set_cell_attribute('search','label',$value['search_label']);
276 276
 
277
-			self::get_sub_types($cell, $value, $tpl);
277
+				self::get_sub_types($cell, $value, $tpl);
278 278
 
279
-			break;
279
+				break;
280 280
 
281
-		case 'link-list':
282
-			$app = $value['to_app'];
283
-			$id  = isset($extension_data['to_id']) ? $extension_data['to_id'] : $value['to_id'];
284
-			if ($this->debug)
285
-			{
286
-				echo "<p>link-list-widget[$name].preprocess: value="; _debug_array($value);
287
-			}
288
-			if (!isset($value['title']))
289
-			{
290
-				$value['title'] = egw_link::title($app,$id);
291
-			}
292
-			$links = egw_link::get_links($app, $id, '', 'link_lastmod DESC', true, $value['show_deleted'], self::LIMIT_LINKS);
293
-			$value['anz_links'] = count($links);
294
-			$extension_data = $value;
281
+			case 'link-list':
282
+				$app = $value['to_app'];
283
+				$id  = isset($extension_data['to_id']) ? $extension_data['to_id'] : $value['to_id'];
284
+				if ($this->debug)
285
+				{
286
+					echo "<p>link-list-widget[$name].preprocess: value="; _debug_array($value);
287
+				}
288
+				if (!isset($value['title']))
289
+				{
290
+					$value['title'] = egw_link::title($app,$id);
291
+				}
292
+				$links = egw_link::get_links($app, $id, '', 'link_lastmod DESC', true, $value['show_deleted'], self::LIMIT_LINKS);
293
+				$value['anz_links'] = count($links);
294
+				$extension_data = $value;
295 295
 
296
-			if (!count($links))
297
-			{
298
-				$cell = $tmpl->empty_cell();
299
-				$value = '';
300
-				return True;
301
-			}
302
-			$value['link_list_format'] = $GLOBALS['egw_info']['user']['preferences']['common']['link_list_format'];
303
-			$tpl = new etemplate('etemplate.link_widget.list');
304
-			for($row=$tpl->rows-1; list(,$link) = each($links); ++$row)
305
-			{
306
-				$value[$row] = $link;
307
-				$value[$row]['title'] = egw_link::title($link['app'],($link['app'] == egw_link::VFS_APPNAME&&!is_array($link['id'])?egw_vfs::decodePath($link['id']):$link['id']),$link);
308
-				if (!is_array($link['id']))
296
+				if (!count($links))
309 297
 				{
310
-					$value[$row]['view']  = egw_link::view($link['app'],$link['id'],$link);
311
-					if (!($value[$row]['popup'] = egw_link::is_popup($link['app'],'view',$link)) &&
312
-						etemplate::$request->output_mode == 2)	// we are in a popup
313
-					{
314
-						$value[$row]['target'] = '_blank';		// we create a new window as the linked page is no popup
315
-					}
298
+					$cell = $tmpl->empty_cell();
299
+					$value = '';
300
+					return True;
316 301
 				}
317
-				if ($link['app'] == egw_link::VFS_APPNAME)
302
+				$value['link_list_format'] = $GLOBALS['egw_info']['user']['preferences']['common']['link_list_format'];
303
+				$tpl = new etemplate('etemplate.link_widget.list');
304
+				for($row=$tpl->rows-1; list(,$link) = each($links); ++$row)
318 305
 				{
319
-					$value[$row]['target'] = '_blank';
320
-					$value[$row]['label'] = 'Delete';
321
-					$value[$row]['help'] = lang('Delete this file');
322
-					if ($value['link_list_format'] != 'text')
306
+					$value[$row] = $link;
307
+					$value[$row]['title'] = egw_link::title($link['app'],($link['app'] == egw_link::VFS_APPNAME&&!is_array($link['id'])?egw_vfs::decodePath($link['id']):$link['id']),$link);
308
+					if (!is_array($link['id']))
323 309
 					{
324
-						$value[$row]['title'] = preg_replace('/: ([^ ]+) /',': ',$value[$row]['title']);	// remove mime-type, it's alread in the icon
310
+						$value[$row]['view']  = egw_link::view($link['app'],$link['id'],$link);
311
+						if (!($value[$row]['popup'] = egw_link::is_popup($link['app'],'view',$link)) &&
312
+							etemplate::$request->output_mode == 2)	// we are in a popup
313
+						{
314
+							$value[$row]['target'] = '_blank';		// we create a new window as the linked page is no popup
315
+						}
325 316
 					}
326
-					$value[$row]['icon'] = egw_link::vfs_path($link['app2'],$link['id2'],$link['id'],true);
327
-				}
328
-				else
329
-				{
330
-					$value[$row]['icon'] = egw_link::get_registry($value[$row]['app'], 'icon');
331
-					$value[$row]['label'] = 'Unlink';
332
-					$value[$row]['help'] = lang('Remove this link (not the entry itself)');
333
-					if(!egw_link::is_popup($link['app'],'view') && etemplate::$request->output_mode == 2)
317
+					if ($link['app'] == egw_link::VFS_APPNAME)
334 318
 					{
335
-						// If link doesn't want a popup, make sure to open it in appropriate tab of main window
336
-						$value[$row]['view'] = "javascript:if(typeof opener.top.framework != 'undefined') {
319
+						$value[$row]['target'] = '_blank';
320
+						$value[$row]['label'] = 'Delete';
321
+						$value[$row]['help'] = lang('Delete this file');
322
+						if ($value['link_list_format'] != 'text')
323
+						{
324
+							$value[$row]['title'] = preg_replace('/: ([^ ]+) /',': ',$value[$row]['title']);	// remove mime-type, it's alread in the icon
325
+						}
326
+						$value[$row]['icon'] = egw_link::vfs_path($link['app2'],$link['id2'],$link['id'],true);
327
+					}
328
+					else
329
+					{
330
+						$value[$row]['icon'] = egw_link::get_registry($value[$row]['app'], 'icon');
331
+						$value[$row]['label'] = 'Unlink';
332
+						$value[$row]['help'] = lang('Remove this link (not the entry itself)');
333
+						if(!egw_link::is_popup($link['app'],'view') && etemplate::$request->output_mode == 2)
334
+						{
335
+							// If link doesn't want a popup, make sure to open it in appropriate tab of main window
336
+							$value[$row]['view'] = "javascript:if(typeof opener.top.framework != 'undefined') {
337 337
 							opener.top.egw_appWindowOpen('{$link['app']}','".egw::link('/index.php',$value[$row]['view'])."');
338 338
 						} else {
339 339
 							opener.open('".egw::link('/index.php',$value[$row]['view'])."','".$value[$row]['target']."');
340 340
 						}";
341
+						}
341 342
 					}
342 343
 				}
343
-			}
344
-			break;
344
+				break;
345 345
 
346
-		case 'link-entry':
347
-			if ($cell['readonly'] || $readonlys)
348
-			{
349
-				if(!is_array($value))
350
-				{
351
-					if (strpos($value,':') !== false) list($app,$value) = explode(':',$value,2);
352
-					$value = array('app' => $app ? $app : $cell['size'],'id' => $value);
353
-				}
354
-				$value = self::link2a_href($value,$help);
355
-				$cell['type'] = 'html';
356
-				$cell['readonly'] = true;
357
-				$extension_data = null;
358
-				return true;
359
-			}
360
-			$GLOBALS['egw_info']['flags']['include_xajax'] = true;
361
-			$tpl = new etemplate('etemplate.link_widget.entry');
362
-			$options = $cell['size'] ? explode(',',$cell['size']) : array();
363
-			$app = $extension_data['app'] = $options[0];
364
-			$link_type = $extension_data['link_type'];
365
-			// handle extra args for onclick like: values2url(this.form,'start,end,duration,participants,recur_type,whole_day')+'&exec[event_id]=
366
-			if ( isset($value) && is_array($value) && isset($value['extra']) )
367
-			{
368
-				//echo '<p>extra='.htmlspecialchars($value['extra'])."</p>\n";
369
-				//something like: values2url(this.form,'start,end,duration,participants,recur_type,whole_day')+'&exec[event_id]=
370
-				$on_click_string =& $tpl->get_cell_attribute('search','onclick');
371
-				$on_click_string = str_replace(');',','.$value['extra'].');',$on_click_string);
372
-				//echo htmlspecialchars($on_click_string);
373
-			}
374
-			if ($value)	// show pre-selected entry in select-box and not the search
375
-			{
376
-				if (is_array($value))
346
+			case 'link-entry':
347
+				if ($cell['readonly'] || $readonlys)
377 348
 				{
378
-					if (isset($value['current']))
349
+					if(!is_array($value))
379 350
 					{
380
-						list($app,$id) = explode(':',$value['current'], 2);
381
-						if ($app) unset($value['default_sel']);	// would overwrite $app!
351
+						if (strpos($value,':') !== false) list($app,$value) = explode(':',$value,2);
352
+						$value = array('app' => $app ? $app : $cell['size'],'id' => $value);
382 353
 					}
354
+					$value = self::link2a_href($value,$help);
355
+					$cell['type'] = 'html';
356
+					$cell['readonly'] = true;
357
+					$extension_data = null;
358
+					return true;
383 359
 				}
384
-				else
360
+				$GLOBALS['egw_info']['flags']['include_xajax'] = true;
361
+				$tpl = new etemplate('etemplate.link_widget.entry');
362
+				$options = $cell['size'] ? explode(',',$cell['size']) : array();
363
+				$app = $extension_data['app'] = $options[0];
364
+				$link_type = $extension_data['link_type'];
365
+				// handle extra args for onclick like: values2url(this.form,'start,end,duration,participants,recur_type,whole_day')+'&exec[event_id]=
366
+				if ( isset($value) && is_array($value) && isset($value['extra']) )
367
+				{
368
+					//echo '<p>extra='.htmlspecialchars($value['extra'])."</p>\n";
369
+					//something like: values2url(this.form,'start,end,duration,participants,recur_type,whole_day')+'&exec[event_id]=
370
+					$on_click_string =& $tpl->get_cell_attribute('search','onclick');
371
+					$on_click_string = str_replace(');',','.$value['extra'].');',$on_click_string);
372
+					//echo htmlspecialchars($on_click_string);
373
+				}
374
+				if ($value)	// show pre-selected entry in select-box and not the search
385 375
 				{
386
-					// add selected-entry plus "new search" to the selectbox-options
387
-					if (!isset($app) || strpos($value,':') !== false)
376
+					if (is_array($value))
388 377
 					{
389
-						list($app,$id) = explode(':',$value, 2);
378
+						if (isset($value['current']))
379
+						{
380
+							list($app,$id) = explode(':',$value['current'], 2);
381
+							if ($app) unset($value['default_sel']);	// would overwrite $app!
382
+						}
390 383
 					}
391 384
 					else
392 385
 					{
393
-						$id = $value;
386
+						// add selected-entry plus "new search" to the selectbox-options
387
+						if (!isset($app) || strpos($value,':') !== false)
388
+						{
389
+							list($app,$id) = explode(':',$value, 2);
390
+						}
391
+						else
392
+						{
393
+							$id = $value;
394
+						}
394 395
 					}
395
-				}
396
-				$titles = array();
397
-				foreach(explode(',',$id) as $id)
398
-				{
399
-					if ($id)
396
+					$titles = array();
397
+					foreach(explode(',',$id) as $id)
400 398
 					{
401
-						if (!($title = egw_link::title($app,$id)))
399
+						if ($id)
402 400
 						{
403
-							$title = $app.': #'.$id;
401
+							if (!($title = egw_link::title($app,$id)))
402
+							{
403
+								$title = $app.': #'.$id;
404
+							}
405
+							$titles[$id] = $title;
404 406
 						}
405
-						$titles[$id] = $title;
407
+					}
408
+					if ($titles)
409
+					{
410
+						if ($cell['onchange']) $titles[0] = lang('Show all / cancel filter');
411
+						$titles[''] = lang('new search').' ...';
412
+						$selectbox =& $tpl->get_widget_by_name('id');
413
+						$selectbox['sel_options'] = $titles;
414
+						// remove link_hide class from select-box-line
415
+						$span =& $tpl->get_cell_attribute('select_line','span');
416
+						$span = str_replace('link_hide','',$span);
417
+						// add link_hide class to search_line
418
+						$span =& $tpl->get_cell_attribute('search_line','span');
419
+						$span .= ' link_hide';
420
+						unset($span);
406 421
 					}
407 422
 				}
408
-				if ($titles)
423
+				if ($extension_data['app'] && count($options) <= 1)	// no app-selection, using app given in first option
409 424
 				{
410
-					if ($cell['onchange']) $titles[0] = lang('Show all / cancel filter');
411
-					$titles[''] = lang('new search').' ...';
412
-					$selectbox =& $tpl->get_widget_by_name('id');
413
-					$selectbox['sel_options'] = $titles;
414
-					// remove link_hide class from select-box-line
415
-					$span =& $tpl->get_cell_attribute('select_line','span');
416
-					$span = str_replace('link_hide','',$span);
417
-					// add link_hide class to search_line
418
-					$span =& $tpl->get_cell_attribute('search_line','span');
419
-					$span .= ' link_hide';
420
-					unset($span);
425
+					$tpl->disable_cells('app');
426
+					$onchange =& $tpl->get_cell_attribute('search','onclick');
427
+					$onchange = str_replace("document.getElementById(form::name('app')).value",'\''.$cell['size'].'\'',$onchange);
428
+					unset($onchange);
421 429
 				}
422
-			}
423
-			if ($extension_data['app'] && count($options) <= 1)	// no app-selection, using app given in first option
424
-			{
425
-				$tpl->disable_cells('app');
426
-				$onchange =& $tpl->get_cell_attribute('search','onclick');
427
-				$onchange = str_replace("document.getElementById(form::name('app')).value",'\''.$cell['size'].'\'',$onchange);
428
-				unset($onchange);
429
-			}
430 430
 
431
-			// store now our values in extension_data to preserve them upon submits (after empty title submit for example)
432
-			$extension_data['default'] = $value;
431
+				// store now our values in extension_data to preserve them upon submits (after empty title submit for example)
432
+				$extension_data['default'] = $value;
433 433
 
434
-			// adding possibility to get a default selection on app select, use for resource in calendar edit.participant
435
-			$value = array(
436
-				'app'        => is_array($value) && isset($value['default_sel']) ? $value['default_sel'] : $app,
437
-				'no_app_sel' => !!$extension_data['app'],
438
-				'id'         => is_array($value) ? $value['current'] : $id,
439
-				'query'      => is_array($value) ? $value['query'] : '',
440
-				'blur'       => $cell['blur'] ? lang($cell['blur']) :
441
-					(count($options) == 1 ? lang($app) : lang('Search')),
442
-				'extra'      => $cell['onchange'] ? ','.self::AJAX_NEED_ONCHANGE : null,	// store flang for ajax_search, to display extra_line required by onchange
443
-			);
444
-			if ($cell['needed']) $value['class'] = 'inputRequired';
434
+				// adding possibility to get a default selection on app select, use for resource in calendar edit.participant
435
+				$value = array(
436
+					'app'        => is_array($value) && isset($value['default_sel']) ? $value['default_sel'] : $app,
437
+					'no_app_sel' => !!$extension_data['app'],
438
+					'id'         => is_array($value) ? $value['current'] : $id,
439
+					'query'      => is_array($value) ? $value['query'] : '',
440
+					'blur'       => $cell['blur'] ? lang($cell['blur']) :
441
+						(count($options) == 1 ? lang($app) : lang('Search')),
442
+					'extra'      => $cell['onchange'] ? ','.self::AJAX_NEED_ONCHANGE : null,	// store flang for ajax_search, to display extra_line required by onchange
443
+				);
444
+				if ($cell['needed']) $value['class'] = 'inputRequired';
445 445
 
446
-			if ($options)	// limit the app-selectbox to the given apps
447
-			{
448
-				$tpl->set_cell_attribute('app','type','select');
449
-				$tpl->set_cell_attribute('app','no_lang',true);
450
-				$apps = egw_link::app_list('query');
451
-				asort($apps);	// sort them alphabetic
452
-				foreach($apps as $app => $label)
446
+				if ($options)	// limit the app-selectbox to the given apps
453 447
 				{
454
-					if (!in_array($app,$options)) unset($apps[$app]);
448
+					$tpl->set_cell_attribute('app','type','select');
449
+					$tpl->set_cell_attribute('app','no_lang',true);
450
+					$apps = egw_link::app_list('query');
451
+					asort($apps);	// sort them alphabetic
452
+					foreach($apps as $app => $label)
453
+					{
454
+						if (!in_array($app,$options)) unset($apps[$app]);
455
+					}
456
+					$value['options-app'] = $apps;
455 457
 				}
456
-				$value['options-app'] = $apps;
457
-			}
458 458
 
459
-			self::get_sub_types($cell, $value, $tpl);
459
+				self::get_sub_types($cell, $value, $tpl);
460 460
 
461
-			break;
461
+				break;
462 462
 
463
-		case 'link-apps':
464
-			$apps = egw_link::app_list($cell['size'] ? $cell['size'] : 'query');
465
-			if (!$apps)	// cant do an add without apps or already created entry
466
-			{
467
-				$cell = $tmpl->empty_cell();
468
-				return;
469
-			}
470
-			asort($apps);	// sort them alphabetic
471
-			$cell['sel_options'] = $apps;
472
-			$cell['no_lang'] = True;	// already translated
473
-			$cell['type'] = 'select';
474
-			return true;
463
+			case 'link-apps':
464
+				$apps = egw_link::app_list($cell['size'] ? $cell['size'] : 'query');
465
+				if (!$apps)	// cant do an add without apps or already created entry
466
+				{
467
+					$cell = $tmpl->empty_cell();
468
+					return;
469
+				}
470
+				asort($apps);	// sort them alphabetic
471
+				$cell['sel_options'] = $apps;
472
+				$cell['no_lang'] = True;	// already translated
473
+				$cell['type'] = 'select';
474
+				return true;
475 475
 		}
476 476
 		$cell['size'] = $cell['name'];
477 477
 		$cell['type'] = 'template';
Please login to merge, or discard this patch.
Spacing   +126 added lines, -127 removed lines patch added patch discarded remove patch
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 	 *
100 100
 	 * @param string $ui '' for html
101 101
 	 */
102
-	function link_widget($ui='')
102
+	function link_widget($ui = '')
103 103
 	{
104 104
 
105 105
 	}
@@ -117,13 +117,13 @@  discard block
 block discarded – undo
117 117
 	 * @param object &$tmpl reference to the template we belong too
118 118
 	 * @return boolean true if extra label is allowed, false otherwise
119 119
 	 */
120
-	function pre_process($name,&$value,&$cell,&$readonlys,&$extension_data,&$tmpl)
120
+	function pre_process($name, &$value, &$cell, &$readonlys, &$extension_data, &$tmpl)
121 121
 	{
122 122
 		$extension_data['type'] = $type = $cell['type'];
123 123
 		$extension_data['needed'] = $cell['needed'];
124 124
 		$help = $cell['help'] ? (is_array($value) && !empty($value['help']) ? $value['help'] : $cell['help']) : lang('view this linked entry in its application');
125 125
 
126
-		if ((in_array($type,array('link-to','link-add','link-entry')) && !$value) && ($cell['readonly'] || $readonlys))
126
+		if ((in_array($type, array('link-to', 'link-add', 'link-entry')) && !$value) && ($cell['readonly'] || $readonlys))
127 127
 		{
128 128
 			//echo "<p>link-to is readonly, cell=".print_r($cell,true).", readonlys=".print_r($readonlys).", value='$value'</p>\n";
129 129
 			// readonly ==> omit the whole widget
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 			$extension_data = null;
133 133
 			return;
134 134
 		}
135
-		if (!is_array($value) && in_array($type,array('link-to','link-list','link-add')))
135
+		if (!is_array($value) && in_array($type, array('link-to', 'link-list', 'link-add')))
136 136
 		{
137 137
 			$value = array(
138 138
 				'to_id' => $value,
@@ -141,14 +141,14 @@  discard block
 block discarded – undo
141 141
 		}
142 142
 		if ($this->debug)
143 143
 		{
144
-			echo "<p>link_widget::pre_process($name,$value,".print_r($cell,true).",$readonlys,,)</p>\n";
144
+			echo "<p>link_widget::pre_process($name,$value,".print_r($cell, true).",$readonlys,,)</p>\n";
145 145
 			echo "<p>start: $cell[type][$name]::pre_process: value ="; _debug_array($value);
146 146
 			echo "extension_data[$cell[type]][$name] ="; _debug_array($extension_data);
147 147
 		}
148 148
 		switch ($cell['type'])
149 149
 		{
150 150
 		case 'link':
151
-			$cell['readonly'] = True;	// set it readonly to NOT call our post_process function
151
+			$cell['readonly'] = True; // set it readonly to NOT call our post_process function
152 152
 			$extension_data = null;
153 153
 			$cell['no_lang'] = 1;
154 154
 			$link = $target = $popup = '';
@@ -162,20 +162,20 @@  discard block
 block discarded – undo
162 162
 			}
163 163
 			if ($value['app'] && $value['id'])
164 164
 			{
165
-				$view = egw_link::view($value['app'],$value['id']);
165
+				$view = egw_link::view($value['app'], $value['id']);
166 166
 				$link = $view['menuaction']; unset($view['menuaction']);
167
-				foreach($view as $var => $val)
167
+				foreach ($view as $var => $val)
168 168
 				{
169 169
 					$link .= '&'.$var.'='.$val;
170 170
 				}
171 171
 				if (isset($value['extra_args']))
172 172
 				{
173
-					foreach($value['extra_args'] as $var => $val)
173
+					foreach ($value['extra_args'] as $var => $val)
174 174
 					{
175 175
 						$link .= '&'.$var.'='.$val;
176 176
 					}
177 177
 				}
178
-				if (!($popup = egw_link::is_popup($value['app'],'view')) &&
178
+				if (!($popup = egw_link::is_popup($value['app'], 'view')) &&
179 179
 					etemplate::$request->output_mode == 2)	// we are in a popup
180 180
 				{
181 181
 					$target = '_blank';
@@ -189,17 +189,17 @@  discard block
 block discarded – undo
189 189
 			elseif (!$value['title'])
190 190
 			{
191 191
 				$cell = $tmpl->empty_cell();
192
-				$cell['readonly'] = True;	// set it readonly to NOT call our post_process function
192
+				$cell['readonly'] = True; // set it readonly to NOT call our post_process function
193 193
 				$extension_data = null;
194 194
 				return;
195 195
 			}
196 196
 			$cell['type'] = 'label';
197 197
 			//  size: [b[old]][i[talic]],[link],[activate_links],[label_for],[link_target],[link_popup_size],[link_title]
198
-			list($cell['size']) = explode(',',$cell['size']);
198
+			list($cell['size']) = explode(',', $cell['size']);
199 199
 			// Pass link through framework's handler
200
-			if(!$popup) $link = str_replace(',','%2C',egw::link('/index.php?menuaction='.$link,false,$value['app']));
200
+			if (!$popup) $link = str_replace(',', '%2C', egw::link('/index.php?menuaction='.$link, false, $value['app']));
201 201
 			$cell['size'] .= ','.$link.',,,'.$target.','.$popup.','.$value['extra_title'];
202
-			$value = $value['title'] ? $value['title'] : egw_link::title($value['app'],$value['id']);
202
+			$value = $value['title'] ? $value['title'] : egw_link::title($value['app'], $value['id']);
203 203
 			return true;
204 204
 
205 205
 		case 'link-string':
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
 			if ($value && !is_array($value) && $cell['size'])
208 208
 			{
209 209
 				$value = array('to_id' => $value);
210
-				list($value['to_app'],$value['only_app']) = explode(',',$cell['size']);
210
+				list($value['to_app'], $value['only_app']) = explode(',', $cell['size']);
211 211
 			}
212 212
 			if ($value['to_id'] && $value['to_app'])
213 213
 			{
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 					'link_lastmod DESC', true, $value['show_deleted'], self::LIMIT_LINKS);
216 216
 				if ($only_app)
217 217
 				{
218
-					foreach($value as $key => $id)
218
+					foreach ($value as $key => $id)
219 219
 					{
220 220
 						$value[$key] = array(
221 221
 							'id'  => $id,
@@ -228,11 +228,11 @@  discard block
 block discarded – undo
228 228
 			{
229 229
 				foreach ($value as $link)
230 230
 				{
231
-					$str .= ($str !== '' ? ', ' : '') . self::link2a_href($link,$help);
231
+					$str .= ($str !== '' ? ', ' : '').self::link2a_href($link, $help);
232 232
 				}
233 233
 			}
234 234
 			$cell['type'] = 'html';
235
-			$cell['readonly'] = True;	// set it readonly to NOT call our post_process function
235
+			$cell['readonly'] = True; // set it readonly to NOT call our post_process function
236 236
 			$extension_data = null;
237 237
 			$value = $str;
238 238
 			return True;
@@ -244,15 +244,15 @@  discard block
 block discarded – undo
244 244
 				$cell = $tmpl->empty_cell();
245 245
 				return;
246 246
 			}
247
-			asort($apps);	// sort them alphabetic
247
+			asort($apps); // sort them alphabetic
248 248
 			$value['options-add_app'] = array();
249
-			foreach($apps as $app => $label)
249
+			foreach ($apps as $app => $label)
250 250
 			{
251
-				$link = $GLOBALS['egw']->link('/index.php',egw_link::add($app,$value['to_app'],$value['to_id'])+
251
+				$link = $GLOBALS['egw']->link('/index.php', egw_link::add($app, $value['to_app'], $value['to_id']) +
252 252
 					(is_array($value['extra']) ? $value['extra'] : array()));
253
-				if (($popup = egw_link::is_popup($app,'add')))
253
+				if (($popup = egw_link::is_popup($app, 'add')))
254 254
 				{
255
-					list($w,$h) = explode('x',$popup);
255
+					list($w, $h) = explode('x', $popup);
256 256
 					$action = "window.open('$link','_blank','width=$w,height=$h,location=no,menubar=no,toolbar=no,scrollbars=yes,status=yes');";
257 257
 				}
258 258
 				else
@@ -271,8 +271,8 @@  discard block
 block discarded – undo
271 271
 			if ($value['search_label'] && $extension_data['search_label'] != $value['search_label']) $value['search_label'] = lang($value['search_label']);
272 272
 			$extension_data = $value;
273 273
 			$tpl = new etemplate('etemplate.link_widget.to');
274
-			if ($value['link_label']) $tpl->set_cell_attribute('create','label',$value['link_label']);
275
-			if ($value['search_label']) $tpl->set_cell_attribute('search','label',$value['search_label']);
274
+			if ($value['link_label']) $tpl->set_cell_attribute('create', 'label', $value['link_label']);
275
+			if ($value['search_label']) $tpl->set_cell_attribute('search', 'label', $value['search_label']);
276 276
 
277 277
 			self::get_sub_types($cell, $value, $tpl);
278 278
 
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
 			}
288 288
 			if (!isset($value['title']))
289 289
 			{
290
-				$value['title'] = egw_link::title($app,$id);
290
+				$value['title'] = egw_link::title($app, $id);
291 291
 			}
292 292
 			$links = egw_link::get_links($app, $id, '', 'link_lastmod DESC', true, $value['show_deleted'], self::LIMIT_LINKS);
293 293
 			$value['anz_links'] = count($links);
@@ -301,17 +301,17 @@  discard block
 block discarded – undo
301 301
 			}
302 302
 			$value['link_list_format'] = $GLOBALS['egw_info']['user']['preferences']['common']['link_list_format'];
303 303
 			$tpl = new etemplate('etemplate.link_widget.list');
304
-			for($row=$tpl->rows-1; list(,$link) = each($links); ++$row)
304
+			for ($row = $tpl->rows - 1; list(,$link) = each($links); ++$row)
305 305
 			{
306 306
 				$value[$row] = $link;
307
-				$value[$row]['title'] = egw_link::title($link['app'],($link['app'] == egw_link::VFS_APPNAME&&!is_array($link['id'])?egw_vfs::decodePath($link['id']):$link['id']),$link);
307
+				$value[$row]['title'] = egw_link::title($link['app'], ($link['app'] == egw_link::VFS_APPNAME && !is_array($link['id']) ? egw_vfs::decodePath($link['id']) : $link['id']), $link);
308 308
 				if (!is_array($link['id']))
309 309
 				{
310
-					$value[$row]['view']  = egw_link::view($link['app'],$link['id'],$link);
311
-					if (!($value[$row]['popup'] = egw_link::is_popup($link['app'],'view',$link)) &&
310
+					$value[$row]['view'] = egw_link::view($link['app'], $link['id'], $link);
311
+					if (!($value[$row]['popup'] = egw_link::is_popup($link['app'], 'view', $link)) &&
312 312
 						etemplate::$request->output_mode == 2)	// we are in a popup
313 313
 					{
314
-						$value[$row]['target'] = '_blank';		// we create a new window as the linked page is no popup
314
+						$value[$row]['target'] = '_blank'; // we create a new window as the linked page is no popup
315 315
 					}
316 316
 				}
317 317
 				if ($link['app'] == egw_link::VFS_APPNAME)
@@ -321,22 +321,22 @@  discard block
 block discarded – undo
321 321
 					$value[$row]['help'] = lang('Delete this file');
322 322
 					if ($value['link_list_format'] != 'text')
323 323
 					{
324
-						$value[$row]['title'] = preg_replace('/: ([^ ]+) /',': ',$value[$row]['title']);	// remove mime-type, it's alread in the icon
324
+						$value[$row]['title'] = preg_replace('/: ([^ ]+) /', ': ', $value[$row]['title']); // remove mime-type, it's alread in the icon
325 325
 					}
326
-					$value[$row]['icon'] = egw_link::vfs_path($link['app2'],$link['id2'],$link['id'],true);
326
+					$value[$row]['icon'] = egw_link::vfs_path($link['app2'], $link['id2'], $link['id'], true);
327 327
 				}
328 328
 				else
329 329
 				{
330 330
 					$value[$row]['icon'] = egw_link::get_registry($value[$row]['app'], 'icon');
331 331
 					$value[$row]['label'] = 'Unlink';
332 332
 					$value[$row]['help'] = lang('Remove this link (not the entry itself)');
333
-					if(!egw_link::is_popup($link['app'],'view') && etemplate::$request->output_mode == 2)
333
+					if (!egw_link::is_popup($link['app'], 'view') && etemplate::$request->output_mode == 2)
334 334
 					{
335 335
 						// If link doesn't want a popup, make sure to open it in appropriate tab of main window
336 336
 						$value[$row]['view'] = "javascript:if(typeof opener.top.framework != 'undefined') {
337
-							opener.top.egw_appWindowOpen('{$link['app']}','".egw::link('/index.php',$value[$row]['view'])."');
337
+							opener.top.egw_appWindowOpen('{$link['app']}','".egw::link('/index.php', $value[$row]['view'])."');
338 338
 						} else {
339
-							opener.open('".egw::link('/index.php',$value[$row]['view'])."','".$value[$row]['target']."');
339
+							opener.open('".egw::link('/index.php', $value[$row]['view'])."','".$value[$row]['target']."');
340 340
 						}";
341 341
 					}
342 342
 				}
@@ -346,12 +346,12 @@  discard block
 block discarded – undo
346 346
 		case 'link-entry':
347 347
 			if ($cell['readonly'] || $readonlys)
348 348
 			{
349
-				if(!is_array($value))
349
+				if (!is_array($value))
350 350
 				{
351
-					if (strpos($value,':') !== false) list($app,$value) = explode(':',$value,2);
352
-					$value = array('app' => $app ? $app : $cell['size'],'id' => $value);
351
+					if (strpos($value, ':') !== false) list($app, $value) = explode(':', $value, 2);
352
+					$value = array('app' => $app ? $app : $cell['size'], 'id' => $value);
353 353
 				}
354
-				$value = self::link2a_href($value,$help);
354
+				$value = self::link2a_href($value, $help);
355 355
 				$cell['type'] = 'html';
356 356
 				$cell['readonly'] = true;
357 357
 				$extension_data = null;
@@ -359,16 +359,16 @@  discard block
 block discarded – undo
359 359
 			}
360 360
 			$GLOBALS['egw_info']['flags']['include_xajax'] = true;
361 361
 			$tpl = new etemplate('etemplate.link_widget.entry');
362
-			$options = $cell['size'] ? explode(',',$cell['size']) : array();
362
+			$options = $cell['size'] ? explode(',', $cell['size']) : array();
363 363
 			$app = $extension_data['app'] = $options[0];
364 364
 			$link_type = $extension_data['link_type'];
365 365
 			// handle extra args for onclick like: values2url(this.form,'start,end,duration,participants,recur_type,whole_day')+'&exec[event_id]=
366
-			if ( isset($value) && is_array($value) && isset($value['extra']) )
366
+			if (isset($value) && is_array($value) && isset($value['extra']))
367 367
 			{
368 368
 				//echo '<p>extra='.htmlspecialchars($value['extra'])."</p>\n";
369 369
 				//something like: values2url(this.form,'start,end,duration,participants,recur_type,whole_day')+'&exec[event_id]=
370
-				$on_click_string =& $tpl->get_cell_attribute('search','onclick');
371
-				$on_click_string = str_replace(');',','.$value['extra'].');',$on_click_string);
370
+				$on_click_string = & $tpl->get_cell_attribute('search', 'onclick');
371
+				$on_click_string = str_replace(');', ','.$value['extra'].');', $on_click_string);
372 372
 				//echo htmlspecialchars($on_click_string);
373 373
 			}
374 374
 			if ($value)	// show pre-selected entry in select-box and not the search
@@ -377,16 +377,16 @@  discard block
 block discarded – undo
377 377
 				{
378 378
 					if (isset($value['current']))
379 379
 					{
380
-						list($app,$id) = explode(':',$value['current'], 2);
381
-						if ($app) unset($value['default_sel']);	// would overwrite $app!
380
+						list($app, $id) = explode(':', $value['current'], 2);
381
+						if ($app) unset($value['default_sel']); // would overwrite $app!
382 382
 					}
383 383
 				}
384 384
 				else
385 385
 				{
386 386
 					// add selected-entry plus "new search" to the selectbox-options
387
-					if (!isset($app) || strpos($value,':') !== false)
387
+					if (!isset($app) || strpos($value, ':') !== false)
388 388
 					{
389
-						list($app,$id) = explode(':',$value, 2);
389
+						list($app, $id) = explode(':', $value, 2);
390 390
 					}
391 391
 					else
392 392
 					{
@@ -394,11 +394,11 @@  discard block
 block discarded – undo
394 394
 					}
395 395
 				}
396 396
 				$titles = array();
397
-				foreach(explode(',',$id) as $id)
397
+				foreach (explode(',', $id) as $id)
398 398
 				{
399 399
 					if ($id)
400 400
 					{
401
-						if (!($title = egw_link::title($app,$id)))
401
+						if (!($title = egw_link::title($app, $id)))
402 402
 						{
403 403
 							$title = $app.': #'.$id;
404 404
 						}
@@ -409,13 +409,13 @@  discard block
 block discarded – undo
409 409
 				{
410 410
 					if ($cell['onchange']) $titles[0] = lang('Show all / cancel filter');
411 411
 					$titles[''] = lang('new search').' ...';
412
-					$selectbox =& $tpl->get_widget_by_name('id');
412
+					$selectbox = & $tpl->get_widget_by_name('id');
413 413
 					$selectbox['sel_options'] = $titles;
414 414
 					// remove link_hide class from select-box-line
415
-					$span =& $tpl->get_cell_attribute('select_line','span');
416
-					$span = str_replace('link_hide','',$span);
415
+					$span = & $tpl->get_cell_attribute('select_line', 'span');
416
+					$span = str_replace('link_hide', '', $span);
417 417
 					// add link_hide class to search_line
418
-					$span =& $tpl->get_cell_attribute('search_line','span');
418
+					$span = & $tpl->get_cell_attribute('search_line', 'span');
419 419
 					$span .= ' link_hide';
420 420
 					unset($span);
421 421
 				}
@@ -423,8 +423,8 @@  discard block
 block discarded – undo
423 423
 			if ($extension_data['app'] && count($options) <= 1)	// no app-selection, using app given in first option
424 424
 			{
425 425
 				$tpl->disable_cells('app');
426
-				$onchange =& $tpl->get_cell_attribute('search','onclick');
427
-				$onchange = str_replace("document.getElementById(form::name('app')).value",'\''.$cell['size'].'\'',$onchange);
426
+				$onchange = & $tpl->get_cell_attribute('search', 'onclick');
427
+				$onchange = str_replace("document.getElementById(form::name('app')).value", '\''.$cell['size'].'\'', $onchange);
428 428
 				unset($onchange);
429 429
 			}
430 430
 
@@ -437,21 +437,20 @@  discard block
 block discarded – undo
437 437
 				'no_app_sel' => !!$extension_data['app'],
438 438
 				'id'         => is_array($value) ? $value['current'] : $id,
439 439
 				'query'      => is_array($value) ? $value['query'] : '',
440
-				'blur'       => $cell['blur'] ? lang($cell['blur']) :
441
-					(count($options) == 1 ? lang($app) : lang('Search')),
442
-				'extra'      => $cell['onchange'] ? ','.self::AJAX_NEED_ONCHANGE : null,	// store flang for ajax_search, to display extra_line required by onchange
440
+				'blur'       => $cell['blur'] ? lang($cell['blur']) : (count($options) == 1 ? lang($app) : lang('Search')),
441
+				'extra'      => $cell['onchange'] ? ','.self::AJAX_NEED_ONCHANGE : null, // store flang for ajax_search, to display extra_line required by onchange
443 442
 			);
444 443
 			if ($cell['needed']) $value['class'] = 'inputRequired';
445 444
 
446 445
 			if ($options)	// limit the app-selectbox to the given apps
447 446
 			{
448
-				$tpl->set_cell_attribute('app','type','select');
449
-				$tpl->set_cell_attribute('app','no_lang',true);
447
+				$tpl->set_cell_attribute('app', 'type', 'select');
448
+				$tpl->set_cell_attribute('app', 'no_lang', true);
450 449
 				$apps = egw_link::app_list('query');
451
-				asort($apps);	// sort them alphabetic
452
-				foreach($apps as $app => $label)
450
+				asort($apps); // sort them alphabetic
451
+				foreach ($apps as $app => $label)
453 452
 				{
454
-					if (!in_array($app,$options)) unset($apps[$app]);
453
+					if (!in_array($app, $options)) unset($apps[$app]);
455 454
 				}
456 455
 				$value['options-app'] = $apps;
457 456
 			}
@@ -467,16 +466,16 @@  discard block
 block discarded – undo
467 466
 				$cell = $tmpl->empty_cell();
468 467
 				return;
469 468
 			}
470
-			asort($apps);	// sort them alphabetic
469
+			asort($apps); // sort them alphabetic
471 470
 			$cell['sel_options'] = $apps;
472
-			$cell['no_lang'] = True;	// already translated
471
+			$cell['no_lang'] = True; // already translated
473 472
 			$cell['type'] = 'select';
474 473
 			return true;
475 474
 		}
476 475
 		$cell['size'] = $cell['name'];
477 476
 		$cell['type'] = 'template';
478 477
 		$cell['name'] = $tpl->name;
479
-		$cell['obj'] =& $tpl;
478
+		$cell['obj'] = & $tpl;
480 479
 		// keep the editor away from the generated tmpls
481 480
 		$tpl->no_onclick = true;
482 481
 
@@ -484,7 +483,7 @@  discard block
 block discarded – undo
484 483
 		{
485 484
 			echo "<p>end: $type"."[$name]::pre_process: value ="; _debug_array($value);
486 485
 		}
487
-		return True;	// extra Label is ok
486
+		return True; // extra Label is ok
488 487
 	}
489 488
 
490 489
 	/**
@@ -494,23 +493,23 @@  discard block
 block discarded – undo
494 493
 	 * @param string $help=''
495 494
 	 * @return string
496 495
 	 */
497
-	static function link2a_href(array $link,$help='')
496
+	static function link2a_href(array $link, $help = '')
498 497
 	{
499 498
 		if (($popup = egw_link::is_popup($link['app'], 'view', $link)))
500 499
 		{
501
-			list($w,$h) = explode('x',$popup);
500
+			list($w, $h) = explode('x', $popup);
502 501
 			$options = ' onclick="window.open(this,this.target,\'width='.(int)$w.',height='.(int)$h.',location=no,menubar=no,toolbar=no,scrollbars=yes,status=yes\'); return false;"';
503 502
 		}
504
-		elseif (etemplate::$request->output_mode == 2 || 	// we are in a popup
505
-			$link['app'] == egw_link::VFS_APPNAME ||		// or it's a link to an attachment
506
-			($target = egw_link::get_registry($link['app'],'view_target')))	// or explicit target set
503
+		elseif (etemplate::$request->output_mode == 2 || // we are in a popup
504
+			$link['app'] == egw_link::VFS_APPNAME || // or it's a link to an attachment
505
+			($target = egw_link::get_registry($link['app'], 'view_target')))	// or explicit target set
507 506
 		{
508 507
 			$options = ' target="'.($target ? $target : '_blank').'"';
509 508
 		}
510 509
 		else
511 510
 		{
512 511
 			// Pass link through framework's handler
513
-			$href = str_replace(',','%2C',egw::link('/index.php',egw_link::view($link['app'],$link['id'],$link),$link['app']));
512
+			$href = str_replace(',', '%2C', egw::link('/index.php', egw_link::view($link['app'], $link['id'], $link), $link['app']));
514 513
 		}
515 514
 		if ($help)
516 515
 		{
@@ -518,8 +517,8 @@  discard block
 block discarded – undo
518 517
 			$options .= " onMouseOut=\"self.status=''; return true;\"";
519 518
 		}
520 519
 		return html::a_href(
521
-			html::htmlspecialchars(egw_link::title($link['app'],($link['app']==egw_link::VFS_APPNAME?egw_vfs::decodePath($link['id']):$link['id']))),
522
-			$href ? $href : egw_link::view($link['app'],$link['id'],$link),'',$options);
520
+			html::htmlspecialchars(egw_link::title($link['app'], ($link['app'] == egw_link::VFS_APPNAME ? egw_vfs::decodePath($link['id']) : $link['id']))),
521
+			$href ? $href : egw_link::view($link['app'], $link['id'], $link), '', $options);
523 522
 	}
524 523
 
525 524
 	/**
@@ -539,17 +538,17 @@  discard block
 block discarded – undo
539 538
 	 * @param mixed &value_in the posted values (already striped of magic-quotes)
540 539
 	 * @return boolean true if $value has valid content, on false no content will be returned!
541 540
 	 */
542
-	function post_process($name,&$value,&$extension_data,&$loop,&$tmpl,$value_in)
541
+	function post_process($name, &$value, &$extension_data, &$loop, &$tmpl, $value_in)
543 542
 	{
544 543
 		//echo "<p>link_widget::post_process('$name',value=".print_r($value,true).",ext=".print_r($extension_data,true).",$loop,,value_in=".print_r($value_in,true)."</p>\n";
545 544
 
546
-		switch($extension_data['type'])
545
+		switch ($extension_data['type'])
547 546
 		{
548 547
 			case 'link-entry':
549 548
 				//error_log(__METHOD__.__LINE__.array2string(array('data'=>$value,'value in'=>$value_in,'extension_data'=>$extension_data,'source'=>function_backtrace())));
550 549
 				if (!$value_in['id'] && $extension_data['needed'])
551 550
 				{
552
-					$tmpl->set_validation_error($name,lang('Field must not be empty !!!'),'');
551
+					$tmpl->set_validation_error($name, lang('Field must not be empty !!!'), '');
553 552
 					return true;
554 553
 				}
555 554
 				$defaultData = false;
@@ -557,14 +556,14 @@  discard block
 block discarded – undo
557 556
 				if (is_array($extension_data['default']) && !empty($extension_data['default']))
558 557
 				{
559 558
 					// this may fail, if $extension_data['default'][0] is set on purpose
560
-					foreach($extension_data['default'] as $k => $v)
559
+					foreach ($extension_data['default'] as $k => $v)
561 560
 					{
562 561
 						if ($v)
563 562
 						{
564
-							$defaultData=true;
565
-							if ($k==0 && !empty($value_in['id'])) // we have a valid incomming id, we intend to use that
563
+							$defaultData = true;
564
+							if ($k == 0 && !empty($value_in['id'])) // we have a valid incomming id, we intend to use that
566 565
 							{
567
-								$defaultData=false;
566
+								$defaultData = false;
568 567
 								continue;
569 568
 							}
570 569
 							break;
@@ -575,10 +574,10 @@  discard block
 block discarded – undo
575 574
 						$value = $extension_data['default'];
576 575
 						$value['current'] = $extension_data['app'] ? $value_in['id'] : $value_in['app'].':'.$value_in['id'];
577 576
 						// we take care for id, in case it is empty AND needed
578
-						if(empty($value['id']) && $extension_data['needed']) $value['id'] = $value['current'];
577
+						if (empty($value['id']) && $extension_data['needed']) $value['id'] = $value['current'];
579 578
 					}
580 579
 				}
581
-				if($defaultData === false)
580
+				if ($defaultData === false)
582 581
 				{
583 582
 					// this was the line before the default opt, not sure it works well in all case
584 583
 					$value = $extension_data['app'] ? $value_in['id'] : $value['app'].':'.$value_in['id'];
@@ -589,13 +588,13 @@  discard block
 block discarded – undo
589 588
 			case 'link-apps':
590 589
 				if (!$value_in && $extension_data['needed'])
591 590
 				{
592
-					$tmpl->set_validation_error($name,lang('Field must not be empty !!!'),'');
591
+					$tmpl->set_validation_error($name, lang('Field must not be empty !!!'), '');
593 592
 					return true;
594 593
 				}
595 594
 				$value = $value_in;
596 595
 				return !!$value;
597 596
 		}
598
-		$buttons = array('search','create','new','upload','attach');
597
+		$buttons = array('search', 'create', 'new', 'upload', 'attach');
599 598
 		while (!$button && list(,$bname) = each($buttons))
600 599
 		{
601 600
 			$button = $value[$bname] ? $bname : '';
@@ -611,7 +610,7 @@  discard block
 block discarded – undo
611 610
 
612 611
 		if (is_array($extension_data))
613 612
 		{
614
-			$value = is_array($value) ? array_merge($extension_data,$value) : $extension_data;
613
+			$value = is_array($value) ? array_merge($extension_data, $value) : $extension_data;
615 614
 		}
616 615
 		if ($button && $this->debug)
617 616
 		{
@@ -622,11 +621,11 @@  discard block
 block discarded – undo
622 621
 			case 'create':
623 622
 				if ($value['to_app'])						// make the link
624 623
 				{
625
-					$link_id = egw_link::link($value['to_app'],$value['to_id'],
626
-						$value['app'],$value['id'],$value['remark']);
624
+					$link_id = egw_link::link($value['to_app'], $value['to_id'],
625
+						$value['app'], $value['id'], $value['remark']);
627 626
 					$value['remark'] = $value['query'] = '';
628 627
 
629
-					if (isset($value['primary']) && !$value['anz_links'] )
628
+					if (isset($value['primary']) && !$value['anz_links'])
630 629
 					{
631 630
 						$value['primary'] = $link_id;
632 631
 					}
@@ -639,7 +638,7 @@  discard block
 block discarded – undo
639 638
 				break;
640 639
 
641 640
 			case 'attach':
642
-				$name = preg_replace('/^exec\[([^]]+)\](.*)$/','\\1\\2',$name);	// remove exec prefix
641
+				$name = preg_replace('/^exec\[([^]]+)\](.*)$/', '\\1\\2', $name); // remove exec prefix
643 642
 				if (is_array($value['file']) && $value['to_app'] &&
644 643
 					!empty($value['file']['tmp_name']) && $value['file']['tmp_name'] != 'none')
645 644
 				{
@@ -647,25 +646,25 @@  discard block
 block discarded – undo
647 646
 					{
648 647
 						if (is_dir($GLOBALS['egw_info']['server']['temp_dir']) && is_writable($GLOBALS['egw_info']['server']['temp_dir']))
649 648
 						{
650
-							$new_file = tempnam($GLOBALS['egw_info']['server']['temp_dir'],'egw_');
649
+							$new_file = tempnam($GLOBALS['egw_info']['server']['temp_dir'], 'egw_');
651 650
 						}
652 651
 						else
653 652
 						{
654 653
 							$new_file = $value['file']['tmp_name'].'+';
655 654
 						}
656
-						move_uploaded_file($value['file']['tmp_name'],$new_file);
655
+						move_uploaded_file($value['file']['tmp_name'], $new_file);
657 656
 						$value['file']['tmp_name'] = $new_file;
658 657
 					}
659
-					if (!($link_id = egw_link::link($value['to_app'],$value['to_id'],
660
-						egw_link::VFS_APPNAME,$value['file'],$value['remark'])))
658
+					if (!($link_id = egw_link::link($value['to_app'], $value['to_id'],
659
+						egw_link::VFS_APPNAME, $value['file'], $value['remark'])))
661 660
 					{
662
-						etemplate::set_validation_error($name.'[file]',lang('Error copying uploaded file to vfs!'));
661
+						etemplate::set_validation_error($name.'[file]', lang('Error copying uploaded file to vfs!'));
663 662
 					}
664 663
 					else
665 664
 					{
666 665
 						$value['remark'] = '';
667 666
 
668
-						if (isset($value['primary']) && !$value['anz_links'] )
667
+						if (isset($value['primary']) && !$value['anz_links'])
669 668
 						{
670 669
 							$value['primary'] = $link_id;
671 670
 						}
@@ -675,7 +674,7 @@  discard block
 block discarded – undo
675 674
 				}
676 675
 				else
677 676
 				{
678
-					etemplate::set_validation_error($name.'[file]',lang('You need to select a file first!'));
677
+					etemplate::set_validation_error($name.'[file]', lang('You need to select a file first!'));
679 678
 				}
680 679
 				$extension_data = $value;
681 680
 				$loop = True;
@@ -687,10 +686,10 @@  discard block
 block discarded – undo
687 686
 					//echo "<p>unlink(link-id=$unlink,$value[to_app],$value[to_id])</p>\n";
688 687
 					if (is_array($value['to_id'])) _debug_array($value['to_id']);
689 688
 				}
690
-				egw_link::unlink2($unlink,$value['to_app'],$value['to_id']);
689
+				egw_link::unlink2($unlink, $value['to_app'], $value['to_id']);
691 690
 				if (is_array($value['to_id']))
692 691
 				{
693
-					$extension_data['to_id'] = $value['to_id'];	// else changes from unlink get lost
692
+					$extension_data['to_id'] = $value['to_id']; // else changes from unlink get lost
694 693
 				}
695 694
 				$loop = True;
696 695
 				break;
@@ -709,20 +708,20 @@  discard block
 block discarded – undo
709 708
 	*/
710 709
 	private static function get_sub_types($cell, &$value, &$tpl) {
711 710
 		// Get sub-types
712
-		if($value['options-app']) {
711
+		if ($value['options-app']) {
713 712
 			$apps = $value['options-app'];
714 713
 		} else {
715 714
 			$apps = egw_link::app_list($cell['size'] ? $cell['size'] : 'query');
716
-			asort($apps);	// sort them alphabetic
715
+			asort($apps); // sort them alphabetic
717 716
 		}
718 717
 
719 718
 		$current_app = $value['app'] ? $value['app'] : key($apps);
720
-		if(is_array(egw_link::$app_register[$current_app]['types'])) {
721
-			foreach(egw_link::$app_register[$current_app]['types'] as $key => $settings) {
719
+		if (is_array(egw_link::$app_register[$current_app]['types'])) {
720
+			foreach (egw_link::$app_register[$current_app]['types'] as $key => $settings) {
722 721
 				$value['options-link_type'][$key] = $settings['name'];
723 722
 			}
724
-			$span =& $tpl->get_cell_attribute('type_box','span');
725
-			$span = str_replace('type_hide','type_show',$span);
723
+			$span = & $tpl->get_cell_attribute('type_box', 'span');
724
+			$span = str_replace('type_hide', 'type_show', $span);
726 725
 			unset($span);
727 726
 		}
728 727
 	}
@@ -742,15 +741,15 @@  discard block
 block discarded – undo
742 741
 	 * @param string $extra optionnal extra search arguments
743 742
 	 * @return string xajax xml response
744 743
 	 */
745
-	static function ajax_search($app,$type,$pattern,$id_res,$id_hide,$id_show,$id_input,$etemplate_exec_id,$extra=array())
744
+	static function ajax_search($app, $type, $pattern, $id_res, $id_hide, $id_show, $id_input, $etemplate_exec_id, $extra = array())
746 745
 	{
747 746
 		$extra_array = array();
748 747
 		if (!empty($extra))
749 748
 		{
750 749
 			//parse $extra as a get url
751
-			parse_str($extra,$extra_array) ;
750
+			parse_str($extra, $extra_array);
752 751
 			// securize entries as they were html encoded and so not checked on the first pass
753
-			_check_script_tag($extra_array,'extra_array');
752
+			_check_script_tag($extra_array, 'extra_array');
754 753
 		}
755 754
 		if ($pattern == lang('Search') || $pattern == lang($app)) $pattern = '';
756 755
 		if (empty($extra_array))
@@ -759,7 +758,7 @@  discard block
 block discarded – undo
759 758
 		}
760 759
 		else
761 760
 		{
762
-			$extra_array['search']= $pattern;
761
+			$extra_array['search'] = $pattern;
763 762
 			$search = $extra_array;
764 763
 		}
765 764
 		// open request
@@ -769,10 +768,10 @@  discard block
 block discarded – undo
769 768
 		$options = array();
770 769
 		//$args = func_get_args(); $response->addAlert("link_widget::ajax_search('".implode("',\n'",$args)."')\n calling link->query( $app , $search, $type )" );
771 770
 		//$args = func_get_args(); error_log(__METHOD__."('".implode("','",$args)."')");
772
-		if($type) {
771
+		if ($type) {
773 772
 			$options['type'] = $type;
774 773
 		}
775
-		if (!($found = egw_link::query($app,$search,$options)))       // ignore the blur-text
774
+		if (!($found = egw_link::query($app, $search, $options)))       // ignore the blur-text
776 775
 		{
777 776
 			$GLOBALS['egw']->translation->add_app('etemplate');
778 777
 			$response->addAlert(lang('Nothing found - try again !!!'));
@@ -785,30 +784,30 @@  discard block
 block discarded – undo
785 784
 			// check if we need to add extra line to produce an onchange to submit the form
786 785
 			if (($data = $request->get_to_process($id_input)) && $data['maxlength'] == self::AJAX_NEED_ONCHANGE)
787 786
 			{
788
-				$script .= "opt = select.options[select.options.length] = new Option('".addslashes(lang('%1 entries found, select one ...',count($found)))."',' ');\n";
787
+				$script .= "opt = select.options[select.options.length] = new Option('".addslashes(lang('%1 entries found, select one ...', count($found)))."',' ');\n";
789 788
 			}
790
-			foreach($found as $id => $option)
789
+			foreach ($found as $id => $option)
791 790
 			{
792 791
 				if (!is_array($option)) $option = array('label' => $option);
793 792
 				// xajax uses xml to transport the label, therefore we have to replace not only CR, LF
794 793
 				// (not allowed unencoded in Javascript strings) but also all utf-8 C0 and C1 plus CR and LF
795
-				$option['label'] = preg_replace('/[\000-\037\177-\237]/u',' ',$option['label']);
794
+				$option['label'] = preg_replace('/[\000-\037\177-\237]/u', ' ', $option['label']);
796 795
 
797 796
 				$script .= "opt = select.options[select.options.length] = new Option('".addslashes($option['label'])."','".addslashes($id)."');\n";
798 797
 				if (count($option) > 1)
799 798
 				{
800
-					foreach($option as $name => $value)
799
+					foreach ($option as $name => $value)
801 800
 					{
802 801
 						if ($name != 'label') $script .= "opt.$name = '".addslashes($value)."';\n";
803 802
 					}
804 803
 				}
805 804
 			}
806 805
 			$script .= "select.options[select.options.length] = new Option('".addslashes(lang('New search').' ...')."','');\n";
807
-			foreach(explode(',',$id_show) as $id)
806
+			foreach (explode(',', $id_show) as $id)
808 807
 			{
809 808
 				$script .= "document.getElementById('$id').style.display='inline';\n";
810 809
 			}
811
-			foreach(explode(',',$id_hide) as $id)
810
+			foreach (explode(',', $id_hide) as $id)
812 811
 			{
813 812
 				$script .= "document.getElementById('$id').style.display='none';\n";
814 813
 			}
@@ -821,11 +820,11 @@  discard block
 block discarded – undo
821 820
 			$data = $request->get_to_process($id_res);
822 821
 			//error_log($id_res.'='.array2string($data));
823 822
 			$data['allowed'] = $found ? array_keys($found) : array();
824
-			$request->set_to_process($id_res,$data);
823
+			$request->set_to_process($id_res, $data);
825 824
 			// update id, if request changed it (happens if the request data is stored direct in the form)
826 825
 			if ($etemplate_exec_id != ($new_id = $request->id()))
827 826
 			{
828
-				$response->addAssign('etemplate_exec_id','value',$new_id);
827
+				$response->addAssign('etemplate_exec_id', 'value', $new_id);
829 828
 			}
830 829
 		}
831 830
 		return $response->getXML();
@@ -841,7 +840,7 @@  discard block
 block discarded – undo
841 840
 	 * @param string $etemplate_exec_id of the calling etemplate, to upate the allowed ids
842 841
 	 * @return string xajax xml response
843 842
 	 */
844
-	static function ajax_get_types($app,$id_res,$etemplate_exec_id)
843
+	static function ajax_get_types($app, $id_res, $etemplate_exec_id)
845 844
 	{
846 845
 		// open request
847 846
 		if ($etemplate_exec_id) $request = etemplate_request::read($etemplate_exec_id);
@@ -852,16 +851,16 @@  discard block
 block discarded – undo
852 851
 
853 852
 
854 853
 		$script = "var select = document.getElementById('$id_res');\nselect.options.length=0;\n";
855
-		if(is_array(egw_link::$app_register[$app]['types']))
854
+		if (is_array(egw_link::$app_register[$app]['types']))
856 855
 		{
857 856
 			$found = egw_link::$app_register[$app]['types'];
858
-			foreach(egw_link::$app_register[$app]['types'] as $id => $option)
857
+			foreach (egw_link::$app_register[$app]['types'] as $id => $option)
859 858
 			{
860 859
 				$option = array('label' => $option['name']);
861 860
 				$script .= "opt = select.options[select.options.length] = new Option('".addslashes($option['label'])."','".addslashes($id)."');\n";
862 861
 				if (count($option) > 1)
863 862
 				{
864
-					foreach($option as $name => $value)
863
+					foreach ($option as $name => $value)
865 864
 					{
866 865
 						if ($name != 'label') $script .= "opt.$name = '".addslashes($value)."';\n";
867 866
 					}
@@ -881,11 +880,11 @@  discard block
 block discarded – undo
881 880
 			$data = $request->get_to_process($id_res);
882 881
 			//error_log($id_res.'='.array2string($data));
883 882
 			$data['allowed'] = $found ? array_keys($found) : array();
884
-			$request->set_to_process($id_res,$data);
883
+			$request->set_to_process($id_res, $data);
885 884
 			// update id, if request changed it (happens if the request data is stored direct in the form)
886 885
 			if ($etemplate_exec_id != ($new_id = $request->id()))
887 886
 			{
888
-				$response->addAssign('etemplate_exec_id','value',$new_id);
887
+				$response->addAssign('etemplate_exec_id', 'value', $new_id);
889 888
 			}
890 889
 		}
891 890
 		return $response->getXML();
Please login to merge, or discard this patch.
Braces   +136 added lines, -37 removed lines patch added patch discarded remove patch
@@ -176,10 +176,13 @@  discard block
 block discarded – undo
176 176
 					}
177 177
 				}
178 178
 				if (!($popup = egw_link::is_popup($value['app'],'view')) &&
179
-					etemplate::$request->output_mode == 2)	// we are in a popup
179
+					etemplate::$request->output_mode == 2)
180
+				{
181
+					// we are in a popup
180 182
 				{
181 183
 					$target = '_blank';
182 184
 				}
185
+				}
183 186
 				if (!$cell['help'])
184 187
 				{
185 188
 					$cell['help'] = $value['help'];
@@ -197,7 +200,10 @@  discard block
 block discarded – undo
197 200
 			//  size: [b[old]][i[talic]],[link],[activate_links],[label_for],[link_target],[link_popup_size],[link_title]
198 201
 			list($cell['size']) = explode(',',$cell['size']);
199 202
 			// Pass link through framework's handler
200
-			if(!$popup) $link = str_replace(',','%2C',egw::link('/index.php?menuaction='.$link,false,$value['app']));
203
+			if(!$popup)
204
+			{
205
+				$link = str_replace(',','%2C',egw::link('/index.php?menuaction='.$link,false,$value['app']));
206
+			}
201 207
 			$cell['size'] .= ','.$link.',,,'.$target.','.$popup.','.$value['extra_title'];
202 208
 			$value = $value['title'] ? $value['title'] : egw_link::title($value['app'],$value['id']);
203 209
 			return true;
@@ -239,9 +245,12 @@  discard block
 block discarded – undo
239 245
 
240 246
 		case 'link-add':
241 247
 			$apps = egw_link::app_list($type == 'link-add' ? 'add_app' : 'query');
242
-			if (!$apps || !$value['to_id'] || is_array($value['to_id']))	// cant do an add without apps or already created entry
248
+			if (!$apps || !$value['to_id'] || is_array($value['to_id']))
249
+			{
250
+				// cant do an add without apps or already created entry
243 251
 			{
244 252
 				$cell = $tmpl->empty_cell();
253
+			}
245 254
 				return;
246 255
 			}
247 256
 			asort($apps);	// sort them alphabetic
@@ -261,18 +270,30 @@  discard block
 block discarded – undo
261 270
 				}
262 271
 				$value['options-add_app'][$action] = $label;
263 272
 				// modify add_app default to the action used as value
264
-				if (isset($value['add_app']) && $app == $value['add_app']) $value['add_app'] = $action;
273
+				if (isset($value['add_app']) && $app == $value['add_app'])
274
+				{
275
+					$value['add_app'] = $action;
276
+				}
265 277
 			}
266 278
 			$tpl = new etemplate('etemplate.link_widget.add');
267 279
 			break;
268 280
 
269 281
 		case 'link-to':
270 282
 			$GLOBALS['egw_info']['flags']['include_xajax'] = true;
271
-			if ($value['search_label'] && $extension_data['search_label'] != $value['search_label']) $value['search_label'] = lang($value['search_label']);
283
+			if ($value['search_label'] && $extension_data['search_label'] != $value['search_label'])
284
+			{
285
+				$value['search_label'] = lang($value['search_label']);
286
+			}
272 287
 			$extension_data = $value;
273 288
 			$tpl = new etemplate('etemplate.link_widget.to');
274
-			if ($value['link_label']) $tpl->set_cell_attribute('create','label',$value['link_label']);
275
-			if ($value['search_label']) $tpl->set_cell_attribute('search','label',$value['search_label']);
289
+			if ($value['link_label'])
290
+			{
291
+				$tpl->set_cell_attribute('create','label',$value['link_label']);
292
+			}
293
+			if ($value['search_label'])
294
+			{
295
+				$tpl->set_cell_attribute('search','label',$value['search_label']);
296
+			}
276 297
 
277 298
 			self::get_sub_types($cell, $value, $tpl);
278 299
 
@@ -309,9 +330,13 @@  discard block
 block discarded – undo
309 330
 				{
310 331
 					$value[$row]['view']  = egw_link::view($link['app'],$link['id'],$link);
311 332
 					if (!($value[$row]['popup'] = egw_link::is_popup($link['app'],'view',$link)) &&
312
-						etemplate::$request->output_mode == 2)	// we are in a popup
333
+						etemplate::$request->output_mode == 2)
334
+					{
335
+						// we are in a popup
313 336
 					{
314
-						$value[$row]['target'] = '_blank';		// we create a new window as the linked page is no popup
337
+						$value[$row]['target'] = '_blank';
338
+					}
339
+					// we create a new window as the linked page is no popup
315 340
 					}
316 341
 				}
317 342
 				if ($link['app'] == egw_link::VFS_APPNAME)
@@ -348,7 +373,10 @@  discard block
 block discarded – undo
348 373
 			{
349 374
 				if(!is_array($value))
350 375
 				{
351
-					if (strpos($value,':') !== false) list($app,$value) = explode(':',$value,2);
376
+					if (strpos($value,':') !== false)
377
+					{
378
+						list($app,$value) = explode(':',$value,2);
379
+					}
352 380
 					$value = array('app' => $app ? $app : $cell['size'],'id' => $value);
353 381
 				}
354 382
 				$value = self::link2a_href($value,$help);
@@ -371,14 +399,21 @@  discard block
 block discarded – undo
371 399
 				$on_click_string = str_replace(');',','.$value['extra'].');',$on_click_string);
372 400
 				//echo htmlspecialchars($on_click_string);
373 401
 			}
374
-			if ($value)	// show pre-selected entry in select-box and not the search
402
+			if ($value)
403
+			{
404
+				// show pre-selected entry in select-box and not the search
375 405
 			{
376 406
 				if (is_array($value))
377 407
 				{
378 408
 					if (isset($value['current']))
379 409
 					{
380 410
 						list($app,$id) = explode(':',$value['current'], 2);
381
-						if ($app) unset($value['default_sel']);	// would overwrite $app!
411
+			}
412
+						if ($app)
413
+						{
414
+							unset($value['default_sel']);
415
+						}
416
+						// would overwrite $app!
382 417
 					}
383 418
 				}
384 419
 				else
@@ -407,7 +442,10 @@  discard block
 block discarded – undo
407 442
 				}
408 443
 				if ($titles)
409 444
 				{
410
-					if ($cell['onchange']) $titles[0] = lang('Show all / cancel filter');
445
+					if ($cell['onchange'])
446
+					{
447
+						$titles[0] = lang('Show all / cancel filter');
448
+					}
411 449
 					$titles[''] = lang('new search').' ...';
412 450
 					$selectbox =& $tpl->get_widget_by_name('id');
413 451
 					$selectbox['sel_options'] = $titles;
@@ -420,9 +458,12 @@  discard block
 block discarded – undo
420 458
 					unset($span);
421 459
 				}
422 460
 			}
423
-			if ($extension_data['app'] && count($options) <= 1)	// no app-selection, using app given in first option
461
+			if ($extension_data['app'] && count($options) <= 1)
462
+			{
463
+				// no app-selection, using app given in first option
424 464
 			{
425 465
 				$tpl->disable_cells('app');
466
+			}
426 467
 				$onchange =& $tpl->get_cell_attribute('search','onclick');
427 468
 				$onchange = str_replace("document.getElementById(form::name('app')).value",'\''.$cell['size'].'\'',$onchange);
428 469
 				unset($onchange);
@@ -441,17 +482,26 @@  discard block
 block discarded – undo
441 482
 					(count($options) == 1 ? lang($app) : lang('Search')),
442 483
 				'extra'      => $cell['onchange'] ? ','.self::AJAX_NEED_ONCHANGE : null,	// store flang for ajax_search, to display extra_line required by onchange
443 484
 			);
444
-			if ($cell['needed']) $value['class'] = 'inputRequired';
485
+			if ($cell['needed'])
486
+			{
487
+				$value['class'] = 'inputRequired';
488
+			}
445 489
 
446
-			if ($options)	// limit the app-selectbox to the given apps
490
+			if ($options)
491
+			{
492
+				// limit the app-selectbox to the given apps
447 493
 			{
448 494
 				$tpl->set_cell_attribute('app','type','select');
495
+			}
449 496
 				$tpl->set_cell_attribute('app','no_lang',true);
450 497
 				$apps = egw_link::app_list('query');
451 498
 				asort($apps);	// sort them alphabetic
452 499
 				foreach($apps as $app => $label)
453 500
 				{
454
-					if (!in_array($app,$options)) unset($apps[$app]);
501
+					if (!in_array($app,$options))
502
+					{
503
+						unset($apps[$app]);
504
+					}
455 505
 				}
456 506
 				$value['options-app'] = $apps;
457 507
 			}
@@ -462,9 +512,12 @@  discard block
 block discarded – undo
462 512
 
463 513
 		case 'link-apps':
464 514
 			$apps = egw_link::app_list($cell['size'] ? $cell['size'] : 'query');
465
-			if (!$apps)	// cant do an add without apps or already created entry
515
+			if (!$apps)
516
+			{
517
+				// cant do an add without apps or already created entry
466 518
 			{
467 519
 				$cell = $tmpl->empty_cell();
520
+			}
468 521
 				return;
469 522
 			}
470 523
 			asort($apps);	// sort them alphabetic
@@ -503,10 +556,13 @@  discard block
 block discarded – undo
503 556
 		}
504 557
 		elseif (etemplate::$request->output_mode == 2 || 	// we are in a popup
505 558
 			$link['app'] == egw_link::VFS_APPNAME ||		// or it's a link to an attachment
506
-			($target = egw_link::get_registry($link['app'],'view_target')))	// or explicit target set
559
+			($target = egw_link::get_registry($link['app'],'view_target')))
560
+		{
561
+			// or explicit target set
507 562
 		{
508 563
 			$options = ' target="'.($target ? $target : '_blank').'"';
509 564
 		}
565
+		}
510 566
 		else
511 567
 		{
512 568
 			// Pass link through framework's handler
@@ -562,9 +618,12 @@  discard block
 block discarded – undo
562 618
 						if ($v)
563 619
 						{
564 620
 							$defaultData=true;
565
-							if ($k==0 && !empty($value_in['id'])) // we have a valid incomming id, we intend to use that
621
+							if ($k==0 && !empty($value_in['id']))
622
+							{
623
+								// we have a valid incomming id, we intend to use that
566 624
 							{
567 625
 								$defaultData=false;
626
+							}
568 627
 								continue;
569 628
 							}
570 629
 							break;
@@ -575,7 +634,10 @@  discard block
 block discarded – undo
575 634
 						$value = $extension_data['default'];
576 635
 						$value['current'] = $extension_data['app'] ? $value_in['id'] : $value_in['app'].':'.$value_in['id'];
577 636
 						// we take care for id, in case it is empty AND needed
578
-						if(empty($value['id']) && $extension_data['needed']) $value['id'] = $value['current'];
637
+						if(empty($value['id']) && $extension_data['needed'])
638
+						{
639
+							$value['id'] = $value['current'];
640
+						}
579 641
 					}
580 642
 				}
581 643
 				if($defaultData === false)
@@ -620,10 +682,13 @@  discard block
 block discarded – undo
620 682
 		switch ($button)
621 683
 		{
622 684
 			case 'create':
623
-				if ($value['to_app'])						// make the link
685
+				if ($value['to_app'])
686
+				{
687
+					// make the link
624 688
 				{
625 689
 					$link_id = egw_link::link($value['to_app'],$value['to_id'],
626 690
 						$value['app'],$value['id'],$value['remark']);
691
+				}
627 692
 					$value['remark'] = $value['query'] = '';
628 693
 
629 694
 					if (isset($value['primary']) && !$value['anz_links'] )
@@ -643,11 +708,14 @@  discard block
 block discarded – undo
643 708
 				if (is_array($value['file']) && $value['to_app'] &&
644 709
 					!empty($value['file']['tmp_name']) && $value['file']['tmp_name'] != 'none')
645 710
 				{
646
-					if (!$value['to_id'] || is_array($value['to_id']))	// otherwise the webserver deletes the file
711
+					if (!$value['to_id'] || is_array($value['to_id']))
712
+					{
713
+						// otherwise the webserver deletes the file
647 714
 					{
648 715
 						if (is_dir($GLOBALS['egw_info']['server']['temp_dir']) && is_writable($GLOBALS['egw_info']['server']['temp_dir']))
649 716
 						{
650 717
 							$new_file = tempnam($GLOBALS['egw_info']['server']['temp_dir'],'egw_');
718
+					}
651 719
 						}
652 720
 						else
653 721
 						{
@@ -685,7 +753,10 @@  discard block
 block discarded – undo
685 753
 				if ($this->debug)
686 754
 				{
687 755
 					//echo "<p>unlink(link-id=$unlink,$value[to_app],$value[to_id])</p>\n";
688
-					if (is_array($value['to_id'])) _debug_array($value['to_id']);
756
+					if (is_array($value['to_id']))
757
+					{
758
+						_debug_array($value['to_id']);
759
+					}
689 760
 				}
690 761
 				egw_link::unlink2($unlink,$value['to_app'],$value['to_id']);
691 762
 				if (is_array($value['to_id']))
@@ -707,18 +778,24 @@  discard block
 block discarded – undo
707 778
 	/**
708 779
 	*	Get sub-types for the current application
709 780
 	*/
710
-	private static function get_sub_types($cell, &$value, &$tpl) {
781
+	private static function get_sub_types($cell, &$value, &$tpl)
782
+	{
711 783
 		// Get sub-types
712
-		if($value['options-app']) {
784
+		if($value['options-app'])
785
+		{
713 786
 			$apps = $value['options-app'];
714
-		} else {
787
+		}
788
+		else
789
+		{
715 790
 			$apps = egw_link::app_list($cell['size'] ? $cell['size'] : 'query');
716 791
 			asort($apps);	// sort them alphabetic
717 792
 		}
718 793
 
719 794
 		$current_app = $value['app'] ? $value['app'] : key($apps);
720
-		if(is_array(egw_link::$app_register[$current_app]['types'])) {
721
-			foreach(egw_link::$app_register[$current_app]['types'] as $key => $settings) {
795
+		if(is_array(egw_link::$app_register[$current_app]['types']))
796
+		{
797
+			foreach(egw_link::$app_register[$current_app]['types'] as $key => $settings)
798
+			{
722 799
 				$value['options-link_type'][$key] = $settings['name'];
723 800
 			}
724 801
 			$span =& $tpl->get_cell_attribute('type_box','span');
@@ -752,7 +829,10 @@  discard block
 block discarded – undo
752 829
 			// securize entries as they were html encoded and so not checked on the first pass
753 830
 			_check_script_tag($extra_array,'extra_array');
754 831
 		}
755
-		if ($pattern == lang('Search') || $pattern == lang($app)) $pattern = '';
832
+		if ($pattern == lang('Search') || $pattern == lang($app))
833
+		{
834
+			$pattern = '';
835
+		}
756 836
 		if (empty($extra_array))
757 837
 		{
758 838
 			$search = $pattern;
@@ -763,18 +843,25 @@  discard block
 block discarded – undo
763 843
 			$search = $extra_array;
764 844
 		}
765 845
 		// open request
766
-		if ($etemplate_exec_id) $request = etemplate_request::read($etemplate_exec_id);
846
+		if ($etemplate_exec_id)
847
+		{
848
+			$request = etemplate_request::read($etemplate_exec_id);
849
+		}
767 850
 
768 851
 		$response = new xajaxResponse();
769 852
 		$options = array();
770 853
 		//$args = func_get_args(); $response->addAlert("link_widget::ajax_search('".implode("',\n'",$args)."')\n calling link->query( $app , $search, $type )" );
771 854
 		//$args = func_get_args(); error_log(__METHOD__."('".implode("','",$args)."')");
772
-		if($type) {
855
+		if($type)
856
+		{
773 857
 			$options['type'] = $type;
774 858
 		}
775
-		if (!($found = egw_link::query($app,$search,$options)))       // ignore the blur-text
859
+		if (!($found = egw_link::query($app,$search,$options)))
860
+		{
861
+			// ignore the blur-text
776 862
 		{
777 863
 			$GLOBALS['egw']->translation->add_app('etemplate');
864
+		}
778 865
 			$response->addAlert(lang('Nothing found - try again !!!'));
779 866
 			$response->addScript("document.getElementById('$id_input').select();");
780 867
 		}
@@ -789,7 +876,10 @@  discard block
 block discarded – undo
789 876
 			}
790 877
 			foreach($found as $id => $option)
791 878
 			{
792
-				if (!is_array($option)) $option = array('label' => $option);
879
+				if (!is_array($option))
880
+				{
881
+					$option = array('label' => $option);
882
+				}
793 883
 				// xajax uses xml to transport the label, therefore we have to replace not only CR, LF
794 884
 				// (not allowed unencoded in Javascript strings) but also all utf-8 C0 and C1 plus CR and LF
795 885
 				$option['label'] = preg_replace('/[\000-\037\177-\237]/u',' ',$option['label']);
@@ -799,7 +889,10 @@  discard block
 block discarded – undo
799 889
 				{
800 890
 					foreach($option as $name => $value)
801 891
 					{
802
-						if ($name != 'label') $script .= "opt.$name = '".addslashes($value)."';\n";
892
+						if ($name != 'label')
893
+						{
894
+							$script .= "opt.$name = '".addslashes($value)."';\n";
895
+						}
803 896
 					}
804 897
 				}
805 898
 			}
@@ -844,7 +937,10 @@  discard block
 block discarded – undo
844 937
 	static function ajax_get_types($app,$id_res,$etemplate_exec_id)
845 938
 	{
846 939
 		// open request
847
-		if ($etemplate_exec_id) $request = etemplate_request::read($etemplate_exec_id);
940
+		if ($etemplate_exec_id)
941
+		{
942
+			$request = etemplate_request::read($etemplate_exec_id);
943
+		}
848 944
 
849 945
 		$response = new xajaxResponse();
850 946
 		//$args = func_get_args(); $response->addAlert("link_widget::ajax_search('".implode("',\n'",$args)."')\n calling link->query( $app , $search )" );
@@ -863,7 +959,10 @@  discard block
 block discarded – undo
863 959
 				{
864 960
 					foreach($option as $name => $value)
865 961
 					{
866
-						if ($name != 'label') $script .= "opt.$name = '".addslashes($value)."';\n";
962
+						if ($name != 'label')
963
+						{
964
+							$script .= "opt.$name = '".addslashes($value)."';\n";
965
+						}
867 966
 					}
868 967
 				}
869 968
 			}
Please login to merge, or discard this patch.
etemplate/inc/class.nextmatch_widget.inc.php 3 patches
Doc Comments   +14 added lines, -21 removed lines patch added patch discarded remove patch
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 	 *
148 148
 	 * @param string $name
149 149
 	 * @param int $offset positive or negative offset (negative is count from the end)
150
-	 * @param int $length=null positiv means return $length elements, negative return til negative offset in $length, default = null means all
150
+	 * @param integer $length positiv means return $length elements, negative return til negative offset in $length, default = null means all
151 151
 	 * @return array
152 152
 	 */
153 153
 	static private function get_parts($name,$offset,$length=null)
@@ -618,8 +618,7 @@  discard block
 block discarded – undo
618 618
 	 * @param string $template_name='' name of the template, used as default for app name of images
619 619
 	 * @param string $prefix='' prefix for ids
620 620
 	 * @param array &$action_links=array() on return all first-level actions plus the ones with enabled='javaScript:...'
621
-	 * @param int $max_length=self::DEFAULT_MAX_MENU_LENGTH automatic pagination, not for first menu level!
622
-	 * @param array $default_attrs=null default attributes
621
+	 * @param array $default_attrs default attributes
623 622
 	 * @return array
624 623
 	 */
625 624
 	public static function egw_actions(array $actions=null, $template_name='', $prefix='', array &$action_links=array(),
@@ -770,12 +769,9 @@  discard block
 block discarded – undo
770 769
 	 * Automatic switch to hierarchical display, if more than $max_cats_flat=14 cats found.
771 770
 	 *
772 771
 	 * @param string $app
773
-	 * @param int $group=0 see self::egw_actions
774
-	 * @param string $caption='Change category'
775
-	 * @param string $prefix='cat_' prefix category id to get action id
776
-	 * @param boolean $globals=true application global categories too
777
-	 * @param int $parent_id=0 only returns cats of a certain parent
778
-	 * @param int $max_cats_flat=self::DEFAULT_MAX_MENU_LENGTH use hierarchical display if more cats
772
+	 * @param int $group see self::egw_actions
773
+	 * @param boolean $globals application global categories too
774
+	 * @param int $parent_id only returns cats of a certain parent
779 775
 	 * @param boolean $none_option = true Include an option 'None' to clear category
780 776
 	 * @return array like self::egw_actions
781 777
 	 */
@@ -828,9 +824,8 @@  discard block
 block discarded – undo
828 824
 	/**
829 825
 	 * Return one level of the category hierarchy
830 826
 	 *
831
-	 * @param array $cats=null all cats if already read
832
-	 * @param string $prefix='cat_' prefix category id to get action id
833
-	 * @param int $parent_id=0 only returns cats of a certain parent
827
+	 * @param int $parent_id only returns cats of a certain parent
828
+	 * @param string $prefix
834 829
 	 * @return array
835 830
 	 */
836 831
 	private static function category_hierarchy(array $cats, $prefix, $parent_id=0)
@@ -875,10 +870,9 @@  discard block
 block discarded – undo
875 870
 	 *
876 871
 	 * Gets called from etemplate::show_grid() and addressbook_ui::view (without arguments).
877 872
 	 *
878
-	 * @param array $actions=null
879
-	 * @param array $action_links=null
873
+	 * @param array $actions
874
+	 * @param array $action_links
880 875
 	 * @param string $template_name='' name of the template, used as default for app name of images - e.g. infolog.index.rows
881
-	 * @param string $prefix='egw_' JS action objects generated for this widget are prefixed with given prefix
882 876
 	 */
883 877
 	public static function init_egw_actions(array $actions=null, $action_links=null, $template_name='', $prefix='egw_')
884 878
 	{
@@ -950,8 +944,7 @@  discard block
 block discarded – undo
950 944
 	 * @param array &$value
951 945
 	 * @param array &$rows=null
952 946
 	 * @param array &$readonlys=null
953
-	 * @param object $obj=null (internal)
954
-	 * @param string|array $method=null (internal)
947
+	 * @param string|array $method (internal)
955 948
 	 * @return int|boolean total items found of false on error ($value['get_rows'] not callable)
956 949
 	 */
957 950
 	private static function call_get_rows(array &$value,array &$rows=null,array &$readonlys=null,$obj=null,$method=null)
@@ -1538,7 +1531,7 @@  discard block
 block discarded – undo
1538 1531
 	 * @param array $row0 first row to guess the available fields
1539 1532
 	 * @param array $fields name=>label or name=>array('lable'=>label,'type'=>type) pairs
1540 1533
 	 * @param string $app app-name
1541
-	 * @param string $charset_out=null output charset
1534
+	 * @param string $charset_out output charset
1542 1535
 	 * @param string $charset data charset
1543 1536
 	 * @param string $separator=';'
1544 1537
 	 * @return FILE
@@ -1570,9 +1563,9 @@  discard block
 block discarded – undo
1570 1563
 	 *
1571 1564
 	 * @param array $data
1572 1565
 	 * @param array $fields
1573
-	 * @param boolean $use_type=true
1574
-	 * @param array $extra_sel_options=null
1575
-	 * @param string $charset_out=null output charset
1566
+	 * @param boolean $use_type
1567
+	 * @param array $extra_sel_options
1568
+	 * @param string $charset_out output charset
1576 1569
 	 * @param string $charset data charset
1577 1570
 	 * @param string $separator=';'
1578 1571
 	 * @return string
Please login to merge, or discard this patch.
Spacing   +255 added lines, -255 removed lines patch added patch discarded remove patch
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
 	 */
139 139
 	static private function last_part($name)
140 140
 	{
141
-		list($last) = self::get_parts($name,-1,1);
141
+		list($last) = self::get_parts($name, -1, 1);
142 142
 		return $last;
143 143
 	}
144 144
 
@@ -150,11 +150,11 @@  discard block
 block discarded – undo
150 150
 	 * @param int $length=null positiv means return $length elements, negative return til negative offset in $length, default = null means all
151 151
 	 * @return array
152 152
 	 */
153
-	static private function get_parts($name,$offset,$length=null)
153
+	static private function get_parts($name, $offset, $length = null)
154 154
 	{
155
-		$parts = explode('[',str_replace(']','',$name));
155
+		$parts = explode('[', str_replace(']', '', $name));
156 156
 		// php5.1 seems to have a bug: array_slice($parts,$offeset) != array_slice($parts,$offeset,null)
157
-		return is_null($length) ? array_slice($parts,$offset) : array_slice($parts,$offset,$length);
157
+		return is_null($length) ? array_slice($parts, $offset) : array_slice($parts, $offset, $length);
158 158
 	}
159 159
 
160 160
 	/**
@@ -164,12 +164,12 @@  discard block
 block discarded – undo
164 164
 	 * @param string $type
165 165
 	 * @return mixed reference to storage: use =& to assign!
166 166
 	 */
167
-	static private function &get_nm_global($name,$type)
167
+	static private function &get_nm_global($name, $type)
168 168
 	{
169 169
 		static $nm_globals = array();
170 170
 
171 171
 		// extract the original nextmatch name from $name, taken into account the type of nextmatch-* subwidgets
172
-		$nm_global = implode('/',self::get_parts($name,1,$type == 'nextmatch' ? null : -2));
172
+		$nm_global = implode('/', self::get_parts($name, 1, $type == 'nextmatch' ? null : -2));
173 173
 		//echo '<p>'.__METHOD__."($name,$type) = $nm_global</p>\n";
174 174
 
175 175
 		return $nm_globals[$nm_global];
@@ -188,9 +188,9 @@  discard block
 block discarded – undo
188 188
 	 * @param etemplate &$tmpl reference to the template we belong too
189 189
 	 * @return boolean true if extra label is allowed, false otherwise
190 190
 	 */
191
-	public function pre_process($name,&$value,array &$cell,&$readonlys,&$extension_data,$tmpl)
191
+	public function pre_process($name, &$value, array &$cell, &$readonlys, &$extension_data, $tmpl)
192 192
 	{
193
-		$nm_global =& self::get_nm_global($name,$cell['type']);
193
+		$nm_global = & self::get_nm_global($name, $cell['type']);
194 194
 		//echo "<p>nextmatch_widget.pre_process(name='$name',type='$cell[type]'): value = "; _debug_array($value);
195 195
 		//echo "<p>nextmatch_widget.pre_process(name='$name',type='$cell[type]'): nm_global = "; _debug_array($nm_global);
196 196
 
@@ -201,10 +201,10 @@  discard block
 block discarded – undo
201 201
 		{
202 202
 			case 'nextmatch-header':
203 203
 				$cell['type'] = 'label';
204
-				return true;	// false = no extra label
204
+				return true; // false = no extra label
205 205
 
206 206
 			case 'nextmatch-sortheader':	// Option: default sort: ASC(default) or DESC
207
-				$extension_data['default_sort'] = $cell['size']&&preg_match('/^(ASC|DESC)/i',$cell['size'],$matches) ? strtoupper($matches[1]) : 'ASC';
207
+				$extension_data['default_sort'] = $cell['size'] && preg_match('/^(ASC|DESC)/i', $cell['size'], $matches) ? strtoupper($matches[1]) : 'ASC';
208 208
 				$cell['type'] = $cell['readonly'] ? 'label' : 'button';
209 209
 				$cell['onchange'] = True;
210 210
 				if (!$cell['help'])
@@ -216,11 +216,11 @@  discard block
 block discarded – undo
216 216
 					$sorting = $cell;
217 217
 					unset($sorting['align']);
218 218
 					unset($sorting['span']);
219
-					$cell = boetemplate::empty_cell('hbox','',array(
219
+					$cell = boetemplate::empty_cell('hbox', '', array(
220 220
 						'span' => $cell['span'],
221 221
 						'size' => '2,,0,0',
222 222
 						1 => $sorting,
223
-						2 => boetemplate::empty_cell('image',$nm_global['sort'] != 'DESC' ? 'down' : 'up'),
223
+						2 => boetemplate::empty_cell('image', $nm_global['sort'] != 'DESC' ? 'down' : 'up'),
224 224
 					));
225 225
 					$class = 'activ_sortcolumn';
226 226
 				}
@@ -228,16 +228,16 @@  discard block
 block discarded – undo
228 228
 				{
229 229
 					$class = 'inactiv_sortcolumn';
230 230
 				}
231
-				$parts = explode(',',$cell['span']);
231
+				$parts = explode(',', $cell['span']);
232 232
 				$parts[1] .= ($parts[1] ? ' ' : '').$class;
233
-				$cell['span'] = implode(',',$parts);
233
+				$cell['span'] = implode(',', $parts);
234 234
 				return True;
235 235
 
236 236
 			case 'nextmatch-accountfilter':	// Option: as for selectbox: [extra-label(default ALL)[,#lines(default 1)]]
237 237
 				$cell['size'] = 'select-account,'.$cell['size'];
238 238
 				// fall through
239 239
 			case 'nextmatch-customfilter':	// Option: widget-name, options as for selectbox
240
-				list($type,$cell['size']) = explode(',',$cell['size'],2);
240
+				list($type, $cell['size']) = explode(',', $cell['size'], 2);
241 241
 				// fall through
242 242
 			case 'nextmatch-filterheader':	// Option: as for selectbox: [extra-label(default ALL)[,#lines(default 1)]]
243 243
 				if (!$type) $type = 'select';
@@ -251,52 +251,52 @@  discard block
 block discarded – undo
251 251
 					$cell['help'] = 'select which values to show';
252 252
 				}
253 253
 				$cell['onchange'] = $cell['noprint'] = True;
254
-				$parts = explode(',',$cell['span']);
254
+				$parts = explode(',', $cell['span']);
255 255
 				$parts[1] .= ($parts[1] ? ' ' : '').'filterheader';
256
-				$cell['span'] = implode(',',$parts);
256
+				$cell['span'] = implode(',', $parts);
257 257
 				$extension_data['old_value'] = $value = $nm_global['col_filter'][self::last_part($name)];
258 258
 				return True;
259 259
 
260 260
 			case 'nextmatch-customfields':
261
-				$extra_label = $this->pre_process_cf_header($cell,$tmpl, $value, $nm_global);
261
+				$extra_label = $this->pre_process_cf_header($cell, $tmpl, $value, $nm_global);
262 262
 				$extension_data['old_value'] = $value;
263 263
 				return $extra_label;
264 264
 		}
265 265
 
266 266
 		// does NOT work with php5.2.6+
267
-		if (version_compare(PHP_VERSION,'5.2.6','>='))
267
+		if (version_compare(PHP_VERSION, '5.2.6', '>='))
268 268
 		{
269 269
 			$value['bottom_too'] = false;
270 270
 		}
271 271
 		// presetting the selectboxes with their default values, to NOT loop, because post-process thinks they changed
272 272
 		if (!isset($value['cat_id'])) $value['cat_id'] = '';
273 273
 		if (!isset($value['search'])) $value['search'] = '';
274
-		foreach(array('filter','filter2') as $f)
274
+		foreach (array('filter', 'filter2') as $f)
275 275
 		{
276 276
 			if (!isset($value[$f]))
277 277
 			{
278 278
 				list($value[$f]) = isset($tmpl->sel_options[$f]) ? @each($tmpl->sel_options[$f]) : @each($value['options-'.$f]);
279
-				if (!is_string($value[$f])) $value[$f] = (string) $value[$f];
279
+				if (!is_string($value[$f])) $value[$f] = (string)$value[$f];
280 280
 			}
281 281
 		}
282 282
 		// save values in persistent extension_data to be able use it in post_process
283 283
 		unset($value['rows']);
284 284
 		$extension_data += $value;
285
-		list($app) = explode('.',$tmpl->name);
285
+		list($app) = explode('.', $tmpl->name);
286 286
 		$export_limit = bo_merge::getExportLimit($app);
287 287
 		$value['no_csv_export'] = $value['csv_fields'] === false ||
288
-			!bo_merge::hasExportLimit($export_limit,'ISALLOWED') &&
288
+			!bo_merge::hasExportLimit($export_limit, 'ISALLOWED') &&
289 289
 			!bo_merge::is_export_limit_excepted();
290 290
 
291 291
 		if (!$value['filter_onchange']) $value['filter_onchange'] = 'this.form.submit();';
292 292
 		if (!$value['filter2_onchange']) $value['filter2_onchange'] = 'this.form.submit();';
293
-		if (!isset($value['cat_app'])) list($value['cat_app']) = explode('.',$value['get_rows']);	// if no cat_app set, use the app from the get_rows func
293
+		if (!isset($value['cat_app'])) list($value['cat_app']) = explode('.', $value['get_rows']); // if no cat_app set, use the app from the get_rows func
294 294
 
295 295
 		if (!($max = (int)$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'])) $max = 15;
296 296
 		$row_options = array();
297
-		foreach(array(5,12,25,50,100,200,500,999) as $n)
297
+		foreach (array(5, 12, 25, 50, 100, 200, 500, 999) as $n)
298 298
 		{
299
-			if ($n-5 <= $max && $max <= $n+5) $n = $max;
299
+			if ($n - 5 <= $max && $max <= $n + 5) $n = $max;
300 300
 			$row_options[$n] = $n;
301 301
 		}
302 302
 		if (!isset($value['num_rows']) || $value['num_rows'] <= 0)	// can be -1 if importexport crashes
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 			$row_options[$value['num_rows']] = $value['num_rows'];
310 310
 			ksort($row_options);
311 311
 		}
312
-		$value['options-num_rows'] =& $row_options;
312
+		$value['options-num_rows'] = & $row_options;
313 313
 
314 314
 		if ($value['num_rows'] != $max)
315 315
 		{
@@ -322,21 +322,21 @@  discard block
 block discarded – undo
322 322
 		}
323 323
 		$rows = array();
324 324
 		if (!is_array($readonlys)) $readonlys = array();
325
-		if (($total = $extension_data['total'] = $value['total'] = self::call_get_rows($value,$rows,$readonlys['rows'])) === false)
325
+		if (($total = $extension_data['total'] = $value['total'] = self::call_get_rows($value, $rows, $readonlys['rows'])) === false)
326 326
 		{
327 327
 			//error_log(__METHOD__."() etemplate::set_validation_error('$name') '$value[get_rows]' is no valid method!!!");
328
-			etemplate::set_validation_error($name,__METHOD__."($cell[name]): '$value[get_rows]' is no valid method !!!");
328
+			etemplate::set_validation_error($name, __METHOD__."($cell[name]): '$value[get_rows]' is no valid method !!!");
329 329
 		}
330 330
 		// allow the get_rows function to override / set sel_options
331 331
 		if (isset($rows['sel_options']) && is_array($rows['sel_options']))
332 332
 		{
333
-			$tmpl->sel_options = array_merge($tmpl->sel_options,$rows['sel_options']);
333
+			$tmpl->sel_options = array_merge($tmpl->sel_options, $rows['sel_options']);
334 334
 			unset($rows['sel_options']);
335 335
 		}
336
-		$value['rows'] =& $rows;
336
+		$value['rows'] = & $rows;
337 337
 		unset($rows);
338 338
 
339
-		list($template,$hide_header,$header_left,$header_right) = explode(',',$cell['size']);
339
+		list($template, $hide_header, $header_left, $header_right) = explode(',', $cell['size']);
340 340
 		if ($header_left) $value['header_left'] = $header_left;
341 341
 		if ($header_right) $value['header_right'] = $header_right;
342 342
 		if ((string)$hide_header !== '') $value['hide_header'] = $hide_header;
@@ -347,21 +347,21 @@  discard block
 block discarded – undo
347 347
 		}
348 348
 		if (!is_object($value['template']))
349 349
 		{
350
-			$value['template'] = new etemplate($value['template'],$tmpl->as_array());
350
+			$value['template'] = new etemplate($value['template'], $tmpl->as_array());
351 351
 		}
352 352
 		if (is_array($value['rows'][0]))	// pad 0 based arrays with rows-1 false values
353 353
 		{
354
-			for($i = 1; $i < $value['template']->rows; $i++)
354
+			for ($i = 1; $i < $value['template']->rows; $i++)
355 355
 			{
356
-				array_unshift($value['rows'],false);
356
+				array_unshift($value['rows'], false);
357 357
 			}
358 358
 		}
359
-		$extension_data['template'] = $value['template']->name;	// used for the column-selection, and might be set in get_rows()
359
+		$extension_data['template'] = $value['template']->name; // used for the column-selection, and might be set in get_rows()
360 360
 		$extension_data['columnselection_pref'] = $value['columnselection_pref'];
361 361
 
362 362
 		if ($total < 1 && $value['template']->rows > 1)
363 363
 		{
364
-			$value['template']->data[0]['h'.$value['template']->rows] .= ',1';	// disable the last data row
364
+			$value['template']->data[0]['h'.$value['template']->rows] .= ',1'; // disable the last data row
365 365
 		}
366 366
 		if (!$value['never_hide'] && $total <= $max && $value['hide_header'] && $value['search'] == '' &&
367 367
 			 ($value['no_cat'] || !$value['cat_id']) &&
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
 				$cell['size'] = $cell['name'].'[rows]';
381 381
 				$cell['obj'] = &$value['template'];
382 382
 				$cell['name'] = $value['template']->name;
383
-				$cell['span'] .= (strpos($cell['span'],',') === false ? ',' : '').' egwGridView_grid';
383
+				$cell['span'] .= (strpos($cell['span'], ',') === false ? ',' : '').' egwGridView_grid';
384 384
 			}
385 385
 		}
386 386
 		else
@@ -390,58 +390,58 @@  discard block
 block discarded – undo
390 390
 			$nextmatch->no_onclick = true;
391 391
 
392 392
 			// category is a selectbox, not a category select widget
393
-			if ($value['cat_is_select'] && ($cat_widget =& $nextmatch->get_widget_by_name('cat_id')))
393
+			if ($value['cat_is_select'] && ($cat_widget = & $nextmatch->get_widget_by_name('cat_id')))
394 394
 			{
395 395
 				$cat_widget['type'] = 'select';
396 396
 				if ($value['cat_is_select'] == 'no_lang') $cat_widget['no_lang'] = true;
397 397
 			}
398 398
 			if ($value['lettersearch'])
399 399
 			{
400
-				$lettersearch =& $nextmatch->get_widget_by_name('lettersearch');	// hbox for the letters
400
+				$lettersearch = & $nextmatch->get_widget_by_name('lettersearch'); // hbox for the letters
401 401
 				if (($alphabet = lang('alphabet')) == 'alphabet*') $alphabet = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z';
402
-				$alphabet = explode(',',$alphabet);
402
+				$alphabet = explode(',', $alphabet);
403 403
 				$alphabet['all'] = lang('all');
404
-				foreach($alphabet as $key => $letter)
404
+				foreach ($alphabet as $key => $letter)
405 405
 				{
406 406
 					// make each letter internally behave like a button
407 407
 					$form_name = $name.'[searchletter]['.($key === 'all' ? $key : $letter).']';
408
-					etemplate::$request->set_to_process($form_name,'button');
408
+					etemplate::$request->set_to_process($form_name, 'button');
409 409
 
410
-					if (!$key) $letterbox =& $lettersearch[1];	// to re-use the first child
411
-					$letterbox = boetemplate::empty_cell('label',$letter,array(
410
+					if (!$key) $letterbox = & $lettersearch[1]; // to re-use the first child
411
+					$letterbox = boetemplate::empty_cell('label', $letter, array(
412 412
 						'label'   => $letter,
413
-						'span'    => ',lettersearch'.($letter == (string) $value['searchletter'] ||
413
+						'span'    => ',lettersearch'.($letter == (string)$value['searchletter'] ||
414 414
 							$key === 'all' && !$value['searchletter'] ? '_active' : ''),
415 415
 						'no_lang' => 2,
416 416
 						'align'   => $key == 'all' ? 'right' : '',
417 417
 						'onclick' => 'return submitit('.etemplate::$name_form.",'$form_name');",
418 418
 					));
419 419
 					// if not the first (re-used) child, add it to the parent
420
-					if ($key) boetemplate::add_child($lettersearch,$letterbox);
420
+					if ($key) boetemplate::add_child($lettersearch, $letterbox);
421 421
 					unset($letterbox);
422 422
 				}
423 423
 				//_debug_array(etemplate::$request->to_process);
424 424
 			}
425
-			if(isset($value['no_search'])) $value['no_start_search'] = $value['no_search'];
426
-			foreach(array('no_cat'=>'cat_id','no_filter'=>'filter','no_filter2'=>'filter2', 'no_search' => 'search', 'no_start_search' => 'start_search' ) as $val_name => $cell_name)
425
+			if (isset($value['no_search'])) $value['no_start_search'] = $value['no_search'];
426
+			foreach (array('no_cat'=>'cat_id', 'no_filter'=>'filter', 'no_filter2'=>'filter2', 'no_search' => 'search', 'no_start_search' => 'start_search') as $val_name => $cell_name)
427 427
 			{
428
-				if (isset($value[$val_name])) $nextmatch->disable_cells($cell_name,$value[$val_name]);
428
+				if (isset($value[$val_name])) $nextmatch->disable_cells($cell_name, $value[$val_name]);
429 429
 			}
430
-			foreach(array('header_left','header_right') as $name)
430
+			foreach (array('header_left', 'header_right') as $name)
431 431
 			{
432 432
 				if (!$value[$name]) $nextmatch->disable_cells('@'.$name);
433 433
 			}
434
-			foreach(array('filter','filter2') as $cell_name)
434
+			foreach (array('filter', 'filter2') as $cell_name)
435 435
 			{
436
-				if (isset($value[$cell_name.'_no_lang'])) $nextmatch->set_cell_attribute($cell_name,'no_lang',$value[$cell_name.'_no_lang']);
436
+				if (isset($value[$cell_name.'_no_lang'])) $nextmatch->set_cell_attribute($cell_name, 'no_lang', $value[$cell_name.'_no_lang']);
437 437
 			}
438 438
 			$start = $value['start'];
439
-			$end   = $start+$max > $total ? $total : $start+$max;
440
-			$value['range'] = $total ? (1+$start) . ' - ' . $end : '0';
441
-			$nextmatch->set_cell_attribute('first','readonly',$start <= 0);
442
-			$nextmatch->set_cell_attribute('left', 'readonly',$start <= 0);
443
-			$nextmatch->set_cell_attribute('right','readonly',$start+$max >= $total);
444
-			$nextmatch->set_cell_attribute('last', 'readonly',$start+$max >= $total);
439
+			$end   = $start + $max > $total ? $total : $start + $max;
440
+			$value['range'] = $total ? (1 + $start).' - '.$end : '0';
441
+			$nextmatch->set_cell_attribute('first', 'readonly', $start <= 0);
442
+			$nextmatch->set_cell_attribute('left', 'readonly', $start <= 0);
443
+			$nextmatch->set_cell_attribute('right', 'readonly', $start + $max >= $total);
444
+			$nextmatch->set_cell_attribute('last', 'readonly', $start + $max >= $total);
445 445
 
446 446
 			$cell['size'] = $cell['name'];
447 447
 			$cell['obj'] = &$nextmatch;
@@ -451,11 +451,11 @@  discard block
 block discarded – undo
451 451
 		if (!$value['no_columnselection'])
452 452
 		{
453 453
 			$name = is_object($value['template']) ? $value['template']->name : $value['template'];
454
-			list($app) = explode('.',$name);
454
+			list($app) = explode('.', $name);
455 455
 			if (isset($value['columnselection_pref'])) $name = $value['columnselection_pref'];
456 456
 			$this->selectcols = $value['selectcols'] = $GLOBALS['egw_info']['user']['preferences'][$app]['nextmatch-'.$name];
457 457
 			// fetching column-names & -labels from the template
458
-			if ($this->cols_from_tpl($value['template'],$value['options-selectcols'],$name2col,$value['rows'],$value['selectcols']))
458
+			if ($this->cols_from_tpl($value['template'], $value['options-selectcols'], $name2col, $value['rows'], $value['selectcols']))
459 459
 			{
460 460
 				//_debug_array($name2col);
461 461
 				//_debug_array($value['options-selectcols']);
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
 					{
468 468
 						if ($value['default_cols'][0] == '!')
469 469
 						{
470
-							$value['selectcols'] = array_diff($value['selectcols'],explode(',',substr($value['default_cols'],1)));
470
+							$value['selectcols'] = array_diff($value['selectcols'], explode(',', substr($value['default_cols'], 1)));
471 471
 						}
472 472
 						else
473 473
 						{
@@ -476,27 +476,27 @@  discard block
 block discarded – undo
476 476
 					}
477 477
 					$this->selectcols = $value['selectcols'];
478 478
 				}
479
-				if (!is_array($value['selectcols'])) $value['selectcols'] = explode(',',$value['selectcols']);
480
-				foreach(array_unique(array_keys($value['options-selectcols']+$name2col)) as $name)
479
+				if (!is_array($value['selectcols'])) $value['selectcols'] = explode(',', $value['selectcols']);
480
+				foreach (array_unique(array_keys($value['options-selectcols'] + $name2col)) as $name)
481 481
 				{
482 482
 					// set 'no_'.$col for each column-name to true, if the column is not selected
483 483
 					// (and the value is not set be the get_rows function / programmer!)
484
-					if (!isset($value['rows']['no_'.$name])) $value['rows']['no_'.$name] = !in_array($name,$value['selectcols']);
484
+					if (!isset($value['rows']['no_'.$name])) $value['rows']['no_'.$name] = !in_array($name, $value['selectcols']);
485 485
 					// setting '@no_'.$name as disabled attr for each column, that has only a single nextmatch-header
486 486
 					if (is_object($value['template']))
487 487
 					{
488 488
 						$col = $name2col[$name];
489 489
 						list(,$disabled) = $value['template']->set_column_attributes($col);
490 490
 						//echo "<p>$col: $name: $disabled</p>\n";
491
-						if (!isset($disabled)) $value['template']->set_column_attributes($col,0,'@no_'.$name);
491
+						if (!isset($disabled)) $value['template']->set_column_attributes($col, 0, '@no_'.$name);
492 492
 					}
493 493
 				}
494 494
 				//_debug_array($value);
495 495
 				if (is_object($nextmatch))
496 496
 				{
497
-					$size =& $nextmatch->get_cell_attribute('selectcols','size');
497
+					$size = & $nextmatch->get_cell_attribute('selectcols', 'size');
498 498
 					// Don't change to fancy multi-select here
499
-					$nextmatch->set_cell_attribute('selectcols','enhance',false);
499
+					$nextmatch->set_cell_attribute('selectcols', 'enhance', false);
500 500
 					if ($size > count($value['options-selectcols'])) $size = '0'.count($value['options-selectcols']);
501 501
 					if (!$GLOBALS['egw_info']['user']['apps']['admin'])
502 502
 					{
@@ -510,18 +510,18 @@  discard block
 block discarded – undo
510 510
 
511 511
 		// Check for preferred import/export definition
512 512
 		$name = is_object($extension_data['template']) ? $extension_data['template']->name : $extension_data['template'];
513
-		list($app) = explode('.',$name);
513
+		list($app) = explode('.', $name);
514 514
 		$definition = $GLOBALS['egw_info']['user']['preferences'][$app]['nextmatch-export-definition'];
515
-		if(!$value['no_csv_export'] && $definition != '~nextmatch~' && ($definition || !is_array($value['csv_fields'])))
515
+		if (!$value['no_csv_export'] && $definition != '~nextmatch~' && ($definition || !is_array($value['csv_fields'])))
516 516
 		{
517
-			if($GLOBALS['egw_info']['user']['apps']['importexport'] && ($definition || $value['csv_fields']) && is_object($nextmatch))
517
+			if ($GLOBALS['egw_info']['user']['apps']['importexport'] && ($definition || $value['csv_fields']) && is_object($nextmatch))
518 518
 			{
519 519
 				$nextmatch->set_cell_attribute('export', 'onclick',
520
-					"egw_openWindowCentered2('". egw::link('/index.php', array(
520
+					"egw_openWindowCentered2('".egw::link('/index.php', array(
521 521
 						'menuaction' => 'importexport.importexport_export_ui.export_dialog',
522 522
 						'appname' => $app,
523 523
 						'definition' => $definition ? $definition : $value['csv_fields']
524
-					)) .
524
+					)).
525 525
 					"', '_blank', 850, 440, 'yes'); return false;"
526 526
 				);
527 527
 			}
@@ -530,16 +530,16 @@  discard block
 block discarded – undo
530 530
 		$cell['type'] = 'template';
531 531
 		$cell['label'] = $cell['help'] = '';
532 532
 
533
-		foreach(array('sort','order','col_filter') as $n)	// save them for the sortheader
533
+		foreach (array('sort', 'order', 'col_filter') as $n)	// save them for the sortheader
534 534
 		{
535 535
 			$nm_global[$n] = $value[$n];
536 536
 		}
537
-		$value['bottom'] = $value;	// copy the values for the bottom-bar
537
+		$value['bottom'] = $value; // copy the values for the bottom-bar
538 538
 
539 539
 		// pass actions and row_id to etemplate::show_grid()
540
-		$value['rows']['_actions'] =& $value['actions'];
541
-		$value['rows']['_action_links'] =& $value['action_links'];
542
-		$value['rows']['_row_id']  =& $value['row_id'];
540
+		$value['rows']['_actions'] = & $value['actions'];
541
+		$value['rows']['_action_links'] = & $value['action_links'];
542
+		$value['rows']['_row_id']  = & $value['row_id'];
543 543
 
544 544
 		// values are NOT yet used on client side, but give warnings if array are not converted to strings
545 545
 		$extension_data['action_var'] = !empty($value['action_var']) ? $value['action_var'] : 'action';
@@ -557,7 +557,7 @@  discard block
 block discarded – undo
557 557
 		}
558 558
 		$value['checkboxes'] = implode(',',$checkboxes);
559 559
 */
560
-		return False;	// NO extra Label
560
+		return False; // NO extra Label
561 561
 	}
562 562
 
563 563
 	/**
@@ -622,19 +622,19 @@  discard block
 block discarded – undo
622 622
 	 * @param array $default_attrs=null default attributes
623 623
 	 * @return array
624 624
 	 */
625
-	public static function egw_actions(array $actions=null, $template_name='', $prefix='', array &$action_links=array(),
626
-		$max_length=self::DEFAULT_MAX_MENU_LENGTH, array $default_attrs=null)
625
+	public static function egw_actions(array $actions = null, $template_name = '', $prefix = '', array &$action_links = array(),
626
+		$max_length = self::DEFAULT_MAX_MENU_LENGTH, array $default_attrs = null)
627 627
 	{
628 628
 		//echo "<p>".__METHOD__."(\$actions, '$template_name', '$prefix', \$action_links, $max_length) \$actions="; _debug_array($actions);
629 629
 		// default icons for some common actions
630 630
 		static $default_icons = array(
631 631
 			'view' => 'view',
632 632
 			'edit' => 'edit',
633
-			'open' => 'edit',	// does edit if possible, otherwise view
633
+			'open' => 'edit', // does edit if possible, otherwise view
634 634
 			'add'  => 'new',
635 635
 			'new'  => 'new',
636 636
 			'delete' => 'delete',
637
-			'cat'  => 'category',		// add as category icon to api
637
+			'cat'  => 'category', // add as category icon to api
638 638
 			'document' => 'etemplate/merge',
639 639
 			'print'=> 'print',
640 640
 			'copy' => 'copy',
@@ -643,12 +643,12 @@  discard block
 block discarded – undo
643 643
 			'paste'=> 'editpaste',
644 644
 		);
645 645
 
646
-		$first_level = !$action_links;	// add all first level actions
646
+		$first_level = !$action_links; // add all first level actions
647 647
 
648 648
 		//echo "actions="; _debug_array($actions);
649 649
 		$egw_actions = array();
650 650
 		$n = 1;
651
-		foreach((array)$actions as $id => $action)
651
+		foreach ((array)$actions as $id => $action)
652 652
 		{
653 653
 			// in case it's only selectbox  id => label pairs
654 654
 			if (!is_array($action)) $action = array('caption' => $action);
@@ -656,12 +656,12 @@  discard block
 block discarded – undo
656 656
 
657 657
 			if (!$first_level && $n == $max_length && count($actions) > $max_length)
658 658
 			{
659
-				$id = 'more_'.count($actions);	// we need a new unique id
659
+				$id = 'more_'.count($actions); // we need a new unique id
660 660
 				$action = array(
661 661
 					'caption' => 'More',
662 662
 					'prefix' => $prefix,
663 663
 					// display rest of actions incl. current one as children
664
-					'children' => array_slice($actions, $max_length-1, count($actions)-$max_length+1, true),
664
+					'children' => array_slice($actions, $max_length - 1, count($actions) - $max_length + 1, true),
665 665
 				);
666 666
 				//echo "*** Inserting id=$prefix$id"; _debug_array($action);
667 667
 				// we break at end of foreach loop, as rest of actions is already dealt with
@@ -670,8 +670,8 @@  discard block
 block discarded – undo
670 670
 			$action['id'] = $prefix.$id;
671 671
 
672 672
 			// add all first level popup actions plus ones with enabled = 'javaScript:...' to action_links
673
-			if ((!isset($action['type']) || in_array($action['type'],array('popup','drag'))) &&	// popup is the default
674
-				($first_level || substr($action['enabled'],0,11) == 'javaScript:'))
673
+			if ((!isset($action['type']) || in_array($action['type'], array('popup', 'drag'))) && // popup is the default
674
+				($first_level || substr($action['enabled'], 0, 11) == 'javaScript:'))
675 675
 			{
676 676
 				$action_links[] = $action['id'];
677 677
 			}
@@ -684,14 +684,14 @@  discard block
 block discarded – undo
684 684
 			// use common eTemplate image semantics
685 685
 			if (!isset($action['iconUrl']) && !empty($action['icon']))
686 686
 			{
687
-				list($app,$img) = explode('/',$action['icon'],2);
688
-				if (!$app || !$img || !is_dir(EGW_SERVER_ROOT.'/'.$app) || strpos($img,'/')!==false)
687
+				list($app, $img) = explode('/', $action['icon'], 2);
688
+				if (!$app || !$img || !is_dir(EGW_SERVER_ROOT.'/'.$app) || strpos($img, '/') !== false)
689 689
 				{
690 690
 					$img = $action['icon'];
691 691
 					list($app) = explode('.', $template_name);
692 692
 				}
693 693
 				$action['iconUrl'] = common::find_image($app, $img);
694
-				unset($action['icon']);	// no need to submit it
694
+				unset($action['icon']); // no need to submit it
695 695
 			}
696 696
 			// translate labels
697 697
 			if (!$action['no_lang'])
@@ -701,18 +701,18 @@  discard block
 block discarded – undo
701 701
 			}
702 702
 			unset($action['no_lang']);
703 703
 
704
-			foreach(array('confirm','confirm_multiple') as $confirm)
704
+			foreach (array('confirm', 'confirm_multiple') as $confirm)
705 705
 			{
706 706
 				if (isset($action[$confirm]))
707 707
 				{
708
-					$action[$confirm] = lang($action[$confirm]).(substr($action[$confirm],-1) != '?' ? '?' : '');
708
+					$action[$confirm] = lang($action[$confirm]).(substr($action[$confirm], -1) != '?' ? '?' : '');
709 709
 				}
710 710
 			}
711 711
 
712 712
 			// add sub-menues
713 713
 			if ($action['children'])
714 714
 			{
715
-				static $inherit_attrs = array('url','popup','nm_action','onExecute','type','egw_open','allowOnMultiple','confirm','confirm_multiple');
715
+				static $inherit_attrs = array('url', 'popup', 'nm_action', 'onExecute', 'type', 'egw_open', 'allowOnMultiple', 'confirm', 'confirm_multiple');
716 716
 				$action['children'] = self::egw_actions($action['children'], $template_name, $action['prefix'], $action_links, $max_length,
717 717
 					array_intersect_key($action, array_flip($inherit_attrs)));
718 718
 
@@ -723,10 +723,10 @@  discard block
 block discarded – undo
723 723
 			// link or popup action
724 724
 			if ($action['url'])
725 725
 			{
726
-				$action['url'] = egw::link('/index.php',str_replace('$action',$id,$action['url']));
726
+				$action['url'] = egw::link('/index.php', str_replace('$action', $id, $action['url']));
727 727
 				if ($action['popup'])
728 728
 				{
729
-					list($action['data']['width'],$action['data']['height']) = explode('x',$action['popup']);
729
+					list($action['data']['width'], $action['data']['height']) = explode('x', $action['popup']);
730 730
 					unset($action['popup']);
731 731
 					$action['data']['nm_action'] = 'popup';
732 732
 				}
@@ -747,13 +747,13 @@  discard block
 block discarded – undo
747 747
 			}
748 748
 
749 749
 			static $egw_action_supported = array(	// attributes supported by egw_action
750
-				'id','caption','iconUrl','type','default','onExecute','group',
751
-				'enabled','allowOnMultiple','hideOnDisabled','data','children',
752
-				'hint','checkbox','checked','radioGroup','acceptedTypes','dragType',
750
+				'id', 'caption', 'iconUrl', 'type', 'default', 'onExecute', 'group',
751
+				'enabled', 'allowOnMultiple', 'hideOnDisabled', 'data', 'children',
752
+				'hint', 'checkbox', 'checked', 'radioGroup', 'acceptedTypes', 'dragType',
753 753
 				'shortcut'
754 754
 			);
755 755
 			// add all not egw_action supported attributes to data
756
-			$action['data'] = array_merge(array_diff_key($action, array_flip($egw_action_supported)),(array)$action['data']);
756
+			$action['data'] = array_merge(array_diff_key($action, array_flip($egw_action_supported)), (array)$action['data']);
757 757
 			if (!$action['data']) unset($action['data']);
758 758
 			// only add egw_action attributes
759 759
 			$egw_actions[] = array_intersect_key($action, array_flip($egw_action_supported));
@@ -779,13 +779,13 @@  discard block
 block discarded – undo
779 779
 	 * @param boolean $none_option = true Include an option 'None' to clear category
780 780
 	 * @return array like self::egw_actions
781 781
 	 */
782
-	public static function category_action($app, $group=0, $caption='Change category',
783
-		$prefix='cat_', $globals=true, $parent_id=0, $max_cats_flat=self::DEFAULT_MAX_MENU_LENGTH, $none_option = true)
782
+	public static function category_action($app, $group = 0, $caption = 'Change category',
783
+		$prefix = 'cat_', $globals = true, $parent_id = 0, $max_cats_flat = self::DEFAULT_MAX_MENU_LENGTH, $none_option = true)
784 784
 	{
785
-		$cat = new categories(null,$app);
786
-		$cats = $cat->return_sorted_array($start=0, $limit=false, $query='', $sort='ASC', $order='cat_name', $globals, $parent_id, $unserialize_data=true);
785
+		$cat = new categories(null, $app);
786
+		$cats = $cat->return_sorted_array($start = 0, $limit = false, $query = '', $sort = 'ASC', $order = 'cat_name', $globals, $parent_id, $unserialize_data = true);
787 787
 
788
-		if($none_option)
788
+		if ($none_option)
789 789
 		{
790 790
 			array_unshift($cats, array(
791 791
 				'id'	=> $prefix.'',
@@ -801,9 +801,9 @@  discard block
 block discarded – undo
801 801
 		else	// flat, indented categories
802 802
 		{
803 803
 			$cat_actions = array();
804
-			foreach((array)$cats as $cat)
804
+			foreach ((array)$cats as $cat)
805 805
 			{
806
-				$name = str_repeat('&nbsp;',2*$cat['level']) . stripslashes($cat['name']);
806
+				$name = str_repeat('&nbsp;', 2 * $cat['level']).stripslashes($cat['name']);
807 807
 
808 808
 				$cat_actions[$cat['id']] = array(
809 809
 					'caption' => $name,
@@ -833,10 +833,10 @@  discard block
 block discarded – undo
833 833
 	 * @param int $parent_id=0 only returns cats of a certain parent
834 834
 	 * @return array
835 835
 	 */
836
-	private static function category_hierarchy(array $cats, $prefix, $parent_id=0)
836
+	private static function category_hierarchy(array $cats, $prefix, $parent_id = 0)
837 837
 	{
838 838
 		$cat_actions = array();
839
-		foreach($cats as $key => $cat)
839
+		foreach ($cats as $key => $cat)
840 840
 		{
841 841
 			// current hierarchy level
842 842
 			if ($cat['parent'] == $parent_id)
@@ -856,14 +856,14 @@  discard block
 block discarded – undo
856 856
 				unset($cats[$key]);
857 857
 			}
858 858
 			// direct children
859
-			elseif(isset($cat_actions[$cat['parent']]))
859
+			elseif (isset($cat_actions[$cat['parent']]))
860 860
 			{
861 861
 				$cat_actions['sub_'.$cat['parent']] = $cat_actions[$cat['parent']];
862 862
 				// have to add category itself to children, to be able to select it!
863
-				$cat_actions[$cat['parent']]['group'] = -1;	// own group on top
863
+				$cat_actions[$cat['parent']]['group'] = -1; // own group on top
864 864
 				$cat_actions['sub_'.$cat['parent']]['children'] = array(
865 865
 					$cat['parent'] => $cat_actions[$cat['parent']],
866
-				)+self::category_hierarchy($cats, $prefix, $cat['parent']);
866
+				) + self::category_hierarchy($cats, $prefix, $cat['parent']);
867 867
 				unset($cat_actions[$cat['parent']]);
868 868
 			}
869 869
 		}
@@ -880,19 +880,19 @@  discard block
 block discarded – undo
880 880
 	 * @param string $template_name='' name of the template, used as default for app name of images - e.g. infolog.index.rows
881 881
 	 * @param string $prefix='egw_' JS action objects generated for this widget are prefixed with given prefix
882 882
 	 */
883
-	public static function init_egw_actions(array $actions=null, $action_links=null, $template_name='', $prefix='egw_')
883
+	public static function init_egw_actions(array $actions = null, $action_links = null, $template_name = '', $prefix = 'egw_')
884 884
 	{
885 885
 		// Load some JS files needed for the egw_action framework
886 886
 		egw_framework::includeCSS('/phpgwapi/js/egw_action/test/skins/dhtmlxmenu_egw.css');
887 887
 
888
-		egw_framework::validate_file('dhtmlxtree','dhtmlxMenu/codebase/dhtmlxcommon');
889
-		egw_framework::validate_file('dhtmlxtree','dhtmlxMenu/codebase/dhtmlxmenu');
890
-		egw_framework::validate_file('egw_action','egw_action');
891
-		egw_framework::validate_file('egw_action','egw_action_common');
892
-		egw_framework::validate_file('egw_action','egw_action_popup');
893
-		egw_framework::validate_file('egw_action','egw_menu');
894
-		egw_framework::validate_file('egw_action','egw_menu_dhtmlx');
895
-		egw_framework::validate_file('egw_action','egw_keymanager');
888
+		egw_framework::validate_file('dhtmlxtree', 'dhtmlxMenu/codebase/dhtmlxcommon');
889
+		egw_framework::validate_file('dhtmlxtree', 'dhtmlxMenu/codebase/dhtmlxmenu');
890
+		egw_framework::validate_file('egw_action', 'egw_action');
891
+		egw_framework::validate_file('egw_action', 'egw_action_common');
892
+		egw_framework::validate_file('egw_action', 'egw_action_popup');
893
+		egw_framework::validate_file('egw_action', 'egw_menu');
894
+		egw_framework::validate_file('egw_action', 'egw_menu_dhtmlx');
895
+		egw_framework::validate_file('egw_action', 'egw_keymanager');
896 896
 		egw_framework::validate_file('.', 'nextmatch_action', 'etemplate');
897 897
 
898 898
 		//egw_framework::validate_file('dhtmlxtree','dhtmlxMenu/codebase/ext/dhtmlxmenu_ext');
@@ -929,7 +929,7 @@  discard block
 block discarded – undo
929 929
 			// Create a new action object
930 930
 			if (elem.id) {
931 931
 				var obj = objectCntr.addObject(elem.id, new nextmatchRowAOI(elem, '.
932
-					($GLOBALS['egw_info']['user']['preferences']['common']['select_mode']?$GLOBALS['egw_info']['user']['preferences']['common']['select_mode']:'EGW_SELECTMODE_DEFAULT').'));
932
+					($GLOBALS['egw_info']['user']['preferences']['common']['select_mode'] ? $GLOBALS['egw_info']['user']['preferences']['common']['select_mode'] : 'EGW_SELECTMODE_DEFAULT').'));
933 933
 
934 934
 				obj.updateActionLinks(actionLinks);
935 935
 			}
@@ -954,27 +954,27 @@  discard block
 block discarded – undo
954 954
 	 * @param string|array $method=null (internal)
955 955
 	 * @return int|boolean total items found of false on error ($value['get_rows'] not callable)
956 956
 	 */
957
-	private static function call_get_rows(array &$value,array &$rows=null,array &$readonlys=null,$obj=null,$method=null)
957
+	private static function call_get_rows(array &$value, array &$rows = null, array &$readonlys = null, $obj = null, $method = null)
958 958
 	{
959 959
 		if (is_null($method)) $method = $value['get_rows'];
960 960
 
961 961
 		if (is_null($obj))
962 962
 		{
963 963
 			// allow static callbacks
964
-			if(strpos($method,'::') !== false)
964
+			if (strpos($method, '::') !== false)
965 965
 			{
966
-				list($class,$method) = explode('::',$method);
966
+				list($class, $method) = explode('::', $method);
967 967
 
968 968
 				//  workaround for php < 5.2.3: do NOT call it static, but allow application code to specify static callbacks
969
-				if (version_compare(PHP_VERSION,'5.2.3','>='))
969
+				if (version_compare(PHP_VERSION, '5.2.3', '>='))
970 970
 				{
971
-					$method = array($class,$method);
971
+					$method = array($class, $method);
972 972
 					unset($class);
973 973
 				}
974 974
 			}
975 975
 			else
976 976
 			{
977
-				list($app,$class,$method) = explode('.',$value['get_rows']);
977
+				list($app, $class, $method) = explode('.', $value['get_rows']);
978 978
 			}
979 979
 			if ($class)
980 980
 			{
@@ -992,23 +992,23 @@  discard block
 block discarded – undo
992 992
 				}
993 993
 			}
994 994
 		}
995
-		if(is_callable($method))	// php5.2.3+ static call (value is always a var param!)
995
+		if (is_callable($method))	// php5.2.3+ static call (value is always a var param!)
996 996
 		{
997
-			$total = call_user_func_array($method,array(&$value,&$rows,&$readonlys));
997
+			$total = call_user_func_array($method, array(&$value, &$rows, &$readonlys));
998 998
 		}
999
-		elseif(is_object($obj) && method_exists($obj,$method))
999
+		elseif (is_object($obj) && method_exists($obj, $method))
1000 1000
 		{
1001 1001
 			if (!is_array($readonlys)) $readonlys = array();
1002
-			$total = $obj->$method($value,$rows,$readonlys);
1002
+			$total = $obj->$method($value, $rows, $readonlys);
1003 1003
 		}
1004 1004
 		else
1005 1005
 		{
1006
-			$total = false;	// method not callable
1006
+			$total = false; // method not callable
1007 1007
 		}
1008 1008
 		if ($method && $total && $value['start'] >= $total)
1009 1009
 		{
1010 1010
 			$value['start'] = 0;
1011
-			$total = self::call_get_rows($value,$rows,$readonlys,$obj,$method);
1011
+			$total = self::call_get_rows($value, $rows, $readonlys, $obj, $method);
1012 1012
 		}
1013 1013
 		// otherwise we get stoped by max_excutiontime
1014 1014
 		if ($total > 200) @set_time_limit(0);
@@ -1021,12 +1021,12 @@  discard block
 block discarded – undo
1021 1021
 	 *
1022 1022
 	 * @param array &$cell
1023 1023
 	 */
1024
-	private function pre_process_cf_header(array &$cell,$tmpl, &$value, $nm_global)
1024
+	private function pre_process_cf_header(array &$cell, $tmpl, &$value, $nm_global)
1025 1025
 	{
1026 1026
 		//echo __CLASS__.'::'.__METHOD__."() selectcols=$this->selectcols\n";
1027 1027
 		if (is_null($this->cfs))
1028 1028
 		{
1029
-			list($app) = explode('.',$tmpl->name);
1029
+			list($app) = explode('.', $tmpl->name);
1030 1030
 
1031 1031
 			$this->cfs = config::get_customfields($app);
1032 1032
 		}
@@ -1040,46 +1040,46 @@  discard block
 block discarded – undo
1040 1040
 
1041 1041
 		if ($this->selectcols)
1042 1042
 		{
1043
-			foreach(is_array($this->selectcols) ? $this->selectcols : explode(',',$this->selectcols) as $col)
1043
+			foreach (is_array($this->selectcols) ? $this->selectcols : explode(',', $this->selectcols) as $col)
1044 1044
 			{
1045 1045
 				if ($col[0] == self::CF_PREFIX) $allowed[] = $col;
1046 1046
 			}
1047 1047
 		}
1048
-		foreach($this->cfs as $name => $field)
1048
+		foreach ($this->cfs as $name => $field)
1049 1049
 		{
1050
-			if (!$allowed || in_array(self::CF_PREFIX.$name,$allowed))
1050
+			if (!$allowed || in_array(self::CF_PREFIX.$name, $allowed))
1051 1051
 			{
1052
-				if($field['type'] == 'select')
1052
+				if ($field['type'] == 'select')
1053 1053
 				{
1054
-					$header =& boetemplate::empty_cell('nextmatch-filterheader',self::CF_PREFIX.$name,array(
1054
+					$header = & boetemplate::empty_cell('nextmatch-filterheader', self::CF_PREFIX.$name, array(
1055 1055
 						'sel_options' => $field['values'],
1056 1056
 						'size'        => $field['label'],
1057 1057
 						'no_lang'     => True,
1058 1058
 						'readonly'    => $cell['readonly'],
1059 1059
 					));
1060 1060
 				}
1061
-				elseif($GLOBALS['egw_info']['apps'][$field['type']])
1061
+				elseif ($GLOBALS['egw_info']['apps'][$field['type']])
1062 1062
 				{
1063
-					$header =& boetemplate::empty_cell('link-entry', $cell_name . '['.self::CF_PREFIX.$name .']', array(
1063
+					$header = & boetemplate::empty_cell('link-entry', $cell_name.'['.self::CF_PREFIX.$name.']', array(
1064 1064
 						'label'		=>	$field['label'],
1065 1065
 						'size'		=>	$field['type'],
1066 1066
 						'readonly'	=>	$cell['readonly'],
1067 1067
 						'onchange'	=>	1
1068 1068
 					));
1069
-					boetemplate::add_child($cell,$header);
1069
+					boetemplate::add_child($cell, $header);
1070 1070
 					unset($header);
1071 1071
 
1072
-					$header =& boetemplate::empty_cell('label', '');
1073
-					$value[self::CF_PREFIX.$name] = $field['type'] . ':' . $nm_global['col_filter'][self::CF_PREFIX.$name];
1072
+					$header = & boetemplate::empty_cell('label', '');
1073
+					$value[self::CF_PREFIX.$name] = $field['type'].':'.$nm_global['col_filter'][self::CF_PREFIX.$name];
1074 1074
 				}
1075 1075
 				else
1076 1076
 				{
1077
-					$header =& boetemplate::empty_cell('nextmatch-sortheader',self::CF_PREFIX.$name,array(
1077
+					$header = & boetemplate::empty_cell('nextmatch-sortheader', self::CF_PREFIX.$name, array(
1078 1078
 						'label'       => $field['label'],
1079 1079
 						'readonly'    => $cell['readonly'],
1080 1080
 					));
1081 1081
 				}
1082
-				boetemplate::add_child($cell,$header);
1082
+				boetemplate::add_child($cell, $header);
1083 1083
 				unset($header);
1084 1084
 			}
1085 1085
 		}
@@ -1088,13 +1088,13 @@  discard block
 block discarded – undo
1088 1088
 		if ($num > 5)
1089 1089
 		{
1090 1090
 			$vbox = $cell;
1091
-			$cell = boetemplate::empty_cell('box','',array(
1091
+			$cell = boetemplate::empty_cell('box', '', array(
1092 1092
 				'size' => '0,,0,0',
1093 1093
 				'span' => ',cf_header_height_limit',
1094 1094
 			));
1095
-			boetemplate::add_child($cell,$vbox);
1095
+			boetemplate::add_child($cell, $vbox);
1096 1096
 		}
1097
-		return false;	// no extra label
1097
+		return false; // no extra label
1098 1098
 	}
1099 1099
 
1100 1100
 	/**
@@ -1107,50 +1107,50 @@  discard block
 block discarded – undo
1107 1107
 	 * @param array $selectcols selected colums
1108 1108
 	 * @return int columns found, count($cols)
1109 1109
 	 */
1110
-	private function cols_from_tpl($tmpl,&$cols,&$name2col,&$content,$selectcols)
1110
+	private function cols_from_tpl($tmpl, &$cols, &$name2col, &$content, $selectcols)
1111 1111
 	{
1112 1112
 		//_debug_array($cols);
1113 1113
 		// fetching column-names & -labels from the template
1114
-		$cols['__content__'] =& $content;
1115
-		$tmpl->widget_tree_walk(array($this,'cols_from_tpl_walker'),$cols);
1114
+		$cols['__content__'] = & $content;
1115
+		$tmpl->widget_tree_walk(array($this, 'cols_from_tpl_walker'), $cols);
1116 1116
 		unset($cols['__content__']);
1117 1117
 		$col2names = is_array($cols['col2names']) ? $cols['col2names'] : array(); unset($cols['col2names']);
1118 1118
 		//_debug_array($col2names);
1119 1119
 		//_debug_array($cols);
1120
-		foreach($cols as $name => $label)
1120
+		foreach ($cols as $name => $label)
1121 1121
 		{
1122 1122
 			if (!$label) unset($cols[$name]);
1123 1123
 		}
1124 1124
 		//_debug_array($cols);
1125 1125
 		$cols2 = $cols;
1126 1126
 		$cols = array();
1127
-		foreach($cols2 as $name => $label)
1127
+		foreach ($cols2 as $name => $label)
1128 1128
 		{
1129 1129
 			$col = $name;
1130 1130
 			// and replace the column letter then with the name concatinated by an underscore
1131 1131
 			if (is_array($col2names[$name]))
1132 1132
 			{
1133
-				$name = implode('_',$col2names[$name]);
1133
+				$name = implode('_', $col2names[$name]);
1134 1134
 				$name2col[$name] = $col;
1135 1135
 			}
1136 1136
 			$cols[$name] = $label;
1137 1137
 
1138 1138
 			// we are behind the column of a custom fields header --> add the individual fields
1139 1139
 			if ($name == $this->cf_header && (!$selectcols ||
1140
-				in_array($this->cf_header,explode(',',$selectcols))))
1140
+				in_array($this->cf_header, explode(',', $selectcols))))
1141 1141
 			{
1142 1142
 				$cols[$name] .= ':';
1143
-				list($app) = explode('.',$tmpl->name);
1143
+				list($app) = explode('.', $tmpl->name);
1144 1144
 				if (($this->cfs = config::get_customfields($app)))
1145 1145
 				{
1146
-					foreach($this->cfs as $name => $field)
1146
+					foreach ($this->cfs as $name => $field)
1147 1147
 					{
1148 1148
 						$cols[self::CF_PREFIX.$name] = '- '.$field['label'];
1149 1149
 					}
1150 1150
 				}
1151 1151
 				else
1152 1152
 				{
1153
-					unset($cols[$name]);	// no cf's defined -> no header
1153
+					unset($cols[$name]); // no cf's defined -> no header
1154 1154
 				}
1155 1155
 			}
1156 1156
 		}
@@ -1165,9 +1165,9 @@  discard block
 block discarded – undo
1165 1165
 	 * @param array &$cols here we add the column-name/-label
1166 1166
 	 * @param string $path
1167 1167
 	 */
1168
-	function cols_from_tpl_walker(&$widget,&$cols,$path)
1168
+	function cols_from_tpl_walker(&$widget, &$cols, $path)
1169 1169
 	{
1170
-		list($type,$subtype) = explode('-',$widget['type']);
1170
+		list($type, $subtype) = explode('-', $widget['type']);
1171 1171
 
1172 1172
 		if ($subtype == 'customfields')
1173 1173
 		{
@@ -1179,28 +1179,28 @@  discard block
 block discarded – undo
1179 1179
 		{
1180 1180
 			return;
1181 1181
 		}
1182
-		$options = explode(',',$widget['size']);
1183
-		if (!($label = $widget['label']) || in_array($subtype,array('header','sortheader')) && $options[1])
1182
+		$options = explode(',', $widget['size']);
1183
+		if (!($label = $widget['label']) || in_array($subtype, array('header', 'sortheader')) && $options[1])
1184 1184
 		{
1185
-			if (in_array($subtype,array('customfilter','sortheader'))) $subtype = array_shift($options);
1185
+			if (in_array($subtype, array('customfilter', 'sortheader'))) $subtype = array_shift($options);
1186 1186
 
1187 1187
 			$label = $options[0];
1188 1188
 
1189 1189
 			// some widgets have label as second option (column name with _ as first), not a perfect detection ...
1190
-			if (strpos($label,'_') !== false && !empty($options[1])) $label = $options[1];
1190
+			if (strpos($label, '_') !== false && !empty($options[1])) $label = $options[1];
1191 1191
 		}
1192
-		list(,,$col,$sub) = explode('/',$path);
1192
+		list(,, $col, $sub) = explode('/', $path);
1193 1193
 		$row = (int)$col;
1194
-		$col = substr($col,$row > 9 ? 2 : 1);
1195
-		if (($label[0] == '@' || strchr($lable,'$') !== false) && is_array($cols['__content__']))
1194
+		$col = substr($col, $row > 9 ? 2 : 1);
1195
+		if (($label[0] == '@' || strchr($lable, '$') !== false) && is_array($cols['__content__']))
1196 1196
 		{
1197
-			$label = boetemplate::expand_name($label,$col,$row,'','',$cols['__content__']);
1197
+			$label = boetemplate::expand_name($label, $col, $row, '', '', $cols['__content__']);
1198 1198
 		}
1199 1199
 		if (!isset($cols[$widget['name']]) && $label)
1200 1200
 		{
1201
-			$label = substr($label,-3) == '...' ? lang(substr($label,0,-3)) : lang($label);
1201
+			$label = substr($label, -3) == '...' ? lang(substr($label, 0, -3)) : lang($label);
1202 1202
 
1203
-			if (empty($label) || strpos($cols[$col],$label) === false)
1203
+			if (empty($label) || strpos($cols[$col], $label) === false)
1204 1204
 			{
1205 1205
 				$cols[$col] .= ($cols[$col] ? ', ' : '').$label;
1206 1206
 			}
@@ -1227,13 +1227,13 @@  discard block
 block discarded – undo
1227 1227
 	 * @param mixed &value_in the posted values (already striped of magic-quotes)
1228 1228
 	 * @return boolean true if $value has valid content, on false no content will be returned!
1229 1229
 	 */
1230
-	public function post_process($name,&$value,&$extension_data,&$loop,&$tmpl,$value_in)
1230
+	public function post_process($name, &$value, &$extension_data, &$loop, &$tmpl, $value_in)
1231 1231
 	{
1232
-		$nm_global =& self::get_nm_global($name,$extension_data['type']);
1232
+		$nm_global = & self::get_nm_global($name, $extension_data['type']);
1233 1233
 
1234
-		if ($this->debug) { echo "<p>nextmatch_widget.post_process(type='$extension_data[type]', name='$name',value_in=".print_r($value_in,true).",order='$nm_global[order]'): value = "; _debug_array($value); }
1234
+		if ($this->debug) { echo "<p>nextmatch_widget.post_process(type='$extension_data[type]', name='$name',value_in=".print_r($value_in, true).",order='$nm_global[order]'): value = "; _debug_array($value); }
1235 1235
 
1236
-		switch($extension_data['type'])
1236
+		switch ($extension_data['type'])
1237 1237
 		{
1238 1238
 			case 'nextmatch':
1239 1239
 				break;
@@ -1244,11 +1244,11 @@  discard block
 block discarded – undo
1244 1244
 					$nm_global['order'] = self::last_part($name);
1245 1245
 					$nm_global['default_sort'] = $extension_data['default_sort'];
1246 1246
 				}
1247
-				return False;	// dont report value back, as it's in the wrong location (rows)
1247
+				return False; // dont report value back, as it's in the wrong location (rows)
1248 1248
 
1249 1249
 			case 'nextmatch-customfields':
1250 1250
 				$this->post_process_cf_header($value, $extension_data, $tmpl, $value_in, $nm_global);
1251
-				return False;   // dont report value back, as it's in the wrong location (rows)
1251
+				return False; // dont report value back, as it's in the wrong location (rows)
1252 1252
 			case 'link-entry':	// allways return app:id, if an entry got selected, otherwise null
1253 1253
 				if (is_array($value_in) && !empty($value_in['id']))
1254 1254
 				{
@@ -1267,21 +1267,21 @@  discard block
 block discarded – undo
1267 1267
 					if ($this->debug) echo "<p>setting nm_global[filter][".self::last_part($name)."]='$value_in' (was '$extension_data[old_value]')</p>\n";
1268 1268
 					$nm_global['filter'][self::last_part($name)] = $value_in;
1269 1269
 				}
1270
-				return False;	// dont report value back, as it's in the wrong location (rows)
1270
+				return False; // dont report value back, as it's in the wrong location (rows)
1271 1271
 
1272 1272
 			case 'nextmatch-header':
1273
-				return False;	// nothing to report
1273
+				return False; // nothing to report
1274 1274
 		}
1275 1275
 		$old_value = $extension_data;
1276 1276
 		if ($this->debug) { echo "old_value="; _debug_array($old_value); }
1277 1277
 
1278
-		$value['start'] = $old_value['start'];	// need to be set, to be reported back
1278
+		$value['start'] = $old_value['start']; // need to be set, to be reported back
1279 1279
 		$value['return'] = $old_value['return'];
1280 1280
 
1281 1281
 		if (is_array($value['bottom']))			// we have a second bottom-bar
1282 1282
 		{
1283
-			$inputs = array('search','cat_id','filter','filter2','num_rows');
1284
-			foreach($inputs as $name)
1283
+			$inputs = array('search', 'cat_id', 'filter', 'filter2', 'num_rows');
1284
+			foreach ($inputs as $name)
1285 1285
 			{
1286 1286
 				if (isset($value['bottom'][$name]) && $value[$name] == $old_value[$name])
1287 1287
 				{
@@ -1289,8 +1289,8 @@  discard block
 block discarded – undo
1289 1289
 					$value[$name] = $value['bottom'][$name];
1290 1290
 				}
1291 1291
 			}
1292
-			$buttons = array('start_search','first','left','right','last','export');
1293
-			foreach($buttons as $name)
1292
+			$buttons = array('start_search', 'first', 'left', 'right', 'last', 'export');
1293
+			foreach ($buttons as $name)
1294 1294
 			{
1295 1295
 				if (isset($value['bottom'][$name]) && $value['bottom'][$name])
1296 1296
 				{
@@ -1307,19 +1307,19 @@  discard block
 block discarded – undo
1307 1307
 		if (isset($old_value['num_rows']) && !is_null($value['num_rows']) && $value['num_rows'] != $old_value['num_rows'])
1308 1308
 		{
1309 1309
 			if ($this->debug) echo "<p>nextmatch_widget::post_process() num_rows changed {$old_value['num_rows']} --> {$value['num_rows']} ==> looping</p>\n";
1310
-			$loop = true;	// num_rows changed
1310
+			$loop = true; // num_rows changed
1311 1311
 		}
1312 1312
 		// num_rows: use old value in extension data, if $value['num_rows'] is not set because nm-header is not shown
1313
-		$value['num_rows'] = isset($value['num_rows']) ? (int) $value['num_rows'] : (int) $extension_data['num_rows'];
1313
+		$value['num_rows'] = isset($value['num_rows']) ? (int)$value['num_rows'] : (int)$extension_data['num_rows'];
1314 1314
 		$max = $value['num_rows'] ? $value['num_rows'] : (int)$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'];
1315 1315
 
1316
-		if(strpos($value['search'],'xjxquery')) {
1316
+		if (strpos($value['search'], 'xjxquery')) {
1317 1317
 			// We deal with advancedsearch
1318 1318
 			$aXml = $value['search'];
1319 1319
 			$value['search'] = '';
1320
-			$aXml = str_replace("<xjxquery><q>","&",$aXml);
1321
-			$aXml = str_replace("</q></xjxquery>","",$aXml);
1322
-			$value['advsearch_cont'] = explode('&',$aXml);
1320
+			$aXml = str_replace("<xjxquery><q>", "&", $aXml);
1321
+			$aXml = str_replace("</q></xjxquery>", "", $aXml);
1322
+			$value['advsearch_cont'] = explode('&', $aXml);
1323 1323
 			//$GLOBALS['egw']->boetemplate = &CreateObject('etemplate.boetemplate');
1324 1324
 			//print_r($GLOBALS['egw']->boetemplate->get_array($value['advsearch_cont'],'exec[]',true));
1325 1325
 			//$value['advsearch_cont'] = preg_replace("/exec\[ (.*)/",'$1',$value['advsearch_cont']);
@@ -1361,7 +1361,7 @@  discard block
 block discarded – undo
1361 1361
 		}
1362 1362
 		elseif ($value['last'])
1363 1363
 		{
1364
-			$value['start'] = (int) (($old_value['total']-1) / $max) * $max;
1364
+			$value['start'] = (int)(($old_value['total'] - 1) / $max) * $max;
1365 1365
 			unset($value['last']);
1366 1366
 			$loop = True;
1367 1367
 		}
@@ -1395,12 +1395,12 @@  discard block
 block discarded – undo
1395 1395
 		if ($value['savecols'])
1396 1396
 		{
1397 1397
 			$name = is_object($extension_data['template']) ? $extension_data['template']->name : $extension_data['template'];
1398
-			list($app) = explode('.',$name);
1398
+			list($app) = explode('.', $name);
1399 1399
 			if (isset($extension_data['columnselection_pref'])) $name = $extension_data['columnselection_pref'];
1400 1400
 			$pref = !$GLOBALS['egw_info']['user']['apps']['admin'] && $value['default_prefs'] ? 'default' : 'user';
1401
-			$GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->add($app,'nextmatch-'.$name,is_array($value['selectcols']) ?
1402
-				implode(',',$value['selectcols']) : $value['selectcols'],$pref);
1403
-			$GLOBALS['egw']->preferences->save_repository(false,$pref);
1401
+			$GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->add($app, 'nextmatch-'.$name, is_array($value['selectcols']) ?
1402
+				implode(',', $value['selectcols']) : $value['selectcols'], $pref);
1403
+			$GLOBALS['egw']->preferences->save_repository(false, $pref);
1404 1404
 			$loop = True;
1405 1405
 		}
1406 1406
 		if ($value['export'])
@@ -1412,12 +1412,12 @@  discard block
 block discarded – undo
1412 1412
 		$value['selected'] = $value['selected'] === '' ? array() : boetemplate::csv_split($value['selected']);
1413 1413
 		$checkboxes = $value['checkboxes'];
1414 1414
 		$value['checkboxes'] = array();
1415
-		foreach(explode(';',$checkboxes) as $data)
1415
+		foreach (explode(';', $checkboxes) as $data)
1416 1416
 		{
1417
-			list($name,$checked) = explode(':',$data);
1417
+			list($name, $checked) = explode(':', $data);
1418 1418
 			if ($name) $value['checkboxes'][$name] = (boolean)$checked;
1419 1419
 		}
1420
-		$value['select_all'] =& $value['checkboxes']['select_all'];
1420
+		$value['select_all'] = & $value['checkboxes']['select_all'];
1421 1421
 
1422 1422
 		return True;
1423 1423
 	}
@@ -1431,14 +1431,14 @@  discard block
 block discarded – undo
1431 1431
 	{
1432 1432
 		if (is_null($this->cfs))
1433 1433
 		{
1434
-			list($app) = explode('.',$tmpl->name);
1434
+			list($app) = explode('.', $tmpl->name);
1435 1435
 			$this->cfs = config::get_customfields($app);
1436 1436
 		}
1437
-		foreach($this->cfs as $name => $field) {
1438
-			if($GLOBALS['egw_info']['apps'][$field['type']]) {
1439
-				if(is_array($value_in[self::CF_PREFIX.$name])) {
1437
+		foreach ($this->cfs as $name => $field) {
1438
+			if ($GLOBALS['egw_info']['apps'][$field['type']]) {
1439
+				if (is_array($value_in[self::CF_PREFIX.$name])) {
1440 1440
 					list($old_app, $old_id) = explode(':', $extension_data['old_value'][self::CF_PREFIX.$name]);
1441
-					if($value_in[self::CF_PREFIX.$name]['id'] != '' && $value_in[self::CF_PREFIX.$name]['id'] != $old_id)  {
1441
+					if ($value_in[self::CF_PREFIX.$name]['id'] != '' && $value_in[self::CF_PREFIX.$name]['id'] != $old_id) {
1442 1442
 						$nm_global['filter'][self::CF_PREFIX.$name] = $value_in[self::CF_PREFIX.$name]['id'];
1443 1443
 					}
1444 1444
 				}
@@ -1458,13 +1458,13 @@  discard block
 block discarded – undo
1458 1458
 	 * @param string $separator=';'
1459 1459
 	 * @return boolean false=error, eg. get_rows callback does not exits, true=nothing to export, otherwise we do NOT return!
1460 1460
 	 */
1461
-	static public function csv_export(&$value,$separator=';')
1461
+	static public function csv_export(&$value, $separator = ';')
1462 1462
 	{
1463 1463
 		$exportLimitExempted = bo_merge::is_export_limit_excepted();
1464 1464
 		if (!$exportLimitExempted)
1465 1465
 		{
1466 1466
 			$name = is_object($value['template']) ? $value['template']->name : $value['template'];
1467
-			list($app) = explode('.',$name);
1467
+			list($app) = explode('.', $name);
1468 1468
 			$export_limit = bo_merge::getExportLimit($app);
1469 1469
 			//if (isset($value['export_limit'])) $export_limit = $value['export_limit'];
1470 1470
 		}
@@ -1482,16 +1482,16 @@  discard block
 block discarded – undo
1482 1482
 
1483 1483
 		$value['start'] = 0;
1484 1484
 		$value['num_rows'] = 500;
1485
-		$value['csv_export'] = true;	// so get_rows method _can_ produce different content or not store state in the session
1485
+		$value['csv_export'] = true; // so get_rows method _can_ produce different content or not store state in the session
1486 1486
 		do
1487 1487
 		{
1488
-			if (!($total = self::call_get_rows($value,$rows)))
1488
+			if (!($total = self::call_get_rows($value, $rows)))
1489 1489
 			{
1490
-				break;	// nothing to export
1490
+				break; // nothing to export
1491 1491
 			}
1492
-			if (!$exportLimitExempted && (!bo_merge::hasExportLimit($export_limit,'ISALLOWED') || (bo_merge::hasExportLimit($export_limit) && (int)$export_limit < $total)))
1492
+			if (!$exportLimitExempted && (!bo_merge::hasExportLimit($export_limit, 'ISALLOWED') || (bo_merge::hasExportLimit($export_limit) && (int)$export_limit < $total)))
1493 1493
 			{
1494
-				etemplate::set_validation_error($name,lang('You are not allowed to export more than %1 entries!',(int)$export_limit));
1494
+				etemplate::set_validation_error($name, lang('You are not allowed to export more than %1 entries!', (int)$export_limit));
1495 1495
 				return false;
1496 1496
 			}
1497 1497
 			if (!isset($value['no_csv_support'])) $value['no_csv_support'] = !is_array($value['csv_fields']);
@@ -1500,22 +1500,22 @@  discard block
 block discarded – undo
1500 1500
 			if (!$value['start'])	// send the neccessary headers
1501 1501
 			{
1502 1502
 				// skip empty data row(s) used to adjust to number of header-lines
1503
-				foreach($rows as $row0)
1503
+				foreach ($rows as $row0)
1504 1504
 				{
1505 1505
 					if (is_array($row0) && count($row0) > 1) break;
1506 1506
 				}
1507
-				$fp = self::csv_open($row0,$value['csv_fields'],$app,$charset_out,$charset,$separator);
1507
+				$fp = self::csv_open($row0, $value['csv_fields'], $app, $charset_out, $charset, $separator);
1508 1508
 			}
1509
-			foreach($rows as $key => $row)
1509
+			foreach ($rows as $key => $row)
1510 1510
 			{
1511
-				if (!is_numeric($key) || !$row) continue;	// not a real rows
1512
-				fwrite($fp,self::csv_encode($row,$value['csv_fields'],true,$rows['sel_options'],$charset_out,$charset,$separator)."\n");
1511
+				if (!is_numeric($key) || !$row) continue; // not a real rows
1512
+				fwrite($fp, self::csv_encode($row, $value['csv_fields'], true, $rows['sel_options'], $charset_out, $charset, $separator)."\n");
1513 1513
 			}
1514 1514
 			$value['start'] += $value['num_rows'];
1515 1515
 
1516
-			@set_time_limit(10);	// 10 more seconds
1516
+			@set_time_limit(10); // 10 more seconds
1517 1517
 		}
1518
-		while($total > $value['start']);
1518
+		while ($total > $value['start']);
1519 1519
 
1520 1520
 		unset($value['csv_export']);
1521 1521
 		$value['start'] = $backup_start;
@@ -1543,24 +1543,24 @@  discard block
 block discarded – undo
1543 1543
 	 * @param string $separator=';'
1544 1544
 	 * @return FILE
1545 1545
 	 */
1546
-	private static function csv_open($row0,&$fields,$app,$charset_out=null,$charset=null,$separator=';')
1546
+	private static function csv_open($row0, &$fields, $app, $charset_out = null, $charset = null, $separator = ';')
1547 1547
 	{
1548 1548
 		if (!is_array($fields) || !count($fields))
1549 1549
 		{
1550
-			$fields = self::autodetect_fields($row0,$app);
1550
+			$fields = self::autodetect_fields($row0, $app);
1551 1551
 		}
1552
-		html::content_header('export.csv','text/comma-separated-values');
1552
+		html::content_header('export.csv', 'text/comma-separated-values');
1553 1553
 		//echo "<pre>";
1554 1554
 
1555
-		if (($fp = fopen('php://output','w')))
1555
+		if (($fp = fopen('php://output', 'w')))
1556 1556
 		{
1557 1557
 			$labels = array();
1558
-			foreach($fields as $field => $label)
1558
+			foreach ($fields as $field => $label)
1559 1559
 			{
1560 1560
 				if (is_array($label)) $label = $label['label'];
1561 1561
 				$labels[$field] = $label ? $label : $field;
1562 1562
 			}
1563
-			fwrite($fp,self::csv_encode($labels,$fields,false,null,$charset_out,$charset,$separator)."\n");
1563
+			fwrite($fp, self::csv_encode($labels, $fields, false, null, $charset_out, $charset, $separator)."\n");
1564 1564
 		}
1565 1565
 		return $fp;
1566 1566
 	}
@@ -1577,19 +1577,19 @@  discard block
 block discarded – undo
1577 1577
 	 * @param string $separator=';'
1578 1578
 	 * @return string
1579 1579
 	 */
1580
-	private static function csv_encode($data,$fields,$use_type=true,$extra_sel_options=null,$charset_out=null,$charset=null,$separator=';')
1580
+	private static function csv_encode($data, $fields, $use_type = true, $extra_sel_options = null, $charset_out = null, $charset = null, $separator = ';')
1581 1581
 	{
1582
-		$sel_options =& etemplate::$request->sel_options;
1582
+		$sel_options = & etemplate::$request->sel_options;
1583 1583
 
1584 1584
 		$out = array();
1585
-		foreach($fields as $field => $label)
1585
+		foreach ($fields as $field => $label)
1586 1586
 		{
1587 1587
 			$value = (array)$data[$field];
1588
-			if ($use_type && is_array($label) && in_array($label['type'],array('select-account','select-cat','date-time','date','select','int','float')))
1588
+			if ($use_type && is_array($label) && in_array($label['type'], array('select-account', 'select-cat', 'date-time', 'date', 'select', 'int', 'float')))
1589 1589
 			{
1590
-				foreach($value as $key => $val)
1590
+				foreach ($value as $key => $val)
1591 1591
 				{
1592
-					switch($label['type'])
1592
+					switch ($label['type'])
1593 1593
 					{
1594 1594
 						case 'select-account':
1595 1595
 							if ($val) $value[$key] = common::grab_owner_name($val);
@@ -1598,11 +1598,11 @@  discard block
 block discarded – undo
1598 1598
 							if ($val)
1599 1599
 							{
1600 1600
 								$cats = array();
1601
-								foreach(is_array($val) ? $val : explode(',',$val) as $cat_id)
1601
+								foreach (is_array($val) ? $val : explode(',', $val) as $cat_id)
1602 1602
 								{
1603 1603
 									$cats[] = $GLOBALS['egw']->categories->id2name($cat_id);
1604 1604
 								}
1605
-								$value[$key] = implode('; ',$cats);
1605
+								$value[$key] = implode('; ', $cats);
1606 1606
 							}
1607 1607
 							break;
1608 1608
 						case 'date-time':
@@ -1610,7 +1610,7 @@  discard block
 block discarded – undo
1610 1610
 							if ($val)
1611 1611
 							{
1612 1612
 								try {
1613
-									$value[$key] = egw_time::to($val,$label['type'] == 'date' ? true : '');
1613
+									$value[$key] = egw_time::to($val, $label['type'] == 'date' ? true : '');
1614 1614
 								}
1615 1615
 								catch (Exception $e) {
1616 1616
 									// ignore conversation errors, leave value unchanged (might be a wrongly as date(time) detected field
@@ -1622,36 +1622,36 @@  discard block
 block discarded – undo
1622 1622
 							{
1623 1623
 								if ($val) $value[$key] = lang($sel_options[$field][$val]);
1624 1624
 							}
1625
-							elseif(is_array($extra_sel_options) && isset($extra_sel_options[$field]))
1625
+							elseif (is_array($extra_sel_options) && isset($extra_sel_options[$field]))
1626 1626
 							{
1627 1627
 								if ($val) $value[$key] = lang($extra_sel_options[$field][$val]);
1628 1628
 							}
1629 1629
 							break;
1630 1630
 						case 'int':		// size: [min],[max],[len],[precission/sprint format]
1631 1631
 						case 'float':
1632
-							list(,,,$pre) = explode(',',$label['size']);
1632
+							list(,,,$pre) = explode(',', $label['size']);
1633 1633
 							if (($label['type'] == 'float' || !is_numeric($pre)) && $val && $pre)
1634 1634
 							{
1635
-								$val = str_replace(array(' ',','),array('','.'),$val);
1636
-								$value[$key] = is_numeric($pre) ? round($value,$pre) : sprintf($pre,$value);
1635
+								$val = str_replace(array(' ', ','), array('', '.'), $val);
1636
+								$value[$key] = is_numeric($pre) ? round($value, $pre) : sprintf($pre, $value);
1637 1637
 							}
1638 1638
 					}
1639 1639
 				}
1640 1640
 			}
1641
-			$value = implode(', ',$value);
1641
+			$value = implode(', ', $value);
1642 1642
 
1643
-			if (strpos($value,$separator) !== false || strpos($value,"\n") !== false || strpos($value,"\r") !== false)
1643
+			if (strpos($value, $separator) !== false || strpos($value, "\n") !== false || strpos($value, "\r") !== false)
1644 1644
 			{
1645
-				$value = '"'.str_replace(array('\\', '"',),array('\\\\','""'),$value).'"';
1645
+				$value = '"'.str_replace(array('\\', '"',), array('\\\\', '""'), $value).'"';
1646 1646
 				$value = str_replace("\r\n", "\n", $value); // to avoid early linebreak by Excel
1647 1647
 			}
1648 1648
 			$out[] = $value;
1649 1649
 		}
1650
-		$out = implode($separator,$out);
1650
+		$out = implode($separator, $out);
1651 1651
 
1652 1652
 		if ($charset_out && $charset != $charset_out)
1653 1653
 		{
1654
-			$out = translation::convert($out,$charset,$charset_out);
1654
+			$out = translation::convert($out, $charset, $charset_out);
1655 1655
 		}
1656 1656
 		return $out;
1657 1657
 	}
@@ -1662,27 +1662,27 @@  discard block
 block discarded – undo
1662 1662
 	 * @param array $row0 first data-row
1663 1663
 	 * @param string $app
1664 1664
 	 */
1665
-	private static function autodetect_fields($row0,$app)
1665
+	private static function autodetect_fields($row0, $app)
1666 1666
 	{
1667
-		$fields = array_combine(array_keys($row0),array_keys($row0));
1667
+		$fields = array_combine(array_keys($row0), array_keys($row0));
1668 1668
 
1669
-		foreach($fields as $name => $label)
1669
+		foreach ($fields as $name => $label)
1670 1670
 		{
1671 1671
 			// try to guess field-type from the fieldname
1672
-			if (preg_match('/(modified|created|start|end)/',$name) && strpos($name,'by')===false &&
1672
+			if (preg_match('/(modified|created|start|end)/', $name) && strpos($name, 'by') === false &&
1673 1673
 				(!$row0[$name] || is_numeric($row0[$name])))	// only use for real timestamps
1674 1674
 			{
1675
-				$fields[$name] = array('label' => $label,'type' => 'date-time');
1675
+				$fields[$name] = array('label' => $label, 'type' => 'date-time');
1676 1676
 			}
1677
-			elseif (preg_match('/(cat_id|category|cat)/',$name))
1677
+			elseif (preg_match('/(cat_id|category|cat)/', $name))
1678 1678
 			{
1679
-				$fields[$name] = array('label' => $label,'type' => 'select-cat');
1679
+				$fields[$name] = array('label' => $label, 'type' => 'select-cat');
1680 1680
 			}
1681
-			elseif (preg_match('/(owner|creator|modifier|assigned|by|coordinator|responsible)/',$name))
1681
+			elseif (preg_match('/(owner|creator|modifier|assigned|by|coordinator|responsible)/', $name))
1682 1682
 			{
1683
-				$fields[$name] = array('label' => $label,'type' => 'select-account');
1683
+				$fields[$name] = array('label' => $label, 'type' => 'select-account');
1684 1684
 			}
1685
-			elseif(preg_match('/(jpeg|photo)/',$name))
1685
+			elseif (preg_match('/(jpeg|photo)/', $name))
1686 1686
 			{
1687 1687
 				unset($fields[$name]);
1688 1688
 			}
@@ -1693,7 +1693,7 @@  discard block
 block discarded – undo
1693 1693
 
1694 1694
 			if (is_array($customfields))
1695 1695
 			{
1696
-				foreach($customfields as $name => $data)
1696
+				foreach ($customfields as $name => $data)
1697 1697
 				{
1698 1698
 					$fields['#'.$name] = array(
1699 1699
 						'label' => $data['label'],
Please login to merge, or discard this patch.
Braces   +295 added lines, -77 removed lines patch added patch discarded remove patch
@@ -211,9 +211,12 @@  discard block
 block discarded – undo
211 211
 				{
212 212
 					$cell['help'] = 'click to order after that criteria';
213 213
 				}
214
-				if (self::last_part($name) == $nm_global['order'] && !$cell['readonly'])	// we're the active column
214
+				if (self::last_part($name) == $nm_global['order'] && !$cell['readonly'])
215
+				{
216
+					// we're the active column
215 217
 				{
216 218
 					$sorting = $cell;
219
+				}
217 220
 					unset($sorting['align']);
218 221
 					unset($sorting['span']);
219 222
 					$cell = boetemplate::empty_cell('hbox','',array(
@@ -240,12 +243,18 @@  discard block
 block discarded – undo
240 243
 				list($type,$cell['size']) = explode(',',$cell['size'],2);
241 244
 				// fall through
242 245
 			case 'nextmatch-filterheader':	// Option: as for selectbox: [extra-label(default ALL)[,#lines(default 1)]]
243
-				if (!$type) $type = 'select';
246
+				if (!$type)
247
+				{
248
+					$type = 'select';
249
+				}
244 250
 				$cell['type'] = $type;
245
-				if (!$cell['size'] && $type != 'link-entry')	// link-entry without option shows application selection!
251
+				if (!$cell['size'] && $type != 'link-entry')
252
+				{
253
+					// link-entry without option shows application selection!
246 254
 				{
247 255
 					$cell['size'] = 'All';
248 256
 				}
257
+				}
249 258
 				if (!$cell['help'])
250 259
 				{
251 260
 					$cell['help'] = 'select which values to show';
@@ -269,14 +278,23 @@  discard block
 block discarded – undo
269 278
 			$value['bottom_too'] = false;
270 279
 		}
271 280
 		// presetting the selectboxes with their default values, to NOT loop, because post-process thinks they changed
272
-		if (!isset($value['cat_id'])) $value['cat_id'] = '';
273
-		if (!isset($value['search'])) $value['search'] = '';
281
+		if (!isset($value['cat_id']))
282
+		{
283
+			$value['cat_id'] = '';
284
+		}
285
+		if (!isset($value['search']))
286
+		{
287
+			$value['search'] = '';
288
+		}
274 289
 		foreach(array('filter','filter2') as $f)
275 290
 		{
276 291
 			if (!isset($value[$f]))
277 292
 			{
278 293
 				list($value[$f]) = isset($tmpl->sel_options[$f]) ? @each($tmpl->sel_options[$f]) : @each($value['options-'.$f]);
279
-				if (!is_string($value[$f])) $value[$f] = (string) $value[$f];
294
+				if (!is_string($value[$f]))
295
+				{
296
+					$value[$f] = (string) $value[$f];
297
+				}
280 298
 			}
281 299
 		}
282 300
 		// save values in persistent extension_data to be able use it in post_process
@@ -288,21 +306,40 @@  discard block
 block discarded – undo
288 306
 			!bo_merge::hasExportLimit($export_limit,'ISALLOWED') &&
289 307
 			!bo_merge::is_export_limit_excepted();
290 308
 
291
-		if (!$value['filter_onchange']) $value['filter_onchange'] = 'this.form.submit();';
292
-		if (!$value['filter2_onchange']) $value['filter2_onchange'] = 'this.form.submit();';
293
-		if (!isset($value['cat_app'])) list($value['cat_app']) = explode('.',$value['get_rows']);	// if no cat_app set, use the app from the get_rows func
309
+		if (!$value['filter_onchange'])
310
+		{
311
+			$value['filter_onchange'] = 'this.form.submit();';
312
+		}
313
+		if (!$value['filter2_onchange'])
314
+		{
315
+			$value['filter2_onchange'] = 'this.form.submit();';
316
+		}
317
+		if (!isset($value['cat_app']))
318
+		{
319
+			list($value['cat_app']) = explode('.',$value['get_rows']);
320
+		}
321
+		// if no cat_app set, use the app from the get_rows func
294 322
 
295
-		if (!($max = (int)$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'])) $max = 15;
323
+		if (!($max = (int)$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']))
324
+		{
325
+			$max = 15;
326
+		}
296 327
 		$row_options = array();
297 328
 		foreach(array(5,12,25,50,100,200,500,999) as $n)
298 329
 		{
299
-			if ($n-5 <= $max && $max <= $n+5) $n = $max;
330
+			if ($n-5 <= $max && $max <= $n+5)
331
+			{
332
+				$n = $max;
333
+			}
300 334
 			$row_options[$n] = $n;
301 335
 		}
302
-		if (!isset($value['num_rows']) || $value['num_rows'] <= 0)	// can be -1 if importexport crashes
336
+		if (!isset($value['num_rows']) || $value['num_rows'] <= 0)
337
+		{
338
+			// can be -1 if importexport crashes
303 339
 		{
304 340
 			$extension_data['num_rows'] = $value['num_rows'] = $max;
305 341
 		}
342
+		}
306 343
 		if (!isset($row_options[$max]) || !isset($row_options[$value['num_rows']]))
307 344
 		{
308 345
 			$row_options[$max] = $max;
@@ -321,7 +358,10 @@  discard block
 block discarded – undo
321 358
 			$value['options-selectcols'] = is_array($value['options-selectcols']) ? $value['options-selectcols'] : array();
322 359
 		}
323 360
 		$rows = array();
324
-		if (!is_array($readonlys)) $readonlys = array();
361
+		if (!is_array($readonlys))
362
+		{
363
+			$readonlys = array();
364
+		}
325 365
 		if (($total = $extension_data['total'] = $value['total'] = self::call_get_rows($value,$rows,$readonlys['rows'])) === false)
326 366
 		{
327 367
 			//error_log(__METHOD__."() etemplate::set_validation_error('$name') '$value[get_rows]' is no valid method!!!");
@@ -337,21 +377,37 @@  discard block
 block discarded – undo
337 377
 		unset($rows);
338 378
 
339 379
 		list($template,$hide_header,$header_left,$header_right) = explode(',',$cell['size']);
340
-		if ($header_left) $value['header_left'] = $header_left;
341
-		if ($header_right) $value['header_right'] = $header_right;
342
-		if ((string)$hide_header !== '') $value['hide_header'] = $hide_header;
380
+		if ($header_left)
381
+		{
382
+			$value['header_left'] = $header_left;
383
+		}
384
+		if ($header_right)
385
+		{
386
+			$value['header_right'] = $header_right;
387
+		}
388
+		if ((string)$hide_header !== '')
389
+		{
390
+			$value['hide_header'] = $hide_header;
391
+		}
343 392
 
344
-		if (!$value['template'] && $template)	// template name can be supplied either in $value['template'] or the options-field
393
+		if (!$value['template'] && $template)
394
+		{
395
+			// template name can be supplied either in $value['template'] or the options-field
345 396
 		{
346 397
 			$value['template'] = $template;
347 398
 		}
399
+		}
348 400
 		if (!is_object($value['template']))
349 401
 		{
350 402
 			$value['template'] = new etemplate($value['template'],$tmpl->as_array());
351 403
 		}
352
-		if (is_array($value['rows'][0]))	// pad 0 based arrays with rows-1 false values
404
+		if (is_array($value['rows'][0]))
405
+		{
406
+			// pad 0 based arrays with rows-1 false values
353 407
 		{
354
-			for($i = 1; $i < $value['template']->rows; $i++)
408
+			for($i = 1;
409
+		}
410
+		$i < $value['template']->rows; $i++)
355 411
 			{
356 412
 				array_unshift($value['rows'],false);
357 413
 			}
@@ -367,7 +423,8 @@  discard block
 block discarded – undo
367 423
 			 ($value['no_cat'] || !$value['cat_id']) &&
368 424
 			 ($value['no_filter'] || !$value['filter'] || $value['filter'] == 'none') &&
369 425
 			 ($value['no_filter2'] || !$value['filter2'] || $value['filter2'] == 'none'))
370
-		{											// disable whole nextmatch line if no scrolling necessary
426
+		{
427
+// disable whole nextmatch line if no scrolling necessary
371 428
 			if ($value['header_left'] || $value['header_right'])
372 429
 			{
373 430
 				$nextmatch = new etemplate('etemplate.nextmatch_widget.header_only');
@@ -393,12 +450,18 @@  discard block
 block discarded – undo
393 450
 			if ($value['cat_is_select'] && ($cat_widget =& $nextmatch->get_widget_by_name('cat_id')))
394 451
 			{
395 452
 				$cat_widget['type'] = 'select';
396
-				if ($value['cat_is_select'] == 'no_lang') $cat_widget['no_lang'] = true;
453
+				if ($value['cat_is_select'] == 'no_lang')
454
+				{
455
+					$cat_widget['no_lang'] = true;
456
+				}
397 457
 			}
398 458
 			if ($value['lettersearch'])
399 459
 			{
400 460
 				$lettersearch =& $nextmatch->get_widget_by_name('lettersearch');	// hbox for the letters
401
-				if (($alphabet = lang('alphabet')) == 'alphabet*') $alphabet = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z';
461
+				if (($alphabet = lang('alphabet')) == 'alphabet*')
462
+				{
463
+					$alphabet = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z';
464
+				}
402 465
 				$alphabet = explode(',',$alphabet);
403 466
 				$alphabet['all'] = lang('all');
404 467
 				foreach($alphabet as $key => $letter)
@@ -407,7 +470,11 @@  discard block
 block discarded – undo
407 470
 					$form_name = $name.'[searchletter]['.($key === 'all' ? $key : $letter).']';
408 471
 					etemplate::$request->set_to_process($form_name,'button');
409 472
 
410
-					if (!$key) $letterbox =& $lettersearch[1];	// to re-use the first child
473
+					if (!$key)
474
+					{
475
+						$letterbox =& $lettersearch[1];
476
+					}
477
+					// to re-use the first child
411 478
 					$letterbox = boetemplate::empty_cell('label',$letter,array(
412 479
 						'label'   => $letter,
413 480
 						'span'    => ',lettersearch'.($letter == (string) $value['searchletter'] ||
@@ -417,23 +484,38 @@  discard block
 block discarded – undo
417 484
 						'onclick' => 'return submitit('.etemplate::$name_form.",'$form_name');",
418 485
 					));
419 486
 					// if not the first (re-used) child, add it to the parent
420
-					if ($key) boetemplate::add_child($lettersearch,$letterbox);
487
+					if ($key)
488
+					{
489
+						boetemplate::add_child($lettersearch,$letterbox);
490
+					}
421 491
 					unset($letterbox);
422 492
 				}
423 493
 				//_debug_array(etemplate::$request->to_process);
424 494
 			}
425
-			if(isset($value['no_search'])) $value['no_start_search'] = $value['no_search'];
495
+			if(isset($value['no_search']))
496
+			{
497
+				$value['no_start_search'] = $value['no_search'];
498
+			}
426 499
 			foreach(array('no_cat'=>'cat_id','no_filter'=>'filter','no_filter2'=>'filter2', 'no_search' => 'search', 'no_start_search' => 'start_search' ) as $val_name => $cell_name)
427 500
 			{
428
-				if (isset($value[$val_name])) $nextmatch->disable_cells($cell_name,$value[$val_name]);
501
+				if (isset($value[$val_name]))
502
+				{
503
+					$nextmatch->disable_cells($cell_name,$value[$val_name]);
504
+				}
429 505
 			}
430 506
 			foreach(array('header_left','header_right') as $name)
431 507
 			{
432
-				if (!$value[$name]) $nextmatch->disable_cells('@'.$name);
508
+				if (!$value[$name])
509
+				{
510
+					$nextmatch->disable_cells('@'.$name);
511
+				}
433 512
 			}
434 513
 			foreach(array('filter','filter2') as $cell_name)
435 514
 			{
436
-				if (isset($value[$cell_name.'_no_lang'])) $nextmatch->set_cell_attribute($cell_name,'no_lang',$value[$cell_name.'_no_lang']);
515
+				if (isset($value[$cell_name.'_no_lang']))
516
+				{
517
+					$nextmatch->set_cell_attribute($cell_name,'no_lang',$value[$cell_name.'_no_lang']);
518
+				}
437 519
 			}
438 520
 			$start = $value['start'];
439 521
 			$end   = $start+$max > $total ? $total : $start+$max;
@@ -452,7 +534,10 @@  discard block
 block discarded – undo
452 534
 		{
453 535
 			$name = is_object($value['template']) ? $value['template']->name : $value['template'];
454 536
 			list($app) = explode('.',$name);
455
-			if (isset($value['columnselection_pref'])) $name = $value['columnselection_pref'];
537
+			if (isset($value['columnselection_pref']))
538
+			{
539
+				$name = $value['columnselection_pref'];
540
+			}
456 541
 			$this->selectcols = $value['selectcols'] = $GLOBALS['egw_info']['user']['preferences'][$app]['nextmatch-'.$name];
457 542
 			// fetching column-names & -labels from the template
458 543
 			if ($this->cols_from_tpl($value['template'],$value['options-selectcols'],$name2col,$value['rows'],$value['selectcols']))
@@ -476,19 +561,28 @@  discard block
 block discarded – undo
476 561
 					}
477 562
 					$this->selectcols = $value['selectcols'];
478 563
 				}
479
-				if (!is_array($value['selectcols'])) $value['selectcols'] = explode(',',$value['selectcols']);
564
+				if (!is_array($value['selectcols']))
565
+				{
566
+					$value['selectcols'] = explode(',',$value['selectcols']);
567
+				}
480 568
 				foreach(array_unique(array_keys($value['options-selectcols']+$name2col)) as $name)
481 569
 				{
482 570
 					// set 'no_'.$col for each column-name to true, if the column is not selected
483 571
 					// (and the value is not set be the get_rows function / programmer!)
484
-					if (!isset($value['rows']['no_'.$name])) $value['rows']['no_'.$name] = !in_array($name,$value['selectcols']);
572
+					if (!isset($value['rows']['no_'.$name]))
573
+					{
574
+						$value['rows']['no_'.$name] = !in_array($name,$value['selectcols']);
575
+					}
485 576
 					// setting '@no_'.$name as disabled attr for each column, that has only a single nextmatch-header
486 577
 					if (is_object($value['template']))
487 578
 					{
488 579
 						$col = $name2col[$name];
489 580
 						list(,$disabled) = $value['template']->set_column_attributes($col);
490 581
 						//echo "<p>$col: $name: $disabled</p>\n";
491
-						if (!isset($disabled)) $value['template']->set_column_attributes($col,0,'@no_'.$name);
582
+						if (!isset($disabled))
583
+						{
584
+							$value['template']->set_column_attributes($col,0,'@no_'.$name);
585
+						}
492 586
 					}
493 587
 				}
494 588
 				//_debug_array($value);
@@ -497,7 +591,10 @@  discard block
 block discarded – undo
497 591
 					$size =& $nextmatch->get_cell_attribute('selectcols','size');
498 592
 					// Don't change to fancy multi-select here
499 593
 					$nextmatch->set_cell_attribute('selectcols','enhance',false);
500
-					if ($size > count($value['options-selectcols'])) $size = '0'.count($value['options-selectcols']);
594
+					if ($size > count($value['options-selectcols']))
595
+					{
596
+						$size = '0'.count($value['options-selectcols']);
597
+					}
501 598
 					if (!$GLOBALS['egw_info']['user']['apps']['admin'])
502 599
 					{
503 600
 						$nextmatch->disable_cells('default_prefs');
@@ -526,14 +623,20 @@  discard block
 block discarded – undo
526 623
 				);
527 624
 			}
528 625
 		}
529
-		if (!$value['filter_onchange']) $value['filter_onchange'] = 'this.form.submit();';
626
+		if (!$value['filter_onchange'])
627
+		{
628
+			$value['filter_onchange'] = 'this.form.submit();';
629
+		}
530 630
 		$cell['type'] = 'template';
531 631
 		$cell['label'] = $cell['help'] = '';
532 632
 
533
-		foreach(array('sort','order','col_filter') as $n)	// save them for the sortheader
633
+		foreach(array('sort','order','col_filter') as $n)
634
+		{
635
+			// save them for the sortheader
534 636
 		{
535 637
 			$nm_global[$n] = $value[$n];
536 638
 		}
639
+		}
537 640
 		$value['bottom'] = $value;	// copy the values for the bottom-bar
538 641
 
539 642
 		// pass actions and row_id to etemplate::show_grid()
@@ -651,8 +754,14 @@  discard block
 block discarded – undo
651 754
 		foreach((array)$actions as $id => $action)
652 755
 		{
653 756
 			// in case it's only selectbox  id => label pairs
654
-			if (!is_array($action)) $action = array('caption' => $action);
655
-			if ($default_attrs) $action += $default_attrs;
757
+			if (!is_array($action))
758
+			{
759
+				$action = array('caption' => $action);
760
+			}
761
+			if ($default_attrs)
762
+			{
763
+				$action += $default_attrs;
764
+			}
656 765
 
657 766
 			if (!$first_level && $n == $max_length && count($actions) > $max_length)
658 767
 			{
@@ -697,7 +806,10 @@  discard block
 block discarded – undo
697 806
 			if (!$action['no_lang'])
698 807
 			{
699 808
 				$action['caption'] = lang($action['caption']);
700
-				if ($action['hint']) $action['hint'] = lang($action['hint']);
809
+				if ($action['hint'])
810
+				{
811
+					$action['hint'] = lang($action['hint']);
812
+				}
701 813
 			}
702 814
 			unset($action['no_lang']);
703 815
 
@@ -754,11 +866,17 @@  discard block
 block discarded – undo
754 866
 			);
755 867
 			// add all not egw_action supported attributes to data
756 868
 			$action['data'] = array_merge(array_diff_key($action, array_flip($egw_action_supported)),(array)$action['data']);
757
-			if (!$action['data']) unset($action['data']);
869
+			if (!$action['data'])
870
+			{
871
+				unset($action['data']);
872
+			}
758 873
 			// only add egw_action attributes
759 874
 			$egw_actions[] = array_intersect_key($action, array_flip($egw_action_supported));
760 875
 
761
-			if (!$first_level && $n++ == $max_length) break;
876
+			if (!$first_level && $n++ == $max_length)
877
+			{
878
+				break;
879
+			}
762 880
 		}
763 881
 		//echo "egw_actions="; _debug_array($egw_actions);
764 882
 		return $egw_actions;
@@ -897,7 +1015,10 @@  discard block
 block discarded – undo
897 1015
 
898 1016
 		//egw_framework::validate_file('dhtmlxtree','dhtmlxMenu/codebase/ext/dhtmlxmenu_ext');
899 1017
 
900
-		if (!is_array($action_links)) $action_links = array();
1018
+		if (!is_array($action_links))
1019
+		{
1020
+			$action_links = array();
1021
+		}
901 1022
 
902 1023
 		$app = $GLOBALS['egw_info']['flags']['currentapp'];
903 1024
 
@@ -956,7 +1077,10 @@  discard block
 block discarded – undo
956 1077
 	 */
957 1078
 	private static function call_get_rows(array &$value,array &$rows=null,array &$readonlys=null,$obj=null,$method=null)
958 1079
 	{
959
-		if (is_null($method)) $method = $value['get_rows'];
1080
+		if (is_null($method))
1081
+		{
1082
+			$method = $value['get_rows'];
1083
+		}
960 1084
 
961 1085
 		if (is_null($obj))
962 1086
 		{
@@ -982,23 +1106,32 @@  discard block
 block discarded – undo
982 1106
 				{
983 1107
 					$GLOBALS[$class] = new $class();
984 1108
 				}
985
-				if (is_object($GLOBALS[$class]))	// use existing instance (put there by a previous CreateObject)
1109
+				if (is_object($GLOBALS[$class]))
1110
+				{
1111
+					// use existing instance (put there by a previous CreateObject)
986 1112
 				{
987 1113
 					$obj = $GLOBALS[$class];
988 1114
 				}
1115
+				}
989 1116
 				else
990 1117
 				{
991 1118
 					$obj = CreateObject($app.'.'.$class);
992 1119
 				}
993 1120
 			}
994 1121
 		}
995
-		if(is_callable($method))	// php5.2.3+ static call (value is always a var param!)
1122
+		if(is_callable($method))
1123
+		{
1124
+			// php5.2.3+ static call (value is always a var param!)
996 1125
 		{
997 1126
 			$total = call_user_func_array($method,array(&$value,&$rows,&$readonlys));
998 1127
 		}
1128
+		}
999 1129
 		elseif(is_object($obj) && method_exists($obj,$method))
1000 1130
 		{
1001
-			if (!is_array($readonlys)) $readonlys = array();
1131
+			if (!is_array($readonlys))
1132
+			{
1133
+				$readonlys = array();
1134
+			}
1002 1135
 			$total = $obj->$method($value,$rows,$readonlys);
1003 1136
 		}
1004 1137
 		else
@@ -1011,7 +1144,10 @@  discard block
 block discarded – undo
1011 1144
 			$total = self::call_get_rows($value,$rows,$readonlys,$obj,$method);
1012 1145
 		}
1013 1146
 		// otherwise we get stoped by max_excutiontime
1014
-		if ($total > 200) @set_time_limit(0);
1147
+		if ($total > 200)
1148
+		{
1149
+			@set_time_limit(0);
1150
+		}
1015 1151
 		//error_log($value['get_rows'].'() returning '.array2string($total).', method = '.array2string($method).', value = '.array2string($value));
1016 1152
 		return $total;
1017 1153
 	}
@@ -1042,7 +1178,10 @@  discard block
 block discarded – undo
1042 1178
 		{
1043 1179
 			foreach(is_array($this->selectcols) ? $this->selectcols : explode(',',$this->selectcols) as $col)
1044 1180
 			{
1045
-				if ($col[0] == self::CF_PREFIX) $allowed[] = $col;
1181
+				if ($col[0] == self::CF_PREFIX)
1182
+				{
1183
+					$allowed[] = $col;
1184
+				}
1046 1185
 			}
1047 1186
 		}
1048 1187
 		foreach($this->cfs as $name => $field)
@@ -1119,7 +1258,10 @@  discard block
 block discarded – undo
1119 1258
 		//_debug_array($cols);
1120 1259
 		foreach($cols as $name => $label)
1121 1260
 		{
1122
-			if (!$label) unset($cols[$name]);
1261
+			if (!$label)
1262
+			{
1263
+				unset($cols[$name]);
1264
+			}
1123 1265
 		}
1124 1266
 		//_debug_array($cols);
1125 1267
 		$cols2 = $cols;
@@ -1171,8 +1313,14 @@  discard block
 block discarded – undo
1171 1313
 
1172 1314
 		if ($subtype == 'customfields')
1173 1315
 		{
1174
-			if (!$widget['name']) $widget['name'] = 'customfields';
1175
-			if (!$widget['label']) $widget['label'] = 'Custom fields';
1316
+			if (!$widget['name'])
1317
+			{
1318
+				$widget['name'] = 'customfields';
1319
+			}
1320
+			if (!$widget['label'])
1321
+			{
1322
+				$widget['label'] = 'Custom fields';
1323
+			}
1176 1324
 			$this->cf_header = $widget['name'];
1177 1325
 		}
1178 1326
 		if ($type != 'nextmatch' || !$subtype || !$widget['name'] || $widget['disabled'])
@@ -1182,12 +1330,18 @@  discard block
 block discarded – undo
1182 1330
 		$options = explode(',',$widget['size']);
1183 1331
 		if (!($label = $widget['label']) || in_array($subtype,array('header','sortheader')) && $options[1])
1184 1332
 		{
1185
-			if (in_array($subtype,array('customfilter','sortheader'))) $subtype = array_shift($options);
1333
+			if (in_array($subtype,array('customfilter','sortheader')))
1334
+			{
1335
+				$subtype = array_shift($options);
1336
+			}
1186 1337
 
1187 1338
 			$label = $options[0];
1188 1339
 
1189 1340
 			// some widgets have label as second option (column name with _ as first), not a perfect detection ...
1190
-			if (strpos($label,'_') !== false && !empty($options[1])) $label = $options[1];
1341
+			if (strpos($label,'_') !== false && !empty($options[1]))
1342
+			{
1343
+				$label = $options[1];
1344
+			}
1191 1345
 		}
1192 1346
 		list(,,$col,$sub) = explode('/',$path);
1193 1347
 		$row = (int)$col;
@@ -1231,7 +1385,9 @@  discard block
 block discarded – undo
1231 1385
 	{
1232 1386
 		$nm_global =& self::get_nm_global($name,$extension_data['type']);
1233 1387
 
1234
-		if ($this->debug) { echo "<p>nextmatch_widget.post_process(type='$extension_data[type]', name='$name',value_in=".print_r($value_in,true).",order='$nm_global[order]'): value = "; _debug_array($value); }
1388
+		if ($this->debug)
1389
+		{
1390
+echo "<p>nextmatch_widget.post_process(type='$extension_data[type]', name='$name',value_in=".print_r($value_in,true).",order='$nm_global[order]'): value = "; _debug_array($value); }
1235 1391
 
1236 1392
 		switch($extension_data['type'])
1237 1393
 		{
@@ -1264,7 +1420,10 @@  discard block
 block discarded – undo
1264 1420
 			case 'nextmatch-filterheader':
1265 1421
 				if ((string)$value_in != (string)$extension_data['old_value'])
1266 1422
 				{
1267
-					if ($this->debug) echo "<p>setting nm_global[filter][".self::last_part($name)."]='$value_in' (was '$extension_data[old_value]')</p>\n";
1423
+					if ($this->debug)
1424
+					{
1425
+						echo "<p>setting nm_global[filter][".self::last_part($name)."]='$value_in' (was '$extension_data[old_value]')</p>\n";
1426
+					}
1268 1427
 					$nm_global['filter'][self::last_part($name)] = $value_in;
1269 1428
 				}
1270 1429
 				return False;	// dont report value back, as it's in the wrong location (rows)
@@ -1273,19 +1432,27 @@  discard block
 block discarded – undo
1273 1432
 				return False;	// nothing to report
1274 1433
 		}
1275 1434
 		$old_value = $extension_data;
1276
-		if ($this->debug) { echo "old_value="; _debug_array($old_value); }
1435
+		if ($this->debug)
1436
+		{
1437
+echo "old_value="; _debug_array($old_value); }
1277 1438
 
1278 1439
 		$value['start'] = $old_value['start'];	// need to be set, to be reported back
1279 1440
 		$value['return'] = $old_value['return'];
1280 1441
 
1281
-		if (is_array($value['bottom']))			// we have a second bottom-bar
1442
+		if (is_array($value['bottom']))
1443
+		{
1444
+			// we have a second bottom-bar
1282 1445
 		{
1283 1446
 			$inputs = array('search','cat_id','filter','filter2','num_rows');
1447
+		}
1284 1448
 			foreach($inputs as $name)
1285 1449
 			{
1286 1450
 				if (isset($value['bottom'][$name]) && $value[$name] == $old_value[$name])
1287 1451
 				{
1288
-					if ($this->debug) echo "value[$name] overwritten by bottom-value[$name]='".$value['bottom'][$name]."', old_value[$name]='".$old_value[$name]."'<br>\n";
1452
+					if ($this->debug)
1453
+					{
1454
+						echo "value[$name] overwritten by bottom-value[$name]='".$value['bottom'][$name]."', old_value[$name]='".$old_value[$name]."'<br>\n";
1455
+					}
1289 1456
 					$value[$name] = $value['bottom'][$name];
1290 1457
 				}
1291 1458
 			}
@@ -1306,14 +1473,18 @@  discard block
 block discarded – undo
1306 1473
 		}
1307 1474
 		if (isset($old_value['num_rows']) && !is_null($value['num_rows']) && $value['num_rows'] != $old_value['num_rows'])
1308 1475
 		{
1309
-			if ($this->debug) echo "<p>nextmatch_widget::post_process() num_rows changed {$old_value['num_rows']} --> {$value['num_rows']} ==> looping</p>\n";
1476
+			if ($this->debug)
1477
+			{
1478
+				echo "<p>nextmatch_widget::post_process() num_rows changed {$old_value['num_rows']} --> {$value['num_rows']} ==> looping</p>\n";
1479
+			}
1310 1480
 			$loop = true;	// num_rows changed
1311 1481
 		}
1312 1482
 		// num_rows: use old value in extension data, if $value['num_rows'] is not set because nm-header is not shown
1313 1483
 		$value['num_rows'] = isset($value['num_rows']) ? (int) $value['num_rows'] : (int) $extension_data['num_rows'];
1314 1484
 		$max = $value['num_rows'] ? $value['num_rows'] : (int)$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'];
1315 1485
 
1316
-		if(strpos($value['search'],'xjxquery')) {
1486
+		if(strpos($value['search'],'xjxquery'))
1487
+		{
1317 1488
 			// We deal with advancedsearch
1318 1489
 			$aXml = $value['search'];
1319 1490
 			$value['search'] = '';
@@ -1376,12 +1547,18 @@  discard block
 block discarded – undo
1376 1547
 			{
1377 1548
 				$value['sort'] = $old_value['sort'] != 'DESC' ? 'DESC' : 'ASC';
1378 1549
 			}
1379
-			if ($this->debug) echo "<p>old_value=$old_value[order]/$old_value[sort] ==> $value[order]/$value[sort]</p>\n";
1550
+			if ($this->debug)
1551
+			{
1552
+				echo "<p>old_value=$old_value[order]/$old_value[sort] ==> $value[order]/$value[sort]</p>\n";
1553
+			}
1380 1554
 			$loop = True;
1381 1555
 		}
1382 1556
 		elseif ($nm_global['filter'])
1383 1557
 		{
1384
-			if (!is_array($value['col_filter'])) $value['col_filter'] = array();
1558
+			if (!is_array($value['col_filter']))
1559
+			{
1560
+				$value['col_filter'] = array();
1561
+			}
1385 1562
 
1386 1563
 			$value['col_filter'] += $nm_global['filter'];
1387 1564
 			$loop = True;
@@ -1389,14 +1566,20 @@  discard block
 block discarded – undo
1389 1566
 		elseif (isset($value['searchletter']))
1390 1567
 		{
1391 1568
 			list($value['searchletter']) = @each($value['searchletter']);
1392
-			if ($value['searchletter'] === 'all') $value['searchletter'] = false;
1569
+			if ($value['searchletter'] === 'all')
1570
+			{
1571
+				$value['searchletter'] = false;
1572
+			}
1393 1573
 			$loop = True;
1394 1574
 		}
1395 1575
 		if ($value['savecols'])
1396 1576
 		{
1397 1577
 			$name = is_object($extension_data['template']) ? $extension_data['template']->name : $extension_data['template'];
1398 1578
 			list($app) = explode('.',$name);
1399
-			if (isset($extension_data['columnselection_pref'])) $name = $extension_data['columnselection_pref'];
1579
+			if (isset($extension_data['columnselection_pref']))
1580
+			{
1581
+				$name = $extension_data['columnselection_pref'];
1582
+			}
1400 1583
 			$pref = !$GLOBALS['egw_info']['user']['apps']['admin'] && $value['default_prefs'] ? 'default' : 'user';
1401 1584
 			$GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->add($app,'nextmatch-'.$name,is_array($value['selectcols']) ?
1402 1585
 				implode(',',$value['selectcols']) : $value['selectcols'],$pref);
@@ -1415,7 +1598,10 @@  discard block
 block discarded – undo
1415 1598
 		foreach(explode(';',$checkboxes) as $data)
1416 1599
 		{
1417 1600
 			list($name,$checked) = explode(':',$data);
1418
-			if ($name) $value['checkboxes'][$name] = (boolean)$checked;
1601
+			if ($name)
1602
+			{
1603
+				$value['checkboxes'][$name] = (boolean)$checked;
1604
+			}
1419 1605
 		}
1420 1606
 		$value['select_all'] =& $value['checkboxes']['select_all'];
1421 1607
 
@@ -1434,11 +1620,15 @@  discard block
 block discarded – undo
1434 1620
 			list($app) = explode('.',$tmpl->name);
1435 1621
 			$this->cfs = config::get_customfields($app);
1436 1622
 		}
1437
-		foreach($this->cfs as $name => $field) {
1438
-			if($GLOBALS['egw_info']['apps'][$field['type']]) {
1439
-				if(is_array($value_in[self::CF_PREFIX.$name])) {
1623
+		foreach($this->cfs as $name => $field)
1624
+		{
1625
+			if($GLOBALS['egw_info']['apps'][$field['type']])
1626
+			{
1627
+				if(is_array($value_in[self::CF_PREFIX.$name]))
1628
+				{
1440 1629
 					list($old_app, $old_id) = explode(':', $extension_data['old_value'][self::CF_PREFIX.$name]);
1441
-					if($value_in[self::CF_PREFIX.$name]['id'] != '' && $value_in[self::CF_PREFIX.$name]['id'] != $old_id)  {
1630
+					if($value_in[self::CF_PREFIX.$name]['id'] != '' && $value_in[self::CF_PREFIX.$name]['id'] != $old_id)
1631
+					{
1442 1632
 						$nm_global['filter'][self::CF_PREFIX.$name] = $value_in[self::CF_PREFIX.$name]['id'];
1443 1633
 					}
1444 1634
 				}
@@ -1494,21 +1684,31 @@  discard block
 block discarded – undo
1494 1684
 				etemplate::set_validation_error($name,lang('You are not allowed to export more than %1 entries!',(int)$export_limit));
1495 1685
 				return false;
1496 1686
 			}
1497
-			if (!isset($value['no_csv_support'])) $value['no_csv_support'] = !is_array($value['csv_fields']);
1687
+			if (!isset($value['no_csv_support']))
1688
+			{
1689
+				$value['no_csv_support'] = !is_array($value['csv_fields']);
1690
+			}
1498 1691
 
1499 1692
 			//echo "<p>start=$value[start], num_rows=$value[num_rows]: total=$total, count(\$rows)=".count($rows)."</p>\n";
1500
-			if (!$value['start'])	// send the neccessary headers
1693
+			if (!$value['start'])
1694
+			{
1695
+				// send the neccessary headers
1501 1696
 			{
1502 1697
 				// skip empty data row(s) used to adjust to number of header-lines
1503 1698
 				foreach($rows as $row0)
1504 1699
 				{
1505 1700
 					if (is_array($row0) && count($row0) > 1) break;
1701
+			}
1506 1702
 				}
1507 1703
 				$fp = self::csv_open($row0,$value['csv_fields'],$app,$charset_out,$charset,$separator);
1508 1704
 			}
1509 1705
 			foreach($rows as $key => $row)
1510 1706
 			{
1511
-				if (!is_numeric($key) || !$row) continue;	// not a real rows
1707
+				if (!is_numeric($key) || !$row)
1708
+				{
1709
+					continue;
1710
+				}
1711
+				// not a real rows
1512 1712
 				fwrite($fp,self::csv_encode($row,$value['csv_fields'],true,$rows['sel_options'],$charset_out,$charset,$separator)."\n");
1513 1713
 			}
1514 1714
 			$value['start'] += $value['num_rows'];
@@ -1520,10 +1720,13 @@  discard block
 block discarded – undo
1520 1720
 		unset($value['csv_export']);
1521 1721
 		$value['start'] = $backup_start;
1522 1722
 		$value['num_rows'] = $backup_num_rows;
1523
-		if ($value['no_csv_support'])	// we need to call the get_rows method in case start&num_rows are stored in the session
1723
+		if ($value['no_csv_support'])
1724
+		{
1725
+			// we need to call the get_rows method in case start&num_rows are stored in the session
1524 1726
 		{
1525 1727
 			self::call_get_rows($value);
1526 1728
 		}
1729
+		}
1527 1730
 		if ($fp)
1528 1731
 		{
1529 1732
 			fclose($fp);
@@ -1557,7 +1760,10 @@  discard block
 block discarded – undo
1557 1760
 			$labels = array();
1558 1761
 			foreach($fields as $field => $label)
1559 1762
 			{
1560
-				if (is_array($label)) $label = $label['label'];
1763
+				if (is_array($label))
1764
+				{
1765
+					$label = $label['label'];
1766
+				}
1561 1767
 				$labels[$field] = $label ? $label : $field;
1562 1768
 			}
1563 1769
 			fwrite($fp,self::csv_encode($labels,$fields,false,null,$charset_out,$charset,$separator)."\n");
@@ -1592,7 +1798,10 @@  discard block
 block discarded – undo
1592 1798
 					switch($label['type'])
1593 1799
 					{
1594 1800
 						case 'select-account':
1595
-							if ($val) $value[$key] = common::grab_owner_name($val);
1801
+							if ($val)
1802
+							{
1803
+								$value[$key] = common::grab_owner_name($val);
1804
+							}
1596 1805
 							break;
1597 1806
 						case 'select-cat':
1598 1807
 							if ($val)
@@ -1620,11 +1829,17 @@  discard block
 block discarded – undo
1620 1829
 						case 'select':
1621 1830
 							if (isset($sel_options[$field]))
1622 1831
 							{
1623
-								if ($val) $value[$key] = lang($sel_options[$field][$val]);
1832
+								if ($val)
1833
+								{
1834
+									$value[$key] = lang($sel_options[$field][$val]);
1835
+								}
1624 1836
 							}
1625 1837
 							elseif(is_array($extra_sel_options) && isset($extra_sel_options[$field]))
1626 1838
 							{
1627
-								if ($val) $value[$key] = lang($extra_sel_options[$field][$val]);
1839
+								if ($val)
1840
+								{
1841
+									$value[$key] = lang($extra_sel_options[$field][$val]);
1842
+								}
1628 1843
 							}
1629 1844
 							break;
1630 1845
 						case 'int':		// size: [min],[max],[len],[precission/sprint format]
@@ -1670,10 +1885,13 @@  discard block
 block discarded – undo
1670 1885
 		{
1671 1886
 			// try to guess field-type from the fieldname
1672 1887
 			if (preg_match('/(modified|created|start|end)/',$name) && strpos($name,'by')===false &&
1673
-				(!$row0[$name] || is_numeric($row0[$name])))	// only use for real timestamps
1888
+				(!$row0[$name] || is_numeric($row0[$name])))
1889
+			{
1890
+				// only use for real timestamps
1674 1891
 			{
1675 1892
 				$fields[$name] = array('label' => $label,'type' => 'date-time');
1676 1893
 			}
1894
+			}
1677 1895
 			elseif (preg_match('/(cat_id|category|cat)/',$name))
1678 1896
 			{
1679 1897
 				$fields[$name] = array('label' => $label,'type' => 'select-cat');
Please login to merge, or discard this patch.
etemplate/inc/class.so_sql.inc.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
 	 *
705 705
 	 * @param array $_fields
706 706
 	 * @param boolean $merge =true if true $fields will be merged with $this->data (after update!), otherwise $this->data will be just $fields
707
-	 * @return int|boolean 0 on success, or errno != 0 on error, or true if $extra_where is given and no rows affected
707
+	 * @return integer 0 on success, or errno != 0 on error, or true if $extra_where is given and no rows affected
708 708
 	 */
709 709
 	function update($_fields,$merge=true)
710 710
 	{
@@ -1194,7 +1194,7 @@  discard block
 block discarded – undo
1194 1194
 	 * @param string &$wildcard ='' on return wildcard char to use, if pattern does not already contain wildcards!
1195 1195
 	 * @param string &$op ='AND' on return boolean operation to use, if pattern does not start with ! we use OR else AND
1196 1196
 	 * @param string $extra_col =null extra column to search
1197
-	 * @param array $search_cols =array() List of columns to search.  If not provided, all columns in $this->db_cols will be considered
1197
+	 * @param string[] $search_cols =array() List of columns to search.  If not provided, all columns in $this->db_cols will be considered
1198 1198
 	 * @return array or column => value pairs
1199 1199
 	 */
1200 1200
 	public function search2criteria($_pattern,&$wildcard='',&$op='AND',$extra_col=null, $search_cols = array())
Please login to merge, or discard this patch.
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1367,14 +1367,14 @@
 block discarded – undo
1367 1367
 	}
1368 1368
 
1369 1369
 	/**
1370
-	* Get a default list of columns to search
1371
-	* This is to be used as a fallback, for when the extending class does not define
1372
-	* $this->columns_to_search.  All the columns are considered, and any with $skip_columns_with in
1373
-	* their name are discarded because these columns are expected to be foreign keys or other numeric
1374
-	* values with no meaning to the user.
1375
-	*
1376
-	* @return array of column names
1377
-	*/
1370
+	 * Get a default list of columns to search
1371
+	 * This is to be used as a fallback, for when the extending class does not define
1372
+	 * $this->columns_to_search.  All the columns are considered, and any with $skip_columns_with in
1373
+	 * their name are discarded because these columns are expected to be foreign keys or other numeric
1374
+	 * values with no meaning to the user.
1375
+	 *
1376
+	 * @return array of column names
1377
+	 */
1378 1378
 	protected function get_default_search_columns()
1379 1379
 	{
1380 1380
 		$skip_columns_with = array('_id', 'modified', 'modifier', 'status', 'cat_id', 'owner');
Please login to merge, or discard this patch.
Spacing   +227 added lines, -227 removed lines patch added patch discarded remove patch
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 	 *
181 181
 	 * @return so_sql
182 182
 	 */
183
-	function __construct($app='',$table='',$db=null,$column_prefix='',$no_clone=false,$timestamp_type=null)
183
+	function __construct($app = '', $table = '', $db = null, $column_prefix = '', $no_clone = false, $timestamp_type = null)
184 184
 	{
185 185
 		if ($no_clone)
186 186
 		{
@@ -198,11 +198,11 @@  discard block
 block discarded – undo
198 198
 
199 199
 			if (!$no_clone) $this->db->set_app($app);
200 200
 
201
-			if ($table) $this->setup_table($app,$table,$column_prefix);
201
+			if ($table) $this->setup_table($app, $table, $column_prefix);
202 202
 		}
203 203
 		$this->init();
204 204
 
205
-		if ((int) $this->debug >= 4)
205
+		if ((int)$this->debug >= 4)
206 206
 		{
207 207
 			echo "<p>so_sql('$app','$table')</p>\n";
208 208
 			_debug_array($this);
@@ -217,21 +217,21 @@  discard block
 block discarded – undo
217 217
 	 * 	null=leave them as is, 'ts'|'integer' use integer unix timestamps, 'object' use egw_time objects,
218 218
 	 *  'string' use DB timestamp (Y-m-d H:i:s) string
219 219
 	 */
220
-	public function set_times($timestamp_type=false)
220
+	public function set_times($timestamp_type = false)
221 221
 	{
222 222
 		if ($timestamp_type !== false) $this->timestamp_type = $timestamp_type;
223 223
 
224 224
 		// set current time
225
-		switch($this->timestamp_type)
225
+		switch ($this->timestamp_type)
226 226
 		{
227 227
 			case 'object':
228 228
 				$this->now = new egw_time('now');
229 229
 				break;
230 230
 			case 'string':
231
-				$this->now = egw_time::to('now',egw_time::DATABASE);
231
+				$this->now = egw_time::to('now', egw_time::DATABASE);
232 232
 				break;
233 233
 			default:
234
-				$this->now = egw_time::to('now','ts');
234
+				$this->now = egw_time::to('now', 'ts');
235 235
 		}
236 236
 		$this->tz_offset_s = egw_time::tz_offset_s();
237 237
 	}
@@ -241,9 +241,9 @@  discard block
 block discarded – undo
241 241
 	 *
242 242
 	 * @deprecated use __construct
243 243
 	 */
244
-	function so_sql($app='',$table='',$db=null,$column_prefix='',$no_clone=false)
244
+	function so_sql($app = '', $table = '', $db = null, $column_prefix = '', $no_clone = false)
245 245
 	{
246
-		self::__construct($app,$table,$db,$column_prefix,$no_clone);
246
+		self::__construct($app, $table, $db, $column_prefix, $no_clone);
247 247
 	}
248 248
 
249 249
 	/**
@@ -255,10 +255,10 @@  discard block
 block discarded – undo
255 255
 	 * @param string $table table-name
256 256
 	 * @param string $colum_prefix ='' column prefix to automatic remove from the column-name, if the column name starts with it
257 257
 	 */
258
-	function setup_table($app,$table,$colum_prefix='')
258
+	function setup_table($app, $table, $colum_prefix = '')
259 259
 	{
260 260
 		$this->table_name = $table;
261
-		$this->table_def = $this->db->get_table_definitions($app,$table);
261
+		$this->table_def = $this->db->get_table_definitions($app, $table);
262 262
 		if (!$this->table_def || !is_array($this->table_def['fd']))
263 263
 		{
264 264
 			throw new egw_exception_wrong_parameter(__METHOD__."('$app','$table'): No table definition for '$table' found !!!");
@@ -266,14 +266,14 @@  discard block
 block discarded – undo
266 266
 		$this->db_key_cols = $this->db_data_cols = $this->db_cols = array();
267 267
 		$this->autoinc_id = '';
268 268
 		$len_prefix = strlen($colum_prefix);
269
-		foreach($this->table_def['fd'] as $col => $def)
269
+		foreach ($this->table_def['fd'] as $col => $def)
270 270
 		{
271 271
 			$name = $col;
272
-			if ($len_prefix && substr($name,0,$len_prefix) == $colum_prefix)
272
+			if ($len_prefix && substr($name, 0, $len_prefix) == $colum_prefix)
273 273
 			{
274
-				$name = substr($col,$len_prefix);
274
+				$name = substr($col, $len_prefix);
275 275
 			}
276
-			if (in_array($col,$this->table_def['pk']))
276
+			if (in_array($col, $this->table_def['pk']))
277 277
 			{
278 278
 				$this->db_key_cols[$col] = $name;
279 279
 			}
@@ -289,13 +289,13 @@  discard block
 block discarded – undo
289 289
 			}
290 290
 			if ($def['type'] == 'bool') $this->has_bools = true;
291 291
 
292
-			foreach($this->table_def['uc'] as $k => $uni_index)
292
+			foreach ($this->table_def['uc'] as $k => $uni_index)
293 293
 			{
294
-				if (is_array($uni_index) && in_array($name,$uni_index))
294
+				if (is_array($uni_index) && in_array($name, $uni_index))
295 295
 				{
296 296
 					$this->db_uni_cols[$k][$col] = $name;
297 297
 				}
298
-				elseif($name === $uni_index)
298
+				elseif ($name === $uni_index)
299 299
 				{
300 300
 					$this->db_uni_cols[$col] = $name;
301 301
 				}
@@ -310,9 +310,9 @@  discard block
 block discarded – undo
310 310
 	function convert_all_timestamps()
311 311
 	{
312 312
 		$check_already_included = !empty($this->timestamps);
313
-		foreach($this->table_def['fd'] as $name => $data)
313
+		foreach ($this->table_def['fd'] as $name => $data)
314 314
 		{
315
-			if ($data['type'] == 'timestamp' && (!$check_already_included || !in_array($name,$this->timestamps)))
315
+			if ($data['type'] == 'timestamp' && (!$check_already_included || !in_array($name, $this->timestamps)))
316 316
 			{
317 317
 				$this->timestamps[] = $name;
318 318
 			}
@@ -326,22 +326,22 @@  discard block
 block discarded – undo
326 326
 	 */
327 327
 	function data_merge($new)
328 328
 	{
329
-		if ((int) $this->debug >= 4) echo "<p>so_sql::data_merge(".print_r($new,true).")</p>\n";
329
+		if ((int)$this->debug >= 4) echo "<p>so_sql::data_merge(".print_r($new, true).")</p>\n";
330 330
 
331 331
 		if (!is_array($new) || !count($new))
332 332
 		{
333 333
 			return;
334 334
 		}
335
-		foreach($this->db_cols as $db_col => $col)
335
+		foreach ($this->db_cols as $db_col => $col)
336 336
 		{
337
-			if (array_key_exists($col,$new))
337
+			if (array_key_exists($col, $new))
338 338
 			{
339 339
 				$this->data[$col] = $new[$col];
340 340
 			}
341 341
 		}
342
-		foreach($this->non_db_cols as $db_col => $col)
342
+		foreach ($this->non_db_cols as $db_col => $col)
343 343
 		{
344
-			if (array_key_exists($col,$new))
344
+			if (array_key_exists($col, $new))
345 345
 			{
346 346
 				$this->data[$col] = $new[$col];
347 347
 			}
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
 		{
351 351
 			$this->data[self::USER_TIMEZONE_READ] = $new[self::USER_TIMEZONE_READ];
352 352
 		}
353
-		if ((int) $this->debug >= 4) _debug_array($this->data);
353
+		if ((int)$this->debug >= 4) _debug_array($this->data);
354 354
 	}
355 355
 
356 356
 	/**
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
 	 * @param array $data =null if given works on that array and returns result, else works on internal data-array
375 375
 	 * @return array
376 376
 	 */
377
-	function db2data($data=null)
377
+	function db2data($data = null)
378 378
 	{
379 379
 		if (!is_array($data))
380 380
 		{
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
 		}
383 383
 		if ($this->timestamps)
384 384
 		{
385
-			foreach($this->timestamps as $name)
385
+			foreach ($this->timestamps as $name)
386 386
 			{
387 387
 				if (isset($data[$name]) && $data[$name])
388 388
 				{
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
 					}
393 393
 					else
394 394
 					{
395
-						$data[$name] = egw_time::server2user($data[$name],$this->timestamp_type);
395
+						$data[$name] = egw_time::server2user($data[$name], $this->timestamp_type);
396 396
 					}
397 397
 				}
398 398
 			}
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
 					throw new egw_exception_wrong_parameter(__METHOD__."(): No table definition for '$this->table' found !!!");
409 409
 				}
410 410
 			}
411
-			foreach($this->table_def['fd'] as $col => $def)
411
+			foreach ($this->table_def['fd'] as $col => $def)
412 412
 			{
413 413
 				if ($def['type'] == 'bool' && isset($data[$col]))
414 414
 				{
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
 	 * @param array $data =null if given works on that array and returns result, else works on internal data-array
441 441
 	 * @return array
442 442
 	 */
443
-	function data2db($data=null)
443
+	function data2db($data = null)
444 444
 	{
445 445
 		if (!is_array($data))
446 446
 		{
@@ -448,11 +448,11 @@  discard block
 block discarded – undo
448 448
 		}
449 449
 		if ($this->timestamps)
450 450
 		{
451
-			foreach($this->timestamps as $name)
451
+			foreach ($this->timestamps as $name)
452 452
 			{
453 453
 				if (isset($data[$name]) && $data[$name])
454 454
 				{
455
-					$data[$name] = egw_time::user2server($data[$name],$this->timestamp_type);
455
+					$data[$name] = egw_time::user2server($data[$name], $this->timestamp_type);
456 456
 				}
457 457
 			}
458 458
 		}
@@ -465,7 +465,7 @@  discard block
 block discarded – undo
465 465
 	 * @param array $keys =array() array with keys in form internalName => value
466 466
 	 * @return array internal data after init
467 467
 	 */
468
-	function init($keys=array())
468
+	function init($keys = array())
469 469
 	{
470 470
 		$this->data = array();
471 471
 
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
 	 * @param string $join ='' sql to do a join, added as is after the table-name, eg. ", table2 WHERE x=y" or
490 490
 	 * @return array|boolean data if row could be retrived else False
491 491
 	 */
492
-	function read($keys,$extra_cols='',$join='')
492
+	function read($keys, $extra_cols = '', $join = '')
493 493
 	{
494 494
 		if (!is_array($keys))
495 495
 		{
@@ -510,16 +510,16 @@  discard block
 block discarded – undo
510 510
 		}
511 511
 		if (!$query)	// no primary key in keys, lets try the data_cols for a unique key
512 512
 		{
513
-			foreach($this->db_uni_cols as $db_col => $col)
513
+			foreach ($this->db_uni_cols as $db_col => $col)
514 514
 			{
515 515
 				if (!is_array($col) && $this->data[$col] != '')
516 516
 				{
517 517
 					$query[$db_col] = $this->data[$col];
518 518
 				}
519
-				elseif(is_array($col))
519
+				elseif (is_array($col))
520 520
 				{
521 521
 					$q = array();
522
-					foreach($col as $db_c => $c)
522
+					foreach ($col as $db_c => $c)
523 523
 					{
524 524
 						if ($this->data[$col] == '')
525 525
 						{
@@ -534,7 +534,7 @@  discard block
 block discarded – undo
534 534
 		}
535 535
 		if (!$query)	// no unique key in keys, lets try everything else
536 536
 		{
537
-			foreach($this->db_data_cols as $db_col => $col)
537
+			foreach ($this->db_data_cols as $db_col => $col)
538 538
 			{
539 539
 				if ($this->data[$col] != '')
540 540
 				{
@@ -550,22 +550,22 @@  discard block
 block discarded – undo
550 550
 		}
551 551
 		if ($join)	// Prefix the columns with the table-name, as they might exist in the join
552 552
 		{
553
-			foreach($query as $col => $val)
553
+			foreach ($query as $col => $val)
554 554
 			{
555
-				if (is_int($col) || strpos($join,$col) === false) continue;
556
-				$query[] = $this->db->expression($this->table_name,$this->table_name.'.',array($col=>$val));
555
+				if (is_int($col) || strpos($join, $col) === false) continue;
556
+				$query[] = $this->db->expression($this->table_name, $this->table_name.'.', array($col=>$val));
557 557
 				unset($query[$col]);
558 558
 			}
559 559
 		}
560
-		foreach($this->db->select($this->table_name,'*'.($extra_cols?','.(is_array($extra_cols)?implode(',',$extra_cols):$extra_cols):''),
561
-			$query,__LINE__,__FILE__,False,'',$this->app,0,$join) as $row)
560
+		foreach ($this->db->select($this->table_name, '*'.($extra_cols ? ','.(is_array($extra_cols) ? implode(',', $extra_cols) : $extra_cols) : ''),
561
+			$query, __LINE__, __FILE__, False, '', $this->app, 0, $join) as $row)
562 562
 		{
563 563
 			$cols = $this->db_cols;
564 564
 			if ($extra_cols)	// extra columns to report
565 565
 			{
566
-				foreach(is_array($extra_cols) ? $extra_cols : array($extra_cols) as $col)
566
+				foreach (is_array($extra_cols) ? $extra_cols : array($extra_cols) as $col)
567 567
 				{
568
-					if (FALSE!==stripos($col,' as ')) $col = preg_replace('/^.* as *([a-z0-9_]+) *$/i','\\1',$col);
568
+					if (FALSE !== stripos($col, ' as ')) $col = preg_replace('/^.* as *([a-z0-9_]+) *$/i', '\\1', $col);
569 569
 					$cols[$col] = $col;
570 570
 				}
571 571
 			}
@@ -578,7 +578,7 @@  discard block
 block discarded – undo
578 578
 			// store user timezone used for reading
579 579
 			$this->data[self::USER_TIMEZONE_READ] = egw_time::$user_timezone->getName();
580 580
 
581
-			if ((int) $this->debug >= 4)
581
+			if ((int)$this->debug >= 4)
582 582
 			{
583 583
 				echo "data =\n"; _debug_array($this->data);
584 584
 			}
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
 		{
589 589
 			unset($this->data[$this->db_key_cols[$this->autoinc_id]]);
590 590
 		}
591
-		if ((int) $this->debug >= 4) echo "nothing found !!!</p>\n";
591
+		if ((int)$this->debug >= 4) echo "nothing found !!!</p>\n";
592 592
 
593 593
 		$this->db2data();
594 594
 
@@ -602,7 +602,7 @@  discard block
 block discarded – undo
602 602
 	 * @param string|array $extra_where =null extra where clause, eg. to check an etag, returns true if no affected rows!
603 603
 	 * @return int|boolean 0 on success, or errno != 0 on error, or true if $extra_where is given and no rows affected
604 604
 	 */
605
-	function save($keys=null,$extra_where=null)
605
+	function save($keys = null, $extra_where = null)
606 606
 	{
607 607
 		if (is_array($keys) && count($keys)) $this->data_merge($keys);
608 608
 
@@ -621,65 +621,65 @@  discard block
 block discarded – undo
621 621
 		}
622 622
 		$this->data2db();
623 623
 
624
-		if ((int) $this->debug >= 4) { echo "so_sql::save(".print_r($keys,true).") autoinc_id='$this->autoinc_id', data="; _debug_array($this->data); }
624
+		if ((int)$this->debug >= 4) { echo "so_sql::save(".print_r($keys, true).") autoinc_id='$this->autoinc_id', data="; _debug_array($this->data); }
625 625
 
626 626
 		if ($this->autoinc_id && !$this->data[$this->db_key_cols[$this->autoinc_id]])	// insert with auto id
627 627
 		{
628
-			foreach($this->db_cols as $db_col => $col)
628
+			foreach ($this->db_cols as $db_col => $col)
629 629
 			{
630 630
 				if (!$this->autoinc_id || $db_col != $this->autoinc_id)	// not write auto-inc-id
631 631
 				{
632
-					if (!array_key_exists($col,$this->data) && 	// handling of unset columns in $this->data
633
-						(isset($this->table_def['fd'][$db_col]['default']) ||	// we have a default value
632
+					if (!array_key_exists($col, $this->data) && // handling of unset columns in $this->data
633
+						(isset($this->table_def['fd'][$db_col]['default']) || // we have a default value
634 634
 						 !isset($this->table_def['fd'][$db_col]['nullable']) || $this->table_def['fd'][$db_col]['nullable']))	// column is nullable
635 635
 					{
636
-						continue;	// no need to write that (unset) column
636
+						continue; // no need to write that (unset) column
637 637
 					}
638 638
 					if ($this->table_def['fd'][$db_col]['type'] == 'varchar' &&
639 639
 						strlen($this->data[$col]) > $this->table_def['fd'][$db_col]['precision'])
640 640
 					{
641 641
 						// truncate the field to mamimum length, if upper layers didn't care
642
-						$data[$db_col] = substr($this->data[$col],0,$this->table_def['fd'][$db_col]['precision']);
642
+						$data[$db_col] = substr($this->data[$col], 0, $this->table_def['fd'][$db_col]['precision']);
643 643
 					}
644 644
 					else
645 645
 					{
646
-						$data[$db_col] = (string) $this->data[$col] === '' && $this->empty_on_write == 'NULL' ? null : $this->data[$col];
646
+						$data[$db_col] = (string)$this->data[$col] === '' && $this->empty_on_write == 'NULL' ? null : $this->data[$col];
647 647
 					}
648 648
 				}
649 649
 			}
650
-			$this->db->insert($this->table_name,$data,false,__LINE__,__FILE__,$this->app);
650
+			$this->db->insert($this->table_name, $data, false, __LINE__, __FILE__, $this->app);
651 651
 
652 652
 			if ($this->autoinc_id)
653 653
 			{
654
-				$this->data[$this->db_key_cols[$this->autoinc_id]] = $this->db->get_last_insert_id($this->table_name,$this->autoinc_id);
654
+				$this->data[$this->db_key_cols[$this->autoinc_id]] = $this->db->get_last_insert_id($this->table_name, $this->autoinc_id);
655 655
 			}
656 656
 		}
657 657
 		else // insert in table without auto id or update of existing row, dont write colums unset in $this->data
658 658
 		{
659
-			foreach($this->db_data_cols as $db_col => $col)
659
+			foreach ($this->db_data_cols as $db_col => $col)
660 660
 			{
661 661
 				// we need to update columns set to null: after a $this->data[$col]=null:
662 662
 				// - array_key_exits($col,$this->data) === true
663 663
 				// - isset($this->data[$col]) === false
664
-				if (!array_key_exists($col,$this->data) &&	// handling of unset columns in $this->data
665
-					($this->autoinc_id ||			// update of table with auto id or
666
-					 isset($this->table_def['fd'][$db_col]['default']) ||	// we have a default value or
664
+				if (!array_key_exists($col, $this->data) && // handling of unset columns in $this->data
665
+					($this->autoinc_id || // update of table with auto id or
666
+					 isset($this->table_def['fd'][$db_col]['default']) || // we have a default value or
667 667
 					 !isset($this->table_def['fd'][$db_col]['nullable']) || $this->table_def['fd'][$db_col]['nullable']))	// column is nullable
668 668
 				{
669
-					continue;	// no need to write that (unset) column
669
+					continue; // no need to write that (unset) column
670 670
 				}
671
-				$data[$db_col] = !is_object($this->data[$col]) && (string) $this->data[$col] === '' && $this->empty_on_write == 'NULL' ? null : $this->data[$col];
671
+				$data[$db_col] = !is_object($this->data[$col]) && (string)$this->data[$col] === '' && $this->empty_on_write == 'NULL' ? null : $this->data[$col];
672 672
 			}
673 673
 			// allow to add direct sql updates, eg. "etag=etag+1" with int keys
674 674
 			if (is_array($keys) && isset($keys[0]))
675 675
 			{
676
-				for($n=0; isset($keys[$n]); ++$n)
676
+				for ($n = 0; isset($keys[$n]); ++$n)
677 677
 				{
678 678
 					$data[] = $keys[$n];
679 679
 				}
680 680
 			}
681 681
 			$keys = $extra_where;
682
-			foreach($this->db_key_cols as $db_col => $col)
682
+			foreach ($this->db_key_cols as $db_col => $col)
683 683
 			{
684 684
 				$keys[$db_col] = $this->data[$col];
685 685
 			}
@@ -690,16 +690,16 @@  discard block
 block discarded – undo
690 690
 			}
691 691
 			if ($this->autoinc_id)
692 692
 			{
693
-				$this->db->update($this->table_name,$data,$keys,__LINE__,__FILE__,$this->app);
693
+				$this->db->update($this->table_name, $data, $keys, __LINE__, __FILE__, $this->app);
694 694
 				if (($nothing_affected = !$this->db->Errno && !$this->db->affected_rows()) && $extra_where)
695 695
 				{
696
-					return true;	// extra_where not met, eg. etag wrong
696
+					return true; // extra_where not met, eg. etag wrong
697 697
 				}
698 698
 			}
699 699
 			// always try an insert if we have no autoinc_id, as we dont know if the data exists
700 700
 			if (!$this->autoinc_id || $nothing_affected)
701 701
 			{
702
-				$this->db->insert($this->table_name,$data,$keys,__LINE__,__FILE__,$this->app);
702
+				$this->db->insert($this->table_name, $data, $keys, __LINE__, __FILE__, $this->app);
703 703
 			}
704 704
 		}
705 705
 		$this->db2data();
@@ -714,7 +714,7 @@  discard block
 block discarded – undo
714 714
 	 * @param boolean $merge =true if true $fields will be merged with $this->data (after update!), otherwise $this->data will be just $fields
715 715
 	 * @return int|boolean 0 on success, or errno != 0 on error, or true if $extra_where is given and no rows affected
716 716
 	 */
717
-	function update($_fields,$merge=true)
717
+	function update($_fields, $merge = true)
718 718
 	{
719 719
 		if ($merge) $this->data_merge($_fields);
720 720
 
@@ -722,23 +722,23 @@  discard block
 block discarded – undo
722 722
 
723 723
 		// extract the keys from $fields or - if not set there - from $this->data
724 724
 		$keys = array();
725
-		foreach($this->db_key_cols as $col => $name)
725
+		foreach ($this->db_key_cols as $col => $name)
726 726
 		{
727 727
 			$keys[$col] = isset($fields[$name]) ? $fields[$name] : $this->data[$name];
728 728
 			unset($fields[$name]);
729 729
 		}
730 730
 		// extract the data from $fields
731 731
 		$data = array();
732
-		foreach($this->db_data_cols as $col => $name)
732
+		foreach ($this->db_data_cols as $col => $name)
733 733
 		{
734
-			if (array_key_exists($name,$fields))
734
+			if (array_key_exists($name, $fields))
735 735
 			{
736 736
 				$data[$col] = $fields[$name];
737 737
 				unset($fields[$name]);
738 738
 			}
739 739
 		}
740 740
 		// add direct sql like 'etag=etag+1' (it has integer keys)
741
-		foreach($fields as $key => $value)
741
+		foreach ($fields as $key => $value)
742 742
 		{
743 743
 			if (is_int($key))
744 744
 			{
@@ -747,9 +747,9 @@  discard block
 block discarded – undo
747 747
 		}
748 748
 		if (!$data)
749 749
 		{
750
-			return 0;	// nothing to update
750
+			return 0; // nothing to update
751 751
 		}
752
-		if (!$this->db->update($this->table_name,$data,$keys,__LINE__,__FILE__,$this->app))
752
+		if (!$this->db->update($this->table_name, $data, $keys, __LINE__, __FILE__, $this->app))
753 753
 		{
754 754
 			return $this->db->Errno;
755 755
 		}
@@ -763,7 +763,7 @@  discard block
 block discarded – undo
763 763
 	 * @param boolean $only_return_query =false return $query of delete call to db object, but not run it (used by so_sql_cf!)
764 764
 	 * @return int|array affected rows, should be 1 if ok, 0 if an error or array with id's if $only_return_ids
765 765
 	 */
766
-	function delete($keys=null,$only_return_query=false)
766
+	function delete($keys = null, $only_return_query = false)
767 767
 	{
768 768
 		if ($this->autoinc_id && $keys && !is_array($keys))
769 769
 		{
@@ -777,7 +777,7 @@  discard block
 block discarded – undo
777 777
 		else	// data and keys are supplied in $keys
778 778
 		{
779 779
 			$data = $keys; $keys = array();
780
-			foreach($this->db_cols as $db_col => $col)
780
+			foreach ($this->db_cols as $db_col => $col)
781 781
 			{
782 782
 				if (isset($data[$col]))
783 783
 				{
@@ -787,13 +787,13 @@  discard block
 block discarded – undo
787 787
 		}
788 788
 		$data = $this->data2db($data);
789 789
 
790
-		foreach($keys as $db_col => $col)
790
+		foreach ($keys as $db_col => $col)
791 791
 		{
792 792
 			$query[$db_col] = $data[$col];
793 793
 		}
794 794
 		if ($only_return_query) return $query;
795 795
 
796
-		$this->db->delete($this->table_name,$query,__LINE__,__FILE__,$this->app);
796
+		$this->db->delete($this->table_name, $query, __LINE__, __FILE__, $this->app);
797 797
 
798 798
 		return $this->db->affected_rows();
799 799
 	}
@@ -821,15 +821,15 @@  discard block
 block discarded – undo
821 821
 	 * @todo return an interator instead of an array
822 822
 	 * @return array|NULL array of matching rows (the row is an array of the cols) or NULL
823 823
 	 */
824
-	function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false)
824
+	function &search($criteria, $only_keys = True, $order_by = '', $extra_cols = '', $wildcard = '', $empty = False, $op = 'AND', $start = false, $filter = null, $join = '', $need_full_no_count = false)
825 825
 	{
826 826
 		//error_log(__METHOD__.'('.array2string(array_combine(array_slice(array('criteria','only_keys','order_by','extra_cols','wildcard','empty','op','start','filter','join','need_full_no_count'), 0, count(func_get_args())), func_get_args())).')');
827
-		if ((int) $this->debug >= 4) echo "<p>so_sql::search(".print_r($criteria,true).",'$only_keys','$order_by',".print_r($extra_cols,true).",'$wildcard','$empty','$op','$start',".print_r($filter,true).",'$join')</p>\n";
827
+		if ((int)$this->debug >= 4) echo "<p>so_sql::search(".print_r($criteria, true).",'$only_keys','$order_by',".print_r($extra_cols, true).",'$wildcard','$empty','$op','$start',".print_r($filter, true).",'$join')</p>\n";
828 828
 
829 829
 		// if extending class or instanciator set columns to search, convert string criteria to array
830 830
 		if ($criteria && !is_array($criteria))
831 831
 		{
832
-			$search = $this->search2criteria($criteria,$wildcard,$op);
832
+			$search = $this->search2criteria($criteria, $wildcard, $op);
833 833
 			$criteria = array($search);
834 834
 		}
835 835
 		if (!is_array($criteria))
@@ -839,7 +839,7 @@  discard block
 block discarded – undo
839 839
 		else
840 840
 		{
841 841
 			$criteria = $this->data2db($criteria);
842
-			foreach($criteria as $col => $val)
842
+			foreach ($criteria as $col => $val)
843 843
 			{
844 844
 				if (is_int($col))
845 845
 				{
@@ -847,7 +847,7 @@  discard block
 block discarded – undo
847 847
 				}
848 848
 				elseif ($empty || $val != '')
849 849
 				{
850
-					if (!($db_col = array_search($col,$this->db_cols)))
850
+					if (!($db_col = array_search($col, $this->db_cols)))
851 851
 					{
852 852
 						$db_col = $col;
853 853
 					}
@@ -858,7 +858,7 @@  discard block
 block discarded – undo
858 858
 							$this->table_def['fd'][$db_col]['nullable'] !== false)
859 859
 						{
860 860
 							unset($criteria[$col]);
861
-							$query[] =  '(' . $db_col . ' IS NULL OR ' . $db_col . " = '')";
861
+							$query[] = '('.$db_col.' IS NULL OR '.$db_col." = '')";
862 862
 						}
863 863
 						else
864 864
 						{
@@ -866,10 +866,10 @@  discard block
 block discarded – undo
866 866
 						}
867 867
 					}
868 868
 					elseif ($wildcard || $criteria[$col][0] == '!' ||
869
-						is_string($criteria[$col]) && (strpos($criteria[$col],'*')!==false || strpos($criteria[$col],'?')!==false))
869
+						is_string($criteria[$col]) && (strpos($criteria[$col], '*') !== false || strpos($criteria[$col], '?') !== false))
870 870
 					{
871 871
 						// if search pattern alread contains a wildcard, do NOT add further ones automatic
872
-						if (is_string($criteria[$col]) && (strpos($criteria[$col],'*')!==false || strpos($criteria[$col],'?')!==false))
872
+						if (is_string($criteria[$col]) && (strpos($criteria[$col], '*') !== false || strpos($criteria[$col], '?') !== false))
873 873
 						{
874 874
 							$wildcard = '';
875 875
 						}
@@ -878,19 +878,19 @@  discard block
 block discarded – undo
878 878
 						if ($criteria[$col][0] == '!')
879 879
 						{
880 880
 							$cmp_op = ' NOT'.$cmp_op;
881
-							$criteria[$col] = substr($criteria[$col],1);
881
+							$criteria[$col] = substr($criteria[$col], 1);
882 882
 							$negate = true;
883 883
 						}
884
-						foreach(explode(' ',$criteria[$col]) as $crit)
884
+						foreach (explode(' ', $criteria[$col]) as $crit)
885 885
 						{
886 886
 							$query[] = ($negate ? ' ('.$db_col.' IS NULL OR ' : '').$db_col.$cmp_op.
887
-								$this->db->quote($wildcard.str_replace(array('%','_','*','?'),array('\\%','\\_','%','_'),$crit).$wildcard).
887
+								$this->db->quote($wildcard.str_replace(array('%', '_', '*', '?'), array('\\%', '\\_', '%', '_'), $crit).$wildcard).
888 888
 								($negate ? ') ' : '');
889 889
 						}
890 890
 					}
891
-					elseif (strpos($db_col,'.') !== false)	// we have a table-name specified
891
+					elseif (strpos($db_col, '.') !== false)	// we have a table-name specified
892 892
 					{
893
-						list($table,$only_col) = explode('.',$db_col);
893
+						list($table, $only_col) = explode('.', $db_col);
894 894
 						$type = $this->db->get_column_attribute($only_col, $table, true, 'type');
895 895
 						if (empty($type))
896 896
 						{
@@ -898,15 +898,15 @@  discard block
 block discarded – undo
898 898
 						}
899 899
 						if (is_array($val) && count($val) > 1)
900 900
 						{
901
-							foreach($val as &$v)
901
+							foreach ($val as &$v)
902 902
 							{
903 903
 								$v = $this->db->quote($v, $type);
904 904
 							}
905
-							$query[] = $sql = $db_col.' IN (' .implode(',',$val).')';
905
+							$query[] = $sql = $db_col.' IN ('.implode(',', $val).')';
906 906
 						}
907 907
 						else
908 908
 						{
909
-							$query[] = $db_col.'='.$this->db->quote(is_array($val)?array_shift($val):$val,$type);
909
+							$query[] = $db_col.'='.$this->db->quote(is_array($val) ? array_shift($val) : $val, $type);
910 910
 						}
911 911
 					}
912 912
 					else
@@ -915,7 +915,7 @@  discard block
 block discarded – undo
915 915
 					}
916 916
 				}
917 917
 			}
918
-			if (is_array($query) && $op != 'AND') $query = $this->db->column_data_implode(' '.$op.' ',$query);
918
+			if (is_array($query) && $op != 'AND') $query = $this->db->column_data_implode(' '.$op.' ', $query);
919 919
 		}
920 920
 		if (is_array($filter))
921 921
 		{
@@ -923,29 +923,29 @@  discard block
 block discarded – undo
923 923
 			$data2db_filter = $this->data2db($filter);
924 924
 			if (!is_array($data2db_filter)) {
925 925
 				echo function_backtrace()."<br/>\n";
926
-				echo "filter=";_debug_array($filter);
927
-				echo "data2db(filter)=";_debug_array($data2db_filter);
926
+				echo "filter="; _debug_array($filter);
927
+				echo "data2db(filter)="; _debug_array($data2db_filter);
928 928
 			}
929
-			foreach($data2db_filter as $col => $val)
929
+			foreach ($data2db_filter as $col => $val)
930 930
 			{
931 931
 				if ($val !== '')
932 932
 				{
933 933
 					// check if a db-internal name conversation necessary
934
-					if (!is_int($col) && ($c = array_search($col,$this->db_cols)))
934
+					if (!is_int($col) && ($c = array_search($col, $this->db_cols)))
935 935
 					{
936 936
 						$col = $c;
937 937
 					}
938
-					if(is_int($col))
938
+					if (is_int($col))
939 939
 					{
940 940
 						$db_filter[] = $val;
941 941
 					}
942 942
 					elseif ($val === "!''")
943 943
 					{
944
-						$db_filter[] = $this->table_name . '.' .$col." != ''";
944
+						$db_filter[] = $this->table_name.'.'.$col." != ''";
945 945
 					}
946 946
 					else
947 947
 					{
948
-						$db_filter[$this->table_name . '.' .$col] = $val;
948
+						$db_filter[$this->table_name.'.'.$col] = $val;
949 949
 					}
950 950
 				}
951 951
 			}
@@ -953,35 +953,35 @@  discard block
 block discarded – undo
953 953
 			{
954 954
 				if ($op != 'AND')
955 955
 				{
956
-					$db_filter[] = '('.$this->db->column_data_implode(' '.$op.' ',$query).')';
956
+					$db_filter[] = '('.$this->db->column_data_implode(' '.$op.' ', $query).')';
957 957
 				}
958 958
 				else
959 959
 				{
960
-					$db_filter = array_merge($db_filter,$query);
960
+					$db_filter = array_merge($db_filter, $query);
961 961
 				}
962 962
 			}
963 963
 			$query = $db_filter;
964 964
 		}
965
-		if ((int) $this->debug >= 4)
965
+		if ((int)$this->debug >= 4)
966 966
 		{
967
-			echo "<p>so_sql::search(,only_keys=$only_keys,order_by='$order_by',wildcard='$wildcard',empty=$empty,$op,start='$start',".print_r($filter,true).") query=".print_r($query,true).", total='$this->total'</p>\n";
967
+			echo "<p>so_sql::search(,only_keys=$only_keys,order_by='$order_by',wildcard='$wildcard',empty=$empty,$op,start='$start',".print_r($filter, true).") query=".print_r($query, true).", total='$this->total'</p>\n";
968 968
 			echo "<br>criteria = "; _debug_array($criteria);
969 969
 		}
970 970
 		if ($only_keys === true)
971 971
 		{
972 972
 			$colums = array_keys($this->db_key_cols);
973
-			foreach($colums as &$column)
973
+			foreach ($colums as &$column)
974 974
 			{
975
-				$column = $this->table_name . '.' . $column;
975
+				$column = $this->table_name.'.'.$column;
976 976
 			}
977 977
 		}
978 978
 		elseif (is_array($only_keys))
979 979
 		{
980 980
 			$colums = array();
981
-			foreach($only_keys as $key => $col)
981
+			foreach ($only_keys as $key => $col)
982 982
 			{
983 983
 				//Convert ambiguous columns to prefixed tablename.column name
984
-				$colums[] = ($db_col = array_search($col,$this->db_cols)) ?  $this->table_name .'.'.$db_col.' AS '.$col :$col;
984
+				$colums[] = ($db_col = array_search($col, $this->db_cols)) ? $this->table_name.'.'.$db_col.' AS '.$col : $col;
985 985
 			}
986 986
 		}
987 987
 		elseif (!$only_keys)
@@ -1011,20 +1011,20 @@  discard block
 block discarded – undo
1011 1011
 			{
1012 1012
 				$colums[$key] = $this->table_name.'.'.$this->autoinc_id.' AS '.$this->autoinc_id;
1013 1013
 			}
1014
-			elseif (!is_array($colums) && strpos($colums,$this->autoinc_id) !== false)
1014
+			elseif (!is_array($colums) && strpos($colums, $this->autoinc_id) !== false)
1015 1015
 			{
1016
-				$colums = preg_replace('/(?<! AS)([ ,]+)'.preg_quote($this->autoinc_id).'([ ,]+)/','\\1'.$this->table_name.'.'.$this->autoinc_id.' AS '.$this->autoinc_id.'\\2',$colums);
1016
+				$colums = preg_replace('/(?<! AS)([ ,]+)'.preg_quote($this->autoinc_id).'([ ,]+)/', '\\1'.$this->table_name.'.'.$this->autoinc_id.' AS '.$this->autoinc_id.'\\2', $colums);
1017 1017
 			}
1018 1018
 		}
1019
-		$num_rows = 0;	// as spec. in max_matches in the user-prefs
1020
-		if (is_array($start)) list($start,$num_rows) = $start;
1019
+		$num_rows = 0; // as spec. in max_matches in the user-prefs
1020
+		if (is_array($start)) list($start, $num_rows) = $start;
1021 1021
 
1022 1022
 		// fix GROUP BY clause to contain all non-aggregate selected columns
1023
-		if ($order_by && stripos($order_by,'GROUP BY') !== false)
1023
+		if ($order_by && stripos($order_by, 'GROUP BY') !== false)
1024 1024
 		{
1025 1025
 			$order_by = $this->fix_group_by_columns($order_by, $colums, $this->table_name, $this->autoinc_id);
1026 1026
 		}
1027
-		elseif ($order_by && stripos($order_by,'ORDER BY')===false && stripos($order_by,'GROUP BY')===false && stripos($order_by,'HAVING')===false)
1027
+		elseif ($order_by && stripos($order_by, 'ORDER BY') === false && stripos($order_by, 'GROUP BY') === false && stripos($order_by, 'HAVING') === false)
1028 1028
 		{
1029 1029
 			$order_by = 'ORDER BY '.$order_by;
1030 1030
 		}
@@ -1047,9 +1047,9 @@  discard block
 block discarded – undo
1047 1047
 				);
1048 1048
 				if (!$union_cols)	// union used the colum-names of the first query
1049 1049
 				{
1050
-					$union_cols = $this->_get_columns($only_keys,$extra_cols);
1050
+					$union_cols = $this->_get_columns($only_keys, $extra_cols);
1051 1051
 				}
1052
-				return true;	// waiting for further calls, before running the union-query
1052
+				return true; // waiting for further calls, before running the union-query
1053 1053
 			}
1054 1054
 			// running the union query now
1055 1055
 			if ($start !== false)	// need to get the total too, saved in $this->total
@@ -1060,10 +1060,10 @@  discard block
 block discarded – undo
1060 1060
 				}
1061 1061
 				else	// cant do a count, have to run the query without limit
1062 1062
 				{
1063
-					$this->total = $this->db->union($union,__LINE__,__FILE__)->NumRows();
1063
+					$this->total = $this->db->union($union, __LINE__, __FILE__)->NumRows();
1064 1064
 				}
1065 1065
 			}
1066
-			$rs = $this->db->union($union,__LINE__,__FILE__,$order_by,$start,$num_rows);
1066
+			$rs = $this->db->union($union, __LINE__, __FILE__, $order_by, $start, $num_rows);
1067 1067
 			if ($this->debug) error_log(__METHOD__."() ".$this->db->Query_ID->sql);
1068 1068
 
1069 1069
 			$cols = $union_cols;
@@ -1077,21 +1077,21 @@  discard block
 block discarded – undo
1077 1077
 				{
1078 1078
 					$mysql_calc_rows = 'SQL_CALC_FOUND_ROWS ';
1079 1079
 				}
1080
-				elseif (!$need_full_no_count && (!$join || stripos($join,'LEFT JOIN')!==false))
1080
+				elseif (!$need_full_no_count && (!$join || stripos($join, 'LEFT JOIN') !== false))
1081 1081
 				{
1082
-					$this->total = $this->db->select($this->table_name,'COUNT(*)',$query,__LINE__,__FILE__,false,'',$this->app,0,$join)->fetchColumn();
1082
+					$this->total = $this->db->select($this->table_name, 'COUNT(*)', $query, __LINE__, __FILE__, false, '', $this->app, 0, $join)->fetchColumn();
1083 1083
 				}
1084 1084
 				else	// cant do a count, have to run the query without limit
1085 1085
 				{
1086
-					$this->total = $this->db->select($this->table_name,$colums,$query,__LINE__,__FILE__,false,$order_by,false,0,$join)->NumRows();
1086
+					$this->total = $this->db->select($this->table_name, $colums, $query, __LINE__, __FILE__, false, $order_by, false, 0, $join)->NumRows();
1087 1087
 				}
1088 1088
 			}
1089
-			$rs = $this->db->select($this->table_name,$mysql_calc_rows.$colums,$query,__LINE__,__FILE__,
1090
-				$start,$order_by,$this->app,$num_rows,$join);
1089
+			$rs = $this->db->select($this->table_name, $mysql_calc_rows.$colums, $query, __LINE__, __FILE__,
1090
+				$start, $order_by, $this->app, $num_rows, $join);
1091 1091
 			if ($this->debug) error_log(__METHOD__."() ".$this->db->Query_ID->sql);
1092
-			$cols = $this->_get_columns($only_keys,$extra_cols);
1092
+			$cols = $this->_get_columns($only_keys, $extra_cols);
1093 1093
 		}
1094
-		if ((int) $this->debug >= 4) echo "<p>sql='{$this->db->Query_ID->sql}'</p>\n";
1094
+		if ((int)$this->debug >= 4) echo "<p>sql='{$this->db->Query_ID->sql}'</p>\n";
1095 1095
 
1096 1096
 		if ($mysql_calc_rows)
1097 1097
 		{
@@ -1100,14 +1100,14 @@  discard block
 block discarded – undo
1100 1100
 		// ToDo: Implement that as an iterator, as $rs is also an interator and we could return one instead of an array
1101 1101
 		if ($this->search_return_iterator)
1102 1102
 		{
1103
-			return new so_sql_db2data_iterator($this,$rs);
1103
+			return new so_sql_db2data_iterator($this, $rs);
1104 1104
 		}
1105 1105
 		$arr = array();
1106 1106
 		$n = 0;
1107
-		if ($rs) foreach($rs as $row)
1107
+		if ($rs) foreach ($rs as $row)
1108 1108
 		{
1109 1109
 			$data = array();
1110
-			foreach($cols as $db_col => $col)
1110
+			foreach ($cols as $db_col => $col)
1111 1111
 			{
1112 1112
 				$data[$col] = (isset($row[$db_col]) ? $row[$db_col] : $row[$col]);
1113 1113
 			}
@@ -1138,7 +1138,7 @@  discard block
 block discarded – undo
1138 1138
 		//error_log(__METHOD__."('$group_by', ..., '$table_name', '$autoinc_id') db->Type=".array2string($GLOBALS['egw']->db->Type));
1139 1139
 		if (substr($GLOBALS['egw']->db->Type, 0, 5) == 'mysql' || !preg_match('/(GROUP BY .*)(HAVING.*|ORDER BY.*)?$/iU', $group_by, $matches))
1140 1140
 		{
1141
-			return $group_by;	// nothing to do
1141
+			return $group_by; // nothing to do
1142 1142
 		}
1143 1143
 		$changes = 0;
1144 1144
 		$group_by_cols = preg_split('/, */', trim(substr($matches[1], 9)));
@@ -1148,9 +1148,9 @@  discard block
 block discarded – undo
1148 1148
 			$columns = preg_split('/, */', $columns);
1149 1149
 
1150 1150
 			// fix columns containing commas as part of function calls
1151
-			for($n = 0; $n < count($columns); ++$n)
1151
+			for ($n = 0; $n < count($columns); ++$n)
1152 1152
 			{
1153
-				$col =& $columns[$n];
1153
+				$col = & $columns[$n];
1154 1154
 				while (substr_count($col, '(') > substr_count($col, ')') && ++$n < count($columns))
1155 1155
 				{
1156 1156
 					$col .= ','.$columns[$n];
@@ -1159,7 +1159,7 @@  discard block
 block discarded – undo
1159 1159
 			}
1160 1160
 			unset($col);
1161 1161
 		}
1162
-		foreach($columns as $n => $col)
1162
+		foreach ($columns as $n => $col)
1163 1163
 		{
1164 1164
 			if ($col == '*')
1165 1165
 			{
@@ -1172,7 +1172,7 @@  discard block
 block discarded – undo
1172 1172
 			{
1173 1173
 				if (($pos = stripos($col, 'DISTINCT ')) !== false)
1174 1174
 				{
1175
-					$col = substr($col, $pos+9);
1175
+					$col = substr($col, $pos + 9);
1176 1176
 				}
1177 1177
 				$alias = $col;
1178 1178
 				if (stripos($col, ' AS ')) list($col, $alias) = preg_split('/ +AS +/i', $col);
@@ -1190,7 +1190,7 @@  discard block
 block discarded – undo
1190 1190
 		$ret = $group_by;
1191 1191
 		if ($changes)
1192 1192
 		{
1193
-			$ret = str_replace($matches[1], 'GROUP BY '.implode(',', $group_by_cols).' ',  $group_by);
1193
+			$ret = str_replace($matches[1], 'GROUP BY '.implode(',', $group_by_cols).' ', $group_by);
1194 1194
 			//error_log(__METHOD__."('$group_by', ".array2string($columns).") group_by_cols=".array2string($group_by_cols)." changed to $ret");
1195 1195
 		}
1196 1196
 		return $ret;
@@ -1206,12 +1206,12 @@  discard block
 block discarded – undo
1206 1206
 	 * @param array $search_cols =array() List of columns to search.  If not provided, all columns in $this->db_cols will be considered
1207 1207
 	 * @return array or column => value pairs
1208 1208
 	 */
1209
-	public function search2criteria($_pattern,&$wildcard='',&$op='AND',$extra_col=null, $search_cols = array())
1209
+	public function search2criteria($_pattern, &$wildcard = '', &$op = 'AND', $extra_col = null, $search_cols = array())
1210 1210
 	{
1211 1211
 		$pattern = trim($_pattern);
1212 1212
 		// This function can get called multiple times.  Make sure it doesn't re-process.
1213 1213
 		if (empty($pattern) || is_array($pattern)) return $pattern;
1214
-		if(strpos($pattern, 'CAST(COALESCE(') !== false)
1214
+		if (strpos($pattern, 'CAST(COALESCE(') !== false)
1215 1215
 		{
1216 1216
 			return $pattern;
1217 1217
 		}
@@ -1227,20 +1227,20 @@  discard block
 block discarded – undo
1227 1227
 		$numeric_types = array('auto', 'int', 'float', 'double', 'decimal');
1228 1228
 		$numeric_columns = array();
1229 1229
 
1230
-		if(!$search_cols)
1230
+		if (!$search_cols)
1231 1231
 		{
1232 1232
 			$search_cols = $this->get_default_search_columns();
1233 1233
 		}
1234 1234
 		// Concat all fields to be searched together, so the conditions operate across the whole record
1235
-		foreach($search_cols as $col)
1235
+		foreach ($search_cols as $col)
1236 1236
 		{
1237 1237
 			$col_name = $col;
1238 1238
 			$table = $this->table_name;
1239
-			if (strpos($col,'.') !== false)
1239
+			if (strpos($col, '.') !== false)
1240 1240
 			{
1241
-				list($table,$col_name) = explode('.',$col);
1241
+				list($table, $col_name) = explode('.', $col);
1242 1242
 			}
1243
-			$table_def = $table == $this->table_name ? $this->table_def : $this->db->get_table_definitions(true,$table);
1243
+			$table_def = $table == $this->table_name ? $this->table_def : $this->db->get_table_definitions(true, $table);
1244 1244
 			if ($table_def['fd'][$col_name] && in_array($table_def['fd'][$col_name]['type'], $numeric_types))
1245 1245
 			{
1246 1246
 				$numeric_columns[] = $col;
@@ -1248,11 +1248,11 @@  discard block
 block discarded – undo
1248 1248
 			}
1249 1249
 			if ($this->db->Type == 'mysql' && $table_def['fd'][$col_name]['type'] === 'ascii' && preg_match('/[\x80-\xFF]/', $_pattern))
1250 1250
 			{
1251
-				continue;	// will only give sql error
1251
+				continue; // will only give sql error
1252 1252
 			}
1253
-			$columns[] = sprintf($this->db->capabilities[egw_db::CAPABILITY_CAST_AS_VARCHAR],"COALESCE($col,'')");
1253
+			$columns[] = sprintf($this->db->capabilities[egw_db::CAPABILITY_CAST_AS_VARCHAR], "COALESCE($col,'')");
1254 1254
 		}
1255
-		if(!$columns)
1255
+		if (!$columns)
1256 1256
 		{
1257 1257
 			return array();
1258 1258
 		}
@@ -1261,9 +1261,9 @@  discard block
 block discarded – undo
1261 1261
 		$break = ' ';
1262 1262
 		$token = strtok($pattern, $break);
1263 1263
 
1264
-		while($token)
1264
+		while ($token)
1265 1265
 		{
1266
-			if($token == strtoupper(lang('AND')) || $token == 'AND')
1266
+			if ($token == strtoupper(lang('AND')) || $token == 'AND')
1267 1267
 			{
1268 1268
 				$token = '+'.strtok($break);
1269 1269
 			}
@@ -1276,10 +1276,10 @@  discard block
 block discarded – undo
1276 1276
 			{
1277 1277
 				$token = '-'.strtok($break);
1278 1278
 			}
1279
-			if ($token[0]=='"')
1279
+			if ($token[0] == '"')
1280 1280
 			{
1281
-				$token = substr($token, 1,strlen($token));
1282
- 				if(substr($token, -1) != '"')
1281
+				$token = substr($token, 1, strlen($token));
1282
+ 				if (substr($token, -1) != '"')
1283 1283
 				{
1284 1284
 					$token .= ' '.strtok('"');
1285 1285
 				}
@@ -1290,16 +1290,16 @@  discard block
 block discarded – undo
1290 1290
 			}
1291 1291
 
1292 1292
 			// prepend and append extra wildcard %, if pattern does NOT already contain wildcards
1293
-			if (strpos($token,'*') === false && strpos($token,'?') === false)
1293
+			if (strpos($token, '*') === false && strpos($token, '?') === false)
1294 1294
 			{
1295
-				$wildcard = '%';	// if pattern contains no wildcards, add them before AND after the pattern
1295
+				$wildcard = '%'; // if pattern contains no wildcards, add them before AND after the pattern
1296 1296
 			}
1297 1297
 			else
1298 1298
 			{
1299
-				$wildcard = '';		// no extra wildcard, if pattern already contains some
1299
+				$wildcard = ''; // no extra wildcard, if pattern already contains some
1300 1300
 			}
1301 1301
 
1302
-			switch($token[0])
1302
+			switch ($token[0])
1303 1303
 			{
1304 1304
 				case '+':
1305 1305
 					$op = 'AND';
@@ -1314,32 +1314,32 @@  discard block
 block discarded – undo
1314 1314
 					$op = 'OR';
1315 1315
 					break;
1316 1316
 			}
1317
-			$token_filter = ' '.call_user_func_array(array($GLOBALS['egw']->db,'concat'),$columns).' '.
1318
-				$this->db->capabilities['case_insensitive_like'] . ' ' .
1319
-				$GLOBALS['egw']->db->quote($wildcard.str_replace(array('%','_','*','?'),array('\\%','\\_','%','_'),$token).$wildcard);
1317
+			$token_filter = ' '.call_user_func_array(array($GLOBALS['egw']->db, 'concat'), $columns).' '.
1318
+				$this->db->capabilities['case_insensitive_like'].' '.
1319
+				$GLOBALS['egw']->db->quote($wildcard.str_replace(array('%', '_', '*', '?'), array('\\%', '\\_', '%', '_'), $token).$wildcard);
1320 1320
 
1321 1321
 			// Compare numeric token as equality for numeric columns
1322 1322
 			// skip user-wildcards (*,?) in is_numeric test, but not SQL wildcards, which get escaped and give sql-error
1323
-			if (is_numeric(str_replace(array('*','?'), '', $token)))
1323
+			if (is_numeric(str_replace(array('*', '?'), '', $token)))
1324 1324
 			{
1325 1325
 				$numeric_filter = array();
1326
-				foreach($numeric_columns as $col)
1326
+				foreach ($numeric_columns as $col)
1327 1327
 				{
1328
-					if($wildcard == '')
1328
+					if ($wildcard == '')
1329 1329
 					{
1330 1330
 						// Token has a wildcard from user, use LIKE
1331
-						$numeric_filter[] = "($col IS NOT NULL AND CAST($col AS CHAR) " .
1332
-							$this->db->capabilities['case_insensitive_like'] . ' ' .
1333
-							$GLOBALS['egw']->db->quote(str_replace(array('*','?'), array('%','_'), $token)) . ')';
1331
+						$numeric_filter[] = "($col IS NOT NULL AND CAST($col AS CHAR) ".
1332
+							$this->db->capabilities['case_insensitive_like'].' '.
1333
+							$GLOBALS['egw']->db->quote(str_replace(array('*', '?'), array('%', '_'), $token)).')';
1334 1334
 					}
1335 1335
 					else
1336 1336
 					{
1337 1337
 						$numeric_filter[] = "($col IS NOT NULL AND $col = $token)";
1338 1338
 					}
1339 1339
 				}
1340
-				if(count($numeric_filter) > 0)
1340
+				if (count($numeric_filter) > 0)
1341 1341
 				{
1342
-					$token_filter = '(' . $token_filter . ' OR ' . implode(' OR ', $numeric_filter) . ')';
1342
+					$token_filter = '('.$token_filter.' OR '.implode(' OR ', $numeric_filter).')';
1343 1343
 				}
1344 1344
 			}
1345 1345
 			$criteria[$op][] = $token_filter;
@@ -1347,32 +1347,32 @@  discard block
 block discarded – undo
1347 1347
 			$token = strtok($break);
1348 1348
 		}
1349 1349
 
1350
-		if($criteria['NOT'])
1350
+		if ($criteria['NOT'])
1351 1351
 		{
1352
-			$filter[] = 'NOT (' . implode(' OR ', $criteria['NOT']) . ') ';
1352
+			$filter[] = 'NOT ('.implode(' OR ', $criteria['NOT']).') ';
1353 1353
 		}
1354
-		if($criteria['AND'])
1354
+		if ($criteria['AND'])
1355 1355
 		{
1356
-			$filter[] = implode(' AND ', $criteria['AND']) . ' ';
1356
+			$filter[] = implode(' AND ', $criteria['AND']).' ';
1357 1357
 		}
1358
-		if($criteria['OR'])
1358
+		if ($criteria['OR'])
1359 1359
 		{
1360
-			$filter[] = '(' . implode(' OR ', $criteria['OR']) . ') ';
1360
+			$filter[] = '('.implode(' OR ', $criteria['OR']).') ';
1361 1361
 		}
1362 1362
 
1363
-		if(count($filter))
1363
+		if (count($filter))
1364 1364
 		{
1365
-			$result = '(' . implode(' AND ', $filter) . ')';
1365
+			$result = '('.implode(' AND ', $filter).')';
1366 1366
 		}
1367 1367
 
1368 1368
 		// OR extra column on the end so a null or blank won't block a hit in the main columns
1369 1369
 		if ($extra_col)
1370 1370
 		{
1371
-			$result .= (strlen($result) ? ' OR ' : ' ') . "$extra_col = " . $GLOBALS['egw']->db->quote($pattern);
1371
+			$result .= (strlen($result) ? ' OR ' : ' ')."$extra_col = ".$GLOBALS['egw']->db->quote($pattern);
1372 1372
 		}
1373 1373
 
1374 1374
 		$op = 'OR';
1375
-		return array('(' . $result . ')');
1375
+		return array('('.$result.')');
1376 1376
 	}
1377 1377
 
1378 1378
 	/**
@@ -1391,21 +1391,21 @@  discard block
 block discarded – undo
1391 1391
 		$numeric_types = array('auto', 'int', 'float', 'double');
1392 1392
 
1393 1393
 		// Skip some numeric columns that don't make sense to search if we have to default to all columns
1394
-		if(is_null($this->columns_to_search))
1394
+		if (is_null($this->columns_to_search))
1395 1395
 		{
1396
-			foreach($search_cols as $key => &$col)
1396
+			foreach ($search_cols as $key => &$col)
1397 1397
 			{
1398 1398
 				// If the name as given isn't a real column name, and adding the prefix doesn't help, skip it
1399
-				if(!$this->table_def['fd'][$col] && !($col = $this->prefix.array_search($col, $search_cols))) {
1399
+				if (!$this->table_def['fd'][$col] && !($col = $this->prefix.array_search($col, $search_cols))) {
1400 1400
 					// Can't search this column
1401 1401
 					unset($search_cols[$key]);
1402 1402
 					continue;
1403 1403
 				}
1404
-				if(in_array($this->table_def['fd'][$col]['type'], $numeric_types))
1404
+				if (in_array($this->table_def['fd'][$col]['type'], $numeric_types))
1405 1405
 				{
1406
-					foreach($skip_columns_with as $bad)
1406
+					foreach ($skip_columns_with as $bad)
1407 1407
 					{
1408
-						if(strpos($col, $bad) !== false)
1408
+						if (strpos($col, $bad) !== false)
1409 1409
 						{
1410 1410
 							unset($search_cols[$key]);
1411 1411
 							continue 2;
@@ -1427,7 +1427,7 @@  discard block
 block discarded – undo
1427 1427
 	 * @param string|array $extra_cols ='' string or array of strings to be added to the SELECT, eg. "count(*) as num"
1428 1428
 	 * @return array with columns as db-name => internal-name pairs
1429 1429
 	 */
1430
-	function _get_columns($only_keys,$extra_cols)
1430
+	function _get_columns($only_keys, $extra_cols)
1431 1431
 	{
1432 1432
 		//echo "_get_columns() only_keys="; _debug_array($only_keys); echo "extra_cols="; _debug_array($extra_cols);
1433 1433
 		if ($only_keys === true)	// only primary key
@@ -1438,7 +1438,7 @@  discard block
 block discarded – undo
1438 1438
 		{
1439 1439
 			$cols = array();
1440 1440
 			$distinct_checked = false;
1441
-			foreach(is_array($only_keys) ? $only_keys : explode(',', $only_keys) as $col)
1441
+			foreach (is_array($only_keys) ? $only_keys : explode(',', $only_keys) as $col)
1442 1442
 			{
1443 1443
 				if (!$distinct_checked)
1444 1444
 				{
@@ -1447,17 +1447,17 @@  discard block
 block discarded – undo
1447 1447
 				}
1448 1448
 				if (!$col || $col == '*' || $col == $this->table_name.'.*')	// all columns
1449 1449
 				{
1450
-					$cols = array_merge($cols,$this->db_cols);
1450
+					$cols = array_merge($cols, $this->db_cols);
1451 1451
 				}
1452 1452
 				else	// only the specified columns
1453 1453
 				{
1454
-					if (stripos($col,'as'))	// if there's already an explicit naming of the column, just use it
1454
+					if (stripos($col, 'as'))	// if there's already an explicit naming of the column, just use it
1455 1455
 					{
1456
-						$col = preg_replace('/^.*as +([a-z0-9_]+) *$/i','\\1',$col);
1456
+						$col = preg_replace('/^.*as +([a-z0-9_]+) *$/i', '\\1', $col);
1457 1457
 						$cols[$col] = $col;
1458 1458
 						continue;
1459 1459
 					}
1460
-					if (($db_col = array_search($col,$this->db_cols)) !== false)
1460
+					if (($db_col = array_search($col, $this->db_cols)) !== false)
1461 1461
 					{
1462 1462
 						$cols[$db_col] = $col;
1463 1463
 					}
@@ -1470,10 +1470,10 @@  discard block
 block discarded – undo
1470 1470
 		}
1471 1471
 		if ($extra_cols)	// extra columns to report
1472 1472
 		{
1473
-			foreach(is_array($extra_cols) ? $extra_cols : explode(',',$extra_cols) as $col)
1473
+			foreach (is_array($extra_cols) ? $extra_cols : explode(',', $extra_cols) as $col)
1474 1474
 			{
1475
-				if (stripos($col,'as ')!==false) $col = preg_replace('/^.*as +([a-z0-9_]+) *$/i','\\1',$col);
1476
-				if (($db_col = array_search($col,$this->db_cols)) !== false)
1475
+				if (stripos($col, 'as ') !== false) $col = preg_replace('/^.*as +([a-z0-9_]+) *$/i', '\\1', $col);
1476
+				if (($db_col = array_search($col, $this->db_cols)) !== false)
1477 1477
 				{
1478 1478
 					$cols[$db_col] = $col;
1479 1479
 				}
@@ -1500,12 +1500,12 @@  discard block
 block discarded – undo
1500 1500
 	 * @param string|array $extra_cols =array()
1501 1501
 	 * @return int total number of rows
1502 1502
 	 */
1503
-	function get_rows($query,&$rows,&$readonlys,$join='',$need_full_no_count=false,$only_keys=false,$extra_cols=array())
1503
+	function get_rows($query, &$rows, &$readonlys, $join = '', $need_full_no_count = false, $only_keys = false, $extra_cols = array())
1504 1504
 	{
1505
-		unset($readonlys);	// required by function signature, but not used in this default implementation
1506
-		if ((int) $this->debug >= 4)
1505
+		unset($readonlys); // required by function signature, but not used in this default implementation
1506
+		if ((int)$this->debug >= 4)
1507 1507
 		{
1508
-			echo "<p>so_sql::get_rows(".print_r($query,true).",,)</p>\n";
1508
+			echo "<p>so_sql::get_rows(".print_r($query, true).",,)</p>\n";
1509 1509
 		}
1510 1510
 		$criteria = array();
1511 1511
 		$op = 'AND';
@@ -1513,11 +1513,11 @@  discard block
 block discarded – undo
1513 1513
 		{
1514 1514
 			$criteria = $query['search'];
1515 1515
 		}
1516
-		$rows = $this->search($criteria,$only_keys,$query['order']?$query['order'].' '.$query['sort']:'',$extra_cols,
1517
-			'',false,$op,$query['num_rows']?array((int)$query['start'],$query['num_rows']):(int)$query['start'],
1518
-			$query['col_filter'],$join,$need_full_no_count);
1516
+		$rows = $this->search($criteria, $only_keys, $query['order'] ? $query['order'].' '.$query['sort'] : '', $extra_cols,
1517
+			'', false, $op, $query['num_rows'] ? array((int)$query['start'], $query['num_rows']) : (int)$query['start'],
1518
+			$query['col_filter'], $join, $need_full_no_count);
1519 1519
 
1520
-		if (!$rows) $rows = array();	// otherwise false returned from search would be returned as array(false)
1520
+		if (!$rows) $rows = array(); // otherwise false returned from search would be returned as array(false)
1521 1521
 
1522 1522
 		return $this->total;
1523 1523
 	}
@@ -1528,7 +1528,7 @@  discard block
 block discarded – undo
1528 1528
 	 * @param array $data =null data-set to check, defaults to $this->data
1529 1529
 	 * @return int 0: all keys are unique, 1: first key not unique, 2: ...
1530 1530
 	 */
1531
-	function not_unique($data=null)
1531
+	function not_unique($data = null)
1532 1532
 	{
1533 1533
 		if (!is_array($data))
1534 1534
 		{
@@ -1541,12 +1541,12 @@  discard block
 block discarded – undo
1541 1541
 		{
1542 1542
 			$uni_keys[] = $this->db_key_cols;
1543 1543
 		}
1544
-		foreach($uni_keys as $db_col => $col)
1544
+		foreach ($uni_keys as $db_col => $col)
1545 1545
 		{
1546 1546
 			if (is_array($col))
1547 1547
 			{
1548 1548
 				$query = array();
1549
-				foreach($col as $db_c => $c)
1549
+				foreach ($col as $db_c => $c)
1550 1550
 				{
1551 1551
 					$query[$db_c] = $data[$c];
1552 1552
 				}
@@ -1555,17 +1555,17 @@  discard block
 block discarded – undo
1555 1555
 			{
1556 1556
 				$query = array($db_col => $data[$col]);
1557 1557
 			}
1558
-			foreach($this->db->select($this->table_name,$this->db_key_cols,$query,__LINE__,__FILE__,false,'',$this->app) as $other)
1558
+			foreach ($this->db->select($this->table_name, $this->db_key_cols, $query, __LINE__, __FILE__, false, '', $this->app) as $other)
1559 1559
 			{
1560
-				foreach($this->db_key_cols as $key_col)
1560
+				foreach ($this->db_key_cols as $key_col)
1561 1561
 				{
1562 1562
 					if ($data[$key_col] != $other[$key_col])
1563 1563
 					{
1564
-						if ((int) $this->debug >= 4)
1564
+						if ((int)$this->debug >= 4)
1565 1565
 						{
1566 1566
 							echo "<p>not_unique in ".array2string($col)." as for '$key_col': '${data[$key_col]}' != '${other[$key_col]}'</p>\n";
1567 1567
 						}
1568
-						return $n;	// different entry => $n not unique
1568
+						return $n; // different entry => $n not unique
1569 1569
 					}
1570 1570
 				}
1571 1571
 			}
@@ -1586,7 +1586,7 @@  discard block
 block discarded – undo
1586 1586
 	 * @param string $order ='' order, default '' = same as (first) $value_col
1587 1587
 	 * @return array with key_col => value_col pairs or array if more then one value_col given (keys as in value_col)
1588 1588
 	 */
1589
-	function query_list($value_col,$key_col='',$filter=array(),$order='')
1589
+	function query_list($value_col, $key_col = '', $filter = array(), $order = '')
1590 1590
 	{
1591 1591
 		static $cache = array();
1592 1592
 
@@ -1599,16 +1599,16 @@  discard block
 block discarded – undo
1599 1599
 		if (!is_array($value_col)) $value_col = array($value_col);
1600 1600
 
1601 1601
 		$cols = $ret = array();
1602
-		foreach($value_col as $key => $col)
1602
+		foreach ($value_col as $key => $col)
1603 1603
 		{
1604 1604
 			$matches = null;
1605
-			$cols[$key] = preg_match('/AS ([a-z_0-9]+)$/i',$col,$matches) ? $matches[1] : $col;
1605
+			$cols[$key] = preg_match('/AS ([a-z_0-9]+)$/i', $col, $matches) ? $matches[1] : $col;
1606 1606
 		}
1607 1607
 		if (!$order) $order = current($cols);
1608 1608
 
1609
-		if (($search =& $this->search(array(),($key_col ? $key_col.',' : 'DISTINCT ').implode(',',$value_col),$order,'','',false,'AND',false,$filter)))
1609
+		if (($search = & $this->search(array(), ($key_col ? $key_col.',' : 'DISTINCT ').implode(',', $value_col), $order, '', '', false, 'AND', false, $filter)))
1610 1610
 		{
1611
-			if (preg_match('/AS ([a-z_0-9]+)$/i',$key_col,$matches))
1611
+			if (preg_match('/AS ([a-z_0-9]+)$/i', $key_col, $matches))
1612 1612
 			{
1613 1613
 				$key_col = $matches[1];
1614 1614
 			}
@@ -1616,12 +1616,12 @@  discard block
 block discarded – undo
1616 1616
 			{
1617 1617
 				$key_col = current($cols);
1618 1618
 			}
1619
-			foreach($search as $row)
1619
+			foreach ($search as $row)
1620 1620
 			{
1621 1621
 				if (count($cols) > 1)
1622 1622
 				{
1623 1623
 					$data = array();
1624
-					foreach($cols as $key => $col)
1624
+					foreach ($cols as $key => $col)
1625 1625
 					{
1626 1626
 						$data[$key] = $row[$col];
1627 1627
 					}
@@ -1633,7 +1633,7 @@  discard block
 block discarded – undo
1633 1633
 				if ($data) $ret[$row[$key_col]] = $data;
1634 1634
 			}
1635 1635
 		}
1636
-		return $cache[$cache_key] =& $ret;
1636
+		return $cache[$cache_key] = & $ret;
1637 1637
 	}
1638 1638
 
1639 1639
 	/**
@@ -1642,13 +1642,13 @@  discard block
 block discarded – undo
1642 1642
 	 * @param string $column =null name of column or null for all (default)
1643 1643
 	 * @return array|string array with internal-name => comment pairs, or string with comment, if $column given
1644 1644
 	 */
1645
-	public function get_comments($column=null)
1645
+	public function get_comments($column = null)
1646 1646
 	{
1647
-		static $comments=null;
1647
+		static $comments = null;
1648 1648
 
1649 1649
 		if (is_null($comments))
1650 1650
 		{
1651
-			foreach($this->db_cols as $db_col => $col)
1651
+			foreach ($this->db_cols as $db_col => $col)
1652 1652
 			{
1653 1653
 				$comments[$col] = $this->table_def['fd'][$db_col]['comment'];
1654 1654
 			}
@@ -1690,13 +1690,13 @@  discard block
 block discarded – undo
1690 1690
 	 * @param so_sql $so_sql
1691 1691
 	 * @param Traversable $rs
1692 1692
 	 */
1693
-	public function __construct(so_sql $so_sql,Traversable $rs=null)
1693
+	public function __construct(so_sql $so_sql, Traversable $rs = null)
1694 1694
 	{
1695 1695
 		$this->so_sql = $so_sql;
1696 1696
 
1697 1697
 		$this->total = $so_sql->total;
1698 1698
 
1699
-		if (is_a($rs,'IteratorAggregate'))
1699
+		if (is_a($rs, 'IteratorAggregate'))
1700 1700
 		{
1701 1701
 			$this->rs = $rs->getIterator();
1702 1702
 		}
@@ -1713,7 +1713,7 @@  discard block
 block discarded – undo
1713 1713
 	 */
1714 1714
 	public function current()
1715 1715
 	{
1716
-		if (is_a($this->rs,'iterator'))
1716
+		if (is_a($this->rs, 'iterator'))
1717 1717
 		{
1718 1718
 			$data = $this->rs->current();
1719 1719
 
@@ -1729,7 +1729,7 @@  discard block
 block discarded – undo
1729 1729
 	 */
1730 1730
 	public function key()
1731 1731
 	{
1732
-		if (is_a($this->rs,'iterator'))
1732
+		if (is_a($this->rs, 'iterator'))
1733 1733
 		{
1734 1734
 			return $this->rs->key();
1735 1735
 		}
@@ -1741,7 +1741,7 @@  discard block
 block discarded – undo
1741 1741
 	 */
1742 1742
 	public function next()
1743 1743
 	{
1744
-		if (is_a($this->rs,'iterator'))
1744
+		if (is_a($this->rs, 'iterator'))
1745 1745
 		{
1746 1746
 			return $this->rs->next();
1747 1747
 		}
@@ -1752,7 +1752,7 @@  discard block
 block discarded – undo
1752 1752
 	 */
1753 1753
 	public function rewind()
1754 1754
 	{
1755
-		if (is_a($this->rs,'iterator'))
1755
+		if (is_a($this->rs, 'iterator'))
1756 1756
 		{
1757 1757
 			return $this->rs->rewind();
1758 1758
 		}
@@ -1763,9 +1763,9 @@  discard block
 block discarded – undo
1763 1763
 	 *
1764 1764
 	 * @return boolean
1765 1765
 	 */
1766
-	public function valid ()
1766
+	public function valid()
1767 1767
 	{
1768
-		if (is_a($this->rs,'iterator'))
1768
+		if (is_a($this->rs, 'iterator'))
1769 1769
 		{
1770 1770
 			return $this->rs->valid();
1771 1771
 		}
Please login to merge, or discard this patch.
Braces   +189 added lines, -50 removed lines patch added patch discarded remove patch
@@ -196,9 +196,15 @@  discard block
 block discarded – undo
196 196
 		{
197 197
 			$this->app = $app;
198 198
 
199
-			if (!$no_clone) $this->db->set_app($app);
199
+			if (!$no_clone)
200
+			{
201
+				$this->db->set_app($app);
202
+			}
200 203
 
201
-			if ($table) $this->setup_table($app,$table,$column_prefix);
204
+			if ($table)
205
+			{
206
+				$this->setup_table($app,$table,$column_prefix);
207
+			}
202 208
 		}
203 209
 		$this->init();
204 210
 
@@ -219,7 +225,10 @@  discard block
 block discarded – undo
219 225
 	 */
220 226
 	public function set_times($timestamp_type=false)
221 227
 	{
222
-		if ($timestamp_type !== false) $this->timestamp_type = $timestamp_type;
228
+		if ($timestamp_type !== false)
229
+		{
230
+			$this->timestamp_type = $timestamp_type;
231
+		}
223 232
 
224 233
 		// set current time
225 234
 		switch($this->timestamp_type)
@@ -287,7 +296,10 @@  discard block
 block discarded – undo
287 296
 			{
288 297
 				$this->autoinc_id = $col;
289 298
 			}
290
-			if ($def['type'] == 'bool') $this->has_bools = true;
299
+			if ($def['type'] == 'bool')
300
+			{
301
+				$this->has_bools = true;
302
+			}
291 303
 
292 304
 			foreach($this->table_def['uc'] as $k => $uni_index)
293 305
 			{
@@ -326,7 +338,10 @@  discard block
 block discarded – undo
326 338
 	 */
327 339
 	function data_merge($new)
328 340
 	{
329
-		if ((int) $this->debug >= 4) echo "<p>so_sql::data_merge(".print_r($new,true).")</p>\n";
341
+		if ((int) $this->debug >= 4)
342
+		{
343
+			echo "<p>so_sql::data_merge(".print_r($new,true).")</p>\n";
344
+		}
330 345
 
331 346
 		if (!is_array($new) || !count($new))
332 347
 		{
@@ -350,7 +365,10 @@  discard block
 block discarded – undo
350 365
 		{
351 366
 			$this->data[self::USER_TIMEZONE_READ] = $new[self::USER_TIMEZONE_READ];
352 367
 		}
353
-		if ((int) $this->debug >= 4) _debug_array($this->data);
368
+		if ((int) $this->debug >= 4)
369
+		{
370
+			_debug_array($this->data);
371
+		}
354 372
 	}
355 373
 
356 374
 	/**
@@ -494,7 +512,10 @@  discard block
 block discarded – undo
494 512
 		if (!is_array($keys))
495 513
 		{
496 514
 			$pk = array_values($this->db_key_cols);
497
-			if ($pk) $keys = array($pk[0] => $keys);
515
+			if ($pk)
516
+			{
517
+				$keys = array($pk[0] => $keys);
518
+			}
498 519
 		}
499 520
 
500 521
 		$this->init($keys);
@@ -508,13 +529,16 @@  discard block
 block discarded – undo
508 529
 				$query[$db_col] = $this->data[$col];
509 530
 			}
510 531
 		}
511
-		if (!$query)	// no primary key in keys, lets try the data_cols for a unique key
532
+		if (!$query)
533
+		{
534
+			// no primary key in keys, lets try the data_cols for a unique key
512 535
 		{
513 536
 			foreach($this->db_uni_cols as $db_col => $col)
514 537
 			{
515 538
 				if (!is_array($col) && $this->data[$col] != '')
516 539
 				{
517 540
 					$query[$db_col] = $this->data[$col];
541
+		}
518 542
 				}
519 543
 				elseif(is_array($col))
520 544
 				{
@@ -528,31 +552,43 @@  discard block
 block discarded – undo
528 552
 						}
529 553
 						$q[$db_c] = $this->data[$c];
530 554
 					}
531
-					if ($q) $query += $q;
555
+					if ($q)
556
+					{
557
+						$query += $q;
558
+					}
532 559
 				}
533 560
 			}
534 561
 		}
535
-		if (!$query)	// no unique key in keys, lets try everything else
562
+		if (!$query)
563
+		{
564
+			// no unique key in keys, lets try everything else
536 565
 		{
537 566
 			foreach($this->db_data_cols as $db_col => $col)
538 567
 			{
539 568
 				if ($this->data[$col] != '')
540 569
 				{
541 570
 					$query[$db_col] = $this->data[$col];
571
+		}
542 572
 				}
543 573
 			}
544 574
 		}
545
-		if (!$query)	// keys has no cols
575
+		if (!$query)
576
+		{
577
+			// keys has no cols
546 578
 		{
547 579
 			$this->db2data();
580
+		}
548 581
 
549 582
 			return False;
550 583
 		}
551
-		if ($join)	// Prefix the columns with the table-name, as they might exist in the join
584
+		if ($join)
585
+		{
586
+			// Prefix the columns with the table-name, as they might exist in the join
552 587
 		{
553 588
 			foreach($query as $col => $val)
554 589
 			{
555 590
 				if (is_int($col) || strpos($join,$col) === false) continue;
591
+		}
556 592
 				$query[] = $this->db->expression($this->table_name,$this->table_name.'.',array($col=>$val));
557 593
 				unset($query[$col]);
558 594
 			}
@@ -561,11 +597,14 @@  discard block
 block discarded – undo
561 597
 			$query,__LINE__,__FILE__,False,'',$this->app,0,$join) as $row)
562 598
 		{
563 599
 			$cols = $this->db_cols;
564
-			if ($extra_cols)	// extra columns to report
600
+			if ($extra_cols)
601
+			{
602
+				// extra columns to report
565 603
 			{
566 604
 				foreach(is_array($extra_cols) ? $extra_cols : array($extra_cols) as $col)
567 605
 				{
568 606
 					if (FALSE!==stripos($col,' as ')) $col = preg_replace('/^.* as *([a-z0-9_]+) *$/i','\\1',$col);
607
+			}
569 608
 					$cols[$col] = $col;
570 609
 				}
571 610
 			}
@@ -588,7 +627,10 @@  discard block
 block discarded – undo
588 627
 		{
589 628
 			unset($this->data[$this->db_key_cols[$this->autoinc_id]]);
590 629
 		}
591
-		if ((int) $this->debug >= 4) echo "nothing found !!!</p>\n";
630
+		if ((int) $this->debug >= 4)
631
+		{
632
+			echo "nothing found !!!</p>\n";
633
+		}
592 634
 
593 635
 		$this->db2data();
594 636
 
@@ -604,7 +646,10 @@  discard block
 block discarded – undo
604 646
 	 */
605 647
 	function save($keys=null,$extra_where=null)
606 648
 	{
607
-		if (is_array($keys) && count($keys)) $this->data_merge($keys);
649
+		if (is_array($keys) && count($keys))
650
+		{
651
+			$this->data_merge($keys);
652
+		}
608 653
 
609 654
 		// check if data contains user timezone during read AND user changed timezone since then
610 655
 		// --> load old timezone for the rest of this request
@@ -621,9 +666,13 @@  discard block
 block discarded – undo
621 666
 		}
622 667
 		$this->data2db();
623 668
 
624
-		if ((int) $this->debug >= 4) { echo "so_sql::save(".print_r($keys,true).") autoinc_id='$this->autoinc_id', data="; _debug_array($this->data); }
669
+		if ((int) $this->debug >= 4)
670
+		{
671
+echo "so_sql::save(".print_r($keys,true).") autoinc_id='$this->autoinc_id', data="; _debug_array($this->data); }
625 672
 
626
-		if ($this->autoinc_id && !$this->data[$this->db_key_cols[$this->autoinc_id]])	// insert with auto id
673
+		if ($this->autoinc_id && !$this->data[$this->db_key_cols[$this->autoinc_id]])
674
+		{
675
+			// insert with auto id
627 676
 		{
628 677
 			foreach($this->db_cols as $db_col => $col)
629 678
 			{
@@ -633,7 +682,9 @@  discard block
 block discarded – undo
633 682
 						(isset($this->table_def['fd'][$db_col]['default']) ||	// we have a default value
634 683
 						 !isset($this->table_def['fd'][$db_col]['nullable']) || $this->table_def['fd'][$db_col]['nullable']))	// column is nullable
635 684
 					{
636
-						continue;	// no need to write that (unset) column
685
+						continue;
686
+		}
687
+		// no need to write that (unset) column
637 688
 					}
638 689
 					if ($this->table_def['fd'][$db_col]['type'] == 'varchar' &&
639 690
 						strlen($this->data[$col]) > $this->table_def['fd'][$db_col]['precision'])
@@ -664,9 +715,13 @@  discard block
 block discarded – undo
664 715
 				if (!array_key_exists($col,$this->data) &&	// handling of unset columns in $this->data
665 716
 					($this->autoinc_id ||			// update of table with auto id or
666 717
 					 isset($this->table_def['fd'][$db_col]['default']) ||	// we have a default value or
667
-					 !isset($this->table_def['fd'][$db_col]['nullable']) || $this->table_def['fd'][$db_col]['nullable']))	// column is nullable
718
+					 !isset($this->table_def['fd'][$db_col]['nullable']) || $this->table_def['fd'][$db_col]['nullable']))
719
+				{
720
+					// column is nullable
668 721
 				{
669
-					continue;	// no need to write that (unset) column
722
+					continue;
723
+				}
724
+				// no need to write that (unset) column
670 725
 				}
671 726
 				$data[$db_col] = !is_object($this->data[$col]) && (string) $this->data[$col] === '' && $this->empty_on_write == 'NULL' ? null : $this->data[$col];
672 727
 			}
@@ -683,9 +738,12 @@  discard block
 block discarded – undo
683 738
 			{
684 739
 				$keys[$db_col] = $this->data[$col];
685 740
 			}
686
-			if (!$data && !$this->autoinc_id)	// happens if all columns are in the primary key
741
+			if (!$data && !$this->autoinc_id)
742
+			{
743
+				// happens if all columns are in the primary key
687 744
 			{
688 745
 				$data = $keys;
746
+			}
689 747
 				$keys = False;
690 748
 			}
691 749
 			if ($this->autoinc_id)
@@ -716,7 +774,10 @@  discard block
 block discarded – undo
716 774
 	 */
717 775
 	function update($_fields,$merge=true)
718 776
 	{
719
-		if ($merge) $this->data_merge($_fields);
777
+		if ($merge)
778
+		{
779
+			$this->data_merge($_fields);
780
+		}
720 781
 
721 782
 		$fields = $this->data2db($_fields);
722 783
 
@@ -769,9 +830,12 @@  discard block
 block discarded – undo
769 830
 		{
770 831
 			$keys = array($this->autoinc_id => $keys);
771 832
 		}
772
-		if (!is_array($keys) || !count($keys))	// use internal data
833
+		if (!is_array($keys) || !count($keys))
834
+		{
835
+			// use internal data
773 836
 		{
774 837
 			$data = $this->data;
838
+		}
775 839
 			$keys = $this->db_key_cols;
776 840
 		}
777 841
 		else	// data and keys are supplied in $keys
@@ -791,7 +855,10 @@  discard block
 block discarded – undo
791 855
 		{
792 856
 			$query[$db_col] = $data[$col];
793 857
 		}
794
-		if ($only_return_query) return $query;
858
+		if ($only_return_query)
859
+		{
860
+			return $query;
861
+		}
795 862
 
796 863
 		$this->db->delete($this->table_name,$query,__LINE__,__FILE__,$this->app);
797 864
 
@@ -824,7 +891,10 @@  discard block
 block discarded – undo
824 891
 	function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false)
825 892
 	{
826 893
 		//error_log(__METHOD__.'('.array2string(array_combine(array_slice(array('criteria','only_keys','order_by','extra_cols','wildcard','empty','op','start','filter','join','need_full_no_count'), 0, count(func_get_args())), func_get_args())).')');
827
-		if ((int) $this->debug >= 4) echo "<p>so_sql::search(".print_r($criteria,true).",'$only_keys','$order_by',".print_r($extra_cols,true).",'$wildcard','$empty','$op','$start',".print_r($filter,true).",'$join')</p>\n";
894
+		if ((int) $this->debug >= 4)
895
+		{
896
+			echo "<p>so_sql::search(".print_r($criteria,true).",'$only_keys','$order_by',".print_r($extra_cols,true).",'$wildcard','$empty','$op','$start',".print_r($filter,true).",'$join')</p>\n";
897
+		}
828 898
 
829 899
 		// if extending class or instanciator set columns to search, convert string criteria to array
830 900
 		if ($criteria && !is_array($criteria))
@@ -888,9 +958,12 @@  discard block
 block discarded – undo
888 958
 								($negate ? ') ' : '');
889 959
 						}
890 960
 					}
891
-					elseif (strpos($db_col,'.') !== false)	// we have a table-name specified
961
+					elseif (strpos($db_col,'.') !== false)
962
+					{
963
+						// we have a table-name specified
892 964
 					{
893 965
 						list($table,$only_col) = explode('.',$db_col);
966
+					}
894 967
 						$type = $this->db->get_column_attribute($only_col, $table, true, 'type');
895 968
 						if (empty($type))
896 969
 						{
@@ -915,13 +988,17 @@  discard block
 block discarded – undo
915 988
 					}
916 989
 				}
917 990
 			}
918
-			if (is_array($query) && $op != 'AND') $query = $this->db->column_data_implode(' '.$op.' ',$query);
991
+			if (is_array($query) && $op != 'AND')
992
+			{
993
+				$query = $this->db->column_data_implode(' '.$op.' ',$query);
994
+			}
919 995
 		}
920 996
 		if (is_array($filter))
921 997
 		{
922 998
 			$db_filter = array();
923 999
 			$data2db_filter = $this->data2db($filter);
924
-			if (!is_array($data2db_filter)) {
1000
+			if (!is_array($data2db_filter))
1001
+			{
925 1002
 				echo function_backtrace()."<br/>\n";
926 1003
 				echo "filter=";_debug_array($filter);
927 1004
 				echo "data2db(filter)=";_debug_array($data2db_filter);
@@ -1017,7 +1094,10 @@  discard block
 block discarded – undo
1017 1094
 			}
1018 1095
 		}
1019 1096
 		$num_rows = 0;	// as spec. in max_matches in the user-prefs
1020
-		if (is_array($start)) list($start,$num_rows) = $start;
1097
+		if (is_array($start))
1098
+		{
1099
+			list($start,$num_rows) = $start;
1100
+		}
1021 1101
 
1022 1102
 		// fix GROUP BY clause to contain all non-aggregate selected columns
1023 1103
 		if ($order_by && stripos($order_by,'GROUP BY') !== false)
@@ -1045,18 +1125,24 @@  discard block
 block discarded – undo
1045 1125
 					'append' => $order_by,
1046 1126
 					'join'   => $join,
1047 1127
 				);
1048
-				if (!$union_cols)	// union used the colum-names of the first query
1128
+				if (!$union_cols)
1129
+				{
1130
+					// union used the colum-names of the first query
1049 1131
 				{
1050 1132
 					$union_cols = $this->_get_columns($only_keys,$extra_cols);
1051 1133
 				}
1134
+				}
1052 1135
 				return true;	// waiting for further calls, before running the union-query
1053 1136
 			}
1054 1137
 			// running the union query now
1055
-			if ($start !== false)	// need to get the total too, saved in $this->total
1138
+			if ($start !== false)
1139
+			{
1140
+				// need to get the total too, saved in $this->total
1056 1141
 			{
1057 1142
 				if ($this->db->Type == 'mysql' && $this->db->ServerInfo['version'] >= 4.0)
1058 1143
 				{
1059 1144
 					$union[0]['cols'] = ($mysql_calc_rows = 'SQL_CALC_FOUND_ROWS ').$union[0]['cols'];
1145
+			}
1060 1146
 				}
1061 1147
 				else	// cant do a count, have to run the query without limit
1062 1148
 				{
@@ -1064,18 +1150,24 @@  discard block
 block discarded – undo
1064 1150
 				}
1065 1151
 			}
1066 1152
 			$rs = $this->db->union($union,__LINE__,__FILE__,$order_by,$start,$num_rows);
1067
-			if ($this->debug) error_log(__METHOD__."() ".$this->db->Query_ID->sql);
1153
+			if ($this->debug)
1154
+			{
1155
+				error_log(__METHOD__."() ".$this->db->Query_ID->sql);
1156
+			}
1068 1157
 
1069 1158
 			$cols = $union_cols;
1070 1159
 			$union = $union_cols = array();
1071 1160
 		}
1072 1161
 		else	// no UNION
1073 1162
 		{
1074
-			if ($start !== false)	// need to get the total too, saved in $this->total
1163
+			if ($start !== false)
1164
+			{
1165
+				// need to get the total too, saved in $this->total
1075 1166
 			{
1076 1167
 				if ($this->db->Type == 'mysql' && $this->db->ServerInfo['version'] >= 4.0)
1077 1168
 				{
1078 1169
 					$mysql_calc_rows = 'SQL_CALC_FOUND_ROWS ';
1170
+			}
1079 1171
 				}
1080 1172
 				elseif (!$need_full_no_count && (!$join || stripos($join,'LEFT JOIN')!==false))
1081 1173
 				{
@@ -1088,10 +1180,16 @@  discard block
 block discarded – undo
1088 1180
 			}
1089 1181
 			$rs = $this->db->select($this->table_name,$mysql_calc_rows.$colums,$query,__LINE__,__FILE__,
1090 1182
 				$start,$order_by,$this->app,$num_rows,$join);
1091
-			if ($this->debug) error_log(__METHOD__."() ".$this->db->Query_ID->sql);
1183
+			if ($this->debug)
1184
+			{
1185
+				error_log(__METHOD__."() ".$this->db->Query_ID->sql);
1186
+			}
1092 1187
 			$cols = $this->_get_columns($only_keys,$extra_cols);
1093 1188
 		}
1094
-		if ((int) $this->debug >= 4) echo "<p>sql='{$this->db->Query_ID->sql}'</p>\n";
1189
+		if ((int) $this->debug >= 4)
1190
+		{
1191
+			echo "<p>sql='{$this->db->Query_ID->sql}'</p>\n";
1192
+		}
1095 1193
 
1096 1194
 		if ($mysql_calc_rows)
1097 1195
 		{
@@ -1104,9 +1202,12 @@  discard block
 block discarded – undo
1104 1202
 		}
1105 1203
 		$arr = array();
1106 1204
 		$n = 0;
1107
-		if ($rs) foreach($rs as $row)
1205
+		if ($rs)
1206
+		{
1207
+			foreach($rs as $row)
1108 1208
 		{
1109 1209
 			$data = array();
1210
+		}
1110 1211
 			foreach($cols as $db_col => $col)
1111 1212
 			{
1112 1213
 				$data[$col] = (isset($row[$db_col]) ? $row[$db_col] : $row[$col]);
@@ -1175,9 +1276,15 @@  discard block
 block discarded – undo
1175 1276
 					$col = substr($col, $pos+9);
1176 1277
 				}
1177 1278
 				$alias = $col;
1178
-				if (stripos($col, ' AS ')) list($col, $alias) = preg_split('/ +AS +/i', $col);
1279
+				if (stripos($col, ' AS '))
1280
+				{
1281
+					list($col, $alias) = preg_split('/ +AS +/i', $col);
1282
+				}
1179 1283
 				// do NOT group by constant expressions
1180
-				if (preg_match('/^ *(-?[0-9]+|".*"|\'.*\'|NULL) *$/i', $col)) continue;
1284
+				if (preg_match('/^ *(-?[0-9]+|".*"|\'.*\'|NULL) *$/i', $col))
1285
+				{
1286
+					continue;
1287
+				}
1181 1288
 				if (!in_array($col, $group_by_cols) && !in_array($alias, $group_by_cols))
1182 1289
 				{
1183 1290
 					// instead of aliased primary key, we have to use original column incl. table-name as alias is ambigues
@@ -1210,7 +1317,10 @@  discard block
 block discarded – undo
1210 1317
 	{
1211 1318
 		$pattern = trim($_pattern);
1212 1319
 		// This function can get called multiple times.  Make sure it doesn't re-process.
1213
-		if (empty($pattern) || is_array($pattern)) return $pattern;
1320
+		if (empty($pattern) || is_array($pattern))
1321
+		{
1322
+			return $pattern;
1323
+		}
1214 1324
 		if(strpos($pattern, 'CAST(COALESCE(') !== false)
1215 1325
 		{
1216 1326
 			return $pattern;
@@ -1280,7 +1390,7 @@  discard block
 block discarded – undo
1280 1390
 			{
1281 1391
 				$token = substr($token, 1,strlen($token));
1282 1392
  				if(substr($token, -1) != '"')
1283
-				{
1393
+ 				{
1284 1394
 					$token .= ' '.strtok('"');
1285 1395
 				}
1286 1396
 				else
@@ -1396,7 +1506,8 @@  discard block
 block discarded – undo
1396 1506
 			foreach($search_cols as $key => &$col)
1397 1507
 			{
1398 1508
 				// If the name as given isn't a real column name, and adding the prefix doesn't help, skip it
1399
-				if(!$this->table_def['fd'][$col] && !($col = $this->prefix.array_search($col, $search_cols))) {
1509
+				if(!$this->table_def['fd'][$col] && !($col = $this->prefix.array_search($col, $search_cols)))
1510
+				{
1400 1511
 					// Can't search this column
1401 1512
 					unset($search_cols[$key]);
1402 1513
 					continue;
@@ -1430,10 +1541,13 @@  discard block
 block discarded – undo
1430 1541
 	function _get_columns($only_keys,$extra_cols)
1431 1542
 	{
1432 1543
 		//echo "_get_columns() only_keys="; _debug_array($only_keys); echo "extra_cols="; _debug_array($extra_cols);
1433
-		if ($only_keys === true)	// only primary key
1544
+		if ($only_keys === true)
1545
+		{
1546
+			// only primary key
1434 1547
 		{
1435 1548
 			$cols = $this->db_key_cols;
1436 1549
 		}
1550
+		}
1437 1551
 		else
1438 1552
 		{
1439 1553
 			$cols = array();
@@ -1442,18 +1556,27 @@  discard block
 block discarded – undo
1442 1556
 			{
1443 1557
 				if (!$distinct_checked)
1444 1558
 				{
1445
-					if (stripos($col, 'DISTINCT ') === 0) $col = substr($col, 9);
1559
+					if (stripos($col, 'DISTINCT ') === 0)
1560
+					{
1561
+						$col = substr($col, 9);
1562
+					}
1446 1563
 					$distinct_checked = true;
1447 1564
 				}
1448
-				if (!$col || $col == '*' || $col == $this->table_name.'.*')	// all columns
1565
+				if (!$col || $col == '*' || $col == $this->table_name.'.*')
1566
+				{
1567
+					// all columns
1449 1568
 				{
1450 1569
 					$cols = array_merge($cols,$this->db_cols);
1451 1570
 				}
1571
+				}
1452 1572
 				else	// only the specified columns
1453 1573
 				{
1454
-					if (stripos($col,'as'))	// if there's already an explicit naming of the column, just use it
1574
+					if (stripos($col,'as'))
1575
+					{
1576
+						// if there's already an explicit naming of the column, just use it
1455 1577
 					{
1456 1578
 						$col = preg_replace('/^.*as +([a-z0-9_]+) *$/i','\\1',$col);
1579
+					}
1457 1580
 						$cols[$col] = $col;
1458 1581
 						continue;
1459 1582
 					}
@@ -1468,11 +1591,14 @@  discard block
 block discarded – undo
1468 1591
 				}
1469 1592
 			}
1470 1593
 		}
1471
-		if ($extra_cols)	// extra columns to report
1594
+		if ($extra_cols)
1595
+		{
1596
+			// extra columns to report
1472 1597
 		{
1473 1598
 			foreach(is_array($extra_cols) ? $extra_cols : explode(',',$extra_cols) as $col)
1474 1599
 			{
1475 1600
 				if (stripos($col,'as ')!==false) $col = preg_replace('/^.*as +([a-z0-9_]+) *$/i','\\1',$col);
1601
+		}
1476 1602
 				if (($db_col = array_search($col,$this->db_cols)) !== false)
1477 1603
 				{
1478 1604
 					$cols[$db_col] = $col;
@@ -1517,7 +1643,11 @@  discard block
 block discarded – undo
1517 1643
 			'',false,$op,$query['num_rows']?array((int)$query['start'],$query['num_rows']):(int)$query['start'],
1518 1644
 			$query['col_filter'],$join,$need_full_no_count);
1519 1645
 
1520
-		if (!$rows) $rows = array();	// otherwise false returned from search would be returned as array(false)
1646
+		if (!$rows)
1647
+		{
1648
+			$rows = array();
1649
+		}
1650
+		// otherwise false returned from search would be returned as array(false)
1521 1651
 
1522 1652
 		return $this->total;
1523 1653
 	}
@@ -1596,7 +1726,10 @@  discard block
 block discarded – undo
1596 1726
 		{
1597 1727
 			return $cache[$cache_key];
1598 1728
 		}
1599
-		if (!is_array($value_col)) $value_col = array($value_col);
1729
+		if (!is_array($value_col))
1730
+		{
1731
+			$value_col = array($value_col);
1732
+		}
1600 1733
 
1601 1734
 		$cols = $ret = array();
1602 1735
 		foreach($value_col as $key => $col)
@@ -1604,7 +1737,10 @@  discard block
 block discarded – undo
1604 1737
 			$matches = null;
1605 1738
 			$cols[$key] = preg_match('/AS ([a-z_0-9]+)$/i',$col,$matches) ? $matches[1] : $col;
1606 1739
 		}
1607
-		if (!$order) $order = current($cols);
1740
+		if (!$order)
1741
+		{
1742
+			$order = current($cols);
1743
+		}
1608 1744
 
1609 1745
 		if (($search =& $this->search(array(),($key_col ? $key_col.',' : 'DISTINCT ').implode(',',$value_col),$order,'','',false,'AND',false,$filter)))
1610 1746
 		{
@@ -1630,7 +1766,10 @@  discard block
 block discarded – undo
1630 1766
 				{
1631 1767
 					$data = $row[current($cols)];
1632 1768
 				}
1633
-				if ($data) $ret[$row[$key_col]] = $data;
1769
+				if ($data)
1770
+				{
1771
+					$ret[$row[$key_col]] = $data;
1772
+				}
1634 1773
 			}
1635 1774
 		}
1636 1775
 		return $cache[$cache_key] =& $ret;
Please login to merge, or discard this patch.
etemplate/inc/class.so_sql2.inc.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@
 block discarded – undo
48 48
 	 * @param string $table should be set if table-defs to be read from <app>/setup/tables_current.inc.php
49 49
 	 * @param object/db $db database object, if not the one in $GLOBALS['egw']->db should be used, eg. for an other database
50 50
 	 * @param string $colum_prefix='' column prefix to automatic remove from the column-name, if the column name starts with it
51
-	 * @param boolean $no_clone=false can we avoid to clone the db-object, default no
51
+	 * @param boolean $no_clone can we avoid to clone the db-object, default no
52 52
 	 * 	new code using appnames and foreach(select(...,$app) can set it to avoid an extra instance of the db object
53 53
 	 *
54 54
 	 * @return so_sql2
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -53,9 +53,9 @@  discard block
 block discarded – undo
53 53
 	 *
54 54
 	 * @return so_sql2
55 55
 	 */
56
-	function __construct($app='',$table='',$db=null,$column_prefix='',$no_clone=false)
56
+	function __construct($app = '', $table = '', $db = null, $column_prefix = '', $no_clone = false)
57 57
 	{
58
-		parent::__construct($app,$table,$db,$column_prefix,$no_clone);
58
+		parent::__construct($app, $table, $db, $column_prefix, $no_clone);
59 59
 	}
60 60
 
61 61
 	/**
@@ -63,9 +63,9 @@  discard block
 block discarded – undo
63 63
 	 *
64 64
 	 * @deprecated use __construct
65 65
 	 */
66
-	function so_sql2($app='',$table='',$db=null,$column_prefix='',$no_clone=false)
66
+	function so_sql2($app = '', $table = '', $db = null, $column_prefix = '', $no_clone = false)
67 67
 	{
68
-		self::__construct($app,$table,$db,$column_prefix,$no_clone);
68
+		self::__construct($app, $table, $db, $column_prefix, $no_clone);
69 69
 	}
70 70
 
71 71
 	/**
@@ -78,13 +78,13 @@  discard block
 block discarded – undo
78 78
 	 */
79 79
 	function __get($property)
80 80
 	{
81
-		switch($property)
81
+		switch ($property)
82 82
 		{
83 83
 			case 'id':
84 84
 				$property = $this->autoinc_id;
85 85
 				break;
86 86
 		}
87
-		if (in_array($property,$this->db_cols) || in_array($property,$this->non_db_cols))
87
+		if (in_array($property, $this->db_cols) || in_array($property, $this->non_db_cols))
88 88
 		{
89 89
 			return $this->data[$property];
90 90
 		}
@@ -98,15 +98,15 @@  discard block
 block discarded – undo
98 98
 	 * @param string $property
99 99
 	 * @param mixed $value
100 100
 	 */
101
-	function __set($property,$value)
101
+	function __set($property, $value)
102 102
 	{
103
-		switch($property)
103
+		switch ($property)
104 104
 		{
105 105
 			case 'id':
106 106
 				$property = $this->autoinc_id;
107 107
 				break;
108 108
 		}
109
-		if (in_array($property,$this->db_cols) || in_array($property,$this->non_db_cols))
109
+		if (in_array($property, $this->db_cols) || in_array($property, $this->non_db_cols))
110 110
 		{
111 111
 			$this->data[$property] = $value;
112 112
 		}
Please login to merge, or discard this patch.
etemplate/inc/class.so_sql_cf.inc.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
 	 * @param string $join ='' sql to do a join, added as is after the table-name, eg. ", table2 WHERE x=y" or
367 367
 	 *	"LEFT JOIN table2 ON (x=y)", Note: there's no quoting done on $join!
368 368
 	 * @param boolean $need_full_no_count =false If true an unlimited query is run to determine the total number of rows, default false
369
-	 * @param mixed $only_keys =false, see search
369
+	 * @param boolean $only_keys =false, see search
370 370
 	 * @param string|array $extra_cols =array()
371 371
 	 * @return int total number of rows
372 372
 	 */
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
 	 * Check if cf is stored as 1:N relation in DB and array in memory
735 735
 	 *
736 736
 	 * @param string $name
737
-	 * @return string
737
+	 * @return boolean
738 738
 	 */
739 739
 	function is_multiple($name)
740 740
 	{
Please login to merge, or discard this patch.
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -207,12 +207,12 @@
 block discarded – undo
207 207
 	}
208 208
 
209 209
 	/**
210
-	* saves custom field data
211
-	*
212
-	* @param array $data data to save (cf's have to be prefixed with self::CF_PREFIX = #)
213
-	* @param array $extra_cols =array()
214
-	* @return bool false on success, errornumber on failure
215
-	*/
210
+	 * saves custom field data
211
+	 *
212
+	 * @param array $data data to save (cf's have to be prefixed with self::CF_PREFIX = #)
213
+	 * @param array $extra_cols =array()
214
+	 * @return bool false on success, errornumber on failure
215
+	 */
216 216
 	function save_customfields($data, array $extra_cols=array())
217 217
 	{
218 218
 		foreach (array_keys((array)$this->customfields) as $name)
Please login to merge, or discard this patch.
Spacing   +100 added lines, -102 removed lines patch added patch discarded remove patch
@@ -115,41 +115,41 @@  discard block
 block discarded – undo
115 115
 	 * @param boolean $allow_multiple_values =false should we allow AND store multiple values (1:N relations)
116 116
 	 * @param string $timestamp_type =null default null=leave them as is, 'ts'|'integer' use integer unix timestamps, 'object' use egw_time objects
117 117
 	 */
118
-	function __construct($app,$table,$extra_table,$column_prefix='',
119
-		$extra_key='_name',$extra_value='_value',$extra_id='_id',
120
-		$db=null,$no_clone=true,$allow_multiple_values=false,$timestamp_type=null)
118
+	function __construct($app, $table, $extra_table, $column_prefix = '',
119
+		$extra_key = '_name', $extra_value = '_value', $extra_id = '_id',
120
+		$db = null, $no_clone = true, $allow_multiple_values = false, $timestamp_type = null)
121 121
 	{
122 122
 		// calling the so_sql constructor
123
-		parent::__construct($app,$table,$db,$column_prefix,$no_clone,$timestamp_type);
123
+		parent::__construct($app, $table, $db, $column_prefix, $no_clone, $timestamp_type);
124 124
 
125 125
 		$this->allow_multiple_values = $allow_multiple_values;
126 126
 		$this->extra_table = $extra_table;
127
-		if (!$this->extra_id) $this->extra_id = $this->autoinc_id;	// default to auto id of regular table
127
+		if (!$this->extra_id) $this->extra_id = $this->autoinc_id; // default to auto id of regular table
128 128
 
129 129
 		// if names from columns of extra table are only postfixes (starting with _), prepend column prefix
130
-		if (!($prefix=$column_prefix))
130
+		if (!($prefix = $column_prefix))
131 131
 		{
132
-			list($prefix) = explode('_',$this->autoinc_id);
132
+			list($prefix) = explode('_', $this->autoinc_id);
133 133
 		}
134
-		elseif(substr($prefix,-1) == '_')
134
+		elseif (substr($prefix, -1) == '_')
135 135
 		{
136
-			$prefix = substr($prefix,0,-1);	// remove trailing underscore from column prefix parameter
136
+			$prefix = substr($prefix, 0, -1); // remove trailing underscore from column prefix parameter
137 137
 		}
138
-		foreach(array(
138
+		foreach (array(
139 139
 			'extra_id' => $extra_id,
140 140
 			'extra_key' => $extra_key,
141 141
 			'extra_value' => $extra_value
142 142
 		) as $col => $val)
143 143
 		{
144 144
 			$this->$col = $col_name = $val;
145
-			if ($col_name[0] == '_') $this->$col = $prefix . $val;
145
+			if ($col_name[0] == '_') $this->$col = $prefix.$val;
146 146
 		}
147 147
 		// some sanity checks, maybe they should be active only for development
148
-		if (!($extra_defs = $this->db->get_table_definitions($app,$extra_table)))
148
+		if (!($extra_defs = $this->db->get_table_definitions($app, $extra_table)))
149 149
 		{
150 150
 			throw new egw_exception_wrong_parameter("extra table $extra_table is NOT defined!");
151 151
 		}
152
-		foreach(array('extra_id','extra_key','extra_value') as $col)
152
+		foreach (array('extra_id', 'extra_key', 'extra_value') as $col)
153 153
 		{
154 154
 			if (!$this->$col || !isset($extra_defs['fd'][$this->$col]))
155 155
 			{
@@ -174,23 +174,23 @@  discard block
 block discarded – undo
174 174
 	 * @param array $field_names =null custom fields to read, default all
175 175
 	 * @return array id => $this->cf_field(name) => value
176 176
 	 */
177
-	function read_customfields($ids,$field_names=null)
177
+	function read_customfields($ids, $field_names = null)
178 178
 	{
179 179
 		if (is_null($field_names)) $field_names = array_keys($this->customfields);
180 180
 
181
-		foreach((array)$ids as $key => $id)
181
+		foreach ((array)$ids as $key => $id)
182 182
 		{
183 183
 			if (!(int)$id && is_array($ids)) unset($ids[$key]);
184 184
 		}
185
-		if (!$ids || !$field_names) return array();	// nothing to do
185
+		if (!$ids || !$field_names) return array(); // nothing to do
186 186
 
187 187
 		$entries = array();
188
-		foreach($this->db->select($this->extra_table,'*',array(
188
+		foreach ($this->db->select($this->extra_table, '*', array(
189 189
 			$this->extra_id => $ids,
190 190
 			$this->extra_key => $field_names,
191
-		),__LINE__,__FILE__,false,'',$this->app) as $row)
191
+		), __LINE__, __FILE__, false, '', $this->app) as $row)
192 192
 		{
193
-			$entry =& $entries[$row[$this->extra_id]];
193
+			$entry = & $entries[$row[$this->extra_id]];
194 194
 			if (!is_array($entry)) $entry = array();
195 195
 			$field = $this->get_cf_field($row[$this->extra_key]);
196 196
 
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 	* @param array $extra_cols =array()
214 214
 	* @return bool false on success, errornumber on failure
215 215
 	*/
216
-	function save_customfields($data, array $extra_cols=array())
216
+	function save_customfields($data, array $extra_cols = array())
217 217
 	{
218 218
 		foreach (array_keys((array)$this->customfields) as $name)
219 219
 		{
@@ -226,22 +226,21 @@  discard block
 block discarded – undo
226 226
 			$is_multiple = $this->is_multiple($name);
227 227
 
228 228
 			// we explicitly need to delete fields, if value is empty or field allows multiple values or we have no unique index
229
-			if(empty($data[$field]) || $is_multiple || !$this->extra_has_unique_index)
229
+			if (empty($data[$field]) || $is_multiple || !$this->extra_has_unique_index)
230 230
 			{
231
-				$this->db->delete($this->extra_table,$where,__LINE__,__FILE__,$this->app);
232
-				if (empty($data[$field])) continue;	// nothing else to do for empty values
231
+				$this->db->delete($this->extra_table, $where, __LINE__, __FILE__, $this->app);
232
+				if (empty($data[$field])) continue; // nothing else to do for empty values
233 233
 			}
234
-			foreach($is_multiple && !is_array($data[$field]) ? explode(',',$data[$field]) :
235
-				// regular custom fields (!$is_multiple) eg. addressbook store multiple values comma-separated
234
+			foreach ($is_multiple && !is_array($data[$field]) ? explode(',', $data[$field]) : // regular custom fields (!$is_multiple) eg. addressbook store multiple values comma-separated
236 235
 				(array)(!$is_multiple && is_array($data[$field]) ? implode(',', $data[$field]) : $data[$field]) as $value)
237 236
 			{
238
-				if (!$this->db->insert($this->extra_table,array($this->extra_value => $value)+$extra_cols,$where,__LINE__,__FILE__,$this->app))
237
+				if (!$this->db->insert($this->extra_table, array($this->extra_value => $value) + $extra_cols, $where, __LINE__, __FILE__, $this->app))
239 238
 				{
240 239
 					return $this->db->Errno;
241 240
 				}
242 241
 			}
243 242
 		}
244
-		return false;	// no error
243
+		return false; // no error
245 244
 	}
246 245
 
247 246
 	/**
@@ -257,7 +256,7 @@  discard block
 block discarded – undo
257 256
 
258 257
 		if ($this->customfields)
259 258
 		{
260
-			foreach(array_keys($this->customfields) as $name)
259
+			foreach (array_keys($this->customfields) as $name)
261 260
 			{
262 261
 				if (isset($new[$field = $this->get_cf_field($name)]))
263 262
 				{
@@ -277,16 +276,16 @@  discard block
 block discarded – undo
277 276
 	 * @param string $join sql to do a join, added as is after the table-name, eg. ", table2 WHERE x=y" or
278 277
 	 * @return array|boolean data if row could be retrived else False
279 278
 	 */
280
-	function read($keys,$extra_cols='',$join='')
279
+	function read($keys, $extra_cols = '', $join = '')
281 280
 	{
282
-		if (!parent::read($keys,$extra_cols,$join))
281
+		if (!parent::read($keys, $extra_cols, $join))
283 282
 		{
284 283
 			return false;
285 284
 		}
286 285
 		if (($id = (int)$this->data[$this->db_key_cols[$this->autoinc_id]]) && $this->customfields &&
287 286
 			($cfs = $this->read_customfields($id)))
288 287
 		{
289
-			$this->data = array_merge($this->data,$cfs[$id]);
288
+			$this->data = array_merge($this->data, $cfs[$id]);
290 289
 		}
291 290
 		return $this->data;
292 291
 	}
@@ -300,14 +299,14 @@  discard block
 block discarded – undo
300 299
 	 * @param string|array $extra_where =null extra where clause, eg. to check an etag, returns true if no affected rows!
301 300
 	 * @return int|boolean 0 on success, or errno != 0 on error, or true if $extra_where is given and no rows affected
302 301
 	 */
303
-	function save($keys=null,$extra_where=null)
302
+	function save($keys = null, $extra_where = null)
304 303
 	{
305 304
 		if (is_array($keys) && count($keys) && !isset($keys[0]))	// allow to use an etag, eg array('etag=etag+1')
306 305
 		{
307 306
 			$this->data_merge($keys);
308 307
 			$keys = null;
309 308
 		}
310
-		$ret = parent::save($keys,$extra_where);
309
+		$ret = parent::save($keys, $extra_where);
311 310
 
312 311
 		if ($ret == 0 && $this->customfields)
313 312
 		{
@@ -325,26 +324,26 @@  discard block
 block discarded – undo
325 324
 	 * @param boolean $only_return_ids =false return $ids of delete call to db object, but not run it (can be used by extending classes!)
326 325
 	 * @return int|array affected rows, should be 1 if ok, 0 if an error or array with id's if $only_return_ids
327 326
 	 */
328
-	function delete($keys=null,$only_return_ids=false)
327
+	function delete($keys = null, $only_return_ids = false)
329 328
 	{
330 329
 		if ($this->customfields || $only_return_ids)
331 330
 		{
332
-			$query = parent::delete($keys,true);
331
+			$query = parent::delete($keys, true);
333 332
 			// check if query contains more then the id's
334 333
 			if (!isset($query[$this->autoinc_id]) || count($query) != 1)
335 334
 			{
336
-				foreach($this->db->select($this->table_name,$this->autoinc_id,$query,__LINE__,__FILE__,false,'',$this->app) as $row)
335
+				foreach ($this->db->select($this->table_name, $this->autoinc_id, $query, __LINE__, __FILE__, false, '', $this->app) as $row)
337 336
 				{
338 337
 					$ids[] = $row[$this->autoinc_id];
339 338
 				}
340
-				if (!$ids) return 0;	// no rows affected
339
+				if (!$ids) return 0; // no rows affected
341 340
 			}
342 341
 			else
343 342
 			{
344 343
 				$ids = (array)$query[$this->autoinc_id];
345 344
 			}
346 345
 			if ($only_return_ids) return $ids;
347
-			$this->db->delete($this->extra_table,array($this->extra_id => $ids),__LINE__,__FILE__);
346
+			$this->db->delete($this->extra_table, array($this->extra_id => $ids), __LINE__, __FILE__);
348 347
 		}
349 348
 		return parent::delete($keys);
350 349
 	}
@@ -367,32 +366,32 @@  discard block
 block discarded – undo
367 366
 	 * @param string|array $extra_cols =array()
368 367
 	 * @return int total number of rows
369 368
 	 */
370
-	function get_rows($query,&$rows,&$readonlys,$join='',$need_full_no_count=false,$only_keys=false,$extra_cols=array())
369
+	function get_rows($query, &$rows, &$readonlys, $join = '', $need_full_no_count = false, $only_keys = false, $extra_cols = array())
371 370
 	{
372
-		parent::get_rows($query,$rows,$readonlys,$join,$need_full_no_count,$only_keys,$extra_cols);
371
+		parent::get_rows($query, $rows, $readonlys, $join, $need_full_no_count, $only_keys, $extra_cols);
373 372
 
374
-		$selectcols = $query['selectcols'] ? explode(',',$query['selectcols']) : array();
373
+		$selectcols = $query['selectcols'] ? explode(',', $query['selectcols']) : array();
375 374
 
376
-		if ($rows && $this->customfields && (!$selectcols || in_array('customfields',$selectcols)))
375
+		if ($rows && $this->customfields && (!$selectcols || in_array('customfields', $selectcols)))
377 376
 		{
378 377
 			$id2keys = array();
379
-			foreach($rows as $key => $row)
378
+			foreach ($rows as $key => $row)
380 379
 			{
381 380
 				$id2keys[$row[$this->db_key_cols[$this->autoinc_id]]] = $key;
382 381
 			}
383 382
 			// check if only certain cf's to show
384 383
 			if (!in_array('customfields', $selectcols))
385 384
 			{
386
-				foreach($selectcols as $col)
385
+				foreach ($selectcols as $col)
387 386
 				{
388 387
 					if ($this->is_cf($col)) $fields[] = $this->get_cf_name($col);
389 388
 				}
390 389
 			}
391
-			if (($cfs = $this->read_customfields(array_keys($id2keys),$fields)))
390
+			if (($cfs = $this->read_customfields(array_keys($id2keys), $fields)))
392 391
 			{
393
-				foreach($cfs as $id => $data)
392
+				foreach ($cfs as $id => $data)
394 393
 				{
395
-					$rows[$id2keys[$id]] = array_merge($rows[$id2keys[$id]],$data);
394
+					$rows[$id2keys[$id]] = array_merge($rows[$id2keys[$id]], $data);
396 395
 				}
397 396
 			}
398 397
 		}
@@ -419,12 +418,12 @@  discard block
 block discarded – undo
419 418
 	 * @param boolean $need_full_no_count =false If true an unlimited query is run to determine the total number of rows, default false
420 419
 	 * @return array|NULL array of matching rows (the row is an array of the cols) or NULL
421 420
 	 */
422
-	function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false)
421
+	function &search($criteria, $only_keys = True, $order_by = '', $extra_cols = '', $wildcard = '', $empty = False, $op = 'AND', $start = false, $filter = null, $join = '', $need_full_no_count = false)
423 422
 	{
424 423
 		//error_log(__METHOD__.'('.array2string(array_combine(array_slice(array('criteria','only_keys','order_by','extra_cols','wildcard','empty','op','start','filter','join','need_full_no_count'), 0, count(func_get_args())), func_get_args())).')');
425 424
 		if (!$this->customfields)
426 425
 		{
427
-			return parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count);
426
+			return parent::search($criteria, $only_keys, $order_by, $extra_cols, $wildcard, $empty, $op, $start, $filter, $join, $need_full_no_count);
428 427
 		}
429 428
 		if ($only_keys === false)
430 429
 		{
@@ -433,7 +432,7 @@  discard block
 block discarded – undo
433 432
 		// if string given as criteria --> search in all (or $this->columns_to_search) columns including custom fields
434 433
 		if ($criteria && is_string($criteria))
435 434
 		{
436
-			$criteria = $this->search2criteria($criteria,$wildcard,$op);
435
+			$criteria = $this->search2criteria($criteria, $wildcard, $op);
437 436
 		}
438 437
 		if ($criteria && is_array($criteria))
439 438
 		{
@@ -442,10 +441,10 @@  discard block
 block discarded – undo
442 441
 			{
443 442
 				if (($negate = $criteria[$this->extra_value][0] === '!'))
444 443
 				{
445
-					$criteria[$this->extra_value] = substr($criteria[$this->extra_value],1);
444
+					$criteria[$this->extra_value] = substr($criteria[$this->extra_value], 1);
446 445
 				}
447
-				$criteria[] = $this->extra_table.'.'.$this->extra_value . ' ' .($negate ? 'NOT ' : '').
448
-					$this->db->capabilities[egw_db::CAPABILITY_CASE_INSENSITIV_LIKE]. ' ' .
446
+				$criteria[] = $this->extra_table.'.'.$this->extra_value.' '.($negate ? 'NOT ' : '').
447
+					$this->db->capabilities[egw_db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.
449 448
 					$this->db->quote($wildcard.$criteria[$this->extra_value].$wildcard);
450 449
 				unset($criteria[$this->extra_value]);
451 450
 			}
@@ -454,14 +453,14 @@  discard block
 block discarded – undo
454 453
 			{
455 454
 				if ($criteria[$this->autoinc_id])
456 455
 				{
457
-					$criteria[] = $this->db->expression($this->table_name,$this->table_name.'.',
456
+					$criteria[] = $this->db->expression($this->table_name, $this->table_name.'.',
458 457
 						array($this->autoinc_id => $criteria[$this->autoinc_id]));
459 458
 				}
460 459
 				unset($criteria[$this->autoinc_id]);
461 460
 			}
462 461
 			// replace ambiguous column with (an exact match of) table_name.column
463 462
 			$extra_join_added = $join && strpos($join, $this->extra_join) !== false;
464
-			foreach($criteria as $name => $val)
463
+			foreach ($criteria as $name => $val)
465 464
 			{
466 465
 				// only add extra_join, if we really need it
467 466
 				if (!$extra_join_added && (
@@ -473,9 +472,9 @@  discard block
 block discarded – undo
473 472
 					$extra_join_added = true;
474 473
 				}
475 474
 				$extra_columns = $this->db->get_table_definitions($this->app, $this->extra_table);
476
-				if(is_string($name) && $extra_columns['fd'][array_search($name, $this->db_cols)])
475
+				if (is_string($name) && $extra_columns['fd'][array_search($name, $this->db_cols)])
477 476
 				{
478
-					$criteria[] = $this->db->expression($this->table_name,$this->table_name.'.',array(
477
+					$criteria[] = $this->db->expression($this->table_name, $this->table_name.'.', array(
479 478
 						array_search($name, $this->db_cols) => $val,
480 479
 					));
481 480
 					unset($criteria[$name]);
@@ -487,12 +486,12 @@  discard block
 block discarded – undo
487 486
 						$name = substr($name, 1);
488 487
 						if (($negate = $criteria[$name][0] === '!'))
489 488
 						{
490
-							$val = substr($val,1);
489
+							$val = substr($val, 1);
491 490
 						}
492
-						$cfcriteria[] = '(' . $this->extra_table.'.'.$this->extra_value . ' ' .($negate ? 'NOT ' : '').
493
-							$this->db->capabilities[egw_db::CAPABILITY_CASE_INSENSITIV_LIKE]. ' ' .
494
-							$this->db->quote($wildcard.$val.$wildcard) . ' AND ' .
495
-							$this->extra_table.'.'.$this->extra_key . ' = ' . $this->db->quote($name) .
491
+						$cfcriteria[] = '('.$this->extra_table.'.'.$this->extra_value.' '.($negate ? 'NOT ' : '').
492
+							$this->db->capabilities[egw_db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.
493
+							$this->db->quote($wildcard.$val.$wildcard).' AND '.
494
+							$this->extra_table.'.'.$this->extra_key.' = '.$this->db->quote($name).
496 495
 							')';
497 496
 						unset($criteria[self::CF_PREFIX.$name]);
498 497
 					}
@@ -504,38 +503,38 @@  discard block
 block discarded – undo
504 503
 					}
505 504
 				}
506 505
 			}
507
-			if ($cfcriteria && $op =='OR') $criteria[] = implode(' OR ',$cfcriteria);
506
+			if ($cfcriteria && $op == 'OR') $criteria[] = implode(' OR ', $cfcriteria);
508 507
 		}
509
-		if($only_keys === true)
508
+		if ($only_keys === true)
510 509
 		{
511 510
 			// Expand to keys here, so table_name can be prepended below
512 511
 			$only_keys = array_values($this->db_key_cols);
513 512
 		}
514 513
 		// replace ambiguous column with (an exact match of) table_name.column
515
-		if(is_array($only_keys))
514
+		if (is_array($only_keys))
516 515
 		{
517
-			foreach($only_keys as $key => &$col)
516
+			foreach ($only_keys as $key => &$col)
518 517
 			{
519
-				if(is_numeric($key) && in_array($col, $this->db_cols, true))
518
+				if (is_numeric($key) && in_array($col, $this->db_cols, true))
520 519
 				{
521
-					$col = $this->table_name .'.'.array_search($col, $this->db_cols).' AS '.$col;
520
+					$col = $this->table_name.'.'.array_search($col, $this->db_cols).' AS '.$col;
522 521
 				}
523 522
 			}
524 523
 		}
525 524
 		// check if we order by a custom field --> join cf table for given cf and order by it's value
526
-		if (strpos($order_by,self::CF_PREFIX) !== false)
525
+		if (strpos($order_by, self::CF_PREFIX) !== false)
527 526
 		{
528 527
 			// fields to order by, as cutomfields may have names with spaces, we examine each order by criteria
529
-			$fields2order = explode(',',$order_by);
530
-			foreach($fields2order as $v)
528
+			$fields2order = explode(',', $order_by);
529
+			foreach ($fields2order as $v)
531 530
 			{
532
-				if (strpos($v,self::CF_PREFIX) !== false)
531
+				if (strpos($v, self::CF_PREFIX) !== false)
533 532
 				{
534 533
 					// we found a customfield, so we split that part by space char in order to get Sorting Direction and Fieldname
535
-					$buff = explode(' ',trim($v));
534
+					$buff = explode(' ', trim($v));
536 535
 					$orderDir = array_pop($buff);
537
-					$key = substr(trim(implode(' ',$buff)), 1);
538
-					switch($this->customfields[$key]['type'])
536
+					$key = substr(trim(implode(' ', $buff)), 1);
537
+					switch ($this->customfields[$key]['type'])
539 538
 					{
540 539
 						case 'int':
541 540
 							$order_by = str_replace($v, 'extra_order.'.$this->extra_value.' IS NULL,'.
@@ -568,26 +567,26 @@  discard block
 block discarded – undo
568 567
 		{
569 568
 			$_cfnames = array_keys($this->customfields);
570 569
 			$extra_filter = null;
571
-			foreach($filter as $name => $val)
570
+			foreach ($filter as $name => $val)
572 571
 			{
573 572
 				// replace ambiguous auto-id with (an exact match of) table_name.autoid
574 573
 				if (is_string($name) && $name == $this->autoinc_id)
575 574
 				{
576 575
 					if ((int)$filter[$this->autoinc_id])
577 576
 					{
578
-						$filter[] = $this->db->expression($this->table_name,$this->table_name.'.',array(
577
+						$filter[] = $this->db->expression($this->table_name, $this->table_name.'.', array(
579 578
 							$this->autoinc_id => $filter[$this->autoinc_id],
580 579
 						));
581 580
 					}
582 581
 					unset($filter[$this->autoinc_id]);
583 582
 				}
584 583
 				// replace ambiguous column with (an exact match of) table_name.column
585
-				elseif (is_string($name) && $val!=null && in_array($name, $this->db_cols))
584
+				elseif (is_string($name) && $val != null && in_array($name, $this->db_cols))
586 585
 				{
587 586
 					$extra_columns = $this->db->get_table_definitions($this->app, $this->extra_table);
588 587
 					if ($extra_columns['fd'][array_search($name, $this->db_cols)])
589 588
 					{
590
-						$filter[] = $this->db->expression($this->table_name,$this->table_name.'.',array(
589
+						$filter[] = $this->db->expression($this->table_name, $this->table_name.'.', array(
591 590
 							array_search($name, $this->db_cols) => $val,
592 591
 						));
593 592
 						unset($filter[$name]);
@@ -599,61 +598,61 @@  discard block
 block discarded – undo
599 598
 					{
600 599
 						if ($val[0] === '!')	// negative filter
601 600
 						{
602
-							$sql_filter = 'extra_filter.'.$this->extra_value.'!='.$this->db->quote(substr($val,1));
601
+							$sql_filter = 'extra_filter.'.$this->extra_value.'!='.$this->db->quote(substr($val, 1));
603 602
 						}
604 603
 						else	// using egw_db::expression to allow to use array() with possible values or NULL
605 604
 						{
606
-							if($this->customfields[$this->get_cf_name($name)]['type'] == 'select' &&
605
+							if ($this->customfields[$this->get_cf_name($name)]['type'] == 'select' &&
607 606
 								$this->customfields[$this->get_cf_name($name)]['rows'] > 1)
608 607
 							{
609 608
 								// Multi-select - any entry with the filter value selected matches
610
-								$sql_filter = str_replace($this->extra_value,'extra_filter.'.
611
-									$this->extra_value,$this->db->expression($this->extra_table,array(
612
-										$this->db->concat("','",$this->extra_value,"','").' '.$this->db->capabilities[egw_db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote('%,'.$val.',%')
609
+								$sql_filter = str_replace($this->extra_value, 'extra_filter.'.
610
+									$this->extra_value, $this->db->expression($this->extra_table, array(
611
+										$this->db->concat("','", $this->extra_value, "','").' '.$this->db->capabilities[egw_db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote('%,'.$val.',%')
613 612
 									))
614 613
 								);
615 614
 							}
616 615
 							elseif ($this->customfields[$this->get_cf_name($name)]['type'] == 'text')
617 616
 							{
618
-								$sql_filter = str_replace($this->extra_value,'extra_filter.'.$this->extra_value,
619
-										$this->db->expression($this->extra_table,array(
617
+								$sql_filter = str_replace($this->extra_value, 'extra_filter.'.$this->extra_value,
618
+										$this->db->expression($this->extra_table, array(
620 619
 										$this->extra_value.' '.$this->db->capabilities[egw_db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote($wildcard.$val.$wildcard)
621 620
 									))
622 621
 								);
623 622
 							}
624 623
 							else
625 624
 							{
626
-								$sql_filter = str_replace($this->extra_value,'extra_filter.'.
627
-									$this->extra_value,$this->db->expression($this->extra_table,array($this->extra_value => $val)));
625
+								$sql_filter = str_replace($this->extra_value, 'extra_filter.'.
626
+									$this->extra_value, $this->db->expression($this->extra_table, array($this->extra_value => $val)));
628 627
 							}
629 628
 						}
630 629
 						// need to use a LEFT JOIN for negative search or to allow NULL values
631
-						$need_left_join = $val[0] === '!' || strpos($sql_filter,'IS NULL') !== false ? ' LEFT ' : '';
632
-						$join .= str_replace('extra_filter','extra_filter'.$extra_filter,$need_left_join.$this->extra_join_filter.
630
+						$need_left_join = $val[0] === '!' || strpos($sql_filter, 'IS NULL') !== false ? ' LEFT ' : '';
631
+						$join .= str_replace('extra_filter', 'extra_filter'.$extra_filter, $need_left_join.$this->extra_join_filter.
633 632
 							' AND extra_filter.'.$this->extra_key.'='.$this->db->quote($this->get_cf_name($name)).
634 633
 							' AND '.$sql_filter);
635 634
 						++$extra_filter;
636 635
 					}
637 636
 					unset($filter[$name]);
638 637
 				}
639
-				elseif(is_int($name) && $this->is_cf($val))	// lettersearch: #cfname LIKE 's%'
638
+				elseif (is_int($name) && $this->is_cf($val))	// lettersearch: #cfname LIKE 's%'
640 639
 				{
641
-					$_cf = explode(' ',$val);
642
-					foreach($_cf as $cf_np)
640
+					$_cf = explode(' ', $val);
641
+					foreach ($_cf as $cf_np)
643 642
 					{
644 643
 						// building cf_name by glueing parts together (, in case someone used whitespace in their custom field names)
645
-						$tcf_name = ($tcf_name?$tcf_name.' ':'').$cf_np;
644
+						$tcf_name = ($tcf_name ? $tcf_name.' ' : '').$cf_np;
646 645
 						// reacts on the first one found that matches an existing customfield, should be better then the old behavior of
647 646
 						// simply splitting by " " and using the first part
648
-						if ($this->is_cf($tcf_name) && ($cfn = $this->get_cf_name($tcf_name)) && array_search($cfn,(array)$_cfnames,true)!==false )
647
+						if ($this->is_cf($tcf_name) && ($cfn = $this->get_cf_name($tcf_name)) && array_search($cfn, (array)$_cfnames, true) !== false)
649 648
 						{
650 649
 							$cf = $tcf_name;
651 650
 							break;
652 651
 						}
653 652
 					}
654
-					$join .= str_replace('extra_filter','extra_filter'.$extra_filter,$this->extra_join_filter.
653
+					$join .= str_replace('extra_filter', 'extra_filter'.$extra_filter, $this->extra_join_filter.
655 654
 						' AND extra_filter.'.$this->extra_key.'='.$this->db->quote($this->get_cf_name($cf)).
656
-						' AND '.str_replace($cf,'extra_filter.'.$this->extra_value,$val));
655
+						' AND '.str_replace($cf, 'extra_filter.'.$this->extra_value, $val));
657 656
 					++$extra_filter;
658 657
 					unset($filter[$name]);
659 658
 				}
@@ -665,15 +664,14 @@  discard block
 block discarded – undo
665 664
 			if (is_array($only_keys))
666 665
 			{
667 666
 				$only_keys = array_values($only_keys);
668
-				$only_keys[0] = 'DISTINCT '.($only_keys[0] != $this->autoinc_id ? $only_keys[0] :
669
-					$this->table_name.'.'.$this->autoinc_id.' AS '.$this->autoinc_id);
667
+				$only_keys[0] = 'DISTINCT '.($only_keys[0] != $this->autoinc_id ? $only_keys[0] : $this->table_name.'.'.$this->autoinc_id.' AS '.$this->autoinc_id);
670 668
 			}
671 669
 			else
672 670
 			{
673 671
 				$only_keys = 'DISTINCT '.$only_keys;
674 672
 			}
675 673
 		}
676
-		return parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count);
674
+		return parent::search($criteria, $only_keys, $order_by, $extra_cols, $wildcard, $empty, $op, $start, $filter, $join, $need_full_no_count);
677 675
 	}
678 676
 
679 677
 	/**
@@ -713,7 +711,7 @@  discard block
 block discarded – undo
713 711
 	 */
714 712
 	function get_cf_name($field)
715 713
 	{
716
-		return substr($field,1);
714
+		return substr($field, 1);
717 715
 	}
718 716
 
719 717
 	/**
@@ -735,7 +733,7 @@  discard block
 block discarded – undo
735 733
 	 */
736 734
 	function is_multiple($name)
737 735
 	{
738
-		return $this->allow_multiple_values && in_array($this->customfields[$name]['type'],array('select','select-account')) &&
736
+		return $this->allow_multiple_values && in_array($this->customfields[$name]['type'], array('select', 'select-account')) &&
739 737
 			$this->customfields[$name]['rows'] > 1;
740 738
 	}
741 739
 
Please login to merge, or discard this patch.
Braces   +64 added lines, -15 removed lines patch added patch discarded remove patch
@@ -127,7 +127,11 @@  discard block
 block discarded – undo
127 127
 
128 128
 		$this->allow_multiple_values = $allow_multiple_values;
129 129
 		$this->extra_table = $extra_table;
130
-		if (!$this->extra_id) $this->extra_id = $this->autoinc_id;	// default to auto id of regular table
130
+		if (!$this->extra_id)
131
+		{
132
+			$this->extra_id = $this->autoinc_id;
133
+		}
134
+		// default to auto id of regular table
131 135
 
132 136
 		// if names from columns of extra table are only postfixes (starting with _), prepend column prefix
133 137
 		if (!($prefix=$column_prefix))
@@ -145,7 +149,10 @@  discard block
 block discarded – undo
145 149
 		) as $col => $val)
146 150
 		{
147 151
 			$this->$col = $col_name = $val;
148
-			if ($col_name[0] == '_') $this->$col = $prefix . $val;
152
+			if ($col_name[0] == '_')
153
+			{
154
+				$this->$col = $prefix . $val;
155
+			}
149 156
 		}
150 157
 		// some sanity checks, maybe they should be active only for development
151 158
 		if (!($extra_defs = $this->db->get_table_definitions($app,$extra_table)))
@@ -179,13 +186,23 @@  discard block
 block discarded – undo
179 186
 	 */
180 187
 	function read_customfields($ids,$field_names=null)
181 188
 	{
182
-		if (is_null($field_names)) $field_names = array_keys($this->customfields);
189
+		if (is_null($field_names))
190
+		{
191
+			$field_names = array_keys($this->customfields);
192
+		}
183 193
 
184 194
 		foreach((array)$ids as $key => $id)
185 195
 		{
186
-			if (!(int)$id && is_array($ids)) unset($ids[$key]);
196
+			if (!(int)$id && is_array($ids))
197
+			{
198
+				unset($ids[$key]);
199
+			}
187 200
 		}
188
-		if (!$ids || !$field_names) return array();	// nothing to do
201
+		if (!$ids || !$field_names)
202
+		{
203
+			return array();
204
+		}
205
+		// nothing to do
189 206
 
190 207
 		$entries = array();
191 208
 		foreach($this->db->select($this->extra_table,'*',array(
@@ -194,7 +211,10 @@  discard block
 block discarded – undo
194 211
 		),__LINE__,__FILE__,false,'',$this->app) as $row)
195 212
 		{
196 213
 			$entry =& $entries[$row[$this->extra_id]];
197
-			if (!is_array($entry)) $entry = array();
214
+			if (!is_array($entry))
215
+			{
216
+				$entry = array();
217
+			}
198 218
 			$field = $this->get_cf_field($row[$this->extra_key]);
199 219
 
200 220
 			if ($this->allow_multiple_values && $this->is_multiple($row[$this->extra_key]))
@@ -220,7 +240,10 @@  discard block
 block discarded – undo
220 240
 	{
221 241
 		foreach (array_keys((array)$this->customfields) as $name)
222 242
 		{
223
-			if (!isset($data[$field = $this->get_cf_field($name)])) continue;
243
+			if (!isset($data[$field = $this->get_cf_field($name)]))
244
+			{
245
+				continue;
246
+			}
224 247
 
225 248
 			$where = array(
226 249
 				$this->extra_id    => isset($data[$this->autoinc_id]) ? $data[$this->autoinc_id] : $data[$this->db_key_cols[$this->autoinc_id]],
@@ -232,7 +255,11 @@  discard block
 block discarded – undo
232 255
 			if(empty($data[$field]) || $is_multiple || !$this->extra_has_unique_index)
233 256
 			{
234 257
 				$this->db->delete($this->extra_table,$where,__LINE__,__FILE__,$this->app);
235
-				if (empty($data[$field])) continue;	// nothing else to do for empty values
258
+				if (empty($data[$field]))
259
+				{
260
+					continue;
261
+				}
262
+				// nothing else to do for empty values
236 263
 			}
237 264
 			foreach($is_multiple && !is_array($data[$field]) ? explode(',',$data[$field]) :
238 265
 				// regular custom fields (!$is_multiple) eg. addressbook store multiple values comma-separated
@@ -305,9 +332,12 @@  discard block
 block discarded – undo
305 332
 	 */
306 333
 	function save($keys=null,$extra_where=null)
307 334
 	{
308
-		if (is_array($keys) && count($keys) && !isset($keys[0]))	// allow to use an etag, eg array('etag=etag+1')
335
+		if (is_array($keys) && count($keys) && !isset($keys[0]))
336
+		{
337
+			// allow to use an etag, eg array('etag=etag+1')
309 338
 		{
310 339
 			$this->data_merge($keys);
340
+		}
311 341
 			$keys = null;
312 342
 		}
313 343
 		$ret = parent::save($keys,$extra_where);
@@ -340,13 +370,20 @@  discard block
 block discarded – undo
340 370
 				{
341 371
 					$ids[] = $row[$this->autoinc_id];
342 372
 				}
343
-				if (!$ids) return 0;	// no rows affected
373
+				if (!$ids)
374
+				{
375
+					return 0;
376
+				}
377
+				// no rows affected
344 378
 			}
345 379
 			else
346 380
 			{
347 381
 				$ids = (array)$query[$this->autoinc_id];
348 382
 			}
349
-			if ($only_return_ids) return $ids;
383
+			if ($only_return_ids)
384
+			{
385
+				return $ids;
386
+			}
350 387
 			$this->db->delete($this->extra_table,array($this->extra_id => $ids),__LINE__,__FILE__);
351 388
 		}
352 389
 		return parent::delete($keys);
@@ -388,7 +425,10 @@  discard block
 block discarded – undo
388 425
 			{
389 426
 				foreach($selectcols as $col)
390 427
 				{
391
-					if ($this->is_cf($col)) $fields[] = $this->get_cf_name($col);
428
+					if ($this->is_cf($col))
429
+					{
430
+						$fields[] = $this->get_cf_name($col);
431
+					}
392 432
 				}
393 433
 			}
394 434
 			if (($cfs = $this->read_customfields(array_keys($id2keys),$fields)))
@@ -507,7 +547,10 @@  discard block
 block discarded – undo
507 547
 					}
508 548
 				}
509 549
 			}
510
-			if ($cfcriteria && $op =='OR') $criteria[] = implode(' OR ',$cfcriteria);
550
+			if ($cfcriteria && $op =='OR')
551
+			{
552
+				$criteria[] = implode(' OR ',$cfcriteria);
553
+			}
511 554
 		}
512 555
 		if($only_keys === true)
513 556
 		{
@@ -598,11 +641,14 @@  discard block
 block discarded – undo
598 641
 				}
599 642
 				elseif (is_string($name) && $this->is_cf($name))
600 643
 				{
601
-					if (!empty($val))	// empty -> dont filter
644
+					if (!empty($val))
645
+					{
646
+						// empty -> dont filter
602 647
 					{
603 648
 						if ($val[0] === '!')	// negative filter
604 649
 						{
605 650
 							$sql_filter = 'extra_filter.'.$this->extra_value.'!='.$this->db->quote(substr($val,1));
651
+					}
606 652
 						}
607 653
 						else	// using Db::expression to allow to use array() with possible values or NULL
608 654
 						{
@@ -639,9 +685,12 @@  discard block
 block discarded – undo
639 685
 					}
640 686
 					unset($filter[$name]);
641 687
 				}
642
-				elseif(is_int($name) && $this->is_cf($val))	// lettersearch: #cfname LIKE 's%'
688
+				elseif(is_int($name) && $this->is_cf($val))
689
+				{
690
+					// lettersearch: #cfname LIKE 's%'
643 691
 				{
644 692
 					$_cf = explode(' ',$val);
693
+				}
645 694
 					foreach($_cf as $cf_np)
646 695
 					{
647 696
 						// building cf_name by glueing parts together (, in case someone used whitespace in their custom field names)
Please login to merge, or discard this patch.
etemplate/inc/class.soetemplate.inc.php 4 patches
Doc Comments   +4 added lines, -5 removed lines patch added patch discarded remove patch
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 	 *
162 162
 	 * @param string $type type of the widget
163 163
 	 * @param string $name name of widget
164
-	 * @param array $attributes=null array with further attributes
164
+	 * @param array $attributes array with further attributes
165 165
 	 * @return array the cell
166 166
 	 */
167 167
 	static function empty_cell($type='label',$name='',$attributes=null)
@@ -685,7 +685,7 @@  discard block
 block discarded – undo
685 685
 	 * Calls it self recursivly for arrays / the rows
686 686
 	 *
687 687
 	 * @param array $arr the array to compress
688
-	 * @param boolean $remove_all_objs if true unset all objs, on false use as_array to save only the data of objs
688
+	 * @param boolean $remove_objs if true unset all objs, on false use as_array to save only the data of objs
689 689
 	 * @return array
690 690
 	 */
691 691
 	function compress_array($arr,$remove_objs=false)
@@ -1102,9 +1102,8 @@  discard block
 block discarded – undo
1102 1102
 	 *
1103 1103
 	 * Please note: as call_user_func_array does not return references, methods ($func is an array) can not either!!!
1104 1104
 	 *
1105
-	 * @param string/array $func function to use or array($obj,'method')
1105
+	 * @param callable $func function to use or array($obj,'method')
1106 1106
 	 * @param mixed &$extra extra parameter passed to function
1107
-	 * @param string $path='/' start-path
1108 1107
 	 * @return mixed return-value of func or null if nothing returned at all
1109 1108
 	 */
1110 1109
 	function &widget_tree_walk($func,&$extra,$path='/')
@@ -1146,7 +1145,7 @@  discard block
 block discarded – undo
1146 1145
 	 * a further widget with children.
1147 1146
 	 *
1148 1147
 	 * @param array $widget the widget(-tree) the function should be applied too
1149
-	 * @param string/array $func function to use or array($obj,'method')
1148
+	 * @param callable $func function to use or array($obj,'method')
1150 1149
 	 * @param mixed &$extra extra parameter passed to function
1151 1150
 	 * @param string $path path of widget in the widget-tree
1152 1151
 	 * @return mixed return-value of func or null if nothing returned at all
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@
 block discarded – undo
33 33
 	 * while it uses select-account for owner in historylog (containing all users).
34 34
 	 *
35 35
 	 * @param string $cname
36
-	*/
36
+	 */
37 37
 	public function beforeSendToClient($cname)
38 38
 	{
39 39
 		$form_name = self::form_name($cname, $this->id);
Please login to merge, or discard this patch.
Spacing   +138 added lines, -139 removed lines patch added patch discarded remove patch
@@ -30,16 +30,16 @@  discard block
 block discarded – undo
30 30
  */
31 31
 class soetemplate
32 32
 {
33
-	public $debug;		// =1 show some debug-messages, = 'app.name' show messages only for eTemplate 'app.name'
34
-	public $name;		// name of the template, e.g. 'infolog.edit'
35
-	public $template;	// '' = default (not 'default')
36
-	public $lang;		// '' if general template else language short, e.g. 'de'
37
-	public $group;		// 0 = not specific else groupId or if < 0  userId
38
-	public $version;	// like 0.9.13.001
39
-	public $style;		// embeded CSS style-sheet
40
-	public $children;	// array with children
41
-	public $data;		// depricated: first grid of the children
42
-	public $size;		// depricated: witdh,height,border of first grid
33
+	public $debug; // =1 show some debug-messages, = 'app.name' show messages only for eTemplate 'app.name'
34
+	public $name; // name of the template, e.g. 'infolog.edit'
35
+	public $template; // '' = default (not 'default')
36
+	public $lang; // '' if general template else language short, e.g. 'de'
37
+	public $group; // 0 = not specific else groupId or if < 0  userId
38
+	public $version; // like 0.9.13.001
39
+	public $style; // embeded CSS style-sheet
40
+	public $children; // array with children
41
+	public $data; // depricated: first grid of the children
42
+	public $size; // depricated: witdh,height,border of first grid
43 43
 	/**
44 44
 	 * private reference to the global db-object
45 45
 	 *
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 	 * @param int $cols initial size of the template, default 1, only used if no name given !!!
96 96
 	 * @return soetemplate
97 97
 	 */
98
-	function __construct($name='',$template='',$lang='',$group=0,$version='',$rows=1,$cols=1)
98
+	function __construct($name = '', $template = '', $lang = '', $group = 0, $version = '', $rows = 1, $cols = 1)
99 99
 	{
100 100
 		if (isset($GLOBALS['egw']->db))
101 101
 		{
@@ -107,11 +107,11 @@  discard block
 block discarded – undo
107 107
 		}
108 108
 		if (empty($name))
109 109
 		{
110
-			$this->init($name,$template,$lang,$group,$version,$rows,$cols);
110
+			$this->init($name, $template, $lang, $group, $version, $rows, $cols);
111 111
 		}
112 112
 		else
113 113
 		{
114
-			$this->read($name,$template,$lang,$group,$version);
114
+			$this->read($name, $template, $lang, $group, $version);
115 115
 		}
116 116
 	}
117 117
 
@@ -145,11 +145,11 @@  discard block
 block discarded – undo
145 145
 		$min = ord('A');
146 146
 		$max = ord('Z') - $min + 1;
147 147
 
148
-		$num = 1+ord($chrs{0})-$min;
148
+		$num = 1 + ord($chrs{0}) - $min;
149 149
 		if (strlen($chrs) > 1)
150 150
 		{
151 151
 			$num *= 1 + $max - $min;
152
-			$num += 1+ord($chrs{1})-$min;
152
+			$num += 1 + ord($chrs{1}) - $min;
153 153
 		}
154 154
 		return $num;
155 155
 	}
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 	 * @param array $attributes=null array with further attributes
165 165
 	 * @return array the cell
166 166
 	 */
167
-	static function empty_cell($type='label',$name='',$attributes=null)
167
+	static function empty_cell($type = 'label', $name = '', $attributes = null)
168 168
 	{
169 169
 		$cell = array(
170 170
 			'type' => $type,
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 	 * @param array $attributes other attributes for the cell
189 189
 	 * @return array a reference to the new cell, use $new_cell = &$tpl->new_cell(); (!)
190 190
 	*/
191
-	function &new_cell($row=False,$type='label',$label='',$name='',$attributes=False)
191
+	function &new_cell($row = False, $type = 'label', $label = '', $name = '', $attributes = False)
192 192
 	{
193 193
 		$row = $row >= 0 ? intval($row) : 0;
194 194
 		if ($row && !isset($this->data[$row]) || !isset($this->data[1]))	// new row ?
@@ -208,14 +208,14 @@  discard block
 block discarded – undo
208 208
 		$row = &$this->data[$row];
209 209
 		$col = $this->num2chrs(count($row));
210 210
 		$cell = &$row[$col];
211
-		$cell = $this->empty_cell($type,$name);
211
+		$cell = $this->empty_cell($type, $name);
212 212
 		if ($label !== '')
213 213
 		{
214 214
 			$attributes['label'] = $label;
215 215
 		}
216 216
 		if (is_array($attributes))
217 217
 		{
218
-			foreach($attributes as $name => $value)
218
+			foreach ($attributes as $name => $value)
219 219
 			{
220 220
 				$cell[$name] = $value;
221 221
 			}
@@ -229,14 +229,14 @@  discard block
 block discarded – undo
229 229
 	 * @param array &$parent referenc to the parent
230 230
 	 * @param array &$cell cell to add (need to be unset after the call to add_child, as it's a referenc !)
231 231
 	 */
232
-	static function add_child(&$parent,&$cell)
232
+	static function add_child(&$parent, &$cell)
233 233
 	{
234 234
 		if (is_object($parent))	// parent is the template itself
235 235
 		{
236 236
 			$parent->children[] = &$cell;
237 237
 			return;
238 238
 		}
239
-		switch($parent['type'])
239
+		switch ($parent['type'])
240 240
 		{
241 241
 			case 'vbox':
242 242
 			case 'hbox':
@@ -244,9 +244,9 @@  discard block
 block discarded – undo
244 244
 			case 'box':
245 245
 			case 'deck':
246 246
 			default:
247
-				list($n,$options) = explode(',',$parent['size'],2);
247
+				list($n, $options) = explode(',', $parent['size'], 2);
248 248
 				$parent[++$n] = &$cell;
249
-				$parent['size'] = $n . ($options ? ','.$options : '');
249
+				$parent['size'] = $n.($options ? ','.$options : '');
250 250
 				break;
251 251
 
252 252
 			case 'grid':
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
 				if (is_array($cell))	// real cell to add
264 264
 				{
265 265
 					$row[soetemplate::num2chrs($col++)] = &$cell;
266
-					list($spanned) = explode(',',$cell['span']);
266
+					list($spanned) = explode(',', $cell['span']);
267 267
 					$spanned = $spanned == 'all' ? 1 + $cols - $col : $spanned;
268 268
 					while (--$spanned > 0)
269 269
 					{
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 	{
285 285
 		$grid['rows'] = count($grid['data']) - 1;
286 286
 		$grid['cols'] = 0;
287
-		for($r = 1; $r <= $grid['rows']; ++$r)
287
+		for ($r = 1; $r <= $grid['rows']; ++$r)
288 288
 		{
289 289
 			$cols = count($grid['data'][$r]);
290 290
 			if ($grid['cols'] < $cols)
@@ -326,14 +326,14 @@  discard block
 block discarded – undo
326 326
 	 * @param int $rows initial size of the template, default 1
327 327
 	 * @param int $cols initial size of the template, default 1
328 328
 	 */
329
-	function init($name='',$template='',$lang='',$group=0,$version='',$rows=1,$cols=1)
329
+	function init($name = '', $template = '', $lang = '', $group = 0, $version = '', $rows = 1, $cols = 1)
330 330
 	{
331 331
 		// unset children and data as they are referenzes to each other
332 332
 		unset($this->children); unset($this->data);
333 333
 
334
-		foreach(self::$db_cols as $db_col => $col)
334
+		foreach (self::$db_cols as $db_col => $col)
335 335
 		{
336
-			if ($col != 'data') $this->$col = is_array($name) ? (string) $name[$col] : $$col;
336
+			if ($col != 'data') $this->$col = is_array($name) ? (string)$name[$col] : $$col;
337 337
 		}
338 338
 		if ($this->template == 'default')
339 339
 		{
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
 
348 348
 		if (is_array($name) && $name['onclick_handler']) $this->onclick_handler = $name['onclick_handler'];
349 349
 
350
-		if (is_array($name)  && isset($name['data']))
350
+		if (is_array($name) && isset($name['data']))
351 351
 		{
352 352
 			// data/children are in $name['data']
353 353
 			$this->children = is_array($name['data']) ? $name['data'] : unserialize($name['data']);
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
 			{
365 365
 				for ($col = 0; $col < $cols; ++$col)
366 366
 				{
367
-					if (!is_array($this->data[$row])) $this->data[$row]=array();
367
+					if (!is_array($this->data[$row])) $this->data[$row] = array();
368 368
 					$this->data[$row][$this->num2chrs($col)] = $this->empty_cell();
369 369
 				}
370 370
 			}
@@ -388,9 +388,9 @@  discard block
 block discarded – undo
388 388
 	 * @param string $version version of the eTemplate
389 389
 	 * @return boolean True if a fitting template is found, else False
390 390
 	 */
391
-	function read($name,$template='default',$lang='default',$group=0,$version='')
391
+	function read($name, $template = 'default', $lang = 'default', $group = 0, $version = '')
392 392
 	{
393
-		$this->init($name,$template,$lang,$group,$version);
393
+		$this->init($name, $template, $lang, $group, $version);
394 394
 		if ($this->debug == 1 || $this->debug == $this->name)
395 395
 		{
396 396
 			echo "<p>soetemplate::read('$this->name','$this->template','$this->lang',$this->group,'$this->version')</p>\n";
@@ -434,7 +434,7 @@  discard block
 block discarded – undo
434 434
 		{
435 435
 			$where['et_version'] = $this->version;
436 436
 		}
437
-		if (!($row = $this->db->select(self::TABLE,'*',$where,__LINE__,__FILE__,false,'ORDER BY et_lang DESC,et_template DESC,et_version DESC','etemplate',1)->fetch()))
437
+		if (!($row = $this->db->select(self::TABLE, '*', $where, __LINE__, __FILE__, false, 'ORDER BY et_lang DESC,et_template DESC,et_version DESC', 'etemplate', 1)->fetch()))
438 438
 		{
439 439
 			$version = $this->version;
440 440
 			return $this->readfile() && (empty($version) || $version == $this->version);
@@ -455,19 +455,19 @@  discard block
 block discarded – undo
455 455
 	 */
456 456
 	function readfile()
457 457
 	{
458
-		list($app,$name) = explode('.',$this->name,2);
458
+		list($app, $name) = explode('.', $this->name, 2);
459 459
 		$template = $this->template == '' ? 'default' : $this->template;
460 460
 
461 461
 		if ($this->lang)
462 462
 		{
463
-			$lang = '.' . $this->lang;
463
+			$lang = '.'.$this->lang;
464 464
 		}
465 465
 		$first_try = $ext = $GLOBALS['egw_info']['server']['eTemplate-source'] == 'xslt' ? '.xsl' : '.xet';
466 466
 
467
-		while ((!$lang || !@file_exists($file = EGW_SERVER_ROOT . "/$app/templates/$template/$name$lang$ext") &&
468
-											!@file_exists($file = EGW_SERVER_ROOT . "/$app/templates/default/$name$lang$ext")) &&
469
-						!@file_exists($file = EGW_SERVER_ROOT . "/$app/templates/$template/$name$ext") &&
470
-						!@file_exists($file = EGW_SERVER_ROOT . "/$app/templates/default/$name$ext"))
467
+		while ((!$lang || !@file_exists($file = EGW_SERVER_ROOT."/$app/templates/$template/$name$lang$ext") &&
468
+											!@file_exists($file = EGW_SERVER_ROOT."/$app/templates/default/$name$lang$ext")) &&
469
+						!@file_exists($file = EGW_SERVER_ROOT."/$app/templates/$template/$name$ext") &&
470
+						!@file_exists($file = EGW_SERVER_ROOT."/$app/templates/default/$name$ext"))
471 471
 		{
472 472
 			if ($ext == $first_try)
473 473
 			{
@@ -483,7 +483,7 @@  discard block
 block discarded – undo
483 483
 				break;
484 484
 			}
485 485
 		}
486
-		if ($this->name == '' || $app == '' || $name == '' || !@file_exists($file) || !($f = @fopen($file,'r')))
486
+		if ($this->name == '' || $app == '' || $name == '' || !@file_exists($file) || !($f = @fopen($file, 'r')))
487 487
 		{
488 488
 			if ($this->debug == 1 || $this->name != '' && $this->debug == $this->name)
489 489
 			{
@@ -491,7 +491,7 @@  discard block
 block discarded – undo
491 491
 			}
492 492
 			return False;
493 493
 		}
494
-		$xml = fread ($f, filesize ($file));
494
+		$xml = fread($f, filesize($file));
495 495
 		fclose($f);
496 496
 
497 497
 		if ($ext == '.xsl')
@@ -501,22 +501,22 @@  discard block
 block discarded – undo
501 501
 			$cell['size'] = $this->name;
502 502
 			//$cell['xslt'] = &$xml;	xslttemplate class cant use it direct at the moment
503 503
 			$cell['name'] = '';
504
-			$this->data = array(0 => array(),1 => array('A' => &$cell));
504
+			$this->data = array(0 => array(), 1 => array('A' => &$cell));
505 505
 			$this->rows = $this->cols = 1;
506 506
 		}
507 507
 		else
508 508
 		{
509 509
 			if (!is_object($this->xul_io))
510 510
 			{
511
-				$this->xul_io =& CreateObject('etemplate.xul_io');
511
+				$this->xul_io = & CreateObject('etemplate.xul_io');
512 512
 			}
513
-			$loaded = $this->xul_io->import($this,$xml);
513
+			$loaded = $this->xul_io->import($this, $xml);
514 514
 
515 515
 			if (!is_array($loaded))
516 516
 			{
517 517
 				return False;
518 518
 			}
519
-			$this->name = $app . '.' . $name;	// if template was copied or app was renamed
519
+			$this->name = $app.'.'.$name; // if template was copied or app was renamed
520 520
 
521 521
 			$this->tpls_in_file = count($loaded);
522 522
 		}
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
 	 */
532 532
 	static function sql_wildcards($pattern)
533 533
 	{
534
-		return str_replace(array('%','_','*','?'),array('\\%','\\_','%','_'),$pattern);
534
+		return str_replace(array('%', '_', '*', '?'), array('\\%', '\\_', '%', '_'), $pattern);
535 535
 	}
536 536
 
537 537
 	/**
@@ -544,19 +544,19 @@  discard block
 block discarded – undo
544 544
 	 * @param string $version version of the eTemplate
545 545
 	 * @return array of arrays with the template-params
546 546
 	 */
547
-	function search($name,$template='default',$lang='default',$group=0,$version='')
547
+	function search($name, $template = 'default', $lang = 'default', $group = 0, $version = '')
548 548
 	{
549 549
 		if ($this->name)
550 550
 		{
551
-			boetemplate::test_import($this->name);	// import updates in setup-dir
551
+			boetemplate::test_import($this->name); // import updates in setup-dir
552 552
 		}
553 553
 		if (is_array($name))
554 554
 		{
555
-			$template = (string) $name['template'];
556
-			$lang     = (string) $name['lang'];
557
-			$group    = (int) $name['group'];
558
-			$version  = (string) $name['version'];
559
-			$name     = (string) $name['name'];
555
+			$template = (string)$name['template'];
556
+			$lang     = (string)$name['lang'];
557
+			$group    = (int)$name['group'];
558
+			$version  = (string)$name['version'];
559
+			$name     = (string)$name['name'];
560 560
 		}
561 561
 		$where = array();
562 562
 		$where[] = 'et_name LIKE '.$this->db->quote($this->sql_wildcards($name).'%');
@@ -573,11 +573,11 @@  discard block
 block discarded – undo
573 573
 			$where[] = 'et_version LIKE '.$this->db->quote($this->sql_wildcards($version).'%');
574 574
 		}
575 575
 		$result = array();
576
-		foreach($this->db->select(self::TABLE,'et_name,et_template,et_lang,et_group,et_version',$where,__LINE__,__FILE__,false,'ORDER BY et_name DESC,et_lang DESC,et_template DESC,et_version DESC','etemplate') as $row)
576
+		foreach ($this->db->select(self::TABLE, 'et_name,et_template,et_lang,et_group,et_version', $where, __LINE__, __FILE__, false, 'ORDER BY et_name DESC,et_lang DESC,et_template DESC,et_version DESC', 'etemplate') as $row)
577 577
 		{
578 578
 			if ($row['et_lang'] != '##')	// exclude or import-time-stamps
579 579
 			{
580
-				$result[] = egw_db::strip_array_keys($row,'et_');
580
+				$result[] = egw_db::strip_array_keys($row, 'et_');
581 581
 			}
582 582
 		}
583 583
 		if ($this->debug)
@@ -632,9 +632,9 @@  discard block
 block discarded – undo
632 632
 			if ($this->name[0] != '.' && is_array($this->data))
633 633
 			{
634 634
 				reset($this->data); each($this->data);
635
-				while (list($row,$cols) = each($this->data))
635
+				while (list($row, $cols) = each($this->data))
636 636
 				{
637
-					while (list($col,$cell) = each($cols))
637
+					while (list($col, $cell) = each($cols))
638 638
 					{
639 639
 						if (is_array($cell['type']))
640 640
 						{
@@ -654,7 +654,7 @@  discard block
 block discarded – undo
654 654
 		{
655 655
 			unset($this->data);
656 656
 			// for the moment we make $this->data as a referenz to the first grid
657
-			foreach($this->children as $key => $child)
657
+			foreach ($this->children as $key => $child)
658 658
 			{
659 659
 				if ($child['type'] == 'grid')
660 660
 				{
@@ -688,7 +688,7 @@  discard block
 block discarded – undo
688 688
 	 * @param boolean $remove_all_objs if true unset all objs, on false use as_array to save only the data of objs
689 689
 	 * @return array
690 690
 	 */
691
-	function compress_array($arr,$remove_objs=false)
691
+	function compress_array($arr, $remove_objs = false)
692 692
 	{
693 693
 		static $recursion = array();
694 694
 
@@ -696,7 +696,7 @@  discard block
 block discarded – undo
696 696
 		{
697 697
 			return $arr;
698 698
 		}
699
-		foreach($arr as $key => $val)
699
+		foreach ($arr as $key => $val)
700 700
 		{
701 701
 			if ($remove_objs && $key === 'obj')	// it can be an array too
702 702
 			{
@@ -704,9 +704,9 @@  discard block
 block discarded – undo
704 704
 			}
705 705
 			elseif (is_array($val))
706 706
 			{
707
-				$arr[$key] = $this->compress_array($val,$remove_objs);
707
+				$arr[$key] = $this->compress_array($val, $remove_objs);
708 708
 			}
709
-			elseif (!$remove_objs && $key == 'obj' && is_object($val) && method_exists($val,'as_array') &&
709
+			elseif (!$remove_objs && $key == 'obj' && is_object($val) && method_exists($val, 'as_array') &&
710 710
 				// this test prevents an infinit recursion of templates calling itself, atm. etemplate.editor.new
711 711
 				self::$compress_array_recursion[$this->name]++ < 2)
712 712
 			{
@@ -730,11 +730,11 @@  discard block
 block discarded – undo
730 730
 	 * @param boolean $db_keys use db-column-names or internal names, default false=internal names
731 731
 	 * @return array with template-data
732 732
 	 */
733
-	function as_array($data_too=0,$db_keys=false)
733
+	function as_array($data_too = 0, $db_keys = false)
734 734
 	{
735 735
 		//echo "<p>soetemplate::as_array($data_too,$db_keys) name='$this->name', ver='$this->version'</p>\n";
736 736
 		$arr = array();
737
-		switch($data_too)
737
+		switch ($data_too)
738 738
 		{
739 739
 			case -1:
740 740
 				$cols = self::$db_key_cols;
@@ -745,14 +745,13 @@  discard block
 block discarded – undo
745 745
 			default:
746 746
 				$cols = self::$db_cols;
747 747
 		}
748
-		foreach($cols as $db_col => $col)
748
+		foreach ($cols as $db_col => $col)
749 749
 		{
750 750
 			if ($col == 'data')
751 751
 			{
752 752
 				if ($data_too > 0)
753 753
 				{
754
-					$arr[$db_keys ? $db_col : $col] = $data_too < 2 ? $this->children :
755
-						serialize($this->compress_array($this->children,$db_keys));
754
+					$arr[$db_keys ? $db_col : $col] = $data_too < 2 ? $this->children : serialize($this->compress_array($this->children, $db_keys));
756 755
 				}
757 756
 			}
758 757
 			else
@@ -781,7 +780,7 @@  discard block
 block discarded – undo
781 780
 	 * @param string $version version of the eTemplate
782 781
 	 * @return int number of affected rows, 1 should be ok, 0 somethings wrong
783 782
 	 */
784
-	function save($name='',$template='.',$lang='.',$group='',$version='.')
783
+	function save($name = '', $template = '.', $lang = '.', $group = '', $version = '.')
785 784
 	{
786 785
 		if (is_array($name))
787 786
 		{
@@ -822,9 +821,9 @@  discard block
 block discarded – undo
822 821
 		if ($this->name[0] != '.' && is_array($this->data))		// correct old messed up templates
823 822
 		{
824 823
 			reset($this->data); each($this->data);
825
-			while (list($row,$cols) = each($this->data))
824
+			while (list($row, $cols) = each($this->data))
826 825
 			{
827
-				while (list($col,$cell) = each($cols))
826
+				while (list($col, $cell) = each($cols))
828 827
 				{
829 828
 					if (is_array($cell['type'])) {
830 829
 						$this->data[$row][$col]['type'] = $cell['type'][0];
@@ -843,7 +842,7 @@  discard block
 block discarded – undo
843 842
 		}
844 843
 		if (is_null($this->group) || !is_int($this->group)) $this->group = 0;
845 844
 
846
-		$this->db->insert(self::TABLE,$this->as_array(3,true),$this->as_array(-1,true),__LINE__,__FILE__,'etemplate');
845
+		$this->db->insert(self::TABLE, $this->as_array(3, true), $this->as_array(-1, true), __LINE__, __FILE__, 'etemplate');
847 846
 
848 847
 		if (!($rows = $this->db->affected_rows()))
849 848
 		{
@@ -859,7 +858,7 @@  discard block
 block discarded – undo
859 858
 	 */
860 859
 	function delete()
861 860
 	{
862
-		$this->db->delete(self::TABLE,$this->as_array(-1,true),__LINE__,__FILE__,'etemplate');
861
+		$this->db->delete(self::TABLE, $this->as_array(-1, true), __LINE__, __FILE__, 'etemplate');
863 862
 
864 863
 		return $this->db->affected_rows();
865 864
 	}
@@ -872,9 +871,9 @@  discard block
 block discarded – undo
872 871
 	 */
873 872
 	function dump4setup($app)
874 873
 	{
875
-		list($app) = explode('.',$app);
874
+		list($app) = explode('.', $app);
876 875
 
877
-		$dir = EGW_SERVER_ROOT . "/$app/setup";
876
+		$dir = EGW_SERVER_ROOT."/$app/setup";
878 877
 		if (!is_writeable($dir))
879 878
 		{
880 879
 			// if dir is not writable, download file
@@ -891,32 +890,32 @@  discard block
 block discarded – undo
891 890
 				{
892 891
 					unlink($old_file);
893 892
 				}
894
-				rename($file,$old_file);
893
+				rename($file, $old_file);
895 894
 			}
896 895
 		}
897
-		if (!($f = fopen($file,'w')))
896
+		if (!($f = fopen($file, 'w')))
898 897
 		{
899 898
 			return 0;
900 899
 		}
901
-		fwrite($f,'<?php
900
+		fwrite($f, '<?php
902 901
 /**
903
- * EGroupware - eTemplates for Application '. $app. '
902
+ * EGroupware - eTemplates for Application '. $app.'
904 903
  * http://www.egroupware.org
905
- * generated by soetemplate::dump4setup() '.date('Y-m-d H:i'). '
904
+ * generated by soetemplate::dump4setup() '.date('Y-m-d H:i').'
906 905
  *
907 906
  * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
908
- * @package '. $app. '
907
+ * @package '. $app.'
909 908
  * @subpackage setup
910 909
  * @version $Id'.'$
911 910
  */'."\n\n\$templ_version=1;\n\n");
912 911
 
913 912
 		$n = 0;
914 913
 		$exported = array();
915
-		foreach($this->db->select(self::TABLE,'*','et_name LIKE '.$this->db->quote($app.'.%'),__LINE__, __FILE__,false,'ORDER BY et_name,et_version DESC','etemplate',0,'',false,egw_db::FETCH_ASSOC) as $row)
914
+		foreach ($this->db->select(self::TABLE, '*', 'et_name LIKE '.$this->db->quote($app.'.%'), __LINE__, __FILE__, false, 'ORDER BY et_name,et_version DESC', 'etemplate', 0, '', false, egw_db::FETCH_ASSOC) as $row)
916 915
 		{
917 916
 			if (isset($exported[$row['et_name']]) && $exported[$row['et_name']] === (string)$row['et_template'])
918 917
 			{
919
-				continue;	// only export highest version (we sort by version DESC!)
918
+				continue; // only export highest version (we sort by version DESC!)
920 919
 			}
921 920
 			$exported[$row['et_name']] = (string)$row['et_template'];
922 921
 
@@ -928,17 +927,17 @@  discard block
 block discarded – undo
928 927
 					$row[$db_col] = preg_replace('/[ \t]+$/m', '', $row[$db_col]);
929 928
 				}
930 929
 				// escape only backslashes and single quotes (in that order)
931
-				$str .= "'$name' => '".str_replace(array('\\','\'',"\r"),array('\\\\','\\\'',''),$row[$db_col])."',";
930
+				$str .= "'$name' => '".str_replace(array('\\', '\'', "\r"), array('\\\\', '\\\'', ''), $row[$db_col])."',";
932 931
 			}
933 932
 			$str .= ");\n\n";
934
-			fwrite($f,$str);
933
+			fwrite($f, $str);
935 934
 			++$n;
936 935
 		}
937 936
 		fclose($f);
938 937
 
939 938
 		if ($file == 'php://stdout') common::egw_exit();
940 939
 
941
-		return lang("%1 eTemplates for Application '%2' dumped to '%3'",$n,$app,$file);
940
+		return lang("%1 eTemplates for Application '%2' dumped to '%3'", $n, $app, $file);
942 941
 	}
943 942
 
944 943
 	/**
@@ -952,7 +951,7 @@  discard block
 block discarded – undo
952 951
 	{
953 952
 		$to_trans = array();
954 953
 
955
-		$this->widget_tree_walk(array('soetemplate','getToTranslateCell'),$to_trans);
954
+		$this->widget_tree_walk(array('soetemplate', 'getToTranslateCell'), $to_trans);
956 955
 
957 956
 		//echo '<b>'.$this->name.'</b>'; _debug_array($to_trans);
958 957
 		return $to_trans;
@@ -970,13 +969,13 @@  discard block
 block discarded – undo
970 969
 
971 970
 		$tpls = $this->search($app);
972 971
 
973
-		$tpl = new soetemplate;	// to not alter our own data
972
+		$tpl = new soetemplate; // to not alter our own data
974 973
 
975 974
 		while (list(,$keys) = each($tpls))
976 975
 		{
977
-			if (($keys['name'] != $last['name'] ||		// write only newest version
976
+			if (($keys['name'] != $last['name'] || // write only newest version
978 977
 					$keys['template'] != $last['template']) &&
979
-					(strpos($keys['name'],'test') === false || $app == 'test'))
978
+					(strpos($keys['name'], 'test') === false || $app == 'test'))
980 979
 			{
981 980
 				$tpl->read($keys);
982 981
 				$to_trans += $tpl->getToTranslate();
@@ -995,41 +994,41 @@  discard block
 block discarded – undo
995 994
 	 * 	select-options they get writen too (form is <unique key> => <message>)
996 995
 	 * @return string translated message with number of messages written (total and new), or error-message
997 996
 	 */
998
-	function writeLangFile($app,$lang='en',$additional='')
997
+	function writeLangFile($app, $lang = 'en', $additional = '')
999 998
 	{
1000 999
 		if (!$additional)
1001 1000
 		{
1002 1001
 			$additional = array();
1003 1002
 		}
1004
-		list($app) = explode('.',$app);
1003
+		list($app) = explode('.', $app);
1005 1004
 
1006 1005
 		if (!file_exists(EGW_SERVER_ROOT.'/developer_tools/inc/class.solangfile.inc.php'))
1007 1006
 		{
1008
-			$solangfile =& CreateObject('etemplate.solangfile');
1007
+			$solangfile = & CreateObject('etemplate.solangfile');
1009 1008
 		}
1010 1009
 		else
1011 1010
 		{
1012
-			$solangfile =& CreateObject('developer_tools.solangfile');
1011
+			$solangfile = & CreateObject('developer_tools.solangfile');
1013 1012
 		}
1014
-		$langarr = $solangfile->load_app($app,$lang);
1013
+		$langarr = $solangfile->load_app($app, $lang);
1015 1014
 		if (!is_array($langarr))
1016 1015
 		{
1017 1016
 			$langarr = array();
1018 1017
 		}
1019
-		$commonarr = $solangfile->load_app('phpgwapi',$lang) + $solangfile->load_app('etemplate',$lang);
1018
+		$commonarr = $solangfile->load_app('phpgwapi', $lang) + $solangfile->load_app('etemplate', $lang);
1020 1019
 
1021 1020
 		$to_trans = $this->getToTranslateApp($app);
1022 1021
 		if (is_array($additional))
1023 1022
 		{
1024 1023
 			//echo "writeLangFile: additional ="; _debug_array($additional);
1025
-			foreach($additional as $msg)
1024
+			foreach ($additional as $msg)
1026 1025
 			{
1027 1026
 				if (!is_array($msg)) $to_trans[trim(strtolower($msg))] = $msg;
1028 1027
 			}
1029 1028
 		}
1030 1029
 		unset($to_trans['']);
1031 1030
 
1032
-		for ($new = $n = 0; list($message_id,$content) = each($to_trans); ++$n)
1031
+		for ($new = $n = 0; list($message_id, $content) = each($to_trans); ++$n)
1033 1032
 		{
1034 1033
 			if (!isset($langarr[$message_id]) && !isset($commonarr[$message_id]))
1035 1034
 			{
@@ -1047,15 +1046,15 @@  discard block
 block discarded – undo
1047 1046
 		}
1048 1047
 		ksort($langarr);
1049 1048
 
1050
-		$dir = EGW_SERVER_ROOT . "/$app/lang";
1049
+		$dir = EGW_SERVER_ROOT."/$app/lang";
1051 1050
 		if (!is_writeable($dir))
1052 1051
 		{
1053
-			return lang("Error: webserver is not allowed to write into '%1' !!!",$dir);
1052
+			return lang("Error: webserver is not allowed to write into '%1' !!!", $dir);
1054 1053
 		}
1055
-		$solangfile->write_file($app,$langarr,$lang);
1056
-		$solangfile->loaddb($app,$lang);
1054
+		$solangfile->write_file($app, $langarr, $lang);
1055
+		$solangfile->loaddb($app, $lang);
1057 1056
 
1058
-		return lang("%1 (%2 new) Messages writen for Application '%3' and Languages '%4'",$n,$new,$app,$lang);
1057
+		return lang("%1 (%2 new) Messages writen for Application '%3' and Languages '%4'", $n, $new, $app, $lang);
1059 1058
 	}
1060 1059
 
1061 1060
 	/**
@@ -1064,15 +1063,15 @@  discard block
 block discarded – undo
1064 1063
 	 * @param boolean $backtrace = true give a function backtrace
1065 1064
 	 * @param boolean $no_other_objs = true dump other objs (db, html, ...) too
1066 1065
 	 */
1067
-	function echo_tmpl($backtrace=true,$no_other_objs=true)
1066
+	function echo_tmpl($backtrace = true, $no_other_objs = true)
1068 1067
 	{
1069
-		static $objs = array('db','html','xul_io');
1068
+		static $objs = array('db', 'html', 'xul_io');
1070 1069
 
1071 1070
 		if ($backtrace) echo "<p>".function_backtrace(1)."</p>\n";
1072 1071
 
1073 1072
 		if ($no_other_objs)
1074 1073
 		{
1075
-			foreach($objs as $obj)
1074
+			foreach ($objs as $obj)
1076 1075
 			{
1077 1076
 				$$obj = &$this->$obj;
1078 1077
 				unset($this->$obj);
@@ -1082,7 +1081,7 @@  discard block
 block discarded – undo
1082 1081
 
1083 1082
 		if ($no_other_objs)
1084 1083
 		{
1085
-			foreach($objs as $obj)
1084
+			foreach ($objs as $obj)
1086 1085
 			{
1087 1086
 				$this->$obj = &$$obj;
1088 1087
 				unset($$obj);
@@ -1107,27 +1106,27 @@  discard block
 block discarded – undo
1107 1106
 	 * @param string $path='/' start-path
1108 1107
 	 * @return mixed return-value of func or null if nothing returned at all
1109 1108
 	 */
1110
-	function &widget_tree_walk($func,&$extra,$path='/')
1109
+	function &widget_tree_walk($func, &$extra, $path = '/')
1111 1110
 	{
1112 1111
 		if (!is_callable($func))
1113 1112
 		{
1114
-			echo "<p><b>boetemplate($this->name)::widget_tree_walk</b>(".print_r($func,true).", ".print_r($extra,true).", ".print_r($opts,true).") func is not callable !!!<br>".function_backtrace()."</p>";
1113
+			echo "<p><b>boetemplate($this->name)::widget_tree_walk</b>(".print_r($func, true).", ".print_r($extra, true).", ".print_r($opts, true).") func is not callable !!!<br>".function_backtrace()."</p>";
1115 1114
 			return false;
1116 1115
 		}
1117
-		foreach($this->children as $c => &$child)
1116
+		foreach ($this->children as $c => &$child)
1118 1117
 		{
1119 1118
 			$child = &$this->children[$c];
1120 1119
 			if (isset(soetemplate::$widgets_with_children[$child['type']]))
1121 1120
 			{
1122
-				$result =& $this->tree_walk($child,$func,$extra,$path.$c);
1121
+				$result = & $this->tree_walk($child, $func, $extra, $path.$c);
1123 1122
 			}
1124 1123
 			elseif (is_array($func))
1125 1124
 			{
1126
-				$result =& call_user_func_array($func,array(&$child,&$extra,$path.$c));
1125
+				$result = & call_user_func_array($func, array(&$child, &$extra, $path.$c));
1127 1126
 			}
1128 1127
 			else
1129 1128
 			{
1130
-				$result =& $func($child,$extra,$path.$c);
1129
+				$result = & $func($child, $extra, $path.$c);
1131 1130
 			}
1132 1131
 			if (!is_null($result) || is_array($extra) && isset($extra['__RETURN_NOW__'])) break;
1133 1132
 		}
@@ -1151,27 +1150,27 @@  discard block
 block discarded – undo
1151 1150
 	 * @param string $path path of widget in the widget-tree
1152 1151
 	 * @return mixed return-value of func or null if nothing returned at all
1153 1152
 	 */
1154
-	function &tree_walk(&$widget,$func,&$extra,$path='')
1153
+	function &tree_walk(&$widget, $func, &$extra, $path = '')
1155 1154
 	{
1156 1155
 		if (!is_callable($func))
1157 1156
 		{
1158
-			echo "<p><b>boetemplate::tree_walk</b>(, ".print_r($func,true).", ".print_r($extra,true).", ".print_r($opts,true).") func is not callable !!!<br>".function_backtrace()."</p>";
1157
+			echo "<p><b>boetemplate::tree_walk</b>(, ".print_r($func, true).", ".print_r($extra, true).", ".print_r($opts, true).") func is not callable !!!<br>".function_backtrace()."</p>";
1159 1158
 			return false;
1160 1159
 		}
1161
-		if(is_array($func))
1160
+		if (is_array($func))
1162 1161
 		{
1163
-			$result =& call_user_func_array($func,array(&$widget,&$extra,$path));
1162
+			$result = & call_user_func_array($func, array(&$widget, &$extra, $path));
1164 1163
 		}
1165 1164
 		else
1166 1165
 		{
1167
-			$result =& $func($widget,$extra,$path);
1166
+			$result = & $func($widget, $extra, $path);
1168 1167
 		}
1169 1168
 		if (!is_null($result) || is_array($extra) && isset($extra['__RETURN__NOW__']) ||
1170 1169
 			!isset(soetemplate::$widgets_with_children[$widget['type']]))
1171 1170
 		{
1172 1171
 			return $result;
1173 1172
 		}
1174
-		switch($widget['type'])
1173
+		switch ($widget['type'])
1175 1174
 		{
1176 1175
 			case 'split':
1177 1176
 			case 'box':
@@ -1179,21 +1178,21 @@  discard block
 block discarded – undo
1179 1178
 			case 'hbox':
1180 1179
 			case 'groupbox':
1181 1180
 			case 'deck':
1182
-				for($n = 1; is_array($widget[$n]); ++$n)
1181
+				for ($n = 1; is_array($widget[$n]); ++$n)
1183 1182
 				{
1184 1183
 					$child = &$widget[$n];
1185 1184
 					$_path = $path.'/'.$n;
1186 1185
 					if (isset(soetemplate::$widgets_with_children[$child['type']]))
1187 1186
 					{
1188
-						$result =& $this->tree_walk($child,$func,$extra,$_path);
1187
+						$result = & $this->tree_walk($child, $func, $extra, $_path);
1189 1188
 					}
1190
-					elseif(is_array($func))
1189
+					elseif (is_array($func))
1191 1190
 					{
1192
-						$result =& call_user_func_array($func,array(&$child,&$extra,$_path));
1191
+						$result = & call_user_func_array($func, array(&$child, &$extra, $_path));
1193 1192
 					}
1194 1193
 					else
1195 1194
 					{
1196
-						$result =& $func($child,$extra,$_path);
1195
+						$result = & $func($child, $extra, $_path);
1197 1196
 					}
1198 1197
 					if (!is_null($result) || is_array($extra) && isset($extra['__RETURN__NOW__'])) return $result;
1199 1198
 				}
@@ -1201,27 +1200,27 @@  discard block
 block discarded – undo
1201 1200
 
1202 1201
 			case 'grid':
1203 1202
 				$data = &$widget['data'];
1204
-				if (!is_array($data)) break;	// no children
1203
+				if (!is_array($data)) break; // no children
1205 1204
 
1206
-				foreach($data as $r => $row)
1205
+				foreach ($data as $r => $row)
1207 1206
 				{
1208 1207
 					if (!$r || !is_array($row)) continue;
1209 1208
 
1210
-					foreach($row as $c => $col)
1209
+					foreach ($row as $c => $col)
1211 1210
 					{
1212 1211
 						$child = &$data[$r][$c];
1213 1212
 						$_path = $path.'/'.$r.$c;
1214 1213
 						if (isset(soetemplate::$widgets_with_children[$child['type']]))
1215 1214
 						{
1216
-							$result =& $this->tree_walk($child,$func,$extra,$_path);
1215
+							$result = & $this->tree_walk($child, $func, $extra, $_path);
1217 1216
 						}
1218
-						elseif(is_array($func))
1217
+						elseif (is_array($func))
1219 1218
 						{
1220
-							$result =& call_user_func_array($func,array(&$child,&$extra,$_path));
1219
+							$result = & call_user_func_array($func, array(&$child, &$extra, $_path));
1221 1220
 						}
1222 1221
 						else
1223 1222
 						{
1224
-							$result =& $func($child,$extra,$_path);
1223
+							$result = & $func($child, $extra, $_path);
1225 1224
 						}
1226 1225
 						if (!is_null($result) || is_array($extra) && isset($extra['__RETURN__NOW__'])) return $result;
1227 1226
 						unset($child);
@@ -1235,9 +1234,9 @@  discard block
 block discarded – undo
1235 1234
 					$widget['obj'] = new etemplate;
1236 1235
 					if (!$widget['obj']->read($widget['name'])) $widget['obj'] = false;
1237 1236
 				}
1238
-				if (!is_object($widget['obj'])) break;	// cant descent into template
1237
+				if (!is_object($widget['obj'])) break; // cant descent into template
1239 1238
 				$_path = $path.'/';
1240
-				$result =& $widget['obj']->widget_tree_walk($func,$extra,$_path);
1239
+				$result = & $widget['obj']->widget_tree_walk($func, $extra, $_path);
1241 1240
 				break;
1242 1241
 		}
1243 1242
 		return $result;
@@ -1249,17 +1248,17 @@  discard block
 block discarded – undo
1249 1248
 	 * @param array $cell the widget
1250 1249
 	 * @param array &$to_trans array with (lowercased) label => translation pairs
1251 1250
 	 */
1252
-	static function getToTranslateCell($cell,&$to_trans)
1251
+	static function getToTranslateCell($cell, &$to_trans)
1253 1252
 	{
1254 1253
 		//echo $cell['name']; _debug_array($cell);
1255
-		$strings = explode('|',$cell['help']);
1254
+		$strings = explode('|', $cell['help']);
1256 1255
 
1257 1256
 		if ($cell['type'] != 'image')
1258 1257
 		{
1259
-			$strings = array_merge($strings,explode('|',$cell['label']));
1258
+			$strings = array_merge($strings, explode('|', $cell['label']));
1260 1259
 		}
1261
-		list($extra_row) = explode(',',$cell['size']);
1262
-		if (substr($cell['type'],0,6) == 'select' && !empty($extra_row) && !intval($extra_row))
1260
+		list($extra_row) = explode(',', $cell['size']);
1261
+		if (substr($cell['type'], 0, 6) == 'select' && !empty($extra_row) && !intval($extra_row))
1263 1262
 		{
1264 1263
 			$strings[] = $extra_row;
1265 1264
 		}
@@ -1267,10 +1266,10 @@  discard block
 block discarded – undo
1267 1266
 		{
1268 1267
 			$strings[] = $cell['blur'];
1269 1268
 		}
1270
-		foreach($strings as $str)
1269
+		foreach ($strings as $str)
1271 1270
 		{
1272 1271
 			if (strlen($str) > 1 && $str{0} != '@' && $str{0} != '$' &&
1273
-				strpos($str,'$row') === false && strpos($str,'$cont') === false)
1272
+				strpos($str, '$row') === false && strpos($str, '$cont') === false)
1274 1273
 			{
1275 1274
 				$to_trans[trim(strtolower($str))] = $str;
1276 1275
 			}
Please login to merge, or discard this patch.
Braces   +128 added lines, -33 removed lines patch added patch discarded remove patch
@@ -191,15 +191,21 @@  discard block
 block discarded – undo
191 191
 	function &new_cell($row=False,$type='label',$label='',$name='',$attributes=False)
192 192
 	{
193 193
 		$row = $row >= 0 ? intval($row) : 0;
194
-		if ($row && !isset($this->data[$row]) || !isset($this->data[1]))	// new row ?
194
+		if ($row && !isset($this->data[$row]) || !isset($this->data[1]))
195
+		{
196
+			// new row ?
195 197
 		{
196 198
 			if (!$row) $row = 1;
199
+		}
197 200
 
198 201
 			$this->data[$row] = array();
199 202
 		}
200
-		if (!$row)	// use last row
203
+		if (!$row)
204
+		{
205
+			// use last row
201 206
 		{
202 207
 			$row = count($this->data);
208
+		}
203 209
 			while (!isset($this->data[$row]))
204 210
 			{
205 211
 				--$row;
@@ -231,9 +237,12 @@  discard block
 block discarded – undo
231 237
 	 */
232 238
 	static function add_child(&$parent,&$cell)
233 239
 	{
234
-		if (is_object($parent))	// parent is the template itself
240
+		if (is_object($parent))
241
+		{
242
+			// parent is the template itself
235 243
 		{
236 244
 			$parent->children[] = &$cell;
245
+		}
237 246
 			return;
238 247
 		}
239 248
 		switch($parent['type'])
@@ -255,21 +264,30 @@  discard block
 block discarded – undo
255 264
 				$rows = &$parent['rows'];
256 265
 				$row = &$data[$rows];
257 266
 				$col = count($row);
258
-				if (!$rows || !is_array($cell))	// create a new row
267
+				if (!$rows || !is_array($cell))
268
+				{
269
+					// create a new row
259 270
 				{
260 271
 					$row = &$data[++$rows];
272
+				}
261 273
 					$row = array();
262 274
 				}
263
-				if (is_array($cell))	// real cell to add
275
+				if (is_array($cell))
276
+				{
277
+					// real cell to add
264 278
 				{
265 279
 					$row[soetemplate::num2chrs($col++)] = &$cell;
280
+				}
266 281
 					list($spanned) = explode(',',$cell['span']);
267 282
 					$spanned = $spanned == 'all' ? 1 + $cols - $col : $spanned;
268 283
 					while (--$spanned > 0)
269 284
 					{
270 285
 						$row[soetemplate::num2chrs($col++)] = soetemplate::empty_cell();
271 286
 					}
272
-					if ($col > $cols) $cols = $col;
287
+					if ($col > $cols)
288
+					{
289
+						$cols = $col;
290
+					}
273 291
 				}
274 292
 				break;
275 293
 		}
@@ -301,10 +319,13 @@  discard block
 block discarded – undo
301 319
 	 */
302 320
 	function set_rows_cols()
303 321
 	{
304
-		if (is_null($this->data))	// tmpl contains no grid
322
+		if (is_null($this->data))
323
+		{
324
+			// tmpl contains no grid
305 325
 		{
306 326
 			$this->rows = $this->cols = 0;
307 327
 		}
328
+		}
308 329
 		else
309 330
 		{
310 331
 			$grid['data'] = &$this->data;
@@ -333,7 +354,10 @@  discard block
 block discarded – undo
333 354
 
334 355
 		foreach(self::$db_cols as $db_col => $col)
335 356
 		{
336
-			if ($col != 'data') $this->$col = is_array($name) ? (string) $name[$col] : $$col;
357
+			if ($col != 'data')
358
+			{
359
+				$this->$col = is_array($name) ? (string) $name[$col] : $$col;
360
+			}
337 361
 		}
338 362
 		if ($this->template == 'default')
339 363
 		{
@@ -345,7 +369,10 @@  discard block
 block discarded – undo
345 369
 		}
346 370
 		$this->tpls_in_file = is_array($name) ? $name['tpls_in_file'] : 0;
347 371
 
348
-		if (is_array($name) && $name['onclick_handler']) $this->onclick_handler = $name['onclick_handler'];
372
+		if (is_array($name) && $name['onclick_handler'])
373
+		{
374
+			$this->onclick_handler = $name['onclick_handler'];
375
+		}
349 376
 
350 377
 		if (is_array($name)  && isset($name['data']))
351 378
 		{
@@ -364,12 +391,21 @@  discard block
 block discarded – undo
364 391
 			{
365 392
 				for ($col = 0; $col < $cols; ++$col)
366 393
 				{
367
-					if (!is_array($this->data[$row])) $this->data[$row]=array();
394
+					if (!is_array($this->data[$row]))
395
+					{
396
+						$this->data[$row]=array();
397
+					}
368 398
 					$this->data[$row][$this->num2chrs($col)] = $this->empty_cell();
369 399
 				}
370 400
 			}
371
-			if (!is_array($this->children)) $this->children = array();
372
-			if (!is_array($this->children[0])) $this->children[0] = array();
401
+			if (!is_array($this->children))
402
+			{
403
+				$this->children = array();
404
+			}
405
+			if (!is_array($this->children[0]))
406
+			{
407
+				$this->children[0] = array();
408
+			}
373 409
 			$this->children[0]['type'] = 'grid';
374 410
 			$this->children[0]['data'] = &$this->data;
375 411
 			$this->children[0]['rows'] = &$this->rows;
@@ -575,10 +611,13 @@  discard block
 block discarded – undo
575 611
 		$result = array();
576 612
 		foreach($this->db->select(self::TABLE,'et_name,et_template,et_lang,et_group,et_version',$where,__LINE__,__FILE__,false,'ORDER BY et_name DESC,et_lang DESC,et_template DESC,et_version DESC','etemplate') as $row)
577 613
 		{
578
-			if ($row['et_lang'] != '##')	// exclude or import-time-stamps
614
+			if ($row['et_lang'] != '##')
615
+			{
616
+				// exclude or import-time-stamps
579 617
 			{
580 618
 				$result[] = egw_db::strip_array_keys($row,'et_');
581 619
 			}
620
+			}
582 621
 		}
583 622
 		if ($this->debug)
584 623
 		{
@@ -614,7 +653,10 @@  discard block
 block discarded – undo
614 653
 	 */
615 654
 	function fix_old_template_format()
616 655
 	{
617
-		if (!is_array($this->children)) $this->children = array();
656
+		if (!is_array($this->children))
657
+		{
658
+			$this->children = array();
659
+		}
618 660
 
619 661
 		if (!isset($this->children[0]['type']))
620 662
 		{
@@ -698,10 +740,13 @@  discard block
 block discarded – undo
698 740
 		}
699 741
 		foreach($arr as $key => $val)
700 742
 		{
701
-			if ($remove_objs && $key === 'obj')	// it can be an array too
743
+			if ($remove_objs && $key === 'obj')
744
+			{
745
+				// it can be an array too
702 746
 			{
703 747
 				unset($arr[$key]);
704 748
 			}
749
+			}
705 750
 			elseif (is_array($val))
706 751
 			{
707 752
 				$arr[$key] = $this->compress_array($val,$remove_objs);
@@ -811,26 +856,35 @@  discard block
 block discarded – undo
811 856
 		{
812 857
 			$this->version = $version;
813 858
 		}
814
-		if ($this->name == '')	// name need to be set !!!
859
+		if ($this->name == '')
860
+		{
861
+			// name need to be set !!!
815 862
 		{
816 863
 			return False;
817 864
 		}
865
+		}
818 866
 		if ($this->debug > 0 || $this->debug == $this->name)
819 867
 		{
820 868
 			echo "<p>soetemplate::save('$this->name','$this->template','$this->lang',$this->group,'$this->version')</p>\n";
821 869
 		}
822
-		if ($this->name[0] != '.' && is_array($this->data))		// correct old messed up templates
870
+		if ($this->name[0] != '.' && is_array($this->data))
871
+		{
872
+			// correct old messed up templates
823 873
 		{
824
-			reset($this->data); each($this->data);
874
+			reset($this->data);
875
+		}
876
+		each($this->data);
825 877
 			while (list($row,$cols) = each($this->data))
826 878
 			{
827 879
 				while (list($col,$cell) = each($cols))
828 880
 				{
829
-					if (is_array($cell['type'])) {
881
+					if (is_array($cell['type']))
882
+					{
830 883
 						$this->data[$row][$col]['type'] = $cell['type'][0];
831 884
 						//echo "corrected in $this->name cell $col$row attribute type<br>\n";
832 885
 					}
833
-					if (is_array($cell['align'])) {
886
+					if (is_array($cell['align']))
887
+					{
834 888
 						$this->data[$row][$col]['align'] = $cell['align'][0];
835 889
 						//echo "corrected in $this->name cell $col$row attribute align<br>\n";
836 890
 					}
@@ -841,7 +895,10 @@  discard block
 block discarded – undo
841 895
 		{
842 896
 			$this->modified = time();
843 897
 		}
844
-		if (is_null($this->group) || !is_int($this->group)) $this->group = 0;
898
+		if (is_null($this->group) || !is_int($this->group))
899
+		{
900
+			$this->group = 0;
901
+		}
845 902
 
846 903
 		$this->db->insert(self::TABLE,$this->as_array(3,true),$this->as_array(-1,true),__LINE__,__FILE__,'etemplate');
847 904
 
@@ -923,10 +980,13 @@  discard block
 block discarded – undo
923 980
 			$str = '$templ_data[] = array(';
924 981
 			foreach (self::$db_cols as $db_col => $name)
925 982
 			{
926
-				if ($name == 'style')	// remove trailing whitespace
983
+				if ($name == 'style')
984
+				{
985
+					// remove trailing whitespace
927 986
 				{
928 987
 					$row[$db_col] = preg_replace('/[ \t]+$/m', '', $row[$db_col]);
929 988
 				}
989
+				}
930 990
 				// escape only backslashes and single quotes (in that order)
931 991
 				$str .= "'$name' => '".str_replace(array('\\','\'',"\r"),array('\\\\','\\\'',''),$row[$db_col])."',";
932 992
 			}
@@ -936,7 +996,10 @@  discard block
 block discarded – undo
936 996
 		}
937 997
 		fclose($f);
938 998
 
939
-		if ($file == 'php://stdout') common::egw_exit();
999
+		if ($file == 'php://stdout')
1000
+		{
1001
+			common::egw_exit();
1002
+		}
940 1003
 
941 1004
 		return lang("%1 eTemplates for Application '%2' dumped to '%3'",$n,$app,$file);
942 1005
 	}
@@ -1024,7 +1087,10 @@  discard block
 block discarded – undo
1024 1087
 			//echo "writeLangFile: additional ="; _debug_array($additional);
1025 1088
 			foreach($additional as $msg)
1026 1089
 			{
1027
-				if (!is_array($msg)) $to_trans[trim(strtolower($msg))] = $msg;
1090
+				if (!is_array($msg))
1091
+				{
1092
+					$to_trans[trim(strtolower($msg))] = $msg;
1093
+				}
1028 1094
 			}
1029 1095
 		}
1030 1096
 		unset($to_trans['']);
@@ -1033,10 +1099,13 @@  discard block
 block discarded – undo
1033 1099
 		{
1034 1100
 			if (!isset($langarr[$message_id]) && !isset($commonarr[$message_id]))
1035 1101
 			{
1036
-				if (@isset($langarr[$content]))	// caused by not lowercased-message_id's
1102
+				if (@isset($langarr[$content]))
1103
+				{
1104
+					// caused by not lowercased-message_id's
1037 1105
 				{
1038 1106
 					unset($langarr[$content]);
1039 1107
 				}
1108
+				}
1040 1109
 				$langarr[$message_id] = array(
1041 1110
 					'message_id' => $message_id,
1042 1111
 					'app_name'   => $app,
@@ -1068,7 +1137,10 @@  discard block
 block discarded – undo
1068 1137
 	{
1069 1138
 		static $objs = array('db','html','xul_io');
1070 1139
 
1071
-		if ($backtrace) echo "<p>".function_backtrace(1)."</p>\n";
1140
+		if ($backtrace)
1141
+		{
1142
+			echo "<p>".function_backtrace(1)."</p>\n";
1143
+		}
1072 1144
 
1073 1145
 		if ($no_other_objs)
1074 1146
 		{
@@ -1129,7 +1201,10 @@  discard block
 block discarded – undo
1129 1201
 			{
1130 1202
 				$result =& $func($child,$extra,$path.$c);
1131 1203
 			}
1132
-			if (!is_null($result) || is_array($extra) && isset($extra['__RETURN_NOW__'])) break;
1204
+			if (!is_null($result) || is_array($extra) && isset($extra['__RETURN_NOW__']))
1205
+			{
1206
+				break;
1207
+			}
1133 1208
 		}
1134 1209
 		return $result;
1135 1210
 	}
@@ -1195,17 +1270,27 @@  discard block
 block discarded – undo
1195 1270
 					{
1196 1271
 						$result =& $func($child,$extra,$_path);
1197 1272
 					}
1198
-					if (!is_null($result) || is_array($extra) && isset($extra['__RETURN__NOW__'])) return $result;
1273
+					if (!is_null($result) || is_array($extra) && isset($extra['__RETURN__NOW__']))
1274
+					{
1275
+						return $result;
1276
+					}
1199 1277
 				}
1200 1278
 				break;
1201 1279
 
1202 1280
 			case 'grid':
1203 1281
 				$data = &$widget['data'];
1204
-				if (!is_array($data)) break;	// no children
1282
+				if (!is_array($data))
1283
+				{
1284
+					break;
1285
+				}
1286
+				// no children
1205 1287
 
1206 1288
 				foreach($data as $r => $row)
1207 1289
 				{
1208
-					if (!$r || !is_array($row)) continue;
1290
+					if (!$r || !is_array($row))
1291
+					{
1292
+						continue;
1293
+					}
1209 1294
 
1210 1295
 					foreach($row as $c => $col)
1211 1296
 					{
@@ -1223,7 +1308,10 @@  discard block
 block discarded – undo
1223 1308
 						{
1224 1309
 							$result =& $func($child,$extra,$_path);
1225 1310
 						}
1226
-						if (!is_null($result) || is_array($extra) && isset($extra['__RETURN__NOW__'])) return $result;
1311
+						if (!is_null($result) || is_array($extra) && isset($extra['__RETURN__NOW__']))
1312
+						{
1313
+							return $result;
1314
+						}
1227 1315
 						unset($child);
1228 1316
 					}
1229 1317
 				}
@@ -1233,9 +1321,16 @@  discard block
 block discarded – undo
1233 1321
 				if (!isset($widget['obj']) && $widget['name'][0] != '@')
1234 1322
 				{
1235 1323
 					$widget['obj'] = new etemplate;
1236
-					if (!$widget['obj']->read($widget['name'])) $widget['obj'] = false;
1324
+					if (!$widget['obj']->read($widget['name']))
1325
+					{
1326
+						$widget['obj'] = false;
1327
+					}
1328
+				}
1329
+				if (!is_object($widget['obj']))
1330
+				{
1331
+					break;
1237 1332
 				}
1238
-				if (!is_object($widget['obj'])) break;	// cant descent into template
1333
+				// cant descent into template
1239 1334
 				$_path = $path.'/';
1240 1335
 				$result =& $widget['obj']->widget_tree_walk($func,$extra,$_path);
1241 1336
 				break;
Please login to merge, or discard this patch.