Passed
Push — 17.1 ( 431f3f...4dae72 )
by Ralf
01:23 queued 12s
created
api/src/Auth/Sql.php 3 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -241,7 +241,6 @@
 block discarded – undo
241 241
 	 * changes password in sql datababse
242 242
 	 *
243 243
 	 * @param string $encrypted_passwd
244
-	 * @param string $new_passwd cleartext
245 244
 	 * @param int $account_id account id of user whose passwd should be changed
246 245
 	 * @param boolean $admin =false called by admin, if not update password in the session
247 246
 	 * @param boolean $update_lastpw_change =true
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 	 * @param string $passwd_type ='text' 'text' for cleartext passwords (default)
53 53
 	 * @return boolean true if successful authenticated, false otherwise
54 54
 	 */
55
-	function authenticate($username, $passwd, $passwd_type='text')
55
+	function authenticate($username, $passwd, $passwd_type = 'text')
56 56
 	{
57 57
 		/* normal web form login */
58 58
 		$where = array(
@@ -65,26 +65,26 @@  discard block
 block discarded – undo
65 65
 			$where[] = 'account_lid '.$this->db->capabilities[Api\Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote($username);
66 66
 			unset($where['account_lid']);
67 67
 		}
68
-		if($passwd_type == 'text')
68
+		if ($passwd_type == 'text')
69 69
 		{
70
-			if (!($row = $this->db->select($this->table,'account_lid,account_pwd,account_lastlogin,account_id',$where,__LINE__,__FILE__)->fetch()) ||
70
+			if (!($row = $this->db->select($this->table, 'account_lid,account_pwd,account_lastlogin,account_id', $where, __LINE__, __FILE__)->fetch()) ||
71 71
 				empty($row['account_pwd']) ||
72 72
 				$GLOBALS['egw_info']['server']['case_sensitive_username'] && $row['account_lid'] != $username)
73 73
 			{
74 74
 				return false;
75 75
 			}
76 76
 			$type = null;
77
-			if(!($match = Api\Auth::compare_password($passwd, $row['account_pwd'], $this->type, strtolower($username), $type)) ||
78
-				$type != $this->type && in_array($type, explode(',',strtolower($GLOBALS['egw_info']['server']['pwd_migration_types']))))
77
+			if (!($match = Api\Auth::compare_password($passwd, $row['account_pwd'], $this->type, strtolower($username), $type)) ||
78
+				$type != $this->type && in_array($type, explode(',', strtolower($GLOBALS['egw_info']['server']['pwd_migration_types']))))
79 79
 			{
80 80
 				// do we have to migrate an old password ?
81
-				if($GLOBALS['egw_info']['server']['pwd_migration_allowed'] && !empty($GLOBALS['egw_info']['server']['pwd_migration_types']))
81
+				if ($GLOBALS['egw_info']['server']['pwd_migration_allowed'] && !empty($GLOBALS['egw_info']['server']['pwd_migration_types']))
82 82
 				{
83 83
 					if (!$match)
84 84
 					{
85
-						foreach(explode(',', $GLOBALS['egw_info']['server']['pwd_migration_types']) as $type)
85
+						foreach (explode(',', $GLOBALS['egw_info']['server']['pwd_migration_types']) as $type)
86 86
 						{
87
-							if(($match = Api\Auth::compare_password($passwd,$row['account_pwd'],$type,strtolower($username))))
87
+							if (($match = Api\Auth::compare_password($passwd, $row['account_pwd'], $type, strtolower($username))))
88 88
 							{
89 89
 								break;
90 90
 							}
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 		else
103 103
 		{
104 104
 			$where['account_pwd'] = $passwd;
105
-			if (!($row = $this->db->select($this->table,'account_lid,account_lastlogin',$where,__LINE__,__FILE__)->fetch()) ||
105
+			if (!($row = $this->db->select($this->table, 'account_lid,account_lastlogin', $where, __LINE__, __FILE__)->fetch()) ||
106 106
 				$GLOBALS['egw_info']['server']['case_sensitive_username'] && $row['account_lid'] != $username)
107 107
 			{
108 108
 				return false;
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 			$where[] = 'account_lid '.$this->db->capabilities[Api\Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote($username);
134 134
 			unset($where['account_lid']);
135 135
 		}
136
-		if (!($row = $this->db->select($this->table,'account_lid,account_lastpwd_change',$where,__LINE__,__FILE__)->fetch()) ||
136
+		if (!($row = $this->db->select($this->table, 'account_lid,account_lastpwd_change', $where, __LINE__, __FILE__)->fetch()) ||
137 137
 			$GLOBALS['egw_info']['server']['case_sensitive_username'] && $row['account_lid'] != $username)
138 138
 		{
139 139
 			return false;
@@ -152,11 +152,11 @@  discard block
 block discarded – undo
152 152
 	 * @param int $_lastpwdchange =null must be a unixtimestamp
153 153
 	 * @return boolean true if account_lastpwd_change successful changed, false otherwise
154 154
 	 */
155
-	function setLastPwdChange($account_id=0, $passwd=NULL, $_lastpwdchange=NULL)
155
+	function setLastPwdChange($account_id = 0, $passwd = NULL, $_lastpwdchange = NULL)
156 156
 	{
157 157
 		$admin = True;
158 158
 		// Don't allow password changes for other accounts when using XML-RPC
159
-		if(!$account_id || $GLOBALS['egw_info']['flags']['currentapp'] == 'login')
159
+		if (!$account_id || $GLOBALS['egw_info']['flags']['currentapp'] == 'login')
160 160
 		{
161 161
 			$admin = False;
162 162
 			$account_id = $GLOBALS['egw_info']['user']['account_id'];
@@ -167,27 +167,27 @@  discard block
 block discarded – undo
167 167
 			$username = $GLOBALS['egw']->accounts->id2name($account_id);
168 168
 		}
169 169
 
170
-		if (($pw = $this->db->select($this->table,'account_pwd',array(
170
+		if (($pw = $this->db->select($this->table, 'account_pwd', array(
171 171
 			'account_id'     => $account_id,
172 172
 			'account_type'   => 'u',
173 173
 			'account_status' => 'A',
174
-		),__LINE__,__FILE__)->fetchColumn()) === false)
174
+		), __LINE__, __FILE__)->fetchColumn()) === false)
175 175
 		{
176
-			return false;	// account not found
176
+			return false; // account not found
177 177
 		}
178 178
 		// Check the passwd to make sure this is legal
179
-		if(!$admin && !Api\Auth::compare_password($passwd,$pw,$this->type,strtolower($username)))
179
+		if (!$admin && !Api\Auth::compare_password($passwd, $pw, $this->type, strtolower($username)))
180 180
 		{
181 181
 			return false;
182 182
 		}
183 183
 		$lastpwdchange = (is_null($_lastpwdchange) || $_lastpwdchange < 0 ? time() : $_lastpwdchange);
184
-		$this->db->update($this->table,array(
184
+		$this->db->update($this->table, array(
185 185
 			'account_lastpwd_change' => $lastpwdchange,
186
-		),array(
186
+		), array(
187 187
 			'account_id' => $account_id,
188
-		),__LINE__,__FILE__);
188
+		), __LINE__, __FILE__);
189 189
 
190
-		if(!$this->db->affected_rows()) return false;
190
+		if (!$this->db->affected_rows()) return false;
191 191
 		if (!$admin) Api\Cache::setSession('phpgwapi', 'auth_alpwchange_val', $lastpwdchange);
192 192
 		return true;
193 193
 	}
@@ -200,11 +200,11 @@  discard block
 block discarded – undo
200 200
 	 * @param int $account_id account id of user whose passwd should be changed
201 201
 	 * @return boolean true if password successful changed, false otherwise
202 202
 	 */
203
-	function change_password($old_passwd, $new_passwd, $account_id=0)
203
+	function change_password($old_passwd, $new_passwd, $account_id = 0)
204 204
 	{
205 205
 		$admin = True;
206 206
 		// Don't allow password changes for other accounts when using XML-RPC
207
-		if(!$account_id)
207
+		if (!$account_id)
208 208
 		{
209 209
 			$admin = False;
210 210
 			$account_id = $GLOBALS['egw_info']['user']['account_id'];
@@ -215,15 +215,15 @@  discard block
 block discarded – undo
215 215
 			$username = $GLOBALS['egw']->accounts->id2name($account_id);
216 216
 		}
217 217
 
218
-		if (($pw = $this->db->select($this->table,'account_pwd',array(
218
+		if (($pw = $this->db->select($this->table, 'account_pwd', array(
219 219
 			'account_id'     => $account_id,
220 220
 			'account_type'   => 'u',
221
-		),__LINE__,__FILE__)->fetchColumn()) === false)
221
+		), __LINE__, __FILE__)->fetchColumn()) === false)
222 222
 		{
223
-			return false;	// account not found
223
+			return false; // account not found
224 224
 		}
225 225
 		// Check the old_passwd to make sure this is legal
226
-		if(!$admin && !Api\Auth::compare_password($old_passwd,$pw,$this->type,strtolower($username)))
226
+		if (!$admin && !Api\Auth::compare_password($old_passwd, $pw, $this->type, strtolower($username)))
227 227
 		{
228 228
 			return false;
229 229
 		}
@@ -247,21 +247,21 @@  discard block
 block discarded – undo
247 247
 	 * @param boolean $update_lastpw_change =true
248 248
 	 * @return boolean true if password successful changed, false otherwise
249 249
 	 */
250
-	private function _update_passwd($encrypted_passwd, $account_id, $admin=false, $update_lastpw_change=true)
250
+	private function _update_passwd($encrypted_passwd, $account_id, $admin = false, $update_lastpw_change = true)
251 251
 	{
252 252
 		$update = array('account_pwd' => $encrypted_passwd);
253 253
 		if ($update_lastpw_change) $update['account_lastpwd_change'] = time();
254 254
 
255
-		if (!$this->db->update($this->table,$update,array(
255
+		if (!$this->db->update($this->table, $update, array(
256 256
 			'account_id' => $account_id,
257
-		),__LINE__,__FILE__))
257
+		), __LINE__, __FILE__))
258 258
 		{
259 259
 			return false;
260 260
 		}
261 261
 
262
-		if(!$admin)
262
+		if (!$admin)
263 263
 		{
264
-			Api\Cache::setSession('phpgwapi','auth_alpwchange_val',$update['account_lastpwd_change']);
264
+			Api\Cache::setSession('phpgwapi', 'auth_alpwchange_val', $update['account_lastpwd_change']);
265 265
 		}
266 266
 		return true;
267 267
 	}
Please login to merge, or discard this patch.
Braces   +24 added lines, -6 removed lines patch added patch discarded remove patch
@@ -60,9 +60,12 @@  discard block
 block discarded – undo
60 60
 			'account_type'   => 'u',
61 61
 			'account_status' => 'A'
62 62
 		);
63
-		if (!$GLOBALS['egw_info']['server']['case_sensitive_username'])	// = is case sensitiv eg. on postgres, but not on mysql!
63
+		if (!$GLOBALS['egw_info']['server']['case_sensitive_username'])
64
+		{
65
+			// = is case sensitiv eg. on postgres, but not on mysql!
64 66
 		{
65 67
 			$where[] = 'account_lid '.$this->db->capabilities[Api\Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote($username);
68
+		}
66 69
 			unset($where['account_lid']);
67 70
 		}
68 71
 		if($passwd_type == 'text')
@@ -95,7 +98,10 @@  discard block
 block discarded – undo
95 98
 						$this->_update_passwd($encrypted_passwd, $row['account_id'], false, true);
96 99
 					}
97 100
 				}
98
-				if (!$match) return false;
101
+				if (!$match)
102
+				{
103
+					return false;
104
+				}
99 105
 			}
100 106
 		}
101 107
 		/* Auth via crypted password. NOTE: mail needs cleartext password to authenticate against mailserver! */
@@ -128,9 +134,12 @@  discard block
 block discarded – undo
128 134
 			'account_type'   => 'u',
129 135
 			'account_status' => 'A'
130 136
 		);
131
-		if (!$GLOBALS['egw_info']['server']['case_sensitive_username'])	// = is case sensitiv eg. on postgres, but not on mysql!
137
+		if (!$GLOBALS['egw_info']['server']['case_sensitive_username'])
138
+		{
139
+			// = is case sensitiv eg. on postgres, but not on mysql!
132 140
 		{
133 141
 			$where[] = 'account_lid '.$this->db->capabilities[Api\Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote($username);
142
+		}
134 143
 			unset($where['account_lid']);
135 144
 		}
136 145
 		if (!($row = $this->db->select($this->table,'account_lid,account_lastpwd_change',$where,__LINE__,__FILE__)->fetch()) ||
@@ -187,8 +196,14 @@  discard block
 block discarded – undo
187 196
 			'account_id' => $account_id,
188 197
 		),__LINE__,__FILE__);
189 198
 
190
-		if(!$this->db->affected_rows()) return false;
191
-		if (!$admin) Api\Cache::setSession('phpgwapi', 'auth_alpwchange_val', $lastpwdchange);
199
+		if(!$this->db->affected_rows())
200
+		{
201
+			return false;
202
+		}
203
+		if (!$admin)
204
+		{
205
+			Api\Cache::setSession('phpgwapi', 'auth_alpwchange_val', $lastpwdchange);
206
+		}
192 207
 		return true;
193 208
 	}
194 209
 
@@ -250,7 +265,10 @@  discard block
 block discarded – undo
250 265
 	private function _update_passwd($encrypted_passwd, $account_id, $admin=false, $update_lastpw_change=true)
251 266
 	{
252 267
 		$update = array('account_pwd' => $encrypted_passwd);
253
-		if ($update_lastpw_change) $update['account_lastpwd_change'] = time();
268
+		if ($update_lastpw_change)
269
+		{
270
+			$update['account_lastpwd_change'] = time();
271
+		}
254 272
 
255 273
 		if (!$this->db->update($this->table,$update,array(
256 274
 			'account_id' => $account_id,
Please login to merge, or discard this patch.
admin/apcu.php 5 patches
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -217,25 +217,25 @@  discard block
 block discarded – undo
217 217
 header("Pragma: no-cache");                                    // HTTP/1.0
218 218
 
219 219
 function duration($ts) {
220
-    global $time;
221
-    $years = (int)((($time - $ts)/(7*86400))/52.177457);
222
-    $rem = (int)(($time-$ts)-($years * 52.177457 * 7 * 86400));
223
-    $weeks = (int)(($rem)/(7*86400));
224
-    $days = (int)(($rem)/86400) - $weeks*7;
225
-    $hours = (int)(($rem)/3600) - $days*24 - $weeks*7*24;
226
-    $mins = (int)(($rem)/60) - $hours*60 - $days*24*60 - $weeks*7*24*60;
227
-    $str = '';
228
-    if($years==1) $str .= "$years year, ";
229
-    if($years>1) $str .= "$years years, ";
230
-    if($weeks==1) $str .= "$weeks week, ";
231
-    if($weeks>1) $str .= "$weeks weeks, ";
232
-    if($days==1) $str .= "$days day,";
233
-    if($days>1) $str .= "$days days,";
234
-    if($hours == 1) $str .= " $hours hour and";
235
-    if($hours>1) $str .= " $hours hours and";
236
-    if($mins == 1) $str .= " 1 minute";
237
-    else $str .= " $mins minutes";
238
-    return $str;
220
+	global $time;
221
+	$years = (int)((($time - $ts)/(7*86400))/52.177457);
222
+	$rem = (int)(($time-$ts)-($years * 52.177457 * 7 * 86400));
223
+	$weeks = (int)(($rem)/(7*86400));
224
+	$days = (int)(($rem)/86400) - $weeks*7;
225
+	$hours = (int)(($rem)/3600) - $days*24 - $weeks*7*24;
226
+	$mins = (int)(($rem)/60) - $hours*60 - $days*24*60 - $weeks*7*24*60;
227
+	$str = '';
228
+	if($years==1) $str .= "$years year, ";
229
+	if($years>1) $str .= "$years years, ";
230
+	if($weeks==1) $str .= "$weeks week, ";
231
+	if($weeks>1) $str .= "$weeks weeks, ";
232
+	if($days==1) $str .= "$days day,";
233
+	if($days>1) $str .= "$days days,";
234
+	if($hours == 1) $str .= " $hours hour and";
235
+	if($hours>1) $str .= " $hours hours and";
236
+	if($mins == 1) $str .= " 1 minute";
237
+	else $str .= " $mins minutes";
238
+	return $str;
239 239
 }
240 240
 
241 241
 // create graphics
@@ -420,18 +420,18 @@  discard block
 block discarded – undo
420 420
 				if($block['offset']!=$ptr) {       // Used block
421 421
 					$h=(GRAPH_SIZE-5)*($block['offset']-$ptr)/$s;
422 422
 					if ($h>0) {
423
-                                                $j++;
423
+												$j++;
424 424
 						if($j<75) fill_box($image,$x,$y,50,$h,$col_black,$col_red,bsize($block['offset']-$ptr),$j);
425
-                                                else fill_box($image,$x,$y,50,$h,$col_black,$col_red);
426
-                                        }
425
+												else fill_box($image,$x,$y,50,$h,$col_black,$col_red);
426
+										}
427 427
 					$y+=$h;
428 428
 				}
429 429
 				$h=(GRAPH_SIZE-5)*($block['size'])/$s;
430 430
 				if ($h>0) {
431
-                                        $j++;
431
+										$j++;
432 432
 					if($j<75) fill_box($image,$x,$y,50,$h,$col_black,$col_green,bsize($block['size']),$j);
433 433
 					else fill_box($image,$x,$y,50,$h,$col_black,$col_green);
434
-                                }
434
+								}
435 435
 				$y+=$h;
436 436
 				$ptr = $block['offset']+$block['size'];
437 437
 			}
@@ -781,7 +781,7 @@  discard block
 block discarded – undo
781 781
 	$apcversion = phpversion('apcu');
782 782
 	$phpversion = phpversion();
783 783
 	$number_vars = $cache['num_entries'];
784
-    $size_vars = bsize($cache['mem_size']);
784
+	$size_vars = bsize($cache['mem_size']);
785 785
 	$i=0;
786 786
 	echo <<< EOB
787 787
 		<div class="info div1"><h2>General Cache Information</h2>
@@ -883,9 +883,9 @@  discard block
 block discarded – undo
883 883
 				++$nseg;
884 884
 			}
885 885
 			$ptr = $block['offset'] + $block['size'];
886
-                        /* Only consider blocks <5M for the fragmentation % */
887
-                        if($block['size']<(5*1024*1024)) $fragsize+=$block['size'];
888
-                        $freetotal+=$block['size'];
886
+						/* Only consider blocks <5M for the fragmentation % */
887
+						if($block['size']<(5*1024*1024)) $fragsize+=$block['size'];
888
+						$freetotal+=$block['size'];
889 889
 		}
890 890
 		$freeseg += count($mem['block_lists'][$i]);
891 891
 	}
@@ -907,15 +907,15 @@  discard block
 block discarded – undo
907 907
 		</td>
908 908
 		</tr>
909 909
 EOB;
910
-        if(isset($mem['adist'])) {
911
-          foreach($mem['adist'] as $i=>$v) {
912
-            $cur = pow(2,$i); $nxt = pow(2,$i+1)-1;
913
-            if($i==0) $range = "1";
914
-            else $range = "$cur - $nxt";
915
-            echo "<tr><th align=right>$range</th><td align=right>$v</td></tr>\n";
916
-          }
917
-        }
918
-        echo <<<EOB
910
+		if(isset($mem['adist'])) {
911
+		  foreach($mem['adist'] as $i=>$v) {
912
+			$cur = pow(2,$i); $nxt = pow(2,$i+1)-1;
913
+			if($i==0) $range = "1";
914
+			else $range = "$cur - $nxt";
915
+			echo "<tr><th align=right>$range</th><td align=right>$v</td></tr>\n";
916
+		  }
917
+		}
918
+		echo <<<EOB
919 919
 		</tbody></table>
920 920
 		</div>
921 921
 EOB;
@@ -928,7 +928,7 @@  discard block
 block discarded – undo
928 928
 // -----------------------------------------------
929 929
 case OB_USER_CACHE:
930 930
 	if (!$AUTHENTICATED) {
931
-    echo '<div class="error">You need to login to see the user values here!<br/>&nbsp;<br/>';
931
+	echo '<div class="error">You need to login to see the user values here!<br/>&nbsp;<br/>';
932 932
 		put_login_link("Login now!");
933 933
 		echo '</div>';
934 934
 		break;
@@ -973,7 +973,7 @@  discard block
 block discarded – undo
973 973
 		'<option value=500',$MYREQUEST['COUNT']=='500'? ' selected':'','>Top 500</option>',
974 974
 		'<option value=0  ',$MYREQUEST['COUNT']=='0'  ? ' selected':'','>All</option>',
975 975
 		'</select>',
976
-    '&nbsp; Search: <input name=SEARCH value="',$MYREQUEST['SEARCH'],'" type=text size=25/>',
976
+	'&nbsp; Search: <input name=SEARCH value="',$MYREQUEST['SEARCH'],'" type=text size=25/>',
977 977
 		'&nbsp;<input type=submit value="GO!">',
978 978
 		'</form></div>';
979 979
 
@@ -982,8 +982,8 @@  discard block
 block discarded – undo
982 982
    // regular expression subpattern.
983 983
    $MYREQUEST['SEARCH'] = '/'.str_replace('/', '\\/', $MYREQUEST['SEARCH']).'/i';
984 984
    if (preg_match($MYREQUEST['SEARCH'], 'test') === false) {
985
-     echo '<div class="error">Error: enter a valid regular expression as a search query.</div>';
986
-     break;
985
+	 echo '<div class="error">Error: enter a valid regular expression as a search query.</div>';
986
+	 break;
987 987
    }
988 988
   }
989 989
 
@@ -1037,45 +1037,45 @@  discard block
 block discarded – undo
1037 1037
 		// output list
1038 1038
 		$i=0;
1039 1039
 		foreach($list as $k => $entry) {
1040
-      if(!$MYREQUEST['SEARCH'] || preg_match($MYREQUEST['SEARCH'], $entry[$fieldname]) != 0) {
1040
+	  if(!$MYREQUEST['SEARCH'] || preg_match($MYREQUEST['SEARCH'], $entry[$fieldname]) != 0) {
1041 1041
 		$sh=md5($entry["info"]);
1042
-        $field_value = htmlentities(strip_tags($entry[$fieldname],''), ENT_QUOTES, 'UTF-8');
1043
-        echo
1044
-          '<tr id="key-'. $sh .'" class=tr-',$i%2,'>',
1045
-          "<td class=td-0><a href=\"$MY_SELF&OB=",$MYREQUEST['OB'],"&SH=",$sh,"#key-". $sh ."\">",$field_value,'</a></td>',
1046
-          '<td class="td-n center">',$entry['num_hits'],'</td>',
1047
-          '<td class="td-n right">',$entry['mem_size'],'</td>',
1048
-          '<td class="td-n center">',date(DATE_FORMAT,$entry['access_time']),'</td>',
1049
-          '<td class="td-n center">',date(DATE_FORMAT,$entry['mtime']),'</td>',
1050
-          '<td class="td-n center">',date(DATE_FORMAT,$entry['creation_time']),'</td>';
1051
-
1052
-        if($fieldname=='info') {
1053
-          if($entry['ttl'])
1054
-            echo '<td class="td-n center">'.$entry['ttl'].' seconds</td>';
1055
-          else
1056
-            echo '<td class="td-n center">None</td>';
1057
-        }
1058
-        if ($entry['deletion_time']) {
1059
-
1060
-          echo '<td class="td-last center">', date(DATE_FORMAT,$entry['deletion_time']), '</td>';
1061
-        } else if ($MYREQUEST['OB'] == OB_USER_CACHE) {
1062
-
1063
-          echo '<td class="td-last center">';
1064
-          echo '[<a href="', $MY_SELF, '&OB=', $MYREQUEST['OB'], '&DU=', urlencode($entry[$fieldkey]), '">Delete Now</a>]';
1065
-          echo '</td>';
1066
-        } else {
1067
-          echo '<td class="td-last center"> &nbsp; </td>';
1068
-        }
1069
-        echo '</tr>';
1042
+		$field_value = htmlentities(strip_tags($entry[$fieldname],''), ENT_QUOTES, 'UTF-8');
1043
+		echo
1044
+		  '<tr id="key-'. $sh .'" class=tr-',$i%2,'>',
1045
+		  "<td class=td-0><a href=\"$MY_SELF&OB=",$MYREQUEST['OB'],"&SH=",$sh,"#key-". $sh ."\">",$field_value,'</a></td>',
1046
+		  '<td class="td-n center">',$entry['num_hits'],'</td>',
1047
+		  '<td class="td-n right">',$entry['mem_size'],'</td>',
1048
+		  '<td class="td-n center">',date(DATE_FORMAT,$entry['access_time']),'</td>',
1049
+		  '<td class="td-n center">',date(DATE_FORMAT,$entry['mtime']),'</td>',
1050
+		  '<td class="td-n center">',date(DATE_FORMAT,$entry['creation_time']),'</td>';
1051
+
1052
+		if($fieldname=='info') {
1053
+		  if($entry['ttl'])
1054
+			echo '<td class="td-n center">'.$entry['ttl'].' seconds</td>';
1055
+		  else
1056
+			echo '<td class="td-n center">None</td>';
1057
+		}
1058
+		if ($entry['deletion_time']) {
1059
+
1060
+		  echo '<td class="td-last center">', date(DATE_FORMAT,$entry['deletion_time']), '</td>';
1061
+		} else if ($MYREQUEST['OB'] == OB_USER_CACHE) {
1062
+
1063
+		  echo '<td class="td-last center">';
1064
+		  echo '[<a href="', $MY_SELF, '&OB=', $MYREQUEST['OB'], '&DU=', urlencode($entry[$fieldkey]), '">Delete Now</a>]';
1065
+		  echo '</td>';
1066
+		} else {
1067
+		  echo '<td class="td-last center"> &nbsp; </td>';
1068
+		}
1069
+		echo '</tr>';
1070 1070
 		if ($sh == $MYREQUEST["SH"]) {
1071 1071
 			echo '<tr>';
1072 1072
 			echo '<td colspan="7"><pre>'.htmlentities(print_r(apcu_fetch($entry['info']), 1)).'</pre></td>';
1073 1073
 			echo '</tr>';
1074 1074
 		}
1075
-        $i++;
1076
-        if ($i == $MYREQUEST['COUNT'])
1077
-          break;
1078
-      }
1075
+		$i++;
1076
+		if ($i == $MYREQUEST['COUNT'])
1077
+		  break;
1078
+	  }
1079 1079
 		}
1080 1080
 
1081 1081
 	} else {
@@ -1106,10 +1106,10 @@  discard block
 block discarded – undo
1106 1106
 		</tr>
1107 1107
 EOB;
1108 1108
   if (defined('PROXY')) {
1109
-    $ctxt = stream_context_create( array( 'http' => array( 'proxy' => PROXY, 'request_fulluri' => True ) ) );
1110
-    $rss = @file_get_contents("http://pecl.php.net/feeds/pkg_apcu.rss", False, $ctxt);
1109
+	$ctxt = stream_context_create( array( 'http' => array( 'proxy' => PROXY, 'request_fulluri' => True ) ) );
1110
+	$rss = @file_get_contents("http://pecl.php.net/feeds/pkg_apcu.rss", False, $ctxt);
1111 1111
   } else {
1112
-    $rss = @file_get_contents("http://pecl.php.net/feeds/pkg_apcu.rss");
1112
+	$rss = @file_get_contents("http://pecl.php.net/feeds/pkg_apcu.rss");
1113 1113
   }
1114 1114
 	if (!$rss) {
1115 1115
 		echo '<tr class="td-last center"><td>Unable to fetch version information.</td></tr>';
Please login to merge, or discard this patch.
Switch Indentation   +284 added lines, -284 removed lines patch added patch discarded remove patch
@@ -344,105 +344,105 @@  discard block
 block discarded – undo
344 344
 
345 345
 	switch ($MYREQUEST['IMG']) {
346 346
 
347
-	case 1:
348
-		$s=$mem['num_seg']*$mem['seg_size'];
349
-		$a=$mem['avail_mem'];
350
-		$x=$y=$size/2;
351
-		$fuzz = 0.000001;
352
-
353
-		// This block of code creates the pie chart.  It is a lot more complex than you
354
-		// would expect because we try to visualize any memory fragmentation as well.
355
-		$angle_from = 0;
356
-		$string_placement=array();
357
-		for($i=0; $i<$mem['num_seg']; $i++) {
358
-			$ptr = 0;
359
-			$free = $mem['block_lists'][$i];
360
-			uasort($free, 'block_sort');
361
-			foreach($free as $block) {
362
-				if($block['offset']!=$ptr) {       // Used block
363
-					$angle_to = $angle_from+($block['offset']-$ptr)/$s;
347
+		case 1:
348
+			$s=$mem['num_seg']*$mem['seg_size'];
349
+			$a=$mem['avail_mem'];
350
+			$x=$y=$size/2;
351
+			$fuzz = 0.000001;
352
+
353
+			// This block of code creates the pie chart.  It is a lot more complex than you
354
+			// would expect because we try to visualize any memory fragmentation as well.
355
+			$angle_from = 0;
356
+			$string_placement=array();
357
+			for($i=0; $i<$mem['num_seg']; $i++) {
358
+				$ptr = 0;
359
+				$free = $mem['block_lists'][$i];
360
+				uasort($free, 'block_sort');
361
+				foreach($free as $block) {
362
+					if($block['offset']!=$ptr) {       // Used block
363
+						$angle_to = $angle_from+($block['offset']-$ptr)/$s;
364
+						if(($angle_to+$fuzz)>1) $angle_to = 1;
365
+						if( ($angle_to*360) - ($angle_from*360) >= 1) {
366
+							fill_arc($image,$x,$y,$size,$angle_from*360,$angle_to*360,$col_black,$col_red);
367
+							if (($angle_to-$angle_from)>0.05) {
368
+								array_push($string_placement, array($angle_from,$angle_to));
369
+							}
370
+						}
371
+						$angle_from = $angle_to;
372
+					}
373
+					$angle_to = $angle_from+($block['size'])/$s;
364 374
 					if(($angle_to+$fuzz)>1) $angle_to = 1;
365 375
 					if( ($angle_to*360) - ($angle_from*360) >= 1) {
366
-						fill_arc($image,$x,$y,$size,$angle_from*360,$angle_to*360,$col_black,$col_red);
376
+						fill_arc($image,$x,$y,$size,$angle_from*360,$angle_to*360,$col_black,$col_green);
367 377
 						if (($angle_to-$angle_from)>0.05) {
368 378
 							array_push($string_placement, array($angle_from,$angle_to));
369 379
 						}
370 380
 					}
371 381
 					$angle_from = $angle_to;
382
+					$ptr = $block['offset']+$block['size'];
372 383
 				}
373
-				$angle_to = $angle_from+($block['size'])/$s;
374
-				if(($angle_to+$fuzz)>1) $angle_to = 1;
375
-				if( ($angle_to*360) - ($angle_from*360) >= 1) {
376
-					fill_arc($image,$x,$y,$size,$angle_from*360,$angle_to*360,$col_black,$col_green);
384
+				if ($ptr < $mem['seg_size']) { // memory at the end
385
+					$angle_to = $angle_from + ($mem['seg_size'] - $ptr)/$s;
386
+					if(($angle_to+$fuzz)>1) $angle_to = 1;
387
+					fill_arc($image,$x,$y,$size,$angle_from*360,$angle_to*360,$col_black,$col_red);
377 388
 					if (($angle_to-$angle_from)>0.05) {
378 389
 						array_push($string_placement, array($angle_from,$angle_to));
379 390
 					}
380 391
 				}
381
-				$angle_from = $angle_to;
382
-				$ptr = $block['offset']+$block['size'];
383 392
 			}
384
-			if ($ptr < $mem['seg_size']) { // memory at the end
385
-				$angle_to = $angle_from + ($mem['seg_size'] - $ptr)/$s;
386
-				if(($angle_to+$fuzz)>1) $angle_to = 1;
387
-				fill_arc($image,$x,$y,$size,$angle_from*360,$angle_to*360,$col_black,$col_red);
388
-				if (($angle_to-$angle_from)>0.05) {
389
-					array_push($string_placement, array($angle_from,$angle_to));
390
-				}
393
+			foreach ($string_placement as $angle) {
394
+				text_arc($image,$x,$y,$size,$angle[0]*360,$angle[1]*360,$col_black,bsize($s*($angle[1]-$angle[0])));
391 395
 			}
392
-		}
393
-		foreach ($string_placement as $angle) {
394
-			text_arc($image,$x,$y,$size,$angle[0]*360,$angle[1]*360,$col_black,bsize($s*($angle[1]-$angle[0])));
395
-		}
396
-		break;
397
-
398
-	case 2:
399
-		$s=$cache['num_hits']+$cache['num_misses'];
400
-		$a=$cache['num_hits'];
396
+			break;
401 397
 
402
-		fill_box($image, 30,$size,50,$s ? (-$a*($size-21)/$s) : 0,$col_black,$col_green,sprintf("%.1f%%",$s ? $cache['num_hits']*100/$s : 0));
403
-		fill_box($image,130,$size,50,$s ? -max(4,($s-$a)*($size-21)/$s) : 0,$col_black,$col_red,sprintf("%.1f%%",$s ? $cache['num_misses']*100/$s : 0));
404
-		break;
405
-
406
-	case 3:
407
-		$s=$mem['num_seg']*$mem['seg_size'];
408
-		$a=$mem['avail_mem'];
409
-		$x=130;
410
-		$y=1;
411
-		$j=1;
398
+		case 2:
399
+			$s=$cache['num_hits']+$cache['num_misses'];
400
+			$a=$cache['num_hits'];
412 401
 
413
-		// This block of code creates the bar chart.  It is a lot more complex than you
414
-		// would expect because we try to visualize any memory fragmentation as well.
415
-		for($i=0; $i<$mem['num_seg']; $i++) {
416
-			$ptr = 0;
417
-			$free = $mem['block_lists'][$i];
418
-			uasort($free, 'block_sort');
419
-			foreach($free as $block) {
420
-				if($block['offset']!=$ptr) {       // Used block
421
-					$h=(GRAPH_SIZE-5)*($block['offset']-$ptr)/$s;
402
+			fill_box($image, 30,$size,50,$s ? (-$a*($size-21)/$s) : 0,$col_black,$col_green,sprintf("%.1f%%",$s ? $cache['num_hits']*100/$s : 0));
403
+			fill_box($image,130,$size,50,$s ? -max(4,($s-$a)*($size-21)/$s) : 0,$col_black,$col_red,sprintf("%.1f%%",$s ? $cache['num_misses']*100/$s : 0));
404
+			break;
405
+
406
+		case 3:
407
+			$s=$mem['num_seg']*$mem['seg_size'];
408
+			$a=$mem['avail_mem'];
409
+			$x=130;
410
+			$y=1;
411
+			$j=1;
412
+
413
+			// This block of code creates the bar chart.  It is a lot more complex than you
414
+			// would expect because we try to visualize any memory fragmentation as well.
415
+			for($i=0; $i<$mem['num_seg']; $i++) {
416
+				$ptr = 0;
417
+				$free = $mem['block_lists'][$i];
418
+				uasort($free, 'block_sort');
419
+				foreach($free as $block) {
420
+					if($block['offset']!=$ptr) {       // Used block
421
+						$h=(GRAPH_SIZE-5)*($block['offset']-$ptr)/$s;
422
+						if ($h>0) {
423
+                                                	$j++;
424
+							if($j<75) fill_box($image,$x,$y,50,$h,$col_black,$col_red,bsize($block['offset']-$ptr),$j);
425
+                                                	else fill_box($image,$x,$y,50,$h,$col_black,$col_red);
426
+                                        	}
427
+						$y+=$h;
428
+					}
429
+					$h=(GRAPH_SIZE-5)*($block['size'])/$s;
422 430
 					if ($h>0) {
423
-                                                $j++;
424
-						if($j<75) fill_box($image,$x,$y,50,$h,$col_black,$col_red,bsize($block['offset']-$ptr),$j);
425
-                                                else fill_box($image,$x,$y,50,$h,$col_black,$col_red);
426
-                                        }
431
+                                        	$j++;
432
+						if($j<75) fill_box($image,$x,$y,50,$h,$col_black,$col_green,bsize($block['size']),$j);
433
+						else fill_box($image,$x,$y,50,$h,$col_black,$col_green);
434
+                                	}
427 435
 					$y+=$h;
436
+					$ptr = $block['offset']+$block['size'];
428 437
 				}
429
-				$h=(GRAPH_SIZE-5)*($block['size'])/$s;
430
-				if ($h>0) {
431
-                                        $j++;
432
-					if($j<75) fill_box($image,$x,$y,50,$h,$col_black,$col_green,bsize($block['size']),$j);
433
-					else fill_box($image,$x,$y,50,$h,$col_black,$col_green);
434
-                                }
435
-				$y+=$h;
436
-				$ptr = $block['offset']+$block['size'];
437
-			}
438
-			if ($ptr < $mem['seg_size']) { // memory at the end
439
-				$h = (GRAPH_SIZE-5) * ($mem['seg_size'] - $ptr) / $s;
440
-				if ($h > 0) {
441
-					fill_box($image,$x,$y,50,$h,$col_black,$col_red,bsize($mem['seg_size']-$ptr),$j++);
438
+				if ($ptr < $mem['seg_size']) { // memory at the end
439
+					$h = (GRAPH_SIZE-5) * ($mem['seg_size'] - $ptr) / $s;
440
+					if ($h > 0) {
441
+						fill_box($image,$x,$y,50,$h,$col_black,$col_red,bsize($mem['seg_size']-$ptr),$j++);
442
+					}
442 443
 				}
443 444
 			}
444
-		}
445
-		break;
445
+			break;
446 446
 
447 447
 		case 4:
448 448
 			$s=$cache['num_hits']+$cache['num_misses'];
@@ -769,40 +769,40 @@  discard block
 block discarded – undo
769 769
 // -----------------------------------------------
770 770
 // Host Stats
771 771
 // -----------------------------------------------
772
-case OB_HOST_STATS:
773
-	$mem_size = $mem['num_seg']*$mem['seg_size'];
774
-	$mem_avail= $mem['avail_mem'];
775
-	$mem_used = $mem_size-$mem_avail;
776
-	$seg_size = bsize($mem['seg_size']);
777
-	$req_rate_user = sprintf("%.2f", $cache['num_hits'] ? (($cache['num_hits']+$cache['num_misses'])/($time-$cache['start_time'])) : 0);
778
-	$hit_rate_user = sprintf("%.2f", $cache['num_hits'] ? (($cache['num_hits'])/($time-$cache['start_time'])) : 0);
779
-	$miss_rate_user = sprintf("%.2f", $cache['num_misses'] ? (($cache['num_misses'])/($time-$cache['start_time'])) : 0);
780
-	$insert_rate_user = sprintf("%.2f", $cache['num_inserts'] ? (($cache['num_inserts'])/($time-$cache['start_time'])) : 0);
781
-	$apcversion = phpversion('apcu');
782
-	$phpversion = phpversion();
783
-	$number_vars = $cache['num_entries'];
784
-    $size_vars = bsize($cache['mem_size']);
785
-	$i=0;
786
-	echo <<< EOB
772
+	case OB_HOST_STATS:
773
+		$mem_size = $mem['num_seg']*$mem['seg_size'];
774
+		$mem_avail= $mem['avail_mem'];
775
+		$mem_used = $mem_size-$mem_avail;
776
+		$seg_size = bsize($mem['seg_size']);
777
+		$req_rate_user = sprintf("%.2f", $cache['num_hits'] ? (($cache['num_hits']+$cache['num_misses'])/($time-$cache['start_time'])) : 0);
778
+		$hit_rate_user = sprintf("%.2f", $cache['num_hits'] ? (($cache['num_hits'])/($time-$cache['start_time'])) : 0);
779
+		$miss_rate_user = sprintf("%.2f", $cache['num_misses'] ? (($cache['num_misses'])/($time-$cache['start_time'])) : 0);
780
+		$insert_rate_user = sprintf("%.2f", $cache['num_inserts'] ? (($cache['num_inserts'])/($time-$cache['start_time'])) : 0);
781
+		$apcversion = phpversion('apcu');
782
+		$phpversion = phpversion();
783
+		$number_vars = $cache['num_entries'];
784
+    	$size_vars = bsize($cache['mem_size']);
785
+		$i=0;
786
+		echo <<< EOB
787 787
 		<div class="info div1"><h2>General Cache Information</h2>
788 788
 		<table cellspacing=0><tbody>
789 789
 		<tr class=tr-0><td class=td-0>APCu Version</td><td>$apcversion</td></tr>
790 790
 		<tr class=tr-1><td class=td-0>PHP Version</td><td>$phpversion</td></tr>
791
-EOB;
791
+	EOB;
792 792
 
793
-	if(!empty($_SERVER['SERVER_NAME']))
794
-		echo "<tr class=tr-0><td class=td-0>APCu Host</td><td>{$_SERVER['SERVER_NAME']} $host</td></tr>\n";
795
-	if(!empty($_SERVER['SERVER_SOFTWARE']))
796
-		echo "<tr class=tr-1><td class=td-0>Server Software</td><td>{$_SERVER['SERVER_SOFTWARE']}</td></tr>\n";
793
+		if(!empty($_SERVER['SERVER_NAME']))
794
+			echo "<tr class=tr-0><td class=td-0>APCu Host</td><td>{$_SERVER['SERVER_NAME']} $host</td></tr>\n";
795
+		if(!empty($_SERVER['SERVER_SOFTWARE']))
796
+			echo "<tr class=tr-1><td class=td-0>Server Software</td><td>{$_SERVER['SERVER_SOFTWARE']}</td></tr>\n";
797 797
 
798
-	echo <<<EOB
799
-		<tr class=tr-0><td class=td-0>Shared Memory</td><td>{$mem['num_seg']} Segment(s) with $seg_size
798
+		echo <<<EOB
799
+			<tr class=tr-0><td class=td-0>Shared Memory</td><td>{$mem['num_seg']} Segment(s) with $seg_size
800 800
     <br/> ({$cache['memory_type']} memory)
801 801
     </td></tr>
802 802
 EOB;
803
-	echo   '<tr class=tr-1><td class=td-0>Start Time</td><td>',date(DATE_FORMAT,$cache['start_time']),'</td></tr>';
804
-	echo   '<tr class=tr-0><td class=td-0>Uptime</td><td>',duration($cache['start_time']),'</td></tr>';
805
-	echo <<<EOB
803
+		echo   '<tr class=tr-1><td class=td-0>Start Time</td><td>',date(DATE_FORMAT,$cache['start_time']),'</td></tr>';
804
+		echo   '<tr class=tr-0><td class=td-0>Uptime</td><td>',duration($cache['start_time']),'</td></tr>';
805
+		echo <<<EOB
806 806
 		</tbody></table>
807 807
 		</div>
808 808
 
@@ -824,46 +824,46 @@  discard block
 block discarded – undo
824 824
 		<div class="info div2"><h2>Runtime Settings</h2><table cellspacing=0><tbody>
825 825
 EOB;
826 826
 
827
-	$j = 0;
828
-	foreach (ini_get_all('apcu') as $k => $v) {
829
-		echo "<tr class=tr-$j><td class=td-0>",$k,"</td><td>",str_replace(',',',<br />',$v['local_value']),"</td></tr>\n";
830
-		$j = 1 - $j;
831
-	}
827
+		$j = 0;
828
+		foreach (ini_get_all('apcu') as $k => $v) {
829
+			echo "<tr class=tr-$j><td class=td-0>",$k,"</td><td>",str_replace(',',',<br />',$v['local_value']),"</td></tr>\n";
830
+			$j = 1 - $j;
831
+		}
832 832
 
833
-	if($mem['num_seg']>1 || $mem['num_seg']==1 && count($mem['block_lists'][0])>1)
834
-		$mem_note = "Memory Usage<br /><font size=-2>(multiple slices indicate fragments)</font>";
835
-	else
836
-		$mem_note = "Memory Usage";
833
+		if($mem['num_seg']>1 || $mem['num_seg']==1 && count($mem['block_lists'][0])>1)
834
+			$mem_note = "Memory Usage<br /><font size=-2>(multiple slices indicate fragments)</font>";
835
+		else
836
+			$mem_note = "Memory Usage";
837 837
 
838
-	echo <<< EOB
838
+		echo <<< EOB
839 839
 		</tbody></table>
840 840
 		</div>
841 841
 
842 842
 		<div class="graph div3"><h2>Host Status Diagrams</h2>
843 843
 		<table cellspacing=0><tbody>
844 844
 EOB;
845
-	$size='width='.(GRAPH_SIZE+50).' height='.(GRAPH_SIZE+10);
846
-echo <<<EOB
845
+		$size='width='.(GRAPH_SIZE+50).' height='.(GRAPH_SIZE+10);
846
+	echo <<<EOB
847 847
 		<tr>
848 848
 		<td class=td-0>$mem_note</td>
849 849
 		<td class=td-1>Hits &amp; Misses</td>
850 850
 		</tr>
851 851
 EOB;
852 852
 
853
-	echo
854
-		graphics_avail() ?
855
-			  '<tr>'.
856
-			  "<td class=td-0><img alt=\"\" $size src=\"$PHP_SELF?IMG=1&$time\"></td>".
857
-			  "<td class=td-1><img alt=\"\" $size src=\"$PHP_SELF?IMG=2&$time\"></td></tr>\n"
858
-			: "",
859
-		'<tr>',
860
-		'<td class=td-0><span class="green box">&nbsp;</span>Free: ',bsize($mem_avail).sprintf(" (%.1f%%)",$mem_avail*100/$mem_size),"</td>\n",
861
-		'<td class=td-1><span class="green box">&nbsp;</span>Hits: ',$cache['num_hits'].@sprintf(" (%.1f%%)",$cache['num_hits']*100/($cache['num_hits']+$cache['num_misses'])),"</td>\n",
862
-		'</tr>',
863
-		'<tr>',
864
-		'<td class=td-0><span class="red box">&nbsp;</span>Used: ',bsize($mem_used).sprintf(" (%.1f%%)",$mem_used *100/$mem_size),"</td>\n",
865
-		'<td class=td-1><span class="red box">&nbsp;</span>Misses: ',$cache['num_misses'].@sprintf(" (%.1f%%)",$cache['num_misses']*100/($cache['num_hits']+$cache['num_misses'])),"</td>\n";
866
-	echo <<< EOB
853
+		echo
854
+			graphics_avail() ?
855
+			  	'<tr>'.
856
+			  	"<td class=td-0><img alt=\"\" $size src=\"$PHP_SELF?IMG=1&$time\"></td>".
857
+			  	"<td class=td-1><img alt=\"\" $size src=\"$PHP_SELF?IMG=2&$time\"></td></tr>\n"
858
+				: "",
859
+			'<tr>',
860
+			'<td class=td-0><span class="green box">&nbsp;</span>Free: ',bsize($mem_avail).sprintf(" (%.1f%%)",$mem_avail*100/$mem_size),"</td>\n",
861
+			'<td class=td-1><span class="green box">&nbsp;</span>Hits: ',$cache['num_hits'].@sprintf(" (%.1f%%)",$cache['num_hits']*100/($cache['num_hits']+$cache['num_misses'])),"</td>\n",
862
+			'</tr>',
863
+			'<tr>',
864
+			'<td class=td-0><span class="red box">&nbsp;</span>Used: ',bsize($mem_used).sprintf(" (%.1f%%)",$mem_used *100/$mem_size),"</td>\n",
865
+			'<td class=td-1><span class="red box">&nbsp;</span>Misses: ',$cache['num_misses'].@sprintf(" (%.1f%%)",$cache['num_misses']*100/($cache['num_hits']+$cache['num_misses'])),"</td>\n";
866
+		echo <<< EOB
867 867
 		</tr>
868 868
 		</tbody></table>
869 869
 
@@ -874,141 +874,141 @@  discard block
 block discarded – undo
874 874
 		<td class=td-0 colspan=2><br/>
875 875
 EOB;
876 876
 
877
-	// Fragementation: (freeseg - 1) / total_seg
878
-	$nseg = $freeseg = $fragsize = $freetotal = 0;
879
-	for($i=0; $i<$mem['num_seg']; $i++) {
880
-		$ptr = 0;
881
-		foreach($mem['block_lists'][$i] as $block) {
882
-			if ($block['offset'] != $ptr) {
883
-				++$nseg;
877
+		// Fragementation: (freeseg - 1) / total_seg
878
+		$nseg = $freeseg = $fragsize = $freetotal = 0;
879
+		for($i=0; $i<$mem['num_seg']; $i++) {
880
+			$ptr = 0;
881
+			foreach($mem['block_lists'][$i] as $block) {
882
+				if ($block['offset'] != $ptr) {
883
+					++$nseg;
884
+				}
885
+				$ptr = $block['offset'] + $block['size'];
886
+                        	/* Only consider blocks <5M for the fragmentation % */
887
+                        	if($block['size']<(5*1024*1024)) $fragsize+=$block['size'];
888
+                        	$freetotal+=$block['size'];
884 889
 			}
885
-			$ptr = $block['offset'] + $block['size'];
886
-                        /* Only consider blocks <5M for the fragmentation % */
887
-                        if($block['size']<(5*1024*1024)) $fragsize+=$block['size'];
888
-                        $freetotal+=$block['size'];
890
+			$freeseg += count($mem['block_lists'][$i]);
889 891
 		}
890
-		$freeseg += count($mem['block_lists'][$i]);
891
-	}
892 892
 
893
-	if ($freeseg > 1) {
894
-		$frag = sprintf("%.2f%% (%s out of %s in %d fragments)", ($fragsize/$freetotal)*100,bsize($fragsize),bsize($freetotal),$freeseg);
895
-	} else {
896
-		$frag = "0%";
897
-	}
893
+		if ($freeseg > 1) {
894
+			$frag = sprintf("%.2f%% (%s out of %s in %d fragments)", ($fragsize/$freetotal)*100,bsize($fragsize),bsize($freetotal),$freeseg);
895
+		} else {
896
+			$frag = "0%";
897
+		}
898 898
 
899
-	if (graphics_avail()) {
900
-		$size='width='.(2*GRAPH_SIZE+150).' height='.(GRAPH_SIZE+10);
899
+		if (graphics_avail()) {
900
+			$size='width='.(2*GRAPH_SIZE+150).' height='.(GRAPH_SIZE+10);
901
+			echo <<<EOB
902
+				<img alt="" $size src="$PHP_SELF?IMG=3&$time">
903
+	EOB;
904
+		}
901 905
 		echo <<<EOB
902
-			<img alt="" $size src="$PHP_SELF?IMG=3&$time">
903
-EOB;
904
-	}
905
-	echo <<<EOB
906
-		</br>Fragmentation: $frag
906
+			</br>Fragmentation: $frag
907 907
 		</td>
908 908
 		</tr>
909 909
 EOB;
910
-        if(isset($mem['adist'])) {
911
-          foreach($mem['adist'] as $i=>$v) {
912
-            $cur = pow(2,$i); $nxt = pow(2,$i+1)-1;
913
-            if($i==0) $range = "1";
914
-            else $range = "$cur - $nxt";
915
-            echo "<tr><th align=right>$range</th><td align=right>$v</td></tr>\n";
916
-          }
917
-        }
918
-        echo <<<EOB
910
+        	if(isset($mem['adist'])) {
911
+          	foreach($mem['adist'] as $i=>$v) {
912
+            	$cur = pow(2,$i); $nxt = pow(2,$i+1)-1;
913
+            	if($i==0) $range = "1";
914
+            	else $range = "$cur - $nxt";
915
+            	echo "<tr><th align=right>$range</th><td align=right>$v</td></tr>\n";
916
+          	}
917
+        	}
918
+        	echo <<<EOB
919 919
 		</tbody></table>
920 920
 		</div>
921 921
 EOB;
922 922
 
923
-	break;
923
+		break;
924 924
 
925 925
 
926
-// -----------------------------------------------
927
-// User Cache Entries
928
-// -----------------------------------------------
929
-case OB_USER_CACHE:
930
-	if (!$AUTHENTICATED) {
931
-    echo '<div class="error">You need to login to see the user values here!<br/>&nbsp;<br/>';
932
-		put_login_link("Login now!");
933
-		echo '</div>';
934
-		break;
935
-	}
936
-	$fieldname='info';
937
-	$fieldheading='User Entry Label';
938
-	$fieldkey='info';
926
+	// -----------------------------------------------
927
+	// User Cache Entries
928
+	// -----------------------------------------------
929
+	case OB_USER_CACHE:
930
+		if (!$AUTHENTICATED) {
931
+    	echo '<div class="error">You need to login to see the user values here!<br/>&nbsp;<br/>';
932
+			put_login_link("Login now!");
933
+			echo '</div>';
934
+			break;
935
+		}
936
+		$fieldname='info';
937
+		$fieldheading='User Entry Label';
938
+		$fieldkey='info';
939 939
 
940
-	$cols=6;
941
-	echo <<<EOB
940
+		$cols=6;
941
+		echo <<<EOB
942 942
 		<div class=sorting><form>Scope:
943 943
 		<input type=hidden name=OB value={$MYREQUEST['OB']}>
944 944
 		<select name=SCOPE>
945 945
 EOB;
946
-	echo
947
-		"<option value=A",$MYREQUEST['SCOPE']=='A' ? " selected":"",">Active</option>",
948
-		"<option value=D",$MYREQUEST['SCOPE']=='D' ? " selected":"",">Deleted</option>",
949
-		"</select>",
950
-		", Sorting:<select name=SORT1>",
951
-		"<option value=H",$MYREQUEST['SORT1']=='H' ? " selected":"",">Hits</option>",
952
-		"<option value=Z",$MYREQUEST['SORT1']=='Z' ? " selected":"",">Size</option>",
953
-		"<option value=S",$MYREQUEST['SORT1']=='S' ? " selected":"",">$fieldheading</option>",
954
-		"<option value=A",$MYREQUEST['SORT1']=='A' ? " selected":"",">Last accessed</option>",
955
-		"<option value=M",$MYREQUEST['SORT1']=='M' ? " selected":"",">Last modified</option>",
956
-		"<option value=C",$MYREQUEST['SORT1']=='C' ? " selected":"",">Created at</option>",
957
-		"<option value=D",$MYREQUEST['SORT1']=='D' ? " selected":"",">Deleted at</option>";
958
-	if($fieldname=='info') echo
959
-		"<option value=D",$MYREQUEST['SORT1']=='T' ? " selected":"",">Timeout</option>";
960
-	echo
961
-		'</select>',
962
-		'<select name=SORT2>',
963
-		'<option value=D',$MYREQUEST['SORT2']=='D' ? ' selected':'','>DESC</option>',
964
-		'<option value=A',$MYREQUEST['SORT2']=='A' ? ' selected':'','>ASC</option>',
965
-		'</select>',
966
-		'<select name=COUNT onChange="form.submit()">',
967
-		'<option value=10 ',$MYREQUEST['COUNT']=='10' ? ' selected':'','>Top 10</option>',
968
-		'<option value=20 ',$MYREQUEST['COUNT']=='20' ? ' selected':'','>Top 20</option>',
969
-		'<option value=50 ',$MYREQUEST['COUNT']=='50' ? ' selected':'','>Top 50</option>',
970
-		'<option value=100',$MYREQUEST['COUNT']=='100'? ' selected':'','>Top 100</option>',
971
-		'<option value=150',$MYREQUEST['COUNT']=='150'? ' selected':'','>Top 150</option>',
972
-		'<option value=200',$MYREQUEST['COUNT']=='200'? ' selected':'','>Top 200</option>',
973
-		'<option value=500',$MYREQUEST['COUNT']=='500'? ' selected':'','>Top 500</option>',
974
-		'<option value=0  ',$MYREQUEST['COUNT']=='0'  ? ' selected':'','>All</option>',
975
-		'</select>',
976
-    '&nbsp; Search: <input name=SEARCH value="',$MYREQUEST['SEARCH'],'" type=text size=25/>',
977
-		'&nbsp;<input type=submit value="GO!">',
978
-		'</form></div>';
979
-
980
-  if (isset($MYREQUEST['SEARCH'])) {
981
-   // Don't use preg_quote because we want the user to be able to specify a
982
-   // regular expression subpattern.
983
-   $MYREQUEST['SEARCH'] = '/'.str_replace('/', '\\/', $MYREQUEST['SEARCH']).'/i';
984
-   if (preg_match($MYREQUEST['SEARCH'], 'test') === false) {
985
-     echo '<div class="error">Error: enter a valid regular expression as a search query.</div>';
986
-     break;
987
-   }
988
-  }
989
-
990
-  echo
991
-		'<div class="info"><table cellspacing=0><tbody>',
992
-		'<tr>',
993
-		'<th>',sortheader('S',$fieldheading,  "&OB=".$MYREQUEST['OB']),'</th>',
994
-		'<th>',sortheader('H','Hits',         "&OB=".$MYREQUEST['OB']),'</th>',
995
-		'<th>',sortheader('Z','Size',         "&OB=".$MYREQUEST['OB']),'</th>',
996
-		'<th>',sortheader('A','Last accessed',"&OB=".$MYREQUEST['OB']),'</th>',
997
-		'<th>',sortheader('M','Last modified',"&OB=".$MYREQUEST['OB']),'</th>',
998
-		'<th>',sortheader('C','Created at',   "&OB=".$MYREQUEST['OB']),'</th>';
999
-
1000
-	if($fieldname=='info') {
1001
-		$cols+=2;
1002
-		 echo '<th>',sortheader('T','Timeout',"&OB=".$MYREQUEST['OB']),'</th>';
1003
-	}
1004
-	echo '<th>',sortheader('D','Deleted at',"&OB=".$MYREQUEST['OB']),'</th></tr>';
946
+		echo
947
+			"<option value=A",$MYREQUEST['SCOPE']=='A' ? " selected":"",">Active</option>",
948
+			"<option value=D",$MYREQUEST['SCOPE']=='D' ? " selected":"",">Deleted</option>",
949
+			"</select>",
950
+			", Sorting:<select name=SORT1>",
951
+			"<option value=H",$MYREQUEST['SORT1']=='H' ? " selected":"",">Hits</option>",
952
+			"<option value=Z",$MYREQUEST['SORT1']=='Z' ? " selected":"",">Size</option>",
953
+			"<option value=S",$MYREQUEST['SORT1']=='S' ? " selected":"",">$fieldheading</option>",
954
+			"<option value=A",$MYREQUEST['SORT1']=='A' ? " selected":"",">Last accessed</option>",
955
+			"<option value=M",$MYREQUEST['SORT1']=='M' ? " selected":"",">Last modified</option>",
956
+			"<option value=C",$MYREQUEST['SORT1']=='C' ? " selected":"",">Created at</option>",
957
+			"<option value=D",$MYREQUEST['SORT1']=='D' ? " selected":"",">Deleted at</option>";
958
+		if($fieldname=='info') echo
959
+			"<option value=D",$MYREQUEST['SORT1']=='T' ? " selected":"",">Timeout</option>";
960
+		echo
961
+			'</select>',
962
+			'<select name=SORT2>',
963
+			'<option value=D',$MYREQUEST['SORT2']=='D' ? ' selected':'','>DESC</option>',
964
+			'<option value=A',$MYREQUEST['SORT2']=='A' ? ' selected':'','>ASC</option>',
965
+			'</select>',
966
+			'<select name=COUNT onChange="form.submit()">',
967
+			'<option value=10 ',$MYREQUEST['COUNT']=='10' ? ' selected':'','>Top 10</option>',
968
+			'<option value=20 ',$MYREQUEST['COUNT']=='20' ? ' selected':'','>Top 20</option>',
969
+			'<option value=50 ',$MYREQUEST['COUNT']=='50' ? ' selected':'','>Top 50</option>',
970
+			'<option value=100',$MYREQUEST['COUNT']=='100'? ' selected':'','>Top 100</option>',
971
+			'<option value=150',$MYREQUEST['COUNT']=='150'? ' selected':'','>Top 150</option>',
972
+			'<option value=200',$MYREQUEST['COUNT']=='200'? ' selected':'','>Top 200</option>',
973
+			'<option value=500',$MYREQUEST['COUNT']=='500'? ' selected':'','>Top 500</option>',
974
+			'<option value=0  ',$MYREQUEST['COUNT']=='0'  ? ' selected':'','>All</option>',
975
+			'</select>',
976
+    	'&nbsp; Search: <input name=SEARCH value="',$MYREQUEST['SEARCH'],'" type=text size=25/>',
977
+			'&nbsp;<input type=submit value="GO!">',
978
+			'</form></div>';
979
+
980
+  	if (isset($MYREQUEST['SEARCH'])) {
981
+   	// Don't use preg_quote because we want the user to be able to specify a
982
+   	// regular expression subpattern.
983
+   	$MYREQUEST['SEARCH'] = '/'.str_replace('/', '\\/', $MYREQUEST['SEARCH']).'/i';
984
+   	if (preg_match($MYREQUEST['SEARCH'], 'test') === false) {
985
+     	echo '<div class="error">Error: enter a valid regular expression as a search query.</div>';
986
+     	break;
987
+   	}
988
+  	}
989
+
990
+  	echo
991
+			'<div class="info"><table cellspacing=0><tbody>',
992
+			'<tr>',
993
+			'<th>',sortheader('S',$fieldheading,  "&OB=".$MYREQUEST['OB']),'</th>',
994
+			'<th>',sortheader('H','Hits',         "&OB=".$MYREQUEST['OB']),'</th>',
995
+			'<th>',sortheader('Z','Size',         "&OB=".$MYREQUEST['OB']),'</th>',
996
+			'<th>',sortheader('A','Last accessed',"&OB=".$MYREQUEST['OB']),'</th>',
997
+			'<th>',sortheader('M','Last modified',"&OB=".$MYREQUEST['OB']),'</th>',
998
+			'<th>',sortheader('C','Created at',   "&OB=".$MYREQUEST['OB']),'</th>';
999
+
1000
+		if($fieldname=='info') {
1001
+			$cols+=2;
1002
+		 	echo '<th>',sortheader('T','Timeout',"&OB=".$MYREQUEST['OB']),'</th>';
1003
+		}
1004
+		echo '<th>',sortheader('D','Deleted at',"&OB=".$MYREQUEST['OB']),'</th></tr>';
1005 1005
 
1006
-	// builds list with alpha numeric sortable keys
1007
-	//
1008
-	$list = array();
1006
+		// builds list with alpha numeric sortable keys
1007
+		//
1008
+		$list = array();
1009 1009
 
1010
-	foreach($cache[$scope_list[$MYREQUEST['SCOPE']]] as $i => $entry) {
1011
-		switch($MYREQUEST['SORT1']) {
1010
+		foreach($cache[$scope_list[$MYREQUEST['SCOPE']]] as $i => $entry) {
1011
+			switch($MYREQUEST['SORT1']) {
1012 1012
 			case 'A': $k=sprintf('%015d-',$entry['access_time']);  	     break;
1013 1013
 			case 'H': $k=sprintf('%015d-',$entry['num_hits']); 	     break;
1014 1014
 			case 'Z': $k=sprintf('%015d-',$entry['mem_size']); 	     break;
@@ -1017,7 +1017,7 @@  discard block
 block discarded – undo
1017 1017
 			case 'T': $k=sprintf('%015d-',$entry['ttl']);		     break;
1018 1018
 			case 'D': $k=sprintf('%015d-',$entry['deletion_time']);      break;
1019 1019
 			case 'S': $k=$entry["info"];				     break;
1020
-		}
1020
+			}
1021 1021
 		if (!$AUTHENTICATED) {
1022 1022
 			// hide all path entries if not logged in
1023 1023
 			$list[$k.$entry[$fieldname]]=preg_replace('/^.*(\\/|\\\\)/','*hidden*/',$entry);
@@ -1097,61 +1097,61 @@  discard block
 block discarded – undo
1097 1097
 // -----------------------------------------------
1098 1098
 // Version check
1099 1099
 // -----------------------------------------------
1100
-case OB_VERSION_CHECK:
1101
-	echo <<<EOB
1100
+	case OB_VERSION_CHECK:
1101
+		echo <<<EOB
1102 1102
 		<div class="info"><h2>APCu Version Information</h2>
1103 1103
 		<table cellspacing=0><tbody>
1104 1104
 		<tr>
1105 1105
 		<th></th>
1106 1106
 		</tr>
1107 1107
 EOB;
1108
-  if (defined('PROXY')) {
1109
-    $ctxt = stream_context_create( array( 'http' => array( 'proxy' => PROXY, 'request_fulluri' => True ) ) );
1110
-    $rss = @file_get_contents("http://pecl.php.net/feeds/pkg_apcu.rss", False, $ctxt);
1111
-  } else {
1112
-    $rss = @file_get_contents("http://pecl.php.net/feeds/pkg_apcu.rss");
1113
-  }
1114
-	if (!$rss) {
1115
-		echo '<tr class="td-last center"><td>Unable to fetch version information.</td></tr>';
1116
-	} else {
1117
-		$apcversion = phpversion('apcu');
1118
-
1119
-		preg_match('!<title>APCu ([0-9.]+)</title>!', $rss, $match);
1120
-		echo '<tr class="tr-0 center"><td>';
1121
-		if (version_compare($apcversion, $match[1], '>=')) {
1122
-			echo '<div class="ok">You are running the latest version of APCu ('.$apcversion.')</div>';
1123
-			$i = 3;
1108
+  	if (defined('PROXY')) {
1109
+    	$ctxt = stream_context_create( array( 'http' => array( 'proxy' => PROXY, 'request_fulluri' => True ) ) );
1110
+    	$rss = @file_get_contents("http://pecl.php.net/feeds/pkg_apcu.rss", False, $ctxt);
1111
+  	} else {
1112
+    	$rss = @file_get_contents("http://pecl.php.net/feeds/pkg_apcu.rss");
1113
+  	}
1114
+		if (!$rss) {
1115
+			echo '<tr class="td-last center"><td>Unable to fetch version information.</td></tr>';
1124 1116
 		} else {
1125
-			echo '<div class="failed">You are running an older version of APCu ('.$apcversion.'),
1117
+			$apcversion = phpversion('apcu');
1118
+
1119
+			preg_match('!<title>APCu ([0-9.]+)</title>!', $rss, $match);
1120
+			echo '<tr class="tr-0 center"><td>';
1121
+			if (version_compare($apcversion, $match[1], '>=')) {
1122
+				echo '<div class="ok">You are running the latest version of APCu ('.$apcversion.')</div>';
1123
+				$i = 3;
1124
+			} else {
1125
+				echo '<div class="failed">You are running an older version of APCu ('.$apcversion.'),
1126 1126
 				newer version '.$match[1].' is available at <a href="http://pecl.php.net/package/APCu/'.$match[1].'">
1127 1127
 				http://pecl.php.net/package/APCu/'.$match[1].'</a>
1128 1128
 				</div>';
1129
-			$i = -1;
1130
-		}
1131
-		echo '</td></tr>';
1132
-		echo '<tr class="tr-0"><td><h3>Change Log:</h3><br/>';
1133
-
1134
-		preg_match_all('!<(title|description)>([^<]+)</\\1>!', $rss, $match);
1135
-		next($match[2]); next($match[2]);
1136
-
1137
-		while (list(,$v) = each($match[2])) {
1138
-			list(,$ver) = explode(' ', $v, 2);
1139
-			if ($i < 0 && version_compare($apcversion, $ver, '>=')) {
1140
-				break;
1141
-			} else if (!$i--) {
1142
-				break;
1129
+				$i = -1;
1130
+			}
1131
+			echo '</td></tr>';
1132
+			echo '<tr class="tr-0"><td><h3>Change Log:</h3><br/>';
1133
+
1134
+			preg_match_all('!<(title|description)>([^<]+)</\\1>!', $rss, $match);
1135
+			next($match[2]); next($match[2]);
1136
+
1137
+			while (list(,$v) = each($match[2])) {
1138
+				list(,$ver) = explode(' ', $v, 2);
1139
+				if ($i < 0 && version_compare($apcversion, $ver, '>=')) {
1140
+					break;
1141
+				} else if (!$i--) {
1142
+					break;
1143
+				}
1144
+				echo "<b><a href=\"http://pecl.php.net/package/APCu/$ver\">".htmlspecialchars($v, ENT_QUOTES, 'UTF-8')."</a></b><br><blockquote>";
1145
+				echo nl2br(htmlspecialchars(current($match[2]), ENT_QUOTES, 'UTF-8'))."</blockquote>";
1146
+				next($match[2]);
1143 1147
 			}
1144
-			echo "<b><a href=\"http://pecl.php.net/package/APCu/$ver\">".htmlspecialchars($v, ENT_QUOTES, 'UTF-8')."</a></b><br><blockquote>";
1145
-			echo nl2br(htmlspecialchars(current($match[2]), ENT_QUOTES, 'UTF-8'))."</blockquote>";
1146
-			next($match[2]);
1148
+			echo '</td></tr>';
1147 1149
 		}
1148
-		echo '</td></tr>';
1149
-	}
1150
-	echo <<< EOB
1150
+		echo <<< EOB
1151 1151
 		</tbody></table>
1152 1152
 		</div>
1153 1153
 EOB;
1154
-	break;
1154
+		break;
1155 1155
 
1156 1156
 }
1157 1157
 
Please login to merge, or discard this patch.
Spacing   +282 added lines, -282 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 );
16 16
 include('../header.inc.php');
17 17
 
18
-if ($GLOBALS['egw']->acl->check('info_access',1,'admin'))
18
+if ($GLOBALS['egw']->acl->check('info_access', 1, 'admin'))
19 19
 {
20 20
 	$GLOBALS['egw']->redirect_link('/index.php');
21 21
 }
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 
44 44
  */
45 45
 
46
-$VERSION='$Id$';
46
+$VERSION = '$Id$';
47 47
 
48 48
 ////////// READ OPTIONAL CONFIGURATION FILE ////////////
49 49
 if (file_exists("apc.conf.php")) include("apc.conf.php");
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 
52 52
 ////////// BEGIN OF DEFAULT CONFIG AREA ///////////////////////////////////////////////////////////
53 53
 
54
-defaults('USE_AUTHENTICATION',1);			// Use (internal) authentication - best choice if
54
+defaults('USE_AUTHENTICATION', 1); // Use (internal) authentication - best choice if
55 55
 											// no other authentication is available
56 56
 											// If set to 0:
57 57
 											//  There will be no further authentication. You
@@ -59,16 +59,16 @@  discard block
 block discarded – undo
59 59
 											// If set to 1:
60 60
 											//  You need to change ADMIN_PASSWORD to make
61 61
 											//  this work!
62
-defaults('ADMIN_USERNAME','apc'); 			// Admin Username
63
-defaults('ADMIN_PASSWORD','password');  	// Admin Password - CHANGE THIS TO ENABLE!!!
62
+defaults('ADMIN_USERNAME', 'apc'); // Admin Username
63
+defaults('ADMIN_PASSWORD', 'password'); // Admin Password - CHANGE THIS TO ENABLE!!!
64 64
 
65 65
 // (beckerr) I'm using a clear text password here, because I've no good idea how to let
66 66
 //           users generate a md5 or crypt password in a easy way to fill it in above
67 67
 
68 68
 //defaults('DATE_FORMAT', "d.m.Y H:i:s");	// German
69
-defaults('DATE_FORMAT', 'Y/m/d H:i:s'); 	// US
69
+defaults('DATE_FORMAT', 'Y/m/d H:i:s'); // US
70 70
 
71
-defaults('GRAPH_SIZE',200);					// Image size
71
+defaults('GRAPH_SIZE', 200); // Image size
72 72
 
73 73
 //defaults('PROXY', 'tcp://127.0.0.1:8080');
74 74
 
@@ -76,45 +76,45 @@  discard block
 block discarded – undo
76 76
 
77 77
 
78 78
 // "define if not defined"
79
-function defaults($d,$v) {
80
-	if (!defined($d)) define($d,$v); // or just @define(...)
79
+function defaults($d, $v) {
80
+	if (!defined($d)) define($d, $v); // or just @define(...)
81 81
 }
82 82
 
83 83
 // rewrite $PHP_SELF to block XSS attacks
84 84
 //
85
-$PHP_SELF= isset($_SERVER['PHP_SELF']) ? htmlentities(strip_tags($_SERVER['PHP_SELF'],''), ENT_QUOTES, 'UTF-8') : '';
85
+$PHP_SELF = isset($_SERVER['PHP_SELF']) ? htmlentities(strip_tags($_SERVER['PHP_SELF'], ''), ENT_QUOTES, 'UTF-8') : '';
86 86
 $time = time();
87 87
 $host = php_uname('n');
88
-if($host) { $host = '('.$host.')'; }
88
+if ($host) { $host = '('.$host.')'; }
89 89
 if (isset($_SERVER['SERVER_ADDR'])) {
90 90
   $host .= ' ('.$_SERVER['SERVER_ADDR'].')';
91 91
 }
92 92
 
93 93
 // operation constants
94
-define('OB_HOST_STATS',1);
95
-define('OB_USER_CACHE',2);
96
-define('OB_VERSION_CHECK',3);
94
+define('OB_HOST_STATS', 1);
95
+define('OB_USER_CACHE', 2);
96
+define('OB_VERSION_CHECK', 3);
97 97
 
98 98
 // check validity of input variables
99
-$vardom=array(
100
-	'OB'	=> '/^\d+$/',			// operational mode switch
101
-	'CC'	=> '/^[01]$/',			// clear cache requested
102
-	'DU'	=> '/^.*$/',			// Delete User Key
103
-	'SH'	=> '/^[a-z0-9]+$/',		// shared object description
104
-
105
-	'IMG'	=> '/^[123]$/',			// image to generate
106
-	'LO'	=> '/^1$/',				// login requested
107
-
108
-	'COUNT'	=> '/^\d+$/',			// number of line displayed in list
109
-	'SCOPE'	=> '/^[AD]$/',			// list view scope
110
-	'SORT1'	=> '/^[AHSMCDTZ]$/',	// first sort key
111
-	'SORT2'	=> '/^[DA]$/',			// second sort key
112
-	'AGGR'	=> '/^\d+$/',			// aggregation by dir level
99
+$vardom = array(
100
+	'OB'	=> '/^\d+$/', // operational mode switch
101
+	'CC'	=> '/^[01]$/', // clear cache requested
102
+	'DU'	=> '/^.*$/', // Delete User Key
103
+	'SH'	=> '/^[a-z0-9]+$/', // shared object description
104
+
105
+	'IMG'	=> '/^[123]$/', // image to generate
106
+	'LO'	=> '/^1$/', // login requested
107
+
108
+	'COUNT'	=> '/^\d+$/', // number of line displayed in list
109
+	'SCOPE'	=> '/^[AD]$/', // list view scope
110
+	'SORT1'	=> '/^[AHSMCDTZ]$/', // first sort key
111
+	'SORT2'	=> '/^[DA]$/', // second sort key
112
+	'AGGR'	=> '/^\d+$/', // aggregation by dir level
113 113
 	'SEARCH'	=> '~^[a-zA-Z0-9/_.-]*$~'			// aggregation by dir level
114 114
 );
115 115
 
116 116
 // cache scope
117
-$scope_list=array(
117
+$scope_list = array(
118 118
 	'A' => 'cache_list',
119 119
 	'D' => 'deleted_list'
120 120
 );
@@ -133,31 +133,31 @@  discard block
 block discarded – undo
133 133
 }
134 134
 
135 135
 // check parameter syntax
136
-foreach($vardom as $var => $dom) {
136
+foreach ($vardom as $var => $dom) {
137 137
 	if (!isset($_REQUEST[$var])) {
138
-		$MYREQUEST[$var]=NULL;
139
-	} else if (!is_array($_REQUEST[$var]) && preg_match($dom.'D',$_REQUEST[$var])) {
140
-		$MYREQUEST[$var]=$_REQUEST[$var];
138
+		$MYREQUEST[$var] = NULL;
139
+	} else if (!is_array($_REQUEST[$var]) && preg_match($dom.'D', $_REQUEST[$var])) {
140
+		$MYREQUEST[$var] = $_REQUEST[$var];
141 141
 	} else {
142
-		$MYREQUEST[$var]=$_REQUEST[$var]=NULL;
142
+		$MYREQUEST[$var] = $_REQUEST[$var] = NULL;
143 143
 	}
144 144
 }
145 145
 
146 146
 // check parameter sematics
147
-if (empty($MYREQUEST['SCOPE'])) $MYREQUEST['SCOPE']="A";
148
-if (empty($MYREQUEST['SORT1'])) $MYREQUEST['SORT1']="H";
149
-if (empty($MYREQUEST['SORT2'])) $MYREQUEST['SORT2']="D";
150
-if (empty($MYREQUEST['OB']))	$MYREQUEST['OB']=OB_HOST_STATS;
151
-if (!isset($MYREQUEST['COUNT'])) $MYREQUEST['COUNT']=20;
152
-if (!isset($scope_list[$MYREQUEST['SCOPE']])) $MYREQUEST['SCOPE']='A';
153
-
154
-$MY_SELF=
147
+if (empty($MYREQUEST['SCOPE'])) $MYREQUEST['SCOPE'] = "A";
148
+if (empty($MYREQUEST['SORT1'])) $MYREQUEST['SORT1'] = "H";
149
+if (empty($MYREQUEST['SORT2'])) $MYREQUEST['SORT2'] = "D";
150
+if (empty($MYREQUEST['OB']))	$MYREQUEST['OB'] = OB_HOST_STATS;
151
+if (!isset($MYREQUEST['COUNT'])) $MYREQUEST['COUNT'] = 20;
152
+if (!isset($scope_list[$MYREQUEST['SCOPE']])) $MYREQUEST['SCOPE'] = 'A';
153
+
154
+$MY_SELF =
155 155
 	"$PHP_SELF".
156 156
 	"?SCOPE=".$MYREQUEST['SCOPE'].
157 157
 	"&SORT1=".$MYREQUEST['SORT1'].
158 158
 	"&SORT2=".$MYREQUEST['SORT2'].
159 159
 	"&COUNT=".$MYREQUEST['COUNT'];
160
-$MY_SELF_WO_SORT=
160
+$MY_SELF_WO_SORT =
161 161
 	"$PHP_SELF".
162 162
 	"?SCOPE=".$MYREQUEST['SCOPE'].
163 163
 	"&COUNT=".$MYREQUEST['COUNT'];
@@ -165,10 +165,10 @@  discard block
 block discarded – undo
165 165
 // authentication needed?
166 166
 //
167 167
 if (!USE_AUTHENTICATION) {
168
-	$AUTHENTICATED=1;
168
+	$AUTHENTICATED = 1;
169 169
 } else {
170
-	$AUTHENTICATED=0;
171
-	if (ADMIN_PASSWORD!='password' && ($MYREQUEST['LO'] == 1 || isset($_SERVER['PHP_AUTH_USER']))) {
170
+	$AUTHENTICATED = 0;
171
+	if (ADMIN_PASSWORD != 'password' && ($MYREQUEST['LO'] == 1 || isset($_SERVER['PHP_AUTH_USER']))) {
172 172
 
173 173
 		if (!isset($_SERVER['PHP_AUTH_USER']) ||
174 174
 			!isset($_SERVER['PHP_AUTH_PW']) ||
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 			exit;
188 188
 
189 189
 		} else {
190
-			$AUTHENTICATED=1;
190
+			$AUTHENTICATED = 1;
191 191
 		}
192 192
 	}
193 193
 }
@@ -201,39 +201,39 @@  discard block
 block discarded – undo
201 201
 	apcu_delete($MYREQUEST['DU']);
202 202
 }
203 203
 
204
-if(!function_exists('apcu_cache_info')) {
204
+if (!function_exists('apcu_cache_info')) {
205 205
 	echo "No cache info available.  APC does not appear to be running.";
206 206
   exit;
207 207
 }
208 208
 
209 209
 $cache = apcu_cache_info();
210 210
 
211
-$mem=apcu_sma_info();
211
+$mem = apcu_sma_info();
212 212
 
213 213
 // don't cache this page
214 214
 //
215
-header("Cache-Control: no-store, no-cache, must-revalidate");  // HTTP/1.1
215
+header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
216 216
 header("Cache-Control: post-check=0, pre-check=0", false);
217
-header("Pragma: no-cache");                                    // HTTP/1.0
217
+header("Pragma: no-cache"); // HTTP/1.0
218 218
 
219 219
 function duration($ts) {
220 220
     global $time;
221
-    $years = (int)((($time - $ts)/(7*86400))/52.177457);
222
-    $rem = (int)(($time-$ts)-($years * 52.177457 * 7 * 86400));
223
-    $weeks = (int)(($rem)/(7*86400));
224
-    $days = (int)(($rem)/86400) - $weeks*7;
225
-    $hours = (int)(($rem)/3600) - $days*24 - $weeks*7*24;
226
-    $mins = (int)(($rem)/60) - $hours*60 - $days*24*60 - $weeks*7*24*60;
221
+    $years = (int)((($time - $ts) / (7 * 86400)) / 52.177457);
222
+    $rem = (int)(($time - $ts) - ($years * 52.177457 * 7 * 86400));
223
+    $weeks = (int)(($rem) / (7 * 86400));
224
+    $days = (int)(($rem) / 86400) - $weeks * 7;
225
+    $hours = (int)(($rem) / 3600) - $days * 24 - $weeks * 7 * 24;
226
+    $mins = (int)(($rem) / 60) - $hours * 60 - $days * 24 * 60 - $weeks * 7 * 24 * 60;
227 227
     $str = '';
228
-    if($years==1) $str .= "$years year, ";
229
-    if($years>1) $str .= "$years years, ";
230
-    if($weeks==1) $str .= "$weeks week, ";
231
-    if($weeks>1) $str .= "$weeks weeks, ";
232
-    if($days==1) $str .= "$days day,";
233
-    if($days>1) $str .= "$days days,";
234
-    if($hours == 1) $str .= " $hours hour and";
235
-    if($hours>1) $str .= " $hours hours and";
236
-    if($mins == 1) $str .= " 1 minute";
228
+    if ($years == 1) $str .= "$years year, ";
229
+    if ($years > 1) $str .= "$years years, ";
230
+    if ($weeks == 1) $str .= "$weeks week, ";
231
+    if ($weeks > 1) $str .= "$weeks weeks, ";
232
+    if ($days == 1) $str .= "$days day,";
233
+    if ($days > 1) $str .= "$days days,";
234
+    if ($hours == 1) $str .= " $hours hour and";
235
+    if ($hours > 1) $str .= " $hours hours and";
236
+    if ($mins == 1) $str .= " 1 minute";
237 237
     else $str .= " $mins minutes";
238 238
     return $str;
239 239
 }
@@ -249,207 +249,207 @@  discard block
 block discarded – undo
249 249
 		exit(0);
250 250
 	}
251 251
 
252
-	function fill_arc($im, $centerX, $centerY, $diameter, $start, $end, $color1,$color2,$text='',$placeindex=0) {
253
-		$r=$diameter/2;
254
-		$w=deg2rad((360+$start+($end-$start)/2)%360);
252
+	function fill_arc($im, $centerX, $centerY, $diameter, $start, $end, $color1, $color2, $text = '', $placeindex = 0) {
253
+		$r = $diameter / 2;
254
+		$w = deg2rad((360 + $start + ($end - $start) / 2) % 360);
255 255
 
256 256
 
257 257
 		if (function_exists("imagefilledarc")) {
258 258
 			// exists only if GD 2.0.1 is avaliable
259
-			imagefilledarc($im, $centerX+1, $centerY+1, $diameter, $diameter, $start, $end, $color1, IMG_ARC_PIE);
259
+			imagefilledarc($im, $centerX + 1, $centerY + 1, $diameter, $diameter, $start, $end, $color1, IMG_ARC_PIE);
260 260
 			imagefilledarc($im, $centerX, $centerY, $diameter, $diameter, $start, $end, $color2, IMG_ARC_PIE);
261 261
 			imagefilledarc($im, $centerX, $centerY, $diameter, $diameter, $start, $end, $color1, IMG_ARC_NOFILL|IMG_ARC_EDGED);
262 262
 		} else {
263 263
 			imagearc($im, $centerX, $centerY, $diameter, $diameter, $start, $end, $color2);
264 264
 			imageline($im, $centerX, $centerY, $centerX + cos(deg2rad($start)) * $r, $centerY + sin(deg2rad($start)) * $r, $color2);
265
-			imageline($im, $centerX, $centerY, $centerX + cos(deg2rad($start+1)) * $r, $centerY + sin(deg2rad($start)) * $r, $color2);
266
-			imageline($im, $centerX, $centerY, $centerX + cos(deg2rad($end-1))   * $r, $centerY + sin(deg2rad($end))   * $r, $color2);
267
-			imageline($im, $centerX, $centerY, $centerX + cos(deg2rad($end))   * $r, $centerY + sin(deg2rad($end))   * $r, $color2);
268
-			imagefill($im,$centerX + $r*cos($w)/2, $centerY + $r*sin($w)/2, $color2);
265
+			imageline($im, $centerX, $centerY, $centerX + cos(deg2rad($start + 1)) * $r, $centerY + sin(deg2rad($start)) * $r, $color2);
266
+			imageline($im, $centerX, $centerY, $centerX + cos(deg2rad($end - 1)) * $r, $centerY + sin(deg2rad($end)) * $r, $color2);
267
+			imageline($im, $centerX, $centerY, $centerX + cos(deg2rad($end)) * $r, $centerY + sin(deg2rad($end)) * $r, $color2);
268
+			imagefill($im, $centerX + $r * cos($w) / 2, $centerY + $r * sin($w) / 2, $color2);
269 269
 		}
270 270
 		if ($text) {
271
-			if ($placeindex>0) {
272
-				imageline($im,$centerX + $r*cos($w)/2, $centerY + $r*sin($w)/2,$diameter, $placeindex*12,$color1);
273
-				imagestring($im,4,$diameter, $placeindex*12,$text,$color1);
271
+			if ($placeindex > 0) {
272
+				imageline($im, $centerX + $r * cos($w) / 2, $centerY + $r * sin($w) / 2, $diameter, $placeindex * 12, $color1);
273
+				imagestring($im, 4, $diameter, $placeindex * 12, $text, $color1);
274 274
 
275 275
 			} else {
276
-				imagestring($im,4,$centerX + $r*cos($w)/2, $centerY + $r*sin($w)/2,$text,$color1);
276
+				imagestring($im, 4, $centerX + $r * cos($w) / 2, $centerY + $r * sin($w) / 2, $text, $color1);
277 277
 			}
278 278
 		}
279 279
 	}
280 280
 
281
-	function text_arc($im, $centerX, $centerY, $diameter, $start, $end, $color1,$text,$placeindex=0) {
282
-		$r=$diameter/2;
283
-		$w=deg2rad((360+$start+($end-$start)/2)%360);
281
+	function text_arc($im, $centerX, $centerY, $diameter, $start, $end, $color1, $text, $placeindex = 0) {
282
+		$r = $diameter / 2;
283
+		$w = deg2rad((360 + $start + ($end - $start) / 2) % 360);
284 284
 
285
-		if ($placeindex>0) {
286
-			imageline($im,$centerX + $r*cos($w)/2, $centerY + $r*sin($w)/2,$diameter, $placeindex*12,$color1);
287
-			imagestring($im,4,$diameter, $placeindex*12,$text,$color1);
285
+		if ($placeindex > 0) {
286
+			imageline($im, $centerX + $r * cos($w) / 2, $centerY + $r * sin($w) / 2, $diameter, $placeindex * 12, $color1);
287
+			imagestring($im, 4, $diameter, $placeindex * 12, $text, $color1);
288 288
 
289 289
 		} else {
290
-			imagestring($im,4,$centerX + $r*cos($w)/2, $centerY + $r*sin($w)/2,$text,$color1);
290
+			imagestring($im, 4, $centerX + $r * cos($w) / 2, $centerY + $r * sin($w) / 2, $text, $color1);
291 291
 		}
292 292
 	}
293 293
 
294
-	function fill_box($im, $x, $y, $w, $h, $color1, $color2,$text='',$placeindex='') {
294
+	function fill_box($im, $x, $y, $w, $h, $color1, $color2, $text = '', $placeindex = '') {
295 295
 		global $col_black;
296
-		$x1=$x+$w-1;
297
-		$y1=$y+$h-1;
296
+		$x1 = $x + $w - 1;
297
+		$y1 = $y + $h - 1;
298 298
 
299
-		imagerectangle($im, $x, $y1, $x1+1, $y+1, $col_black);
300
-		if($y1>$y) imagefilledrectangle($im, $x, $y, $x1, $y1, $color2);
299
+		imagerectangle($im, $x, $y1, $x1 + 1, $y + 1, $col_black);
300
+		if ($y1 > $y) imagefilledrectangle($im, $x, $y, $x1, $y1, $color2);
301 301
 		else imagefilledrectangle($im, $x, $y1, $x1, $y, $color2);
302 302
 		imagerectangle($im, $x, $y1, $x1, $y, $color1);
303 303
 		if ($text) {
304
-			if ($placeindex>0) {
304
+			if ($placeindex > 0) {
305 305
 
306
-				if ($placeindex<16)
306
+				if ($placeindex < 16)
307 307
 				{
308
-					$px=5;
309
-					$py=$placeindex*12+6;
310
-					imagefilledrectangle($im, $px+90, $py+3, $px+90-4, $py-3, $color2);
311
-					imageline($im,$x,$y+$h/2,$px+90,$py,$color2);
312
-					imagestring($im,2,$px,$py-6,$text,$color1);
308
+					$px = 5;
309
+					$py = $placeindex * 12 + 6;
310
+					imagefilledrectangle($im, $px + 90, $py + 3, $px + 90 - 4, $py - 3, $color2);
311
+					imageline($im, $x, $y + $h / 2, $px + 90, $py, $color2);
312
+					imagestring($im, 2, $px, $py - 6, $text, $color1);
313 313
 
314 314
 				} else {
315
-					if ($placeindex<31) {
316
-						$px=$x+40*2;
317
-						$py=($placeindex-15)*12+6;
315
+					if ($placeindex < 31) {
316
+						$px = $x + 40 * 2;
317
+						$py = ($placeindex - 15) * 12 + 6;
318 318
 					} else {
319
-						$px=$x+40*2+100*intval(($placeindex-15)/15);
320
-						$py=($placeindex%15)*12+6;
319
+						$px = $x + 40 * 2 + 100 * intval(($placeindex - 15) / 15);
320
+						$py = ($placeindex % 15) * 12 + 6;
321 321
 					}
322
-					imagefilledrectangle($im, $px, $py+3, $px-4, $py-3, $color2);
323
-					imageline($im,$x+$w,$y+$h/2,$px,$py,$color2);
324
-					imagestring($im,2,$px+2,$py-6,$text,$color1);
322
+					imagefilledrectangle($im, $px, $py + 3, $px - 4, $py - 3, $color2);
323
+					imageline($im, $x + $w, $y + $h / 2, $px, $py, $color2);
324
+					imagestring($im, 2, $px + 2, $py - 6, $text, $color1);
325 325
 				}
326 326
 			} else {
327
-				imagestring($im,4,$x+5,$y1-16,$text,$color1);
327
+				imagestring($im, 4, $x + 5, $y1 - 16, $text, $color1);
328 328
 			}
329 329
 		}
330 330
 	}
331 331
 
332 332
 
333 333
 	$size = GRAPH_SIZE; // image size
334
-	if ($MYREQUEST['IMG']==3)
335
-		$image = imagecreate(2*$size+150, $size+10);
334
+	if ($MYREQUEST['IMG'] == 3)
335
+		$image = imagecreate(2 * $size + 150, $size + 10);
336 336
 	else
337
-		$image = imagecreate($size+50, $size+10);
337
+		$image = imagecreate($size + 50, $size + 10);
338 338
 
339 339
 	$col_white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
340
-	$col_red   = imagecolorallocate($image, 0xD0, 0x60,  0x30);
340
+	$col_red   = imagecolorallocate($image, 0xD0, 0x60, 0x30);
341 341
 	$col_green = imagecolorallocate($image, 0x60, 0xF0, 0x60);
342
-	$col_black = imagecolorallocate($image,   0,   0,   0);
343
-	imagecolortransparent($image,$col_white);
342
+	$col_black = imagecolorallocate($image, 0, 0, 0);
343
+	imagecolortransparent($image, $col_white);
344 344
 
345 345
 	switch ($MYREQUEST['IMG']) {
346 346
 
347 347
 	case 1:
348
-		$s=$mem['num_seg']*$mem['seg_size'];
349
-		$a=$mem['avail_mem'];
350
-		$x=$y=$size/2;
348
+		$s = $mem['num_seg'] * $mem['seg_size'];
349
+		$a = $mem['avail_mem'];
350
+		$x = $y = $size / 2;
351 351
 		$fuzz = 0.000001;
352 352
 
353 353
 		// This block of code creates the pie chart.  It is a lot more complex than you
354 354
 		// would expect because we try to visualize any memory fragmentation as well.
355 355
 		$angle_from = 0;
356
-		$string_placement=array();
357
-		for($i=0; $i<$mem['num_seg']; $i++) {
356
+		$string_placement = array();
357
+		for ($i = 0; $i < $mem['num_seg']; $i++) {
358 358
 			$ptr = 0;
359 359
 			$free = $mem['block_lists'][$i];
360 360
 			uasort($free, 'block_sort');
361
-			foreach($free as $block) {
362
-				if($block['offset']!=$ptr) {       // Used block
363
-					$angle_to = $angle_from+($block['offset']-$ptr)/$s;
364
-					if(($angle_to+$fuzz)>1) $angle_to = 1;
365
-					if( ($angle_to*360) - ($angle_from*360) >= 1) {
366
-						fill_arc($image,$x,$y,$size,$angle_from*360,$angle_to*360,$col_black,$col_red);
367
-						if (($angle_to-$angle_from)>0.05) {
368
-							array_push($string_placement, array($angle_from,$angle_to));
361
+			foreach ($free as $block) {
362
+				if ($block['offset'] != $ptr) {       // Used block
363
+					$angle_to = $angle_from + ($block['offset'] - $ptr) / $s;
364
+					if (($angle_to + $fuzz) > 1) $angle_to = 1;
365
+					if (($angle_to * 360) - ($angle_from * 360) >= 1) {
366
+						fill_arc($image, $x, $y, $size, $angle_from * 360, $angle_to * 360, $col_black, $col_red);
367
+						if (($angle_to - $angle_from) > 0.05) {
368
+							array_push($string_placement, array($angle_from, $angle_to));
369 369
 						}
370 370
 					}
371 371
 					$angle_from = $angle_to;
372 372
 				}
373
-				$angle_to = $angle_from+($block['size'])/$s;
374
-				if(($angle_to+$fuzz)>1) $angle_to = 1;
375
-				if( ($angle_to*360) - ($angle_from*360) >= 1) {
376
-					fill_arc($image,$x,$y,$size,$angle_from*360,$angle_to*360,$col_black,$col_green);
377
-					if (($angle_to-$angle_from)>0.05) {
378
-						array_push($string_placement, array($angle_from,$angle_to));
373
+				$angle_to = $angle_from + ($block['size']) / $s;
374
+				if (($angle_to + $fuzz) > 1) $angle_to = 1;
375
+				if (($angle_to * 360) - ($angle_from * 360) >= 1) {
376
+					fill_arc($image, $x, $y, $size, $angle_from * 360, $angle_to * 360, $col_black, $col_green);
377
+					if (($angle_to - $angle_from) > 0.05) {
378
+						array_push($string_placement, array($angle_from, $angle_to));
379 379
 					}
380 380
 				}
381 381
 				$angle_from = $angle_to;
382
-				$ptr = $block['offset']+$block['size'];
382
+				$ptr = $block['offset'] + $block['size'];
383 383
 			}
384 384
 			if ($ptr < $mem['seg_size']) { // memory at the end
385
-				$angle_to = $angle_from + ($mem['seg_size'] - $ptr)/$s;
386
-				if(($angle_to+$fuzz)>1) $angle_to = 1;
387
-				fill_arc($image,$x,$y,$size,$angle_from*360,$angle_to*360,$col_black,$col_red);
388
-				if (($angle_to-$angle_from)>0.05) {
389
-					array_push($string_placement, array($angle_from,$angle_to));
385
+				$angle_to = $angle_from + ($mem['seg_size'] - $ptr) / $s;
386
+				if (($angle_to + $fuzz) > 1) $angle_to = 1;
387
+				fill_arc($image, $x, $y, $size, $angle_from * 360, $angle_to * 360, $col_black, $col_red);
388
+				if (($angle_to - $angle_from) > 0.05) {
389
+					array_push($string_placement, array($angle_from, $angle_to));
390 390
 				}
391 391
 			}
392 392
 		}
393 393
 		foreach ($string_placement as $angle) {
394
-			text_arc($image,$x,$y,$size,$angle[0]*360,$angle[1]*360,$col_black,bsize($s*($angle[1]-$angle[0])));
394
+			text_arc($image, $x, $y, $size, $angle[0] * 360, $angle[1] * 360, $col_black, bsize($s * ($angle[1] - $angle[0])));
395 395
 		}
396 396
 		break;
397 397
 
398 398
 	case 2:
399
-		$s=$cache['num_hits']+$cache['num_misses'];
400
-		$a=$cache['num_hits'];
399
+		$s = $cache['num_hits'] + $cache['num_misses'];
400
+		$a = $cache['num_hits'];
401 401
 
402
-		fill_box($image, 30,$size,50,$s ? (-$a*($size-21)/$s) : 0,$col_black,$col_green,sprintf("%.1f%%",$s ? $cache['num_hits']*100/$s : 0));
403
-		fill_box($image,130,$size,50,$s ? -max(4,($s-$a)*($size-21)/$s) : 0,$col_black,$col_red,sprintf("%.1f%%",$s ? $cache['num_misses']*100/$s : 0));
402
+		fill_box($image, 30, $size, 50, $s ? (-$a * ($size - 21) / $s) : 0, $col_black, $col_green, sprintf("%.1f%%", $s ? $cache['num_hits'] * 100 / $s : 0));
403
+		fill_box($image, 130, $size, 50, $s ? -max(4, ($s - $a) * ($size - 21) / $s) : 0, $col_black, $col_red, sprintf("%.1f%%", $s ? $cache['num_misses'] * 100 / $s : 0));
404 404
 		break;
405 405
 
406 406
 	case 3:
407
-		$s=$mem['num_seg']*$mem['seg_size'];
408
-		$a=$mem['avail_mem'];
409
-		$x=130;
410
-		$y=1;
411
-		$j=1;
407
+		$s = $mem['num_seg'] * $mem['seg_size'];
408
+		$a = $mem['avail_mem'];
409
+		$x = 130;
410
+		$y = 1;
411
+		$j = 1;
412 412
 
413 413
 		// This block of code creates the bar chart.  It is a lot more complex than you
414 414
 		// would expect because we try to visualize any memory fragmentation as well.
415
-		for($i=0; $i<$mem['num_seg']; $i++) {
415
+		for ($i = 0; $i < $mem['num_seg']; $i++) {
416 416
 			$ptr = 0;
417 417
 			$free = $mem['block_lists'][$i];
418 418
 			uasort($free, 'block_sort');
419
-			foreach($free as $block) {
420
-				if($block['offset']!=$ptr) {       // Used block
421
-					$h=(GRAPH_SIZE-5)*($block['offset']-$ptr)/$s;
422
-					if ($h>0) {
419
+			foreach ($free as $block) {
420
+				if ($block['offset'] != $ptr) {       // Used block
421
+					$h = (GRAPH_SIZE - 5) * ($block['offset'] - $ptr) / $s;
422
+					if ($h > 0) {
423 423
                                                 $j++;
424
-						if($j<75) fill_box($image,$x,$y,50,$h,$col_black,$col_red,bsize($block['offset']-$ptr),$j);
425
-                                                else fill_box($image,$x,$y,50,$h,$col_black,$col_red);
424
+						if ($j < 75) fill_box($image, $x, $y, 50, $h, $col_black, $col_red, bsize($block['offset'] - $ptr), $j);
425
+                                                else fill_box($image, $x, $y, 50, $h, $col_black, $col_red);
426 426
                                         }
427
-					$y+=$h;
427
+					$y += $h;
428 428
 				}
429
-				$h=(GRAPH_SIZE-5)*($block['size'])/$s;
430
-				if ($h>0) {
429
+				$h = (GRAPH_SIZE - 5) * ($block['size']) / $s;
430
+				if ($h > 0) {
431 431
                                         $j++;
432
-					if($j<75) fill_box($image,$x,$y,50,$h,$col_black,$col_green,bsize($block['size']),$j);
433
-					else fill_box($image,$x,$y,50,$h,$col_black,$col_green);
432
+					if ($j < 75) fill_box($image, $x, $y, 50, $h, $col_black, $col_green, bsize($block['size']), $j);
433
+					else fill_box($image, $x, $y, 50, $h, $col_black, $col_green);
434 434
                                 }
435
-				$y+=$h;
436
-				$ptr = $block['offset']+$block['size'];
435
+				$y += $h;
436
+				$ptr = $block['offset'] + $block['size'];
437 437
 			}
438 438
 			if ($ptr < $mem['seg_size']) { // memory at the end
439
-				$h = (GRAPH_SIZE-5) * ($mem['seg_size'] - $ptr) / $s;
439
+				$h = (GRAPH_SIZE - 5) * ($mem['seg_size'] - $ptr) / $s;
440 440
 				if ($h > 0) {
441
-					fill_box($image,$x,$y,50,$h,$col_black,$col_red,bsize($mem['seg_size']-$ptr),$j++);
441
+					fill_box($image, $x, $y, 50, $h, $col_black, $col_red, bsize($mem['seg_size'] - $ptr), $j++);
442 442
 				}
443 443
 			}
444 444
 		}
445 445
 		break;
446 446
 
447 447
 		case 4:
448
-			$s=$cache['num_hits']+$cache['num_misses'];
449
-			$a=$cache['num_hits'];
448
+			$s = $cache['num_hits'] + $cache['num_misses'];
449
+			$a = $cache['num_hits'];
450 450
 
451
-			fill_box($image, 30,$size,50,$s ? -$a*($size-21)/$s : 0,$col_black,$col_green,sprintf("%.1f%%", $s ? $cache['num_hits']*100/$s : 0));
452
-			fill_box($image,130,$size,50,$s ? -max(4,($s-$a)*($size-21)/$s) : 0,$col_black,$col_red,sprintf("%.1f%%", $s ? $cache['num_misses']*100/$s : 0));
451
+			fill_box($image, 30, $size, 50, $s ? -$a * ($size - 21) / $s : 0, $col_black, $col_green, sprintf("%.1f%%", $s ? $cache['num_hits'] * 100 / $s : 0));
452
+			fill_box($image, 130, $size, 50, $s ? -max(4, ($s - $a) * ($size - 21) / $s) : 0, $col_black, $col_red, sprintf("%.1f%%", $s ? $cache['num_misses'] * 100 / $s : 0));
453 453
 		break;
454 454
 	}
455 455
 
@@ -461,28 +461,28 @@  discard block
 block discarded – undo
461 461
 // pretty printer for byte values
462 462
 //
463 463
 function bsize($s) {
464
-	foreach (array('','K','M','G') as $i => $k) {
464
+	foreach (array('', 'K', 'M', 'G') as $i => $k) {
465 465
 		if ($s < 1024) break;
466
-		$s/=1024;
466
+		$s /= 1024;
467 467
 	}
468
-	return sprintf("%5.1f %sBytes",$s,$k);
468
+	return sprintf("%5.1f %sBytes", $s, $k);
469 469
 }
470 470
 
471 471
 // sortable table header in "scripts for this host" view
472
-function sortheader($key,$name,$extra='') {
472
+function sortheader($key, $name, $extra = '') {
473 473
 	global $MYREQUEST, $MY_SELF_WO_SORT;
474 474
 
475
-	if ($MYREQUEST['SORT1']==$key) {
476
-		$MYREQUEST['SORT2'] = $MYREQUEST['SORT2']=='A' ? 'D' : 'A';
475
+	if ($MYREQUEST['SORT1'] == $key) {
476
+		$MYREQUEST['SORT2'] = $MYREQUEST['SORT2'] == 'A' ? 'D' : 'A';
477 477
 	}
478 478
 	return "<a class=sortable href=\"$MY_SELF_WO_SORT$extra&SORT1=$key&SORT2=".$MYREQUEST['SORT2']."\">$name</a>";
479 479
 
480 480
 }
481 481
 
482 482
 // create menu entry
483
-function menu_entry($ob,$title) {
484
-	global $MYREQUEST,$MY_SELF;
485
-	if ($MYREQUEST['OB']!=$ob) {
483
+function menu_entry($ob, $title) {
484
+	global $MYREQUEST, $MY_SELF;
485
+	if ($MYREQUEST['OB'] != $ob) {
486 486
 		return "<li><a href=\"$MY_SELF&OB=$ob\">$title</a></li>";
487 487
 	} else if (empty($MYREQUEST['SH'])) {
488 488
 		return "<li><span class=active>$title</span></li>";
@@ -491,14 +491,14 @@  discard block
 block discarded – undo
491 491
 	}
492 492
 }
493 493
 
494
-function put_login_link($s="Login")
494
+function put_login_link($s = "Login")
495 495
 {
496
-	global $MY_SELF,$MYREQUEST,$AUTHENTICATED;
496
+	global $MY_SELF, $MYREQUEST, $AUTHENTICATED;
497 497
 	// needs ADMIN_PASSWORD to be changed!
498 498
 	//
499 499
 	if (!USE_AUTHENTICATION) {
500 500
 		return;
501
-	} else if (ADMIN_PASSWORD=='password')
501
+	} else if (ADMIN_PASSWORD == 'password')
502 502
 	{
503 503
 		print <<<EOB
504 504
 			<a href="#" onClick="javascript:alert('You need to set a password at the top of apc.php before this will work!');return false";>$s</a>
@@ -507,7 +507,7 @@  discard block
 block discarded – undo
507 507
 		print <<<EOB
508 508
 			'{$_SERVER['PHP_AUTH_USER']}'&nbsp;logged&nbsp;in!
509 509
 EOB;
510
-	} else{
510
+	} else {
511 511
 		print <<<EOB
512 512
 			<a href="$MY_SELF&LO=1&OB={$MYREQUEST['OB']}">$s</a>
513 513
 EOB;
@@ -744,9 +744,9 @@  discard block
 block discarded – undo
744 744
 	<li><a href="$MY_SELF&OB={$MYREQUEST['OB']}&SH={$MYREQUEST['SH']}">Refresh Data</a></li>
745 745
 EOB;
746 746
 echo
747
-	menu_entry(OB_HOST_STATS,'View Host Stats'),
748
-	menu_entry(OB_USER_CACHE,'User Cache Entries'),
749
-	menu_entry(OB_VERSION_CHECK,'Version Check');
747
+	menu_entry(OB_HOST_STATS, 'View Host Stats'),
748
+	menu_entry(OB_USER_CACHE, 'User Cache Entries'),
749
+	menu_entry(OB_VERSION_CHECK, 'Version Check');
750 750
 
751 751
 if ($AUTHENTICATED) {
752 752
 	echo <<<EOB
@@ -770,19 +770,19 @@  discard block
 block discarded – undo
770 770
 // Host Stats
771 771
 // -----------------------------------------------
772 772
 case OB_HOST_STATS:
773
-	$mem_size = $mem['num_seg']*$mem['seg_size'];
774
-	$mem_avail= $mem['avail_mem'];
775
-	$mem_used = $mem_size-$mem_avail;
773
+	$mem_size = $mem['num_seg'] * $mem['seg_size'];
774
+	$mem_avail = $mem['avail_mem'];
775
+	$mem_used = $mem_size - $mem_avail;
776 776
 	$seg_size = bsize($mem['seg_size']);
777
-	$req_rate_user = sprintf("%.2f", $cache['num_hits'] ? (($cache['num_hits']+$cache['num_misses'])/($time-$cache['start_time'])) : 0);
778
-	$hit_rate_user = sprintf("%.2f", $cache['num_hits'] ? (($cache['num_hits'])/($time-$cache['start_time'])) : 0);
779
-	$miss_rate_user = sprintf("%.2f", $cache['num_misses'] ? (($cache['num_misses'])/($time-$cache['start_time'])) : 0);
780
-	$insert_rate_user = sprintf("%.2f", $cache['num_inserts'] ? (($cache['num_inserts'])/($time-$cache['start_time'])) : 0);
777
+	$req_rate_user = sprintf("%.2f", $cache['num_hits'] ? (($cache['num_hits'] + $cache['num_misses']) / ($time - $cache['start_time'])) : 0);
778
+	$hit_rate_user = sprintf("%.2f", $cache['num_hits'] ? (($cache['num_hits']) / ($time - $cache['start_time'])) : 0);
779
+	$miss_rate_user = sprintf("%.2f", $cache['num_misses'] ? (($cache['num_misses']) / ($time - $cache['start_time'])) : 0);
780
+	$insert_rate_user = sprintf("%.2f", $cache['num_inserts'] ? (($cache['num_inserts']) / ($time - $cache['start_time'])) : 0);
781 781
 	$apcversion = phpversion('apcu');
782 782
 	$phpversion = phpversion();
783 783
 	$number_vars = $cache['num_entries'];
784 784
     $size_vars = bsize($cache['mem_size']);
785
-	$i=0;
785
+	$i = 0;
786 786
 	echo <<< EOB
787 787
 		<div class="info div1"><h2>General Cache Information</h2>
788 788
 		<table cellspacing=0><tbody>
@@ -790,9 +790,9 @@  discard block
 block discarded – undo
790 790
 		<tr class=tr-1><td class=td-0>PHP Version</td><td>$phpversion</td></tr>
791 791
 EOB;
792 792
 
793
-	if(!empty($_SERVER['SERVER_NAME']))
793
+	if (!empty($_SERVER['SERVER_NAME']))
794 794
 		echo "<tr class=tr-0><td class=td-0>APCu Host</td><td>{$_SERVER['SERVER_NAME']} $host</td></tr>\n";
795
-	if(!empty($_SERVER['SERVER_SOFTWARE']))
795
+	if (!empty($_SERVER['SERVER_SOFTWARE']))
796 796
 		echo "<tr class=tr-1><td class=td-0>Server Software</td><td>{$_SERVER['SERVER_SOFTWARE']}</td></tr>\n";
797 797
 
798 798
 	echo <<<EOB
@@ -800,8 +800,8 @@  discard block
 block discarded – undo
800 800
     <br/> ({$cache['memory_type']} memory)
801 801
     </td></tr>
802 802
 EOB;
803
-	echo   '<tr class=tr-1><td class=td-0>Start Time</td><td>',date(DATE_FORMAT,$cache['start_time']),'</td></tr>';
804
-	echo   '<tr class=tr-0><td class=td-0>Uptime</td><td>',duration($cache['start_time']),'</td></tr>';
803
+	echo   '<tr class=tr-1><td class=td-0>Start Time</td><td>', date(DATE_FORMAT, $cache['start_time']), '</td></tr>';
804
+	echo   '<tr class=tr-0><td class=td-0>Uptime</td><td>', duration($cache['start_time']), '</td></tr>';
805 805
 	echo <<<EOB
806 806
 		</tbody></table>
807 807
 		</div>
@@ -826,11 +826,11 @@  discard block
 block discarded – undo
826 826
 
827 827
 	$j = 0;
828 828
 	foreach (ini_get_all('apcu') as $k => $v) {
829
-		echo "<tr class=tr-$j><td class=td-0>",$k,"</td><td>",str_replace(',',',<br />',$v['local_value']),"</td></tr>\n";
829
+		echo "<tr class=tr-$j><td class=td-0>", $k, "</td><td>", str_replace(',', ',<br />', $v['local_value']), "</td></tr>\n";
830 830
 		$j = 1 - $j;
831 831
 	}
832 832
 
833
-	if($mem['num_seg']>1 || $mem['num_seg']==1 && count($mem['block_lists'][0])>1)
833
+	if ($mem['num_seg'] > 1 || $mem['num_seg'] == 1 && count($mem['block_lists'][0]) > 1)
834 834
 		$mem_note = "Memory Usage<br /><font size=-2>(multiple slices indicate fragments)</font>";
835 835
 	else
836 836
 		$mem_note = "Memory Usage";
@@ -842,7 +842,7 @@  discard block
 block discarded – undo
842 842
 		<div class="graph div3"><h2>Host Status Diagrams</h2>
843 843
 		<table cellspacing=0><tbody>
844 844
 EOB;
845
-	$size='width='.(GRAPH_SIZE+50).' height='.(GRAPH_SIZE+10);
845
+	$size = 'width='.(GRAPH_SIZE + 50).' height='.(GRAPH_SIZE + 10);
846 846
 echo <<<EOB
847 847
 		<tr>
848 848
 		<td class=td-0>$mem_note</td>
@@ -857,12 +857,12 @@  discard block
 block discarded – undo
857 857
 			  "<td class=td-1><img alt=\"\" $size src=\"$PHP_SELF?IMG=2&$time\"></td></tr>\n"
858 858
 			: "",
859 859
 		'<tr>',
860
-		'<td class=td-0><span class="green box">&nbsp;</span>Free: ',bsize($mem_avail).sprintf(" (%.1f%%)",$mem_avail*100/$mem_size),"</td>\n",
861
-		'<td class=td-1><span class="green box">&nbsp;</span>Hits: ',$cache['num_hits'].@sprintf(" (%.1f%%)",$cache['num_hits']*100/($cache['num_hits']+$cache['num_misses'])),"</td>\n",
860
+		'<td class=td-0><span class="green box">&nbsp;</span>Free: ', bsize($mem_avail).sprintf(" (%.1f%%)", $mem_avail * 100 / $mem_size), "</td>\n",
861
+		'<td class=td-1><span class="green box">&nbsp;</span>Hits: ', $cache['num_hits'].@sprintf(" (%.1f%%)", $cache['num_hits'] * 100 / ($cache['num_hits'] + $cache['num_misses'])), "</td>\n",
862 862
 		'</tr>',
863 863
 		'<tr>',
864
-		'<td class=td-0><span class="red box">&nbsp;</span>Used: ',bsize($mem_used).sprintf(" (%.1f%%)",$mem_used *100/$mem_size),"</td>\n",
865
-		'<td class=td-1><span class="red box">&nbsp;</span>Misses: ',$cache['num_misses'].@sprintf(" (%.1f%%)",$cache['num_misses']*100/($cache['num_hits']+$cache['num_misses'])),"</td>\n";
864
+		'<td class=td-0><span class="red box">&nbsp;</span>Used: ', bsize($mem_used).sprintf(" (%.1f%%)", $mem_used * 100 / $mem_size), "</td>\n",
865
+		'<td class=td-1><span class="red box">&nbsp;</span>Misses: ', $cache['num_misses'].@sprintf(" (%.1f%%)", $cache['num_misses'] * 100 / ($cache['num_hits'] + $cache['num_misses'])), "</td>\n";
866 866
 	echo <<< EOB
867 867
 		</tr>
868 868
 		</tbody></table>
@@ -876,28 +876,28 @@  discard block
 block discarded – undo
876 876
 
877 877
 	// Fragementation: (freeseg - 1) / total_seg
878 878
 	$nseg = $freeseg = $fragsize = $freetotal = 0;
879
-	for($i=0; $i<$mem['num_seg']; $i++) {
879
+	for ($i = 0; $i < $mem['num_seg']; $i++) {
880 880
 		$ptr = 0;
881
-		foreach($mem['block_lists'][$i] as $block) {
881
+		foreach ($mem['block_lists'][$i] as $block) {
882 882
 			if ($block['offset'] != $ptr) {
883 883
 				++$nseg;
884 884
 			}
885 885
 			$ptr = $block['offset'] + $block['size'];
886 886
                         /* Only consider blocks <5M for the fragmentation % */
887
-                        if($block['size']<(5*1024*1024)) $fragsize+=$block['size'];
888
-                        $freetotal+=$block['size'];
887
+                        if ($block['size'] < (5 * 1024 * 1024)) $fragsize += $block['size'];
888
+                        $freetotal += $block['size'];
889 889
 		}
890 890
 		$freeseg += count($mem['block_lists'][$i]);
891 891
 	}
892 892
 
893 893
 	if ($freeseg > 1) {
894
-		$frag = sprintf("%.2f%% (%s out of %s in %d fragments)", ($fragsize/$freetotal)*100,bsize($fragsize),bsize($freetotal),$freeseg);
894
+		$frag = sprintf("%.2f%% (%s out of %s in %d fragments)", ($fragsize / $freetotal) * 100, bsize($fragsize), bsize($freetotal), $freeseg);
895 895
 	} else {
896 896
 		$frag = "0%";
897 897
 	}
898 898
 
899 899
 	if (graphics_avail()) {
900
-		$size='width='.(2*GRAPH_SIZE+150).' height='.(GRAPH_SIZE+10);
900
+		$size = 'width='.(2 * GRAPH_SIZE + 150).' height='.(GRAPH_SIZE + 10);
901 901
 		echo <<<EOB
902 902
 			<img alt="" $size src="$PHP_SELF?IMG=3&$time">
903 903
 EOB;
@@ -907,10 +907,10 @@  discard block
 block discarded – undo
907 907
 		</td>
908 908
 		</tr>
909 909
 EOB;
910
-        if(isset($mem['adist'])) {
911
-          foreach($mem['adist'] as $i=>$v) {
912
-            $cur = pow(2,$i); $nxt = pow(2,$i+1)-1;
913
-            if($i==0) $range = "1";
910
+        if (isset($mem['adist'])) {
911
+          foreach ($mem['adist'] as $i=>$v) {
912
+            $cur = pow(2, $i); $nxt = pow(2, $i + 1) - 1;
913
+            if ($i == 0) $range = "1";
914 914
             else $range = "$cur - $nxt";
915 915
             echo "<tr><th align=right>$range</th><td align=right>$v</td></tr>\n";
916 916
           }
@@ -933,47 +933,47 @@  discard block
 block discarded – undo
933 933
 		echo '</div>';
934 934
 		break;
935 935
 	}
936
-	$fieldname='info';
937
-	$fieldheading='User Entry Label';
938
-	$fieldkey='info';
936
+	$fieldname = 'info';
937
+	$fieldheading = 'User Entry Label';
938
+	$fieldkey = 'info';
939 939
 
940
-	$cols=6;
940
+	$cols = 6;
941 941
 	echo <<<EOB
942 942
 		<div class=sorting><form>Scope:
943 943
 		<input type=hidden name=OB value={$MYREQUEST['OB']}>
944 944
 		<select name=SCOPE>
945 945
 EOB;
946 946
 	echo
947
-		"<option value=A",$MYREQUEST['SCOPE']=='A' ? " selected":"",">Active</option>",
948
-		"<option value=D",$MYREQUEST['SCOPE']=='D' ? " selected":"",">Deleted</option>",
947
+		"<option value=A", $MYREQUEST['SCOPE'] == 'A' ? " selected" : "", ">Active</option>",
948
+		"<option value=D", $MYREQUEST['SCOPE'] == 'D' ? " selected" : "", ">Deleted</option>",
949 949
 		"</select>",
950 950
 		", Sorting:<select name=SORT1>",
951
-		"<option value=H",$MYREQUEST['SORT1']=='H' ? " selected":"",">Hits</option>",
952
-		"<option value=Z",$MYREQUEST['SORT1']=='Z' ? " selected":"",">Size</option>",
953
-		"<option value=S",$MYREQUEST['SORT1']=='S' ? " selected":"",">$fieldheading</option>",
954
-		"<option value=A",$MYREQUEST['SORT1']=='A' ? " selected":"",">Last accessed</option>",
955
-		"<option value=M",$MYREQUEST['SORT1']=='M' ? " selected":"",">Last modified</option>",
956
-		"<option value=C",$MYREQUEST['SORT1']=='C' ? " selected":"",">Created at</option>",
957
-		"<option value=D",$MYREQUEST['SORT1']=='D' ? " selected":"",">Deleted at</option>";
958
-	if($fieldname=='info') echo
959
-		"<option value=D",$MYREQUEST['SORT1']=='T' ? " selected":"",">Timeout</option>";
951
+		"<option value=H", $MYREQUEST['SORT1'] == 'H' ? " selected" : "", ">Hits</option>",
952
+		"<option value=Z", $MYREQUEST['SORT1'] == 'Z' ? " selected" : "", ">Size</option>",
953
+		"<option value=S", $MYREQUEST['SORT1'] == 'S' ? " selected" : "", ">$fieldheading</option>",
954
+		"<option value=A", $MYREQUEST['SORT1'] == 'A' ? " selected" : "", ">Last accessed</option>",
955
+		"<option value=M", $MYREQUEST['SORT1'] == 'M' ? " selected" : "", ">Last modified</option>",
956
+		"<option value=C", $MYREQUEST['SORT1'] == 'C' ? " selected" : "", ">Created at</option>",
957
+		"<option value=D", $MYREQUEST['SORT1'] == 'D' ? " selected" : "", ">Deleted at</option>";
958
+	if ($fieldname == 'info') echo
959
+		"<option value=D", $MYREQUEST['SORT1'] == 'T' ? " selected" : "", ">Timeout</option>";
960 960
 	echo
961 961
 		'</select>',
962 962
 		'<select name=SORT2>',
963
-		'<option value=D',$MYREQUEST['SORT2']=='D' ? ' selected':'','>DESC</option>',
964
-		'<option value=A',$MYREQUEST['SORT2']=='A' ? ' selected':'','>ASC</option>',
963
+		'<option value=D', $MYREQUEST['SORT2'] == 'D' ? ' selected' : '', '>DESC</option>',
964
+		'<option value=A', $MYREQUEST['SORT2'] == 'A' ? ' selected' : '', '>ASC</option>',
965 965
 		'</select>',
966 966
 		'<select name=COUNT onChange="form.submit()">',
967
-		'<option value=10 ',$MYREQUEST['COUNT']=='10' ? ' selected':'','>Top 10</option>',
968
-		'<option value=20 ',$MYREQUEST['COUNT']=='20' ? ' selected':'','>Top 20</option>',
969
-		'<option value=50 ',$MYREQUEST['COUNT']=='50' ? ' selected':'','>Top 50</option>',
970
-		'<option value=100',$MYREQUEST['COUNT']=='100'? ' selected':'','>Top 100</option>',
971
-		'<option value=150',$MYREQUEST['COUNT']=='150'? ' selected':'','>Top 150</option>',
972
-		'<option value=200',$MYREQUEST['COUNT']=='200'? ' selected':'','>Top 200</option>',
973
-		'<option value=500',$MYREQUEST['COUNT']=='500'? ' selected':'','>Top 500</option>',
974
-		'<option value=0  ',$MYREQUEST['COUNT']=='0'  ? ' selected':'','>All</option>',
967
+		'<option value=10 ', $MYREQUEST['COUNT'] == '10' ? ' selected' : '', '>Top 10</option>',
968
+		'<option value=20 ', $MYREQUEST['COUNT'] == '20' ? ' selected' : '', '>Top 20</option>',
969
+		'<option value=50 ', $MYREQUEST['COUNT'] == '50' ? ' selected' : '', '>Top 50</option>',
970
+		'<option value=100', $MYREQUEST['COUNT'] == '100' ? ' selected' : '', '>Top 100</option>',
971
+		'<option value=150', $MYREQUEST['COUNT'] == '150' ? ' selected' : '', '>Top 150</option>',
972
+		'<option value=200', $MYREQUEST['COUNT'] == '200' ? ' selected' : '', '>Top 200</option>',
973
+		'<option value=500', $MYREQUEST['COUNT'] == '500' ? ' selected' : '', '>Top 500</option>',
974
+		'<option value=0  ', $MYREQUEST['COUNT'] == '0' ? ' selected' : '', '>All</option>',
975 975
 		'</select>',
976
-    '&nbsp; Search: <input name=SEARCH value="',$MYREQUEST['SEARCH'],'" type=text size=25/>',
976
+    '&nbsp; Search: <input name=SEARCH value="', $MYREQUEST['SEARCH'], '" type=text size=25/>',
977 977
 		'&nbsp;<input type=submit value="GO!">',
978 978
 		'</form></div>';
979 979
 
@@ -990,39 +990,39 @@  discard block
 block discarded – undo
990 990
   echo
991 991
 		'<div class="info"><table cellspacing=0><tbody>',
992 992
 		'<tr>',
993
-		'<th>',sortheader('S',$fieldheading,  "&OB=".$MYREQUEST['OB']),'</th>',
994
-		'<th>',sortheader('H','Hits',         "&OB=".$MYREQUEST['OB']),'</th>',
995
-		'<th>',sortheader('Z','Size',         "&OB=".$MYREQUEST['OB']),'</th>',
996
-		'<th>',sortheader('A','Last accessed',"&OB=".$MYREQUEST['OB']),'</th>',
997
-		'<th>',sortheader('M','Last modified',"&OB=".$MYREQUEST['OB']),'</th>',
998
-		'<th>',sortheader('C','Created at',   "&OB=".$MYREQUEST['OB']),'</th>';
999
-
1000
-	if($fieldname=='info') {
1001
-		$cols+=2;
1002
-		 echo '<th>',sortheader('T','Timeout',"&OB=".$MYREQUEST['OB']),'</th>';
993
+		'<th>', sortheader('S', $fieldheading, "&OB=".$MYREQUEST['OB']), '</th>',
994
+		'<th>', sortheader('H', 'Hits', "&OB=".$MYREQUEST['OB']), '</th>',
995
+		'<th>', sortheader('Z', 'Size', "&OB=".$MYREQUEST['OB']), '</th>',
996
+		'<th>', sortheader('A', 'Last accessed', "&OB=".$MYREQUEST['OB']), '</th>',
997
+		'<th>', sortheader('M', 'Last modified', "&OB=".$MYREQUEST['OB']), '</th>',
998
+		'<th>', sortheader('C', 'Created at', "&OB=".$MYREQUEST['OB']), '</th>';
999
+
1000
+	if ($fieldname == 'info') {
1001
+		$cols += 2;
1002
+		 echo '<th>', sortheader('T', 'Timeout', "&OB=".$MYREQUEST['OB']), '</th>';
1003 1003
 	}
1004
-	echo '<th>',sortheader('D','Deleted at',"&OB=".$MYREQUEST['OB']),'</th></tr>';
1004
+	echo '<th>', sortheader('D', 'Deleted at', "&OB=".$MYREQUEST['OB']), '</th></tr>';
1005 1005
 
1006 1006
 	// builds list with alpha numeric sortable keys
1007 1007
 	//
1008 1008
 	$list = array();
1009 1009
 
1010
-	foreach($cache[$scope_list[$MYREQUEST['SCOPE']]] as $i => $entry) {
1011
-		switch($MYREQUEST['SORT1']) {
1012
-			case 'A': $k=sprintf('%015d-',$entry['access_time']);  	     break;
1013
-			case 'H': $k=sprintf('%015d-',$entry['num_hits']); 	     break;
1014
-			case 'Z': $k=sprintf('%015d-',$entry['mem_size']); 	     break;
1015
-			case 'M': $k=sprintf('%015d-',$entry['mtime']);  break;
1016
-			case 'C': $k=sprintf('%015d-',$entry['creation_time']);      break;
1017
-			case 'T': $k=sprintf('%015d-',$entry['ttl']);		     break;
1018
-			case 'D': $k=sprintf('%015d-',$entry['deletion_time']);      break;
1019
-			case 'S': $k=$entry["info"];				     break;
1010
+	foreach ($cache[$scope_list[$MYREQUEST['SCOPE']]] as $i => $entry) {
1011
+		switch ($MYREQUEST['SORT1']) {
1012
+			case 'A': $k = sprintf('%015d-', $entry['access_time']); break;
1013
+			case 'H': $k = sprintf('%015d-', $entry['num_hits']); break;
1014
+			case 'Z': $k = sprintf('%015d-', $entry['mem_size']); break;
1015
+			case 'M': $k = sprintf('%015d-', $entry['mtime']); break;
1016
+			case 'C': $k = sprintf('%015d-', $entry['creation_time']); break;
1017
+			case 'T': $k = sprintf('%015d-', $entry['ttl']); break;
1018
+			case 'D': $k = sprintf('%015d-', $entry['deletion_time']); break;
1019
+			case 'S': $k = $entry["info"]; break;
1020 1020
 		}
1021 1021
 		if (!$AUTHENTICATED) {
1022 1022
 			// hide all path entries if not logged in
1023
-			$list[$k.$entry[$fieldname]]=preg_replace('/^.*(\\/|\\\\)/','*hidden*/',$entry);
1023
+			$list[$k.$entry[$fieldname]] = preg_replace('/^.*(\\/|\\\\)/', '*hidden*/', $entry);
1024 1024
 		} else {
1025
-			$list[$k.$entry[$fieldname]]=$entry;
1025
+			$list[$k.$entry[$fieldname]] = $entry;
1026 1026
 		}
1027 1027
 	}
1028 1028
 
@@ -1030,34 +1030,34 @@  discard block
 block discarded – undo
1030 1030
 		// sort list
1031 1031
 		//
1032 1032
 		switch ($MYREQUEST['SORT2']) {
1033
-			case "A":	krsort($list);	break;
1034
-			case "D":	ksort($list);	break;
1033
+			case "A":	krsort($list); break;
1034
+			case "D":	ksort($list); break;
1035 1035
 		}
1036 1036
 
1037 1037
 		// output list
1038
-		$i=0;
1039
-		foreach($list as $k => $entry) {
1040
-      if(!$MYREQUEST['SEARCH'] || preg_match($MYREQUEST['SEARCH'], $entry[$fieldname]) != 0) {
1041
-		$sh=md5($entry["info"]);
1042
-        $field_value = htmlentities(strip_tags($entry[$fieldname],''), ENT_QUOTES, 'UTF-8');
1038
+		$i = 0;
1039
+		foreach ($list as $k => $entry) {
1040
+      if (!$MYREQUEST['SEARCH'] || preg_match($MYREQUEST['SEARCH'], $entry[$fieldname]) != 0) {
1041
+		$sh = md5($entry["info"]);
1042
+        $field_value = htmlentities(strip_tags($entry[$fieldname], ''), ENT_QUOTES, 'UTF-8');
1043 1043
         echo
1044
-          '<tr id="key-'. $sh .'" class=tr-',$i%2,'>',
1045
-          "<td class=td-0><a href=\"$MY_SELF&OB=",$MYREQUEST['OB'],"&SH=",$sh,"#key-". $sh ."\">",$field_value,'</a></td>',
1046
-          '<td class="td-n center">',$entry['num_hits'],'</td>',
1047
-          '<td class="td-n right">',$entry['mem_size'],'</td>',
1048
-          '<td class="td-n center">',date(DATE_FORMAT,$entry['access_time']),'</td>',
1049
-          '<td class="td-n center">',date(DATE_FORMAT,$entry['mtime']),'</td>',
1050
-          '<td class="td-n center">',date(DATE_FORMAT,$entry['creation_time']),'</td>';
1051
-
1052
-        if($fieldname=='info') {
1053
-          if($entry['ttl'])
1044
+          '<tr id="key-'.$sh.'" class=tr-', $i % 2, '>',
1045
+          "<td class=td-0><a href=\"$MY_SELF&OB=", $MYREQUEST['OB'], "&SH=", $sh, "#key-".$sh."\">", $field_value, '</a></td>',
1046
+          '<td class="td-n center">', $entry['num_hits'], '</td>',
1047
+          '<td class="td-n right">', $entry['mem_size'], '</td>',
1048
+          '<td class="td-n center">', date(DATE_FORMAT, $entry['access_time']), '</td>',
1049
+          '<td class="td-n center">', date(DATE_FORMAT, $entry['mtime']), '</td>',
1050
+          '<td class="td-n center">', date(DATE_FORMAT, $entry['creation_time']), '</td>';
1051
+
1052
+        if ($fieldname == 'info') {
1053
+          if ($entry['ttl'])
1054 1054
             echo '<td class="td-n center">'.$entry['ttl'].' seconds</td>';
1055 1055
           else
1056 1056
             echo '<td class="td-n center">None</td>';
1057 1057
         }
1058 1058
         if ($entry['deletion_time']) {
1059 1059
 
1060
-          echo '<td class="td-last center">', date(DATE_FORMAT,$entry['deletion_time']), '</td>';
1060
+          echo '<td class="td-last center">', date(DATE_FORMAT, $entry['deletion_time']), '</td>';
1061 1061
         } else if ($MYREQUEST['OB'] == OB_USER_CACHE) {
1062 1062
 
1063 1063
           echo '<td class="td-last center">';
@@ -1079,14 +1079,14 @@  discard block
 block discarded – undo
1079 1079
 		}
1080 1080
 
1081 1081
 	} else {
1082
-		echo '<tr class=tr-0><td class="center" colspan=',$cols,'><i>No data</i></td></tr>';
1082
+		echo '<tr class=tr-0><td class="center" colspan=', $cols, '><i>No data</i></td></tr>';
1083 1083
 	}
1084 1084
 	echo <<< EOB
1085 1085
 		</tbody></table>
1086 1086
 EOB;
1087 1087
 
1088 1088
 	if ($list && $i < count($list)) {
1089
-		echo "<a href=\"$MY_SELF&OB=",$MYREQUEST['OB'],"&COUNT=0\"><i>",count($list)-$i,' more available...</i></a>';
1089
+		echo "<a href=\"$MY_SELF&OB=", $MYREQUEST['OB'], "&COUNT=0\"><i>", count($list) - $i, ' more available...</i></a>';
1090 1090
 	}
1091 1091
 
1092 1092
 	echo <<< EOB
@@ -1106,7 +1106,7 @@  discard block
 block discarded – undo
1106 1106
 		</tr>
1107 1107
 EOB;
1108 1108
   if (defined('PROXY')) {
1109
-    $ctxt = stream_context_create( array( 'http' => array( 'proxy' => PROXY, 'request_fulluri' => True ) ) );
1109
+    $ctxt = stream_context_create(array('http' => array('proxy' => PROXY, 'request_fulluri' => True)));
1110 1110
     $rss = @file_get_contents("http://pecl.php.net/feeds/pkg_apcu.rss", False, $ctxt);
1111 1111
   } else {
1112 1112
     $rss = @file_get_contents("http://pecl.php.net/feeds/pkg_apcu.rss");
Please login to merge, or discard this patch.
Braces   +403 added lines, -154 removed lines patch added patch discarded remove patch
@@ -46,7 +46,10 @@  discard block
 block discarded – undo
46 46
 $VERSION='$Id$';
47 47
 
48 48
 ////////// READ OPTIONAL CONFIGURATION FILE ////////////
49
-if (file_exists("apc.conf.php")) include("apc.conf.php");
49
+if (file_exists("apc.conf.php"))
50
+{
51
+	include("apc.conf.php");
52
+}
50 53
 ////////////////////////////////////////////////////////
51 54
 
52 55
 ////////// BEGIN OF DEFAULT CONFIG AREA ///////////////////////////////////////////////////////////
@@ -76,8 +79,13 @@  discard block
 block discarded – undo
76 79
 
77 80
 
78 81
 // "define if not defined"
79
-function defaults($d,$v) {
80
-	if (!defined($d)) define($d,$v); // or just @define(...)
82
+function defaults($d,$v)
83
+{
84
+	if (!defined($d))
85
+	{
86
+		define($d,$v);
87
+	}
88
+	// or just @define(...)
81 89
 }
82 90
 
83 91
 // rewrite $PHP_SELF to block XSS attacks
@@ -85,8 +93,11 @@  discard block
 block discarded – undo
85 93
 $PHP_SELF= isset($_SERVER['PHP_SELF']) ? htmlentities(strip_tags($_SERVER['PHP_SELF'],''), ENT_QUOTES, 'UTF-8') : '';
86 94
 $time = time();
87 95
 $host = php_uname('n');
88
-if($host) { $host = '('.$host.')'; }
89
-if (isset($_SERVER['SERVER_ADDR'])) {
96
+if($host)
97
+{
98
+$host = '('.$host.')'; }
99
+if (isset($_SERVER['SERVER_ADDR']))
100
+{
90 101
   $host .= ' ('.$_SERVER['SERVER_ADDR'].')';
91 102
 }
92 103
 
@@ -120,36 +131,68 @@  discard block
 block discarded – undo
120 131
 );
121 132
 
122 133
 // handle POST and GET requests
123
-if (empty($_REQUEST)) {
124
-	if (!empty($_GET) && !empty($_POST)) {
134
+if (empty($_REQUEST))
135
+{
136
+	if (!empty($_GET) && !empty($_POST))
137
+	{
125 138
 		$_REQUEST = array_merge($_GET, $_POST);
126
-	} else if (!empty($_GET)) {
139
+	}
140
+	else if (!empty($_GET))
141
+	{
127 142
 		$_REQUEST = $_GET;
128
-	} else if (!empty($_POST)) {
143
+	}
144
+	else if (!empty($_POST))
145
+	{
129 146
 		$_REQUEST = $_POST;
130
-	} else {
147
+	}
148
+	else
149
+	{
131 150
 		$_REQUEST = array();
132 151
 	}
133 152
 }
134 153
 
135 154
 // check parameter syntax
136
-foreach($vardom as $var => $dom) {
137
-	if (!isset($_REQUEST[$var])) {
155
+foreach($vardom as $var => $dom)
156
+{
157
+	if (!isset($_REQUEST[$var]))
158
+	{
138 159
 		$MYREQUEST[$var]=NULL;
139
-	} else if (!is_array($_REQUEST[$var]) && preg_match($dom.'D',$_REQUEST[$var])) {
160
+	}
161
+	else if (!is_array($_REQUEST[$var]) && preg_match($dom.'D',$_REQUEST[$var]))
162
+	{
140 163
 		$MYREQUEST[$var]=$_REQUEST[$var];
141
-	} else {
164
+	}
165
+	else
166
+	{
142 167
 		$MYREQUEST[$var]=$_REQUEST[$var]=NULL;
143 168
 	}
144 169
 }
145 170
 
146 171
 // check parameter sematics
147
-if (empty($MYREQUEST['SCOPE'])) $MYREQUEST['SCOPE']="A";
148
-if (empty($MYREQUEST['SORT1'])) $MYREQUEST['SORT1']="H";
149
-if (empty($MYREQUEST['SORT2'])) $MYREQUEST['SORT2']="D";
150
-if (empty($MYREQUEST['OB']))	$MYREQUEST['OB']=OB_HOST_STATS;
151
-if (!isset($MYREQUEST['COUNT'])) $MYREQUEST['COUNT']=20;
152
-if (!isset($scope_list[$MYREQUEST['SCOPE']])) $MYREQUEST['SCOPE']='A';
172
+if (empty($MYREQUEST['SCOPE']))
173
+{
174
+	$MYREQUEST['SCOPE']="A";
175
+}
176
+if (empty($MYREQUEST['SORT1']))
177
+{
178
+	$MYREQUEST['SORT1']="H";
179
+}
180
+if (empty($MYREQUEST['SORT2']))
181
+{
182
+	$MYREQUEST['SORT2']="D";
183
+}
184
+if (empty($MYREQUEST['OB']))
185
+{
186
+	$MYREQUEST['OB']=OB_HOST_STATS;
187
+}
188
+if (!isset($MYREQUEST['COUNT']))
189
+{
190
+	$MYREQUEST['COUNT']=20;
191
+}
192
+if (!isset($scope_list[$MYREQUEST['SCOPE']]))
193
+{
194
+	$MYREQUEST['SCOPE']='A';
195
+}
153 196
 
154 197
 $MY_SELF=
155 198
 	"$PHP_SELF".
@@ -164,16 +207,21 @@  discard block
 block discarded – undo
164 207
 
165 208
 // authentication needed?
166 209
 //
167
-if (!USE_AUTHENTICATION) {
210
+if (!USE_AUTHENTICATION)
211
+{
168 212
 	$AUTHENTICATED=1;
169
-} else {
213
+}
214
+else
215
+{
170 216
 	$AUTHENTICATED=0;
171
-	if (ADMIN_PASSWORD!='password' && ($MYREQUEST['LO'] == 1 || isset($_SERVER['PHP_AUTH_USER']))) {
217
+	if (ADMIN_PASSWORD!='password' && ($MYREQUEST['LO'] == 1 || isset($_SERVER['PHP_AUTH_USER'])))
218
+	{
172 219
 
173 220
 		if (!isset($_SERVER['PHP_AUTH_USER']) ||
174 221
 			!isset($_SERVER['PHP_AUTH_PW']) ||
175 222
 			$_SERVER['PHP_AUTH_USER'] != ADMIN_USERNAME ||
176
-			$_SERVER['PHP_AUTH_PW'] != ADMIN_PASSWORD) {
223
+			$_SERVER['PHP_AUTH_PW'] != ADMIN_PASSWORD)
224
+		{
177 225
 			Header("WWW-Authenticate: Basic realm=\"APC Login\"");
178 226
 			Header("HTTP/1.0 401 Unauthorized");
179 227
 
@@ -186,22 +234,27 @@  discard block
 block discarded – undo
186 234
 EOB;
187 235
 			exit;
188 236
 
189
-		} else {
237
+		}
238
+		else
239
+		{
190 240
 			$AUTHENTICATED=1;
191 241
 		}
192 242
 	}
193 243
 }
194 244
 
195 245
 // clear cache
196
-if ($AUTHENTICATED && isset($MYREQUEST['CC']) && $MYREQUEST['CC']) {
246
+if ($AUTHENTICATED && isset($MYREQUEST['CC']) && $MYREQUEST['CC'])
247
+{
197 248
 	apcu_clear_cache();
198 249
 }
199 250
 
200
-if ($AUTHENTICATED && !empty($MYREQUEST['DU'])) {
251
+if ($AUTHENTICATED && !empty($MYREQUEST['DU']))
252
+{
201 253
 	apcu_delete($MYREQUEST['DU']);
202 254
 }
203 255
 
204
-if(!function_exists('apcu_cache_info')) {
256
+if(!function_exists('apcu_cache_info'))
257
+{
205 258
 	echo "No cache info available.  APC does not appear to be running.";
206 259
   exit;
207 260
 }
@@ -216,7 +269,8 @@  discard block
 block discarded – undo
216 269
 header("Cache-Control: post-check=0, pre-check=0", false);
217 270
 header("Pragma: no-cache");                                    // HTTP/1.0
218 271
 
219
-function duration($ts) {
272
+function duration($ts)
273
+{
220 274
     global $time;
221 275
     $years = (int)((($time - $ts)/(7*86400))/52.177457);
222 276
     $rem = (int)(($time-$ts)-($years * 52.177457 * 7 * 86400));
@@ -225,41 +279,76 @@  discard block
 block discarded – undo
225 279
     $hours = (int)(($rem)/3600) - $days*24 - $weeks*7*24;
226 280
     $mins = (int)(($rem)/60) - $hours*60 - $days*24*60 - $weeks*7*24*60;
227 281
     $str = '';
228
-    if($years==1) $str .= "$years year, ";
229
-    if($years>1) $str .= "$years years, ";
230
-    if($weeks==1) $str .= "$weeks week, ";
231
-    if($weeks>1) $str .= "$weeks weeks, ";
232
-    if($days==1) $str .= "$days day,";
233
-    if($days>1) $str .= "$days days,";
234
-    if($hours == 1) $str .= " $hours hour and";
235
-    if($hours>1) $str .= " $hours hours and";
236
-    if($mins == 1) $str .= " 1 minute";
237
-    else $str .= " $mins minutes";
282
+    if($years==1)
283
+    {
284
+    	$str .= "$years year, ";
285
+    }
286
+    if($years>1)
287
+    {
288
+    	$str .= "$years years, ";
289
+    }
290
+    if($weeks==1)
291
+    {
292
+    	$str .= "$weeks week, ";
293
+    }
294
+    if($weeks>1)
295
+    {
296
+    	$str .= "$weeks weeks, ";
297
+    }
298
+    if($days==1)
299
+    {
300
+    	$str .= "$days day,";
301
+    }
302
+    if($days>1)
303
+    {
304
+    	$str .= "$days days,";
305
+    }
306
+    if($hours == 1)
307
+    {
308
+    	$str .= " $hours hour and";
309
+    }
310
+    if($hours>1)
311
+    {
312
+    	$str .= " $hours hours and";
313
+    }
314
+    if($mins == 1)
315
+    {
316
+    	$str .= " 1 minute";
317
+    }
318
+    else {
319
+    	$str .= " $mins minutes";
320
+    }
238 321
     return $str;
239 322
 }
240 323
 
241 324
 // create graphics
242 325
 //
243
-function graphics_avail() {
326
+function graphics_avail()
327
+{
244 328
 	return extension_loaded('gd');
245 329
 }
246 330
 if (isset($MYREQUEST['IMG']))
247 331
 {
248
-	if (!graphics_avail()) {
332
+	if (!graphics_avail())
333
+	{
249 334
 		exit(0);
250 335
 	}
251 336
 
252
-	function fill_arc($im, $centerX, $centerY, $diameter, $start, $end, $color1,$color2,$text='',$placeindex=0) {
337
+	function fill_arc($im, $centerX, $centerY, $diameter, $start, $end, $color1,$color2,$text='',$placeindex=0)
338
+	{
253 339
 		$r=$diameter/2;
254 340
 		$w=deg2rad((360+$start+($end-$start)/2)%360);
255 341
 
256 342
 
257
-		if (function_exists("imagefilledarc")) {
343
+		if (function_exists("imagefilledarc"))
344
+		{
258 345
 			// exists only if GD 2.0.1 is avaliable
259 346
 			imagefilledarc($im, $centerX+1, $centerY+1, $diameter, $diameter, $start, $end, $color1, IMG_ARC_PIE);
260 347
 			imagefilledarc($im, $centerX, $centerY, $diameter, $diameter, $start, $end, $color2, IMG_ARC_PIE);
261 348
 			imagefilledarc($im, $centerX, $centerY, $diameter, $diameter, $start, $end, $color1, IMG_ARC_NOFILL|IMG_ARC_EDGED);
262
-		} else {
349
+		}
350
+		else
351
+		{
263 352
 			imagearc($im, $centerX, $centerY, $diameter, $diameter, $start, $end, $color2);
264 353
 			imageline($im, $centerX, $centerY, $centerX + cos(deg2rad($start)) * $r, $centerY + sin(deg2rad($start)) * $r, $color2);
265 354
 			imageline($im, $centerX, $centerY, $centerX + cos(deg2rad($start+1)) * $r, $centerY + sin(deg2rad($start)) * $r, $color2);
@@ -267,41 +356,57 @@  discard block
 block discarded – undo
267 356
 			imageline($im, $centerX, $centerY, $centerX + cos(deg2rad($end))   * $r, $centerY + sin(deg2rad($end))   * $r, $color2);
268 357
 			imagefill($im,$centerX + $r*cos($w)/2, $centerY + $r*sin($w)/2, $color2);
269 358
 		}
270
-		if ($text) {
271
-			if ($placeindex>0) {
359
+		if ($text)
360
+		{
361
+			if ($placeindex>0)
362
+			{
272 363
 				imageline($im,$centerX + $r*cos($w)/2, $centerY + $r*sin($w)/2,$diameter, $placeindex*12,$color1);
273 364
 				imagestring($im,4,$diameter, $placeindex*12,$text,$color1);
274 365
 
275
-			} else {
366
+			}
367
+			else
368
+			{
276 369
 				imagestring($im,4,$centerX + $r*cos($w)/2, $centerY + $r*sin($w)/2,$text,$color1);
277 370
 			}
278 371
 		}
279 372
 	}
280 373
 
281
-	function text_arc($im, $centerX, $centerY, $diameter, $start, $end, $color1,$text,$placeindex=0) {
374
+	function text_arc($im, $centerX, $centerY, $diameter, $start, $end, $color1,$text,$placeindex=0)
375
+	{
282 376
 		$r=$diameter/2;
283 377
 		$w=deg2rad((360+$start+($end-$start)/2)%360);
284 378
 
285
-		if ($placeindex>0) {
379
+		if ($placeindex>0)
380
+		{
286 381
 			imageline($im,$centerX + $r*cos($w)/2, $centerY + $r*sin($w)/2,$diameter, $placeindex*12,$color1);
287 382
 			imagestring($im,4,$diameter, $placeindex*12,$text,$color1);
288 383
 
289
-		} else {
384
+		}
385
+		else
386
+		{
290 387
 			imagestring($im,4,$centerX + $r*cos($w)/2, $centerY + $r*sin($w)/2,$text,$color1);
291 388
 		}
292 389
 	}
293 390
 
294
-	function fill_box($im, $x, $y, $w, $h, $color1, $color2,$text='',$placeindex='') {
391
+	function fill_box($im, $x, $y, $w, $h, $color1, $color2,$text='',$placeindex='')
392
+	{
295 393
 		global $col_black;
296 394
 		$x1=$x+$w-1;
297 395
 		$y1=$y+$h-1;
298 396
 
299 397
 		imagerectangle($im, $x, $y1, $x1+1, $y+1, $col_black);
300
-		if($y1>$y) imagefilledrectangle($im, $x, $y, $x1, $y1, $color2);
301
-		else imagefilledrectangle($im, $x, $y1, $x1, $y, $color2);
398
+		if($y1>$y)
399
+		{
400
+			imagefilledrectangle($im, $x, $y, $x1, $y1, $color2);
401
+		}
402
+		else {
403
+			imagefilledrectangle($im, $x, $y1, $x1, $y, $color2);
404
+		}
302 405
 		imagerectangle($im, $x, $y1, $x1, $y, $color1);
303
-		if ($text) {
304
-			if ($placeindex>0) {
406
+		if ($text)
407
+		{
408
+			if ($placeindex>0)
409
+			{
305 410
 
306 411
 				if ($placeindex<16)
307 412
 				{
@@ -311,11 +416,16 @@  discard block
 block discarded – undo
311 416
 					imageline($im,$x,$y+$h/2,$px+90,$py,$color2);
312 417
 					imagestring($im,2,$px,$py-6,$text,$color1);
313 418
 
314
-				} else {
315
-					if ($placeindex<31) {
419
+				}
420
+				else
421
+				{
422
+					if ($placeindex<31)
423
+					{
316 424
 						$px=$x+40*2;
317 425
 						$py=($placeindex-15)*12+6;
318
-					} else {
426
+					}
427
+					else
428
+					{
319 429
 						$px=$x+40*2+100*intval(($placeindex-15)/15);
320 430
 						$py=($placeindex%15)*12+6;
321 431
 					}
@@ -323,7 +433,9 @@  discard block
 block discarded – undo
323 433
 					imageline($im,$x+$w,$y+$h/2,$px,$py,$color2);
324 434
 					imagestring($im,2,$px+2,$py-6,$text,$color1);
325 435
 				}
326
-			} else {
436
+			}
437
+			else
438
+			{
327 439
 				imagestring($im,4,$x+5,$y1-16,$text,$color1);
328 440
 			}
329 441
 		}
@@ -332,9 +444,12 @@  discard block
 block discarded – undo
332 444
 
333 445
 	$size = GRAPH_SIZE; // image size
334 446
 	if ($MYREQUEST['IMG']==3)
335
-		$image = imagecreate(2*$size+150, $size+10);
336
-	else
337
-		$image = imagecreate($size+50, $size+10);
447
+	{
448
+			$image = imagecreate(2*$size+150, $size+10);
449
+	}
450
+	else {
451
+			$image = imagecreate($size+50, $size+10);
452
+	}
338 453
 
339 454
 	$col_white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
340 455
 	$col_red   = imagecolorallocate($image, 0xD0, 0x60,  0x30);
@@ -342,7 +457,8 @@  discard block
 block discarded – undo
342 457
 	$col_black = imagecolorallocate($image,   0,   0,   0);
343 458
 	imagecolortransparent($image,$col_white);
344 459
 
345
-	switch ($MYREQUEST['IMG']) {
460
+	switch ($MYREQUEST['IMG'])
461
+	{
346 462
 
347 463
 	case 1:
348 464
 		$s=$mem['num_seg']*$mem['seg_size'];
@@ -354,43 +470,64 @@  discard block
 block discarded – undo
354 470
 		// would expect because we try to visualize any memory fragmentation as well.
355 471
 		$angle_from = 0;
356 472
 		$string_placement=array();
357
-		for($i=0; $i<$mem['num_seg']; $i++) {
473
+		for($i=0; $i<$mem['num_seg']; $i++)
474
+		{
358 475
 			$ptr = 0;
359 476
 			$free = $mem['block_lists'][$i];
360 477
 			uasort($free, 'block_sort');
361
-			foreach($free as $block) {
362
-				if($block['offset']!=$ptr) {       // Used block
478
+			foreach($free as $block)
479
+			{
480
+				if($block['offset']!=$ptr)
481
+				{
482
+// Used block
363 483
 					$angle_to = $angle_from+($block['offset']-$ptr)/$s;
364
-					if(($angle_to+$fuzz)>1) $angle_to = 1;
365
-					if( ($angle_to*360) - ($angle_from*360) >= 1) {
484
+					if(($angle_to+$fuzz)>1)
485
+					{
486
+						$angle_to = 1;
487
+					}
488
+					if( ($angle_to*360) - ($angle_from*360) >= 1)
489
+					{
366 490
 						fill_arc($image,$x,$y,$size,$angle_from*360,$angle_to*360,$col_black,$col_red);
367
-						if (($angle_to-$angle_from)>0.05) {
491
+						if (($angle_to-$angle_from)>0.05)
492
+						{
368 493
 							array_push($string_placement, array($angle_from,$angle_to));
369 494
 						}
370 495
 					}
371 496
 					$angle_from = $angle_to;
372 497
 				}
373 498
 				$angle_to = $angle_from+($block['size'])/$s;
374
-				if(($angle_to+$fuzz)>1) $angle_to = 1;
375
-				if( ($angle_to*360) - ($angle_from*360) >= 1) {
499
+				if(($angle_to+$fuzz)>1)
500
+				{
501
+					$angle_to = 1;
502
+				}
503
+				if( ($angle_to*360) - ($angle_from*360) >= 1)
504
+				{
376 505
 					fill_arc($image,$x,$y,$size,$angle_from*360,$angle_to*360,$col_black,$col_green);
377
-					if (($angle_to-$angle_from)>0.05) {
506
+					if (($angle_to-$angle_from)>0.05)
507
+					{
378 508
 						array_push($string_placement, array($angle_from,$angle_to));
379 509
 					}
380 510
 				}
381 511
 				$angle_from = $angle_to;
382 512
 				$ptr = $block['offset']+$block['size'];
383 513
 			}
384
-			if ($ptr < $mem['seg_size']) { // memory at the end
514
+			if ($ptr < $mem['seg_size'])
515
+			{
516
+// memory at the end
385 517
 				$angle_to = $angle_from + ($mem['seg_size'] - $ptr)/$s;
386
-				if(($angle_to+$fuzz)>1) $angle_to = 1;
518
+				if(($angle_to+$fuzz)>1)
519
+				{
520
+					$angle_to = 1;
521
+				}
387 522
 				fill_arc($image,$x,$y,$size,$angle_from*360,$angle_to*360,$col_black,$col_red);
388
-				if (($angle_to-$angle_from)>0.05) {
523
+				if (($angle_to-$angle_from)>0.05)
524
+				{
389 525
 					array_push($string_placement, array($angle_from,$angle_to));
390 526
 				}
391 527
 			}
392 528
 		}
393
-		foreach ($string_placement as $angle) {
529
+		foreach ($string_placement as $angle)
530
+		{
394 531
 			text_arc($image,$x,$y,$size,$angle[0]*360,$angle[1]*360,$col_black,bsize($s*($angle[1]-$angle[0])));
395 532
 		}
396 533
 		break;
@@ -412,32 +549,51 @@  discard block
 block discarded – undo
412 549
 
413 550
 		// This block of code creates the bar chart.  It is a lot more complex than you
414 551
 		// would expect because we try to visualize any memory fragmentation as well.
415
-		for($i=0; $i<$mem['num_seg']; $i++) {
552
+		for($i=0; $i<$mem['num_seg']; $i++)
553
+		{
416 554
 			$ptr = 0;
417 555
 			$free = $mem['block_lists'][$i];
418 556
 			uasort($free, 'block_sort');
419
-			foreach($free as $block) {
420
-				if($block['offset']!=$ptr) {       // Used block
557
+			foreach($free as $block)
558
+			{
559
+				if($block['offset']!=$ptr)
560
+				{
561
+// Used block
421 562
 					$h=(GRAPH_SIZE-5)*($block['offset']-$ptr)/$s;
422
-					if ($h>0) {
563
+					if ($h>0)
564
+					{
423 565
                                                 $j++;
424
-						if($j<75) fill_box($image,$x,$y,50,$h,$col_black,$col_red,bsize($block['offset']-$ptr),$j);
425
-                                                else fill_box($image,$x,$y,50,$h,$col_black,$col_red);
566
+						if($j<75)
567
+						{
568
+							fill_box($image,$x,$y,50,$h,$col_black,$col_red,bsize($block['offset']-$ptr),$j);
569
+						}
570
+                                                else {
571
+                                                	fill_box($image,$x,$y,50,$h,$col_black,$col_red);
572
+                                                }
426 573
                                         }
427 574
 					$y+=$h;
428 575
 				}
429 576
 				$h=(GRAPH_SIZE-5)*($block['size'])/$s;
430
-				if ($h>0) {
577
+				if ($h>0)
578
+				{
431 579
                                         $j++;
432
-					if($j<75) fill_box($image,$x,$y,50,$h,$col_black,$col_green,bsize($block['size']),$j);
433
-					else fill_box($image,$x,$y,50,$h,$col_black,$col_green);
580
+					if($j<75)
581
+					{
582
+						fill_box($image,$x,$y,50,$h,$col_black,$col_green,bsize($block['size']),$j);
583
+					}
584
+					else {
585
+						fill_box($image,$x,$y,50,$h,$col_black,$col_green);
586
+					}
434 587
                                 }
435 588
 				$y+=$h;
436 589
 				$ptr = $block['offset']+$block['size'];
437 590
 			}
438
-			if ($ptr < $mem['seg_size']) { // memory at the end
591
+			if ($ptr < $mem['seg_size'])
592
+			{
593
+// memory at the end
439 594
 				$h = (GRAPH_SIZE-5) * ($mem['seg_size'] - $ptr) / $s;
440
-				if ($h > 0) {
595
+				if ($h > 0)
596
+				{
441 597
 					fill_box($image,$x,$y,50,$h,$col_black,$col_red,bsize($mem['seg_size']-$ptr),$j++);
442 598
 				}
443 599
 			}
@@ -460,19 +616,26 @@  discard block
 block discarded – undo
460 616
 
461 617
 // pretty printer for byte values
462 618
 //
463
-function bsize($s) {
464
-	foreach (array('','K','M','G') as $i => $k) {
465
-		if ($s < 1024) break;
619
+function bsize($s)
620
+{
621
+	foreach (array('','K','M','G') as $i => $k)
622
+	{
623
+		if ($s < 1024)
624
+		{
625
+			break;
626
+		}
466 627
 		$s/=1024;
467 628
 	}
468 629
 	return sprintf("%5.1f %sBytes",$s,$k);
469 630
 }
470 631
 
471 632
 // sortable table header in "scripts for this host" view
472
-function sortheader($key,$name,$extra='') {
633
+function sortheader($key,$name,$extra='')
634
+{
473 635
 	global $MYREQUEST, $MY_SELF_WO_SORT;
474 636
 
475
-	if ($MYREQUEST['SORT1']==$key) {
637
+	if ($MYREQUEST['SORT1']==$key)
638
+	{
476 639
 		$MYREQUEST['SORT2'] = $MYREQUEST['SORT2']=='A' ? 'D' : 'A';
477 640
 	}
478 641
 	return "<a class=sortable href=\"$MY_SELF_WO_SORT$extra&SORT1=$key&SORT2=".$MYREQUEST['SORT2']."\">$name</a>";
@@ -480,13 +643,19 @@  discard block
 block discarded – undo
480 643
 }
481 644
 
482 645
 // create menu entry
483
-function menu_entry($ob,$title) {
646
+function menu_entry($ob,$title)
647
+{
484 648
 	global $MYREQUEST,$MY_SELF;
485
-	if ($MYREQUEST['OB']!=$ob) {
649
+	if ($MYREQUEST['OB']!=$ob)
650
+	{
486 651
 		return "<li><a href=\"$MY_SELF&OB=$ob\">$title</a></li>";
487
-	} else if (empty($MYREQUEST['SH'])) {
652
+	}
653
+	else if (empty($MYREQUEST['SH']))
654
+	{
488 655
 		return "<li><span class=active>$title</span></li>";
489
-	} else {
656
+	}
657
+	else
658
+	{
490 659
 		return "<li><a class=\"child_active\" href=\"$MY_SELF&OB=$ob\">$title</a></li>";
491 660
 	}
492 661
 }
@@ -496,18 +665,24 @@  discard block
 block discarded – undo
496 665
 	global $MY_SELF,$MYREQUEST,$AUTHENTICATED;
497 666
 	// needs ADMIN_PASSWORD to be changed!
498 667
 	//
499
-	if (!USE_AUTHENTICATION) {
668
+	if (!USE_AUTHENTICATION)
669
+	{
500 670
 		return;
501
-	} else if (ADMIN_PASSWORD=='password')
671
+	}
672
+	else if (ADMIN_PASSWORD=='password')
502 673
 	{
503 674
 		print <<<EOB
504 675
 			<a href="#" onClick="javascript:alert('You need to set a password at the top of apc.php before this will work!');return false";>$s</a>
505 676
 EOB;
506
-	} else if ($AUTHENTICATED) {
677
+	}
678
+	else if ($AUTHENTICATED)
679
+	{
507 680
 		print <<<EOB
508 681
 			'{$_SERVER['PHP_AUTH_USER']}'&nbsp;logged&nbsp;in!
509 682
 EOB;
510
-	} else{
683
+	}
684
+	else
685
+	{
511 686
 		print <<<EOB
512 687
 			<a href="$MY_SELF&LO=1&OB={$MYREQUEST['OB']}">$s</a>
513 688
 EOB;
@@ -516,9 +691,12 @@  discard block
 block discarded – undo
516 691
 
517 692
 function block_sort($array1, $array2)
518 693
 {
519
-	if ($array1['offset'] > $array2['offset']) {
694
+	if ($array1['offset'] > $array2['offset'])
695
+	{
520 696
 		return 1;
521
-	} else {
697
+	}
698
+	else
699
+	{
522 700
 		return -1;
523 701
 	}
524 702
 }
@@ -748,7 +926,8 @@  discard block
 block discarded – undo
748 926
 	menu_entry(OB_USER_CACHE,'User Cache Entries'),
749 927
 	menu_entry(OB_VERSION_CHECK,'Version Check');
750 928
 
751
-if ($AUTHENTICATED) {
929
+if ($AUTHENTICATED)
930
+{
752 931
 	echo <<<EOB
753 932
 		<li><a class="aright" href="$MY_SELF&CC=1&OB={$MYREQUEST['OB']}" onClick="javascript:return confirm('Are you sure?');">Clear Cache</a></li>
754 933
 EOB;
@@ -765,7 +944,8 @@  discard block
 block discarded – undo
765 944
 
766 945
 // MAIN SWITCH STATEMENT
767 946
 
768
-switch ($MYREQUEST['OB']) {
947
+switch ($MYREQUEST['OB'])
948
+{
769 949
 // -----------------------------------------------
770 950
 // Host Stats
771 951
 // -----------------------------------------------
@@ -791,9 +971,13 @@  discard block
 block discarded – undo
791 971
 EOB;
792 972
 
793 973
 	if(!empty($_SERVER['SERVER_NAME']))
794
-		echo "<tr class=tr-0><td class=td-0>APCu Host</td><td>{$_SERVER['SERVER_NAME']} $host</td></tr>\n";
974
+	{
975
+			echo "<tr class=tr-0><td class=td-0>APCu Host</td><td>{$_SERVER['SERVER_NAME']} $host</td></tr>\n";
976
+	}
795 977
 	if(!empty($_SERVER['SERVER_SOFTWARE']))
796
-		echo "<tr class=tr-1><td class=td-0>Server Software</td><td>{$_SERVER['SERVER_SOFTWARE']}</td></tr>\n";
978
+	{
979
+			echo "<tr class=tr-1><td class=td-0>Server Software</td><td>{$_SERVER['SERVER_SOFTWARE']}</td></tr>\n";
980
+	}
797 981
 
798 982
 	echo <<<EOB
799 983
 		<tr class=tr-0><td class=td-0>Shared Memory</td><td>{$mem['num_seg']} Segment(s) with $seg_size
@@ -825,15 +1009,19 @@  discard block
 block discarded – undo
825 1009
 EOB;
826 1010
 
827 1011
 	$j = 0;
828
-	foreach (ini_get_all('apcu') as $k => $v) {
1012
+	foreach (ini_get_all('apcu') as $k => $v)
1013
+	{
829 1014
 		echo "<tr class=tr-$j><td class=td-0>",$k,"</td><td>",str_replace(',',',<br />',$v['local_value']),"</td></tr>\n";
830 1015
 		$j = 1 - $j;
831 1016
 	}
832 1017
 
833 1018
 	if($mem['num_seg']>1 || $mem['num_seg']==1 && count($mem['block_lists'][0])>1)
834
-		$mem_note = "Memory Usage<br /><font size=-2>(multiple slices indicate fragments)</font>";
835
-	else
836
-		$mem_note = "Memory Usage";
1019
+	{
1020
+			$mem_note = "Memory Usage<br /><font size=-2>(multiple slices indicate fragments)</font>";
1021
+	}
1022
+	else {
1023
+			$mem_note = "Memory Usage";
1024
+	}
837 1025
 
838 1026
 	echo <<< EOB
839 1027
 		</tbody></table>
@@ -876,27 +1064,37 @@  discard block
 block discarded – undo
876 1064
 
877 1065
 	// Fragementation: (freeseg - 1) / total_seg
878 1066
 	$nseg = $freeseg = $fragsize = $freetotal = 0;
879
-	for($i=0; $i<$mem['num_seg']; $i++) {
1067
+	for($i=0; $i<$mem['num_seg']; $i++)
1068
+	{
880 1069
 		$ptr = 0;
881
-		foreach($mem['block_lists'][$i] as $block) {
882
-			if ($block['offset'] != $ptr) {
1070
+		foreach($mem['block_lists'][$i] as $block)
1071
+		{
1072
+			if ($block['offset'] != $ptr)
1073
+			{
883 1074
 				++$nseg;
884 1075
 			}
885 1076
 			$ptr = $block['offset'] + $block['size'];
886 1077
                         /* Only consider blocks <5M for the fragmentation % */
887
-                        if($block['size']<(5*1024*1024)) $fragsize+=$block['size'];
1078
+                        if($block['size']<(5*1024*1024))
1079
+                        {
1080
+                        	$fragsize+=$block['size'];
1081
+                        }
888 1082
                         $freetotal+=$block['size'];
889 1083
 		}
890 1084
 		$freeseg += count($mem['block_lists'][$i]);
891 1085
 	}
892 1086
 
893
-	if ($freeseg > 1) {
1087
+	if ($freeseg > 1)
1088
+	{
894 1089
 		$frag = sprintf("%.2f%% (%s out of %s in %d fragments)", ($fragsize/$freetotal)*100,bsize($fragsize),bsize($freetotal),$freeseg);
895
-	} else {
1090
+	}
1091
+	else
1092
+	{
896 1093
 		$frag = "0%";
897 1094
 	}
898 1095
 
899
-	if (graphics_avail()) {
1096
+	if (graphics_avail())
1097
+	{
900 1098
 		$size='width='.(2*GRAPH_SIZE+150).' height='.(GRAPH_SIZE+10);
901 1099
 		echo <<<EOB
902 1100
 			<img alt="" $size src="$PHP_SELF?IMG=3&$time">
@@ -907,11 +1105,18 @@  discard block
 block discarded – undo
907 1105
 		</td>
908 1106
 		</tr>
909 1107
 EOB;
910
-        if(isset($mem['adist'])) {
911
-          foreach($mem['adist'] as $i=>$v) {
1108
+        if(isset($mem['adist']))
1109
+        {
1110
+          foreach($mem['adist'] as $i=>$v)
1111
+          {
912 1112
             $cur = pow(2,$i); $nxt = pow(2,$i+1)-1;
913
-            if($i==0) $range = "1";
914
-            else $range = "$cur - $nxt";
1113
+            if($i==0)
1114
+            {
1115
+            	$range = "1";
1116
+            }
1117
+            else {
1118
+            	$range = "$cur - $nxt";
1119
+            }
915 1120
             echo "<tr><th align=right>$range</th><td align=right>$v</td></tr>\n";
916 1121
           }
917 1122
         }
@@ -927,7 +1132,8 @@  discard block
 block discarded – undo
927 1132
 // User Cache Entries
928 1133
 // -----------------------------------------------
929 1134
 case OB_USER_CACHE:
930
-	if (!$AUTHENTICATED) {
1135
+	if (!$AUTHENTICATED)
1136
+	{
931 1137
     echo '<div class="error">You need to login to see the user values here!<br/>&nbsp;<br/>';
932 1138
 		put_login_link("Login now!");
933 1139
 		echo '</div>';
@@ -955,8 +1161,11 @@  discard block
 block discarded – undo
955 1161
 		"<option value=M",$MYREQUEST['SORT1']=='M' ? " selected":"",">Last modified</option>",
956 1162
 		"<option value=C",$MYREQUEST['SORT1']=='C' ? " selected":"",">Created at</option>",
957 1163
 		"<option value=D",$MYREQUEST['SORT1']=='D' ? " selected":"",">Deleted at</option>";
958
-	if($fieldname=='info') echo
1164
+	if($fieldname=='info')
1165
+	{
1166
+		echo
959 1167
 		"<option value=D",$MYREQUEST['SORT1']=='T' ? " selected":"",">Timeout</option>";
1168
+	}
960 1169
 	echo
961 1170
 		'</select>',
962 1171
 		'<select name=SORT2>',
@@ -977,11 +1186,13 @@  discard block
 block discarded – undo
977 1186
 		'&nbsp;<input type=submit value="GO!">',
978 1187
 		'</form></div>';
979 1188
 
980
-  if (isset($MYREQUEST['SEARCH'])) {
1189
+  if (isset($MYREQUEST['SEARCH']))
1190
+  {
981 1191
    // Don't use preg_quote because we want the user to be able to specify a
982 1192
    // regular expression subpattern.
983 1193
    $MYREQUEST['SEARCH'] = '/'.str_replace('/', '\\/', $MYREQUEST['SEARCH']).'/i';
984
-   if (preg_match($MYREQUEST['SEARCH'], 'test') === false) {
1194
+   if (preg_match($MYREQUEST['SEARCH'], 'test') === false)
1195
+   {
985 1196
      echo '<div class="error">Error: enter a valid regular expression as a search query.</div>';
986 1197
      break;
987 1198
    }
@@ -997,7 +1208,8 @@  discard block
 block discarded – undo
997 1208
 		'<th>',sortheader('M','Last modified',"&OB=".$MYREQUEST['OB']),'</th>',
998 1209
 		'<th>',sortheader('C','Created at',   "&OB=".$MYREQUEST['OB']),'</th>';
999 1210
 
1000
-	if($fieldname=='info') {
1211
+	if($fieldname=='info')
1212
+	{
1001 1213
 		$cols+=2;
1002 1214
 		 echo '<th>',sortheader('T','Timeout',"&OB=".$MYREQUEST['OB']),'</th>';
1003 1215
 	}
@@ -1007,8 +1219,10 @@  discard block
 block discarded – undo
1007 1219
 	//
1008 1220
 	$list = array();
1009 1221
 
1010
-	foreach($cache[$scope_list[$MYREQUEST['SCOPE']]] as $i => $entry) {
1011
-		switch($MYREQUEST['SORT1']) {
1222
+	foreach($cache[$scope_list[$MYREQUEST['SCOPE']]] as $i => $entry)
1223
+	{
1224
+		switch($MYREQUEST['SORT1'])
1225
+		{
1012 1226
 			case 'A': $k=sprintf('%015d-',$entry['access_time']);  	     break;
1013 1227
 			case 'H': $k=sprintf('%015d-',$entry['num_hits']); 	     break;
1014 1228
 			case 'Z': $k=sprintf('%015d-',$entry['mem_size']); 	     break;
@@ -1018,26 +1232,33 @@  discard block
 block discarded – undo
1018 1232
 			case 'D': $k=sprintf('%015d-',$entry['deletion_time']);      break;
1019 1233
 			case 'S': $k=$entry["info"];				     break;
1020 1234
 		}
1021
-		if (!$AUTHENTICATED) {
1235
+		if (!$AUTHENTICATED)
1236
+		{
1022 1237
 			// hide all path entries if not logged in
1023 1238
 			$list[$k.$entry[$fieldname]]=preg_replace('/^.*(\\/|\\\\)/','*hidden*/',$entry);
1024
-		} else {
1239
+		}
1240
+		else
1241
+		{
1025 1242
 			$list[$k.$entry[$fieldname]]=$entry;
1026 1243
 		}
1027 1244
 	}
1028 1245
 
1029
-	if ($list) {
1246
+	if ($list)
1247
+	{
1030 1248
 		// sort list
1031 1249
 		//
1032
-		switch ($MYREQUEST['SORT2']) {
1250
+		switch ($MYREQUEST['SORT2'])
1251
+		{
1033 1252
 			case "A":	krsort($list);	break;
1034 1253
 			case "D":	ksort($list);	break;
1035 1254
 		}
1036 1255
 
1037 1256
 		// output list
1038 1257
 		$i=0;
1039
-		foreach($list as $k => $entry) {
1040
-      if(!$MYREQUEST['SEARCH'] || preg_match($MYREQUEST['SEARCH'], $entry[$fieldname]) != 0) {
1258
+		foreach($list as $k => $entry)
1259
+		{
1260
+      if(!$MYREQUEST['SEARCH'] || preg_match($MYREQUEST['SEARCH'], $entry[$fieldname]) != 0)
1261
+      {
1041 1262
 		$sh=md5($entry["info"]);
1042 1263
         $field_value = htmlentities(strip_tags($entry[$fieldname],''), ENT_QUOTES, 'UTF-8');
1043 1264
         echo
@@ -1049,43 +1270,58 @@  discard block
 block discarded – undo
1049 1270
           '<td class="td-n center">',date(DATE_FORMAT,$entry['mtime']),'</td>',
1050 1271
           '<td class="td-n center">',date(DATE_FORMAT,$entry['creation_time']),'</td>';
1051 1272
 
1052
-        if($fieldname=='info') {
1273
+        if($fieldname=='info')
1274
+        {
1053 1275
           if($entry['ttl'])
1054
-            echo '<td class="td-n center">'.$entry['ttl'].' seconds</td>';
1055
-          else
1056
-            echo '<td class="td-n center">None</td>';
1276
+          {
1277
+                      echo '<td class="td-n center">'.$entry['ttl'].' seconds</td>';
1278
+          }
1279
+          else {
1280
+                      echo '<td class="td-n center">None</td>';
1281
+          }
1057 1282
         }
1058
-        if ($entry['deletion_time']) {
1283
+        if ($entry['deletion_time'])
1284
+        {
1059 1285
 
1060 1286
           echo '<td class="td-last center">', date(DATE_FORMAT,$entry['deletion_time']), '</td>';
1061
-        } else if ($MYREQUEST['OB'] == OB_USER_CACHE) {
1287
+        }
1288
+        else if ($MYREQUEST['OB'] == OB_USER_CACHE)
1289
+        {
1062 1290
 
1063 1291
           echo '<td class="td-last center">';
1064 1292
           echo '[<a href="', $MY_SELF, '&OB=', $MYREQUEST['OB'], '&DU=', urlencode($entry[$fieldkey]), '">Delete Now</a>]';
1065 1293
           echo '</td>';
1066
-        } else {
1294
+        }
1295
+        else
1296
+        {
1067 1297
           echo '<td class="td-last center"> &nbsp; </td>';
1068 1298
         }
1069 1299
         echo '</tr>';
1070
-		if ($sh == $MYREQUEST["SH"]) {
1300
+		if ($sh == $MYREQUEST["SH"])
1301
+		{
1071 1302
 			echo '<tr>';
1072 1303
 			echo '<td colspan="7"><pre>'.htmlentities(print_r(apcu_fetch($entry['info']), 1)).'</pre></td>';
1073 1304
 			echo '</tr>';
1074 1305
 		}
1075 1306
         $i++;
1076 1307
         if ($i == $MYREQUEST['COUNT'])
1077
-          break;
1308
+        {
1309
+                  break;
1310
+        }
1078 1311
       }
1079 1312
 		}
1080 1313
 
1081
-	} else {
1314
+	}
1315
+	else
1316
+	{
1082 1317
 		echo '<tr class=tr-0><td class="center" colspan=',$cols,'><i>No data</i></td></tr>';
1083 1318
 	}
1084 1319
 	echo <<< EOB
1085 1320
 		</tbody></table>
1086 1321
 EOB;
1087 1322
 
1088
-	if ($list && $i < count($list)) {
1323
+	if ($list && $i < count($list))
1324
+	{
1089 1325
 		echo "<a href=\"$MY_SELF&OB=",$MYREQUEST['OB'],"&COUNT=0\"><i>",count($list)-$i,' more available...</i></a>';
1090 1326
 	}
1091 1327
 
@@ -1105,23 +1341,32 @@  discard block
 block discarded – undo
1105 1341
 		<th></th>
1106 1342
 		</tr>
1107 1343
 EOB;
1108
-  if (defined('PROXY')) {
1344
+  if (defined('PROXY'))
1345
+  {
1109 1346
     $ctxt = stream_context_create( array( 'http' => array( 'proxy' => PROXY, 'request_fulluri' => True ) ) );
1110 1347
     $rss = @file_get_contents("http://pecl.php.net/feeds/pkg_apcu.rss", False, $ctxt);
1111
-  } else {
1348
+  }
1349
+  else
1350
+  {
1112 1351
     $rss = @file_get_contents("http://pecl.php.net/feeds/pkg_apcu.rss");
1113 1352
   }
1114
-	if (!$rss) {
1353
+	if (!$rss)
1354
+	{
1115 1355
 		echo '<tr class="td-last center"><td>Unable to fetch version information.</td></tr>';
1116
-	} else {
1356
+	}
1357
+	else
1358
+	{
1117 1359
 		$apcversion = phpversion('apcu');
1118 1360
 
1119 1361
 		preg_match('!<title>APCu ([0-9.]+)</title>!', $rss, $match);
1120 1362
 		echo '<tr class="tr-0 center"><td>';
1121
-		if (version_compare($apcversion, $match[1], '>=')) {
1363
+		if (version_compare($apcversion, $match[1], '>='))
1364
+		{
1122 1365
 			echo '<div class="ok">You are running the latest version of APCu ('.$apcversion.')</div>';
1123 1366
 			$i = 3;
1124
-		} else {
1367
+		}
1368
+		else
1369
+		{
1125 1370
 			echo '<div class="failed">You are running an older version of APCu ('.$apcversion.'),
1126 1371
 				newer version '.$match[1].' is available at <a href="http://pecl.php.net/package/APCu/'.$match[1].'">
1127 1372
 				http://pecl.php.net/package/APCu/'.$match[1].'</a>
@@ -1134,11 +1379,15 @@  discard block
 block discarded – undo
1134 1379
 		preg_match_all('!<(title|description)>([^<]+)</\\1>!', $rss, $match);
1135 1380
 		next($match[2]); next($match[2]);
1136 1381
 
1137
-		while (list(,$v) = each($match[2])) {
1382
+		while (list(,$v) = each($match[2]))
1383
+		{
1138 1384
 			list(,$ver) = explode(' ', $v, 2);
1139
-			if ($i < 0 && version_compare($apcversion, $ver, '>=')) {
1385
+			if ($i < 0 && version_compare($apcversion, $ver, '>='))
1386
+			{
1140 1387
 				break;
1141
-			} else if (!$i--) {
1388
+			}
1389
+			else if (!$i--)
1390
+			{
1142 1391
 				break;
1143 1392
 			}
1144 1393
 			echo "<b><a href=\"http://pecl.php.net/package/APCu/$ver\">".htmlspecialchars($v, ENT_QUOTES, 'UTF-8')."</a></b><br><blockquote>";
Please login to merge, or discard this patch.
Upper-Lower-Casing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 				<big>Wrong Username or Password!</big><br/>&nbsp;<br/>&nbsp;
184 184
 				<big><a href='$PHP_SELF?OB={$MYREQUEST['OB']}'>Continue...</a></big>
185 185
 				</body></html>
186
-EOB;
186
+eob;
187 187
 			exit;
188 188
 
189 189
 		} else {
@@ -502,15 +502,15 @@  discard block
 block discarded – undo
502 502
 	{
503 503
 		print <<<EOB
504 504
 			<a href="#" onClick="javascript:alert('You need to set a password at the top of apc.php before this will work!');return false";>$s</a>
505
-EOB;
505
+eob;
506 506
 	} else if ($AUTHENTICATED) {
507 507
 		print <<<EOB
508 508
 			'{$_SERVER['PHP_AUTH_USER']}'&nbsp;logged&nbsp;in!
509
-EOB;
509
+eob;
510 510
 	} else{
511 511
 		print <<<EOB
512 512
 			<a href="$MY_SELF&LO=1&OB={$MYREQUEST['OB']}">$s</a>
513
-EOB;
513
+eob;
514 514
 	}
515 515
 }
516 516
 
@@ -742,7 +742,7 @@  discard block
 block discarded – undo
742 742
 echo <<<EOB
743 743
 	<ol class=menu>
744 744
 	<li><a href="$MY_SELF&OB={$MYREQUEST['OB']}&SH={$MYREQUEST['SH']}">Refresh Data</a></li>
745
-EOB;
745
+eob;
746 746
 echo
747 747
 	menu_entry(OB_HOST_STATS,'View Host Stats'),
748 748
 	menu_entry(OB_USER_CACHE,'User Cache Entries'),
@@ -751,17 +751,17 @@  discard block
 block discarded – undo
751 751
 if ($AUTHENTICATED) {
752 752
 	echo <<<EOB
753 753
 		<li><a class="aright" href="$MY_SELF&CC=1&OB={$MYREQUEST['OB']}" onClick="javascript:return confirm('Are you sure?');">Clear Cache</a></li>
754
-EOB;
754
+eob;
755 755
 }
756 756
 echo <<<EOB
757 757
 	</ol>
758
-EOB;
758
+eob;
759 759
 
760 760
 
761 761
 // CONTENT
762 762
 echo <<<EOB
763 763
 	<div class=content>
764
-EOB;
764
+eob;
765 765
 
766 766
 // MAIN SWITCH STATEMENT
767 767
 
@@ -788,7 +788,7 @@  discard block
 block discarded – undo
788 788
 		<table cellspacing=0><tbody>
789 789
 		<tr class=tr-0><td class=td-0>APCu Version</td><td>$apcversion</td></tr>
790 790
 		<tr class=tr-1><td class=td-0>PHP Version</td><td>$phpversion</td></tr>
791
-EOB;
791
+eob;
792 792
 
793 793
 	if(!empty($_SERVER['SERVER_NAME']))
794 794
 		echo "<tr class=tr-0><td class=td-0>APCu Host</td><td>{$_SERVER['SERVER_NAME']} $host</td></tr>\n";
@@ -799,7 +799,7 @@  discard block
 block discarded – undo
799 799
 		<tr class=tr-0><td class=td-0>Shared Memory</td><td>{$mem['num_seg']} Segment(s) with $seg_size
800 800
     <br/> ({$cache['memory_type']} memory)
801 801
     </td></tr>
802
-EOB;
802
+eob;
803 803
 	echo   '<tr class=tr-1><td class=td-0>Start Time</td><td>',date(DATE_FORMAT,$cache['start_time']),'</td></tr>';
804 804
 	echo   '<tr class=tr-0><td class=td-0>Uptime</td><td>',duration($cache['start_time']),'</td></tr>';
805 805
 	echo <<<EOB
@@ -822,7 +822,7 @@  discard block
 block discarded – undo
822 822
 		</div>
823 823
 
824 824
 		<div class="info div2"><h2>Runtime Settings</h2><table cellspacing=0><tbody>
825
-EOB;
825
+eob;
826 826
 
827 827
 	$j = 0;
828 828
 	foreach (ini_get_all('apcu') as $k => $v) {
@@ -841,14 +841,14 @@  discard block
 block discarded – undo
841 841
 
842 842
 		<div class="graph div3"><h2>Host Status Diagrams</h2>
843 843
 		<table cellspacing=0><tbody>
844
-EOB;
844
+eob;
845 845
 	$size='width='.(GRAPH_SIZE+50).' height='.(GRAPH_SIZE+10);
846 846
 echo <<<EOB
847 847
 		<tr>
848 848
 		<td class=td-0>$mem_note</td>
849 849
 		<td class=td-1>Hits &amp; Misses</td>
850 850
 		</tr>
851
-EOB;
851
+eob;
852 852
 
853 853
 	echo
854 854
 		graphics_avail() ?
@@ -872,7 +872,7 @@  discard block
 block discarded – undo
872 872
 		<table cellspacing=0><tbody>
873 873
 		<tr>
874 874
 		<td class=td-0 colspan=2><br/>
875
-EOB;
875
+eob;
876 876
 
877 877
 	// Fragementation: (freeseg - 1) / total_seg
878 878
 	$nseg = $freeseg = $fragsize = $freetotal = 0;
@@ -900,13 +900,13 @@  discard block
 block discarded – undo
900 900
 		$size='width='.(2*GRAPH_SIZE+150).' height='.(GRAPH_SIZE+10);
901 901
 		echo <<<EOB
902 902
 			<img alt="" $size src="$PHP_SELF?IMG=3&$time">
903
-EOB;
903
+eob;
904 904
 	}
905 905
 	echo <<<EOB
906 906
 		</br>Fragmentation: $frag
907 907
 		</td>
908 908
 		</tr>
909
-EOB;
909
+eob;
910 910
         if(isset($mem['adist'])) {
911 911
           foreach($mem['adist'] as $i=>$v) {
912 912
             $cur = pow(2,$i); $nxt = pow(2,$i+1)-1;
@@ -918,7 +918,7 @@  discard block
 block discarded – undo
918 918
         echo <<<EOB
919 919
 		</tbody></table>
920 920
 		</div>
921
-EOB;
921
+eob;
922 922
 
923 923
 	break;
924 924
 
@@ -942,7 +942,7 @@  discard block
 block discarded – undo
942 942
 		<div class=sorting><form>Scope:
943 943
 		<input type=hidden name=OB value={$MYREQUEST['OB']}>
944 944
 		<select name=SCOPE>
945
-EOB;
945
+eob;
946 946
 	echo
947 947
 		"<option value=A",$MYREQUEST['SCOPE']=='A' ? " selected":"",">Active</option>",
948 948
 		"<option value=D",$MYREQUEST['SCOPE']=='D' ? " selected":"",">Deleted</option>",
@@ -1083,7 +1083,7 @@  discard block
 block discarded – undo
1083 1083
 	}
1084 1084
 	echo <<< EOB
1085 1085
 		</tbody></table>
1086
-EOB;
1086
+eob;
1087 1087
 
1088 1088
 	if ($list && $i < count($list)) {
1089 1089
 		echo "<a href=\"$MY_SELF&OB=",$MYREQUEST['OB'],"&COUNT=0\"><i>",count($list)-$i,' more available...</i></a>';
@@ -1091,7 +1091,7 @@  discard block
 block discarded – undo
1091 1091
 
1092 1092
 	echo <<< EOB
1093 1093
 		</div>
1094
-EOB;
1094
+eob;
1095 1095
 	break;
1096 1096
 
1097 1097
 // -----------------------------------------------
@@ -1104,7 +1104,7 @@  discard block
 block discarded – undo
1104 1104
 		<tr>
1105 1105
 		<th></th>
1106 1106
 		</tr>
1107
-EOB;
1107
+eob;
1108 1108
   if (defined('PROXY')) {
1109 1109
     $ctxt = stream_context_create( array( 'http' => array( 'proxy' => PROXY, 'request_fulluri' => True ) ) );
1110 1110
     $rss = @file_get_contents("http://pecl.php.net/feeds/pkg_apcu.rss", False, $ctxt);
@@ -1150,14 +1150,14 @@  discard block
 block discarded – undo
1150 1150
 	echo <<< EOB
1151 1151
 		</tbody></table>
1152 1152
 		</div>
1153
-EOB;
1153
+eob;
1154 1154
 	break;
1155 1155
 
1156 1156
 }
1157 1157
 
1158 1158
 echo <<< EOB
1159 1159
 	</div>
1160
-EOB;
1160
+eob;
1161 1161
 
1162 1162
 ?>
1163 1163
 
Please login to merge, or discard this patch.
doc/test-cli.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 		// Find all /test/*Test.php files/classes
34 34
 		foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($basedir)) as $file)
35 35
 		{
36
-			if ($file->isFile() && preg_match('|/test/[^/]+Test\.php$|', $path=$file->getPathname()))
36
+			if ($file->isFile() && preg_match('|/test/[^/]+Test\.php$|', $path = $file->getPathname()))
37 37
 			{
38 38
 				// Include the test suite, as it is NOT autoloadable in test directory!
39 39
 				require_once($path);
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 					$class = 'EGroupware\\'.ucfirst($matches[1]);
47 47
 					if (!empty($matches[2]))
48 48
 					{
49
-						foreach(explode('/', $matches[3]) as $name)
49
+						foreach (explode('/', $matches[3]) as $name)
50 50
 						{
51 51
 							$class .= '\\'.ucfirst($name);
52 52
 						}
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -7,10 +7,13 @@
 block discarded – undo
7 7
  * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
8 8
  */
9 9
 
10
-if (php_sapi_name() !== 'cli')	// security precaution: forbit calling as web-page
10
+if (php_sapi_name() !== 'cli')
11
+{
12
+	// security precaution: forbit calling as web-page
11 13
 {
12 14
 	die('<h1>test-cli.php must NOT be called as web-page --> exiting !!!</h1>');
13 15
 }
16
+}
14 17
 
15 18
 ini_set('apc.enable_cli', true);
16 19
 
Please login to merge, or discard this patch.
api/src/loader/deprecated_factory.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
  */
28 28
 function CreateObject($class)
29 29
 {
30
-	list($appname,$classname) = explode('.',$class);
30
+	list($appname, $classname) = explode('.', $class);
31 31
 
32 32
 	if (!class_exists($classname))
33 33
 	{
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 				$classname = $replace[$classname];
54 54
 			}
55 55
 		}
56
-		if (!file_exists($f=EGW_INCLUDE_ROOT.'/'.$appname.'/inc/class.'.$classname.'.inc.php'))
56
+		if (!file_exists($f = EGW_INCLUDE_ROOT.'/'.$appname.'/inc/class.'.$classname.'.inc.php'))
57 57
 		{
58 58
 			throw new Api\Exception\AssertionFailed(__FUNCTION__."($classname) file $f not found!");
59 59
 		}
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 		require_once(EGW_INCLUDE_ROOT.'/'.$appname.'/inc/class.'.$classname.'.inc.php');
62 62
 	}
63 63
 	$args = func_get_args();
64
-	switch(count($args))
64
+	switch (count($args))
65 65
 	{
66 66
 		case 1:
67 67
 			$obj = new $classname;
@@ -70,18 +70,18 @@  discard block
 block discarded – undo
70 70
 			$obj = new $classname($args[1]);
71 71
 			break;
72 72
 		case 3:
73
-			$obj = new $classname($args[1],$args[2]);
73
+			$obj = new $classname($args[1], $args[2]);
74 74
 			break;
75 75
 		case 4:
76
-			$obj = new $classname($args[1],$args[2],$args[3]);
76
+			$obj = new $classname($args[1], $args[2], $args[3]);
77 77
 			break;
78 78
 		default:
79
-			$code = '$obj = new ' . $classname . '(';
80
-			foreach(array_keys($args) as $n)
79
+			$code = '$obj = new '.$classname.'(';
80
+			foreach (array_keys($args) as $n)
81 81
 			{
82 82
 				if ($n)
83 83
 				{
84
-					$code .= ($n > 1 ? ',' : '') . '$args[' . $n . ']';
84
+					$code .= ($n > 1 ? ',' : '').'$args['.$n.']';
85 85
 				}
86 86
 			}
87 87
 			$code .= ');';
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 {
108 108
 	if (!is_callable($acm))
109 109
 	{
110
-		list(,$class,$method) = explode('.',$acm);
110
+		list(,$class, $method) = explode('.', $acm);
111 111
 
112 112
 		if (class_exists($class))
113 113
 		{
@@ -118,17 +118,17 @@  discard block
 block discarded – undo
118 118
 			$obj = CreateObject($acm);
119 119
 		}
120 120
 
121
-		if (!method_exists($obj,$method))
121
+		if (!method_exists($obj, $method))
122 122
 		{
123 123
 			echo "<p><b>".function_backtrace()."</b>: no methode '$method' in class '$class'</p>\n";
124 124
 			return False;
125 125
 		}
126
-		$acm = array($obj,$method);
126
+		$acm = array($obj, $method);
127 127
 	}
128 128
 	$args = func_get_args();
129 129
 	unset($args[0]);
130 130
 
131
-	return call_user_func_array($acm,$args);
131
+	return call_user_func_array($acm, $args);
132 132
 }
133 133
 
134 134
 /**
@@ -146,13 +146,13 @@  discard block
 block discarded – undo
146 146
  */
147 147
 function ExecMethod($method, $functionparam = '_UNDEF_', $loglevel = 3, $classparams = '_UNDEF_')
148 148
 {
149
-	unset($loglevel);	// not used
149
+	unset($loglevel); // not used
150 150
 	/* Need to make sure this is working against a single dimensional object */
151
-	$partscount = count(explode('.',$method)) - 1;
151
+	$partscount = count(explode('.', $method)) - 1;
152 152
 
153 153
 	if (!is_callable($method) && $partscount == 2)
154 154
 	{
155
-		list($appname,$classname,$functionname) = explode(".", $method);
155
+		list($appname, $classname, $functionname) = explode(".", $method);
156 156
 
157 157
 		if ($classparams != '_UNDEF_' && ($classparams || $classparams != 'True'))
158 158
 		{
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 	}
177 177
 	if (is_callable($method))
178 178
 	{
179
-		return $functionparam != '_UNDEF_' ? call_user_func($method,$functionparam) : call_user_func($method);
179
+		return $functionparam != '_UNDEF_' ? call_user_func($method, $functionparam) : call_user_func($method);
180 180
 	}
181 181
 	error_log("ExecMethod('$method', ...) Error in parts! ".function_backtrace());
182 182
 	return false;
Please login to merge, or discard this patch.
api/src/Accounts/Ads.php 4 patches
Doc Comments   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 	/**
130 130
 	 * Factory method and singelton to get adLDAP object for given configuration or default server config
131 131
 	 *
132
-	 * @param array $config=null values for keys 'ads_domain', 'ads_host' (required) and optional 'ads_admin_user', 'ads_admin_passwd', 'ads_connection'
132
+	 * @param array $config values for keys 'ads_domain', 'ads_host' (required) and optional 'ads_admin_user', 'ads_admin_passwd', 'ads_connection'
133 133
 	 * @return adLDAP
134 134
 	 * @throws adLDAPException
135 135
 	 */
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
 	 * Convert binary GUID to string
309 309
 	 *
310 310
 	 * @param string $objectguid
311
-	 * @return int
311
+	 * @return string
312 312
 	 */
313 313
 	public function objectguid2str($objectguid)
314 314
 	{
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
 	 * Convert a string GUID to hex string used in filter
320 320
 	 *
321 321
 	 * @param string $strGUID
322
-	 * @return int
322
+	 * @return string
323 323
 	 */
324 324
 	public function objectguid2hex($strGUID)
325 325
 	{
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
 	 * Delete one account, deletes also all acl-entries for that account
379 379
 	 *
380 380
 	 * @param int $account_id numeric account_id
381
-	 * @return boolean true on success, false otherwise
381
+	 * @return string|boolean true on success, false otherwise
382 382
 	 */
383 383
 	function delete($account_id)
384 384
 	{
@@ -1138,7 +1138,7 @@  discard block
 block discarded – undo
1138 1138
 	 *
1139 1139
 	 * @param int $_account_id
1140 1140
 	 * @param string $ip
1141
-	 * @return int lastlogin time
1141
+	 * @return boolean lastlogin time
1142 1142
 	 */
1143 1143
 	function update_lastlogin($_account_id, $ip)
1144 1144
 	{
@@ -1335,7 +1335,7 @@  discard block
 block discarded – undo
1335 1335
 	 * - activate user
1336 1336
 	 *
1337 1337
 	 * @param array $attributes The attributes to set to the user account
1338
-	 * @return bool
1338
+	 * @return string|boolean
1339 1339
 	 */
1340 1340
 	public function create($attributes)
1341 1341
 	{
@@ -1525,7 +1525,7 @@  discard block
 block discarded – undo
1525 1525
     * @param string $username The username to query
1526 1526
     * @param array $attributes The attributes to modify.  Note if you set the enabled attribute you must not specify any other attributes
1527 1527
     * @param bool $isGUID Is the username passed a GUID or a samAccountName
1528
-    * @return bool
1528
+    * @return string|boolean
1529 1529
     */
1530 1530
     public function modify($username, $attributes, $isGUID = false)
1531 1531
     {
@@ -1590,7 +1590,7 @@  discard block
 block discarded – undo
1590 1590
 	 * Extended to allow to specify $attribute["container"] as string, because array hardcodes "OU=", while Samba4 and win2008r2 uses "CN=Users"
1591 1591
 	 *
1592 1592
 	 * @param array $attributes Default attributes of the group
1593
-	 * @return bool
1593
+	 * @return string|boolean
1594 1594
 	 */
1595 1595
 	public function create($attributes)
1596 1596
 	{
Please login to merge, or discard this patch.
Indentation   +174 added lines, -174 removed lines patch added patch discarded remove patch
@@ -807,11 +807,11 @@  discard block
 block discarded – undo
807 807
 	}
808 808
 
809 809
 	/**
810
-	* Add seconds between 1601-01-01 and 1970-01-01 and multiply by 10000000
811
-	*
812
-	* @param long $unixTime
813
-	* @return long windowsTime
814
-	*/
810
+	 * Add seconds between 1601-01-01 and 1970-01-01 and multiply by 10000000
811
+	 *
812
+	 * @param long $unixTime
813
+	 * @return long windowsTime
814
+	 */
815 815
 	public static function convertUnixTimeToWindowsTime($unixTime)
816 816
 	{
817 817
 		return ($unixTime + 11644477200) * 10000000;
@@ -1263,10 +1263,10 @@  discard block
 block discarded – undo
1263 1263
 	}
1264 1264
 
1265 1265
 	/**
1266
-    * Convert 8bit characters e.g. accented characters to UTF8 encoded characters
1267
-    *
1268
-    * Extended to use mbstring to convert from arbitrary charset to utf-8
1269
-	*/
1266
+	 * Convert 8bit characters e.g. accented characters to UTF8 encoded characters
1267
+	 *
1268
+	 * Extended to use mbstring to convert from arbitrary charset to utf-8
1269
+	 */
1270 1270
 	public function encode8Bit(&$item, $key)
1271 1271
 	{
1272 1272
 		if ($this->charset != 'utf-8' && $key != 'password')
@@ -1294,29 +1294,29 @@  discard block
 block discarded – undo
1294 1294
 		return $this->userClass;
1295 1295
 	}
1296 1296
 
1297
-    /**
1298
-    * Get the group class interface
1299
-    *
1300
-    * @return adLDAPGroups
1301
-    */
1302
-    public function group() {
1303
-        if (!$this->groupClass) {
1304
-            $this->groupClass = new adLDAPGroups($this);
1305
-        }
1306
-        return $this->groupClass;
1307
-    }
1308
-
1309
-    /**
1310
-    * Get the utils class interface
1311
-    *
1312
-    * @return adLDAPUtils
1313
-    */
1314
-    public function utilities() {
1315
-        if (!$this->utilClass) {
1316
-            $this->utilClass = new adLDAPUtils($this);
1317
-        }
1318
-        return $this->utilClass;
1319
-    }
1297
+	/**
1298
+	 * Get the group class interface
1299
+	 *
1300
+	 * @return adLDAPGroups
1301
+	 */
1302
+	public function group() {
1303
+		if (!$this->groupClass) {
1304
+			$this->groupClass = new adLDAPGroups($this);
1305
+		}
1306
+		return $this->groupClass;
1307
+	}
1308
+
1309
+	/**
1310
+	 * Get the utils class interface
1311
+	 *
1312
+	 * @return adLDAPUtils
1313
+	 */
1314
+	public function utilities() {
1315
+		if (!$this->utilClass) {
1316
+			$this->utilClass = new adLDAPUtils($this);
1317
+		}
1318
+		return $this->utilClass;
1319
+	}
1320 1320
 }
1321 1321
 
1322 1322
 /**
@@ -1405,45 +1405,45 @@  discard block
 block discarded – undo
1405 1405
 		return true;
1406 1406
 	}
1407 1407
 
1408
-    /**
1409
-    * Encode a password for transmission over LDAP
1410
-    *
1411
-    * Extended to use mbstring to convert from arbitrary charset to UTF-16LE
1412
-    *
1413
-    * @param string $password The password to encode
1414
-    * @return string
1415
-    */
1416
-    public function encodePassword($password)
1417
-    {
1418
-        $password="\"".$password."\"";
1419
-        if (function_exists('mb_convert_encoding') && !empty($this->adldap->charset))
1420
-        {
1421
-            return mb_convert_encoding($password, 'UTF-16LE', $this->adldap->charset);
1422
-        }
1423
-        $encoded="";
1424
-        for ($i=0; $i <strlen($password); $i++){ $encoded.="{$password{$i}}\000"; }
1425
-        return $encoded;
1426
-    }
1427
-
1428
-    /**
1429
-     * Set a password
1430
-     *
1431
-     * Requires "Reset password" priviledges from bind user!
1432
-     *
1408
+	/**
1409
+	 * Encode a password for transmission over LDAP
1410
+	 *
1411
+	 * Extended to use mbstring to convert from arbitrary charset to UTF-16LE
1412
+	 *
1413
+	 * @param string $password The password to encode
1414
+	 * @return string
1415
+	 */
1416
+	public function encodePassword($password)
1417
+	{
1418
+		$password="\"".$password."\"";
1419
+		if (function_exists('mb_convert_encoding') && !empty($this->adldap->charset))
1420
+		{
1421
+			return mb_convert_encoding($password, 'UTF-16LE', $this->adldap->charset);
1422
+		}
1423
+		$encoded="";
1424
+		for ($i=0; $i <strlen($password); $i++){ $encoded.="{$password{$i}}\000"; }
1425
+		return $encoded;
1426
+	}
1427
+
1428
+	/**
1429
+	 * Set a password
1430
+	 *
1431
+	 * Requires "Reset password" priviledges from bind user!
1432
+	 *
1433 1433
 	 * We can NOT set password with ldap_add or ldap_modify, it needs ldap_mod_replace, at least under Win2008r2!
1434 1434
 	 *
1435
-     * @param string $dn
1436
-     * @param string $password
1437
-     * @return boolean
1438
-     */
1439
-    public function setPassword($dn, $password)
1440
-    {
1441
-    	$result = ldap_mod_replace($ds=$this->adldap->getLdapConnection(), $dn, array(
1442
-    		'unicodePwd' => $this->encodePassword($password),
1443
-    	));
1444
-    	if (!$result) error_log(__METHOD__."('$dn', '$password') ldap_mod_replace($ds, '$dn', \$password) returned FALSE: ".ldap_error($ds));
1445
-    	return $result;
1446
-    }
1435
+	 * @param string $dn
1436
+	 * @param string $password
1437
+	 * @return boolean
1438
+	 */
1439
+	public function setPassword($dn, $password)
1440
+	{
1441
+		$result = ldap_mod_replace($ds=$this->adldap->getLdapConnection(), $dn, array(
1442
+			'unicodePwd' => $this->encodePassword($password),
1443
+		));
1444
+		if (!$result) error_log(__METHOD__."('$dn', '$password') ldap_mod_replace($ds, '$dn', \$password) returned FALSE: ".ldap_error($ds));
1445
+		return $result;
1446
+	}
1447 1447
 
1448 1448
 	/**
1449 1449
 	 * Check if we can to a real password change, not just a password reset
@@ -1457,30 +1457,30 @@  discard block
 block discarded – undo
1457 1457
 		return function_exists('ldap_modify_batch');
1458 1458
 	}
1459 1459
 
1460
-    /**
1461
-    * Set the password of a user - This must be performed over SSL
1462
-    *
1463
-    * @param string $username The username to modify
1464
-    * @param string $password The new password
1465
-    * @param bool $isGUID Is the username passed a GUID or a samAccountName
1466
-	* @param string $old_password old password for password change, if supported
1467
-    * @return bool
1468
-    */
1469
-    public function password($username, $password, $isGUID = false, $old_password=null)
1470
-    {
1471
-        if ($username === NULL) { return false; }
1472
-        if ($password === NULL) { return false; }
1473
-        if (!$this->adldap->getLdapBind()) { return false; }
1474
-        if (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) {
1475
-            throw new adLDAPException('SSL must be configured on your webserver and enabled in the class to set passwords.');
1476
-        }
1477
-
1478
-        $userDn = $this->dn($username, $isGUID);
1479
-        if ($userDn === false) {
1480
-            return false;
1481
-        }
1482
-
1483
-        $add=array();
1460
+	/**
1461
+	 * Set the password of a user - This must be performed over SSL
1462
+	 *
1463
+	 * @param string $username The username to modify
1464
+	 * @param string $password The new password
1465
+	 * @param bool $isGUID Is the username passed a GUID or a samAccountName
1466
+	 * @param string $old_password old password for password change, if supported
1467
+	 * @return bool
1468
+	 */
1469
+	public function password($username, $password, $isGUID = false, $old_password=null)
1470
+	{
1471
+		if ($username === NULL) { return false; }
1472
+		if ($password === NULL) { return false; }
1473
+		if (!$this->adldap->getLdapBind()) { return false; }
1474
+		if (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) {
1475
+			throw new adLDAPException('SSL must be configured on your webserver and enabled in the class to set passwords.');
1476
+		}
1477
+
1478
+		$userDn = $this->dn($username, $isGUID);
1479
+		if ($userDn === false) {
1480
+			return false;
1481
+		}
1482
+
1483
+		$add=array();
1484 1484
 
1485 1485
 		if (empty($old_password) || !function_exists('ldap_modify_batch')) {
1486 1486
 			$add["unicodePwd"][0] = $this->encodePassword($password);
@@ -1502,76 +1502,76 @@  discard block
 block discarded – undo
1502 1502
 			);
1503 1503
 			$result = ldap_modify_batch($this->adldap->getLdapConnection(), $userDn, $mods);
1504 1504
 		}
1505
-        if ($result === false){
1506
-            $err = ldap_errno($this->adldap->getLdapConnection());
1507
-            if ($err) {
1508
-                $msg = 'Error ' . $err . ': ' . ldap_err2str($err) . '.';
1509
-                if($err == 53) {
1510
-                    $msg .= ' Your password might not match the password policy.';
1511
-                }
1512
-                throw new adLDAPException($msg);
1513
-            }
1514
-            else {
1515
-                return false;
1516
-            }
1517
-        }
1518
-
1519
-        return true;
1520
-    }
1521
-
1522
-    /**
1523
-    * Modify a user
1524
-    *
1525
-    * @param string $username The username to query
1526
-    * @param array $attributes The attributes to modify.  Note if you set the enabled attribute you must not specify any other attributes
1527
-    * @param bool $isGUID Is the username passed a GUID or a samAccountName
1528
-    * @return bool
1529
-    */
1530
-    public function modify($username, $attributes, $isGUID = false)
1531
-    {
1532
-        if ($username === NULL) { return "Missing compulsory field [username]"; }
1533
-        if (array_key_exists("password", $attributes) && !$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) {
1534
-            throw new adLDAPException('SSL/TLS must be configured on your webserver and enabled in the class to set passwords.');
1535
-        }
1536
-
1537
-        // Find the dn of the user
1538
-        $userDn = $this->dn($username, $isGUID);
1539
-        if ($userDn === false) {
1540
-            return false;
1541
-        }
1542
-
1543
-        // Translate the update to the LDAP schema
1544
-        $mod = $this->adldap->adldap_schema($attributes);
1545
-
1546
-        // Check to see if this is an enabled status update
1547
-        if (!$mod && !array_key_exists("enabled", $attributes)){
1548
-            return false;
1549
-        }
1550
-
1551
-        // Set the account control attribute (only if specified)
1552
-        if (array_key_exists("enabled", $attributes)){
1553
-            if ($attributes["enabled"]){
1554
-                $controlOptions = array("NORMAL_ACCOUNT");
1555
-            }
1556
-            else {
1557
-                $controlOptions = array("NORMAL_ACCOUNT", "ACCOUNTDISABLE");
1558
-            }
1559
-            $mod["userAccountControl"][0] = $this->accountControl($controlOptions);
1560
-        }
1505
+		if ($result === false){
1506
+			$err = ldap_errno($this->adldap->getLdapConnection());
1507
+			if ($err) {
1508
+				$msg = 'Error ' . $err . ': ' . ldap_err2str($err) . '.';
1509
+				if($err == 53) {
1510
+					$msg .= ' Your password might not match the password policy.';
1511
+				}
1512
+				throw new adLDAPException($msg);
1513
+			}
1514
+			else {
1515
+				return false;
1516
+			}
1517
+		}
1518
+
1519
+		return true;
1520
+	}
1521
+
1522
+	/**
1523
+	 * Modify a user
1524
+	 *
1525
+	 * @param string $username The username to query
1526
+	 * @param array $attributes The attributes to modify.  Note if you set the enabled attribute you must not specify any other attributes
1527
+	 * @param bool $isGUID Is the username passed a GUID or a samAccountName
1528
+	 * @return bool
1529
+	 */
1530
+	public function modify($username, $attributes, $isGUID = false)
1531
+	{
1532
+		if ($username === NULL) { return "Missing compulsory field [username]"; }
1533
+		if (array_key_exists("password", $attributes) && !$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) {
1534
+			throw new adLDAPException('SSL/TLS must be configured on your webserver and enabled in the class to set passwords.');
1535
+		}
1536
+
1537
+		// Find the dn of the user
1538
+		$userDn = $this->dn($username, $isGUID);
1539
+		if ($userDn === false) {
1540
+			return false;
1541
+		}
1542
+
1543
+		// Translate the update to the LDAP schema
1544
+		$mod = $this->adldap->adldap_schema($attributes);
1545
+
1546
+		// Check to see if this is an enabled status update
1547
+		if (!$mod && !array_key_exists("enabled", $attributes)){
1548
+			return false;
1549
+		}
1550
+
1551
+		// Set the account control attribute (only if specified)
1552
+		if (array_key_exists("enabled", $attributes)){
1553
+			if ($attributes["enabled"]){
1554
+				$controlOptions = array("NORMAL_ACCOUNT");
1555
+			}
1556
+			else {
1557
+				$controlOptions = array("NORMAL_ACCOUNT", "ACCOUNTDISABLE");
1558
+			}
1559
+			$mod["userAccountControl"][0] = $this->accountControl($controlOptions);
1560
+		}
1561 1561
 		// we can NOT set password with ldap_add or ldap_modify, it needs ldap_mod_replace, at least under Win2008r2
1562 1562
 		unset($mod['unicodePwd']);
1563 1563
 
1564 1564
 		if ($mod)
1565 1565
 		{
1566
-	        // Do the update
1567
-	        $result = @ldap_modify($ds=$this->adldap->getLdapConnection(), $userDn, $mod);
1568
-	        if ($result == false) {
1566
+			// Do the update
1567
+			$result = @ldap_modify($ds=$this->adldap->getLdapConnection(), $userDn, $mod);
1568
+			if ($result == false) {
1569 1569
 				if (isset($mod['unicodePwd'])) $mod['unicodePwd'] = '***';
1570 1570
 				error_log(__METHOD__."(".array2string($attributes).") ldap_modify($ds, '$userDn', ".array2string($mod).") returned ".array2string($result)." ldap_error()=".ldap_error($ds));
1571
-	        	return false;
1572
-	        }
1571
+				return false;
1572
+			}
1573 1573
 		}
1574
-        if (array_key_exists("password",$attributes) && !$this->setPassword($userDn, $attributes['password']))
1574
+		if (array_key_exists("password",$attributes) && !$this->setPassword($userDn, $attributes['password']))
1575 1575
 		{
1576 1576
 			return false;
1577 1577
 		}
@@ -1636,23 +1636,23 @@  discard block
 block discarded – undo
1636 1636
 		return $this->adldap->encode8bit($item, $key);
1637 1637
 	}
1638 1638
 
1639
-    /**
1640
-    * Escape strings for the use in LDAP filters
1641
-    *
1642
-    * DEVELOPERS SHOULD BE DOING PROPER FILTERING IF THEY'RE ACCEPTING USER INPUT
1643
-    * Ported from Perl's Net::LDAP::Util escape_filter_value
1644
-    *
1645
-    * @param string $str The string the parse
1646
-    * @author Port by Andreas Gohr <[email protected]>
1647
-    * @return string
1648
-    */
1649
-    public function ldapSlashes($str){
1650
-        return preg_replace_callback(
1651
-      		'/([\x00-\x1F\*\(\)\\\\])/',
1652
-        	function ($matches) {
1653
-            	return "\\".join("", unpack("H2", $matches[1]));
1654
-        	},
1655
-        	$str
1656
-    	);
1657
-    }
1639
+	/**
1640
+	 * Escape strings for the use in LDAP filters
1641
+	 *
1642
+	 * DEVELOPERS SHOULD BE DOING PROPER FILTERING IF THEY'RE ACCEPTING USER INPUT
1643
+	 * Ported from Perl's Net::LDAP::Util escape_filter_value
1644
+	 *
1645
+	 * @param string $str The string the parse
1646
+	 * @author Port by Andreas Gohr <[email protected]>
1647
+	 * @return string
1648
+	 */
1649
+	public function ldapSlashes($str){
1650
+		return preg_replace_callback(
1651
+	  		'/([\x00-\x1F\*\(\)\\\\])/',
1652
+			function ($matches) {
1653
+				return "\\".join("", unpack("H2", $matches[1]));
1654
+			},
1655
+			$str
1656
+		);
1657
+	}
1658 1658
 }
Please login to merge, or discard this patch.
Braces   +238 added lines, -79 removed lines patch added patch discarded remove patch
@@ -136,12 +136,21 @@  discard block
 block discarded – undo
136 136
 	public static function get_adldap(array &$config=null)
137 137
 	{
138 138
 		static $adldap = array();
139
-		if (!$config) $config =& $GLOBALS['egw_info']['server'];
139
+		if (!$config)
140
+		{
141
+			$config =& $GLOBALS['egw_info']['server'];
142
+		}
140 143
 
141 144
 		if (!isset($adldap[$config['ads_domain']]))
142 145
 		{
143
-			if (empty($config['ads_host'])) throw new Api\Exception("Required ADS host name(s) missing!");
144
-			if (empty($config['ads_domain'])) throw new Api\Exception("Required ADS domain missing!");
146
+			if (empty($config['ads_host']))
147
+			{
148
+				throw new Api\Exception("Required ADS host name(s) missing!");
149
+			}
150
+			if (empty($config['ads_domain']))
151
+			{
152
+				throw new Api\Exception("Required ADS domain missing!");
153
+			}
145 154
 
146 155
 			$base_dn_parts = array();
147 156
 			foreach(explode('.', $config['ads_domain']) as $dc)
@@ -160,7 +169,10 @@  discard block
 block discarded – undo
160 169
 				'charset' => Api\Translation::charset(),
161 170
 			);
162 171
 			$adldap[$config['ads_domain']] = new adLDAP($options);
163
-			if (self::$debug) error_log(__METHOD__."() new adLDAP(".array2string($options).") returned ".array2string($adldap[$config['ads_domain']]).' '.function_backtrace());
172
+			if (self::$debug)
173
+			{
174
+				error_log(__METHOD__."() new adLDAP(".array2string($options).") returned ".array2string($adldap[$config['ads_domain']]).' '.function_backtrace());
175
+			}
164 176
 		}
165 177
 		//else error_log(__METHOD__."() returning cached adLDAP ".array2string($adldap[$config['ads_domain']]).' '.function_backtrace());
166 178
 		return $adldap[$config['ads_domain']];
@@ -241,7 +253,10 @@  discard block
 block discarded – undo
241 253
 			throw new Api\Exception\WrongUserinput("Wrong or not configured ADS context '$context' (baseDN='$base')!");
242 254
 		}
243 255
 		$container = $matches[1];
244
-		if (self::$debug) error_log(__METHOD__."() context='$context', base='$base' returning ".array2string($container));
256
+		if (self::$debug)
257
+		{
258
+			error_log(__METHOD__."() context='$context', base='$base' returning ".array2string($container));
259
+		}
245 260
 		return $container;
246 261
 	}
247 262
 
@@ -334,10 +349,16 @@  discard block
 block discarded – undo
334 349
 	 */
335 350
 	public function read($account_id)
336 351
 	{
337
-		if (!(int)$account_id) return false;
352
+		if (!(int)$account_id)
353
+		{
354
+			return false;
355
+		}
338 356
 
339 357
 		$ret = $account_id < 0 ? $this->_read_group($account_id) : $this->_read_user($account_id);
340
-		if (self::$debug) error_log(__METHOD__."($account_id) returning ".array2string($ret));
358
+		if (self::$debug)
359
+		{
360
+			error_log(__METHOD__."($account_id) returning ".array2string($ret));
361
+		}
341 362
 		return $ret;
342 363
 	}
343 364
 
@@ -370,7 +391,10 @@  discard block
 block discarded – undo
370 391
 		}
371 392
 		$ret = $is_group ? $this->_save_group($data, $old) : $this->_save_user($data, $old);
372 393
 
373
-		if (self::$debug) error_log(__METHOD__.'('.array2string($data).') returning '.array2string($ret));
394
+		if (self::$debug)
395
+		{
396
+			error_log(__METHOD__.'('.array2string($data).') returning '.array2string($ret));
397
+		}
374 398
 		return $ret;
375 399
 	}
376 400
 
@@ -400,7 +424,10 @@  discard block
 block discarded – undo
400 424
 		{
401 425
 			$ret = $this->adldap->user()->delete($account_lid);
402 426
 		}
403
-		if (self::$debug) error_log(__METHOD__."($account_id) account_lid='$account_lid' returning ".array2string($ret));
427
+		if (self::$debug)
428
+		{
429
+			error_log(__METHOD__."($account_id) account_lid='$account_lid' returning ".array2string($ret));
430
+		}
404 431
 		return $ret;
405 432
 	}
406 433
 
@@ -562,11 +589,17 @@  discard block
 block discarded – undo
562 589
 	protected static function _when2ts($_when)
563 590
 	{
564 591
 		static $utc=null;
565
-		if (!isset($utc)) $utc = new \DateTimeZone('UTC');
592
+		if (!isset($utc))
593
+		{
594
+			$utc = new \DateTimeZone('UTC');
595
+		}
566 596
 
567 597
 		list($when) = explode('.', $_when);	// remove .0Z not understood by createFromFormat
568 598
 		$datetime = Api\DateTime::createFromFormat(self::WHEN_FORMAT, $when, $utc);
569
-		if (Api\DateTime::$server_timezone) $datetime->setTimezone(Api\DateTime::$server_timezone);
599
+		if (Api\DateTime::$server_timezone)
600
+		{
601
+			$datetime->setTimezone(Api\DateTime::$server_timezone);
602
+		}
570 603
 
571 604
 		return $datetime->getTimestamp();
572 605
 	}
@@ -583,12 +616,15 @@  discard block
 block discarded – undo
583 616
 	{
584 617
 		//error_log(__METHOD__.'('.array2string($data).', old='.array2string($old).')');
585 618
 
586
-		if (!$old)	// new entry
619
+		if (!$old)
620
+		{
621
+			// new entry
587 622
 		{
588 623
 			static $new2adldap = array(
589 624
 				'account_lid'       => 'group_name',
590 625
 				'account_description' => 'description',
591 626
 			);
627
+		}
592 628
 			$attributes = array();
593 629
 			foreach($new2adldap as $egw => $adldap)
594 630
 			{
@@ -668,7 +704,9 @@  discard block
 block discarded – undo
668 704
 			$data['account_fullname'] = $data['account_firstname'].' '.$data['account_lastname'];
669 705
 		}
670 706
 
671
-		if (($new_entry = !$old))	// new entry
707
+		if (($new_entry = !$old))
708
+		{
709
+			// new entry
672 710
 		{
673 711
 			static $new2adldap = array(
674 712
 				'account_lid'       => 'username',
@@ -679,6 +717,7 @@  discard block
 block discarded – undo
679 717
 				'account_passwd'    => 'password',
680 718
 				'account_status'    => 'enabled',
681 719
 			);
720
+		}
682 721
 			$attributes = array();
683 722
 			foreach($new2adldap as $egw => $adldap)
684 723
 			{
@@ -687,7 +726,10 @@  discard block
 block discarded – undo
687 726
 				{
688 727
 					continue;	// do not try to set password, if no SSL or TLS, whole user creation will fail
689 728
 				}
690
-				if (isset($data[$egw])) $attributes[$adldap] = $data[$egw];
729
+				if (isset($data[$egw]))
730
+				{
731
+					$attributes[$adldap] = $data[$egw];
732
+				}
691 733
 			}
692 734
 			$attributes['enabled'] = !isset($data['account_status']) || $data['account_status'] === 'A';
693 735
 			$attributes['container'] = $this->_get_container();
@@ -773,7 +815,11 @@  discard block
 block discarded – undo
773 815
 							self::convertUnixTimeToWindowsTime($data[$egw]);
774 816
 						break;
775 817
 					case 'account_status':
776
-						if ($new_entry && empty($data['account_passwd'])) continue;	// cant active new account without passwd!
818
+						if ($new_entry && empty($data['account_passwd']))
819
+						{
820
+							continue;
821
+						}
822
+						// cant active new account without passwd!
777 823
 						$attributes[$adldap] = $data[$egw] == 'A';
778 824
 						break;
779 825
 					case 'account_lastpwd_change':
@@ -853,8 +899,14 @@  discard block
 block discarded – undo
853 899
 		}
854 900
 		// if it's a limited query, check if the unlimited query is cached
855 901
 		$start = $param['start'];
856
-		if (!($maxmatchs = $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs'])) $maxmatchs = 15;
857
-		if (!($offset = $param['offset'])) $offset = $maxmatchs;
902
+		if (!($maxmatchs = $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']))
903
+		{
904
+			$maxmatchs = 15;
905
+		}
906
+		if (!($offset = $param['offset']))
907
+		{
908
+			$offset = $maxmatchs;
909
+		}
858 910
 		unset($param['start']);
859 911
 		unset($param['offset']);
860 912
 		$unl_serial = serialize($param);
@@ -945,7 +997,10 @@  discard block
 block discarded – undo
945 997
 			$this->_callback_order = empty($param['order']) ? array('account_lid') : explode(',',$param['order']);
946 998
 			foreach($this->_callback_order as &$col)
947 999
 			{
948
-				if (substr($col, 0, 8) !== 'account_') $col = 'account_'.$col;
1000
+				if (substr($col, 0, 8) !== 'account_')
1001
+				{
1002
+					$col = 'account_'.$col;
1003
+				}
949 1004
 			}
950 1005
 			$sortedAccounts = $accounts;
951 1006
 			uasort($sortedAccounts,array($this,'_sort_callback'));
@@ -1055,7 +1110,10 @@  discard block
 block discarded – undo
1055 1110
 			$attrs ? $attrs : self::$default_attributes);
1056 1111
 		if (!$sri)
1057 1112
 		{
1058
-			if (self::$debug) error_log(__METHOD__.'('.array2string($attr_filter).", '$account_type') ldap_search($ds, '$context', '$filter') returned ".array2string($sri).' trying to reconnect ...');
1113
+			if (self::$debug)
1114
+			{
1115
+				error_log(__METHOD__.'('.array2string($attr_filter).", '$account_type') ldap_search($ds, '$context', '$filter') returned ".array2string($sri).' trying to reconnect ...');
1116
+			}
1059 1117
 			$sri = ldap_search($ds=$this->ldap_connection(true), $context=$this->ads_context(), $filter,
1060 1118
 				$attrs ? $attrs : self::$default_attributes);
1061 1119
 		}
@@ -1064,7 +1122,10 @@  discard block
 block discarded – undo
1064 1122
 		{
1065 1123
 			foreach($allValues as $key => $data)
1066 1124
 			{
1067
-				if ($key === 'count') continue;
1125
+				if ($key === 'count')
1126
+				{
1127
+					continue;
1128
+				}
1068 1129
 
1069 1130
 				if ($account_type && !($account_type == 'u' && $data['samaccounttype'][0] == adLDAP::ADLDAP_NORMAL_ACCOUNT ||
1070 1131
 					$account_type == 'g' && $data['samaccounttype'][0] == adLDAP::ADLDAP_SECURITY_GLOBAL_GROUP))
@@ -1082,7 +1143,10 @@  discard block
 block discarded – undo
1082 1143
 					$attrs ? $data : Api\Translation::convert($data['samaccountname'][0], 'utf-8');
1083 1144
 			}
1084 1145
 		}
1085
-		else if (self::$debug) error_log(__METHOD__.'('.array2string($attr_filter).", '$account_type') ldap_search($ds, '$context', '$filter')=$sri allValues=".array2string($allValues));
1146
+		else if (self::$debug)
1147
+		{
1148
+			error_log(__METHOD__.'('.array2string($attr_filter).", '$account_type') ldap_search($ds, '$context', '$filter')=$sri allValues=".array2string($allValues));
1149
+		}
1086 1150
 
1087 1151
 		//error_log(__METHOD__.'('.array2string($attr_filter).", '$account_type') ldap_search($ds, '$context', '$filter') returning ".array2string($accounts).' '.function_backtrace());
1088 1152
 		return $accounts;
@@ -1119,7 +1183,10 @@  discard block
 block discarded – undo
1119 1183
 				break;
1120 1184
 			}
1121 1185
 		}
1122
-		if (self::$debug) error_log(__METHOD__."('$name', '$which', '$account_type') returning ".array2string($ret));
1186
+		if (self::$debug)
1187
+		{
1188
+			error_log(__METHOD__."('$name', '$which', '$account_type') returning ".array2string($ret));
1189
+		}
1123 1190
 		return $ret;
1124 1191
 	}
1125 1192
 
@@ -1161,7 +1228,10 @@  discard block
 block discarded – undo
1161 1228
 	 */
1162 1229
 	function memberships($account_id)
1163 1230
 	{
1164
-		if (!($data = $this->frontend->read($account_id)) || $data['account_id'] <= 0) return false;
1231
+		if (!($data = $this->frontend->read($account_id)) || $data['account_id'] <= 0)
1232
+		{
1233
+			return false;
1234
+		}
1165 1235
 
1166 1236
 		return $data['memberships'];
1167 1237
 	}
@@ -1176,7 +1246,10 @@  discard block
 block discarded – undo
1176 1246
 	 */
1177 1247
 	function members($gid)
1178 1248
 	{
1179
-		if (!($data = $this->frontend->read($gid)) || $data['account_id'] >= 0) return false;
1249
+		if (!($data = $this->frontend->read($gid)) || $data['account_id'] >= 0)
1250
+		{
1251
+			return false;
1252
+		}
1180 1253
 
1181 1254
 		return $data['members'];
1182 1255
 	}
@@ -1190,7 +1263,10 @@  discard block
 block discarded – undo
1190 1263
 	 */
1191 1264
 	function set_memberships($groups,$account_id)
1192 1265
 	{
1193
-		if (!($account = $this->id2name($account_id))) return;
1266
+		if (!($account = $this->id2name($account_id)))
1267
+		{
1268
+			return;
1269
+		}
1194 1270
 		$current = array_keys($this->memberships($account_id));
1195 1271
 
1196 1272
 		$changed = 0;
@@ -1207,7 +1283,10 @@  discard block
 block discarded – undo
1207 1283
 				$changed += (int)$ok;
1208 1284
 			}
1209 1285
 		}
1210
-		if (self::$debug) error_log(__METHOD__.'('.array2string($groups).", $account_id) current=".array2string($current)." returning $changed");
1286
+		if (self::$debug)
1287
+		{
1288
+			error_log(__METHOD__.'('.array2string($groups).", $account_id) current=".array2string($current)." returning $changed");
1289
+		}
1211 1290
 		return $changed;
1212 1291
 	}
1213 1292
 
@@ -1220,7 +1299,10 @@  discard block
 block discarded – undo
1220 1299
 	 */
1221 1300
 	function set_members($users, $gid)
1222 1301
 	{
1223
-		if (!($group = $this->id2name($gid))) return;
1302
+		if (!($group = $this->id2name($gid)))
1303
+		{
1304
+			return;
1305
+		}
1224 1306
 		$current = array_keys($this->members($gid));
1225 1307
 
1226 1308
 		$changed = 0;
@@ -1237,7 +1319,10 @@  discard block
 block discarded – undo
1237 1319
 				$changed += (int)$ok;
1238 1320
 			}
1239 1321
 		}
1240
-		if (self::$debug) error_log(__METHOD__.'('.array2string($users).", $gid) current=".array2string($current)." returning $changed");
1322
+		if (self::$debug)
1323
+		{
1324
+			error_log(__METHOD__.'('.array2string($users).", $gid) current=".array2string($current)." returning $changed");
1325
+		}
1241 1326
 		return $changed;
1242 1327
 	}
1243 1328
 }
@@ -1291,8 +1376,10 @@  discard block
 block discarded – undo
1291 1376
 	 *
1292 1377
 	 * @return adLDAPUsers
1293 1378
 	 */
1294
-	public function user() {
1295
-		if (!$this->userClass) {
1379
+	public function user()
1380
+	{
1381
+		if (!$this->userClass)
1382
+		{
1296 1383
 			$this->userClass = new adLDAPUsers($this);
1297 1384
 		}
1298 1385
 		return $this->userClass;
@@ -1303,8 +1390,10 @@  discard block
 block discarded – undo
1303 1390
     *
1304 1391
     * @return adLDAPGroups
1305 1392
     */
1306
-    public function group() {
1307
-        if (!$this->groupClass) {
1393
+    public function group()
1394
+    {
1395
+        if (!$this->groupClass)
1396
+        {
1308 1397
             $this->groupClass = new adLDAPGroups($this);
1309 1398
         }
1310 1399
         return $this->groupClass;
@@ -1315,8 +1404,10 @@  discard block
 block discarded – undo
1315 1404
     *
1316 1405
     * @return adLDAPUtils
1317 1406
     */
1318
-    public function utilities() {
1319
-        if (!$this->utilClass) {
1407
+    public function utilities()
1408
+    {
1409
+        if (!$this->utilClass)
1410
+        {
1320 1411
             $this->utilClass = new adLDAPUtils($this);
1321 1412
         }
1322 1413
         return $this->utilClass;
@@ -1344,18 +1435,32 @@  discard block
 block discarded – undo
1344 1435
 	public function create($attributes)
1345 1436
 	{
1346 1437
 		// Check for compulsory fields
1347
-		if (!array_key_exists("username", $attributes)){ return "Missing compulsory field [username]"; }
1348
-		if (!array_key_exists("firstname", $attributes)){ return "Missing compulsory field [firstname]"; }
1349
-		if (!array_key_exists("surname", $attributes)){ return "Missing compulsory field [surname]"; }
1350
-		if (!array_key_exists("email", $attributes)){ return "Missing compulsory field [email]"; }
1351
-		if (!array_key_exists("container", $attributes)){ return "Missing compulsory field [container]"; }
1352
-		if (empty($attributes["container"])){ return "Container attribute must be an array or string."; }
1353
-
1354
-		if (array_key_exists("password",$attributes) && (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS())){
1438
+		if (!array_key_exists("username", $attributes))
1439
+		{
1440
+return "Missing compulsory field [username]"; }
1441
+		if (!array_key_exists("firstname", $attributes))
1442
+		{
1443
+return "Missing compulsory field [firstname]"; }
1444
+		if (!array_key_exists("surname", $attributes))
1445
+		{
1446
+return "Missing compulsory field [surname]"; }
1447
+		if (!array_key_exists("email", $attributes))
1448
+		{
1449
+return "Missing compulsory field [email]"; }
1450
+		if (!array_key_exists("container", $attributes))
1451
+		{
1452
+return "Missing compulsory field [container]"; }
1453
+		if (empty($attributes["container"]))
1454
+		{
1455
+return "Container attribute must be an array or string."; }
1456
+
1457
+		if (array_key_exists("password",$attributes) && (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()))
1458
+		{
1355 1459
 			throw new adLDAPException('SSL must be configured on your webserver and enabled in the class to set passwords.');
1356 1460
 		}
1357 1461
 
1358
-		if (!array_key_exists("display_name", $attributes)) {
1462
+		if (!array_key_exists("display_name", $attributes))
1463
+		{
1359 1464
 			$attributes["display_name"] = $attributes["firstname"] . " " . $attributes["surname"];
1360 1465
 		}
1361 1466
 
@@ -1377,7 +1482,8 @@  discard block
 block discarded – undo
1377 1482
 		$add["userAccountControl"][0] = $this->accountControl($control_options);
1378 1483
 
1379 1484
 		// Determine the container
1380
-		if (is_array($attributes['container'])) {
1485
+		if (is_array($attributes['container']))
1486
+		{
1381 1487
 			$attributes["container"] = array_reverse($attributes["container"]);
1382 1488
 			$attributes["container"] = "OU=" . implode(",OU=",$attributes["container"]);
1383 1489
 		}
@@ -1386,7 +1492,8 @@  discard block
 block discarded – undo
1386 1492
 
1387 1493
 		// Add the entry
1388 1494
 		$result = ldap_add($ds=$this->adldap->getLdapConnection(), $dn="CN=" . $add["cn"][0] . "," . $attributes["container"] . "," . $this->adldap->getBaseDn(), $add);
1389
-		if ($result != true) {
1495
+		if ($result != true)
1496
+		{
1390 1497
 			error_log(__METHOD__."(".array2string($attributes).") ldap_add($ds, '$dn', ".array2string($add).") returned ".array2string($result)." ldap_error()=".ldap_error($ds));
1391 1498
 			return false;
1392 1499
 		}
@@ -1394,7 +1501,10 @@  discard block
 block discarded – undo
1394 1501
 		// now password can be added to still disabled account
1395 1502
 		if (array_key_exists("password",$attributes))
1396 1503
 		{
1397
-			if (!$this->setPassword($dn, $attributes['password'])) return false;
1504
+			if (!$this->setPassword($dn, $attributes['password']))
1505
+			{
1506
+				return false;
1507
+			}
1398 1508
 
1399 1509
 			// now account can be enabled
1400 1510
 			if ($attributes["enabled"])
@@ -1402,7 +1512,10 @@  discard block
 block discarded – undo
1402 1512
 				$control_options = array("NORMAL_ACCOUNT");
1403 1513
 				$mod = array("userAccountControl" => $this->accountControl($control_options));
1404 1514
 				$result = ldap_modify($ds, $dn, $mod);
1405
-				if (!$result) error_log(__METHOD__."(".array2string($attributes).") ldap_modify($ds, '$dn', ".array2string($mod).") returned ".array2string($result)." ldap_error()=".ldap_error($ds));
1515
+				if (!$result)
1516
+				{
1517
+					error_log(__METHOD__."(".array2string($attributes).") ldap_modify($ds, '$dn', ".array2string($mod).") returned ".array2string($result)." ldap_error()=".ldap_error($ds));
1518
+				}
1406 1519
 			}
1407 1520
 		}
1408 1521
 
@@ -1425,7 +1538,9 @@  discard block
 block discarded – undo
1425 1538
             return mb_convert_encoding($password, 'UTF-16LE', $this->adldap->charset);
1426 1539
         }
1427 1540
         $encoded="";
1428
-        for ($i=0; $i <strlen($password); $i++){ $encoded.="{$password{$i}}\000"; }
1541
+        for ($i=0; $i <strlen($password); $i++)
1542
+        {
1543
+$encoded.="{$password{$i}}\000"; }
1429 1544
         return $encoded;
1430 1545
     }
1431 1546
 
@@ -1445,7 +1560,10 @@  discard block
 block discarded – undo
1445 1560
     	$result = ldap_mod_replace($ds=$this->adldap->getLdapConnection(), $dn, array(
1446 1561
     		'unicodePwd' => $this->encodePassword($password),
1447 1562
     	));
1448
-    	if (!$result) error_log(__METHOD__."('$dn', '$password') ldap_mod_replace($ds, '$dn', \$password) returned FALSE: ".ldap_error($ds));
1563
+    	if (!$result)
1564
+    	{
1565
+    		error_log(__METHOD__."('$dn', '$password') ldap_mod_replace($ds, '$dn', \$password) returned FALSE: ".ldap_error($ds));
1566
+    	}
1449 1567
     	return $result;
1450 1568
     }
1451 1569
 
@@ -1472,26 +1590,36 @@  discard block
 block discarded – undo
1472 1590
     */
1473 1591
     public function password($username, $password, $isGUID = false, $old_password=null)
1474 1592
     {
1475
-        if ($username === NULL) { return false; }
1476
-        if ($password === NULL) { return false; }
1477
-        if (!$this->adldap->getLdapBind()) { return false; }
1478
-        if (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) {
1593
+        if ($username === NULL)
1594
+        {
1595
+return false; }
1596
+        if ($password === NULL)
1597
+        {
1598
+return false; }
1599
+        if (!$this->adldap->getLdapBind())
1600
+        {
1601
+return false; }
1602
+        if (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS())
1603
+        {
1479 1604
             throw new adLDAPException('SSL must be configured on your webserver and enabled in the class to set passwords.');
1480 1605
         }
1481 1606
 
1482 1607
         $userDn = $this->dn($username, $isGUID);
1483
-        if ($userDn === false) {
1608
+        if ($userDn === false)
1609
+        {
1484 1610
             return false;
1485 1611
         }
1486 1612
 
1487 1613
         $add=array();
1488 1614
 
1489
-		if (empty($old_password) || !function_exists('ldap_modify_batch')) {
1615
+		if (empty($old_password) || !function_exists('ldap_modify_batch'))
1616
+		{
1490 1617
 			$add["unicodePwd"][0] = $this->encodePassword($password);
1491 1618
 
1492 1619
 			$result = @ldap_mod_replace($this->adldap->getLdapConnection(), $userDn, $add);
1493 1620
 		}
1494
-		else {
1621
+		else
1622
+		{
1495 1623
 			$mods = array(
1496 1624
 				array(
1497 1625
 					"attrib"  => "unicodePwd",
@@ -1506,16 +1634,20 @@  discard block
 block discarded – undo
1506 1634
 			);
1507 1635
 			$result = ldap_modify_batch($this->adldap->getLdapConnection(), $userDn, $mods);
1508 1636
 		}
1509
-        if ($result === false){
1637
+        if ($result === false)
1638
+        {
1510 1639
             $err = ldap_errno($this->adldap->getLdapConnection());
1511
-            if ($err) {
1640
+            if ($err)
1641
+            {
1512 1642
                 $msg = 'Error ' . $err . ': ' . ldap_err2str($err) . '.';
1513
-                if($err == 53) {
1643
+                if($err == 53)
1644
+                {
1514 1645
                     $msg .= ' Your password might not match the password policy.';
1515 1646
                 }
1516 1647
                 throw new adLDAPException($msg);
1517 1648
             }
1518
-            else {
1649
+            else
1650
+            {
1519 1651
                 return false;
1520 1652
             }
1521 1653
         }
@@ -1533,14 +1665,18 @@  discard block
 block discarded – undo
1533 1665
     */
1534 1666
     public function modify($username, $attributes, $isGUID = false)
1535 1667
     {
1536
-        if ($username === NULL) { return "Missing compulsory field [username]"; }
1537
-        if (array_key_exists("password", $attributes) && !$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()) {
1668
+        if ($username === NULL)
1669
+        {
1670
+return "Missing compulsory field [username]"; }
1671
+        if (array_key_exists("password", $attributes) && !$this->adldap->getUseSSL() && !$this->adldap->getUseTLS())
1672
+        {
1538 1673
             throw new adLDAPException('SSL/TLS must be configured on your webserver and enabled in the class to set passwords.');
1539 1674
         }
1540 1675
 
1541 1676
         // Find the dn of the user
1542 1677
         $userDn = $this->dn($username, $isGUID);
1543
-        if ($userDn === false) {
1678
+        if ($userDn === false)
1679
+        {
1544 1680
             return false;
1545 1681
         }
1546 1682
 
@@ -1548,16 +1684,20 @@  discard block
 block discarded – undo
1548 1684
         $mod = $this->adldap->adldap_schema($attributes);
1549 1685
 
1550 1686
         // Check to see if this is an enabled status update
1551
-        if (!$mod && !array_key_exists("enabled", $attributes)){
1687
+        if (!$mod && !array_key_exists("enabled", $attributes))
1688
+        {
1552 1689
             return false;
1553 1690
         }
1554 1691
 
1555 1692
         // Set the account control attribute (only if specified)
1556
-        if (array_key_exists("enabled", $attributes)){
1557
-            if ($attributes["enabled"]){
1693
+        if (array_key_exists("enabled", $attributes))
1694
+        {
1695
+            if ($attributes["enabled"])
1696
+            {
1558 1697
                 $controlOptions = array("NORMAL_ACCOUNT");
1559 1698
             }
1560
-            else {
1699
+            else
1700
+            {
1561 1701
                 $controlOptions = array("NORMAL_ACCOUNT", "ACCOUNTDISABLE");
1562 1702
             }
1563 1703
             $mod["userAccountControl"][0] = $this->accountControl($controlOptions);
@@ -1569,14 +1709,18 @@  discard block
 block discarded – undo
1569 1709
 		{
1570 1710
 	        // Do the update
1571 1711
 	        $result = @ldap_modify($ds=$this->adldap->getLdapConnection(), $userDn, $mod);
1572
-	        if ($result == false) {
1573
-				if (isset($mod['unicodePwd'])) $mod['unicodePwd'] = '***';
1712
+	        if ($result == false)
1713
+	        {
1714
+				if (isset($mod['unicodePwd']))
1715
+				{
1716
+					$mod['unicodePwd'] = '***';
1717
+				}
1574 1718
 				error_log(__METHOD__."(".array2string($attributes).") ldap_modify($ds, '$userDn', ".array2string($mod).") returned ".array2string($result)." ldap_error()=".ldap_error($ds));
1575 1719
 	        	return false;
1576 1720
 	        }
1577 1721
 		}
1578 1722
         if (array_key_exists("password",$attributes) && !$this->setPassword($userDn, $attributes['password']))
1579
-		{
1723
+        {
1580 1724
 			return false;
1581 1725
 		}
1582 1726
 		return true;
@@ -1598,10 +1742,18 @@  discard block
 block discarded – undo
1598 1742
 	 */
1599 1743
 	public function create($attributes)
1600 1744
 	{
1601
-		if (!is_array($attributes)){ return "Attributes must be an array"; }
1602
-		if (!array_key_exists("group_name", $attributes)){ return "Missing compulsory field [group_name]"; }
1603
-		if (!array_key_exists("container", $attributes)){ return "Missing compulsory field [container]"; }
1604
-		if (empty($attributes["container"])){ return "Container attribute must be an array or string."; }
1745
+		if (!is_array($attributes))
1746
+		{
1747
+return "Attributes must be an array"; }
1748
+		if (!array_key_exists("group_name", $attributes))
1749
+		{
1750
+return "Missing compulsory field [group_name]"; }
1751
+		if (!array_key_exists("container", $attributes))
1752
+		{
1753
+return "Missing compulsory field [container]"; }
1754
+		if (empty($attributes["container"]))
1755
+		{
1756
+return "Container attribute must be an array or string."; }
1605 1757
 
1606 1758
 		//$member_array = array();
1607 1759
 		//$member_array[0] = "cn=user1,cn=Users,dc=yourdomain,dc=com";
@@ -1611,16 +1763,21 @@  discard block
 block discarded – undo
1611 1763
 		$add["cn"] = $attributes["group_name"];
1612 1764
 		$add["samaccountname"] = $attributes["group_name"];
1613 1765
 		$add["objectClass"] = "Group";
1614
-		if (!empty($attributes["description"])) $add["description"] = $attributes["description"];
1766
+		if (!empty($attributes["description"]))
1767
+		{
1768
+			$add["description"] = $attributes["description"];
1769
+		}
1615 1770
 		//$add["member"] = $member_array; UNTESTED
1616 1771
 
1617 1772
 		// Determine the container
1618
-		if (is_array($attributes['container'])) {
1773
+		if (is_array($attributes['container']))
1774
+		{
1619 1775
 			$attributes["container"] = array_reverse($attributes["container"]);
1620 1776
 			$attributes["container"] = "OU=" . implode(",OU=",$attributes["container"]);
1621 1777
 		}
1622 1778
 		$result = ldap_add($this->adldap->getLdapConnection(), "CN=" . $add["cn"] . "," . $attributes["container"] . "," . $this->adldap->getBaseDn(), $add);
1623
-		if ($result != true) {
1779
+		if ($result != true)
1780
+		{
1624 1781
 			return false;
1625 1782
 		}
1626 1783
 		return true;
@@ -1650,10 +1807,12 @@  discard block
 block discarded – undo
1650 1807
     * @author Port by Andreas Gohr <[email protected]>
1651 1808
     * @return string
1652 1809
     */
1653
-    public function ldapSlashes($str){
1810
+    public function ldapSlashes($str)
1811
+    {
1654 1812
         return preg_replace_callback(
1655 1813
       		'/([\x00-\x1F\*\(\)\\\\])/',
1656
-        	function ($matches) {
1814
+        	function ($matches)
1815
+        	{
1657 1816
             	return "\\".join("", unpack("H2", $matches[1]));
1658 1817
         	},
1659 1818
         	$str
Please login to merge, or discard this patch.
Spacing   +110 added lines, -115 removed lines patch added patch discarded remove patch
@@ -133,10 +133,10 @@  discard block
 block discarded – undo
133 133
 	 * @return adLDAP
134 134
 	 * @throws adLDAPException
135 135
 	 */
136
-	public static function get_adldap(array &$config=null)
136
+	public static function get_adldap(array &$config = null)
137 137
 	{
138 138
 		static $adldap = array();
139
-		if (!$config) $config =& $GLOBALS['egw_info']['server'];
139
+		if (!$config) $config = & $GLOBALS['egw_info']['server'];
140 140
 
141 141
 		if (!isset($adldap[$config['ads_domain']]))
142 142
 		{
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 			if (empty($config['ads_domain'])) throw new Api\Exception("Required ADS domain missing!");
145 145
 
146 146
 			$base_dn_parts = array();
147
-			foreach(explode('.', $config['ads_domain']) as $dc)
147
+			foreach (explode('.', $config['ads_domain']) as $dc)
148 148
 			{
149 149
 				$base_dn_parts[] = 'DC='.$dc;
150 150
 			}
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 	 * @param int $account_id
173 173
 	 * @return string|NULL
174 174
 	 */
175
-	protected function get_sid($account_id=null)
175
+	protected function get_sid($account_id = null)
176 176
 	{
177 177
 		static $domain_sid = null;
178 178
 		if (!isset($domain_sid))
@@ -207,14 +207,14 @@  discard block
 block discarded – undo
207 207
 	 * @param boolean $set_if_empty =false true set from DN of "Domain Users" group #
208 208
 	 * @return string
209 209
 	 */
210
-	public function ads_context($set_if_empty=false)
210
+	public function ads_context($set_if_empty = false)
211 211
 	{
212 212
 		if (empty($this->frontend->config[self::ADS_CONTEXT]))
213 213
 		{
214 214
 			if ($set_if_empty && ($dn = $this->id2name(-self::DOMAIN_USERS_GROUP, 'account_dn')))
215 215
 			{
216 216
 				$dn = preg_replace('/^CN=.*?,(CN|OU)=/i', '$1=', $dn);
217
-				Api\Config::save_value(self::ADS_CONTEXT, $this->frontend->config[self::ADS_CONTEXT]=$dn, 'phpgwapi');
217
+				Api\Config::save_value(self::ADS_CONTEXT, $this->frontend->config[self::ADS_CONTEXT] = $dn, 'phpgwapi');
218 218
 			}
219 219
 			else
220 220
 			{
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 	 * @param boolean $reconnect =false true: reconnect even if already connected
252 252
 	 * @return resource
253 253
 	 */
254
-	public function ldap_connection($reconnect=false)
254
+	public function ldap_connection($reconnect = false)
255 255
 	{
256 256
 		if (($reconnect || !($ds = $this->adldap->getLdapConnection())) &&
257 257
 			// call connect, thought I dont know how it can be not connected ...
@@ -415,8 +415,7 @@  discard block
 block discarded – undo
415 415
 		$data = Api\Translation::convert($_data, 'utf-8');
416 416
 
417 417
 		// no need to calculate sid, if already calculated
418
-		$sid = is_string($data['objectsid']) ? $data['objectsid'] :
419
-			$this->adldap->utilities()->getTextSID($data['objectsid'][0]);
418
+		$sid = is_string($data['objectsid']) ? $data['objectsid'] : $this->adldap->utilities()->getTextSID($data['objectsid'][0]);
420 419
 		$account_id = -self::sid2account_id($sid);
421 420
 
422 421
 		$group = array(
@@ -453,7 +452,7 @@  discard block
 block discarded – undo
453 452
 	{
454 453
 		if (!($data = $this->filter(array('objectsid' => $this->get_sid($account_id)), 'g', self::$group_attributes)))
455 454
 		{
456
-			return false;	// group not found
455
+			return false; // group not found
457 456
 		}
458 457
 		$group = $this->_ldap2group(array_shift($data));
459 458
 
@@ -476,8 +475,7 @@  discard block
 block discarded – undo
476 475
 		$data = Api\Translation::convert($_data, 'utf-8');
477 476
 
478 477
 		// no need to calculate sid, if already calculated
479
-		$sid = is_string($data['objectsid']) ? $data['objectsid'] :
480
-			$this->adldap->utilities()->getTextSID($data['objectsid'][0]);
478
+		$sid = is_string($data['objectsid']) ? $data['objectsid'] : $this->adldap->utilities()->getTextSID($data['objectsid'][0]);
481 479
 		$account_id = self::sid2account_id($sid);
482 480
 
483 481
 		$user = array(
@@ -493,12 +491,10 @@  discard block
 block discarded – undo
493 491
 			'account_email'     => $data['mail'][0],
494 492
 			'account_fullname'  => $data['displayname'][0],
495 493
 			'account_phone'     => $data['telephonenumber'][0],
496
-			'account_status'    => $data['useraccountcontrol'][0] & 2 ? false : 'A',
494
+			'account_status'    => $data['useraccountcontrol'][0]&2 ? false : 'A',
497 495
 			'account_expires'   => !isset($data['accountexpires']) || !$data['accountexpires'][0] ||
498
-				$data['accountexpires'][0] == self::EXPIRES_NEVER ? -1 :
499
-				$this->adldap->utilities()->convertWindowsTimeToUnixTime($data['accountexpires'][0]),
500
-			'account_lastpwd_change' => !isset($data['pwdlastset']) ? null : (!$data['pwdlastset'][0] ? 0 :
501
-				$this->adldap->utilities()->convertWindowsTimeToUnixTime($data['pwdlastset'][0])),
496
+				$data['accountexpires'][0] == self::EXPIRES_NEVER ? -1 : $this->adldap->utilities()->convertWindowsTimeToUnixTime($data['accountexpires'][0]),
497
+			'account_lastpwd_change' => !isset($data['pwdlastset']) ? null : (!$data['pwdlastset'][0] ? 0 : $this->adldap->utilities()->convertWindowsTimeToUnixTime($data['pwdlastset'][0])),
502 498
 			'account_created' => !isset($data['whencreated'][0]) ? null :
503 499
 				self::_when2ts($data['whencreated'][0]),
504 500
 			'account_modified' => !isset($data['whenchanged'][0]) ? null :
@@ -509,7 +505,7 @@  discard block
 block discarded – undo
509 505
 		{
510 506
 			$user['account_status'] = false;
511 507
 		}
512
-		$user['person_id'] = $user['account_guid'];	// id of contact
508
+		$user['person_id'] = $user['account_guid']; // id of contact
513 509
 		//error_log(__METHOD__."(".array2string($data).") returning ".array2string($user));
514 510
 		return $user;
515 511
 	}
@@ -539,7 +535,7 @@  discard block
 block discarded – undo
539 535
 	{
540 536
 		if (!($data = $this->filter(array('objectsid' => $this->get_sid($account_id)), 'u', self::$user_attributes)))
541 537
 		{
542
-			return false;	// user not found
538
+			return false; // user not found
543 539
 		}
544 540
 		$user = $this->_ldap2user(array_shift($data));
545 541
 
@@ -562,10 +558,10 @@  discard block
 block discarded – undo
562 558
 	 */
563 559
 	protected static function _when2ts($_when)
564 560
 	{
565
-		static $utc=null;
561
+		static $utc = null;
566 562
 		if (!isset($utc)) $utc = new \DateTimeZone('UTC');
567 563
 
568
-		list($when) = explode('.', $_when);	// remove .0Z not understood by createFromFormat
564
+		list($when) = explode('.', $_when); // remove .0Z not understood by createFromFormat
569 565
 		$datetime = Api\DateTime::createFromFormat(self::WHEN_FORMAT, $when, $utc);
570 566
 		if (Api\DateTime::$server_timezone) $datetime->setTimezone(Api\DateTime::$server_timezone);
571 567
 
@@ -580,7 +576,7 @@  discard block
 block discarded – undo
580 576
 	 * @param array $old =null current data
581 577
 	 * @return int|false account_id or false on error
582 578
 	 */
583
-	protected function _save_group(array &$data, array $old=null)
579
+	protected function _save_group(array &$data, array $old = null)
584 580
 	{
585 581
 		//error_log(__METHOD__.'('.array2string($data).', old='.array2string($old).')');
586 582
 
@@ -591,7 +587,7 @@  discard block
 block discarded – undo
591 587
 				'account_description' => 'description',
592 588
 			);
593 589
 			$attributes = array();
594
-			foreach($new2adldap as $egw => $adldap)
590
+			foreach ($new2adldap as $egw => $adldap)
595 591
 			{
596 592
 				$attributes[$adldap] = (string)$data[$egw];
597 593
 			}
@@ -628,11 +624,11 @@  discard block
 block discarded – undo
628 624
 			'account_description' => 'description',
629 625
 		);
630 626
 		$ldap = array();
631
-		foreach($egw2adldap as $egw => $adldap)
627
+		foreach ($egw2adldap as $egw => $adldap)
632 628
 		{
633 629
 			if (isset($data[$egw]) && (string)$data[$egw] != (string)$old[$egw])
634 630
 			{
635
-				switch($egw)
631
+				switch ($egw)
636 632
 				{
637 633
 					case 'account_description':
638 634
 						$ldap[$adldap] = !empty($data[$egw]) ? $data[$egw] : array();
@@ -645,7 +641,7 @@  discard block
 block discarded – undo
645 641
 			}
646 642
 		}
647 643
 		// attributes not (yet) suppored by adldap
648
-		if ($ldap && !($ret = @ldap_modify($ds=$this->ldap_connection(), $old['account_dn'], $ldap)))
644
+		if ($ldap && !($ret = @ldap_modify($ds = $this->ldap_connection(), $old['account_dn'], $ldap)))
649 645
 		{
650 646
 			error_log(__METHOD__."(".array2string($data).") ldap_modify($ds, '$old[account_dn]', ".array2string($ldap).') returned '.array2string($ret));
651 647
 			return false;
@@ -661,7 +657,7 @@  discard block
 block discarded – undo
661 657
 	 * @param array $old =null current data
662 658
 	 * @return int|false account_id or false on error
663 659
 	 */
664
-	protected function _save_user(array &$data, array $old=null)
660
+	protected function _save_user(array &$data, array $old = null)
665 661
 	{
666 662
 		//error_log(__METHOD__.'('.array2string($data).', old='.array2string($old).')');
667 663
 		if (!isset($data['account_fullname']) && !empty($data['account_firstname']) && !empty($data['account_lastname']))
@@ -681,12 +677,12 @@  discard block
 block discarded – undo
681 677
 				'account_status'    => 'enabled',
682 678
 			);
683 679
 			$attributes = array();
684
-			foreach($new2adldap as $egw => $adldap)
680
+			foreach ($new2adldap as $egw => $adldap)
685 681
 			{
686 682
 				if ($egw == 'account_passwd' && (empty($data[$egw]) ||
687 683
 					!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS()))
688 684
 				{
689
-					continue;	// do not try to set password, if no SSL or TLS, whole user creation will fail
685
+					continue; // do not try to set password, if no SSL or TLS, whole user creation will fail
690 686
 				}
691 687
 				if (isset($data[$egw])) $attributes[$adldap] = $data[$egw];
692 688
 			}
@@ -723,7 +719,7 @@  discard block
 block discarded – undo
723 719
 			'account_firstname' => 'firstname',
724 720
 			'account_lastname'  => 'surname',
725 721
 			'account_email'     => 'email',
726
-			'account_fullname'  => 'display_name',	// handeled currently in rename above, as not supported by adLDAP
722
+			'account_fullname'  => 'display_name', // handeled currently in rename above, as not supported by adLDAP
727 723
 			'account_passwd'    => 'password',
728 724
 			'account_status'    => 'enabled',
729 725
 			'account_primary_group' => 'primarygroupid',
@@ -736,7 +732,7 @@  discard block
 block discarded – undo
736 732
 		// for a new entry set certain values (eg. profilePath) to in setup configured value
737 733
 		if ($new_entry)
738 734
 		{
739
-			foreach($this->frontend->config as $name => $value)
735
+			foreach ($this->frontend->config as $name => $value)
740 736
 			{
741 737
 				if (substr($name, 0, 8) == 'ads_new_')
742 738
 				{
@@ -744,22 +740,22 @@  discard block
 block discarded – undo
744 740
 				}
745 741
 			}
746 742
 		}
747
-		foreach($egw2adldap as $egw => $adldap)
743
+		foreach ($egw2adldap as $egw => $adldap)
748 744
 		{
749 745
 			if (isset($data[$egw]) && (string)$data[$egw] != (string)$old[$egw])
750 746
 			{
751
-				switch($egw)
747
+				switch ($egw)
752 748
 				{
753 749
 					case 'account_passwd':
754 750
 						if (!empty($data[$egw]) && ($this->adldap->getUseSSL() || $this->adldap->getUseTLS()))
755 751
 						{
756
-							$attributes[$adldap] = $data[$egw];	// only try to set password, if no SSL or TLS
752
+							$attributes[$adldap] = $data[$egw]; // only try to set password, if no SSL or TLS
757 753
 						}
758 754
 						break;
759 755
 					case 'account_primary_group':
760 756
 						// setting a primary group seems to fail, if user is no member of that group
761 757
 						if (isset($old['memberships'][$data[$egw]]) ||
762
-							($group=$this->id2name($data[$egw])) && $this->adldap->group()->addUser($group, $data['account_id']))
758
+							($group = $this->id2name($data[$egw])) && $this->adldap->group()->addUser($group, $data['account_id']))
763 759
 						{
764 760
 							$old['memberships'][$data[$egw]] = $group;
765 761
 							$ldap[$adldap] = abs($data[$egw]);
@@ -770,11 +766,10 @@  discard block
 block discarded – undo
770 766
 						$ldap['userPrincipalName'] = $data[$egw].'@'.$this->frontend->config['ads_domain'];
771 767
 						break;
772 768
 					case 'account_expires':
773
-						$attributes[$adldap] = $data[$egw] == -1 ? self::EXPIRES_NEVER :
774
-							self::convertUnixTimeToWindowsTime($data[$egw]);
769
+						$attributes[$adldap] = $data[$egw] == -1 ? self::EXPIRES_NEVER : self::convertUnixTimeToWindowsTime($data[$egw]);
775 770
 						break;
776 771
 					case 'account_status':
777
-						if ($new_entry && empty($data['account_passwd'])) continue;	// cant active new account without passwd!
772
+						if ($new_entry && empty($data['account_passwd'])) continue; // cant active new account without passwd!
778 773
 						$attributes[$adldap] = $data[$egw] == 'A';
779 774
 						break;
780 775
 					case 'account_lastpwd_change':
@@ -796,7 +791,7 @@  discard block
 block discarded – undo
796 791
 		}
797 792
 		//elseif ($attributes) error_log(__METHOD__."(".array2string($data).") adldap->user()->modify('$data[account_lid]', ".array2string($attributes).') returned '.array2string($ret).' '.function_backtrace());
798 793
 		// attributes not (yet) suppored by adldap
799
-		if ($ldap && !($ret = @ldap_modify($ds=$this->ldap_connection(), $old['account_dn'], $ldap)))
794
+		if ($ldap && !($ret = @ldap_modify($ds = $this->ldap_connection(), $old['account_dn'], $ldap)))
800 795
 		{
801 796
 			error_log(__METHOD__."(".array2string($data).") ldap_modify($ds, '$old[account_dn]', ".array2string($ldap).') returned '.array2string($ret).' ('.ldap_error($ds).') '.function_backtrace());
802 797
 			return false;
@@ -869,11 +864,11 @@  discard block
 block discarded – undo
869 864
 			$query = Api\Ldap::quote(strtolower($param['query']));
870 865
 
871 866
 			$accounts = array();
872
-			if($param['type'] !== 'groups')
867
+			if ($param['type'] !== 'groups')
873 868
 			{
874 869
 				if (!empty($query) && $query != '*')
875 870
 				{
876
-					switch($param['query_type'])
871
+					switch ($param['query_type'])
877 872
 					{
878 873
 						case 'all':
879 874
 						default:
@@ -904,14 +899,14 @@  discard block
 block discarded – undo
904 899
 					$membership_filter = '(|(memberOf='.$this->id2name((int)$param['type'], 'account_dn').')(PrimaryGroupId='.abs($param['type']).'))';
905 900
 					$filter = $filter ? "(&$membership_filter$filter)" : $membership_filter;
906 901
 				}
907
-				foreach($this->filter($filter, 'u', self::$user_attributes) as $account_id => $data)
902
+				foreach ($this->filter($filter, 'u', self::$user_attributes) as $account_id => $data)
908 903
 				{
909 904
 					$account = $this->_ldap2user($data);
910 905
 					if ($param['active'] && !$this->frontend->is_active($account))
911 906
 					{
912 907
 						continue;
913 908
 					}
914
-					$account['account_fullname'] = Api\Accounts::format_username($account['account_lid'],$account['account_firstname'],$account['account_lastname'],$account['account_id']);
909
+					$account['account_fullname'] = Api\Accounts::format_username($account['account_lid'], $account['account_firstname'], $account['account_lastname'], $account['account_id']);
915 910
 					$accounts[$account_id] = $account;
916 911
 				}
917 912
 			}
@@ -920,9 +915,9 @@  discard block
 block discarded – undo
920 915
 				$query = Api\Ldap::quote(strtolower($param['query']));
921 916
 
922 917
 				$filter = null;
923
-				if(!empty($query) && $query != '*')
918
+				if (!empty($query) && $query != '*')
924 919
 				{
925
-					switch($param['query_type'])
920
+					switch ($param['query_type'])
926 921
 					{
927 922
 						case 'all':
928 923
 						default:
@@ -936,27 +931,27 @@  discard block
 block discarded – undo
936 931
 					}
937 932
 					$filter = "(|(cn=$query)(description=$query))";
938 933
 				}
939
-				foreach($this->filter($filter, 'g', self::$group_attributes) as $account_id => $data)
934
+				foreach ($this->filter($filter, 'g', self::$group_attributes) as $account_id => $data)
940 935
 				{
941 936
 					$accounts[$account_id] = $this->_ldap2group($data);
942 937
 				}
943 938
 			}
944 939
 			// sort the array
945 940
 			$this->_callback_sort = strtoupper($param['sort']);
946
-			$this->_callback_order = empty($param['order']) ? array('account_lid') : explode(',',$param['order']);
947
-			foreach($this->_callback_order as &$col)
941
+			$this->_callback_order = empty($param['order']) ? array('account_lid') : explode(',', $param['order']);
942
+			foreach ($this->_callback_order as &$col)
948 943
 			{
949 944
 				if (substr($col, 0, 8) !== 'account_') $col = 'account_'.$col;
950 945
 			}
951 946
 			$sortedAccounts = $accounts;
952
-			uasort($sortedAccounts,array($this,'_sort_callback'));
947
+			uasort($sortedAccounts, array($this, '_sort_callback'));
953 948
 			$account_search[$unl_serial]['data'] = $sortedAccounts;
954 949
 
955 950
 			$account_search[$unl_serial]['total'] = $this->total = count($accounts);
956 951
 		}
957 952
 		// return only the wanted accounts
958 953
 		reset($sortedAccounts);
959
-		if(is_numeric($start) && is_numeric($offset))
954
+		if (is_numeric($start) && is_numeric($offset))
960 955
 		{
961 956
 			$account_search[$serial]['data'] = array_slice($sortedAccounts, $start, $offset);
962 957
 			$account_search[$serial]['total'] = $this->total;
@@ -987,19 +982,19 @@  discard block
 block discarded – undo
987 982
 	 * @param array $b
988 983
 	 * @return int
989 984
 	 */
990
-	protected function _sort_callback($a,$b)
985
+	protected function _sort_callback($a, $b)
991 986
 	{
992
-		foreach($this->_callback_order as $col )
987
+		foreach ($this->_callback_order as $col)
993 988
 		{
994
-			if($this->_callback_sort != 'DESC')
989
+			if ($this->_callback_sort != 'DESC')
995 990
 			{
996
-				$cmp = strcasecmp( $a[$col], $b[$col] );
991
+				$cmp = strcasecmp($a[$col], $b[$col]);
997 992
 			}
998 993
 			else
999 994
 			{
1000
-				$cmp = strcasecmp( $b[$col], $a[$col] );
995
+				$cmp = strcasecmp($b[$col], $a[$col]);
1001 996
 			}
1002
-			if ( $cmp != 0 )
997
+			if ($cmp != 0)
1003 998
 			{
1004 999
 				return $cmp;
1005 1000
 			}
@@ -1018,9 +1013,9 @@  discard block
 block discarded – undo
1018 1013
 	 * @param array $accounts =array() array to add filtered accounts too, default empty array
1019 1014
 	 * @return array account_id => account_lid or values for $attrs pairs
1020 1015
 	 */
1021
-	protected function filter($attr_filter, $account_type=null, array $attrs=null, array $accounts=array())
1016
+	protected function filter($attr_filter, $account_type = null, array $attrs = null, array $accounts = array())
1022 1017
 	{
1023
-		switch($account_type)
1018
+		switch ($account_type)
1024 1019
 		{
1025 1020
 			case 'u':
1026 1021
 				$type_filter = '(samaccounttype='.adLDAP::ADLDAP_NORMAL_ACCOUNT.')';
@@ -1045,25 +1040,25 @@  discard block
 block discarded – undo
1045 1040
 			}
1046 1041
 			else
1047 1042
 			{
1048
-				foreach($attr_filter as $attr => $value)
1043
+				foreach ($attr_filter as $attr => $value)
1049 1044
 				{
1050 1045
 					$filter .= '('.$attr.'='.$this->adldap->utilities()->ldapSlashes($value).')';
1051 1046
 				}
1052 1047
 			}
1053 1048
 			$filter .= $type_filter.')';
1054 1049
 		}
1055
-		$sri = ldap_search($ds=$this->ldap_connection(), $context=$this->ads_context(), $filter,
1050
+		$sri = ldap_search($ds = $this->ldap_connection(), $context = $this->ads_context(), $filter,
1056 1051
 			$attrs ? $attrs : self::$default_attributes);
1057 1052
 		if (!$sri)
1058 1053
 		{
1059 1054
 			if (self::$debug) error_log(__METHOD__.'('.array2string($attr_filter).", '$account_type') ldap_search($ds, '$context', '$filter') returned ".array2string($sri).' trying to reconnect ...');
1060
-			$sri = ldap_search($ds=$this->ldap_connection(true), $context=$this->ads_context(), $filter,
1055
+			$sri = ldap_search($ds = $this->ldap_connection(true), $context = $this->ads_context(), $filter,
1061 1056
 				$attrs ? $attrs : self::$default_attributes);
1062 1057
 		}
1063 1058
 
1064 1059
 		if ($sri && ($allValues = ldap_get_entries($ds, $sri)))
1065 1060
 		{
1066
-			foreach($allValues as $key => $data)
1061
+			foreach ($allValues as $key => $data)
1067 1062
 			{
1068 1063
 				if ($key === 'count') continue;
1069 1064
 
@@ -1077,7 +1072,7 @@  discard block
 block discarded – undo
1077 1072
 
1078 1073
 				if ($data['samaccounttype'][0] == adLDAP::ADLDAP_NORMAL_ACCOUNT && $rid < self::MIN_ACCOUNT_ID)
1079 1074
 				{
1080
-					continue;	// ignore system accounts incl. "Administrator"
1075
+					continue; // ignore system accounts incl. "Administrator"
1081 1076
 				}
1082 1077
 				$accounts[($data['samaccounttype'][0] == adLDAP::ADLDAP_SECURITY_GLOBAL_GROUP ? '-' : '').$rid] =
1083 1078
 					$attrs ? $data : Api\Translation::convert($data['samaccountname'][0], 'utf-8');
@@ -1101,7 +1096,7 @@  discard block
 block discarded – undo
1101 1096
 	 * @param string $account_type u = user, g = group, default null = try both
1102 1097
 	 * @return int|false numeric account_id or false on error ($name not found)
1103 1098
 	 */
1104
-	public function name2id($name, $which='account_lid', $account_type=null)
1099
+	public function name2id($name, $which = 'account_lid', $account_type = null)
1105 1100
 	{
1106 1101
 		static $to_ldap = array(
1107 1102
 			'account_lid'   => 'samaccountname',
@@ -1113,7 +1108,7 @@  discard block
 block discarded – undo
1113 1108
 		$ret = false;
1114 1109
 		if (isset($to_ldap[$which]))
1115 1110
 		{
1116
-			foreach($this->filter(array($to_ldap[$which] => $name), $account_type) as $account_id => $account_lid)
1111
+			foreach ($this->filter(array($to_ldap[$which] => $name), $account_type) as $account_id => $account_lid)
1117 1112
 			{
1118 1113
 				unset($account_lid);
1119 1114
 				$ret = $account_id;
@@ -1133,9 +1128,9 @@  discard block
 block discarded – undo
1133 1128
 	 * @param string $which ='account_lid' type to convert to: account_lid (default), account_email, ...
1134 1129
 	 * @return string/false converted value or false on error ($account_id not found)
1135 1130
 	 */
1136
-	public function id2name($account_id, $which='account_lid')
1131
+	public function id2name($account_id, $which = 'account_lid')
1137 1132
 	{
1138
-		return $this->frontend->id2name($account_id,$which);
1133
+		return $this->frontend->id2name($account_id, $which);
1139 1134
 	}
1140 1135
 
1141 1136
 	/**
@@ -1147,9 +1142,9 @@  discard block
 block discarded – undo
1147 1142
 	 */
1148 1143
 	function update_lastlogin($_account_id, $ip)
1149 1144
 	{
1150
-		unset($_account_id, $ip);	// not used, but required by function signature
1145
+		unset($_account_id, $ip); // not used, but required by function signature
1151 1146
 
1152
-		return false;	// not longer supported
1147
+		return false; // not longer supported
1153 1148
 	}
1154 1149
 
1155 1150
 	/**
@@ -1189,21 +1184,21 @@  discard block
 block discarded – undo
1189 1184
 	 * @param int $account_id uidnumber
1190 1185
 	 * @return int number of added or removed memberships
1191 1186
 	 */
1192
-	function set_memberships($groups,$account_id)
1187
+	function set_memberships($groups, $account_id)
1193 1188
 	{
1194 1189
 		if (!($account = $this->id2name($account_id))) return;
1195 1190
 		$current = array_keys($this->memberships($account_id));
1196 1191
 
1197 1192
 		$changed = 0;
1198
-		foreach(array(
1199
-			'add' => array_diff($groups, $current),		// add account to all groups he is currently not in
1200
-			'remove' => array_diff($current, $groups),	// remove account from all groups he is only currently in
1193
+		foreach (array(
1194
+			'add' => array_diff($groups, $current), // add account to all groups he is currently not in
1195
+			'remove' => array_diff($current, $groups), // remove account from all groups he is only currently in
1201 1196
 		) as $op => $memberships)
1202 1197
 		{
1203 1198
 			$func = $op.($account_id > 0 ? 'User' : 'Group');
1204
-			foreach($memberships as $gid)
1199
+			foreach ($memberships as $gid)
1205 1200
 			{
1206
-				$ok = $this->adldap->group()->$func($group=$this->id2name($gid), $account);
1201
+				$ok = $this->adldap->group()->$func($group = $this->id2name($gid), $account);
1207 1202
 				//error_log(__METHOD__.'('.array2string($groups).", $account_id) $func('$group', '$account') returned ".array2string($ok));
1208 1203
 				$changed += (int)$ok;
1209 1204
 			}
@@ -1225,15 +1220,15 @@  discard block
 block discarded – undo
1225 1220
 		$current = array_keys($this->members($gid));
1226 1221
 
1227 1222
 		$changed = 0;
1228
-		foreach(array(
1229
-			'add' => array_diff($users, $current),	// add members currently not in
1230
-			'remove' => array_diff($current, $users),	// remove members only currently in
1223
+		foreach (array(
1224
+			'add' => array_diff($users, $current), // add members currently not in
1225
+			'remove' => array_diff($current, $users), // remove members only currently in
1231 1226
 		) as $op => $members)
1232 1227
 		{
1233
-			foreach($members as $account_id)
1228
+			foreach ($members as $account_id)
1234 1229
 			{
1235 1230
 				$func = $op.($account_id > 0 ? 'User' : 'Group');
1236
-				$ok = $this->adldap->group()->$func($group, $account=$this->id2name($account_id));
1231
+				$ok = $this->adldap->group()->$func($group, $account = $this->id2name($account_id));
1237 1232
 				//error_log(__METHOD__.'('.array2string($users).", $account_id) $func('$group', '$account') returned ".array2string($ok));
1238 1233
 				$changed += (int)$ok;
1239 1234
 			}
@@ -1258,7 +1253,7 @@  discard block
 block discarded – undo
1258 1253
 	 */
1259 1254
 	public $charset = 'iso-8859-1';
1260 1255
 
1261
-	function __construct(array $options=array())
1256
+	function __construct(array $options = array())
1262 1257
 	{
1263 1258
 		if (isset($options['charset']))
1264 1259
 		{
@@ -1345,19 +1340,19 @@  discard block
 block discarded – undo
1345 1340
 	public function create($attributes)
1346 1341
 	{
1347 1342
 		// Check for compulsory fields
1348
-		if (!array_key_exists("username", $attributes)){ return "Missing compulsory field [username]"; }
1349
-		if (!array_key_exists("firstname", $attributes)){ return "Missing compulsory field [firstname]"; }
1350
-		if (!array_key_exists("surname", $attributes)){ return "Missing compulsory field [surname]"; }
1351
-		if (!array_key_exists("email", $attributes)){ return "Missing compulsory field [email]"; }
1352
-		if (!array_key_exists("container", $attributes)){ return "Missing compulsory field [container]"; }
1353
-		if (empty($attributes["container"])){ return "Container attribute must be an array or string."; }
1354
-
1355
-		if (array_key_exists("password",$attributes) && (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS())){
1343
+		if (!array_key_exists("username", $attributes)) { return "Missing compulsory field [username]"; }
1344
+		if (!array_key_exists("firstname", $attributes)) { return "Missing compulsory field [firstname]"; }
1345
+		if (!array_key_exists("surname", $attributes)) { return "Missing compulsory field [surname]"; }
1346
+		if (!array_key_exists("email", $attributes)) { return "Missing compulsory field [email]"; }
1347
+		if (!array_key_exists("container", $attributes)) { return "Missing compulsory field [container]"; }
1348
+		if (empty($attributes["container"])) { return "Container attribute must be an array or string."; }
1349
+
1350
+		if (array_key_exists("password", $attributes) && (!$this->adldap->getUseSSL() && !$this->adldap->getUseTLS())) {
1356 1351
 			throw new adLDAPException('SSL must be configured on your webserver and enabled in the class to set passwords.');
1357 1352
 		}
1358 1353
 
1359 1354
 		if (!array_key_exists("display_name", $attributes)) {
1360
-			$attributes["display_name"] = $attributes["firstname"] . " " . $attributes["surname"];
1355
+			$attributes["display_name"] = $attributes["firstname"]." ".$attributes["surname"];
1361 1356
 		}
1362 1357
 
1363 1358
 		// Translate the schema
@@ -1380,20 +1375,20 @@  discard block
 block discarded – undo
1380 1375
 		// Determine the container
1381 1376
 		if (is_array($attributes['container'])) {
1382 1377
 			$attributes["container"] = array_reverse($attributes["container"]);
1383
-			$attributes["container"] = "OU=" . implode(",OU=",$attributes["container"]);
1378
+			$attributes["container"] = "OU=".implode(",OU=", $attributes["container"]);
1384 1379
 		}
1385 1380
 		// we can NOT set password with ldap_add or ldap_modify, it needs ldap_mod_replace, at least under Win2008r2
1386 1381
 		unset($add['unicodePwd']);
1387 1382
 
1388 1383
 		// Add the entry
1389
-		$result = ldap_add($ds=$this->adldap->getLdapConnection(), $dn="CN=" . $add["cn"][0] . "," . $attributes["container"] . "," . $this->adldap->getBaseDn(), $add);
1384
+		$result = ldap_add($ds = $this->adldap->getLdapConnection(), $dn = "CN=".$add["cn"][0].",".$attributes["container"].",".$this->adldap->getBaseDn(), $add);
1390 1385
 		if ($result != true) {
1391 1386
 			error_log(__METHOD__."(".array2string($attributes).") ldap_add($ds, '$dn', ".array2string($add).") returned ".array2string($result)." ldap_error()=".ldap_error($ds));
1392 1387
 			return false;
1393 1388
 		}
1394 1389
 
1395 1390
 		// now password can be added to still disabled account
1396
-		if (array_key_exists("password",$attributes))
1391
+		if (array_key_exists("password", $attributes))
1397 1392
 		{
1398 1393
 			if (!$this->setPassword($dn, $attributes['password'])) return false;
1399 1394
 
@@ -1420,13 +1415,13 @@  discard block
 block discarded – undo
1420 1415
     */
1421 1416
     public function encodePassword($password)
1422 1417
     {
1423
-        $password="\"".$password."\"";
1418
+        $password = "\"".$password."\"";
1424 1419
         if (function_exists('mb_convert_encoding') && !empty($this->adldap->charset))
1425 1420
         {
1426 1421
             return mb_convert_encoding($password, 'UTF-16LE', $this->adldap->charset);
1427 1422
         }
1428
-        $encoded="";
1429
-        for ($i=0; $i <strlen($password); $i++){ $encoded.="{$password{$i}}\000"; }
1423
+        $encoded = "";
1424
+        for ($i = 0; $i < strlen($password); $i++) { $encoded .= "{$password{$i}}\000"; }
1430 1425
         return $encoded;
1431 1426
     }
1432 1427
 
@@ -1443,7 +1438,7 @@  discard block
 block discarded – undo
1443 1438
      */
1444 1439
     public function setPassword($dn, $password)
1445 1440
     {
1446
-    	$result = ldap_mod_replace($ds=$this->adldap->getLdapConnection(), $dn, array(
1441
+    	$result = ldap_mod_replace($ds = $this->adldap->getLdapConnection(), $dn, array(
1447 1442
     		'unicodePwd' => $this->encodePassword($password),
1448 1443
     	));
1449 1444
     	if (!$result) error_log(__METHOD__."('$dn', '$password') ldap_mod_replace($ds, '$dn', \$password) returned FALSE: ".ldap_error($ds));
@@ -1471,7 +1466,7 @@  discard block
 block discarded – undo
1471 1466
 	* @param string $old_password old password for password change, if supported
1472 1467
     * @return bool
1473 1468
     */
1474
-    public function password($username, $password, $isGUID = false, $old_password=null)
1469
+    public function password($username, $password, $isGUID = false, $old_password = null)
1475 1470
     {
1476 1471
         if ($username === NULL) { return false; }
1477 1472
         if ($password === NULL) { return false; }
@@ -1485,7 +1480,7 @@  discard block
 block discarded – undo
1485 1480
             return false;
1486 1481
         }
1487 1482
 
1488
-        $add=array();
1483
+        $add = array();
1489 1484
 
1490 1485
 		if (empty($old_password) || !function_exists('ldap_modify_batch')) {
1491 1486
 			$add["unicodePwd"][0] = $this->encodePassword($password);
@@ -1507,11 +1502,11 @@  discard block
 block discarded – undo
1507 1502
 			);
1508 1503
 			$result = ldap_modify_batch($this->adldap->getLdapConnection(), $userDn, $mods);
1509 1504
 		}
1510
-        if ($result === false){
1505
+        if ($result === false) {
1511 1506
             $err = ldap_errno($this->adldap->getLdapConnection());
1512 1507
             if ($err) {
1513
-                $msg = 'Error ' . $err . ': ' . ldap_err2str($err) . '.';
1514
-                if($err == 53) {
1508
+                $msg = 'Error '.$err.': '.ldap_err2str($err).'.';
1509
+                if ($err == 53) {
1515 1510
                     $msg .= ' Your password might not match the password policy.';
1516 1511
                 }
1517 1512
                 throw new adLDAPException($msg);
@@ -1549,13 +1544,13 @@  discard block
 block discarded – undo
1549 1544
         $mod = $this->adldap->adldap_schema($attributes);
1550 1545
 
1551 1546
         // Check to see if this is an enabled status update
1552
-        if (!$mod && !array_key_exists("enabled", $attributes)){
1547
+        if (!$mod && !array_key_exists("enabled", $attributes)) {
1553 1548
             return false;
1554 1549
         }
1555 1550
 
1556 1551
         // Set the account control attribute (only if specified)
1557
-        if (array_key_exists("enabled", $attributes)){
1558
-            if ($attributes["enabled"]){
1552
+        if (array_key_exists("enabled", $attributes)) {
1553
+            if ($attributes["enabled"]) {
1559 1554
                 $controlOptions = array("NORMAL_ACCOUNT");
1560 1555
             }
1561 1556
             else {
@@ -1569,14 +1564,14 @@  discard block
 block discarded – undo
1569 1564
 		if ($mod)
1570 1565
 		{
1571 1566
 	        // Do the update
1572
-	        $result = @ldap_modify($ds=$this->adldap->getLdapConnection(), $userDn, $mod);
1567
+	        $result = @ldap_modify($ds = $this->adldap->getLdapConnection(), $userDn, $mod);
1573 1568
 	        if ($result == false) {
1574 1569
 				if (isset($mod['unicodePwd'])) $mod['unicodePwd'] = '***';
1575 1570
 				error_log(__METHOD__."(".array2string($attributes).") ldap_modify($ds, '$userDn', ".array2string($mod).") returned ".array2string($result)." ldap_error()=".ldap_error($ds));
1576 1571
 	        	return false;
1577 1572
 	        }
1578 1573
 		}
1579
-        if (array_key_exists("password",$attributes) && !$this->setPassword($userDn, $attributes['password']))
1574
+        if (array_key_exists("password", $attributes) && !$this->setPassword($userDn, $attributes['password']))
1580 1575
 		{
1581 1576
 			return false;
1582 1577
 		}
@@ -1599,10 +1594,10 @@  discard block
 block discarded – undo
1599 1594
 	 */
1600 1595
 	public function create($attributes)
1601 1596
 	{
1602
-		if (!is_array($attributes)){ return "Attributes must be an array"; }
1603
-		if (!array_key_exists("group_name", $attributes)){ return "Missing compulsory field [group_name]"; }
1604
-		if (!array_key_exists("container", $attributes)){ return "Missing compulsory field [container]"; }
1605
-		if (empty($attributes["container"])){ return "Container attribute must be an array or string."; }
1597
+		if (!is_array($attributes)) { return "Attributes must be an array"; }
1598
+		if (!array_key_exists("group_name", $attributes)) { return "Missing compulsory field [group_name]"; }
1599
+		if (!array_key_exists("container", $attributes)) { return "Missing compulsory field [container]"; }
1600
+		if (empty($attributes["container"])) { return "Container attribute must be an array or string."; }
1606 1601
 
1607 1602
 		//$member_array = array();
1608 1603
 		//$member_array[0] = "cn=user1,cn=Users,dc=yourdomain,dc=com";
@@ -1618,9 +1613,9 @@  discard block
 block discarded – undo
1618 1613
 		// Determine the container
1619 1614
 		if (is_array($attributes['container'])) {
1620 1615
 			$attributes["container"] = array_reverse($attributes["container"]);
1621
-			$attributes["container"] = "OU=" . implode(",OU=",$attributes["container"]);
1616
+			$attributes["container"] = "OU=".implode(",OU=", $attributes["container"]);
1622 1617
 		}
1623
-		$result = ldap_add($this->adldap->getLdapConnection(), "CN=" . $add["cn"] . "," . $attributes["container"] . "," . $this->adldap->getBaseDn(), $add);
1618
+		$result = ldap_add($this->adldap->getLdapConnection(), "CN=".$add["cn"].",".$attributes["container"].",".$this->adldap->getBaseDn(), $add);
1624 1619
 		if ($result != true) {
1625 1620
 			return false;
1626 1621
 		}
@@ -1651,10 +1646,10 @@  discard block
 block discarded – undo
1651 1646
     * @author Port by Andreas Gohr <[email protected]>
1652 1647
     * @return string
1653 1648
     */
1654
-    public function ldapSlashes($str){
1649
+    public function ldapSlashes($str) {
1655 1650
         return preg_replace_callback(
1656 1651
       		'/([\x00-\x1F\*\(\)\\\\])/',
1657
-        	function ($matches) {
1652
+        	function($matches) {
1658 1653
             	return "\\".join("", unpack("H2", $matches[1]));
1659 1654
         	},
1660 1655
         	$str
Please login to merge, or discard this patch.
api/ntlm/index.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 function check_domain($url)
23 23
 {
24 24
 	$whitelisted = array(
25
-		$_SERVER['HTTP_HOST'],	// can contain :port
25
+		$_SERVER['HTTP_HOST'], // can contain :port
26 26
 		// add additional domains-names (just full qualified hostnames) here
27 27
 
28 28
 	);
@@ -50,13 +50,13 @@  discard block
 block discarded – undo
50 50
 
51 51
 	if (isset($_SERVER['REMOTE_USER']) && $_SERVER['REMOTE_USER'] && isset($_SERVER['AUTH_TYPE']) &&
52 52
 		isset($GLOBALS['egw_info']['server']['http_auth_types']) && $GLOBALS['egw_info']['server']['http_auth_types'] &&
53
-		in_array(strtoupper($_SERVER['AUTH_TYPE']),explode(',',strtoupper($GLOBALS['egw_info']['server']['http_auth_types']))))
53
+		in_array(strtoupper($_SERVER['AUTH_TYPE']), explode(',', strtoupper($GLOBALS['egw_info']['server']['http_auth_types']))))
54 54
 	{
55
-		if (strpos($account=$_SERVER['REMOTE_USER'],'\\') !== false)
55
+		if (strpos($account = $_SERVER['REMOTE_USER'], '\\') !== false)
56 56
 		{
57
-			list(,$account) = explode('\\',$account,2);
57
+			list(,$account) = explode('\\', $account, 2);
58 58
 		}
59
-		$sessionid = $GLOBALS['egw']->session->create($account,null,'ntlm',false,false);	// false=no auth check
59
+		$sessionid = $GLOBALS['egw']->session->create($account, null, 'ntlm', false, false); // false=no auth check
60 60
 		//error_log("create('$account',null,'ntlm',false,false)=$sessionid ({$GLOBALS['egw']->session->reason})");
61 61
 	}
62 62
 	if (!$sessionid)
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@
 block discarded – undo
28 28
  * Create a session or if the user has no account return authenticate header and 401 Unauthorized
29 29
  *
30 30
  * @param array &$account
31
- * @return int session-id
31
+ * @return string session-id
32 32
  */
33 33
 function check_access(&$account)
34 34
 {
Please login to merge, or discard this patch.
calendar/inc/class.calendar_groupdav.inc.php 4 patches
Doc Comments   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 	 *
316 316
 	 * @param string $path
317 317
 	 * @param array $filter
318
-	 * @param array|boolean $start =false false=return all or array(start,num)
318
+	 * @param integer[] $start =false false=return all or array(start,num)
319 319
 	 * @return array with "files" array with values for keys path and props
320 320
 	 */
321 321
 	function &propfind_callback($path,array $filter,$start=false)
@@ -620,7 +620,7 @@  discard block
 block discarded – undo
620 620
 	 * @param array &$options
621 621
 	 * @param int $id
622 622
 	 * @param int $user =null account_id
623
-	 * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found')
623
+	 * @return string|boolean boolean true on success, false on failure or string with http status (eg. '404 Not Found')
624 624
 	 */
625 625
 	function get(&$options,$id,$user=null)
626 626
 	{
@@ -793,7 +793,7 @@  discard block
 block discarded – undo
793 793
 	 * Check if $user is a participant of given $event incl. group-invitations
794 794
 	 *
795 795
 	 * @param array $event
796
-	 * @param int|string $user
796
+	 * @param integer $user
797 797
 	 * @return boolean
798 798
 	 */
799 799
 	public static function isParticipant(array $event, $user)
@@ -810,7 +810,7 @@  discard block
 block discarded – undo
810 810
 	 * @param int $id
811 811
 	 * @param int $user =null account_id of owner, default null
812 812
 	 * @param string $prefix =null user prefix from path (eg. /ralf from /ralf/addressbook)
813
-	 * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found')
813
+	 * @return string|boolean boolean true on success, false on failure or string with http status (eg. '404 Not Found')
814 814
 	 */
815 815
 	function put(&$options,$id,$user=null,$prefix=null)
816 816
 	{
@@ -1038,7 +1038,7 @@  discard block
 block discarded – undo
1038 1038
 	 * @param array &$options
1039 1039
 	 * @param int $id
1040 1040
 	 * @param int $user =null account_id of owner, default null
1041
-	 * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found')
1041
+	 * @return string|boolean boolean true on success, false on failure or string with http status (eg. '404 Not Found')
1042 1042
 	 */
1043 1043
 	function post(&$options,$id,$user=null)
1044 1044
 	{
@@ -1112,7 +1112,7 @@  discard block
 block discarded – undo
1112 1112
 	 * @param string $charset of ical
1113 1113
 	 * @param int $user account_id of owner
1114 1114
 	 * @param array &$options
1115
-	 * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found')
1115
+	 * @return string|boolean boolean true on success, false on failure or string with http status (eg. '404 Not Found')
1116 1116
 	 */
1117 1117
 	protected function outbox_freebusy_request($ical, $charset, $user, array &$options)
1118 1118
 	{
@@ -1187,7 +1187,7 @@  discard block
 block discarded – undo
1187 1187
 	 * @param string $path
1188 1188
 	 * @param array $options
1189 1189
 	 * @param int $user account_id
1190
-	 * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found')
1190
+	 * @return string|null boolean true on success, false on failure or string with http status (eg. '404 Not Found')
1191 1191
 	 */
1192 1192
 	function free_busy_report($path,$options,$user)
1193 1193
 	{
@@ -1416,7 +1416,7 @@  discard block
 block discarded – undo
1416 1416
 	/**
1417 1417
 	 * Query ctag for calendar
1418 1418
 	 *
1419
-	 * @return string
1419
+	 * @return integer
1420 1420
 	 */
1421 1421
 	public function getctag($path,$user)
1422 1422
 	{
@@ -1449,7 +1449,7 @@  discard block
 block discarded – undo
1449 1449
 	 *
1450 1450
 	 * @param int|array $entry id or array of new created entry
1451 1451
 	 * @param string $path
1452
-	 * @param int|string $retval
1452
+	 * @param string|boolean $retval
1453 1453
 	 * @param boolean $path_attr_is_name =true true: path_attr is ca(l|rd)dav_name, false: id (GroupDAV needs Location header)
1454 1454
 	 */
1455 1455
 	function put_response_headers($entry, $path, $retval, $path_attr_is_name=true)
Please login to merge, or discard this patch.
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -134,11 +134,11 @@
 block discarded – undo
134 134
 	}
135 135
 
136 136
 /**
137
-	 * Create the path for an event
138
-	 *
139
-	 * @param array|int $event
140
-	 * @return string
141
-	 */
137
+ * Create the path for an event
138
+ *
139
+ * @param array|int $event
140
+ * @return string
141
+ */
142 142
 	function get_path($event)
143 143
 	{
144 144
 		if (is_numeric($event) && self::$path_attr == 'id')
Please login to merge, or discard this patch.
Spacing   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 	 * @param string $id =''
154 154
 	 * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found')
155 155
 	 */
156
-	function propfind($path,&$options,&$files,$user,$id='')
156
+	function propfind($path, &$options, &$files, $user, $id = '')
157 157
 	{
158 158
 		if ($this->debug)
159 159
 		{
@@ -179,10 +179,10 @@  discard block
 block discarded – undo
179 179
 			'enum_recuring' => false,
180 180
 			'daywise' => false,
181 181
 			'date_format' => 'server',
182
-			'no_total' => true,	// we need no total number of rows (saves extra query)
183
-			'cfs' => array(),	// return custom-fields, as we use them to store X- attributes
182
+			'no_total' => true, // we need no total number of rows (saves extra query)
183
+			'cfs' => array(), // return custom-fields, as we use them to store X- attributes
184 184
 		);
185
-		foreach(array(
185
+		foreach (array(
186 186
 			'start' => $GLOBALS['egw_info']['user']['preferences']['groupdav']['calendar-past-limit'],
187 187
 			'end' => $GLOBALS['egw_info']['user']['preferences']['groupdav']['calendar-future-limit'],
188 188
 		) as $name => $value)
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 			{
192 192
 				$value = $name == 'start' ? self::PAST_LIMIT : self::FUTURE_LIMIT;
193 193
 			}
194
-			$filter[$name] = $this->bo->now + 24*3600*($name == 'start' ? -1 : 1)*abs($value);
194
+			$filter[$name] = $this->bo->now + 24 * 3600 * ($name == 'start' ? -1 : 1) * abs($value);
195 195
 		}
196 196
 		if ($this->client_shared_uid_exceptions)	// do NOT return (non-virtual) exceptions
197 197
 		{
@@ -203,13 +203,13 @@  discard block
 block discarded – undo
203 203
 			$filter['filter'] = 'owner';
204 204
 		}
205 205
 		// scheduling inbox, shows only not yet accepted or rejected events
206
-		elseif (substr($path,-7) == '/inbox/')
206
+		elseif (substr($path, -7) == '/inbox/')
207 207
 		{
208 208
 			$filter['filter'] = 'unknown';
209
-			$filter['start'] = $this->bo->now;	// only return future invitations
209
+			$filter['start'] = $this->bo->now; // only return future invitations
210 210
 		}
211 211
 		// ToDo: not sure what scheduling outbox is supposed to show, leave it empty for now
212
-		elseif (substr($path,-8) == '/outbox/')
212
+		elseif (substr($path, -8) == '/outbox/')
213 213
 		{
214 214
 			return true;
215 215
 		}
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 			// when trying to request not supported components, eg. VTODO on a calendar collection
227 227
 			return true;
228 228
 		}
229
-		if ($id) $path = dirname($path).'/';	// caldav_name get's added anyway in the callback
229
+		if ($id) $path = dirname($path).'/'; // caldav_name get's added anyway in the callback
230 230
 
231 231
 		if ($this->debug > 1)
232 232
 		{
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
 
244 244
 			$this->sync_collection_token = null;
245 245
 
246
-			$filter['order'] = 'cal_modified ASC';	// return oldest modifications first
246
+			$filter['order'] = 'cal_modified ASC'; // return oldest modifications first
247 247
 			$filter['sync-collection'] = true;
248 248
 			// no end-date / limit into the future, as unchanged entries would never be transferted later on
249 249
 			unset($filter['end']);
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 
252 252
 		if (isset($nresults))
253 253
 		{
254
-			unset($filter['no_total']);	// we need the total!
254
+			unset($filter['no_total']); // we need the total!
255 255
 			$files['files'] = $this->propfind_callback($path, $filter, array(0, (int)$nresults));
256 256
 
257 257
 			// hack to support limit with sync-collection report: events are returned in modified ASC order (oldest first)
@@ -260,13 +260,13 @@  discard block
 block discarded – undo
260 260
 			if ($options['root']['name'] == 'sync-collection' && $this->bo->total > $nresults)
261 261
 			{
262 262
 				--$this->sync_collection_token;
263
-				$files['sync-token-params'][] = true;	// tel get_sync_collection_token that we have more entries
263
+				$files['sync-token-params'][] = true; // tel get_sync_collection_token that we have more entries
264 264
 			}
265 265
 		}
266 266
 		else
267 267
 		{
268 268
 			// return iterator, calling ourself to return result in chunks
269
-			$files['files'] = new Api\CalDAV\PropfindIterator($this,$path,$filter,$files['files']);
269
+			$files['files'] = new Api\CalDAV\PropfindIterator($this, $path, $filter, $files['files']);
270 270
 		}
271 271
 		if (isset($_GET['download']))
272 272
 		{
@@ -286,9 +286,9 @@  discard block
 block discarded – undo
286 286
 		Api\Header\Content::type('calendar.ics', 'text/calendar');
287 287
 
288 288
 		$n = 0;
289
-		foreach($files as $file)
289
+		foreach ($files as $file)
290 290
 		{
291
-			if (!$n++) continue;	// first entry is collection itself
291
+			if (!$n++) continue; // first entry is collection itself
292 292
 
293 293
 			$icalendar = $file['props']['calendar-data']['val'];
294 294
 			if (($start = strpos($icalendar, 'BEGIN:VEVENT')) !== false &&
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
 						echo substr($icalendar, 0, $start);
313 313
 					}
314 314
 				}
315
-				echo substr($icalendar, $start, $end-$start);
315
+				echo substr($icalendar, $start, $end - $start);
316 316
 			}
317 317
 		}
318 318
 		if ($icalendar && $end)
@@ -330,12 +330,12 @@  discard block
 block discarded – undo
330 330
 	 * @param array|boolean $start =false false=return all or array(start,num)
331 331
 	 * @return array with "files" array with values for keys path and props
332 332
 	 */
333
-	function &propfind_callback($path,array $filter,$start=false)
333
+	function &propfind_callback($path, array $filter, $start = false)
334 334
 	{
335 335
 		if ($this->debug) $starttime = microtime(true);
336 336
 
337 337
 		$calendar_data = $this->caldav->prop_requested('calendar-data', Api\CalDAV::CALDAV, true);
338
-		if (!is_array($calendar_data)) $calendar_data = false;	// not in allprop or autoindex
338
+		if (!is_array($calendar_data)) $calendar_data = false; // not in allprop or autoindex
339 339
 
340 340
 		$files = array();
341 341
 
@@ -347,11 +347,11 @@  discard block
 block discarded – undo
347 347
 		$requested_multiget_ids = (array)$filter['query'][self::$path_attr];
348 348
 		$sync_collection = $filter['sync-collection'];
349 349
 
350
-		$events =& $this->bo->search($filter);
350
+		$events = & $this->bo->search($filter);
351 351
 
352 352
 		if ($events)
353 353
 		{
354
-			foreach($events as $event)
354
+			foreach ($events as $event)
355 355
 			{
356 356
 				// remove event from requested multiget ids, to be able to report not found urls
357 357
 				if ($requested_multiget_ids && ($k = array_search($event[self::$path_attr], $requested_multiget_ids)) !== false)
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
 					unset($requested_multiget_ids[$k]);
360 360
 				}
361 361
 				// sync-collection report: deleted entries need to be reported without properties, same for rejected or deleted invitations
362
-				if ($sync_collection && ($event['deleted'] && !$event['cal_reference'] || in_array($event['participants'][$filter['users']][0], array('R','X'))))
362
+				if ($sync_collection && ($event['deleted'] && !$event['cal_reference'] || in_array($event['participants'][$filter['users']][0], array('R', 'X'))))
363 363
 				{
364 364
 					$files[] = array('path' => $path.urldecode($this->get_path($event)));
365 365
 					continue;
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
 						!isset($calendar_data['children']['expand']) ? false :
391 391
 							($calendar_data['children']['expand']['attrs'] ? $calendar_data['children']['expand']['attrs'] : true));
392 392
 					$props['getcontentlength'] = bytes($content);
393
-					$props['calendar-data'] = Api\CalDAV::mkprop(Api\CalDAV::CALDAV,'calendar-data',$content);
393
+					$props['calendar-data'] = Api\CalDAV::mkprop(Api\CalDAV::CALDAV, 'calendar-data', $content);
394 394
 				}
395 395
 				/* Calendarserver reports new events with schedule-changes: action: create, which iCal request
396 396
 				 * adding it, unfortunately does not lead to showing the new event in the users inbox
@@ -409,7 +409,7 @@  discard block
 block discarded – undo
409 409
 		// report not found multiget urls
410 410
 		if ($requested_multiget_ids)
411 411
 		{
412
-			foreach($requested_multiget_ids as $id)
412
+			foreach ($requested_multiget_ids as $id)
413 413
 			{
414 414
 				$files[] = array('path' => $path.$id.self::$path_extension);
415 415
 			}
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
 	private function _created_updated_by_prop($user, $time)
446 446
 	{
447 447
 		$props = array();
448
-		foreach(array(
448
+		foreach (array(
449 449
 			'first-name' => 'account_firstname',
450 450
 			'last-name' => 'account_lastname',
451 451
 			'href' => 'account_email',
@@ -488,23 +488,23 @@  discard block
 block discarded – undo
488 488
 			$cal_end = $cal_filters['end']; unset($cal_filters['end']);
489 489
 			$num_filters = count($cal_filters);
490 490
 
491
-			foreach($options['filters'] as $filter)
491
+			foreach ($options['filters'] as $filter)
492 492
 			{
493
-				switch($filter['name'])
493
+				switch ($filter['name'])
494 494
 				{
495 495
 					case 'comp-filter':
496 496
 						if ($this->debug > 1) error_log(__METHOD__."($options[path],...) comp-filter='{$filter['attrs']['name']}'");
497 497
 
498
-						switch($filter['attrs']['name'])
498
+						switch ($filter['attrs']['name'])
499 499
 						{
500 500
 							case 'VTODO':
501
-								return false;	// return nothing for now, todo: check if we can pass it on to the infolog handler
501
+								return false; // return nothing for now, todo: check if we can pass it on to the infolog handler
502 502
 								// todos are handled by the infolog handler
503 503
 								//$infolog_handler = new groupdav_infolog();
504 504
 								//return $infolog_handler->propfind($options['path'],$options,$options['files'],$user,$method);
505 505
 							case 'VCALENDAR':
506 506
 							case 'VEVENT':
507
-								break;			// that's our default anyway
507
+								break; // that's our default anyway
508 508
 						}
509 509
 						break;
510 510
 					case 'prop-filter':
@@ -527,14 +527,14 @@  discard block
 block discarded – undo
527 527
 						if ($this->debug) error_log(__METHOD__."($options[path],...) param-filter='{$filter['attrs']['name']}' not (yet) implemented!");
528 528
 						break;
529 529
 					case 'time-range':
530
-				 		if ($this->debug > 1) error_log(__FILE__ . __METHOD__."($options[path],...) time-range={$filter['attrs']['start']}-{$filter['attrs']['end']}");
530
+				 		if ($this->debug > 1) error_log(__FILE__.__METHOD__."($options[path],...) time-range={$filter['attrs']['start']}-{$filter['attrs']['end']}");
531 531
 				 		if (!empty($filter['attrs']['start']))
532 532
 				 		{
533 533
 					 		$cal_filters['start'] = $this->vCalendar->_parseDateTime($filter['attrs']['start']);
534 534
 				 		}
535 535
 				 		if (!empty($filter['attrs']['end']))
536 536
 				 		{
537
-					 		$cal_filters['end']   = $this->vCalendar->_parseDateTime($filter['attrs']['end']);
537
+					 		$cal_filters['end'] = $this->vCalendar->_parseDateTime($filter['attrs']['end']);
538 538
 				 		}
539 539
 						break;
540 540
 					default:
@@ -555,9 +555,9 @@  discard block
 block discarded – undo
555 555
 		    <B:nresults>10</B:nresults>
556 556
 		  </B:limit>
557 557
 		*/
558
-		foreach((array)$options['other'] as $option)
558
+		foreach ((array)$options['other'] as $option)
559 559
 		{
560
-			switch($option['name'])
560
+			switch ($option['name'])
561 561
 			{
562 562
 				case 'nresults':
563 563
 					$nresults = (int)$option['data'];
@@ -566,7 +566,7 @@  discard block
 block discarded – undo
566 566
 				case 'limit':
567 567
 					break;
568 568
 				case 'href':
569
-					break;	// from addressbook-multiget, handled below
569
+					break; // from addressbook-multiget, handled below
570 570
 				// rfc 6578 sync-report
571 571
 				case 'sync-token':
572 572
 					if (!empty($option['data']))
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
 						$parts = explode('/', $option['data']);
575 575
 						$sync_token = array_pop($parts);
576 576
 						$cal_filters['query'][] = 'cal_modified>'.(int)$sync_token;
577
-						$cal_filters['filter'] = 'everything';	// to return deleted entries too
577
+						$cal_filters['filter'] = 'everything'; // to return deleted entries too
578 578
 						// no standard time-range!
579 579
 						unset($cal_filters['start']);
580 580
 					}
@@ -603,25 +603,25 @@  discard block
 block discarded – undo
603 603
 			if ($id)
604 604
 			{
605 605
 				$cal_filters['query'][self::$path_attr] = self::$path_extension ?
606
-					basename($id,self::$path_extension) : $id;
606
+					basename($id, self::$path_extension) : $id;
607 607
 			}
608 608
 			else	// fetch all given url's
609 609
 			{
610
-				foreach($options['other'] as $option)
610
+				foreach ($options['other'] as $option)
611 611
 				{
612 612
 					if ($option['name'] == 'href')
613 613
 					{
614
-						$parts = explode('/',$option['data']);
614
+						$parts = explode('/', $option['data']);
615 615
 						if (($id = urldecode(array_pop($parts))))
616 616
 						{
617 617
 							$cal_filters['query'][self::$path_attr][] = self::$path_extension ?
618
-								basename($id,self::$path_extension) : $id;
618
+								basename($id, self::$path_extension) : $id;
619 619
 						}
620 620
 					}
621 621
 				}
622 622
 			}
623 623
 
624
-			if ($this->debug > 1) error_log(__FILE__ . __METHOD__ ."($options[path],...,$id) calendar-multiget: ids=".implode(',',$ids).', cal_filters='.array2string($cal_filters));
624
+			if ($this->debug > 1) error_log(__FILE__.__METHOD__."($options[path],...,$id) calendar-multiget: ids=".implode(',', $ids).', cal_filters='.array2string($cal_filters));
625 625
 		}
626 626
 		return true;
627 627
 	}
@@ -634,9 +634,9 @@  discard block
 block discarded – undo
634 634
 	 * @param int $user =null account_id
635 635
 	 * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found')
636 636
 	 */
637
-	function get(&$options,$id,$user=null)
637
+	function get(&$options, $id, $user = null)
638 638
 	{
639
-		if (!is_array($event = $this->_common_get_put_delete('GET',$options,$id)))
639
+		if (!is_array($event = $this->_common_get_put_delete('GET', $options, $id)))
640 640
 		{
641 641
 			return $event;
642 642
 		}
@@ -664,7 +664,7 @@  discard block
 block discarded – undo
664 664
 	 * @param boolean|array $expand =false true or array with values for 'start', 'end' to expand recurrences
665 665
 	 * @return string
666 666
 	 */
667
-	private function iCal(array $event,$user=null, $method=null, $expand=false)
667
+	private function iCal(array $event, $user = null, $method = null, $expand = false)
668 668
 	{
669 669
 		static $handler = null;
670 670
 		if (is_null($handler)) $handler = $this->_get_handler();
@@ -688,13 +688,13 @@  discard block
 block discarded – undo
688 688
 				if (isset($expand['start'])) $expand['start'] = $this->vCalendar->_parseDateTime($expand['start']);
689 689
 				if (isset($expand['end'])) $expand['end'] = $this->vCalendar->_parseDateTime($expand['end']);
690 690
 			}
691
-			$events =& self::get_series($event['uid'], $this->bo, $expand, $user);
691
+			$events = & self::get_series($event['uid'], $this->bo, $expand, $user);
692 692
 			// as alarm is now only on next recurrence, set alarm from original event on master
693 693
 			if ($event['alarm']) $events[0]['alarm'] = $event['alarm'];
694 694
 		}
695
-		elseif(!$this->client_shared_uid_exceptions && $event['reference'])
695
+		elseif (!$this->client_shared_uid_exceptions && $event['reference'])
696 696
 		{
697
-			$events[0]['uid'] .= '-'.$event['id'];	// force a different uid
697
+			$events[0]['uid'] .= '-'.$event['id']; // force a different uid
698 698
 		}
699 699
 		return $handler->exportVCal($events, '2.0', $method);
700 700
 	}
@@ -710,20 +710,20 @@  discard block
 block discarded – undo
710 710
 	 * @param int $user =null account_id of calendar to display, to remove master, if current user does not participate in
711 711
 	 * @return array
712 712
 	 */
713
-	private static function &get_series($uid,calendar_bo $bo=null, $expand=false, $user=null)
713
+	private static function &get_series($uid, calendar_bo $bo = null, $expand = false, $user = null)
714 714
 	{
715 715
 		if (is_null($bo)) $bo = new calendar_bopdate();
716 716
 
717 717
 		$params = array(
718 718
 			'query' => array('cal_uid' => $uid),
719
-			'filter' => 'owner',  // return all possible entries
719
+			'filter' => 'owner', // return all possible entries
720 720
 			'daywise' => false,
721 721
 			'date_format' => 'server',
722
-			'cfs' => array(),	// read cfs as we use them to store X- attributes
722
+			'cfs' => array(), // read cfs as we use them to store X- attributes
723 723
 		);
724 724
 		if (is_array($expand)) $params += $expand;
725 725
 
726
-		if (!($events =& $bo->search($params)))
726
+		if (!($events = & $bo->search($params)))
727 727
 		{
728 728
 			return array();
729 729
 		}
@@ -731,12 +731,12 @@  discard block
 block discarded – undo
731 731
 		// find master, which is not always first event, eg. when first event is an exception
732 732
 		$master = null;
733 733
 		$exceptions = array();
734
-		foreach($events as $k => &$recurrence)
734
+		foreach ($events as $k => &$recurrence)
735 735
 		{
736 736
 			if ($recurrence['recur_type'])
737 737
 			{
738 738
 				$master = $recurrence;
739
-				$exceptions =& $master['recur_exception'];
739
+				$exceptions = & $master['recur_exception'];
740 740
 				unset($events[$k]);
741 741
 				break;
742 742
 			}
@@ -744,13 +744,13 @@  discard block
 block discarded – undo
744 744
 		// if recurring event starts in future behind horizont, nothing will be returned by bo::search()
745 745
 		if (!isset($master)) $master = $bo->read($uid);
746 746
 
747
-		foreach($events as $k => &$recurrence)
747
+		foreach ($events as $k => &$recurrence)
748 748
 		{
749 749
 			//error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."($uid)[$k]:" . array2string($recurrence));
750 750
 			if ($master && $recurrence['reference'] != $master['id'])
751 751
 			{
752 752
 				unset($events[$k]);
753
-				continue;	// same uid, but references a different event or is own master
753
+				continue; // same uid, but references a different event or is own master
754 754
 			}
755 755
 			if (!$master || $recurrence['id'] != $master['id'])	// real exception
756 756
 			{
@@ -771,11 +771,11 @@  discard block
 block discarded – undo
771 771
 				// at least Lightning "understands" EXDATE as exception from what's included
772 772
 				// in the whole resource / VCALENDAR component
773 773
 				// not removing it causes Lightning to remove the exception itself
774
-				if (($e = array_search($recurrence['recurrence'],$exceptions)) !== false)
774
+				if (($e = array_search($recurrence['recurrence'], $exceptions)) !== false)
775 775
 				{
776 776
 					unset($exceptions[$e]);
777 777
 				}
778
-				continue;	// nothing to change
778
+				continue; // nothing to change
779 779
 			}
780 780
 			// add alarms from master to recurrences, as clients otherwise have no alarms on virtual exceptions
781 781
 			if ($master && $master['alarm'])
@@ -786,14 +786,14 @@  discard block
 block discarded – undo
786 786
 			if (!$expand && $master && $master['participants'] == $recurrence['participants'])
787 787
 			{
788 788
 				//error_log('NO exception: '.array2string($recurrence));
789
-				unset($events[$k]);	// no exception --> remove it
789
+				unset($events[$k]); // no exception --> remove it
790 790
 				continue;
791 791
 			}
792 792
 			// this is a virtual exception now (no extra event/cal_id in DB)
793 793
 			//error_log('virtual exception: '.array2string($recurrence));
794 794
 			$recurrence['recurrence'] = $recurrence['start'];
795 795
 			if ($master) $recurrence['reference'] = $master['id'];
796
-			$recurrence['recur_type'] = MCAL_RECUR_NONE;	// is set, as this is a copy of the master
796
+			$recurrence['recur_type'] = MCAL_RECUR_NONE; // is set, as this is a copy of the master
797 797
 			// not for included exceptions (Lightning): $master['recur_exception'][] = $recurrence['start'];
798 798
 		}
799 799
 		// only add master if we are not expanding and current user participates in master (and not just some exceptions)
@@ -829,11 +829,11 @@  discard block
 block discarded – undo
829 829
 	 * @param string $prefix =null user prefix from path (eg. /ralf from /ralf/addressbook)
830 830
 	 * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found')
831 831
 	 */
832
-	function put(&$options,$id,$user=null,$prefix=null)
832
+	function put(&$options, $id, $user = null, $prefix = null)
833 833
 	{
834
-		if ($this->debug) error_log(__METHOD__."($id, $user)".print_r($options,true));
834
+		if ($this->debug) error_log(__METHOD__."($id, $user)".print_r($options, true));
835 835
 
836
-		if (!$prefix) $user = null;	// /infolog/ does not imply setting the current user (for new entries it's done anyway)
836
+		if (!$prefix) $user = null; // /infolog/ does not imply setting the current user (for new entries it's done anyway)
837 837
 
838 838
 		// work around missing handling / racecondition in Lightning, if event already exists on server,
839 839
 		// but Lightning has not yet synced with the server: Lightning just retries the PUT, not GETing the event
@@ -850,12 +850,12 @@  discard block
 block discarded – undo
850 850
 		{
851 851
 			$_SERVER['HTTP_IF_SCHEDULE_TAG_MATCH'] = $_SERVER['HTTP_IF_SCHEDULE'];
852 852
 		}
853
-		$return_no_access = true;	// as handled by importVCal anyway and allows it to set the status for participants
854
-		$oldEvent = $this->_common_get_put_delete('PUT',$options,$id,$return_no_access,
855
-			isset($_SERVER['HTTP_IF_SCHEDULE_TAG_MATCH']));	// dont fail with 412 Precondition Failed in that case
853
+		$return_no_access = true; // as handled by importVCal anyway and allows it to set the status for participants
854
+		$oldEvent = $this->_common_get_put_delete('PUT', $options, $id, $return_no_access,
855
+			isset($_SERVER['HTTP_IF_SCHEDULE_TAG_MATCH'])); // dont fail with 412 Precondition Failed in that case
856 856
 		if (!is_null($oldEvent) && !is_array($oldEvent))
857 857
 		{
858
-			if ($this->debug) error_log(__METHOD__.': '.print_r($oldEvent,true).function_backtrace());
858
+			if ($this->debug) error_log(__METHOD__.': '.print_r($oldEvent, true).function_backtrace());
859 859
 			return $oldEvent;
860 860
 		}
861 861
 
@@ -947,7 +947,7 @@  discard block
 block discarded – undo
947 947
 				if (($events = $handler->icaltoegw($vCalendar)))
948 948
 				{
949 949
 					$modified = 0;
950
-					foreach($events as $n => $event)
950
+					foreach ($events as $n => $event)
951 951
 					{
952 952
 						// for recurrances of event series, we need to read correct recurrence (or if series master is no first event)
953 953
 						if ($event['recurrence'] || $n && !$event['recurrence'] || isset($series))
@@ -958,7 +958,7 @@  discard block
 block discarded – undo
958 958
 								$series = self::get_series($event['uid'], $this->bo);
959 959
 								//foreach($series as $s => $sEvent) error_log("series[$s]: ".array2string($sEvent));
960 960
 							}
961
-							foreach($series as $oldEvent)
961
+							foreach ($series as $oldEvent)
962 962
 							{
963 963
 								if ($oldEvent['recurrence'] == $event['recurrence']) break;
964 964
 							}
@@ -1023,9 +1023,9 @@  discard block
 block discarded – undo
1023 1023
 					isset($oldEvent['participants'][$GLOBALS['egw_info']['user']['account_id']]))
1024 1024
 				{
1025 1025
 					// just update etag in database
1026
-					$GLOBALS['egw']->db->update($this->bo->so->cal_table,'cal_etag=cal_etag+1',array(
1026
+					$GLOBALS['egw']->db->update($this->bo->so->cal_table, 'cal_etag=cal_etag+1', array(
1027 1027
 						'cal_id' => $eventId,
1028
-					),__LINE__,__FILE__,'calendar');
1028
+					), __LINE__, __FILE__, 'calendar');
1029 1029
 				}
1030 1030
 			}
1031 1031
 		}
@@ -1077,9 +1077,9 @@  discard block
 block discarded – undo
1077 1077
 	 * @param int $user =null account_id of owner, default null
1078 1078
 	 * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found')
1079 1079
 	 */
1080
-	function post(&$options,$id,$user=null)
1080
+	function post(&$options, $id, $user = null)
1081 1081
 	{
1082
-		if ($this->debug) error_log(__METHOD__."($id, $user)".print_r($options,true));
1082
+		if ($this->debug) error_log(__METHOD__."($id, $user)".print_r($options, true));
1083 1083
 
1084 1084
 		$vCalendar = htmlspecialchars_decode($options['content']);
1085 1085
 		$charset = null;
@@ -1101,7 +1101,7 @@  discard block
 block discarded – undo
1101 1101
 			}
1102 1102
 		}
1103 1103
 
1104
-		if (substr($options['path'],-8) == '/outbox/')
1104
+		if (substr($options['path'], -8) == '/outbox/')
1105 1105
 		{
1106 1106
 			if (preg_match('/^METHOD:REQUEST(\r\n|\r|\n)(.*)^BEGIN:VFREEBUSY/ism', $vCalendar))
1107 1107
 			{
@@ -1152,7 +1152,7 @@  discard block
 block discarded – undo
1152 1152
 	 */
1153 1153
 	protected function outbox_freebusy_request($ical, $charset, $user, array &$options)
1154 1154
 	{
1155
-		unset($options);	// not used, but required by function signature
1155
+		unset($options); // not used, but required by function signature
1156 1156
 
1157 1157
 		$vcal = new Horde_Icalendar();
1158 1158
 		if (!$vcal->parsevCalendar($ical, 'VCALENDAR', $charset))
@@ -1165,7 +1165,7 @@  discard block
 block discarded – undo
1165 1165
 
1166 1166
 		$handler = $this->_get_handler();
1167 1167
 		$handler->setSupportedFields('groupdav');
1168
-		$handler->calendarOwner = $handler->user = 0;	// to NOT default owner/organizer to something
1168
+		$handler->calendarOwner = $handler->user = 0; // to NOT default owner/organizer to something
1169 1169
 		if (!($component = $vcal->getComponent(0)) ||
1170 1170
 			!($event = $handler->vevent2egw($component, $version, $handler->supportedFields, $this->caldav->current_user_principal, 'Horde_Icalendar_Vfreebusy')))
1171 1171
 		{
@@ -1190,13 +1190,13 @@  discard block
 block discarded – undo
1190 1190
 		$xml->startDocument('1.0', 'UTF-8');
1191 1191
 		$xml->startElementNs('C', 'schedule-response', Api\CalDAV::CALDAV);
1192 1192
 
1193
-		foreach(array_keys($event['participants']) as $uid)
1193
+		foreach (array_keys($event['participants']) as $uid)
1194 1194
 		{
1195 1195
 			$xml->startElementNs('C', 'response', null);
1196 1196
 
1197 1197
 			$xml->startElementNs('C', 'recipient', null);
1198
-			$xml->writeElementNs('D', 'href', 'DAV:', $attendee=array_shift($attendees));
1199
-			$xml->endElement();	// recipient
1198
+			$xml->writeElementNs('D', 'href', 'DAV:', $attendee = array_shift($attendees));
1199
+			$xml->endElement(); // recipient
1200 1200
 
1201 1201
 			$xml->writeElementNs('C', 'request-status', null, '2.0;Success');
1202 1202
 			$xml->writeElementNs('C', 'calendar-data', null,
@@ -1204,13 +1204,13 @@  discard block
 block discarded – undo
1204 1204
 					'UID' => $event['uid'],
1205 1205
 					'ORGANIZER' => $organizer,
1206 1206
 					'ATTENDEE' => $attendee,
1207
-				)+(empty($mask_uid) || !is_string($mask_uid) ? array() : array(
1207
+				) + (empty($mask_uid) || !is_string($mask_uid) ? array() : array(
1208 1208
 					'X-CALENDARSERVER-MASK-UID' => $mask_uid,
1209 1209
 				))));
1210 1210
 
1211
-			$xml->endElement();	// response
1211
+			$xml->endElement(); // response
1212 1212
 		}
1213
-		$xml->endElement();	// schedule-response
1213
+		$xml->endElement(); // schedule-response
1214 1214
 		$xml->endDocument();
1215 1215
 		echo $xml->outputMemory();
1216 1216
 
@@ -1225,14 +1225,14 @@  discard block
 block discarded – undo
1225 1225
 	 * @param int $user account_id
1226 1226
 	 * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found')
1227 1227
 	 */
1228
-	function free_busy_report($path,$options,$user)
1228
+	function free_busy_report($path, $options, $user)
1229 1229
 	{
1230
-		unset($path);	// unused, but required by function signature
1230
+		unset($path); // unused, but required by function signature
1231 1231
 		if (!$this->bo->check_perms(calendar_bo::ACL_FREEBUSY, 0, $user))
1232 1232
 		{
1233 1233
 			return '403 Forbidden';
1234 1234
 		}
1235
-		foreach($options['other'] as $filter)
1235
+		foreach ($options['other'] as $filter)
1236 1236
 		{
1237 1237
 			if ($filter['name'] == 'time-range')
1238 1238
 			{
@@ -1244,7 +1244,7 @@  discard block
 block discarded – undo
1244 1244
 		header('Content-Type: text/calendar');
1245 1245
 		echo $handler->freebusy($user, $end, true, 'utf-8', $start, 'REPLY', array());
1246 1246
 
1247
-		exit();	// otherwise we get a 207 multistatus, not 200 Ok
1247
+		exit(); // otherwise we get a 207 multistatus, not 200 Ok
1248 1248
 	}
1249 1249
 
1250 1250
 	/**
@@ -1256,7 +1256,7 @@  discard block
 block discarded – undo
1256 1256
 	 * @param int $user =null owner of the collection, default current user
1257 1257
 	 * @return array with privileges
1258 1258
 	 */
1259
-	public function current_user_privileges($path, $user=null)
1259
+	public function current_user_privileges($path, $user = null)
1260 1260
 	{
1261 1261
 		$privileges = parent::current_user_privileges($path, $user);
1262 1262
 		//error_log(__METHOD__."('$path', $user) parent gave ".array2string($privileges));
@@ -1299,7 +1299,7 @@  discard block
 block discarded – undo
1299 1299
 
1300 1300
 		// get array with orginal recurrences indexed by recurrence-id
1301 1301
 		$org_recurrences = $exceptions = array();
1302
-		foreach(self::get_series($events[0]['uid'],$bo) as $k => $event)
1302
+		foreach (self::get_series($events[0]['uid'], $bo) as $k => $event)
1303 1303
 		{
1304 1304
 			if (!$k) $master = $event;
1305 1305
 			if ($event['recurrence'])
@@ -1309,13 +1309,13 @@  discard block
 block discarded – undo
1309 1309
 		}
1310 1310
 
1311 1311
 		// assign cal_id's to already existing recurrences and evtl. re-add recur_exception to master
1312
-		foreach($events as $k => &$recurrence)
1312
+		foreach ($events as $k => &$recurrence)
1313 1313
 		{
1314 1314
 			if (!$recurrence['recurrence'])
1315 1315
 			{
1316 1316
 				// master
1317 1317
 				$recurrence['id'] = $master['id'];
1318
-				$master =& $events[$k];
1318
+				$master = & $events[$k];
1319 1319
 				continue;
1320 1320
 			}
1321 1321
 
@@ -1339,12 +1339,12 @@  discard block
 block discarded – undo
1339 1339
 		$master['recur_exception'] = array_merge($exceptions, $master['recur_exception']);
1340 1340
 
1341 1341
 		// delete not longer existing recurrences
1342
-		foreach($org_recurrences as $org_recurrence)
1342
+		foreach ($org_recurrences as $org_recurrence)
1343 1343
 		{
1344 1344
 			if ($org_recurrence['id'] != $master['id'])	// non-virtual recurrence
1345 1345
 			{
1346 1346
 				//error_log(__METHOD__.'() deleting #'.$org_recurrence['id']);
1347
-				$bo->delete($org_recurrence['id']);	// might fail because of permissions
1347
+				$bo->delete($org_recurrence['id']); // might fail because of permissions
1348 1348
 			}
1349 1349
 			else	// virtual recurrence
1350 1350
 			{
@@ -1366,14 +1366,14 @@  discard block
 block discarded – undo
1366 1366
 	 * @param int $user account_id of collection owner
1367 1367
 	 * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found')
1368 1368
 	 */
1369
-	function delete(&$options,$id,$user)
1369
+	function delete(&$options, $id, $user)
1370 1370
 	{
1371 1371
 		if (strpos($options['path'], '/inbox/') !== false)
1372 1372
 		{
1373
-			return true;	// simply ignore DELETE in inbox for now
1373
+			return true; // simply ignore DELETE in inbox for now
1374 1374
 		}
1375
-		$return_no_access = true;	// to allow to check if current use is a participant and reject the event for him
1376
-		if (!is_array($event = $this->_common_get_put_delete('DELETE',$options,$id,$return_no_access)) || !$return_no_access ||
1375
+		$return_no_access = true; // to allow to check if current use is a participant and reject the event for him
1376
+		if (!is_array($event = $this->_common_get_put_delete('DELETE', $options, $id, $return_no_access)) || !$return_no_access ||
1377 1377
 			// Work around problems with Outlook CalDAV Synchroniser (https://caldavsynchronizer.org/)
1378 1378
 			// - sends a DELETE to reject a meeting request --> deletes event for all participants, if user has delete rights on the calendar
1379 1379
 			// --> only set status for everyone else but the organizer
@@ -1384,11 +1384,11 @@  discard block
 block discarded – undo
1384 1384
 				// check if user is a participant or one of the groups he is a member of --> reject the meeting request
1385 1385
 				$ret = '403 Forbidden';
1386 1386
 				$memberships = $GLOBALS['egw']->accounts->memberships($this->bo->user, true);
1387
-				foreach(array_keys($event['participants']) as $uid)
1387
+				foreach (array_keys($event['participants']) as $uid)
1388 1388
 				{
1389 1389
 					if ($this->bo->user == $uid || in_array($uid, $memberships))
1390 1390
 					{
1391
-						$this->bo->set_status($event,$this->bo->user, 'R');
1391
+						$this->bo->set_status($event, $this->bo->user, 'R');
1392 1392
 						$ret = true;
1393 1393
 						break;
1394 1394
 					}
@@ -1403,7 +1403,7 @@  discard block
 block discarded – undo
1403 1403
 		{
1404 1404
 			$ret = $this->bo->delete($event['id']);
1405 1405
 		}
1406
-		if ($this->debug) error_log(__METHOD__."(,$id) return_no_access=$return_no_access, event[participants]=".array2string(is_array($event)?$event['participants']:null).", user={$this->bo->user} --> return ".array2string($ret));
1406
+		if ($this->debug) error_log(__METHOD__."(,$id) return_no_access=$return_no_access, event[participants]=".array2string(is_array($event) ? $event['participants'] : null).", user={$this->bo->user} --> return ".array2string($ret));
1407 1407
 		return $ret;
1408 1408
 	}
1409 1409
 
@@ -1418,12 +1418,12 @@  discard block
 block discarded – undo
1418 1418
 	 */
1419 1419
 	function read($id)
1420 1420
 	{
1421
-		if (strpos($column=self::$path_attr,'_') === false) $column = 'cal_'.$column;
1421
+		if (strpos($column = self::$path_attr, '_') === false) $column = 'cal_'.$column;
1422 1422
 
1423 1423
 		$event = $this->bo->read(array($column => $id, 'cal_deleted IS NULL', 'cal_reference=0'), null, true, 'server');
1424
-		if ($event) $event = array_shift($event);	// read with array as 1. param, returns an array of events!
1424
+		if ($event) $event = array_shift($event); // read with array as 1. param, returns an array of events!
1425 1425
 
1426
-		if (!($retval = $this->bo->check_perms(calendar_bo::ACL_FREEBUSY,$event, 0, 'server')) &&
1426
+		if (!($retval = $this->bo->check_perms(calendar_bo::ACL_FREEBUSY, $event, 0, 'server')) &&
1427 1427
 			// above can be true, if current user is not in master but just a recurrence
1428 1428
 			(!$event['recur_type'] || !($events = self::get_series($event['uid'], $this->bo))))
1429 1429
 		{
@@ -1459,11 +1459,11 @@  discard block
 block discarded – undo
1459 1459
 	 *
1460 1460
 	 * @return string
1461 1461
 	 */
1462
-	public function getctag($path,$user)
1462
+	public function getctag($path, $user)
1463 1463
 	{
1464
-		$ctag = $this->bo->get_ctag($user,$path == '/calendar/' ? 'owner' : 'default'); // default = not rejected
1464
+		$ctag = $this->bo->get_ctag($user, $path == '/calendar/' ? 'owner' : 'default'); // default = not rejected
1465 1465
 
1466
-		if ($this->debug > 1) error_log(__FILE__.'['.__LINE__.'] '.__METHOD__. "($path)[$user] = $ctag");
1466
+		if ($this->debug > 1) error_log(__FILE__.'['.__LINE__.'] '.__METHOD__."($path)[$user] = $ctag");
1467 1467
 
1468 1468
 		return $ctag;
1469 1469
 	}
@@ -1475,7 +1475,7 @@  discard block
 block discarded – undo
1475 1475
 	 * @param string $schedule_tag =null on return schedule-tag
1476 1476
 	 * @return string|boolean string with etag or false
1477 1477
 	 */
1478
-	function get_etag($entry, &$schedule_tag=null)
1478
+	function get_etag($entry, &$schedule_tag = null)
1479 1479
 	{
1480 1480
 		$etag = $this->bo->get_etag($entry, $schedule_tag, $this->client_shared_uid_exceptions);
1481 1481
 
@@ -1493,7 +1493,7 @@  discard block
 block discarded – undo
1493 1493
 	 * @param int|string $retval
1494 1494
 	 * @param boolean $path_attr_is_name =true true: path_attr is ca(l|rd)dav_name, false: id (GroupDAV needs Location header)
1495 1495
 	 */
1496
-	function put_response_headers($entry, $path, $retval, $path_attr_is_name=true)
1496
+	function put_response_headers($entry, $path, $retval, $path_attr_is_name = true)
1497 1497
 	{
1498 1498
 		$schedule_tag = null;
1499 1499
 		$etag = $this->get_etag($entry, $schedule_tag);
@@ -1512,14 +1512,14 @@  discard block
 block discarded – undo
1512 1512
 	 * @param array|int $event event-array or id
1513 1513
 	 * @return boolean null if entry does not exist, false if no access, true if access permitted
1514 1514
 	 */
1515
-	function check_access($acl,$event)
1515
+	function check_access($acl, $event)
1516 1516
 	{
1517 1517
 		if ($acl == Acl::READ)
1518 1518
 		{
1519 1519
 			// we need at least calendar_bo::ACL_FREEBUSY to get some information
1520 1520
 			$acl = calendar_bo::ACL_FREEBUSY;
1521 1521
 		}
1522
-		return $this->bo->check_perms($acl,$event,0,'server');
1522
+		return $this->bo->check_perms($acl, $event, 0, 'server');
1523 1523
 	}
1524 1524
 
1525 1525
 	/**
@@ -1532,52 +1532,52 @@  discard block
 block discarded – undo
1532 1532
 	 * @param string $path =null path of the collection
1533 1533
 	 * @return array
1534 1534
 	 */
1535
-	public function extra_properties(array $props, $displayname, $base_uri=null, $user=null, $path=null)
1535
+	public function extra_properties(array $props, $displayname, $base_uri = null, $user = null, $path = null)
1536 1536
 	{
1537
-		unset($base_uri);	// unused, but required by function signature
1537
+		unset($base_uri); // unused, but required by function signature
1538 1538
 		if (!isset($props['calendar-description']))
1539 1539
 		{
1540 1540
 			// default calendar description: can be overwritten via PROPPATCH, in which case it's already set
1541
-			$props['calendar-description'] = Api\CalDAV::mkprop(Api\CalDAV::CALDAV,'calendar-description',$displayname);
1541
+			$props['calendar-description'] = Api\CalDAV::mkprop(Api\CalDAV::CALDAV, 'calendar-description', $displayname);
1542 1542
 		}
1543 1543
 		$supported_components = array(
1544
-			Api\CalDAV::mkprop(Api\CalDAV::CALDAV,'comp',array('name' => 'VEVENT')),
1544
+			Api\CalDAV::mkprop(Api\CalDAV::CALDAV, 'comp', array('name' => 'VEVENT')),
1545 1545
 		);
1546 1546
 		// outbox supports VFREEBUSY too, it is required from OS X iCal to autocomplete locations
1547
-		if (substr($path,-8) == '/outbox/')
1547
+		if (substr($path, -8) == '/outbox/')
1548 1548
 		{
1549
-			$supported_components[] = Api\CalDAV::mkprop(Api\CalDAV::CALDAV,'comp',array('name' => 'VFREEBUSY'));
1549
+			$supported_components[] = Api\CalDAV::mkprop(Api\CalDAV::CALDAV, 'comp', array('name' => 'VFREEBUSY'));
1550 1550
 		}
1551 1551
 		$props['supported-calendar-component-set'] = Api\CalDAV::mkprop(Api\CalDAV::CALDAV,
1552
-			'supported-calendar-component-set',$supported_components);
1552
+			'supported-calendar-component-set', $supported_components);
1553 1553
 		// supported reports
1554 1554
 		$props['supported-report-set'] = array(
1555
-			'calendar-query' => Api\CalDAV::mkprop('supported-report',array(
1556
-				Api\CalDAV::mkprop('report',array(
1557
-					Api\CalDAV::mkprop(Api\CalDAV::CALDAV,'calendar-query',''))))),
1558
-			'calendar-multiget' => Api\CalDAV::mkprop('supported-report',array(
1559
-				Api\CalDAV::mkprop('report',array(
1560
-					Api\CalDAV::mkprop(Api\CalDAV::CALDAV,'calendar-multiget',''))))),
1561
-			'free-busy-query' => Api\CalDAV::mkprop('supported-report',array(
1562
-				Api\CalDAV::mkprop('report',array(
1563
-					Api\CalDAV::mkprop(Api\CalDAV::CALDAV,'free-busy-query',''))))),
1555
+			'calendar-query' => Api\CalDAV::mkprop('supported-report', array(
1556
+				Api\CalDAV::mkprop('report', array(
1557
+					Api\CalDAV::mkprop(Api\CalDAV::CALDAV, 'calendar-query', ''))))),
1558
+			'calendar-multiget' => Api\CalDAV::mkprop('supported-report', array(
1559
+				Api\CalDAV::mkprop('report', array(
1560
+					Api\CalDAV::mkprop(Api\CalDAV::CALDAV, 'calendar-multiget', ''))))),
1561
+			'free-busy-query' => Api\CalDAV::mkprop('supported-report', array(
1562
+				Api\CalDAV::mkprop('report', array(
1563
+					Api\CalDAV::mkprop(Api\CalDAV::CALDAV, 'free-busy-query', ''))))),
1564 1564
 		);
1565 1565
 		// rfc 6578 sync-collection report for everything but outbox
1566 1566
 		// only if "delete-prevention" is switched on (deleted entries get marked deleted but not actualy deleted
1567 1567
 		if (strpos($path, '/outbox/') === false && $GLOBALS['egw_info']['server']['calendar_delete_history'])
1568 1568
 		{
1569
-			$props['supported-report-set']['sync-collection'] = Api\CalDAV::mkprop('supported-report',array(
1570
-				Api\CalDAV::mkprop('report',array(
1571
-					Api\CalDAV::mkprop('sync-collection','')))));
1569
+			$props['supported-report-set']['sync-collection'] = Api\CalDAV::mkprop('supported-report', array(
1570
+				Api\CalDAV::mkprop('report', array(
1571
+					Api\CalDAV::mkprop('sync-collection', '')))));
1572 1572
 		}
1573
-		$props['supported-calendar-data'] = Api\CalDAV::mkprop(Api\CalDAV::CALDAV,'supported-calendar-data',array(
1574
-			Api\CalDAV::mkprop(Api\CalDAV::CALDAV,'calendar-data', array('content-type' => 'text/calendar', 'version'=> '2.0')),
1575
-			Api\CalDAV::mkprop(Api\CalDAV::CALDAV,'calendar-data', array('content-type' => 'text/x-calendar', 'version'=> '1.0'))));
1573
+		$props['supported-calendar-data'] = Api\CalDAV::mkprop(Api\CalDAV::CALDAV, 'supported-calendar-data', array(
1574
+			Api\CalDAV::mkprop(Api\CalDAV::CALDAV, 'calendar-data', array('content-type' => 'text/calendar', 'version'=> '2.0')),
1575
+			Api\CalDAV::mkprop(Api\CalDAV::CALDAV, 'calendar-data', array('content-type' => 'text/x-calendar', 'version'=> '1.0'))));
1576 1576
 
1577 1577
 		// get timezone of calendar
1578 1578
 		if ($this->caldav->prop_requested('calendar-timezone'))
1579 1579
 		{
1580
-			$props['calendar-timezone'] = Api\CalDAV::mkprop(Api\CalDAV::CALDAV,'calendar-timezone',
1580
+			$props['calendar-timezone'] = Api\CalDAV::mkprop(Api\CalDAV::CALDAV, 'calendar-timezone',
1581 1581
 				calendar_timezones::user_timezone($user));
1582 1582
 		}
1583 1583
 		return $props;
@@ -1591,9 +1591,9 @@  discard block
 block discarded – undo
1591 1591
 	private function _get_handler()
1592 1592
 	{
1593 1593
 		$handler = new calendar_ical();
1594
-		$handler->setSupportedFields('GroupDAV',$this->agent);
1595
-		$handler->supportedFields['attachments'] = true;	// enabling attachments
1596
-		if ($this->debug > 1) error_log("ical Handler called: " . $this->agent);
1594
+		$handler->setSupportedFields('GroupDAV', $this->agent);
1595
+		$handler->supportedFields['attachments'] = true; // enabling attachments
1596
+		if ($this->debug > 1) error_log("ical Handler called: ".$this->agent);
1597 1597
 		return $handler;
1598 1598
 	}
1599 1599
 
@@ -1608,7 +1608,7 @@  discard block
 block discarded – undo
1608 1608
 		$pref = $GLOBALS['egw_info']['user']['preferences']['groupdav']['calendar-home-set'];
1609 1609
 		$calendar_home_set = $pref ? explode(',', $pref) : array();
1610 1610
 		// replace symbolic id's with real nummeric id's
1611
-		foreach(array(
1611
+		foreach (array(
1612 1612
 			'G' => $GLOBALS['egw_info']['user']['account_primary_group'],
1613 1613
 		) as $sym => $id)
1614 1614
 		{
@@ -1617,11 +1617,11 @@  discard block
 block discarded – undo
1617 1617
 				$calendar_home_set[$key] = $id;
1618 1618
 			}
1619 1619
 		}
1620
-		foreach(ExecMethod('calendar.calendar_bo.list_cals') as $entry)
1620
+		foreach (ExecMethod('calendar.calendar_bo.list_cals') as $entry)
1621 1621
 		{
1622 1622
 			$id = $entry['grantor'];
1623
-			if ($id && $GLOBALS['egw_info']['user']['account_id'] != $id &&	// no current user
1624
-				(in_array('A',$calendar_home_set) || in_array((string)$id,$calendar_home_set)) &&
1623
+			if ($id && $GLOBALS['egw_info']['user']['account_id'] != $id && // no current user
1624
+				(in_array('A', $calendar_home_set) || in_array((string)$id, $calendar_home_set)) &&
1625 1625
 				is_numeric($id) && ($owner = $this->accounts->id2name($id)))
1626 1626
 			{
1627 1627
 				$shared[$id] = 'calendar-'.$owner;
@@ -1630,11 +1630,11 @@  discard block
 block discarded – undo
1630 1630
 		// shared locations and resources
1631 1631
 		if ($GLOBALS['egw_info']['user']['apps']['resources'])
1632 1632
 		{
1633
-			foreach(array('locations','resources') as $res)
1633
+			foreach (array('locations', 'resources') as $res)
1634 1634
 			{
1635 1635
 				if (($pref = $GLOBALS['egw_info']['user']['preferences']['groupdav']['calendar-home-set-'.$res]))
1636 1636
 				{
1637
-					foreach(explode(',', $pref) as $res_id)
1637
+					foreach (explode(',', $pref) as $res_id)
1638 1638
 					{
1639 1639
 						$is_location = $res == 'locations';
1640 1640
 						$shared['r'.$res_id] = str_replace('s/', '-', Api\CalDAV\Principals::resource2name($res_id, $is_location));
@@ -1664,7 +1664,7 @@  discard block
 block discarded – undo
1664 1664
 			{
1665 1665
 				$calendars[$entry['grantor']] = $entry['name'];
1666 1666
 			}
1667
-			if ($user > 0) unset($calendars[$user]);	// skip current user
1667
+			if ($user > 0) unset($calendars[$user]); // skip current user
1668 1668
 		}
1669 1669
 
1670 1670
 		$settings = array();
@@ -1672,7 +1672,7 @@  discard block
 block discarded – undo
1672 1672
 			'type'   => 'multiselect',
1673 1673
 			'label'  => 'Calendars to sync in addition to personal calendar',
1674 1674
 			'name'   => 'calendar-home-set',
1675
-			'help'   => lang('Only supported by a few fully conformant clients (eg. from Apple). If you have to enter a URL, it will most likly not be suppored!').'<br/>'.lang('They will be sub-folders in users home (%1 attribute).','CalDAV "calendar-home-set"'),
1675
+			'help'   => lang('Only supported by a few fully conformant clients (eg. from Apple). If you have to enter a URL, it will most likly not be suppored!').'<br/>'.lang('They will be sub-folders in users home (%1 attribute).', 'CalDAV "calendar-home-set"'),
1676 1676
 			'values' => $calendars,
1677 1677
 			'xmlrpc' => True,
1678 1678
 			'admin'  => False,
@@ -1698,7 +1698,7 @@  discard block
 block discarded – undo
1698 1698
 		if ($GLOBALS['egw_info']['user']['apps']['resources'] && ($all_resources = Api\CalDAV\Principals::get_resources()))
1699 1699
 		{
1700 1700
 			$resources = $locations = array();
1701
-			foreach($all_resources as $resource)
1701
+			foreach ($all_resources as $resource)
1702 1702
 			{
1703 1703
 				if (Api\CalDAV\Principals::resource_is_location($resource))
1704 1704
 				{
@@ -1709,7 +1709,7 @@  discard block
 block discarded – undo
1709 1709
 					$resources[$resource['res_id']] = $resource['name'];
1710 1710
 				}
1711 1711
 			}
1712
-			foreach(array(
1712
+			foreach (array(
1713 1713
 				'locations' => $locations,
1714 1714
 				'resources' => $resources,
1715 1715
 			) as $name => $options)
@@ -1722,7 +1722,7 @@  discard block
 block discarded – undo
1722 1722
 						'label'  => lang('%1 to sync', lang($name == 'locations' ? 'Location calendars' : 'Resource calendars')),
1723 1723
 						'no_lang'=> true,
1724 1724
 						'name'   => 'calendar-home-set-'.$name,
1725
-						'help'   => lang('Only supported by a few fully conformant clients (eg. from Apple). If you have to enter a URL, it will most likly not be suppored!').'<br/>'.lang('They will be sub-folders in users home (%1 attribute).','CalDAV "calendar-home-set"'),
1725
+						'help'   => lang('Only supported by a few fully conformant clients (eg. from Apple). If you have to enter a URL, it will most likly not be suppored!').'<br/>'.lang('They will be sub-folders in users home (%1 attribute).', 'CalDAV "calendar-home-set"'),
1726 1726
 						'values' => $options,
1727 1727
 						'xmlrpc' => True,
1728 1728
 						'admin'  => False,
Please login to merge, or discard this patch.
Braces   +229 added lines, -57 removed lines patch added patch discarded remove patch
@@ -132,7 +132,10 @@  discard block
 block discarded – undo
132 132
 		}
133 133
 		else
134 134
 		{
135
-			if (!is_array($event)) $event = $this->bo->read($event);
135
+			if (!is_array($event))
136
+			{
137
+				$event = $this->bo->read($event);
138
+			}
136 139
 			$name = $event[self::$path_attr];
137 140
 		}
138 141
 		$name .= self::$path_extension;
@@ -193,10 +196,13 @@  discard block
 block discarded – undo
193 196
 			}
194 197
 			$filter[$name] = $this->bo->now + 24*3600*($name == 'start' ? -1 : 1)*abs($value);
195 198
 		}
196
-		if ($this->client_shared_uid_exceptions)	// do NOT return (non-virtual) exceptions
199
+		if ($this->client_shared_uid_exceptions)
200
+		{
201
+			// do NOT return (non-virtual) exceptions
197 202
 		{
198 203
 			$filter['query'] = array('cal_reference' => 0);
199 204
 		}
205
+		}
200 206
 
201 207
 		if ($path == '/calendar/')
202 208
 		{
@@ -226,7 +232,11 @@  discard block
 block discarded – undo
226 232
 			// when trying to request not supported components, eg. VTODO on a calendar collection
227 233
 			return true;
228 234
 		}
229
-		if ($id) $path = dirname($path).'/';	// caldav_name get's added anyway in the callback
235
+		if ($id)
236
+		{
237
+			$path = dirname($path).'/';
238
+		}
239
+		// caldav_name get's added anyway in the callback
230 240
 
231 241
 		if ($this->debug > 1)
232 242
 		{
@@ -288,7 +298,11 @@  discard block
 block discarded – undo
288 298
 		$n = 0;
289 299
 		foreach($files as $file)
290 300
 		{
291
-			if (!$n++) continue;	// first entry is collection itself
301
+			if (!$n++)
302
+			{
303
+				continue;
304
+			}
305
+			// first entry is collection itself
292 306
 
293 307
 			$icalendar = $file['props']['calendar-data']['val'];
294 308
 			if (($start = strpos($icalendar, 'BEGIN:VEVENT')) !== false &&
@@ -332,10 +346,17 @@  discard block
 block discarded – undo
332 346
 	 */
333 347
 	function &propfind_callback($path,array $filter,$start=false)
334 348
 	{
335
-		if ($this->debug) $starttime = microtime(true);
349
+		if ($this->debug)
350
+		{
351
+			$starttime = microtime(true);
352
+		}
336 353
 
337 354
 		$calendar_data = $this->caldav->prop_requested('calendar-data', Api\CalDAV::CALDAV, true);
338
-		if (!is_array($calendar_data)) $calendar_data = false;	// not in allprop or autoindex
355
+		if (!is_array($calendar_data))
356
+		{
357
+			$calendar_data = false;
358
+		}
359
+		// not in allprop or autoindex
339 360
 
340 361
 		$files = array();
341 362
 
@@ -493,7 +514,10 @@  discard block
 block discarded – undo
493 514
 				switch($filter['name'])
494 515
 				{
495 516
 					case 'comp-filter':
496
-						if ($this->debug > 1) error_log(__METHOD__."($options[path],...) comp-filter='{$filter['attrs']['name']}'");
517
+						if ($this->debug > 1)
518
+						{
519
+							error_log(__METHOD__."($options[path],...) comp-filter='{$filter['attrs']['name']}'");
520
+						}
497 521
 
498 522
 						switch($filter['attrs']['name'])
499 523
 						{
@@ -508,14 +532,23 @@  discard block
 block discarded – undo
508 532
 						}
509 533
 						break;
510 534
 					case 'prop-filter':
511
-						if ($this->debug > 1) error_log(__METHOD__."($options[path],...) prop-filter='{$filter['attrs']['name']}'");
535
+						if ($this->debug > 1)
536
+						{
537
+							error_log(__METHOD__."($options[path],...) prop-filter='{$filter['attrs']['name']}'");
538
+						}
512 539
 						$prop_filter = $filter['attrs']['name'];
513 540
 						break;
514 541
 					case 'text-match':
515
-						if ($this->debug > 1) error_log(__METHOD__."($options[path],...) text-match: $prop_filter='{$filter['data']}'");
542
+						if ($this->debug > 1)
543
+						{
544
+							error_log(__METHOD__."($options[path],...) text-match: $prop_filter='{$filter['data']}'");
545
+						}
516 546
 						if (!isset($this->filter_prop2cal[strtoupper($prop_filter)]))
517 547
 						{
518
-							if ($this->debug) error_log(__METHOD__."($options[path],".array2string($options).",...) unknown property '$prop_filter' --> ignored");
548
+							if ($this->debug)
549
+							{
550
+								error_log(__METHOD__."($options[path],".array2string($options).",...) unknown property '$prop_filter' --> ignored");
551
+							}
519 552
 						}
520 553
 						else
521 554
 						{
@@ -524,10 +557,16 @@  discard block
 block discarded – undo
524 557
 						unset($prop_filter);
525 558
 						break;
526 559
 					case 'param-filter':
527
-						if ($this->debug) error_log(__METHOD__."($options[path],...) param-filter='{$filter['attrs']['name']}' not (yet) implemented!");
560
+						if ($this->debug)
561
+						{
562
+							error_log(__METHOD__."($options[path],...) param-filter='{$filter['attrs']['name']}' not (yet) implemented!");
563
+						}
528 564
 						break;
529 565
 					case 'time-range':
530
-				 		if ($this->debug > 1) error_log(__FILE__ . __METHOD__."($options[path],...) time-range={$filter['attrs']['start']}-{$filter['attrs']['end']}");
566
+				 		if ($this->debug > 1)
567
+				 		{
568
+				 			error_log(__FILE__ . __METHOD__."($options[path],...) time-range={$filter['attrs']['start']}-{$filter['attrs']['end']}");
569
+				 		}
531 570
 				 		if (!empty($filter['attrs']['start']))
532 571
 				 		{
533 572
 					 		$cal_filters['start'] = $this->vCalendar->_parseDateTime($filter['attrs']['start']);
@@ -538,13 +577,19 @@  discard block
 block discarded – undo
538 577
 				 		}
539 578
 						break;
540 579
 					default:
541
-						if ($this->debug) error_log(__METHOD__."($options[path],".array2string($options).",...) unknown filter --> ignored");
580
+						if ($this->debug)
581
+						{
582
+							error_log(__METHOD__."($options[path],".array2string($options).",...) unknown filter --> ignored");
583
+						}
542 584
 						break;
543 585
 				}
544 586
 			}
545
-			if (count($cal_filters) == $num_filters)	// no filters set --> restore default start and end time
587
+			if (count($cal_filters) == $num_filters)
588
+			{
589
+				// no filters set --> restore default start and end time
546 590
 			{
547 591
 				$cal_filters['start'] = $cal_start;
592
+			}
548 593
 				$cal_filters['end']   = $cal_end;
549 594
 			}
550 595
 		}
@@ -621,7 +666,10 @@  discard block
 block discarded – undo
621 666
 				}
622 667
 			}
623 668
 
624
-			if ($this->debug > 1) error_log(__FILE__ . __METHOD__ ."($options[path],...,$id) calendar-multiget: ids=".implode(',',$ids).', cal_filters='.array2string($cal_filters));
669
+			if ($this->debug > 1)
670
+			{
671
+				error_log(__FILE__ . __METHOD__ ."($options[path],...,$id) calendar-multiget: ids=".implode(',',$ids).', cal_filters='.array2string($cal_filters));
672
+			}
625 673
 		}
626 674
 		return true;
627 675
 	}
@@ -667,9 +715,15 @@  discard block
 block discarded – undo
667 715
 	private function iCal(array $event,$user=null, $method=null, $expand=false)
668 716
 	{
669 717
 		static $handler = null;
670
-		if (is_null($handler)) $handler = $this->_get_handler();
718
+		if (is_null($handler))
719
+		{
720
+			$handler = $this->_get_handler();
721
+		}
671 722
 
672
-		if (!$user) $user = $GLOBALS['egw_info']['user']['account_id'];
723
+		if (!$user)
724
+		{
725
+			$user = $GLOBALS['egw_info']['user']['account_id'];
726
+		}
673 727
 
674 728
 		// only return alarms in own calendar, not other users calendars
675 729
 		if ($user != $GLOBALS['egw_info']['user']['account_id'])
@@ -685,12 +739,21 @@  discard block
 block discarded – undo
685 739
 		{
686 740
 			if (is_array($expand))
687 741
 			{
688
-				if (isset($expand['start'])) $expand['start'] = $this->vCalendar->_parseDateTime($expand['start']);
689
-				if (isset($expand['end'])) $expand['end'] = $this->vCalendar->_parseDateTime($expand['end']);
742
+				if (isset($expand['start']))
743
+				{
744
+					$expand['start'] = $this->vCalendar->_parseDateTime($expand['start']);
745
+				}
746
+				if (isset($expand['end']))
747
+				{
748
+					$expand['end'] = $this->vCalendar->_parseDateTime($expand['end']);
749
+				}
690 750
 			}
691 751
 			$events =& self::get_series($event['uid'], $this->bo, $expand, $user);
692 752
 			// as alarm is now only on next recurrence, set alarm from original event on master
693
-			if ($event['alarm']) $events[0]['alarm'] = $event['alarm'];
753
+			if ($event['alarm'])
754
+			{
755
+				$events[0]['alarm'] = $event['alarm'];
756
+			}
694 757
 		}
695 758
 		elseif(!$this->client_shared_uid_exceptions && $event['reference'])
696 759
 		{
@@ -712,7 +775,10 @@  discard block
 block discarded – undo
712 775
 	 */
713 776
 	private static function &get_series($uid,calendar_bo $bo=null, $expand=false, $user=null)
714 777
 	{
715
-		if (is_null($bo)) $bo = new calendar_bopdate();
778
+		if (is_null($bo))
779
+		{
780
+			$bo = new calendar_bopdate();
781
+		}
716 782
 
717 783
 		$params = array(
718 784
 			'query' => array('cal_uid' => $uid),
@@ -721,7 +787,10 @@  discard block
 block discarded – undo
721 787
 			'date_format' => 'server',
722 788
 			'cfs' => array(),	// read cfs as we use them to store X- attributes
723 789
 		);
724
-		if (is_array($expand)) $params += $expand;
790
+		if (is_array($expand))
791
+		{
792
+			$params += $expand;
793
+		}
725 794
 
726 795
 		if (!($events =& $bo->search($params)))
727 796
 		{
@@ -742,7 +811,10 @@  discard block
 block discarded – undo
742 811
 			}
743 812
 		}
744 813
 		// if recurring event starts in future behind horizont, nothing will be returned by bo::search()
745
-		if (!isset($master)) $master = $bo->read($uid);
814
+		if (!isset($master))
815
+		{
816
+			$master = $bo->read($uid);
817
+		}
746 818
 
747 819
 		foreach($events as $k => &$recurrence)
748 820
 		{
@@ -752,7 +824,9 @@  discard block
 block discarded – undo
752 824
 				unset($events[$k]);
753 825
 				continue;	// same uid, but references a different event or is own master
754 826
 			}
755
-			if (!$master || $recurrence['id'] != $master['id'])	// real exception
827
+			if (!$master || $recurrence['id'] != $master['id'])
828
+			{
829
+				// real exception
756 830
 			{
757 831
 				// user is NOT participating in this exception
758 832
 				if ($user && !self::isParticipant($recurrence, $user))
@@ -761,6 +835,7 @@  discard block
 block discarded – undo
761 835
 					if (!$master || !self::isParticipant($master, $user))
762 836
 					{
763 837
 						unset($events[$k]);
838
+			}
764 839
 						continue;
765 840
 					}
766 841
 					// otherwise mark him in this exception as rejected
@@ -792,7 +867,10 @@  discard block
 block discarded – undo
792 867
 			// this is a virtual exception now (no extra event/cal_id in DB)
793 868
 			//error_log('virtual exception: '.array2string($recurrence));
794 869
 			$recurrence['recurrence'] = $recurrence['start'];
795
-			if ($master) $recurrence['reference'] = $master['id'];
870
+			if ($master)
871
+			{
872
+				$recurrence['reference'] = $master['id'];
873
+			}
796 874
 			$recurrence['recur_type'] = MCAL_RECUR_NONE;	// is set, as this is a copy of the master
797 875
 			// not for included exceptions (Lightning): $master['recur_exception'][] = $recurrence['start'];
798 876
 		}
@@ -831,9 +909,16 @@  discard block
 block discarded – undo
831 909
 	 */
832 910
 	function put(&$options,$id,$user=null,$prefix=null)
833 911
 	{
834
-		if ($this->debug) error_log(__METHOD__."($id, $user)".print_r($options,true));
912
+		if ($this->debug)
913
+		{
914
+			error_log(__METHOD__."($id, $user)".print_r($options,true));
915
+		}
835 916
 
836
-		if (!$prefix) $user = null;	// /infolog/ does not imply setting the current user (for new entries it's done anyway)
917
+		if (!$prefix)
918
+		{
919
+			$user = null;
920
+		}
921
+		// /infolog/ does not imply setting the current user (for new entries it's done anyway)
837 922
 
838 923
 		// work around missing handling / racecondition in Lightning, if event already exists on server,
839 924
 		// but Lightning has not yet synced with the server: Lightning just retries the PUT, not GETing the event
@@ -855,7 +940,10 @@  discard block
 block discarded – undo
855 940
 			isset($_SERVER['HTTP_IF_SCHEDULE_TAG_MATCH']));	// dont fail with 412 Precondition Failed in that case
856 941
 		if (!is_null($oldEvent) && !is_array($oldEvent))
857 942
 		{
858
-			if ($this->debug) error_log(__METHOD__.': '.print_r($oldEvent,true).function_backtrace());
943
+			if ($this->debug)
944
+			{
945
+				error_log(__METHOD__.': '.print_r($oldEvent,true).function_backtrace());
946
+			}
859 947
 			return $oldEvent;
860 948
 		}
861 949
 
@@ -866,7 +954,10 @@  discard block
 block discarded – undo
866 954
 		{
867 955
 			// we have no add permission on this user's calendar
868 956
 			// ToDo: create event in current users calendar and invite only $user
869
-			if ($this->debug) error_log(__METHOD__."(,,$user) we have not enough rights on this calendar");
957
+			if ($this->debug)
958
+			{
959
+				error_log(__METHOD__."(,,$user) we have not enough rights on this calendar");
960
+			}
870 961
 			return '403 Forbidden';
871 962
 		}
872 963
 
@@ -913,13 +1004,19 @@  discard block
 block discarded – undo
913 1004
 			if ($this->use_schedule_tag && isset($_SERVER['HTTP_IF_SCHEDULE_TAG_MATCH']))
914 1005
 			{
915 1006
 				$schedule_tag_match = $_SERVER['HTTP_IF_SCHEDULE_TAG_MATCH'];
916
-				if ($schedule_tag_match[0] == '"') $schedule_tag_match = substr($schedule_tag_match, 1, -1);
1007
+				if ($schedule_tag_match[0] == '"')
1008
+				{
1009
+					$schedule_tag_match = substr($schedule_tag_match, 1, -1);
1010
+				}
917 1011
 				$schedule_tag = null;
918 1012
 				$this->get_etag($oldEvent, $schedule_tag);
919 1013
 
920 1014
 				if ($schedule_tag_match !== $schedule_tag)
921 1015
 				{
922
-					if ($this->debug) error_log(__METHOD__."(,,$user) schedule_tag missmatch: given '$schedule_tag_match' != '$schedule_tag'");
1016
+					if ($this->debug)
1017
+					{
1018
+						error_log(__METHOD__."(,,$user) schedule_tag missmatch: given '$schedule_tag_match' != '$schedule_tag'");
1019
+					}
923 1020
 					// honor Prefer: return=representation for 412 too (no need for client to explicitly reload)
924 1021
 					$this->check_return_representation($options, $id, $user);
925 1022
 					return '412 Precondition Failed';
@@ -940,7 +1037,10 @@  discard block
 block discarded – undo
940 1037
 					// above can be true, if current user is not in master but just a recurrence
941 1038
 					(!$oldEvent['recur_type'] || !($series = self::get_series($oldEvent['uid'], $this->bo))))
942 1039
 				{
943
-					if ($this->debug) error_log(__METHOD__."(,,$user) user $user is NOT an attendee!");
1040
+					if ($this->debug)
1041
+					{
1042
+						error_log(__METHOD__."(,,$user) user $user is NOT an attendee!");
1043
+					}
944 1044
 					return '403 Forbidden';
945 1045
 				}
946 1046
 				// update only participant status and alarms of current user
@@ -960,7 +1060,10 @@  discard block
 block discarded – undo
960 1060
 							}
961 1061
 							foreach($series as $oldEvent)
962 1062
 							{
963
-								if ($oldEvent['recurrence'] == $event['recurrence']) break;
1063
+								if ($oldEvent['recurrence'] == $event['recurrence'])
1064
+								{
1065
+									break;
1066
+								}
964 1067
 							}
965 1068
 							// if no exception found, check if it might be just a recurrence (no exception)
966 1069
 							if ($event['recurrence'] && $oldEvent['recurrence'] != $event['recurrence'])
@@ -975,7 +1078,10 @@  discard block
 block discarded – undo
975 1078
 								}
976 1079
 							}
977 1080
 						}
978
-						if ($this->debug) error_log(__METHOD__."(, $id, $user, '$prefix') eventId=$eventId ($oldEvent[id]), user=$user, old-status='{$oldEvent['participants'][$user]}', new-status='{$event['participants'][$user]}', recurrence=$event[recurrence]=".Api\DateTime::to($event['recurrence']).", event=".array2string($event));
1081
+						if ($this->debug)
1082
+						{
1083
+							error_log(__METHOD__."(, $id, $user, '$prefix') eventId=$eventId ($oldEvent[id]), user=$user, old-status='{$oldEvent['participants'][$user]}', new-status='{$event['participants'][$user]}', recurrence=$event[recurrence]=".Api\DateTime::to($event['recurrence']).", event=".array2string($event));
1084
+						}
979 1085
 						if (isset($event['participants']) && isset($event['participants'][$user]) &&
980 1086
 							$event['participants'][$user] !== $oldEvent['participants'][$user])
981 1087
 						{
@@ -983,13 +1089,19 @@  discard block
 block discarded – undo
983 1089
 								// real (not virtual) exceptions use recurrence 0 in egw_cal_user.cal_recurrence!
984 1090
 								$recurrence = $eventId == $oldEvent['id'] ? $event['recurrence'] : 0))
985 1091
 							{
986
-								if ($this->debug) error_log(__METHOD__."(,,$user) failed to set_status($oldEvent[id], $user, '{$event['participants'][$user]}', $recurrence=".Api\DateTime::to($recurrence).')');
1092
+								if ($this->debug)
1093
+								{
1094
+									error_log(__METHOD__."(,,$user) failed to set_status($oldEvent[id], $user, '{$event['participants'][$user]}', $recurrence=".Api\DateTime::to($recurrence).')');
1095
+								}
987 1096
 								return '403 Forbidden';
988 1097
 							}
989 1098
 							else
990 1099
 							{
991 1100
 								++$modified;
992
-								if ($this->debug) error_log(__METHOD__."() set_status($oldEvent[id], $user, {$event['participants'][$user]} , $recurrence=".Api\DateTime::to($recurrence).')');
1101
+								if ($this->debug)
1102
+								{
1103
+									error_log(__METHOD__."() set_status($oldEvent[id], $user, {$event['participants'][$user]} , $recurrence=".Api\DateTime::to($recurrence).')');
1104
+								}
993 1105
 							}
994 1106
 						}
995 1107
 						// import alarms, if given and changed
@@ -999,15 +1111,21 @@  discard block
 block discarded – undo
999 1111
 							$modified += $handler->sync_alarms($event, (array)$oldEvent['alarm'], $user);
1000 1112
 						}
1001 1113
 					}
1002
-					if (!$modified)	// NO modififictions, or none we understood --> log it and return Ok: "204 No Content"
1114
+					if (!$modified)
1115
+					{
1116
+						// NO modififictions, or none we understood --> log it and return Ok: "204 No Content"
1003 1117
 					{
1004 1118
 						$this->caldav->log(__METHOD__."(,,$user) NO changes for current user events=".array2string($events).', old-event='.array2string($oldEvent));
1005 1119
 					}
1120
+					}
1006 1121
 					$this->put_response_headers($eventId, $options['path'], '204 No Content', self::$path_attr == 'caldav_name');
1007 1122
 
1008 1123
 					return '204 No Content';
1009 1124
 				}
1010
-				if ($this->debug && !isset($events)) error_log(__METHOD__."(,,$user) only schedule-tag given for event without participants (only calendar owner) --> handle as regular PUT");
1125
+				if ($this->debug && !isset($events))
1126
+				{
1127
+					error_log(__METHOD__."(,,$user) only schedule-tag given for event without participants (only calendar owner) --> handle as regular PUT");
1128
+				}
1011 1129
 			}
1012 1130
 			if ($return_no_access)
1013 1131
 			{
@@ -1044,17 +1162,23 @@  discard block
 block discarded – undo
1044 1162
 		if (!($cal_id = $handler->importVCal($vCalendar, $eventId,
1045 1163
 			self::etag2value($this->http_if_match), false, 0, $this->caldav->current_user_principal, $user, $charset, $id)))
1046 1164
 		{
1047
-			if ($this->debug) error_log(__METHOD__."(,$id) eventId=$eventId: importVCal('$options[content]') returned ".array2string($cal_id));
1165
+			if ($this->debug)
1166
+			{
1167
+				error_log(__METHOD__."(,$id) eventId=$eventId: importVCal('$options[content]') returned ".array2string($cal_id));
1168
+			}
1048 1169
 			if ($eventId && $cal_id === false)
1049 1170
 			{
1050 1171
 				// ignore import failures
1051 1172
 				$cal_id = $eventId;
1052 1173
 				$retval = true;
1053 1174
 			}
1054
-			elseif ($cal_id === 0)	// etag failure
1175
+			elseif ($cal_id === 0)
1176
+			{
1177
+				// etag failure
1055 1178
 			{
1056 1179
 				// honor Prefer: return=representation for 412 too (no need for client to explicitly reload)
1057 1180
 				$this->check_return_representation($options, $id, $user);
1181
+			}
1058 1182
 				return '412 Precondition Failed';
1059 1183
 			}
1060 1184
 			else
@@ -1079,7 +1203,10 @@  discard block
 block discarded – undo
1079 1203
 	 */
1080 1204
 	function post(&$options,$id,$user=null)
1081 1205
 	{
1082
-		if ($this->debug) error_log(__METHOD__."($id, $user)".print_r($options,true));
1206
+		if ($this->debug)
1207
+		{
1208
+			error_log(__METHOD__."($id, $user)".print_r($options,true));
1209
+		}
1083 1210
 
1084 1211
 		$vCalendar = htmlspecialchars_decode($options['content']);
1085 1212
 		$charset = null;
@@ -1133,7 +1260,10 @@  discard block
 block discarded – undo
1133 1260
 				if (!($cal_id = $handler->importVCal($vCalendar, $eventId, null,
1134 1261
 					false, 0, $this->caldav->current_user_principal, $user, $charset)))
1135 1262
 				{
1136
-					if ($this->debug) error_log(__METHOD__."() importVCal($eventId) returned false");
1263
+					if ($this->debug)
1264
+					{
1265
+						error_log(__METHOD__."() importVCal($eventId) returned false");
1266
+					}
1137 1267
 				}
1138 1268
 				header('ETag: "'.$this->get_etag($eventId).'"');
1139 1269
 			}
@@ -1301,7 +1431,10 @@  discard block
 block discarded – undo
1301 1431
 		$org_recurrences = $exceptions = array();
1302 1432
 		foreach(self::get_series($events[0]['uid'],$bo) as $k => $event)
1303 1433
 		{
1304
-			if (!$k) $master = $event;
1434
+			if (!$k)
1435
+			{
1436
+				$master = $event;
1437
+			}
1305 1438
 			if ($event['recurrence'])
1306 1439
 			{
1307 1440
 				$org_recurrences[$event['recurrence']] = $event;
@@ -1321,10 +1454,13 @@  discard block
 block discarded – undo
1321 1454
 
1322 1455
 			// from now on we deal with exceptions
1323 1456
 			$org_recurrence = $org_recurrences[$recurrence['recurrence']];
1324
-			if (isset($org_recurrence))	// already existing recurrence
1457
+			if (isset($org_recurrence))
1458
+			{
1459
+				// already existing recurrence
1325 1460
 			{
1326 1461
 				//error_log(__METHOD__.'() setting id #'.$org_recurrence['id']).' for '.$recurrence['recurrence'].' = '.date('Y-m-d H:i:s',$recurrence['recurrence']);
1327 1462
 				$recurrence['id'] = $org_recurrence['id'];
1463
+			}
1328 1464
 
1329 1465
 				// re-add (non-virtual) exceptions to master's recur_exception
1330 1466
 				if ($recurrence['id'] != $master['id'])
@@ -1341,10 +1477,14 @@  discard block
 block discarded – undo
1341 1477
 		// delete not longer existing recurrences
1342 1478
 		foreach($org_recurrences as $org_recurrence)
1343 1479
 		{
1344
-			if ($org_recurrence['id'] != $master['id'])	// non-virtual recurrence
1480
+			if ($org_recurrence['id'] != $master['id'])
1481
+			{
1482
+				// non-virtual recurrence
1345 1483
 			{
1346 1484
 				//error_log(__METHOD__.'() deleting #'.$org_recurrence['id']);
1347
-				$bo->delete($org_recurrence['id']);	// might fail because of permissions
1485
+				$bo->delete($org_recurrence['id']);
1486
+			}
1487
+			// might fail because of permissions
1348 1488
 			}
1349 1489
 			else	// virtual recurrence
1350 1490
 			{
@@ -1380,7 +1520,7 @@  discard block
 block discarded – undo
1380 1520
 			self::get_agent() == 'caldavsynchronizer' && is_array($event) && $event['owner'] != $user)
1381 1521
 		{
1382 1522
  			if (is_array($event) && (!$return_no_access || $event['owner'] != $user))
1383
-			{
1523
+ 			{
1384 1524
 				// check if user is a participant or one of the groups he is a member of --> reject the meeting request
1385 1525
 				$ret = '403 Forbidden';
1386 1526
 				$memberships = $GLOBALS['egw']->accounts->memberships($this->bo->user, true);
@@ -1403,7 +1543,10 @@  discard block
 block discarded – undo
1403 1543
 		{
1404 1544
 			$ret = $this->bo->delete($event['id']);
1405 1545
 		}
1406
-		if ($this->debug) error_log(__METHOD__."(,$id) return_no_access=$return_no_access, event[participants]=".array2string(is_array($event)?$event['participants']:null).", user={$this->bo->user} --> return ".array2string($ret));
1546
+		if ($this->debug)
1547
+		{
1548
+			error_log(__METHOD__."(,$id) return_no_access=$return_no_access, event[participants]=".array2string(is_array($event)?$event['participants']:null).", user={$this->bo->user} --> return ".array2string($ret));
1549
+		}
1407 1550
 		return $ret;
1408 1551
 	}
1409 1552
 
@@ -1418,16 +1561,26 @@  discard block
 block discarded – undo
1418 1561
 	 */
1419 1562
 	function read($id)
1420 1563
 	{
1421
-		if (strpos($column=self::$path_attr,'_') === false) $column = 'cal_'.$column;
1564
+		if (strpos($column=self::$path_attr,'_') === false)
1565
+		{
1566
+			$column = 'cal_'.$column;
1567
+		}
1422 1568
 
1423 1569
 		$event = $this->bo->read(array($column => $id, 'cal_deleted IS NULL', 'cal_reference=0'), null, true, 'server');
1424
-		if ($event) $event = array_shift($event);	// read with array as 1. param, returns an array of events!
1570
+		if ($event)
1571
+		{
1572
+			$event = array_shift($event);
1573
+		}
1574
+		// read with array as 1. param, returns an array of events!
1425 1575
 
1426 1576
 		if (!($retval = $this->bo->check_perms(calendar_bo::ACL_FREEBUSY,$event, 0, 'server')) &&
1427 1577
 			// above can be true, if current user is not in master but just a recurrence
1428 1578
 			(!$event['recur_type'] || !($events = self::get_series($event['uid'], $this->bo))))
1429 1579
 		{
1430
-			if ($this->debug > 0) error_log(__METHOD__."($id) no READ or FREEBUSY rights returning ".array2string($retval));
1580
+			if ($this->debug > 0)
1581
+			{
1582
+				error_log(__METHOD__."($id) no READ or FREEBUSY rights returning ".array2string($retval));
1583
+			}
1431 1584
 			return $retval;
1432 1585
 		}
1433 1586
 		if (!$this->bo->check_perms(Acl::READ, $event, 0, 'server'))
@@ -1435,9 +1588,15 @@  discard block
 block discarded – undo
1435 1588
 			$this->bo->clear_private_infos($event, array($this->bo->user, $event['owner']));
1436 1589
 		}
1437 1590
 		// handle deleted events, as not existing
1438
-		if ($event['deleted']) $event = null;
1591
+		if ($event['deleted'])
1592
+		{
1593
+			$event = null;
1594
+		}
1439 1595
 
1440
-		if ($this->debug > 1) error_log(__METHOD__."($id) returning ".array2string($event));
1596
+		if ($this->debug > 1)
1597
+		{
1598
+			error_log(__METHOD__."($id) returning ".array2string($event));
1599
+		}
1441 1600
 
1442 1601
 		return $event;
1443 1602
 	}
@@ -1449,7 +1608,10 @@  discard block
 block discarded – undo
1449 1608
 	 */
1450 1609
 	public function update_tags($entry)
1451 1610
 	{
1452
-		if (!is_array($entry)) $entry = $this->read($entry);
1611
+		if (!is_array($entry))
1612
+		{
1613
+			$entry = $this->read($entry);
1614
+		}
1453 1615
 
1454 1616
 		$this->bo->update($entry, true);
1455 1617
 	}
@@ -1463,7 +1625,10 @@  discard block
 block discarded – undo
1463 1625
 	{
1464 1626
 		$ctag = $this->bo->get_ctag($user,$path == '/calendar/' ? 'owner' : 'default'); // default = not rejected
1465 1627
 
1466
-		if ($this->debug > 1) error_log(__FILE__.'['.__LINE__.'] '.__METHOD__. "($path)[$user] = $ctag");
1628
+		if ($this->debug > 1)
1629
+		{
1630
+			error_log(__FILE__.'['.__LINE__.'] '.__METHOD__. "($path)[$user] = $ctag");
1631
+		}
1467 1632
 
1468 1633
 		return $ctag;
1469 1634
 	}
@@ -1593,7 +1758,10 @@  discard block
 block discarded – undo
1593 1758
 		$handler = new calendar_ical();
1594 1759
 		$handler->setSupportedFields('GroupDAV',$this->agent);
1595 1760
 		$handler->supportedFields['attachments'] = true;	// enabling attachments
1596
-		if ($this->debug > 1) error_log("ical Handler called: " . $this->agent);
1761
+		if ($this->debug > 1)
1762
+		{
1763
+			error_log("ical Handler called: " . $this->agent);
1764
+		}
1597 1765
 		return $handler;
1598 1766
 	}
1599 1767
 
@@ -1664,7 +1832,11 @@  discard block
 block discarded – undo
1664 1832
 			{
1665 1833
 				$calendars[$entry['grantor']] = $entry['name'];
1666 1834
 			}
1667
-			if ($user > 0) unset($calendars[$user]);	// skip current user
1835
+			if ($user > 0)
1836
+			{
1837
+				unset($calendars[$user]);
1838
+			}
1839
+			// skip current user
1668 1840
 		}
1669 1841
 
1670 1842
 		$settings = array();
Please login to merge, or discard this patch.
api/src/Auth/Ldap.php 2 patches
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -43,29 +43,29 @@  discard block
 block discarded – undo
43 43
 	 * @param string $_passwd corresponding password
44 44
 	 * @return boolean true if successful authenticated, false otherwise
45 45
 	 */
46
-	function authenticate($_username, $_passwd, $passwd_type='text')
46
+	function authenticate($_username, $_passwd, $passwd_type = 'text')
47 47
 	{
48
-		unset($passwd_type);	// not used by required by function signature
48
+		unset($passwd_type); // not used by required by function signature
49 49
 
50 50
 		// allow non-ascii in username & password
51
-		$username = Api\Translation::convert($_username,Api\Translation::charset(),'utf-8');
51
+		$username = Api\Translation::convert($_username, Api\Translation::charset(), 'utf-8');
52 52
 		// harden ldap auth, by removing \000 bytes, causing passwords to be not empty by php, but empty to c libaries
53
-		$passwd = str_replace("\000", '', Api\Translation::convert($_passwd,Api\Translation::charset(),'utf-8'));
53
+		$passwd = str_replace("\000", '', Api\Translation::convert($_passwd, Api\Translation::charset(), 'utf-8'));
54 54
 
55 55
 		// Login with the LDAP Admin. User to find the User DN.
56 56
 		try {
57 57
 			$ldap = Api\Ldap::factory();
58 58
 		}
59
-		catch(Api\Exception\NoPermission $e)
59
+		catch (Api\Exception\NoPermission $e)
60 60
 		{
61 61
 			unset($e);
62 62
 			if ($this->debug) error_log(__METHOD__."('$username',\$password) can NOT bind with ldap_root_dn to search!");
63 63
 			return False;
64 64
 		}
65 65
 		/* find the dn for this uid, the uid is not always in the dn */
66
-		$attributes	= array('uid','dn','givenName','sn','mail','uidNumber','shadowExpire','homeDirectory');
66
+		$attributes = array('uid', 'dn', 'givenName', 'sn', 'mail', 'uidNumber', 'shadowExpire', 'homeDirectory');
67 67
 
68
-		$filter = str_replace(array('%user','%domain'),array(Api\Ldap::quote($username),$GLOBALS['egw_info']['user']['domain']),
68
+		$filter = str_replace(array('%user', '%domain'), array(Api\Ldap::quote($username), $GLOBALS['egw_info']['user']['domain']),
69 69
 			$GLOBALS['egw_info']['server']['ldap_search_filter'] ? $GLOBALS['egw_info']['server']['ldap_search_filter'] : '(uid=%user)');
70 70
 
71 71
 		if ($GLOBALS['egw_info']['server']['account_repository'] == 'ldap')
@@ -84,10 +84,10 @@  discard block
 block discarded – undo
84 84
 				return false;
85 85
 			}
86 86
 			if ($GLOBALS['egw_info']['server']['account_repository'] == 'ldap' &&
87
-				isset($allValues[0]['shadowexpire']) && $allValues[0]['shadowexpire'][0]*24*3600 < time())
87
+				isset($allValues[0]['shadowexpire']) && $allValues[0]['shadowexpire'][0] * 24 * 3600 < time())
88 88
 			{
89 89
 				if ($this->debug) error_log(__METHOD__."('$username',\$password) account is expired!");
90
-				return false;	// account is expired
90
+				return false; // account is expired
91 91
 			}
92 92
 			$userDN = $allValues[0]['dn'];
93 93
 
@@ -103,13 +103,13 @@  discard block
 block discarded – undo
103 103
 					{
104 104
 						$GLOBALS['auto_create_acct']['homedirectory'] = $allValues[0]['homedirectory'][0];
105 105
 					}
106
-					if (!($id = $GLOBALS['egw']->accounts->name2id($username,'account_lid','u')))
106
+					if (!($id = $GLOBALS['egw']->accounts->name2id($username, 'account_lid', 'u')))
107 107
 					{
108 108
 						// account does NOT exist, check if we should create it
109 109
 						if ($GLOBALS['egw_info']['server']['auto_create_acct'])
110 110
 						{
111 111
 							// create a global array with all availible info about that account
112
-							foreach(array(
112
+							foreach (array(
113 113
 								'givenname' => 'firstname',
114 114
 								'sn'        => 'lastname',
115 115
 								'uidnumber' => 'account_id',
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 							) as $ldap_name => $acct_name)
118 118
 							{
119 119
 								$GLOBALS['auto_create_acct'][$acct_name] =
120
-									Api\Translation::convert($allValues[0][$ldap_name][0],'utf-8');
120
+									Api\Translation::convert($allValues[0][$ldap_name][0], 'utf-8');
121 121
 							}
122 122
 							$ret = true;
123 123
 						}
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 					// account exists, check if it is acctive
131 131
 					else
132 132
 					{
133
-						$ret = $GLOBALS['egw']->accounts->id2name($id,'account_status') == 'A';
133
+						$ret = $GLOBALS['egw']->accounts->id2name($id, 'account_status') == 'A';
134 134
 
135 135
 						if ($this->debug && !$ret) error_log(__METHOD__."('$username',\$password) account NOT active!");
136 136
 					}
@@ -141,12 +141,12 @@  discard block
 block discarded – undo
141 141
 				{
142 142
 					$matches = null;
143 143
 					// try to query password from ldap server (might fail because of ACL) and check if we need to migrate the hash
144
-					if (($sri = ldap_search($ldap, $userDN,"(objectclass=*)", array('userPassword'))) &&
144
+					if (($sri = ldap_search($ldap, $userDN, "(objectclass=*)", array('userPassword'))) &&
145 145
 						($values = ldap_get_entries($ldap, $sri)) && isset($values[0]['userpassword'][0]) &&
146
-						($type = preg_match('/^{(.+)}/',$values[0]['userpassword'][0],$matches) ? strtolower($matches[1]) : 'plain') &&
146
+						($type = preg_match('/^{(.+)}/', $values[0]['userpassword'][0], $matches) ? strtolower($matches[1]) : 'plain') &&
147 147
 						// for crypt use Api\Auth::crypt_compare to detect correct sub-type, strlen("{crypt}")=7
148 148
 						($type != 'crypt' || Api\Auth::crypt_compare($passwd, substr($values[0]['userpassword'][0], 7), $type)) &&
149
-						in_array($type, explode(',',strtolower($GLOBALS['egw_info']['server']['pwd_migration_types']))))
149
+						in_array($type, explode(',', strtolower($GLOBALS['egw_info']['server']['pwd_migration_types']))))
150 150
 					{
151 151
 						$this->change_password($passwd, $passwd, $allValues[0]['uidnumber'][0], false);
152 152
 					}
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
 	function getLastPwdChange($_username)
169 169
 	{
170 170
 		// allow non-ascii in username & password
171
-		$username = Api\Translation::convert($_username,Api\Translation::charset(),'utf-8');
171
+		$username = Api\Translation::convert($_username, Api\Translation::charset(), 'utf-8');
172 172
 
173 173
 		// Login with the LDAP Admin. User to find the User DN.
174 174
 		try {
@@ -180,9 +180,9 @@  discard block
 block discarded – undo
180 180
 			return false;
181 181
 		}
182 182
 		/* find the dn for this uid, the uid is not always in the dn */
183
-		$attributes	= array('uid','dn','shadowexpire','shadowlastchange');
183
+		$attributes = array('uid', 'dn', 'shadowexpire', 'shadowlastchange');
184 184
 
185
-		$filter = str_replace(array('%user','%domain'),array(Api\Ldap::quote($username),$GLOBALS['egw_info']['user']['domain']),
185
+		$filter = str_replace(array('%user', '%domain'), array(Api\Ldap::quote($username), $GLOBALS['egw_info']['user']['domain']),
186 186
 			$GLOBALS['egw_info']['server']['ldap_search_filter'] ? $GLOBALS['egw_info']['server']['ldap_search_filter'] : '(uid=%user)');
187 187
 
188 188
 		if ($GLOBALS['egw_info']['server']['account_repository'] == 'ldap')
@@ -206,12 +206,12 @@  discard block
 block discarded – undo
206 206
 				return false;
207 207
 			}
208 208
 			if ($GLOBALS['egw_info']['server']['account_repository'] == 'ldap' &&
209
-				isset($allValues[0]['shadowexpire']) && $allValues[0]['shadowexpire'][0]*24*3600 < time())
209
+				isset($allValues[0]['shadowexpire']) && $allValues[0]['shadowexpire'][0] * 24 * 3600 < time())
210 210
 			{
211 211
 				if ($this->debug) error_log(__METHOD__."('$username',\$password) account is expired!");
212
-				return false;	// account is expired
212
+				return false; // account is expired
213 213
 			}
214
-			return $allValues[0]['shadowlastchange'][0]*24*3600;
214
+			return $allValues[0]['shadowlastchange'][0] * 24 * 3600;
215 215
 		}
216 216
 		if ($this->debug) error_log(__METHOD__."('$username') dn not found or password wrong!");
217 217
 		// dn not found or password wrong
@@ -226,11 +226,11 @@  discard block
 block discarded – undo
226 226
 	 * @param int $lastpwdchange must be a unixtimestamp
227 227
 	 * @return boolean true if account_lastpwd_change successful changed, false otherwise
228 228
 	 */
229
-	function setLastPwdChange($account_id=0, $passwd=NULL, $lastpwdchange=NULL)
229
+	function setLastPwdChange($account_id = 0, $passwd = NULL, $lastpwdchange = NULL)
230 230
 	{
231 231
 		$admin = True;
232 232
 		// Don't allow password changes for other accounts when using XML-RPC
233
-		if(!$account_id || $GLOBALS['egw_info']['flags']['currentapp'] == 'login')
233
+		if (!$account_id || $GLOBALS['egw_info']['flags']['currentapp'] == 'login')
234 234
 		{
235 235
 			$admin = False;
236 236
 			$username = $GLOBALS['egw_info']['user']['account_lid'];
@@ -238,22 +238,22 @@  discard block
 block discarded – undo
238 238
 		else
239 239
 		{
240 240
 			$username = Api\Translation::convert($GLOBALS['egw']->accounts->id2name($account_id),
241
-				Api\Translation::charset(),'utf-8');
241
+				Api\Translation::charset(), 'utf-8');
242 242
 		}
243 243
 		//echo "<p>auth_Api\Ldap::change_password('$old_passwd','$new_passwd',$account_id) username='$username'</p>\n";
244 244
 
245
-		$filter = str_replace(array('%user','%domain'),array($username,$GLOBALS['egw_info']['user']['domain']),
245
+		$filter = str_replace(array('%user', '%domain'), array($username, $GLOBALS['egw_info']['user']['domain']),
246 246
 			$GLOBALS['egw_info']['server']['ldap_search_filter'] ? $GLOBALS['egw_info']['server']['ldap_search_filter'] : '(uid=%user)');
247 247
 
248 248
 		$ds = Api\Ldap::factory();
249 249
 		$sri = ldap_search($ds, $GLOBALS['egw_info']['server']['ldap_context'], $filter);
250 250
 		$allValues = ldap_get_entries($ds, $sri);
251 251
 
252
-		$entry['shadowlastchange'] = (is_null($lastpwdchange) || $lastpwdchange<0 ? round((time()-date('Z')) / (24*3600)):$lastpwdchange);
252
+		$entry['shadowlastchange'] = (is_null($lastpwdchange) || $lastpwdchange < 0 ? round((time() - date('Z')) / (24 * 3600)) : $lastpwdchange);
253 253
 
254 254
 		$dn = $allValues[0]['dn'];
255 255
 
256
-		if(!$admin && $passwd)	// if old password given (not called by admin) --> bind as that user to change the pw
256
+		if (!$admin && $passwd)	// if old password given (not called by admin) --> bind as that user to change the pw
257 257
 		{
258 258
 			$ds = Api\Ldap::factory(true, '', $dn, $passwd);
259 259
 		}
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 			return false;
263 263
 		}
264 264
 		// using time() is sufficient to represent the current time, we do not need the timestamp written to the storage
265
-		if (!$admin) Api\Cache::setSession('phpgwapi','auth_alpwchange_val',(is_null($lastpwdchange) || $lastpwdchange<0 ? time():$lastpwdchange));
265
+		if (!$admin) Api\Cache::setSession('phpgwapi', 'auth_alpwchange_val', (is_null($lastpwdchange) || $lastpwdchange < 0 ? time() : $lastpwdchange));
266 266
 		return true;
267 267
 	}
268 268
 
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
 	 * @param boolean $update_lastchange =true
279 279
 	 * @return boolean true if password successful changed, false otherwise
280 280
 	 */
281
-	function change_password($old_passwd, $new_passwd, $account_id=0, $update_lastchange=true)
281
+	function change_password($old_passwd, $new_passwd, $account_id = 0, $update_lastchange = true)
282 282
 	{
283 283
 		if (!$account_id)
284 284
 		{
@@ -287,11 +287,11 @@  discard block
 block discarded – undo
287 287
 		else
288 288
 		{
289 289
 			$username = Api\Translation::convert($GLOBALS['egw']->accounts->id2name($account_id),
290
-				Api\Translation::charset(),'utf-8');
290
+				Api\Translation::charset(), 'utf-8');
291 291
 		}
292 292
 		if ($this->debug) error_log(__METHOD__."('$old_passwd','$new_passwd',$account_id, $update_lastchange) username='$username'");
293 293
 
294
-		$filter = str_replace(array('%user','%domain'),array($username,$GLOBALS['egw_info']['user']['domain']),
294
+		$filter = str_replace(array('%user', '%domain'), array($username, $GLOBALS['egw_info']['user']['domain']),
295 295
 			$GLOBALS['egw_info']['server']['ldap_search_filter'] ? $GLOBALS['egw_info']['server']['ldap_search_filter'] : '(uid=%user)');
296 296
 
297 297
 		$ds = $ds_admin = Api\Ldap::factory();
@@ -301,19 +301,19 @@  discard block
 block discarded – undo
301 301
 		$entry['userpassword'] = Api\Auth::encrypt_password($new_passwd);
302 302
 		if ($update_lastchange)
303 303
 		{
304
-			$entry['shadowlastchange'] = round((time()-date('Z')) / (24*3600));
304
+			$entry['shadowlastchange'] = round((time() - date('Z')) / (24 * 3600));
305 305
 		}
306 306
 
307 307
 		$dn = $allValues[0]['dn'];
308 308
 
309
-		if($old_passwd)	// if old password given (not called by admin) --> bind as that user to change the pw
309
+		if ($old_passwd)	// if old password given (not called by admin) --> bind as that user to change the pw
310 310
 		{
311 311
 			try {
312 312
 				$ds = Api\Ldap::factory(true, '', $dn, $old_passwd);
313 313
 			}
314 314
 			catch (Api\Exception\NoPermission $e) {
315 315
 				unset($e);
316
-				return false;	// wrong old user password
316
+				return false; // wrong old user password
317 317
 			}
318 318
 		}
319 319
 		// try changing password bind as user or as admin, to cater for all sorts of ldap configuration
@@ -322,10 +322,10 @@  discard block
 block discarded – undo
322 322
 		{
323 323
 			return false;
324 324
 		}
325
-		if($old_passwd)	// if old password given (not called by admin) update the password in the session
325
+		if ($old_passwd)	// if old password given (not called by admin) update the password in the session
326 326
 		{
327 327
 			// using time() is sufficient to represent the current time, we do not need the timestamp written to the storage
328
-			Api\Cache::setSession('phpgwapi','auth_alpwchange_val',time());
328
+			Api\Cache::setSession('phpgwapi', 'auth_alpwchange_val', time());
329 329
 		}
330 330
 		return $entry['userpassword'];
331 331
 	}
Please login to merge, or discard this patch.
Braces   +64 added lines, -16 removed lines patch added patch discarded remove patch
@@ -59,7 +59,10 @@  discard block
 block discarded – undo
59 59
 		catch(Api\Exception\NoPermission $e)
60 60
 		{
61 61
 			unset($e);
62
-			if ($this->debug) error_log(__METHOD__."('$username',\$password) can NOT bind with ldap_root_dn to search!");
62
+			if ($this->debug)
63
+			{
64
+				error_log(__METHOD__."('$username',\$password) can NOT bind with ldap_root_dn to search!");
65
+			}
63 66
 			return False;
64 67
 		}
65 68
 		/* find the dn for this uid, the uid is not always in the dn */
@@ -80,13 +83,19 @@  discard block
 block discarded – undo
80 83
 			if ($GLOBALS['egw_info']['server']['case_sensitive_username'] == true &&
81 84
 				$allValues[0]['uid'][0] != $username)
82 85
 			{
83
-				if ($this->debug) error_log(__METHOD__."('$username',\$password) wrong case in username!");
86
+				if ($this->debug)
87
+				{
88
+					error_log(__METHOD__."('$username',\$password) wrong case in username!");
89
+				}
84 90
 				return false;
85 91
 			}
86 92
 			if ($GLOBALS['egw_info']['server']['account_repository'] == 'ldap' &&
87 93
 				isset($allValues[0]['shadowexpire']) && $allValues[0]['shadowexpire'][0]*24*3600 < time())
88 94
 			{
89
-				if ($this->debug) error_log(__METHOD__."('$username',\$password) account is expired!");
95
+				if ($this->debug)
96
+				{
97
+					error_log(__METHOD__."('$username',\$password) account is expired!");
98
+				}
90 99
 				return false;	// account is expired
91 100
 			}
92 101
 			$userDN = $allValues[0]['dn'];
@@ -124,7 +133,10 @@  discard block
 block discarded – undo
124 133
 						else
125 134
 						{
126 135
 							$ret = false;
127
-							if ($this->debug) error_log(__METHOD__."('$username',\$password) bind as user failed!");
136
+							if ($this->debug)
137
+							{
138
+								error_log(__METHOD__."('$username',\$password) bind as user failed!");
139
+							}
128 140
 						}
129 141
 					}
130 142
 					// account exists, check if it is acctive
@@ -132,7 +144,10 @@  discard block
 block discarded – undo
132 144
 					{
133 145
 						$ret = $GLOBALS['egw']->accounts->id2name($id,'account_status') == 'A';
134 146
 
135
-						if ($this->debug && !$ret) error_log(__METHOD__."('$username',\$password) account NOT active!");
147
+						if ($this->debug && !$ret)
148
+						{
149
+							error_log(__METHOD__."('$username',\$password) account NOT active!");
150
+						}
136 151
 					}
137 152
 				}
138 153
 				// account-repository is ldap --> check if passwd hash migration is enabled
@@ -154,7 +169,10 @@  discard block
 block discarded – undo
154 169
 				return $ret;
155 170
 			}
156 171
 		}
157
-		if ($this->debug) error_log(__METHOD__."('$_username', '$_passwd') dn not found or password wrong!");
172
+		if ($this->debug)
173
+		{
174
+			error_log(__METHOD__."('$_username', '$_passwd') dn not found or password wrong!");
175
+		}
158 176
 		// dn not found or password wrong
159 177
 		return False;
160 178
 	}
@@ -176,7 +194,10 @@  discard block
 block discarded – undo
176 194
 		}
177 195
 		catch (Api\Exception\NoPermission $ex) {
178 196
 			unset($ex);
179
-			if ($this->debug) error_log(__METHOD__."('$username') can NOT bind with ldap_root_dn to search!");
197
+			if ($this->debug)
198
+			{
199
+				error_log(__METHOD__."('$username') can NOT bind with ldap_root_dn to search!");
200
+			}
180 201
 			return false;
181 202
 		}
182 203
 		/* find the dn for this uid, the uid is not always in the dn */
@@ -196,24 +217,36 @@  discard block
 block discarded – undo
196 217
 		{
197 218
 			if (!isset($allValues[0]['shadowlastchange']))
198 219
 			{
199
-				if ($this->debug) error_log(__METHOD__."('$username') no shadowlastchange attribute!");
220
+				if ($this->debug)
221
+				{
222
+					error_log(__METHOD__."('$username') no shadowlastchange attribute!");
223
+				}
200 224
 				return false;
201 225
 			}
202 226
 			if ($GLOBALS['egw_info']['server']['case_sensitive_username'] == true &&
203 227
 				$allValues[0]['uid'][0] != $username)
204 228
 			{
205
-				if ($this->debug) error_log(__METHOD__."('$username') wrong case in username!");
229
+				if ($this->debug)
230
+				{
231
+					error_log(__METHOD__."('$username') wrong case in username!");
232
+				}
206 233
 				return false;
207 234
 			}
208 235
 			if ($GLOBALS['egw_info']['server']['account_repository'] == 'ldap' &&
209 236
 				isset($allValues[0]['shadowexpire']) && $allValues[0]['shadowexpire'][0]*24*3600 < time())
210 237
 			{
211
-				if ($this->debug) error_log(__METHOD__."('$username',\$password) account is expired!");
238
+				if ($this->debug)
239
+				{
240
+					error_log(__METHOD__."('$username',\$password) account is expired!");
241
+				}
212 242
 				return false;	// account is expired
213 243
 			}
214 244
 			return $allValues[0]['shadowlastchange'][0]*24*3600;
215 245
 		}
216
-		if ($this->debug) error_log(__METHOD__."('$username') dn not found or password wrong!");
246
+		if ($this->debug)
247
+		{
248
+			error_log(__METHOD__."('$username') dn not found or password wrong!");
249
+		}
217 250
 		// dn not found or password wrong
218 251
 		return false;
219 252
 	}
@@ -253,16 +286,22 @@  discard block
 block discarded – undo
253 286
 
254 287
 		$dn = $allValues[0]['dn'];
255 288
 
256
-		if(!$admin && $passwd)	// if old password given (not called by admin) --> bind as that user to change the pw
289
+		if(!$admin && $passwd)
290
+		{
291
+			// if old password given (not called by admin) --> bind as that user to change the pw
257 292
 		{
258 293
 			$ds = Api\Ldap::factory(true, '', $dn, $passwd);
259 294
 		}
295
+		}
260 296
 		if (!@ldap_modify($ds, $dn, $entry))
261 297
 		{
262 298
 			return false;
263 299
 		}
264 300
 		// using time() is sufficient to represent the current time, we do not need the timestamp written to the storage
265
-		if (!$admin) Api\Cache::setSession('phpgwapi','auth_alpwchange_val',(is_null($lastpwdchange) || $lastpwdchange<0 ? time():$lastpwdchange));
301
+		if (!$admin)
302
+		{
303
+			Api\Cache::setSession('phpgwapi','auth_alpwchange_val',(is_null($lastpwdchange) || $lastpwdchange<0 ? time():$lastpwdchange));
304
+		}
266 305
 		return true;
267 306
 	}
268 307
 
@@ -289,7 +328,10 @@  discard block
 block discarded – undo
289 328
 			$username = Api\Translation::convert($GLOBALS['egw']->accounts->id2name($account_id),
290 329
 				Api\Translation::charset(),'utf-8');
291 330
 		}
292
-		if ($this->debug) error_log(__METHOD__."('$old_passwd','$new_passwd',$account_id, $update_lastchange) username='$username'");
331
+		if ($this->debug)
332
+		{
333
+			error_log(__METHOD__."('$old_passwd','$new_passwd',$account_id, $update_lastchange) username='$username'");
334
+		}
293 335
 
294 336
 		$filter = str_replace(array('%user','%domain'),array($username,$GLOBALS['egw_info']['user']['domain']),
295 337
 			$GLOBALS['egw_info']['server']['ldap_search_filter'] ? $GLOBALS['egw_info']['server']['ldap_search_filter'] : '(uid=%user)');
@@ -306,10 +348,13 @@  discard block
 block discarded – undo
306 348
 
307 349
 		$dn = $allValues[0]['dn'];
308 350
 
309
-		if($old_passwd)	// if old password given (not called by admin) --> bind as that user to change the pw
351
+		if($old_passwd)
352
+		{
353
+			// if old password given (not called by admin) --> bind as that user to change the pw
310 354
 		{
311 355
 			try {
312 356
 				$ds = Api\Ldap::factory(true, '', $dn, $old_passwd);
357
+		}
313 358
 			}
314 359
 			catch (Api\Exception\NoPermission $e) {
315 360
 				unset($e);
@@ -322,11 +367,14 @@  discard block
 block discarded – undo
322 367
 		{
323 368
 			return false;
324 369
 		}
325
-		if($old_passwd)	// if old password given (not called by admin) update the password in the session
370
+		if($old_passwd)
371
+		{
372
+			// if old password given (not called by admin) update the password in the session
326 373
 		{
327 374
 			// using time() is sufficient to represent the current time, we do not need the timestamp written to the storage
328 375
 			Api\Cache::setSession('phpgwapi','auth_alpwchange_val',time());
329 376
 		}
377
+		}
330 378
 		return $entry['userpassword'];
331 379
 	}
332 380
 }
Please login to merge, or discard this patch.
api/src/Auth/Http.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -29,9 +29,9 @@  discard block
 block discarded – undo
29 29
 	 * @param string $passwd_type ='text' 'text' for cleartext passwords (default)
30 30
 	 * @return boolean true if successful authenticated, false otherwise
31 31
 	 */
32
-	function authenticate($username, $passwd, $passwd_type='text')
32
+	function authenticate($username, $passwd, $passwd_type = 'text')
33 33
 	{
34
-		unset($passwd, $passwd_type);	// not used, but required by interface
34
+		unset($passwd, $passwd_type); // not used, but required by interface
35 35
 
36 36
 		return isset($_SERVER['PHP_AUTH_USER']) && $_SERVER['PHP_AUTH_USER'] === $username;
37 37
 	}
@@ -44,9 +44,9 @@  discard block
 block discarded – undo
44 44
 	 * @param int $account_id account id of user whose passwd should be changed
45 45
 	 * @return boolean true if password successful changed, false otherwise
46 46
 	 */
47
-	function change_password($old_passwd, $new_passwd, $account_id=0)
47
+	function change_password($old_passwd, $new_passwd, $account_id = 0)
48 48
 	{
49
-		unset($old_passwd, $new_passwd, $account_id);	// not used, but required by interface
49
+		unset($old_passwd, $new_passwd, $account_id); // not used, but required by interface
50 50
 
51 51
 		return False;
52 52
 	}
Please login to merge, or discard this patch.