@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | /** |
83 | 83 | * Constructor |
84 | 84 | * |
85 | - * @param array|Imap $params =array() |
|
85 | + * @param Imap $params =array() |
|
86 | 86 | */ |
87 | 87 | function __construct($params=array()) |
88 | 88 | { |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | * |
166 | 166 | * @param array $_emailNotification |
167 | 167 | * @param string $_scriptName |
168 | - * @return Script |
|
168 | + * @return boolean |
|
169 | 169 | */ |
170 | 170 | function setEmailNotification(array $_emailNotification, $_scriptName=null) |
171 | 171 | { |
@@ -37,28 +37,28 @@ discard block |
||
37 | 37 | var $icServer; |
38 | 38 | |
39 | 39 | /** |
40 | - * @var string name of active script queried from Sieve server |
|
41 | - */ |
|
40 | + * @var string name of active script queried from Sieve server |
|
41 | + */ |
|
42 | 42 | var $scriptName; |
43 | 43 | |
44 | 44 | /** |
45 | - * @var $rules containing the rules |
|
46 | - */ |
|
45 | + * @var $rules containing the rules |
|
46 | + */ |
|
47 | 47 | var $rules; |
48 | 48 | |
49 | 49 | /** |
50 | - * @var $vacation containing the vacation |
|
51 | - */ |
|
50 | + * @var $vacation containing the vacation |
|
51 | + */ |
|
52 | 52 | var $vacation; |
53 | 53 | |
54 | 54 | /** |
55 | - * @var $emailNotification containing the emailNotification |
|
56 | - */ |
|
55 | + * @var $emailNotification containing the emailNotification |
|
56 | + */ |
|
57 | 57 | var $emailNotification; |
58 | 58 | |
59 | 59 | /** |
60 | - * @var object $error the last PEAR error object |
|
61 | - */ |
|
60 | + * @var object $error the last PEAR error object |
|
61 | + */ |
|
62 | 62 | var $error; |
63 | 63 | |
64 | 64 | /** |
@@ -170,11 +170,11 @@ discard block |
||
170 | 170 | function setEmailNotification(array $_emailNotification, $_scriptName=null) |
171 | 171 | { |
172 | 172 | if ($_emailNotification['externalEmail'] == '' || !preg_match("/\@/",$_emailNotification['externalEmail'])) { |
173 | - $_emailNotification['status'] = 'off'; |
|
174 | - $_emailNotification['externalEmail'] = ''; |
|
175 | - } |
|
173 | + $_emailNotification['status'] = 'off'; |
|
174 | + $_emailNotification['externalEmail'] = ''; |
|
175 | + } |
|
176 | 176 | |
177 | - $script = $this->retrieveRules($_scriptName); |
|
177 | + $script = $this->retrieveRules($_scriptName); |
|
178 | 178 | $script->emailNotification = $_emailNotification; |
179 | 179 | $ret = $script->updateScript($this); |
180 | 180 | $this->error = $script->errstr; |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * |
85 | 85 | * @param array|Imap $params =array() |
86 | 86 | */ |
87 | - function __construct($params=array()) |
|
87 | + function __construct($params = array()) |
|
88 | 88 | { |
89 | 89 | if (is_a($params, __NAMESPACE__.'\\Imap')) |
90 | 90 | { |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | } |
100 | 100 | parent::__construct($params); |
101 | 101 | |
102 | - $this->displayCharset = Translation::charset(); |
|
102 | + $this->displayCharset = Translation::charset(); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | function getRules() |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | * @param string $_scriptName |
131 | 131 | * @param boolean $utf7imap_fileinto =false true: encode foldernames with utf7imap, default utf8 |
132 | 132 | */ |
133 | - function setRules(array $_rules, $_scriptName=null, $utf7imap_fileinto=false) |
|
133 | + function setRules(array $_rules, $_scriptName = null, $utf7imap_fileinto = false) |
|
134 | 134 | { |
135 | 135 | $script = $this->retrieveRules($_scriptName); |
136 | 136 | $script->debug = $this->debug; |
@@ -146,11 +146,11 @@ discard block |
||
146 | 146 | * @param array $_vacation |
147 | 147 | * @param string $_scriptName |
148 | 148 | */ |
149 | - function setVacation(array $_vacation, $_scriptName=null) |
|
149 | + function setVacation(array $_vacation, $_scriptName = null) |
|
150 | 150 | { |
151 | 151 | if ($this->debug) |
152 | 152 | { |
153 | - error_log(__METHOD__ . "($_scriptName," . print_r($_vacation, true) . ')'); |
|
153 | + error_log(__METHOD__."($_scriptName,".print_r($_vacation, true).')'); |
|
154 | 154 | } |
155 | 155 | $script = $this->retrieveRules($_scriptName); |
156 | 156 | $script->debug = $this->debug; |
@@ -167,9 +167,9 @@ discard block |
||
167 | 167 | * @param string $_scriptName |
168 | 168 | * @return Script |
169 | 169 | */ |
170 | - function setEmailNotification(array $_emailNotification, $_scriptName=null) |
|
170 | + function setEmailNotification(array $_emailNotification, $_scriptName = null) |
|
171 | 171 | { |
172 | - if ($_emailNotification['externalEmail'] == '' || !preg_match("/\@/",$_emailNotification['externalEmail'])) { |
|
172 | + if ($_emailNotification['externalEmail'] == '' || !preg_match("/\@/", $_emailNotification['externalEmail'])) { |
|
173 | 173 | $_emailNotification['status'] = 'off'; |
174 | 174 | $_emailNotification['externalEmail'] = ''; |
175 | 175 | } |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | * @param string $_scriptName |
188 | 188 | * @return Script |
189 | 189 | */ |
190 | - function retrieveRules($_scriptName=null) |
|
190 | + function retrieveRules($_scriptName = null) |
|
191 | 191 | { |
192 | 192 | if (!$_scriptName) |
193 | 193 | { |
@@ -197,8 +197,8 @@ discard block |
||
197 | 197 | try { |
198 | 198 | $this->scriptName = $this->getActive(); |
199 | 199 | } |
200 | - catch(Exception $e) { |
|
201 | - unset($e); // ignore NOTEXISTS exception |
|
200 | + catch (Exception $e) { |
|
201 | + unset($e); // ignore NOTEXISTS exception |
|
202 | 202 | } |
203 | 203 | if (empty($this->scriptName)) |
204 | 204 | { |
@@ -213,11 +213,11 @@ discard block |
||
213 | 213 | $script->retrieveRules($this); |
214 | 214 | } |
215 | 215 | catch (\Exception $e) { |
216 | - unset($e); // ignore not found script exception |
|
216 | + unset($e); // ignore not found script exception |
|
217 | 217 | } |
218 | - $this->rules =& $script->rules; |
|
219 | - $this->vacation =& $script->vacation; |
|
220 | - $this->emailNotification =& $script->emailNotification; // Added email notifications |
|
218 | + $this->rules = & $script->rules; |
|
219 | + $this->vacation = & $script->vacation; |
|
220 | + $this->emailNotification = & $script->emailNotification; // Added email notifications |
|
221 | 221 | |
222 | 222 | return $script; |
223 | 223 | } |
@@ -104,21 +104,30 @@ discard block |
||
104 | 104 | |
105 | 105 | function getRules() |
106 | 106 | { |
107 | - if (!isset($this->rules)) $this->retrieveRules(); |
|
107 | + if (!isset($this->rules)) |
|
108 | + { |
|
109 | + $this->retrieveRules(); |
|
110 | + } |
|
108 | 111 | |
109 | 112 | return $this->rules; |
110 | 113 | } |
111 | 114 | |
112 | 115 | function getVacation() |
113 | 116 | { |
114 | - if (!isset($this->rules)) $this->retrieveRules(); |
|
117 | + if (!isset($this->rules)) |
|
118 | + { |
|
119 | + $this->retrieveRules(); |
|
120 | + } |
|
115 | 121 | |
116 | 122 | return $this->vacation; |
117 | 123 | } |
118 | 124 | |
119 | 125 | function getEmailNotification() |
120 | 126 | { |
121 | - if (!isset($this->rules)) $this->retrieveRules(); |
|
127 | + if (!isset($this->rules)) |
|
128 | + { |
|
129 | + $this->retrieveRules(); |
|
130 | + } |
|
122 | 131 | |
123 | 132 | return $this->emailNotification; |
124 | 133 | } |
@@ -169,7 +178,8 @@ discard block |
||
169 | 178 | */ |
170 | 179 | function setEmailNotification(array $_emailNotification, $_scriptName=null) |
171 | 180 | { |
172 | - if ($_emailNotification['externalEmail'] == '' || !preg_match("/\@/",$_emailNotification['externalEmail'])) { |
|
181 | + if ($_emailNotification['externalEmail'] == '' || !preg_match("/\@/",$_emailNotification['externalEmail'])) |
|
182 | + { |
|
173 | 183 | $_emailNotification['status'] = 'off'; |
174 | 184 | $_emailNotification['externalEmail'] = ''; |
175 | 185 | } |
@@ -156,7 +156,7 @@ |
||
156 | 156 | /** |
157 | 157 | * Get the data of a given user |
158 | 158 | * |
159 | - * @param int|string $user numerical account-id, account-name or email address |
|
159 | + * @param integer $user numerical account-id, account-name or email address |
|
160 | 160 | * @param boolean $match_uid_at_domain =true true: uid@domain matches, false only an email or alias address matches |
161 | 161 | * @return array with values for keys 'mailLocalAddress', 'mailAlternateAddress' (array), 'mailForwardingAddress' (array), |
162 | 162 | * 'accountStatus' ("active"), 'quotaLimit' and 'deliveryMode' ("forwardOnly") |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * |
80 | 80 | * @param string $defaultDomain =null |
81 | 81 | */ |
82 | - function __construct($defaultDomain=null) |
|
82 | + function __construct($defaultDomain = null) |
|
83 | 83 | { |
84 | 84 | $this->defaultDomain = $defaultDomain ? $defaultDomain : $GLOBALS['egw_info']['server']['mail_suffix']; |
85 | 85 | |
@@ -104,12 +104,10 @@ discard block |
||
104 | 104 | */ |
105 | 105 | function addAccount($_hookValues) |
106 | 106 | { |
107 | - $mailLocalAddress = $_hookValues['account_email'] ? $_hookValues['account_email'] : |
|
108 | - Api\Accounts::email($_hookValues['account_firstname'], |
|
109 | - $_hookValues['account_lastname'],$_hookValues['account_lid'],$this->defaultDomain); |
|
107 | + $mailLocalAddress = $_hookValues['account_email'] ? $_hookValues['account_email'] : Api\Accounts::email($_hookValues['account_firstname'], |
|
108 | + $_hookValues['account_lastname'], $_hookValues['account_lid'], $this->defaultDomain); |
|
110 | 109 | |
111 | - $account_id = !empty($_hookValues['account_id']) ? $_hookValues['account_id'] : |
|
112 | - $this->accounts->name2id($_hookValues['account_lid'], 'account_lid', 'u'); |
|
110 | + $account_id = !empty($_hookValues['account_id']) ? $_hookValues['account_id'] : $this->accounts->name2id($_hookValues['account_lid'], 'account_lid', 'u'); |
|
113 | 111 | |
114 | 112 | if ($this->accounts->exists($account_id) != 1) |
115 | 113 | { |
@@ -126,7 +124,7 @@ discard block |
||
126 | 124 | */ |
127 | 125 | function deleteAccount($_hookValues) |
128 | 126 | { |
129 | - unset($_hookValues); // not used, but required by function signature |
|
127 | + unset($_hookValues); // not used, but required by function signature |
|
130 | 128 | |
131 | 129 | return true; |
132 | 130 | } |
@@ -139,12 +137,12 @@ discard block |
||
139 | 137 | */ |
140 | 138 | function getAccountEmailAddress($_accountName) |
141 | 139 | { |
142 | - $emailAddresses = array(); |
|
140 | + $emailAddresses = array(); |
|
143 | 141 | |
144 | 142 | if (($account_id = $this->accounts->name2id($_accountName, 'account_lid', 'u'))) |
145 | 143 | { |
146 | - $realName = trim($GLOBALS['egw_info']['user']['account_firstname'] . (!empty($GLOBALS['egw_info']['user']['account_firstname']) ? ' ' : '') . $GLOBALS['egw_info']['user']['account_lastname']); |
|
147 | - $emailAddresses[] = array ( |
|
144 | + $realName = trim($GLOBALS['egw_info']['user']['account_firstname'].(!empty($GLOBALS['egw_info']['user']['account_firstname']) ? ' ' : '').$GLOBALS['egw_info']['user']['account_lastname']); |
|
145 | + $emailAddresses[] = array( |
|
148 | 146 | 'name' => $realName, |
149 | 147 | 'address' => $this->accounts->id2name($account_id, 'account_email'), |
150 | 148 | 'type' => 'default', |
@@ -161,9 +159,9 @@ discard block |
||
161 | 159 | * @return array with values for keys 'mailLocalAddress', 'mailAlternateAddress' (array), 'mailForwardingAddress' (array), |
162 | 160 | * 'accountStatus' ("active"), 'quotaLimit' and 'deliveryMode' ("forwardOnly") |
163 | 161 | */ |
164 | - function getUserData($user, $match_uid_at_domain=false) |
|
162 | + function getUserData($user, $match_uid_at_domain = false) |
|
165 | 163 | { |
166 | - unset($user, $match_uid_at_domain); // not used, but required by function signature |
|
164 | + unset($user, $match_uid_at_domain); // not used, but required by function signature |
|
167 | 165 | |
168 | 166 | $userData = array(); |
169 | 167 | |
@@ -201,9 +199,9 @@ discard block |
||
201 | 199 | * @return boolean true on success, false on error writing to ldap |
202 | 200 | */ |
203 | 201 | function setUserData($_uidnumber, array $_mailAlternateAddress, array $_mailForwardingAddress, $_deliveryMode, |
204 | - $_accountStatus, $_mailLocalAddress, $_quota, $_forwarding_only=false, $_setMailbox=null) |
|
202 | + $_accountStatus, $_mailLocalAddress, $_quota, $_forwarding_only = false, $_setMailbox = null) |
|
205 | 203 | { |
206 | - unset($_uidnumber, $_mailAlternateAddress, $_mailForwardingAddress, // not used, but require by function signature |
|
204 | + unset($_uidnumber, $_mailAlternateAddress, $_mailForwardingAddress, // not used, but require by function signature |
|
207 | 205 | $_deliveryMode, $_accountStatus, $_mailLocalAddress, $_quota, $_forwarding_only, $_setMailbox); |
208 | 206 | |
209 | 207 | return true; |
@@ -217,7 +215,7 @@ discard block |
||
217 | 215 | */ |
218 | 216 | function updateAccount($_hookValues) |
219 | 217 | { |
220 | - unset($_hookValues); // not used, but required by function signature |
|
218 | + unset($_hookValues); // not used, but required by function signature |
|
221 | 219 | |
222 | 220 | return true; |
223 | 221 | } |
@@ -233,15 +231,15 @@ discard block |
||
233 | 231 | * default use $this->loginType |
234 | 232 | * @return string |
235 | 233 | */ |
236 | - /*static*/ public function mailbox_addr($account,$domain=null,$mail_login_type=null) |
|
234 | + /*static*/ public function mailbox_addr($account, $domain = null, $mail_login_type = null) |
|
237 | 235 | { |
238 | 236 | if (is_null($domain)) $domain = $this->defaultDomain; |
239 | 237 | if (is_null($mail_login_type)) $mail_login_type = $this->loginType; |
240 | 238 | |
241 | - switch($mail_login_type) |
|
239 | + switch ($mail_login_type) |
|
242 | 240 | { |
243 | 241 | case 'email': |
244 | - $mbox = is_array($account) ? $account['account_email'] : $GLOBALS['egw']->accounts->id2name($account,'account_email'); |
|
242 | + $mbox = is_array($account) ? $account['account_email'] : $GLOBALS['egw']->accounts->id2name($account, 'account_email'); |
|
245 | 243 | break; |
246 | 244 | |
247 | 245 | case 'uidNumber': |
@@ -235,8 +235,14 @@ discard block |
||
235 | 235 | */ |
236 | 236 | /*static*/ public function mailbox_addr($account,$domain=null,$mail_login_type=null) |
237 | 237 | { |
238 | - if (is_null($domain)) $domain = $this->defaultDomain; |
|
239 | - if (is_null($mail_login_type)) $mail_login_type = $this->loginType; |
|
238 | + if (is_null($domain)) |
|
239 | + { |
|
240 | + $domain = $this->defaultDomain; |
|
241 | + } |
|
242 | + if (is_null($mail_login_type)) |
|
243 | + { |
|
244 | + $mail_login_type = $this->loginType; |
|
245 | + } |
|
240 | 246 | |
241 | 247 | switch($mail_login_type) |
242 | 248 | { |
@@ -245,7 +251,10 @@ discard block |
||
245 | 251 | break; |
246 | 252 | |
247 | 253 | case 'uidNumber': |
248 | - if (is_array($account)) $account = $account['account_id']; |
|
254 | + if (is_array($account)) |
|
255 | + { |
|
256 | + $account = $account['account_id']; |
|
257 | + } |
|
249 | 258 | $mbox = 'u'.$account.'@'.$domain; |
250 | 259 | break; |
251 | 260 |
@@ -628,7 +628,7 @@ |
||
628 | 628 | * @param int $_accountID |
629 | 629 | * @param string $_forwardingAddress |
630 | 630 | * @param string $_keepLocalCopy 'yes' |
631 | - * @return boolean true on success, false on error writing to ldap |
|
631 | + * @return boolean|null true on success, false on error writing to ldap |
|
632 | 632 | */ |
633 | 633 | function saveSMTPForwarding($_accountID, $_forwardingAddress, $_keepLocalCopy) |
634 | 634 | { |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | * |
158 | 158 | * @param string $defaultDomain =null |
159 | 159 | */ |
160 | - function __construct($defaultDomain=null) |
|
160 | + function __construct($defaultDomain = null) |
|
161 | 161 | { |
162 | 162 | parent::__construct($defaultDomain); |
163 | 163 | |
@@ -205,9 +205,8 @@ discard block |
||
205 | 205 | */ |
206 | 206 | function addAccount($_hookValues) |
207 | 207 | { |
208 | - $mailLocalAddress = $_hookValues['account_email'] ? $_hookValues['account_email'] : |
|
209 | - Api\Accounts::email($_hookValues['account_firstname'], |
|
210 | - $_hookValues['account_lastname'],$_hookValues['account_lid'],$this->defaultDomain); |
|
208 | + $mailLocalAddress = $_hookValues['account_email'] ? $_hookValues['account_email'] : Api\Accounts::email($_hookValues['account_firstname'], |
|
209 | + $_hookValues['account_lastname'], $_hookValues['account_lid'], $this->defaultDomain); |
|
211 | 210 | |
212 | 211 | $ds = $this->getLdapConnection(); |
213 | 212 | |
@@ -219,13 +218,13 @@ discard block |
||
219 | 218 | } |
220 | 219 | $allValues = ldap_get_entries($ds, $sri); |
221 | 220 | $accountDN = $allValues[0]['dn']; |
222 | - $objectClasses = $allValues[0]['objectclass']; |
|
221 | + $objectClasses = $allValues[0]['objectclass']; |
|
223 | 222 | unset($objectClasses['count']); |
224 | 223 | |
225 | 224 | // add our mail schema, if not already set |
226 | - if(!in_array(static::SCHEMA,$objectClasses) && !in_array(strtolower(static::SCHEMA),$objectClasses)) |
|
225 | + if (!in_array(static::SCHEMA, $objectClasses) && !in_array(strtolower(static::SCHEMA), $objectClasses)) |
|
227 | 226 | { |
228 | - $objectClasses[] = static::SCHEMA; |
|
227 | + $objectClasses[] = static::SCHEMA; |
|
229 | 228 | } |
230 | 229 | // the new code for postfix+cyrus+ldap |
231 | 230 | $newData = array( |
@@ -256,7 +255,7 @@ discard block |
||
256 | 255 | { |
257 | 256 | error_log(__METHOD__.'('.array2string(func_get_args()).") --> ldap_mod_replace(,'$accountDN',". |
258 | 257 | array2string($newData).') returning '.array2string($ret). |
259 | - (!$ret?' ('.ldap_error($ds).')':'')); |
|
258 | + (!$ret ? ' ('.ldap_error($ds).')' : '')); |
|
260 | 259 | } |
261 | 260 | return $ret; |
262 | 261 | } |
@@ -270,7 +269,7 @@ discard block |
||
270 | 269 | */ |
271 | 270 | function addAccountExtra(array $_hookValues, array $allValues, array &$newData) |
272 | 271 | { |
273 | - unset($_hookValues, $allValues, $newData); // not used, but required by function signature |
|
272 | + unset($_hookValues, $allValues, $newData); // not used, but required by function signature |
|
274 | 273 | } |
275 | 274 | |
276 | 275 | /** |
@@ -281,24 +280,24 @@ discard block |
||
281 | 280 | */ |
282 | 281 | function getAccountEmailAddress($_accountName) |
283 | 282 | { |
284 | - $emailAddresses = array(); |
|
283 | + $emailAddresses = array(); |
|
285 | 284 | $ds = $this->getLdapConnection(); |
286 | 285 | $filter = '(&'.static::USER_FILTER.'('.static::USER_ATTR.'='.Api\Ldap::quote($_accountName).'))'; |
287 | - $attributes = array('dn', static::MAIL_ATTR, static::ALIAS_ATTR); |
|
286 | + $attributes = array('dn', static::MAIL_ATTR, static::ALIAS_ATTR); |
|
288 | 287 | $sri = @ldap_search($ds, $this->search_base, $filter, $attributes); |
289 | 288 | |
290 | 289 | if ($sri) |
291 | 290 | { |
292 | - $realName = trim($GLOBALS['egw_info']['user']['account_firstname'] . (!empty($GLOBALS['egw_info']['user']['account_firstname']) ? ' ' : '') . $GLOBALS['egw_info']['user']['account_lastname']); |
|
291 | + $realName = trim($GLOBALS['egw_info']['user']['account_firstname'].(!empty($GLOBALS['egw_info']['user']['account_firstname']) ? ' ' : '').$GLOBALS['egw_info']['user']['account_lastname']); |
|
293 | 292 | $allValues = ldap_get_entries($ds, $sri); |
294 | 293 | |
295 | - if(isset($allValues[0][static::MAIL_ATTR])) |
|
294 | + if (isset($allValues[0][static::MAIL_ATTR])) |
|
296 | 295 | { |
297 | - foreach($allValues[0][static::MAIL_ATTR] as $key => $value) |
|
296 | + foreach ($allValues[0][static::MAIL_ATTR] as $key => $value) |
|
298 | 297 | { |
299 | 298 | if ($key === 'count') continue; |
300 | 299 | |
301 | - $emailAddresses[] = array ( |
|
300 | + $emailAddresses[] = array( |
|
302 | 301 | 'name' => $realName, |
303 | 302 | 'address' => $value, |
304 | 303 | 'type' => !$key ? 'default' : 'alternate', |
@@ -307,7 +306,7 @@ discard block |
||
307 | 306 | } |
308 | 307 | if (static::ALIAS_ATTR && isset($allValues[0][static::ALIAS_ATTR])) |
309 | 308 | { |
310 | - foreach(self::getAttributePrefix($allValues[0][static::ALIAS_ATTR], static::ALIAS_PREFIX) as $value) |
|
309 | + foreach (self::getAttributePrefix($allValues[0][static::ALIAS_ATTR], static::ALIAS_PREFIX) as $value) |
|
311 | 310 | { |
312 | 311 | $emailAddresses[] = array( |
313 | 312 | 'name' => $realName, |
@@ -334,7 +333,7 @@ discard block |
||
334 | 333 | * @return array with values for keys 'mailLocalAddress', 'mailAlternateAddress' (array), 'mailForwardingAddress' (array), |
335 | 334 | * 'accountStatus' ("active"), 'quotaLimit' and 'deliveryMode' ("forwardOnly") |
336 | 335 | */ |
337 | - function getUserData($user, $match_uid_at_domain=false) |
|
336 | + function getUserData($user, $match_uid_at_domain = false) |
|
338 | 337 | { |
339 | 338 | $userData = array( |
340 | 339 | 'mailbox' => array(), |
@@ -394,7 +393,7 @@ discard block |
||
394 | 393 | $allValues = ldap_get_entries($ldap, $sri); |
395 | 394 | if ($this->debug) error_log(__METHOD__."('$user') --> ldap_search(, '$this->search_base', '$filter') --> ldap_get_entries=".array2string($allValues[0])); |
396 | 395 | |
397 | - foreach($allValues as $key => $values) |
|
396 | + foreach ($allValues as $key => $values) |
|
398 | 397 | { |
399 | 398 | if ($key === 'count') continue; |
400 | 399 | |
@@ -477,16 +476,16 @@ discard block |
||
477 | 476 | |
478 | 477 | if (static::FORWARD_ATTR) |
479 | 478 | { |
480 | - $userData['mailForwardingAddress'] = self::getAttributePrefix($values[static::FORWARD_ATTR], static::FORWARD_PREFIX); |
|
479 | + $userData['mailForwardingAddress'] = self::getAttributePrefix($values[static::FORWARD_ATTR], static::FORWARD_PREFIX); |
|
481 | 480 | } |
482 | 481 | |
483 | - if (static::MAILBOX_ATTR) $userData['mailMessageStore'] = $values[static::MAILBOX_ATTR][0]; |
|
482 | + if (static::MAILBOX_ATTR) $userData['mailMessageStore'] = $values[static::MAILBOX_ATTR][0]; |
|
484 | 483 | |
485 | 484 | $userData['deliveryMode'] = $deliveryMode; |
486 | 485 | |
487 | 486 | // eg. suse stores all email addresses as aliases |
488 | 487 | if (static::REQUIRE_MAIL_AS_ALIAS && |
489 | - ($k = array_search($userData['mailLocalAddress'],$userData['mailAlternateAddress'])) !== false) |
|
488 | + ($k = array_search($userData['mailLocalAddress'], $userData['mailAlternateAddress'])) !== false) |
|
490 | 489 | { |
491 | 490 | unset($userData['mailAlternateAddress'][$k]); |
492 | 491 | } |
@@ -519,9 +518,9 @@ discard block |
||
519 | 518 | * @return boolean true on success, false on error writing to ldap |
520 | 519 | */ |
521 | 520 | function setUserData($_uidnumber, array $_mailAlternateAddress, array $_mailForwardingAddress, $_deliveryMode, |
522 | - $_accountStatus, $_mailLocalAddress, $_quota, $_forwarding_only=false, $_setMailbox=null) |
|
521 | + $_accountStatus, $_mailLocalAddress, $_quota, $_forwarding_only = false, $_setMailbox = null) |
|
523 | 522 | { |
524 | - unset($_forwarding_only); // not used |
|
523 | + unset($_forwarding_only); // not used |
|
525 | 524 | |
526 | 525 | if (static::USERID_ATTR) |
527 | 526 | { |
@@ -541,15 +540,15 @@ discard block |
||
541 | 540 | $allValues = ldap_get_entries($ldap, $sri); |
542 | 541 | |
543 | 542 | $accountDN = $allValues[0]['dn']; |
544 | - $uid = $allValues[0][static::USER_ATTR][0]; |
|
545 | - $objectClasses = $allValues[0]['objectclass']; |
|
543 | + $uid = $allValues[0][static::USER_ATTR][0]; |
|
544 | + $objectClasses = $allValues[0]['objectclass']; |
|
546 | 545 | |
547 | 546 | unset($objectClasses['count']); |
548 | 547 | |
549 | - if(!in_array(static::SCHEMA,$objectClasses) && !in_array(strtolower(static::SCHEMA),$objectClasses)) |
|
548 | + if (!in_array(static::SCHEMA, $objectClasses) && !in_array(strtolower(static::SCHEMA), $objectClasses)) |
|
550 | 549 | { |
551 | - $objectClasses[] = static::SCHEMA; |
|
552 | - $newData['objectclass'] = $objectClasses; |
|
550 | + $objectClasses[] = static::SCHEMA; |
|
551 | + $newData['objectclass'] = $objectClasses; |
|
553 | 552 | } |
554 | 553 | |
555 | 554 | sort($_mailAlternateAddress); |
@@ -562,7 +561,7 @@ discard block |
||
562 | 561 | self::setAttributePrefix($newData[static::ALIAS_ATTR], $_mailAlternateAddress, static::ALIAS_PREFIX); |
563 | 562 | |
564 | 563 | // all email must be stored as alias for suse |
565 | - if (static::REQUIRE_MAIL_AS_ALIAS && !in_array($_mailLocalAddress,(array)$_mailAlternateAddress)) |
|
564 | + if (static::REQUIRE_MAIL_AS_ALIAS && !in_array($_mailLocalAddress, (array)$_mailAlternateAddress)) |
|
566 | 565 | { |
567 | 566 | self::setAttributePrefix($newData[static::ALIAS_ATTR], $_mailLocalAddress, static::ALIAS_PREFIX); |
568 | 567 | } |
@@ -595,12 +594,12 @@ discard block |
||
595 | 594 | if (static::QUOTA_ATTR) |
596 | 595 | { |
597 | 596 | self::setAttributePrefix($newData[static::QUOTA_ATTR], |
598 | - (int)$_quota > 0 ? (int)$_quota*static::QUOTA_FACTOR : array(), static::QUOTA_PREFIX); |
|
597 | + (int)$_quota > 0 ? (int)$_quota * static::QUOTA_FACTOR : array(), static::QUOTA_PREFIX); |
|
599 | 598 | } |
600 | 599 | // does schema support enabling/disabling mail via attribute |
601 | 600 | if (static::MAIL_ENABLE_ATTR) |
602 | 601 | { |
603 | - $newData[static::MAIL_ENABLE_ATTR] = $_accountStatus ? |
|
602 | + $newData[static::MAIL_ENABLE_ATTR] = $_accountStatus ? |
|
604 | 603 | (static::MAIL_ENABLED == self::MAIL_ENABLED_USE_MAIL ? $_mailLocalAddress : static::MAIL_ENABLED) : array(); |
605 | 604 | } |
606 | 605 | // if we have no mail-enabled attribute, but require primary mail in aliases-attr |
@@ -642,7 +641,7 @@ discard block |
||
642 | 641 | $uid = $GLOBALS['egw']->accounts->id2name($_accountID); |
643 | 642 | $filter = '(&'.static::USER_FILTER.'('.static::USER_ATTR.'='.Api\Ldap::quote($uid).'))'; |
644 | 643 | } |
645 | - $attributes = array('dn', static::FORWARD_ATTR, 'objectclass'); |
|
644 | + $attributes = array('dn', static::FORWARD_ATTR, 'objectclass'); |
|
646 | 645 | if (static::FORWARD_ONLY_ATTR) |
647 | 646 | { |
648 | 647 | $attributes[] = static::FORWARD_ONLY_ATTR; |
@@ -653,12 +652,12 @@ discard block |
||
653 | 652 | { |
654 | 653 | $newData = array(); |
655 | 654 | $allValues = ldap_get_entries($ds, $sri); |
656 | - $objectClasses = $allValues[0]['objectclass']; |
|
657 | - $newData['objectclass'] = $allValues[0]['objectclass']; |
|
655 | + $objectClasses = $allValues[0]['objectclass']; |
|
656 | + $newData['objectclass'] = $allValues[0]['objectclass']; |
|
658 | 657 | |
659 | 658 | unset($newData['objectclass']['count']); |
660 | 659 | |
661 | - if(!in_array(static::SCHEMA,$objectClasses)) |
|
660 | + if (!in_array(static::SCHEMA, $objectClasses)) |
|
662 | 661 | { |
663 | 662 | $newData['objectclass'][] = static::SCHEMA; |
664 | 663 | } |
@@ -668,9 +667,9 @@ discard block |
||
668 | 667 | $newData[static::FORWARD_ATTR] = $allValues[0][static::FORWARD_ATTR]; |
669 | 668 | $forwards = self::getAttributePrefix($newData[static::FORWARD_ATTR], static::FORWARD_PREFIX); |
670 | 669 | |
671 | - if(!empty($_forwardingAddress)) |
|
670 | + if (!empty($_forwardingAddress)) |
|
672 | 671 | { |
673 | - if($forwards) |
|
672 | + if ($forwards) |
|
674 | 673 | { |
675 | 674 | if (!is_array($_forwardingAddress)) |
676 | 675 | { |
@@ -702,7 +701,7 @@ discard block |
||
702 | 701 | } |
703 | 702 | if ($this->debug) error_log(__METHOD__.'('.array2string(func_get_args()).") --> ldap_mod_replace(,'{$allValues[0]['dn']}',".array2string($newData).')'); |
704 | 703 | |
705 | - return ldap_modify ($ds, $allValues[0]['dn'], $newData); |
|
704 | + return ldap_modify($ds, $allValues[0]['dn'], $newData); |
|
706 | 705 | } |
707 | 706 | } |
708 | 707 | |
@@ -744,9 +743,9 @@ discard block |
||
744 | 743 | unset($entries['count']); |
745 | 744 | |
746 | 745 | $mailboxes = array(); |
747 | - foreach($entries as $entry) |
|
746 | + foreach ($entries as $entry) |
|
748 | 747 | { |
749 | - if ($entry[static::USER_ATTR][0] == 'anonymous') continue; // anonymous is never a mail-user! |
|
748 | + if ($entry[static::USER_ATTR][0] == 'anonymous') continue; // anonymous is never a mail-user! |
|
750 | 749 | list($mailbox) = explode('@', $entry[static::MAILBOX_ATTR ? static::MAILBOX_ATTR : static::MAIL_ATTR][0]); |
751 | 750 | $mailboxes[$entry[static::USER_ATTR][0]] = $mailbox; |
752 | 751 | } |
@@ -760,13 +759,13 @@ discard block |
||
760 | 759 | * @param string|array $values value(s) to set |
761 | 760 | * @param string $prefix ='' prefix to use or '' |
762 | 761 | */ |
763 | - protected static function setAttributePrefix(&$attribute, $values, $prefix='') |
|
762 | + protected static function setAttributePrefix(&$attribute, $values, $prefix = '') |
|
764 | 763 | { |
765 | 764 | //$attribute_in = $attribute; |
766 | 765 | if (empty($attribute)) $attribute = array(); |
767 | 766 | if (!is_array($attribute)) $attribute = (array)$attribute; |
768 | 767 | |
769 | - foreach((array)$values as $value) |
|
768 | + foreach ((array)$values as $value) |
|
770 | 769 | { |
771 | 770 | $attribute[] = $prefix.$value; |
772 | 771 | } |
@@ -781,7 +780,7 @@ discard block |
||
781 | 780 | * @param boolean $remove =true remove returned values from $attribute |
782 | 781 | * @return array with values (prefix removed) or array() if nothing found |
783 | 782 | */ |
784 | - protected static function getAttributePrefix(&$attribute, $prefix='', $remove=true) |
|
783 | + protected static function getAttributePrefix(&$attribute, $prefix = '', $remove = true) |
|
785 | 784 | { |
786 | 785 | //$attribute_in = $attribute; |
787 | 786 | $values = array(); |
@@ -790,7 +789,7 @@ discard block |
||
790 | 789 | { |
791 | 790 | unset($attribute['count']); |
792 | 791 | |
793 | - foreach($attribute as $key => $value) |
|
792 | + foreach ($attribute as $key => $value) |
|
794 | 793 | { |
795 | 794 | if (!$prefix || stripos($value, $prefix) === 0) |
796 | 795 | { |
@@ -296,7 +296,10 @@ discard block |
||
296 | 296 | { |
297 | 297 | foreach($allValues[0][static::MAIL_ATTR] as $key => $value) |
298 | 298 | { |
299 | - if ($key === 'count') continue; |
|
299 | + if ($key === 'count') |
|
300 | + { |
|
301 | + continue; |
|
302 | + } |
|
300 | 303 | |
301 | 304 | $emailAddresses[] = array ( |
302 | 305 | 'name' => $realName, |
@@ -317,7 +320,10 @@ discard block |
||
317 | 320 | } |
318 | 321 | } |
319 | 322 | } |
320 | - if ($this->debug) error_log(__METHOD__."('$_accountName') returning ".array2string($emailAddresses)); |
|
323 | + if ($this->debug) |
|
324 | + { |
|
325 | + error_log(__METHOD__."('$_accountName') returning ".array2string($emailAddresses)); |
|
326 | + } |
|
321 | 327 | |
322 | 328 | return $emailAddresses; |
323 | 329 | } |
@@ -350,7 +356,10 @@ discard block |
||
350 | 356 | } |
351 | 357 | elseif (strpos($user, '@') === false) |
352 | 358 | { |
353 | - if (is_numeric($user)) $user = $GLOBALS['egw']->accounts->id2name($user); |
|
359 | + if (is_numeric($user)) |
|
360 | + { |
|
361 | + $user = $GLOBALS['egw']->accounts->id2name($user); |
|
362 | + } |
|
354 | 363 | $filter = '(&'.static::USER_FILTER.'('.static::USER_ATTR.'='.Api\Ldap::quote($user).'))'; |
355 | 364 | } |
356 | 365 | else // email address --> build filter by attributes defined in config |
@@ -367,7 +376,10 @@ discard block |
||
367 | 376 | else |
368 | 377 | { |
369 | 378 | $to_or = array('('.static::MAIL_ATTR.'='.Api\Ldap::quote($user).')'); |
370 | - if ($match_uid_at_domain) $to_or[] = '('.static::USER_ATTR.'='.Api\Ldap::quote($namepart).')'; |
|
379 | + if ($match_uid_at_domain) |
|
380 | + { |
|
381 | + $to_or[] = '('.static::USER_ATTR.'='.Api\Ldap::quote($namepart).')'; |
|
382 | + } |
|
371 | 383 | if (static::ALIAS_ATTR) |
372 | 384 | { |
373 | 385 | $to_or[] = '('.static::ALIAS_ATTR.'='.static::ALIAS_PREFIX.Api\Ldap::quote($user).')'; |
@@ -392,11 +404,17 @@ discard block |
||
392 | 404 | if ($sri) |
393 | 405 | { |
394 | 406 | $allValues = ldap_get_entries($ldap, $sri); |
395 | - if ($this->debug) error_log(__METHOD__."('$user') --> ldap_search(, '$this->search_base', '$filter') --> ldap_get_entries=".array2string($allValues[0])); |
|
407 | + if ($this->debug) |
|
408 | + { |
|
409 | + error_log(__METHOD__."('$user') --> ldap_search(, '$this->search_base', '$filter') --> ldap_get_entries=".array2string($allValues[0])); |
|
410 | + } |
|
396 | 411 | |
397 | 412 | foreach($allValues as $key => $values) |
398 | 413 | { |
399 | - if ($key === 'count') continue; |
|
414 | + if ($key === 'count') |
|
415 | + { |
|
416 | + continue; |
|
417 | + } |
|
400 | 418 | |
401 | 419 | // groups are always active (if they have an email) and allways forwardOnly |
402 | 420 | if (in_array(static::GROUP_SCHEMA, $values['objectclass'])) |
@@ -421,11 +439,14 @@ discard block |
||
421 | 439 | } |
422 | 440 | if (static::FORWARD_ONLY_ATTR) |
423 | 441 | { |
424 | - if (static::FORWARD_ONLY) // check caseinsensitiv for existence of that value |
|
442 | + if (static::FORWARD_ONLY) |
|
443 | + { |
|
444 | + // check caseinsensitiv for existence of that value |
|
425 | 445 | { |
426 | 446 | $deliveryMode = self::getAttributePrefix($values[static::FORWARD_ONLY_ATTR], static::FORWARD_ONLY) ? |
427 | 447 | Mail\Smtp::FORWARD_ONLY : ''; |
428 | 448 | } |
449 | + } |
|
429 | 450 | else // check for existence of any value |
430 | 451 | { |
431 | 452 | $deliveryMode = $values[static::FORWARD_ONLY_ATTR]['count'] > 0 ? |
@@ -458,7 +479,10 @@ discard block |
||
458 | 479 | } |
459 | 480 | |
460 | 481 | // regular user-data can only be from users, NOT groups |
461 | - if (in_array(static::GROUP_SCHEMA, $values['objectclass'])) continue; |
|
482 | + if (in_array(static::GROUP_SCHEMA, $values['objectclass'])) |
|
483 | + { |
|
484 | + continue; |
|
485 | + } |
|
462 | 486 | |
463 | 487 | $userData['mailLocalAddress'] = $values[static::MAIL_ATTR][0]; |
464 | 488 | $userData['accountStatus'] = $accountStatus; |
@@ -480,7 +504,10 @@ discard block |
||
480 | 504 | $userData['mailForwardingAddress'] = self::getAttributePrefix($values[static::FORWARD_ATTR], static::FORWARD_PREFIX); |
481 | 505 | } |
482 | 506 | |
483 | - if (static::MAILBOX_ATTR) $userData['mailMessageStore'] = $values[static::MAILBOX_ATTR][0]; |
|
507 | + if (static::MAILBOX_ATTR) |
|
508 | + { |
|
509 | + $userData['mailMessageStore'] = $values[static::MAILBOX_ATTR][0]; |
|
510 | + } |
|
484 | 511 | |
485 | 512 | $userData['deliveryMode'] = $deliveryMode; |
486 | 513 | |
@@ -499,7 +526,10 @@ discard block |
||
499 | 526 | } |
500 | 527 | } |
501 | 528 | } |
502 | - if ($this->debug) error_log(__METHOD__."('$user') returning ".array2string($userData)); |
|
529 | + if ($this->debug) |
|
530 | + { |
|
531 | + error_log(__METHOD__."('$user') returning ".array2string($userData)); |
|
532 | + } |
|
503 | 533 | |
504 | 534 | return $userData; |
505 | 535 | } |
@@ -617,7 +647,10 @@ discard block |
||
617 | 647 | |
618 | 648 | $this->addAccountExtra(array('location' => 'setUserData'), $allValues[0], $newData); |
619 | 649 | |
620 | - if ($this->debug) error_log(__METHOD__.'('.array2string(func_get_args()).") --> ldap_mod_replace(,'$accountDN',".array2string($newData).')'); |
|
650 | + if ($this->debug) |
|
651 | + { |
|
652 | + error_log(__METHOD__.'('.array2string(func_get_args()).") --> ldap_mod_replace(,'$accountDN',".array2string($newData).')'); |
|
653 | + } |
|
621 | 654 | |
622 | 655 | return ldap_mod_replace($ldap, $accountDN, $newData); |
623 | 656 | } |
@@ -700,7 +733,10 @@ discard block |
||
700 | 733 | // merge in again all new set forwards incl. opt. prefix |
701 | 734 | self::setAttributePrefix($newData[static::FORWARD_ATTR], $forwards, static::FORWARD_PREFIX); |
702 | 735 | } |
703 | - if ($this->debug) error_log(__METHOD__.'('.array2string(func_get_args()).") --> ldap_mod_replace(,'{$allValues[0]['dn']}',".array2string($newData).')'); |
|
736 | + if ($this->debug) |
|
737 | + { |
|
738 | + error_log(__METHOD__.'('.array2string(func_get_args()).") --> ldap_mod_replace(,'{$allValues[0]['dn']}',".array2string($newData).')'); |
|
739 | + } |
|
704 | 740 | |
705 | 741 | return ldap_modify ($ds, $allValues[0]['dn'], $newData); |
706 | 742 | } |
@@ -746,7 +782,11 @@ discard block |
||
746 | 782 | $mailboxes = array(); |
747 | 783 | foreach($entries as $entry) |
748 | 784 | { |
749 | - if ($entry[static::USER_ATTR][0] == 'anonymous') continue; // anonymous is never a mail-user! |
|
785 | + if ($entry[static::USER_ATTR][0] == 'anonymous') |
|
786 | + { |
|
787 | + continue; |
|
788 | + } |
|
789 | + // anonymous is never a mail-user! |
|
750 | 790 | list($mailbox) = explode('@', $entry[static::MAILBOX_ATTR ? static::MAILBOX_ATTR : static::MAIL_ATTR][0]); |
751 | 791 | $mailboxes[$entry[static::USER_ATTR][0]] = $mailbox; |
752 | 792 | } |
@@ -763,8 +803,14 @@ discard block |
||
763 | 803 | protected static function setAttributePrefix(&$attribute, $values, $prefix='') |
764 | 804 | { |
765 | 805 | //$attribute_in = $attribute; |
766 | - if (empty($attribute)) $attribute = array(); |
|
767 | - if (!is_array($attribute)) $attribute = (array)$attribute; |
|
806 | + if (empty($attribute)) |
|
807 | + { |
|
808 | + $attribute = array(); |
|
809 | + } |
|
810 | + if (!is_array($attribute)) |
|
811 | + { |
|
812 | + $attribute = (array)$attribute; |
|
813 | + } |
|
768 | 814 | |
769 | 815 | foreach((array)$values as $value) |
770 | 816 | { |
@@ -794,12 +840,18 @@ discard block |
||
794 | 840 | { |
795 | 841 | if (!$prefix || stripos($value, $prefix) === 0) |
796 | 842 | { |
797 | - if ($remove) unset($attribute[$key]); |
|
843 | + if ($remove) |
|
844 | + { |
|
845 | + unset($attribute[$key]); |
|
846 | + } |
|
798 | 847 | $values[] = substr($value, strlen($prefix)); |
799 | 848 | } |
800 | 849 | } |
801 | 850 | // reindex $attribute, if neccessary |
802 | - if ($values && $attribute) $attribute = array_values($attribute); |
|
851 | + if ($values && $attribute) |
|
852 | + { |
|
853 | + $attribute = array_values($attribute); |
|
854 | + } |
|
803 | 855 | } |
804 | 856 | //error_log(__METHOD__."(".array2string($attribute_in).", '$prefix', $remove) attribute=".array2string($attribute).' returning '.array2string($values)); |
805 | 857 | return $values; |
@@ -311,6 +311,7 @@ discard block |
||
311 | 311 | * Encrypt the variables in the session |
312 | 312 | * |
313 | 313 | * Is called by self::__destruct(). |
314 | + * @param string $kp3 |
|
314 | 315 | */ |
315 | 316 | static function encrypt($kp3) |
316 | 317 | { |
@@ -439,7 +440,7 @@ discard block |
||
439 | 440 | * @param boolean $no_session =false dont create a real session, eg. for GroupDAV clients using only basic auth, no cookie support |
440 | 441 | * @param boolean $auth_check =true if false, the user is loged in without checking his password (eg. for single sign on), default = true |
441 | 442 | * @param boolean $fail_on_forced_password_change =false true: do NOT create session, if password change requested |
442 | - * @return string|boolean session id or false if session was not created, $this->(cd_)reason contains cause |
|
443 | + * @return false|string session id or false if session was not created, $this->(cd_)reason contains cause |
|
443 | 444 | */ |
444 | 445 | function create($login,$passwd = '',$passwd_type = '',$no_session=false,$auth_check=true,$fail_on_forced_password_change=false) |
445 | 446 | { |
@@ -1021,7 +1022,7 @@ discard block |
||
1021 | 1022 | /** |
1022 | 1023 | * Terminate a session |
1023 | 1024 | * |
1024 | - * @param int|string $sessionid nummeric or php session id of session to be terminated |
|
1025 | + * @param string $sessionid nummeric or php session id of session to be terminated |
|
1025 | 1026 | * @param string $kp3 |
1026 | 1027 | * @return boolean true on success, false on error |
1027 | 1028 | */ |
@@ -80,60 +80,60 @@ discard block |
||
80 | 80 | const MCRYPT_MODE = MCRYPT_MODE_ECB; |
81 | 81 | |
82 | 82 | /** |
83 | - * current user login (account_lid@domain) |
|
84 | - * |
|
85 | - * @var string |
|
86 | - */ |
|
83 | + * current user login (account_lid@domain) |
|
84 | + * |
|
85 | + * @var string |
|
86 | + */ |
|
87 | 87 | var $login; |
88 | 88 | |
89 | 89 | /** |
90 | - * current user password |
|
91 | - * |
|
92 | - * @var string |
|
93 | - */ |
|
90 | + * current user password |
|
91 | + * |
|
92 | + * @var string |
|
93 | + */ |
|
94 | 94 | var $passwd; |
95 | 95 | |
96 | 96 | /** |
97 | - * current user db/ldap account id |
|
98 | - * |
|
99 | - * @var int |
|
100 | - */ |
|
97 | + * current user db/ldap account id |
|
98 | + * |
|
99 | + * @var int |
|
100 | + */ |
|
101 | 101 | var $account_id; |
102 | 102 | |
103 | 103 | /** |
104 | - * current user account login id (without the eGW-domain/-instance part |
|
105 | - * |
|
106 | - * @var string |
|
107 | - */ |
|
104 | + * current user account login id (without the eGW-domain/-instance part |
|
105 | + * |
|
106 | + * @var string |
|
107 | + */ |
|
108 | 108 | var $account_lid; |
109 | 109 | |
110 | 110 | /** |
111 | - * domain for current user |
|
112 | - * |
|
113 | - * @var string |
|
114 | - */ |
|
111 | + * domain for current user |
|
112 | + * |
|
113 | + * @var string |
|
114 | + */ |
|
115 | 115 | var $account_domain; |
116 | 116 | |
117 | 117 | /** |
118 | - * type flag, A - anonymous session, N - None, normal session |
|
119 | - * |
|
120 | - * @var string |
|
121 | - */ |
|
118 | + * type flag, A - anonymous session, N - None, normal session |
|
119 | + * |
|
120 | + * @var string |
|
121 | + */ |
|
122 | 122 | var $session_flags; |
123 | 123 | |
124 | 124 | /** |
125 | - * current user session id |
|
126 | - * |
|
127 | - * @var string |
|
128 | - */ |
|
125 | + * current user session id |
|
126 | + * |
|
127 | + * @var string |
|
128 | + */ |
|
129 | 129 | var $sessionid; |
130 | 130 | |
131 | 131 | /** |
132 | - * an other session specific id (md5 from a random string), |
|
133 | - * used together with the sessionid for xmlrpc basic auth and the encryption of session-data (if that's enabled) |
|
134 | - * |
|
135 | - * @var string |
|
136 | - */ |
|
132 | + * an other session specific id (md5 from a random string), |
|
133 | + * used together with the sessionid for xmlrpc basic auth and the encryption of session-data (if that's enabled) |
|
134 | + * |
|
135 | + * @var string |
|
136 | + */ |
|
137 | 137 | var $kp3; |
138 | 138 | |
139 | 139 | /** |
@@ -144,17 +144,17 @@ discard block |
||
144 | 144 | var $sessionid_access_log; |
145 | 145 | |
146 | 146 | /** |
147 | - * name of XML-RPC/SOAP method called |
|
148 | - * |
|
149 | - * @var string |
|
150 | - */ |
|
147 | + * name of XML-RPC/SOAP method called |
|
148 | + * |
|
149 | + * @var string |
|
150 | + */ |
|
151 | 151 | var $xmlrpc_method_called; |
152 | 152 | |
153 | 153 | /** |
154 | - * Array with the name of the system domains |
|
155 | - * |
|
156 | - * @var array |
|
157 | - */ |
|
154 | + * Array with the name of the system domains |
|
155 | + * |
|
156 | + * @var array |
|
157 | + */ |
|
158 | 158 | private $egw_domains; |
159 | 159 | |
160 | 160 | /** |
@@ -248,9 +248,9 @@ discard block |
||
248 | 248 | |
249 | 249 | // set session_timeout from global php.ini and default to 14400=4h, if not set |
250 | 250 | if (!($GLOBALS['egw_info']['server']['sessions_timeout'] = ini_get('session.gc_maxlifetime'))) |
251 | - { |
|
252 | - ini_set('session.gc_maxlifetime', $GLOBALS['egw_info']['server']['sessions_timeout']=14400); |
|
253 | - } |
|
251 | + { |
|
252 | + ini_set('session.gc_maxlifetime', $GLOBALS['egw_info']['server']['sessions_timeout']=14400); |
|
253 | + } |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | /** |
@@ -661,14 +661,14 @@ discard block |
||
661 | 661 | const ACCESS_LOG_TABLE = 'egw_access_log'; |
662 | 662 | |
663 | 663 | /** |
664 | - * Write or update (for logout) the access_log |
|
665 | - * |
|
666 | - * @param string|int $sessionid nummeric or PHP session id or 0 for unsuccessful logins |
|
667 | - * @param string $login ='' account_lid (evtl. with domain) or '' for setting the logout-time |
|
668 | - * @param string $user_ip ='' ip to log |
|
669 | - * @param int $account_id =0 numerical account_id |
|
670 | - * @return int $sessionid primary key of egw_access_log for login, null otherwise |
|
671 | - */ |
|
664 | + * Write or update (for logout) the access_log |
|
665 | + * |
|
666 | + * @param string|int $sessionid nummeric or PHP session id or 0 for unsuccessful logins |
|
667 | + * @param string $login ='' account_lid (evtl. with domain) or '' for setting the logout-time |
|
668 | + * @param string $user_ip ='' ip to log |
|
669 | + * @param int $account_id =0 numerical account_id |
|
670 | + * @return int $sessionid primary key of egw_access_log for login, null otherwise |
|
671 | + */ |
|
672 | 672 | private function log_access($sessionid,$login='',$user_ip='',$account_id=0) |
673 | 673 | { |
674 | 674 | $now = time(); |
@@ -716,7 +716,7 @@ discard block |
||
716 | 716 | |
717 | 717 | /** |
718 | 718 | * Protect against brute force attacks, block login if too many unsuccessful login attmepts |
719 | - * |
|
719 | + * |
|
720 | 720 | * @param string $login account_lid (evtl. with domain) |
721 | 721 | * @param string $ip ip of the user |
722 | 722 | * @returns bool login blocked? |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | const CD_BAD_LOGIN_OR_PASSWORD = 5; |
174 | 174 | const CD_FORCE_PASSWORD_CHANGE = 97; |
175 | 175 | const CD_ACCOUNT_EXPIRED = 98; |
176 | - const CD_BLOCKED = 99; // to many failed attempts to loing |
|
176 | + const CD_BLOCKED = 99; // to many failed attempts to loing |
|
177 | 177 | |
178 | 178 | /** |
179 | 179 | * Verbose reason why session creation failed |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | * |
195 | 195 | * @param array $domain_names =null domain-names used in this install |
196 | 196 | */ |
197 | - function __construct(array $domain_names=null) |
|
197 | + function __construct(array $domain_names = null) |
|
198 | 198 | { |
199 | 199 | $this->required_files = $_SESSION[self::EGW_REQUIRED_FILES]; |
200 | 200 | |
@@ -210,27 +210,27 @@ discard block |
||
210 | 210 | $save_rep = false; |
211 | 211 | if (!isset($GLOBALS['egw_info']['server']['max_access_log_age'])) |
212 | 212 | { |
213 | - $GLOBALS['egw_info']['server']['max_access_log_age'] = 90; // default 90 days |
|
213 | + $GLOBALS['egw_info']['server']['max_access_log_age'] = 90; // default 90 days |
|
214 | 214 | $save_rep = true; |
215 | 215 | } |
216 | 216 | if (!isset($GLOBALS['egw_info']['server']['block_time'])) |
217 | 217 | { |
218 | - $GLOBALS['egw_info']['server']['block_time'] = 1; // default 1min, its enough to slow down brute force attacks |
|
218 | + $GLOBALS['egw_info']['server']['block_time'] = 1; // default 1min, its enough to slow down brute force attacks |
|
219 | 219 | $save_rep = true; |
220 | 220 | } |
221 | 221 | if (!isset($GLOBALS['egw_info']['server']['num_unsuccessful_id'])) |
222 | 222 | { |
223 | - $GLOBALS['egw_info']['server']['num_unsuccessful_id'] = 3; // default 3 trys per id |
|
223 | + $GLOBALS['egw_info']['server']['num_unsuccessful_id'] = 3; // default 3 trys per id |
|
224 | 224 | $save_rep = true; |
225 | 225 | } |
226 | 226 | if (!isset($GLOBALS['egw_info']['server']['num_unsuccessful_ip'])) |
227 | 227 | { |
228 | - $GLOBALS['egw_info']['server']['num_unsuccessful_ip'] = $GLOBALS['egw_info']['server']['num_unsuccessful_id'] * 5; // default is 5 times as high as the id default; since accessing via proxy is quite common |
|
228 | + $GLOBALS['egw_info']['server']['num_unsuccessful_ip'] = $GLOBALS['egw_info']['server']['num_unsuccessful_id'] * 5; // default is 5 times as high as the id default; since accessing via proxy is quite common |
|
229 | 229 | $save_rep = true; |
230 | 230 | } |
231 | 231 | if (!isset($GLOBALS['egw_info']['server']['install_id'])) |
232 | 232 | { |
233 | - $GLOBALS['egw_info']['server']['install_id'] = md5(Auth::randomstring(15)); |
|
233 | + $GLOBALS['egw_info']['server']['install_id'] = md5(Auth::randomstring(15)); |
|
234 | 234 | } |
235 | 235 | if (!isset($GLOBALS['egw_info']['server']['max_history'])) |
236 | 236 | { |
@@ -242,12 +242,12 @@ discard block |
||
242 | 242 | { |
243 | 243 | $config = new Config('phpgwapi'); |
244 | 244 | $config->read_repository(); |
245 | - $config->value('max_access_log_age',$GLOBALS['egw_info']['server']['max_access_log_age']); |
|
246 | - $config->value('block_time',$GLOBALS['egw_info']['server']['block_time']); |
|
247 | - $config->value('num_unsuccessful_id',$GLOBALS['egw_info']['server']['num_unsuccessful_id']); |
|
248 | - $config->value('num_unsuccessful_ip',$GLOBALS['egw_info']['server']['num_unsuccessful_ip']); |
|
249 | - $config->value('install_id',$GLOBALS['egw_info']['server']['install_id']); |
|
250 | - $config->value('max_history',$GLOBALS['egw_info']['server']['max_history']); |
|
245 | + $config->value('max_access_log_age', $GLOBALS['egw_info']['server']['max_access_log_age']); |
|
246 | + $config->value('block_time', $GLOBALS['egw_info']['server']['block_time']); |
|
247 | + $config->value('num_unsuccessful_id', $GLOBALS['egw_info']['server']['num_unsuccessful_id']); |
|
248 | + $config->value('num_unsuccessful_ip', $GLOBALS['egw_info']['server']['num_unsuccessful_ip']); |
|
249 | + $config->value('install_id', $GLOBALS['egw_info']['server']['install_id']); |
|
250 | + $config->value('max_history', $GLOBALS['egw_info']['server']['max_history']); |
|
251 | 251 | $config->save_repository(); |
252 | 252 | } |
253 | 253 | } |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | // set session_timeout from global php.ini and default to 14400=4h, if not set |
257 | 257 | if (!($GLOBALS['egw_info']['server']['sessions_timeout'] = ini_get('session.gc_maxlifetime'))) |
258 | 258 | { |
259 | - ini_set('session.gc_maxlifetime', $GLOBALS['egw_info']['server']['sessions_timeout']=14400); |
|
259 | + ini_set('session.gc_maxlifetime', $GLOBALS['egw_info']['server']['sessions_timeout'] = 14400); |
|
260 | 260 | } |
261 | 261 | } |
262 | 262 | |
@@ -329,15 +329,15 @@ discard block |
||
329 | 329 | |
330 | 330 | if (!isset($_SESSION[self::EGW_SESSION_ENCRYPTED]) && self::init_crypt($kp3)) |
331 | 331 | { |
332 | - foreach(self::$egw_session_vars as $name) |
|
332 | + foreach (self::$egw_session_vars as $name) |
|
333 | 333 | { |
334 | 334 | if (isset($_SESSION[$name])) |
335 | 335 | { |
336 | - $_SESSION[$name] = mcrypt_generic(self::$mcrypt,serialize($_SESSION[$name])); |
|
336 | + $_SESSION[$name] = mcrypt_generic(self::$mcrypt, serialize($_SESSION[$name])); |
|
337 | 337 | //error_log(__METHOD__."() 'encrypting' session var: $name, len=".strlen($_SESSION[$name])); |
338 | 338 | } |
339 | 339 | } |
340 | - $_SESSION[self::EGW_SESSION_ENCRYPTED] = true; // flag session as encrypted |
|
340 | + $_SESSION[self::EGW_SESSION_ENCRYPTED] = true; // flag session as encrypted |
|
341 | 341 | |
342 | 342 | mcrypt_generic_deinit(self::$mcrypt); |
343 | 343 | self::$mcrypt = null; |
@@ -352,24 +352,24 @@ discard block |
||
352 | 352 | * @param boolean $recursion =true if true call itself for every item > $limit |
353 | 353 | * @param int $limit =1000 log only differences > $limit |
354 | 354 | */ |
355 | - static function log_session_usage(&$arr,$label,$recursion=true,$limit=1000) |
|
355 | + static function log_session_usage(&$arr, $label, $recursion = true, $limit = 1000) |
|
356 | 356 | { |
357 | 357 | if (!is_array($arr)) return; |
358 | 358 | |
359 | 359 | $sizes = array(); |
360 | - foreach($arr as $key => &$data) |
|
360 | + foreach ($arr as $key => &$data) |
|
361 | 361 | { |
362 | 362 | $sizes[$key] = strlen(serialize($data)); |
363 | 363 | } |
364 | - arsort($sizes,SORT_NUMERIC); |
|
365 | - foreach($sizes as $key => $size) |
|
364 | + arsort($sizes, SORT_NUMERIC); |
|
365 | + foreach ($sizes as $key => $size) |
|
366 | 366 | { |
367 | 367 | $diff = $size - (int)$_SESSION[$label.'-sizes'][$key]; |
368 | 368 | $_SESSION[$label.'-sizes'][$key] = $size; |
369 | 369 | if ($diff > $limit) |
370 | 370 | { |
371 | 371 | error_log("strlen({$label}[$key])=".Vfs::hsize($size).", diff=".Vfs::hsize($diff)); |
372 | - if ($recursion) self::log_session_usage($arr[$key],$label.'['.$key.']',$recursion,$limit); |
|
372 | + if ($recursion) self::log_session_usage($arr[$key], $label.'['.$key.']', $recursion, $limit); |
|
373 | 373 | } |
374 | 374 | } |
375 | 375 | } |
@@ -384,15 +384,15 @@ discard block |
||
384 | 384 | { |
385 | 385 | if ($_SESSION[self::EGW_SESSION_ENCRYPTED] && self::init_crypt(self::get_request('kp3'))) |
386 | 386 | { |
387 | - foreach(self::$egw_session_vars as $name) |
|
387 | + foreach (self::$egw_session_vars as $name) |
|
388 | 388 | { |
389 | 389 | if (isset($_SESSION[$name])) |
390 | 390 | { |
391 | - $_SESSION[$name] = unserialize(trim(mdecrypt_generic(self::$mcrypt,$_SESSION[$name]))); |
|
391 | + $_SESSION[$name] = unserialize(trim(mdecrypt_generic(self::$mcrypt, $_SESSION[$name]))); |
|
392 | 392 | //error_log(__METHOD__."() 'decrypting' session var $name: gettype($name) = ".gettype($_SESSION[$name])); |
393 | 393 | } |
394 | 394 | } |
395 | - unset($_SESSION[self::EGW_SESSION_ENCRYPTED]); // delete encryption flag |
|
395 | + unset($_SESSION[self::EGW_SESSION_ENCRYPTED]); // delete encryption flag |
|
396 | 396 | } |
397 | 397 | } |
398 | 398 | |
@@ -405,15 +405,15 @@ discard block |
||
405 | 405 | * @param string $mode =self::MCRYPT_MODE |
406 | 406 | * @return boolean true if encryption is used, false otherwise |
407 | 407 | */ |
408 | - static private function init_crypt($kp3,$algo=self::MCRYPT_ALGO,$mode=self::MCRYPT_MODE) |
|
408 | + static private function init_crypt($kp3, $algo = self::MCRYPT_ALGO, $mode = self::MCRYPT_MODE) |
|
409 | 409 | { |
410 | - if(!$GLOBALS['egw_info']['server']['mcrypt_enabled']) |
|
410 | + if (!$GLOBALS['egw_info']['server']['mcrypt_enabled']) |
|
411 | 411 | { |
412 | - return false; // session encryption is switched off |
|
412 | + return false; // session encryption is switched off |
|
413 | 413 | } |
414 | 414 | if ($GLOBALS['egw_info']['currentapp'] == 'syncml' || !$kp3) |
415 | 415 | { |
416 | - $kp3 = 'staticsyncmlkp3'; // syncml has no kp3! |
|
416 | + $kp3 = 'staticsyncmlkp3'; // syncml has no kp3! |
|
417 | 417 | } |
418 | 418 | if (is_null(self::$mcrypt)) |
419 | 419 | { |
@@ -429,9 +429,9 @@ discard block |
||
429 | 429 | } |
430 | 430 | $iv_size = mcrypt_enc_get_iv_size(self::$mcrypt); |
431 | 431 | $iv = !isset($GLOBALS['egw_info']['server']['mcrypt_iv']) || strlen($GLOBALS['egw_info']['server']['mcrypt_iv']) < $iv_size ? |
432 | - mcrypt_create_iv ($iv_size, MCRYPT_RAND) : substr($GLOBALS['egw_info']['server']['mcrypt_iv'],0,$iv_size); |
|
432 | + mcrypt_create_iv($iv_size, MCRYPT_RAND) : substr($GLOBALS['egw_info']['server']['mcrypt_iv'], 0, $iv_size); |
|
433 | 433 | |
434 | - if (mcrypt_generic_init(self::$mcrypt,$kp3, $iv) < 0) |
|
434 | + if (mcrypt_generic_init(self::$mcrypt, $kp3, $iv) < 0) |
|
435 | 435 | { |
436 | 436 | error_log(__METHOD__."() could not initialise mcrypt, sessions get NOT encrypted!"); |
437 | 437 | return self::$mcrypt = false; |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | * @param boolean $fail_on_forced_password_change =false true: do NOT create session, if password change requested |
452 | 452 | * @return string|boolean session id or false if session was not created, $this->(cd_)reason contains cause |
453 | 453 | */ |
454 | - function create($login,$passwd = '',$passwd_type = '',$no_session=false,$auth_check=true,$fail_on_forced_password_change=false) |
|
454 | + function create($login, $passwd = '', $passwd_type = '', $no_session = false, $auth_check = true, $fail_on_forced_password_change = false) |
|
455 | 455 | { |
456 | 456 | try { |
457 | 457 | if (is_array($login)) |
@@ -469,9 +469,9 @@ discard block |
||
469 | 469 | } |
470 | 470 | if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) starting ..."); |
471 | 471 | |
472 | - self::split_login_domain($login,$this->account_lid,$this->account_domain); |
|
472 | + self::split_login_domain($login, $this->account_lid, $this->account_domain); |
|
473 | 473 | // add domain to the login, if not already there |
474 | - if (substr($this->login,-strlen($this->account_domain)-1) != '@'.$this->account_domain) |
|
474 | + if (substr($this->login, -strlen($this->account_domain) - 1) != '@'.$this->account_domain) |
|
475 | 475 | { |
476 | 476 | $this->login .= '@'.$this->account_domain; |
477 | 477 | } |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | { |
489 | 489 | $this->account_domain = $GLOBALS['egw_info']['user']['domain']; |
490 | 490 | } |
491 | - elseif($this->account_domain != $GLOBALS['egw_info']['user']['domain']) |
|
491 | + elseif ($this->account_domain != $GLOBALS['egw_info']['user']['domain']) |
|
492 | 492 | { |
493 | 493 | throw new Exception("Wrong domain! '$this->account_domain' != '{$GLOBALS['egw_info']['user']['domain']}'"); |
494 | 494 | } |
@@ -496,9 +496,9 @@ discard block |
||
496 | 496 | |
497 | 497 | $user_ip = self::getuser_ip(); |
498 | 498 | |
499 | - $this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid,'account_lid','u'); |
|
499 | + $this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid, 'account_lid', 'u'); |
|
500 | 500 | |
501 | - if (($blocked = $this->login_blocked($login,$user_ip)) || // too many unsuccessful attempts |
|
501 | + if (($blocked = $this->login_blocked($login, $user_ip)) || // too many unsuccessful attempts |
|
502 | 502 | $GLOBALS['egw_info']['server']['global_denied_users'][$this->account_lid] || |
503 | 503 | $auth_check && !$GLOBALS['egw']->auth->authenticate($this->account_lid, $this->passwd, $this->passwd_type) || |
504 | 504 | $this->account_id && $GLOBALS['egw']->accounts->get_type($this->account_id) == 'g') |
@@ -507,9 +507,9 @@ discard block |
||
507 | 507 | $this->cd_reason = $blocked ? self::CD_BLOCKED : self::CD_BAD_LOGIN_OR_PASSWORD; |
508 | 508 | |
509 | 509 | // we dont log anon users as it would block the website |
510 | - if (!$GLOBALS['egw']->acl->get_specific_rights_for_account($this->account_id,'anonymous','phpgwapi')) |
|
510 | + if (!$GLOBALS['egw']->acl->get_specific_rights_for_account($this->account_id, 'anonymous', 'phpgwapi')) |
|
511 | 511 | { |
512 | - $this->log_access($this->reason,$login,$user_ip,0); // log unsuccessfull login |
|
512 | + $this->log_access($this->reason, $login, $user_ip, 0); // log unsuccessfull login |
|
513 | 513 | } |
514 | 514 | if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)"); |
515 | 515 | return false; |
@@ -531,7 +531,7 @@ discard block |
||
531 | 531 | if ($this->account_lid != ($lid = $GLOBALS['egw']->accounts->id2name($this->account_id))) |
532 | 532 | { |
533 | 533 | $this->account_lid = $lid; |
534 | - $this->login = $lid.substr($this->login,strlen($lid)); |
|
534 | + $this->login = $lid.substr($this->login, strlen($lid)); |
|
535 | 535 | } |
536 | 536 | |
537 | 537 | $GLOBALS['egw_info']['user']['account_id'] = $this->account_id; |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | } |
554 | 554 | $this->sessionid = session_id(); |
555 | 555 | } |
556 | - $this->kp3 = Auth::randomstring(24); |
|
556 | + $this->kp3 = Auth::randomstring(24); |
|
557 | 557 | |
558 | 558 | $GLOBALS['egw_info']['user'] = $this->read_repositories(); |
559 | 559 | if ($GLOBALS['egw']->accounts->is_expired($GLOBALS['egw_info']['user'])) |
@@ -567,7 +567,7 @@ discard block |
||
567 | 567 | |
568 | 568 | Cache::setSession('phpgwapi', 'password', base64_encode($this->passwd)); |
569 | 569 | |
570 | - if ($GLOBALS['egw']->acl->check('anonymous',1,'phpgwapi')) |
|
570 | + if ($GLOBALS['egw']->acl->check('anonymous', 1, 'phpgwapi')) |
|
571 | 571 | { |
572 | 572 | $this->session_flags = 'A'; |
573 | 573 | } |
@@ -585,46 +585,46 @@ discard block |
||
585 | 585 | 'passwd' => $this->passwd, |
586 | 586 | 'account_domain' => $this->account_domain, |
587 | 587 | 'user_ip' => $user_ip, |
588 | - ),'',true))) // true = run hooks from all apps, not just the ones the current user has perms to run |
|
588 | + ), '', true))) // true = run hooks from all apps, not just the ones the current user has perms to run |
|
589 | 589 | { |
590 | - foreach($hook_result as $reason) |
|
590 | + foreach ($hook_result as $reason) |
|
591 | 591 | { |
592 | 592 | if ($reason) // called hook requests to deny the session |
593 | 593 | { |
594 | 594 | $this->reason = $this->cd_reason = $reason; |
595 | - $this->log_access($this->reason,$login,$user_ip,0); // log unsuccessfull login |
|
595 | + $this->log_access($this->reason, $login, $user_ip, 0); // log unsuccessfull login |
|
596 | 596 | if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)"); |
597 | 597 | return false; |
598 | 598 | } |
599 | 599 | } |
600 | 600 | } |
601 | 601 | $GLOBALS['egw']->db->transaction_begin(); |
602 | - $this->register_session($this->login,$user_ip,$now,$this->session_flags); |
|
602 | + $this->register_session($this->login, $user_ip, $now, $this->session_flags); |
|
603 | 603 | if ($this->session_flags != 'A') // dont log anonymous sessions |
604 | 604 | { |
605 | - $this->sessionid_access_log = $this->log_access($this->sessionid,$login,$user_ip,$this->account_id); |
|
605 | + $this->sessionid_access_log = $this->log_access($this->sessionid, $login, $user_ip, $this->account_id); |
|
606 | 606 | } |
607 | 607 | Cache::setSession('phpgwapi', 'account_previous_login', $GLOBALS['egw']->auth->previous_login); |
608 | - $GLOBALS['egw']->accounts->update_lastlogin($this->account_id,$user_ip); |
|
608 | + $GLOBALS['egw']->accounts->update_lastlogin($this->account_id, $user_ip); |
|
609 | 609 | $GLOBALS['egw']->db->transaction_commit(); |
610 | 610 | |
611 | 611 | if ($GLOBALS['egw_info']['server']['usecookies'] && !$no_session) |
612 | 612 | { |
613 | - self::egw_setcookie(self::EGW_SESSION_NAME,$this->sessionid); |
|
614 | - self::egw_setcookie('kp3',$this->kp3); |
|
615 | - self::egw_setcookie('domain',$this->account_domain); |
|
613 | + self::egw_setcookie(self::EGW_SESSION_NAME, $this->sessionid); |
|
614 | + self::egw_setcookie('kp3', $this->kp3); |
|
615 | + self::egw_setcookie('domain', $this->account_domain); |
|
616 | 616 | } |
617 | 617 | if ($GLOBALS['egw_info']['server']['usecookies'] && !$no_session || isset($_COOKIE['last_loginid'])) |
618 | 618 | { |
619 | - self::egw_setcookie('last_loginid', $this->account_lid ,$now+1209600); /* For 2 weeks */ |
|
620 | - self::egw_setcookie('last_domain',$this->account_domain,$now+1209600); |
|
619 | + self::egw_setcookie('last_loginid', $this->account_lid, $now + 1209600); /* For 2 weeks */ |
|
620 | + self::egw_setcookie('last_domain', $this->account_domain, $now + 1209600); |
|
621 | 621 | } |
622 | 622 | if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) successfull sessionid=$this->sessionid"); |
623 | 623 | |
624 | 624 | return $this->sessionid; |
625 | 625 | } |
626 | 626 | // catch all exceptions, as their (allways logged) trace (eg. on a database error) would contain the user password |
627 | - catch(Exception $e) { |
|
627 | + catch (Exception $e) { |
|
628 | 628 | $this->reason = $this->cd_reason = $e->getMessage(); |
629 | 629 | error_log(__METHOD__."('$login', ".array2string(str_repeat('*', strlen($passwd))). |
630 | 630 | ", '$passwd_type', no_session=".array2string($no_session). |
@@ -643,13 +643,12 @@ discard block |
||
643 | 643 | * @param int $now |
644 | 644 | * @param string $session_flags |
645 | 645 | */ |
646 | - private function register_session($login,$user_ip,$now,$session_flags) |
|
646 | + private function register_session($login, $user_ip, $now, $session_flags) |
|
647 | 647 | { |
648 | 648 | // restore session vars set before session was started |
649 | 649 | if (is_array($this->required_files)) |
650 | 650 | { |
651 | - $_SESSION[self::EGW_REQUIRED_FILES] = !is_array($_SESSION[self::EGW_REQUIRED_FILES]) ? $this->required_files : |
|
652 | - array_unique(array_merge($_SESSION[self::EGW_REQUIRED_FILES],$this->required_files)); |
|
651 | + $_SESSION[self::EGW_REQUIRED_FILES] = !is_array($_SESSION[self::EGW_REQUIRED_FILES]) ? $this->required_files : array_unique(array_merge($_SESSION[self::EGW_REQUIRED_FILES], $this->required_files)); |
|
653 | 652 | unset($this->required_files); |
654 | 653 | } |
655 | 654 | $_SESSION[self::EGW_SESSION_VAR] = array( |
@@ -679,13 +678,13 @@ discard block |
||
679 | 678 | * @param int $account_id =0 numerical account_id |
680 | 679 | * @return int $sessionid primary key of egw_access_log for login, null otherwise |
681 | 680 | */ |
682 | - private function log_access($sessionid,$login='',$user_ip='',$account_id=0) |
|
681 | + private function log_access($sessionid, $login = '', $user_ip = '', $account_id = 0) |
|
683 | 682 | { |
684 | 683 | $now = time(); |
685 | 684 | |
686 | 685 | if ($login) |
687 | 686 | { |
688 | - $GLOBALS['egw']->db->insert(self::ACCESS_LOG_TABLE,array( |
|
687 | + $GLOBALS['egw']->db->insert(self::ACCESS_LOG_TABLE, array( |
|
689 | 688 | 'session_php' => $sessionid, |
690 | 689 | 'loginid' => $login, |
691 | 690 | 'ip' => $user_ip, |
@@ -693,10 +692,10 @@ discard block |
||
693 | 692 | 'account_id'=> $account_id, |
694 | 693 | 'user_agent'=> $_SERVER['HTTP_USER_AGENT'], |
695 | 694 | 'session_dla' => $now, |
696 | - 'session_action' => $this->update_dla(false), // dont update egw_access_log |
|
697 | - ),false,__LINE__,__FILE__); |
|
695 | + 'session_action' => $this->update_dla(false), // dont update egw_access_log |
|
696 | + ), false, __LINE__, __FILE__); |
|
698 | 697 | |
699 | - $ret = $GLOBALS['egw']->db->get_last_insert_id(self::ACCESS_LOG_TABLE,'sessionid'); |
|
698 | + $ret = $GLOBALS['egw']->db->get_last_insert_id(self::ACCESS_LOG_TABLE, 'sessionid'); |
|
700 | 699 | } |
701 | 700 | else |
702 | 701 | { |
@@ -704,20 +703,20 @@ discard block |
||
704 | 703 | { |
705 | 704 | $sessionid = $this->sessionid_access_log; |
706 | 705 | } |
707 | - $GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE,array( |
|
706 | + $GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE, array( |
|
708 | 707 | 'lo' => $now |
709 | - ),is_numeric($sessionid) ? array( |
|
708 | + ), is_numeric($sessionid) ? array( |
|
710 | 709 | 'sessionid' => $sessionid, |
711 | 710 | ) : array( |
712 | 711 | 'session_php' => $sessionid, |
713 | - ),__LINE__,__FILE__); |
|
712 | + ), __LINE__, __FILE__); |
|
714 | 713 | |
715 | 714 | // run maintenance only on logout, to not delay login |
716 | 715 | if ($GLOBALS['egw_info']['server']['max_access_log_age']) |
717 | 716 | { |
718 | 717 | $max_age = $now - $GLOBALS['egw_info']['server']['max_access_log_age'] * 24 * 60 * 60; |
719 | 718 | |
720 | - $GLOBALS['egw']->db->delete(self::ACCESS_LOG_TABLE,"li < $max_age",__LINE__,__FILE__); |
|
719 | + $GLOBALS['egw']->db->delete(self::ACCESS_LOG_TABLE, "li < $max_age", __LINE__, __FILE__); |
|
721 | 720 | } |
722 | 721 | } |
723 | 722 | //error_log(__METHOD__."('$sessionid', '$login', '$user_ip', $account_id) returning ".array2string($ret)); |
@@ -731,12 +730,12 @@ discard block |
||
731 | 730 | * @param string $ip ip of the user |
732 | 731 | * @returns bool login blocked? |
733 | 732 | */ |
734 | - private function login_blocked($login,$ip) |
|
733 | + private function login_blocked($login, $ip) |
|
735 | 734 | { |
736 | 735 | $block_time = time() - $GLOBALS['egw_info']['server']['block_time'] * 60; |
737 | 736 | |
738 | 737 | $false_id = $false_ip = 0; |
739 | - foreach($GLOBALS['egw']->db->union(array( |
|
738 | + foreach ($GLOBALS['egw']->db->union(array( |
|
740 | 739 | array( |
741 | 740 | 'table' => self::ACCESS_LOG_TABLE, |
742 | 741 | 'cols' => "'false_ip' AS name,COUNT(*) AS num", |
@@ -773,28 +772,28 @@ discard block |
||
773 | 772 | //error_log(__METHOD__."('$login', '$ip') false_ip=$false_ip, false_id=$false_id --> blocked=".array2string($blocked)); |
774 | 773 | |
775 | 774 | if ($blocked && $GLOBALS['egw_info']['server']['admin_mails'] && |
776 | - $GLOBALS['egw_info']['server']['login_blocked_mail_time'] < time()-5*60) // max. one mail every 5mins |
|
775 | + $GLOBALS['egw_info']['server']['login_blocked_mail_time'] < time() - 5 * 60) // max. one mail every 5mins |
|
777 | 776 | { |
778 | 777 | try { |
779 | 778 | $mailer = new Mailer(); |
780 | 779 | // notify admin(s) via email |
781 | 780 | $mailer->setFrom('eGroupWare@'.$GLOBALS['egw_info']['server']['mail_suffix']); |
782 | - $mailer->addHeader('Subject', lang("eGroupWare: login blocked for user '%1', IP %2",$login,$ip)); |
|
783 | - $mailer->setBody(lang("Too many unsucessful attempts to login: %1 for the user '%2', %3 for the IP %4",$false_id,$login,$false_ip,$ip)); |
|
784 | - foreach(preg_split('/,\s*/',$GLOBALS['egw_info']['server']['admin_mails']) as $mail) |
|
781 | + $mailer->addHeader('Subject', lang("eGroupWare: login blocked for user '%1', IP %2", $login, $ip)); |
|
782 | + $mailer->setBody(lang("Too many unsucessful attempts to login: %1 for the user '%2', %3 for the IP %4", $false_id, $login, $false_ip, $ip)); |
|
783 | + foreach (preg_split('/,\s*/', $GLOBALS['egw_info']['server']['admin_mails']) as $mail) |
|
785 | 784 | { |
786 | 785 | $mailer->addAddress($mail); |
787 | 786 | } |
788 | 787 | $mailer->send(); |
789 | 788 | } |
790 | - catch(Exception $e) { |
|
789 | + catch (Exception $e) { |
|
791 | 790 | // ignore exception, but log it, to block the account and give a correct error-message to user |
792 | 791 | error_log(__METHOD__."('$login', '$ip') ".$e->getMessage()); |
793 | 792 | } |
794 | 793 | // save time of mail, to not send to many mails |
795 | 794 | $config = new Config('phpgwapi'); |
796 | 795 | $config->read_repository(); |
797 | - $config->value('login_blocked_mail_time',time()); |
|
796 | + $config->value('login_blocked_mail_time', time()); |
|
798 | 797 | $config->save_repository(); |
799 | 798 | } |
800 | 799 | return $blocked; |
@@ -815,7 +814,7 @@ discard block |
||
815 | 814 | * @param boolean $only_basic_auth =false return only a basic auth pseudo sessionid, default no |
816 | 815 | * @return string |
817 | 816 | */ |
818 | - static function get_sessionid($only_basic_auth=false) |
|
817 | + static function get_sessionid($only_basic_auth = false) |
|
819 | 818 | { |
820 | 819 | // for WebDAV and GroupDAV we use a pseudo sessionid created from md5(user:passwd) |
821 | 820 | // --> allows this stateless protocolls which use basic auth to use sessions! |
@@ -842,11 +841,11 @@ discard block |
||
842 | 841 | EGW_SERVER_ROOT.':'.self::getuser_ip().':'.filemtime(EGW_SERVER_ROOT.'/api/setup/setup.inc.php'). |
843 | 842 | ':'.$_SERVER['HTTP_USER_AGENT']); |
844 | 843 | } |
845 | - elseif(!$only_basic_auth && isset($_REQUEST[self::EGW_SESSION_NAME])) |
|
844 | + elseif (!$only_basic_auth && isset($_REQUEST[self::EGW_SESSION_NAME])) |
|
846 | 845 | { |
847 | 846 | $sessionid = $_REQUEST[self::EGW_SESSION_NAME]; |
848 | 847 | } |
849 | - elseif(!$only_basic_auth && isset($_COOKIE[self::EGW_SESSION_NAME])) |
|
848 | + elseif (!$only_basic_auth && isset($_COOKIE[self::EGW_SESSION_NAME])) |
|
850 | 849 | { |
851 | 850 | $sessionid = $_COOKIE[self::EGW_SESSION_NAME]; |
852 | 851 | } |
@@ -854,7 +853,7 @@ discard block |
||
854 | 853 | { |
855 | 854 | $sessionid = false; |
856 | 855 | } |
857 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() _SERVER[REQUEST_URI]='$_SERVER[REQUEST_URI]' returning ".print_r($sessionid,true)); |
|
856 | + if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() _SERVER[REQUEST_URI]='$_SERVER[REQUEST_URI]' returning ".print_r($sessionid, true)); |
|
858 | 857 | return $sessionid; |
859 | 858 | } |
860 | 859 | |
@@ -870,9 +869,7 @@ discard block |
||
870 | 869 | */ |
871 | 870 | static function get_request($name) |
872 | 871 | { |
873 | - return isset($_REQUEST[$name]) ? $_REQUEST[$name] : |
|
874 | - (isset($_COOKIE[$name]) ? $_COOKIE[$name] : |
|
875 | - (isset($_COOKIE[$name=ucfirst($name)]) ? $_COOKIE[$name] : null)); |
|
872 | + return isset($_REQUEST[$name]) ? $_REQUEST[$name] : (isset($_COOKIE[$name]) ? $_COOKIE[$name] : (isset($_COOKIE[$name = ucfirst($name)]) ? $_COOKIE[$name] : null)); |
|
876 | 873 | } |
877 | 874 | |
878 | 875 | /** |
@@ -882,13 +879,13 @@ discard block |
||
882 | 879 | * @param string $kp3 ?? to be verified |
883 | 880 | * @return bool is the session valid? |
884 | 881 | */ |
885 | - function verify($sessionid=null,$kp3=null) |
|
882 | + function verify($sessionid = null, $kp3 = null) |
|
886 | 883 | { |
887 | 884 | if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid','$kp3') ".function_backtrace()); |
888 | 885 | |
889 | 886 | $fill_egw_info_and_repositories = !$GLOBALS['egw_info']['flags']['restored_from_session']; |
890 | 887 | |
891 | - if(!$sessionid) |
|
888 | + if (!$sessionid) |
|
892 | 889 | { |
893 | 890 | $sessionid = self::get_sessionid(); |
894 | 891 | $kp3 = self::get_request('kp3'); |
@@ -915,23 +912,23 @@ discard block |
||
915 | 912 | if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') session does NOT exist!"); |
916 | 913 | return false; |
917 | 914 | } |
918 | - $session =& $_SESSION[self::EGW_SESSION_VAR]; |
|
915 | + $session = & $_SESSION[self::EGW_SESSION_VAR]; |
|
919 | 916 | |
920 | 917 | if ($session['session_dla'] <= time() - $GLOBALS['egw_info']['server']['sessions_timeout']) |
921 | 918 | { |
922 | 919 | if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') session timed out!"); |
923 | - $this->destroy($sessionid,$kp3); |
|
920 | + $this->destroy($sessionid, $kp3); |
|
924 | 921 | return false; |
925 | 922 | } |
926 | 923 | |
927 | 924 | $this->session_flags = $session['session_flags']; |
928 | 925 | |
929 | - $this->split_login_domain($session['session_lid'],$this->account_lid,$this->account_domain); |
|
926 | + $this->split_login_domain($session['session_lid'], $this->account_lid, $this->account_domain); |
|
930 | 927 | |
931 | 928 | // This is to ensure that we authenticate to the correct domain (might not be default) |
932 | - if($GLOBALS['egw_info']['user']['domain'] && $this->account_domain != $GLOBALS['egw_info']['user']['domain']) |
|
929 | + if ($GLOBALS['egw_info']['user']['domain'] && $this->account_domain != $GLOBALS['egw_info']['user']['domain']) |
|
933 | 930 | { |
934 | - return false; // session not verified, domain changed |
|
931 | + return false; // session not verified, domain changed |
|
935 | 932 | } |
936 | 933 | $GLOBALS['egw_info']['user']['kp3'] = $this->kp3; |
937 | 934 | |
@@ -944,7 +941,7 @@ discard block |
||
944 | 941 | { |
945 | 942 | $this->update_notification_heartbeat(); |
946 | 943 | } |
947 | - $this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid,'account_lid','u'); |
|
944 | + $this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid, 'account_lid', 'u'); |
|
948 | 945 | if (!$this->account_id) |
949 | 946 | { |
950 | 947 | if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) !accounts::name2id('$this->account_lid')"); |
@@ -982,7 +979,7 @@ discard block |
||
982 | 979 | |
983 | 980 | if ($GLOBALS['egw_info']['server']['sessions_checkip']) |
984 | 981 | { |
985 | - if (strtoupper(substr(PHP_OS,0,3)) != 'WIN' && (!$GLOBALS['egw_info']['user']['session_ip'] || |
|
982 | + if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN' && (!$GLOBALS['egw_info']['user']['session_ip'] || |
|
986 | 983 | $GLOBALS['egw_info']['user']['session_ip'] != $this->getuser_ip())) |
987 | 984 | { |
988 | 985 | if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) wrong IP"); |
@@ -1005,9 +1002,9 @@ discard block |
||
1005 | 1002 | // query accesslog-id, if not set in session (session is made persistent after login!) |
1006 | 1003 | if (!$this->sessionid_access_log && $this->session_flags != 'A') |
1007 | 1004 | { |
1008 | - $this->sessionid_access_log = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE,'sessionid',array( |
|
1005 | + $this->sessionid_access_log = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE, 'sessionid', array( |
|
1009 | 1006 | 'session_php' => $this->sessionid, |
1010 | - ),__LINE__,__FILE__)->fetchColumn(); |
|
1007 | + ), __LINE__, __FILE__)->fetchColumn(); |
|
1011 | 1008 | //error_log(__METHOD__."() sessionid=$this->sessionid --> sessionid_access_log=$this->sessionid_access_log"); |
1012 | 1009 | } |
1013 | 1010 | |
@@ -1018,9 +1015,9 @@ discard block |
||
1018 | 1015 | (!isset($_COOKIE[self::EGW_SESSION_NAME]) || $_COOKIE[self::EGW_SESSION_NAME] !== $_REQUEST[self::EGW_SESSION_NAME])) |
1019 | 1016 | { |
1020 | 1017 | if (self::ERROR_LOG_DEBUG) error_log("--> Session::verify($sessionid) SUCCESS, but NO required cookies set --> setting them now"); |
1021 | - self::egw_setcookie(self::EGW_SESSION_NAME,$this->sessionid); |
|
1022 | - self::egw_setcookie('kp3',$this->kp3); |
|
1023 | - self::egw_setcookie('domain',$this->account_domain); |
|
1018 | + self::egw_setcookie(self::EGW_SESSION_NAME, $this->sessionid); |
|
1019 | + self::egw_setcookie('kp3', $this->kp3); |
|
1020 | + self::egw_setcookie('domain', $this->account_domain); |
|
1024 | 1021 | } |
1025 | 1022 | |
1026 | 1023 | if (self::ERROR_LOG_DEBUG) error_log("--> Session::verify($sessionid) SUCCESS"); |
@@ -1035,27 +1032,27 @@ discard block |
||
1035 | 1032 | * @param string $kp3 |
1036 | 1033 | * @return boolean true on success, false on error |
1037 | 1034 | */ |
1038 | - function destroy($sessionid, $kp3='') |
|
1035 | + function destroy($sessionid, $kp3 = '') |
|
1039 | 1036 | { |
1040 | 1037 | if (!$sessionid && $kp3) |
1041 | 1038 | { |
1042 | 1039 | return false; |
1043 | 1040 | } |
1044 | - $this->log_access($sessionid); // log logout-time |
|
1041 | + $this->log_access($sessionid); // log logout-time |
|
1045 | 1042 | |
1046 | 1043 | if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($sessionid,$kp3)"); |
1047 | 1044 | |
1048 | 1045 | if (is_numeric($sessionid)) // do we have a access-log-id --> get PHP session id |
1049 | 1046 | { |
1050 | - $sessionid = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE,'session_php',array( |
|
1047 | + $sessionid = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE, 'session_php', array( |
|
1051 | 1048 | 'sessionid' => $sessionid, |
1052 | - ),__LINE__,__FILE__)->fetchColumn(); |
|
1049 | + ), __LINE__, __FILE__)->fetchColumn(); |
|
1053 | 1050 | } |
1054 | 1051 | |
1055 | 1052 | Hooks::process(array( |
1056 | 1053 | 'location' => 'session_destroyed', |
1057 | 1054 | 'sessionid' => $sessionid, |
1058 | - ),'',true); // true = run hooks from all apps, not just the ones the current user has perms to run |
|
1055 | + ), '', true); // true = run hooks from all apps, not just the ones the current user has perms to run |
|
1059 | 1056 | |
1060 | 1057 | // Only do the following, if where working with the current user |
1061 | 1058 | if (!$GLOBALS['egw_info']['user']['sessionid'] || $sessionid == $GLOBALS['egw_info']['user']['sessionid']) |
@@ -1076,7 +1073,7 @@ discard block |
||
1076 | 1073 | } |
1077 | 1074 | else |
1078 | 1075 | { |
1079 | - $this->commit_session(); // close our own session |
|
1076 | + $this->commit_session(); // close our own session |
|
1080 | 1077 | |
1081 | 1078 | session_id($sessionid); |
1082 | 1079 | if (session_start()) |
@@ -1116,25 +1113,25 @@ discard block |
||
1116 | 1113 | // as $webserver_url may be part of $url (as /egw is part of phpgwapi/js/egw_instant_load.html) |
1117 | 1114 | if (($url[0] != '/' || $webserver_url != '/') && (!$webserver_url || strpos($url, $webserver_url.'/') === false)) |
1118 | 1115 | { |
1119 | - if($url[0] != '/' && substr($webserver_url,-1) != '/') |
|
1116 | + if ($url[0] != '/' && substr($webserver_url, -1) != '/') |
|
1120 | 1117 | { |
1121 | - $url = $webserver_url .'/'. $url; |
|
1118 | + $url = $webserver_url.'/'.$url; |
|
1122 | 1119 | } |
1123 | 1120 | else |
1124 | 1121 | { |
1125 | - $url = $webserver_url . $url; |
|
1122 | + $url = $webserver_url.$url; |
|
1126 | 1123 | } |
1127 | 1124 | } |
1128 | 1125 | |
1129 | - if(isset($GLOBALS['egw_info']['server']['enforce_ssl']) && $GLOBALS['egw_info']['server']['enforce_ssl']) |
|
1126 | + if (isset($GLOBALS['egw_info']['server']['enforce_ssl']) && $GLOBALS['egw_info']['server']['enforce_ssl']) |
|
1130 | 1127 | { |
1131 | - if(substr($url ,0,4) != 'http') |
|
1128 | + if (substr($url, 0, 4) != 'http') |
|
1132 | 1129 | { |
1133 | 1130 | $url = 'https://'.$_SERVER['HTTP_HOST'].$url; |
1134 | 1131 | } |
1135 | 1132 | else |
1136 | 1133 | { |
1137 | - $url = str_replace ( 'http:', 'https:', $url); |
|
1134 | + $url = str_replace('http:', 'https:', $url); |
|
1138 | 1135 | } |
1139 | 1136 | } |
1140 | 1137 | $vars = array(); |
@@ -1147,7 +1144,7 @@ discard block |
||
1147 | 1144 | } |
1148 | 1145 | |
1149 | 1146 | // check if the url already contains a query and ensure that vars is an array and all strings are in extravars |
1150 | - list($ret_url,$othervars) = explode('?', $url, 2); |
|
1147 | + list($ret_url, $othervars) = explode('?', $url, 2); |
|
1151 | 1148 | if ($extravars && is_array($extravars)) |
1152 | 1149 | { |
1153 | 1150 | $vars += $extravars; |
@@ -1155,19 +1152,19 @@ discard block |
||
1155 | 1152 | } |
1156 | 1153 | else |
1157 | 1154 | { |
1158 | - if ($othervars) $extravars .= ($extravars?'&':'').$othervars; |
|
1155 | + if ($othervars) $extravars .= ($extravars ? '&' : '').$othervars; |
|
1159 | 1156 | } |
1160 | 1157 | |
1161 | 1158 | // parse extravars string into the vars array |
1162 | 1159 | if ($extravars) |
1163 | 1160 | { |
1164 | - foreach(explode('&',$extravars) as $expr) |
|
1161 | + foreach (explode('&', $extravars) as $expr) |
|
1165 | 1162 | { |
1166 | - list($var,$val) = explode('=', $expr,2); |
|
1167 | - if (strpos($val,'%26') != false) $val = str_replace('%26','&',$val); // make sure to not double encode & |
|
1168 | - if (substr($var,-2) == '[]') |
|
1163 | + list($var, $val) = explode('=', $expr, 2); |
|
1164 | + if (strpos($val, '%26') != false) $val = str_replace('%26', '&', $val); // make sure to not double encode & |
|
1165 | + if (substr($var, -2) == '[]') |
|
1169 | 1166 | { |
1170 | - $vars[substr($var,0,-2)][] = $val; |
|
1167 | + $vars[substr($var, 0, -2)][] = $val; |
|
1171 | 1168 | } |
1172 | 1169 | else |
1173 | 1170 | { |
@@ -1180,11 +1177,11 @@ discard block |
||
1180 | 1177 | if (count($vars)) |
1181 | 1178 | { |
1182 | 1179 | $query = array(); |
1183 | - foreach($vars as $key => $value) |
|
1180 | + foreach ($vars as $key => $value) |
|
1184 | 1181 | { |
1185 | 1182 | if (is_array($value)) |
1186 | 1183 | { |
1187 | - foreach($value as $val) |
|
1184 | + foreach ($value as $val) |
|
1188 | 1185 | { |
1189 | 1186 | $query[] = $key.'[]='.urlencode($val); |
1190 | 1187 | } |
@@ -1194,7 +1191,7 @@ discard block |
||
1194 | 1191 | $query[] = $key.'='.urlencode($value); |
1195 | 1192 | } |
1196 | 1193 | } |
1197 | - $ret_url .= '?' . implode('&',$query); |
|
1194 | + $ret_url .= '?'.implode('&', $query); |
|
1198 | 1195 | } |
1199 | 1196 | return $ret_url; |
1200 | 1197 | } |
@@ -1239,7 +1236,7 @@ discard block |
||
1239 | 1236 | * @param int $cookietime =0 when cookie should expire, 0 for session only (optional) |
1240 | 1237 | * @param string $cookiepath =null optional path (eg. '/') if the eGW install-dir should not be used |
1241 | 1238 | */ |
1242 | - public static function egw_setcookie($cookiename,$cookievalue='',$cookietime=0,$cookiepath=null) |
|
1239 | + public static function egw_setcookie($cookiename, $cookievalue = '', $cookietime = 0, $cookiepath = null) |
|
1243 | 1240 | { |
1244 | 1241 | if (empty(self::$cookie_domain) || empty(self::$cookie_path)) |
1245 | 1242 | { |
@@ -1252,11 +1249,11 @@ discard block |
||
1252 | 1249 | static $is_iOS = null; |
1253 | 1250 | if (!$cookietime && !isset($is_iOS)) $is_iOS = (bool)preg_match('/^(iPhone|iPad|iPod)/i', Header\UserAgent::mobile()); |
1254 | 1251 | |
1255 | - if(!headers_sent()) // gives only a warning, but can not send the cookie anyway |
|
1252 | + if (!headers_sent()) // gives only a warning, but can not send the cookie anyway |
|
1256 | 1253 | { |
1257 | 1254 | setcookie($cookiename, $cookievalue, |
1258 | - !$cookietime && $is_iOS ? time()+self::IOS_SESSION_COOKIE_LIFETIME : $cookietime, |
|
1259 | - is_null($cookiepath) ? self::$cookie_path : $cookiepath,self::$cookie_domain, |
|
1255 | + !$cookietime && $is_iOS ? time() + self::IOS_SESSION_COOKIE_LIFETIME : $cookietime, |
|
1256 | + is_null($cookiepath) ? self::$cookie_path : $cookiepath, self::$cookie_domain, |
|
1260 | 1257 | // if called via HTTPS, only send cookie for https and only allow cookie access via HTTP (true) |
1261 | 1258 | empty($GLOBALS['egw_info']['server']['insecure_cookies']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off', true); |
1262 | 1259 | } |
@@ -1275,21 +1272,21 @@ discard block |
||
1275 | 1272 | else |
1276 | 1273 | { |
1277 | 1274 | // Use HTTP_X_FORWARDED_HOST if set, which is the case behind a none-transparent proxy |
1278 | - self::$cookie_domain = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST']; |
|
1275 | + self::$cookie_domain = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : $_SERVER['HTTP_HOST']; |
|
1279 | 1276 | } |
1280 | 1277 | // remove port from HTTP_HOST |
1281 | 1278 | $arr = null; |
1282 | - if (preg_match("/^(.*):(.*)$/",self::$cookie_domain,$arr)) |
|
1279 | + if (preg_match("/^(.*):(.*)$/", self::$cookie_domain, $arr)) |
|
1283 | 1280 | { |
1284 | 1281 | self::$cookie_domain = $arr[1]; |
1285 | 1282 | } |
1286 | - if (count(explode('.',self::$cookie_domain)) <= 1) |
|
1283 | + if (count(explode('.', self::$cookie_domain)) <= 1) |
|
1287 | 1284 | { |
1288 | 1285 | // setcookie dont likes domains without dots, leaving it empty, gets setcookie to fill the domain in |
1289 | 1286 | self::$cookie_domain = ''; |
1290 | 1287 | } |
1291 | 1288 | if (!$GLOBALS['egw_info']['server']['cookiepath'] || |
1292 | - !(self::$cookie_path = parse_url($GLOBALS['egw_info']['server']['webserver_url'],PHP_URL_PATH))) |
|
1289 | + !(self::$cookie_path = parse_url($GLOBALS['egw_info']['server']['webserver_url'], PHP_URL_PATH))) |
|
1293 | 1290 | { |
1294 | 1291 | self::$cookie_path = '/'; |
1295 | 1292 | } |
@@ -1309,7 +1306,7 @@ discard block |
||
1309 | 1306 | * @param array $domains =null defaults to $GLOBALS['egw_domain'] from the header |
1310 | 1307 | * @return string $GLOBALS['egw_info']['user']['domain'] set with the domain/instance to use |
1311 | 1308 | */ |
1312 | - public static function search_instance($login,$domain_requested,&$default_domain,$server_names,array $domains=null) |
|
1309 | + public static function search_instance($login, $domain_requested, &$default_domain, $server_names, array $domains = null) |
|
1313 | 1310 | { |
1314 | 1311 | if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$login','$domain_requested',".array2string($default_domain).".".array2string($server_names).".".array2string($domains).")"); |
1315 | 1312 | |
@@ -1317,10 +1314,10 @@ discard block |
||
1317 | 1314 | |
1318 | 1315 | if (!isset($default_domain) || !isset($domains[$default_domain])) // allow to overwrite the default domain |
1319 | 1316 | { |
1320 | - foreach((array)$server_names as $server_name) |
|
1317 | + foreach ((array)$server_names as $server_name) |
|
1321 | 1318 | { |
1322 | - list($server_name) = explode(':', $server_name); // remove port from HTTP_HOST |
|
1323 | - if(isset($domains[$server_name])) |
|
1319 | + list($server_name) = explode(':', $server_name); // remove port from HTTP_HOST |
|
1320 | + if (isset($domains[$server_name])) |
|
1324 | 1321 | { |
1325 | 1322 | $default_domain = $server_name; |
1326 | 1323 | break; |
@@ -1330,7 +1327,7 @@ discard block |
||
1330 | 1327 | $parts = explode('.', $server_name); |
1331 | 1328 | array_shift($parts); |
1332 | 1329 | $domain_part = implode('.', $parts); |
1333 | - if(isset($domains[$domain_part])) |
|
1330 | + if (isset($domains[$domain_part])) |
|
1334 | 1331 | { |
1335 | 1332 | $default_domain = $domain_part; |
1336 | 1333 | break; |
@@ -1346,11 +1343,11 @@ discard block |
||
1346 | 1343 | } |
1347 | 1344 | if (isset($login)) // on login |
1348 | 1345 | { |
1349 | - if (strpos($login,'@') === false || count($domains) == 1) |
|
1346 | + if (strpos($login, '@') === false || count($domains) == 1) |
|
1350 | 1347 | { |
1351 | - $login .= '@' . (isset($_POST['logindomain']) ? $_POST['logindomain'] : $default_domain); |
|
1348 | + $login .= '@'.(isset($_POST['logindomain']) ? $_POST['logindomain'] : $default_domain); |
|
1352 | 1349 | } |
1353 | - $parts = explode('@',$login); |
|
1350 | + $parts = explode('@', $login); |
|
1354 | 1351 | $domain = array_pop($parts); |
1355 | 1352 | $GLOBALS['login'] = $login; |
1356 | 1353 | } |
@@ -1383,7 +1380,7 @@ discard block |
||
1383 | 1380 | * @param boolean $update_access_log =false false: dont update egw_access_log table, but set $this->action |
1384 | 1381 | * @return string action as written to egw_access_log.session_action |
1385 | 1382 | */ |
1386 | - private function update_dla($update_access_log=false) |
|
1383 | + private function update_dla($update_access_log = false) |
|
1387 | 1384 | { |
1388 | 1385 | // This way XML-RPC users aren't always listed as xmlrpc.php |
1389 | 1386 | if (!$update_access_log) |
@@ -1401,14 +1398,14 @@ discard block |
||
1401 | 1398 | $action = $_SERVER['PHP_SELF']; |
1402 | 1399 | // remove EGroupware path, if not installed in webroot |
1403 | 1400 | $egw_path = $GLOBALS['egw_info']['server']['webserver_url']; |
1404 | - if ($egw_path[0] != '/') $egw_path = parse_url($egw_path,PHP_URL_PATH); |
|
1401 | + if ($egw_path[0] != '/') $egw_path = parse_url($egw_path, PHP_URL_PATH); |
|
1405 | 1402 | if ($action == '/Microsoft-Server-ActiveSync') |
1406 | 1403 | { |
1407 | 1404 | $action .= '?Cmd='.$_GET['Cmd'].'&DeviceId='.$_GET['DeviceId']; |
1408 | 1405 | } |
1409 | 1406 | elseif ($egw_path) |
1410 | 1407 | { |
1411 | - list(,$action) = explode($egw_path,$action,2); |
|
1408 | + list(,$action) = explode($egw_path, $action, 2); |
|
1412 | 1409 | } |
1413 | 1410 | } |
1414 | 1411 | $this->set_action($action); |
@@ -1416,13 +1413,13 @@ discard block |
||
1416 | 1413 | // update dla in access-log table, if we have an access-log row (non-anonymous session) |
1417 | 1414 | if ($this->sessionid_access_log && $update_access_log) |
1418 | 1415 | { |
1419 | - $GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE,array( |
|
1416 | + $GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE, array( |
|
1420 | 1417 | 'session_dla' => time(), |
1421 | 1418 | 'session_action' => $this->action, |
1422 | - 'lo' => null, // just in case it was (automatic) timed out before |
|
1423 | - ),array( |
|
1419 | + 'lo' => null, // just in case it was (automatic) timed out before |
|
1420 | + ), array( |
|
1424 | 1421 | 'sessionid' => $this->sessionid_access_log, |
1425 | - ),__LINE__,__FILE__); |
|
1422 | + ), __LINE__, __FILE__); |
|
1426 | 1423 | } |
1427 | 1424 | |
1428 | 1425 | $_SESSION[self::EGW_SESSION_VAR]['session_dla'] = time(); |
@@ -1440,12 +1437,12 @@ discard block |
||
1440 | 1437 | // update dla in access-log table, if we have an access-log row (non-anonymous session) |
1441 | 1438 | if ($this->sessionid_access_log) |
1442 | 1439 | { |
1443 | - $GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE,array( |
|
1440 | + $GLOBALS['egw']->db->update(self::ACCESS_LOG_TABLE, array( |
|
1444 | 1441 | 'notification_heartbeat' => time(), |
1445 | - ),array( |
|
1442 | + ), array( |
|
1446 | 1443 | 'sessionid' => $this->sessionid_access_log, |
1447 | 1444 | 'lo IS NULL', |
1448 | - ),__LINE__,__FILE__); |
|
1445 | + ), __LINE__, __FILE__); |
|
1449 | 1446 | } |
1450 | 1447 | } |
1451 | 1448 | |
@@ -1466,7 +1463,7 @@ discard block |
||
1466 | 1463 | { |
1467 | 1464 | // authentication happens in login.php, which does NOT yet create egw-object in session |
1468 | 1465 | // --> need to store homedirectory in session |
1469 | - if(isset($GLOBALS['auto_create_acct']['homedirectory'])) |
|
1466 | + if (isset($GLOBALS['auto_create_acct']['homedirectory'])) |
|
1470 | 1467 | { |
1471 | 1468 | Cache::setSession(__CLASS__, 'homedirectory', |
1472 | 1469 | $user['homedirectory'] = $GLOBALS['auto_create_acct']['homedirectory']); |
@@ -1479,7 +1476,7 @@ discard block |
||
1479 | 1476 | $user['preferences'] = $GLOBALS['egw']->preferences->read_repository(); |
1480 | 1477 | if (is_object($GLOBALS['egw']->datetime)) |
1481 | 1478 | { |
1482 | - $GLOBALS['egw']->datetime->__construct(); // to set tz_offset from the now read prefs |
|
1479 | + $GLOBALS['egw']->datetime->__construct(); // to set tz_offset from the now read prefs |
|
1483 | 1480 | } |
1484 | 1481 | $user['apps'] = $GLOBALS['egw']->applications->read_repository(); |
1485 | 1482 | $user['domain'] = $this->account_domain; |
@@ -1502,9 +1499,9 @@ discard block |
||
1502 | 1499 | * @param string &$account_lid returned account_lid (ie. user) |
1503 | 1500 | * @param string &$domain returned domain (ie. domain) |
1504 | 1501 | */ |
1505 | - private function split_login_domain($login,&$account_lid,&$domain) |
|
1502 | + private function split_login_domain($login, &$account_lid, &$domain) |
|
1506 | 1503 | { |
1507 | - $parts = explode('@',$login); |
|
1504 | + $parts = explode('@', $login); |
|
1508 | 1505 | |
1509 | 1506 | //conference - for strings like [email protected]@default , |
1510 | 1507 | //allows that user have a login that is his e-mail. (viniciuscb) |
@@ -1512,11 +1509,11 @@ discard block |
||
1512 | 1509 | { |
1513 | 1510 | $probable_domain = array_pop($parts); |
1514 | 1511 | //Last part of login string, when separated by @, is a domain name |
1515 | - if (in_array($probable_domain,$this->egw_domains)) |
|
1512 | + if (in_array($probable_domain, $this->egw_domains)) |
|
1516 | 1513 | { |
1517 | 1514 | $got_login = true; |
1518 | 1515 | $domain = $probable_domain; |
1519 | - $account_lid = implode('@',$parts); |
|
1516 | + $account_lid = implode('@', $parts); |
|
1520 | 1517 | } |
1521 | 1518 | } |
1522 | 1519 | |
@@ -1539,9 +1536,9 @@ discard block |
||
1539 | 1536 | * @param boolean $allow_password_md5 =false can password alread be an md5 hash |
1540 | 1537 | * @return string |
1541 | 1538 | */ |
1542 | - static function user_pw_hash($user,$password,$allow_password_md5=false) |
|
1539 | + static function user_pw_hash($user, $password, $allow_password_md5 = false) |
|
1543 | 1540 | { |
1544 | - $password_md5 = $allow_password_md5 && preg_match('/^[a-f0-9]{32}$/',$password) ? $password : md5($password); |
|
1541 | + $password_md5 = $allow_password_md5 && preg_match('/^[a-f0-9]{32}$/', $password) ? $password : md5($password); |
|
1545 | 1542 | |
1546 | 1543 | $hash = sha1(strtolower($user).$password_md5); |
1547 | 1544 | |
@@ -1555,7 +1552,7 @@ discard block |
||
1555 | 1552 | { |
1556 | 1553 | if (self::ERROR_LOG_DEBUG) error_log(__METHOD__.'() session_handler='.self::$session_handler.', egw_info[server][session_handler]='.$GLOBALS['egw_info']['server']['session_handler'].' called from:'.function_backtrace()); |
1557 | 1554 | |
1558 | - ini_set('session.use_cookies',0); // disable the automatic use of cookies, as it uses the path / by default |
|
1555 | + ini_set('session.use_cookies', 0); // disable the automatic use of cookies, as it uses the path / by default |
|
1559 | 1556 | session_name(self::EGW_SESSION_NAME); |
1560 | 1557 | if (($sessionid = self::get_sessionid())) |
1561 | 1558 | { |
@@ -1582,7 +1579,7 @@ discard block |
||
1582 | 1579 | * @param int $expire =null expiration time in seconds, default $GLOBALS['egw_info']['flags']['nocachecontrol'] or php.ini session.cache_expire |
1583 | 1580 | * @param int $private =null allows to set private caching with given expiration time, by setting it to true |
1584 | 1581 | */ |
1585 | - public static function cache_control($expire=null, $private=null) |
|
1582 | + public static function cache_control($expire = null, $private = null) |
|
1586 | 1583 | { |
1587 | 1584 | if (is_null($expire) && isset($GLOBALS['egw_info']['flags']['nocachecontrol']) && is_int($GLOBALS['egw_info']['flags']['nocachecontrol'])) |
1588 | 1585 | { |
@@ -1592,7 +1589,7 @@ discard block |
||
1592 | 1589 | if (!isset($_SESSION)) |
1593 | 1590 | { |
1594 | 1591 | // controling caching and expires header |
1595 | - if(!isset($expire) && (!isset($GLOBALS['egw_info']['flags']['nocachecontrol']) || |
|
1592 | + if (!isset($expire) && (!isset($GLOBALS['egw_info']['flags']['nocachecontrol']) || |
|
1596 | 1593 | !$GLOBALS['egw_info']['flags']['nocachecontrol'])) |
1597 | 1594 | { |
1598 | 1595 | session_cache_limiter('nocache'); |
@@ -1602,7 +1599,7 @@ discard block |
||
1602 | 1599 | // allow public caching: proxys, cdns, ... |
1603 | 1600 | if (isset($expire)) |
1604 | 1601 | { |
1605 | - session_cache_expire((int)ceil($expire/60)); // in minutes |
|
1602 | + session_cache_expire((int)ceil($expire / 60)); // in minutes |
|
1606 | 1603 | } |
1607 | 1604 | session_cache_limiter($private ? 'private' : 'public'); |
1608 | 1605 | } |
@@ -1615,8 +1612,8 @@ discard block |
||
1615 | 1612 | // session already started |
1616 | 1613 | if (isset($_SESSION)) |
1617 | 1614 | { |
1618 | - if ($expire && (session_cache_limiter() !== ($expire===true?'private_no_expire':'public') || |
|
1619 | - is_int($expire) && $expire/60 !== session_cache_expire())) |
|
1615 | + if ($expire && (session_cache_limiter() !== ($expire === true ? 'private_no_expire' : 'public') || |
|
1616 | + is_int($expire) && $expire / 60 !== session_cache_expire())) |
|
1620 | 1617 | { |
1621 | 1618 | $file = $line = null; |
1622 | 1619 | if (headers_sent($file, $line)) |
@@ -1624,20 +1621,20 @@ discard block |
||
1624 | 1621 | error_log(__METHOD__."($expire) called, but header already sent in $file: $line"); |
1625 | 1622 | return; |
1626 | 1623 | } |
1627 | - if($expire === true) // same behavior as session_cache_limiter('private_no_expire') |
|
1624 | + if ($expire === true) // same behavior as session_cache_limiter('private_no_expire') |
|
1628 | 1625 | { |
1629 | - header('Cache-Control: private, max-age='.(60*session_cache_expire())); |
|
1626 | + header('Cache-Control: private, max-age='.(60 * session_cache_expire())); |
|
1630 | 1627 | header_remove('Expires'); |
1631 | 1628 | } |
1632 | 1629 | elseif ($private) |
1633 | 1630 | { |
1634 | 1631 | header('Cache-Control: private, max-age='.$expire); |
1635 | - header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expire) . ' GMT'); |
|
1632 | + header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expire).' GMT'); |
|
1636 | 1633 | } |
1637 | 1634 | else |
1638 | 1635 | { |
1639 | 1636 | header('Cache-Control: public, max-age='.$expire); |
1640 | - header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expire) . ' GMT'); |
|
1637 | + header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expire).' GMT'); |
|
1641 | 1638 | } |
1642 | 1639 | // remove Pragma header, might be set by old header |
1643 | 1640 | if (function_exists('header_remove')) // PHP 5.3+ |
@@ -1662,10 +1659,10 @@ discard block |
||
1662 | 1659 | * @param array $filter =array() extra filter for sessions |
1663 | 1660 | * @return array with sessions (values for keys as in $sort) |
1664 | 1661 | */ |
1665 | - public static function session_list($start,$sort='DESC',$order='session_dla',$all_no_sort=False,array $filter=array()) |
|
1662 | + public static function session_list($start, $sort = 'DESC', $order = 'session_dla', $all_no_sort = False, array $filter = array()) |
|
1666 | 1663 | { |
1667 | 1664 | $sessions = array(); |
1668 | - if (!preg_match('/^[a-z0-9_ ,]+$/i',$order_by=$order.' '.$sort) || $order_by == ' ') |
|
1665 | + if (!preg_match('/^[a-z0-9_ ,]+$/i', $order_by = $order.' '.$sort) || $order_by == ' ') |
|
1669 | 1666 | { |
1670 | 1667 | $order_by = 'session_dla DESC'; |
1671 | 1668 | } |
@@ -1673,7 +1670,7 @@ discard block |
||
1673 | 1670 | $filter[] = 'account_id>0'; |
1674 | 1671 | $filter[] = 'session_dla > '.(int)(time() - $GLOBALS['egw_info']['server']['sessions_timeout']); |
1675 | 1672 | $filter[] = '(notification_heartbeat IS NULL OR notification_heartbeat > '.self::heartbeat_limit().')'; |
1676 | - foreach($GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE, '*', $filter, __LINE__, __FILE__, |
|
1673 | + foreach ($GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE, '*', $filter, __LINE__, __FILE__, |
|
1677 | 1674 | $all_no_sort ? false : $start, 'ORDER BY '.$order_by) as $row) |
1678 | 1675 | { |
1679 | 1676 | $sessions[$row['sessionid']] = $row; |
@@ -1687,7 +1684,7 @@ discard block |
||
1687 | 1684 | * @param array $filter =array() extra filter for sessions |
1688 | 1685 | * @return int number of active sessions |
1689 | 1686 | */ |
1690 | - public static function session_count(array $filter=array()) |
|
1687 | + public static function session_count(array $filter = array()) |
|
1691 | 1688 | { |
1692 | 1689 | $filter['lo'] = null; |
1693 | 1690 | $filter[] = 'account_id>0'; |
@@ -1703,16 +1700,16 @@ discard block |
||
1703 | 1700 | */ |
1704 | 1701 | public static function heartbeat_limit() |
1705 | 1702 | { |
1706 | - static $limit=null; |
|
1703 | + static $limit = null; |
|
1707 | 1704 | |
1708 | 1705 | if (is_null($limit)) |
1709 | 1706 | { |
1710 | 1707 | $config = Config::read('notifications'); |
1711 | - if (!($popup_poll_interval = $config['popup_poll_interval'])) |
|
1708 | + if (!($popup_poll_interval = $config['popup_poll_interval'])) |
|
1712 | 1709 | { |
1713 | 1710 | $popup_poll_interval = 60; |
1714 | 1711 | } |
1715 | - $limit = (int)(time() - $popup_poll_interval-10); // 10s grace periode |
|
1712 | + $limit = (int)(time() - $popup_poll_interval - 10); // 10s grace periode |
|
1716 | 1713 | } |
1717 | 1714 | return $limit; |
1718 | 1715 | } |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | |
256 | 256 | // set session_timeout from global php.ini and default to 14400=4h, if not set |
257 | 257 | if (!($GLOBALS['egw_info']['server']['sessions_timeout'] = ini_get('session.gc_maxlifetime'))) |
258 | - { |
|
258 | + { |
|
259 | 259 | ini_set('session.gc_maxlifetime', $GLOBALS['egw_info']['server']['sessions_timeout']=14400); |
260 | 260 | } |
261 | 261 | } |
@@ -292,7 +292,10 @@ discard block |
||
292 | 292 | */ |
293 | 293 | function commit_session() |
294 | 294 | { |
295 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() sessionid=$this->sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]).' '.function_backtrace()); |
|
295 | + if (self::ERROR_LOG_DEBUG) |
|
296 | + { |
|
297 | + error_log(__METHOD__."() sessionid=$this->sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]).' '.function_backtrace()); |
|
298 | + } |
|
296 | 299 | self::encrypt($this->kp3); |
297 | 300 | |
298 | 301 | session_write_close(); |
@@ -354,7 +357,10 @@ discard block |
||
354 | 357 | */ |
355 | 358 | static function log_session_usage(&$arr,$label,$recursion=true,$limit=1000) |
356 | 359 | { |
357 | - if (!is_array($arr)) return; |
|
360 | + if (!is_array($arr)) |
|
361 | + { |
|
362 | + return; |
|
363 | + } |
|
358 | 364 | |
359 | 365 | $sizes = array(); |
360 | 366 | foreach($arr as $key => &$data) |
@@ -369,7 +375,10 @@ discard block |
||
369 | 375 | if ($diff > $limit) |
370 | 376 | { |
371 | 377 | error_log("strlen({$label}[$key])=".Vfs::hsize($size).", diff=".Vfs::hsize($diff)); |
372 | - if ($recursion) self::log_session_usage($arr[$key],$label.'['.$key.']',$recursion,$limit); |
|
378 | + if ($recursion) |
|
379 | + { |
|
380 | + self::log_session_usage($arr[$key],$label.'['.$key.']',$recursion,$limit); |
|
381 | + } |
|
373 | 382 | } |
374 | 383 | } |
375 | 384 | } |
@@ -467,7 +476,10 @@ discard block |
||
467 | 476 | $this->passwd = $passwd; |
468 | 477 | $this->passwd_type = $passwd_type; |
469 | 478 | } |
470 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) starting ..."); |
|
479 | + if (self::ERROR_LOG_DEBUG) |
|
480 | + { |
|
481 | + error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) starting ..."); |
|
482 | + } |
|
471 | 483 | |
472 | 484 | self::split_login_domain($login,$this->account_lid,$this->account_domain); |
473 | 485 | // add domain to the login, if not already there |
@@ -511,7 +523,10 @@ discard block |
||
511 | 523 | { |
512 | 524 | $this->log_access($this->reason,$login,$user_ip,0); // log unsuccessfull login |
513 | 525 | } |
514 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)"); |
|
526 | + if (self::ERROR_LOG_DEBUG) |
|
527 | + { |
|
528 | + error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)"); |
|
529 | + } |
|
515 | 530 | return false; |
516 | 531 | } |
517 | 532 | if ($fail_on_forced_password_change && Auth::check_password_change($this->reason) === false) |
@@ -561,7 +576,10 @@ discard block |
||
561 | 576 | $this->reason = 'account is expired'; |
562 | 577 | $this->cd_reason = self::CD_ACCOUNT_EXPIRED; |
563 | 578 | |
564 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)"); |
|
579 | + if (self::ERROR_LOG_DEBUG) |
|
580 | + { |
|
581 | + error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)"); |
|
582 | + } |
|
565 | 583 | return false; |
566 | 584 | } |
567 | 585 | |
@@ -585,25 +603,34 @@ discard block |
||
585 | 603 | 'passwd' => $this->passwd, |
586 | 604 | 'account_domain' => $this->account_domain, |
587 | 605 | 'user_ip' => $user_ip, |
588 | - ),'',true))) // true = run hooks from all apps, not just the ones the current user has perms to run |
|
606 | + ),'',true))) |
|
607 | + { |
|
608 | + // true = run hooks from all apps, not just the ones the current user has perms to run |
|
589 | 609 | { |
590 | 610 | foreach($hook_result as $reason) |
591 | 611 | { |
592 | 612 | if ($reason) // called hook requests to deny the session |
593 | 613 | { |
594 | 614 | $this->reason = $this->cd_reason = $reason; |
615 | + } |
|
595 | 616 | $this->log_access($this->reason,$login,$user_ip,0); // log unsuccessfull login |
596 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)"); |
|
617 | + if (self::ERROR_LOG_DEBUG) |
|
618 | + { |
|
619 | + error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)"); |
|
620 | + } |
|
597 | 621 | return false; |
598 | 622 | } |
599 | 623 | } |
600 | 624 | } |
601 | 625 | $GLOBALS['egw']->db->transaction_begin(); |
602 | 626 | $this->register_session($this->login,$user_ip,$now,$this->session_flags); |
603 | - if ($this->session_flags != 'A') // dont log anonymous sessions |
|
627 | + if ($this->session_flags != 'A') |
|
628 | + { |
|
629 | + // dont log anonymous sessions |
|
604 | 630 | { |
605 | 631 | $this->sessionid_access_log = $this->log_access($this->sessionid,$login,$user_ip,$this->account_id); |
606 | 632 | } |
633 | + } |
|
607 | 634 | Cache::setSession('phpgwapi', 'account_previous_login', $GLOBALS['egw']->auth->previous_login); |
608 | 635 | $GLOBALS['egw']->accounts->update_lastlogin($this->account_id,$user_ip); |
609 | 636 | $GLOBALS['egw']->db->transaction_commit(); |
@@ -619,7 +646,10 @@ discard block |
||
619 | 646 | self::egw_setcookie('last_loginid', $this->account_lid ,$now+1209600); /* For 2 weeks */ |
620 | 647 | self::egw_setcookie('last_domain',$this->account_domain,$now+1209600); |
621 | 648 | } |
622 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) successfull sessionid=$this->sessionid"); |
|
649 | + if (self::ERROR_LOG_DEBUG) |
|
650 | + { |
|
651 | + error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) successfull sessionid=$this->sessionid"); |
|
652 | + } |
|
623 | 653 | |
624 | 654 | return $this->sessionid; |
625 | 655 | } |
@@ -773,10 +803,13 @@ discard block |
||
773 | 803 | //error_log(__METHOD__."('$login', '$ip') false_ip=$false_ip, false_id=$false_id --> blocked=".array2string($blocked)); |
774 | 804 | |
775 | 805 | if ($blocked && $GLOBALS['egw_info']['server']['admin_mails'] && |
776 | - $GLOBALS['egw_info']['server']['login_blocked_mail_time'] < time()-5*60) // max. one mail every 5mins |
|
806 | + $GLOBALS['egw_info']['server']['login_blocked_mail_time'] < time()-5*60) |
|
807 | + { |
|
808 | + // max. one mail every 5mins |
|
777 | 809 | { |
778 | 810 | try { |
779 | 811 | $mailer = new Mailer(); |
812 | + } |
|
780 | 813 | // notify admin(s) via email |
781 | 814 | $mailer->setFrom('eGroupWare@'.$GLOBALS['egw_info']['server']['mail_suffix']); |
782 | 815 | $mailer->addHeader('Subject', lang("eGroupWare: login blocked for user '%1', IP %2",$login,$ip)); |
@@ -854,7 +887,10 @@ discard block |
||
854 | 887 | { |
855 | 888 | $sessionid = false; |
856 | 889 | } |
857 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() _SERVER[REQUEST_URI]='$_SERVER[REQUEST_URI]' returning ".print_r($sessionid,true)); |
|
890 | + if (self::ERROR_LOG_DEBUG) |
|
891 | + { |
|
892 | + error_log(__METHOD__."() _SERVER[REQUEST_URI]='$_SERVER[REQUEST_URI]' returning ".print_r($sessionid,true)); |
|
893 | + } |
|
858 | 894 | return $sessionid; |
859 | 895 | } |
860 | 896 | |
@@ -884,7 +920,10 @@ discard block |
||
884 | 920 | */ |
885 | 921 | function verify($sessionid=null,$kp3=null) |
886 | 922 | { |
887 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid','$kp3') ".function_backtrace()); |
|
923 | + if (self::ERROR_LOG_DEBUG) |
|
924 | + { |
|
925 | + error_log(__METHOD__."('$sessionid','$kp3') ".function_backtrace()); |
|
926 | + } |
|
888 | 927 | |
889 | 928 | $fill_egw_info_and_repositories = !$GLOBALS['egw_info']['flags']['restored_from_session']; |
890 | 929 | |
@@ -900,7 +939,10 @@ discard block |
||
900 | 939 | |
901 | 940 | if (!$this->sessionid) |
902 | 941 | { |
903 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') get_sessionid()='".self::get_sessionid()."' No session ID"); |
|
942 | + if (self::ERROR_LOG_DEBUG) |
|
943 | + { |
|
944 | + error_log(__METHOD__."('$sessionid') get_sessionid()='".self::get_sessionid()."' No session ID"); |
|
945 | + } |
|
904 | 946 | return false; |
905 | 947 | } |
906 | 948 | |
@@ -912,14 +954,20 @@ discard block |
||
912 | 954 | // check if we have a eGroupware session --> return false if not (but dont destroy it!) |
913 | 955 | if (is_null($_SESSION) || !isset($_SESSION[self::EGW_SESSION_VAR])) |
914 | 956 | { |
915 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') session does NOT exist!"); |
|
957 | + if (self::ERROR_LOG_DEBUG) |
|
958 | + { |
|
959 | + error_log(__METHOD__."('$sessionid') session does NOT exist!"); |
|
960 | + } |
|
916 | 961 | return false; |
917 | 962 | } |
918 | 963 | $session =& $_SESSION[self::EGW_SESSION_VAR]; |
919 | 964 | |
920 | 965 | if ($session['session_dla'] <= time() - $GLOBALS['egw_info']['server']['sessions_timeout']) |
921 | 966 | { |
922 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') session timed out!"); |
|
967 | + if (self::ERROR_LOG_DEBUG) |
|
968 | + { |
|
969 | + error_log(__METHOD__."('$sessionid') session timed out!"); |
|
970 | + } |
|
923 | 971 | $this->destroy($sessionid,$kp3); |
924 | 972 | return false; |
925 | 973 | } |
@@ -947,7 +995,10 @@ discard block |
||
947 | 995 | $this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid,'account_lid','u'); |
948 | 996 | if (!$this->account_id) |
949 | 997 | { |
950 | - if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) !accounts::name2id('$this->account_lid')"); |
|
998 | + if (self::ERROR_LOG_DEBUG) |
|
999 | + { |
|
1000 | + error_log("*** Session::verify($sessionid) !accounts::name2id('$this->account_lid')"); |
|
1001 | + } |
|
951 | 1002 | return false; |
952 | 1003 | } |
953 | 1004 | |
@@ -965,7 +1016,10 @@ discard block |
||
965 | 1016 | |
966 | 1017 | if ($GLOBALS['egw']->accounts->is_expired($GLOBALS['egw_info']['user'])) |
967 | 1018 | { |
968 | - if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) accounts is expired"); |
|
1019 | + if (self::ERROR_LOG_DEBUG) |
|
1020 | + { |
|
1021 | + error_log("*** Session::verify($sessionid) accounts is expired"); |
|
1022 | + } |
|
969 | 1023 | return false; |
970 | 1024 | } |
971 | 1025 | $this->passwd = base64_decode(Cache::getSession('phpgwapi', 'password')); |
@@ -976,7 +1030,10 @@ discard block |
||
976 | 1030 | } |
977 | 1031 | if ($this->account_domain != $GLOBALS['egw_info']['user']['domain']) |
978 | 1032 | { |
979 | - if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) wrong domain"); |
|
1033 | + if (self::ERROR_LOG_DEBUG) |
|
1034 | + { |
|
1035 | + error_log("*** Session::verify($sessionid) wrong domain"); |
|
1036 | + } |
|
980 | 1037 | return false; |
981 | 1038 | } |
982 | 1039 | |
@@ -985,7 +1042,10 @@ discard block |
||
985 | 1042 | if (strtoupper(substr(PHP_OS,0,3)) != 'WIN' && (!$GLOBALS['egw_info']['user']['session_ip'] || |
986 | 1043 | $GLOBALS['egw_info']['user']['session_ip'] != $this->getuser_ip())) |
987 | 1044 | { |
988 | - if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) wrong IP"); |
|
1045 | + if (self::ERROR_LOG_DEBUG) |
|
1046 | + { |
|
1047 | + error_log("*** Session::verify($sessionid) wrong IP"); |
|
1048 | + } |
|
989 | 1049 | return false; |
990 | 1050 | } |
991 | 1051 | } |
@@ -998,7 +1058,10 @@ discard block |
||
998 | 1058 | } |
999 | 1059 | if (!$this->account_lid) |
1000 | 1060 | { |
1001 | - if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) !account_lid"); |
|
1061 | + if (self::ERROR_LOG_DEBUG) |
|
1062 | + { |
|
1063 | + error_log("*** Session::verify($sessionid) !account_lid"); |
|
1064 | + } |
|
1002 | 1065 | return false; |
1003 | 1066 | } |
1004 | 1067 | |
@@ -1017,13 +1080,19 @@ discard block |
||
1017 | 1080 | $_REQUEST[self::EGW_SESSION_NAME] === $this->sessionid && |
1018 | 1081 | (!isset($_COOKIE[self::EGW_SESSION_NAME]) || $_COOKIE[self::EGW_SESSION_NAME] !== $_REQUEST[self::EGW_SESSION_NAME])) |
1019 | 1082 | { |
1020 | - if (self::ERROR_LOG_DEBUG) error_log("--> Session::verify($sessionid) SUCCESS, but NO required cookies set --> setting them now"); |
|
1083 | + if (self::ERROR_LOG_DEBUG) |
|
1084 | + { |
|
1085 | + error_log("--> Session::verify($sessionid) SUCCESS, but NO required cookies set --> setting them now"); |
|
1086 | + } |
|
1021 | 1087 | self::egw_setcookie(self::EGW_SESSION_NAME,$this->sessionid); |
1022 | 1088 | self::egw_setcookie('kp3',$this->kp3); |
1023 | 1089 | self::egw_setcookie('domain',$this->account_domain); |
1024 | 1090 | } |
1025 | 1091 | |
1026 | - if (self::ERROR_LOG_DEBUG) error_log("--> Session::verify($sessionid) SUCCESS"); |
|
1092 | + if (self::ERROR_LOG_DEBUG) |
|
1093 | + { |
|
1094 | + error_log("--> Session::verify($sessionid) SUCCESS"); |
|
1095 | + } |
|
1027 | 1096 | |
1028 | 1097 | return true; |
1029 | 1098 | } |
@@ -1043,14 +1112,20 @@ discard block |
||
1043 | 1112 | } |
1044 | 1113 | $this->log_access($sessionid); // log logout-time |
1045 | 1114 | |
1046 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($sessionid,$kp3)"); |
|
1115 | + if (self::ERROR_LOG_DEBUG) |
|
1116 | + { |
|
1117 | + error_log(__METHOD__."($sessionid,$kp3)"); |
|
1118 | + } |
|
1047 | 1119 | |
1048 | - if (is_numeric($sessionid)) // do we have a access-log-id --> get PHP session id |
|
1120 | + if (is_numeric($sessionid)) |
|
1121 | + { |
|
1122 | + // do we have a access-log-id --> get PHP session id |
|
1049 | 1123 | { |
1050 | 1124 | $sessionid = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE,'session_php',array( |
1051 | 1125 | 'sessionid' => $sessionid, |
1052 | 1126 | ),__LINE__,__FILE__)->fetchColumn(); |
1053 | 1127 | } |
1128 | + } |
|
1054 | 1129 | |
1055 | 1130 | Hooks::process(array( |
1056 | 1131 | 'location' => 'session_destroyed', |
@@ -1060,7 +1135,10 @@ discard block |
||
1060 | 1135 | // Only do the following, if where working with the current user |
1061 | 1136 | if (!$GLOBALS['egw_info']['user']['sessionid'] || $sessionid == $GLOBALS['egw_info']['user']['sessionid']) |
1062 | 1137 | { |
1063 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__." ********* about to call session_destroy!"); |
|
1138 | + if (self::ERROR_LOG_DEBUG) |
|
1139 | + { |
|
1140 | + error_log(__METHOD__." ********* about to call session_destroy!"); |
|
1141 | + } |
|
1064 | 1142 | session_unset(); |
1065 | 1143 | @session_destroy(); |
1066 | 1144 | // we need to (re-)load the eGW session-handler, as session_destroy unloads custom session-handlers |
@@ -1155,7 +1233,10 @@ discard block |
||
1155 | 1233 | } |
1156 | 1234 | else |
1157 | 1235 | { |
1158 | - if ($othervars) $extravars .= ($extravars?'&':'').$othervars; |
|
1236 | + if ($othervars) |
|
1237 | + { |
|
1238 | + $extravars .= ($extravars?'&':'').$othervars; |
|
1239 | + } |
|
1159 | 1240 | } |
1160 | 1241 | |
1161 | 1242 | // parse extravars string into the vars array |
@@ -1164,7 +1245,11 @@ discard block |
||
1164 | 1245 | foreach(explode('&',$extravars) as $expr) |
1165 | 1246 | { |
1166 | 1247 | list($var,$val) = explode('=', $expr,2); |
1167 | - if (strpos($val,'%26') != false) $val = str_replace('%26','&',$val); // make sure to not double encode & |
|
1248 | + if (strpos($val,'%26') != false) |
|
1249 | + { |
|
1250 | + $val = str_replace('%26','&',$val); |
|
1251 | + } |
|
1252 | + // make sure to not double encode & |
|
1168 | 1253 | if (substr($var,-2) == '[]') |
1169 | 1254 | { |
1170 | 1255 | $vars[substr($var,0,-2)][] = $val; |
@@ -1245,14 +1330,22 @@ discard block |
||
1245 | 1330 | { |
1246 | 1331 | self::set_cookiedomain(); |
1247 | 1332 | } |
1248 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($cookiename,$cookievalue,$cookietime,$cookiepath,".self::$cookie_domain.")"); |
|
1333 | + if (self::ERROR_LOG_DEBUG) |
|
1334 | + { |
|
1335 | + error_log(__METHOD__."($cookiename,$cookievalue,$cookietime,$cookiepath,".self::$cookie_domain.")"); |
|
1336 | + } |
|
1249 | 1337 | |
1250 | 1338 | // if we are installed in iOS as web-app, we must not set a cookietime==0 (session-cookie), |
1251 | 1339 | // as every change between apps will cause the cookie to get lost |
1252 | 1340 | static $is_iOS = null; |
1253 | - if (!$cookietime && !isset($is_iOS)) $is_iOS = (bool)preg_match('/^(iPhone|iPad|iPod)/i', Header\UserAgent::mobile()); |
|
1341 | + if (!$cookietime && !isset($is_iOS)) |
|
1342 | + { |
|
1343 | + $is_iOS = (bool)preg_match('/^(iPhone|iPad|iPod)/i', Header\UserAgent::mobile()); |
|
1344 | + } |
|
1254 | 1345 | |
1255 | - if(!headers_sent()) // gives only a warning, but can not send the cookie anyway |
|
1346 | + if(!headers_sent()) |
|
1347 | + { |
|
1348 | + // gives only a warning, but can not send the cookie anyway |
|
1256 | 1349 | { |
1257 | 1350 | setcookie($cookiename, $cookievalue, |
1258 | 1351 | !$cookietime && $is_iOS ? time()+self::IOS_SESSION_COOKIE_LIFETIME : $cookietime, |
@@ -1260,6 +1353,7 @@ discard block |
||
1260 | 1353 | // if called via HTTPS, only send cookie for https and only allow cookie access via HTTP (true) |
1261 | 1354 | empty($GLOBALS['egw_info']['server']['insecure_cookies']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off', true); |
1262 | 1355 | } |
1356 | + } |
|
1263 | 1357 | } |
1264 | 1358 | |
1265 | 1359 | /** |
@@ -1311,15 +1405,25 @@ discard block |
||
1311 | 1405 | */ |
1312 | 1406 | public static function search_instance($login,$domain_requested,&$default_domain,$server_names,array $domains=null) |
1313 | 1407 | { |
1314 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$login','$domain_requested',".array2string($default_domain).".".array2string($server_names).".".array2string($domains).")"); |
|
1408 | + if (self::ERROR_LOG_DEBUG) |
|
1409 | + { |
|
1410 | + error_log(__METHOD__."('$login','$domain_requested',".array2string($default_domain).".".array2string($server_names).".".array2string($domains).")"); |
|
1411 | + } |
|
1315 | 1412 | |
1316 | - if (is_null($domains)) $domains = $GLOBALS['egw_domain']; |
|
1413 | + if (is_null($domains)) |
|
1414 | + { |
|
1415 | + $domains = $GLOBALS['egw_domain']; |
|
1416 | + } |
|
1317 | 1417 | |
1318 | - if (!isset($default_domain) || !isset($domains[$default_domain])) // allow to overwrite the default domain |
|
1418 | + if (!isset($default_domain) || !isset($domains[$default_domain])) |
|
1419 | + { |
|
1420 | + // allow to overwrite the default domain |
|
1319 | 1421 | { |
1320 | 1422 | foreach((array)$server_names as $server_name) |
1321 | 1423 | { |
1322 | - list($server_name) = explode(':', $server_name); // remove port from HTTP_HOST |
|
1424 | + list($server_name) = explode(':', $server_name); |
|
1425 | + } |
|
1426 | + // remove port from HTTP_HOST |
|
1323 | 1427 | if(isset($domains[$server_name])) |
1324 | 1428 | { |
1325 | 1429 | $default_domain = $server_name; |
@@ -1344,11 +1448,14 @@ discard block |
||
1344 | 1448 | } |
1345 | 1449 | } |
1346 | 1450 | } |
1347 | - if (isset($login)) // on login |
|
1451 | + if (isset($login)) |
|
1452 | + { |
|
1453 | + // on login |
|
1348 | 1454 | { |
1349 | 1455 | if (strpos($login,'@') === false || count($domains) == 1) |
1350 | 1456 | { |
1351 | 1457 | $login .= '@' . (isset($_POST['logindomain']) ? $_POST['logindomain'] : $default_domain); |
1458 | + } |
|
1352 | 1459 | } |
1353 | 1460 | $parts = explode('@',$login); |
1354 | 1461 | $domain = array_pop($parts); |
@@ -1362,7 +1469,10 @@ discard block |
||
1362 | 1469 | { |
1363 | 1470 | $domain = $default_domain; |
1364 | 1471 | } |
1365 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() default_domain=".array2string($default_domain).', login='.array2string($login)." returning ".array2string($domain)); |
|
1472 | + if (self::ERROR_LOG_DEBUG) |
|
1473 | + { |
|
1474 | + error_log(__METHOD__."() default_domain=".array2string($default_domain).', login='.array2string($login)." returning ".array2string($domain)); |
|
1475 | + } |
|
1366 | 1476 | |
1367 | 1477 | return $domain; |
1368 | 1478 | } |
@@ -1401,7 +1511,10 @@ discard block |
||
1401 | 1511 | $action = $_SERVER['PHP_SELF']; |
1402 | 1512 | // remove EGroupware path, if not installed in webroot |
1403 | 1513 | $egw_path = $GLOBALS['egw_info']['server']['webserver_url']; |
1404 | - if ($egw_path[0] != '/') $egw_path = parse_url($egw_path,PHP_URL_PATH); |
|
1514 | + if ($egw_path[0] != '/') |
|
1515 | + { |
|
1516 | + $egw_path = parse_url($egw_path,PHP_URL_PATH); |
|
1517 | + } |
|
1405 | 1518 | if ($action == '/Microsoft-Server-ActiveSync') |
1406 | 1519 | { |
1407 | 1520 | $action .= '?Cmd='.$_GET['Cmd'].'&DeviceId='.$_GET['DeviceId']; |
@@ -1427,7 +1540,10 @@ discard block |
||
1427 | 1540 | |
1428 | 1541 | $_SESSION[self::EGW_SESSION_VAR]['session_dla'] = time(); |
1429 | 1542 | $_SESSION[self::EGW_SESSION_VAR]['session_action'] = $this->action; |
1430 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__.'() _SESSION['.self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR])); |
|
1543 | + if (self::ERROR_LOG_DEBUG) |
|
1544 | + { |
|
1545 | + error_log(__METHOD__.'() _SESSION['.self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR])); |
|
1546 | + } |
|
1431 | 1547 | |
1432 | 1548 | return $this->action; |
1433 | 1549 | } |
@@ -1553,7 +1669,10 @@ discard block |
||
1553 | 1669 | */ |
1554 | 1670 | public static function init_handler() |
1555 | 1671 | { |
1556 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__.'() session_handler='.self::$session_handler.', egw_info[server][session_handler]='.$GLOBALS['egw_info']['server']['session_handler'].' called from:'.function_backtrace()); |
|
1672 | + if (self::ERROR_LOG_DEBUG) |
|
1673 | + { |
|
1674 | + error_log(__METHOD__.'() session_handler='.self::$session_handler.', egw_info[server][session_handler]='.$GLOBALS['egw_info']['server']['session_handler'].' called from:'.function_backtrace()); |
|
1675 | + } |
|
1557 | 1676 | |
1558 | 1677 | ini_set('session.use_cookies',0); // disable the automatic use of cookies, as it uses the path / by default |
1559 | 1678 | session_name(self::EGW_SESSION_NAME); |
@@ -1563,10 +1682,16 @@ discard block |
||
1563 | 1682 | self::cache_control(); |
1564 | 1683 | $ok = session_start(); |
1565 | 1684 | self::decrypt(); |
1566 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() sessionid=$sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR])); |
|
1685 | + if (self::ERROR_LOG_DEBUG) |
|
1686 | + { |
|
1687 | + error_log(__METHOD__."() sessionid=$sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR])); |
|
1688 | + } |
|
1567 | 1689 | return $ok; |
1568 | 1690 | } |
1569 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() no active session!"); |
|
1691 | + if (self::ERROR_LOG_DEBUG) |
|
1692 | + { |
|
1693 | + error_log(__METHOD__."() no active session!"); |
|
1694 | + } |
|
1570 | 1695 | |
1571 | 1696 | return false; |
1572 | 1697 | } |
@@ -1624,9 +1749,12 @@ discard block |
||
1624 | 1749 | error_log(__METHOD__."($expire) called, but header already sent in $file: $line"); |
1625 | 1750 | return; |
1626 | 1751 | } |
1627 | - if($expire === true) // same behavior as session_cache_limiter('private_no_expire') |
|
1752 | + if($expire === true) |
|
1753 | + { |
|
1754 | + // same behavior as session_cache_limiter('private_no_expire') |
|
1628 | 1755 | { |
1629 | 1756 | header('Cache-Control: private, max-age='.(60*session_cache_expire())); |
1757 | + } |
|
1630 | 1758 | header_remove('Expires'); |
1631 | 1759 | } |
1632 | 1760 | elseif ($private) |
@@ -1640,10 +1768,13 @@ discard block |
||
1640 | 1768 | header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expire) . ' GMT'); |
1641 | 1769 | } |
1642 | 1770 | // remove Pragma header, might be set by old header |
1643 | - if (function_exists('header_remove')) // PHP 5.3+ |
|
1771 | + if (function_exists('header_remove')) |
|
1772 | + { |
|
1773 | + // PHP 5.3+ |
|
1644 | 1774 | { |
1645 | 1775 | header_remove('Pragma'); |
1646 | 1776 | } |
1777 | + } |
|
1647 | 1778 | else |
1648 | 1779 | { |
1649 | 1780 | header('Pragma:'); |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | * @param string $join ='' sql to do a join, added as is after the table-name, eg. ", table2 WHERE x=y" or |
367 | 367 | * "LEFT JOIN table2 ON (x=y)", Note: there's no quoting done on $join! |
368 | 368 | * @param boolean $need_full_no_count =false If true an unlimited query is run to determine the total number of rows, default false |
369 | - * @param mixed $only_keys =false, see search |
|
369 | + * @param boolean $only_keys =false, see search |
|
370 | 370 | * @param string|array $extra_cols =array() |
371 | 371 | * @return int total number of rows |
372 | 372 | */ |
@@ -734,7 +734,7 @@ discard block |
||
734 | 734 | * Check if cf is stored as 1:N relation in DB and array in memory |
735 | 735 | * |
736 | 736 | * @param string $name |
737 | - * @return string |
|
737 | + * @return boolean |
|
738 | 738 | */ |
739 | 739 | function is_multiple($name) |
740 | 740 | { |
@@ -210,12 +210,12 @@ |
||
210 | 210 | } |
211 | 211 | |
212 | 212 | /** |
213 | - * saves custom field data |
|
214 | - * |
|
215 | - * @param array $data data to save (cf's have to be prefixed with self::CF_PREFIX = #) |
|
216 | - * @param array $extra_cols =array() extra-data to be saved |
|
217 | - * @return bool false on success, errornumber on failure |
|
218 | - */ |
|
213 | + * saves custom field data |
|
214 | + * |
|
215 | + * @param array $data data to save (cf's have to be prefixed with self::CF_PREFIX = #) |
|
216 | + * @param array $extra_cols =array() extra-data to be saved |
|
217 | + * @return bool false on success, errornumber on failure |
|
218 | + */ |
|
219 | 219 | function save_customfields($data, array $extra_cols=array()) |
220 | 220 | { |
221 | 221 | foreach (array_keys((array)$this->customfields) as $name) |
@@ -118,41 +118,41 @@ discard block |
||
118 | 118 | * @param boolean $allow_multiple_values =false should we allow AND store multiple values (1:N relations) |
119 | 119 | * @param string $timestamp_type =null default null=leave them as is, 'ts'|'integer' use integer unix timestamps, 'object' use DateTime objects |
120 | 120 | */ |
121 | - function __construct($app,$table,$extra_table,$column_prefix='', |
|
122 | - $extra_key='_name',$extra_value='_value',$extra_id='_id', |
|
123 | - Db $db=null,$no_clone=true,$allow_multiple_values=false,$timestamp_type=null) |
|
121 | + function __construct($app, $table, $extra_table, $column_prefix = '', |
|
122 | + $extra_key = '_name', $extra_value = '_value', $extra_id = '_id', |
|
123 | + Db $db = null, $no_clone = true, $allow_multiple_values = false, $timestamp_type = null) |
|
124 | 124 | { |
125 | 125 | // calling the Storage\Base constructor |
126 | - parent::__construct($app,$table,$db,$column_prefix,$no_clone,$timestamp_type); |
|
126 | + parent::__construct($app, $table, $db, $column_prefix, $no_clone, $timestamp_type); |
|
127 | 127 | |
128 | 128 | $this->allow_multiple_values = $allow_multiple_values; |
129 | 129 | $this->extra_table = $extra_table; |
130 | - if (!$this->extra_id) $this->extra_id = $this->autoinc_id; // default to auto id of regular table |
|
130 | + if (!$this->extra_id) $this->extra_id = $this->autoinc_id; // default to auto id of regular table |
|
131 | 131 | |
132 | 132 | // if names from columns of extra table are only postfixes (starting with _), prepend column prefix |
133 | - if (!($prefix=$column_prefix)) |
|
133 | + if (!($prefix = $column_prefix)) |
|
134 | 134 | { |
135 | - list($prefix) = explode('_',$this->autoinc_id); |
|
135 | + list($prefix) = explode('_', $this->autoinc_id); |
|
136 | 136 | } |
137 | - elseif(substr($prefix,-1) == '_') |
|
137 | + elseif (substr($prefix, -1) == '_') |
|
138 | 138 | { |
139 | - $prefix = substr($prefix,0,-1); // remove trailing underscore from column prefix parameter |
|
139 | + $prefix = substr($prefix, 0, -1); // remove trailing underscore from column prefix parameter |
|
140 | 140 | } |
141 | - foreach(array( |
|
141 | + foreach (array( |
|
142 | 142 | 'extra_id' => $extra_id, |
143 | 143 | 'extra_key' => $extra_key, |
144 | 144 | 'extra_value' => $extra_value |
145 | 145 | ) as $col => $val) |
146 | 146 | { |
147 | 147 | $this->$col = $col_name = $val; |
148 | - if ($col_name[0] == '_') $this->$col = $prefix . $val; |
|
148 | + if ($col_name[0] == '_') $this->$col = $prefix.$val; |
|
149 | 149 | } |
150 | 150 | // some sanity checks, maybe they should be active only for development |
151 | - if (!($extra_defs = $this->db->get_table_definitions($app,$extra_table))) |
|
151 | + if (!($extra_defs = $this->db->get_table_definitions($app, $extra_table))) |
|
152 | 152 | { |
153 | 153 | throw new Exception\WrongParameter("extra table $extra_table is NOT defined!"); |
154 | 154 | } |
155 | - foreach(array('extra_id','extra_key','extra_value') as $col) |
|
155 | + foreach (array('extra_id', 'extra_key', 'extra_value') as $col) |
|
156 | 156 | { |
157 | 157 | if (!$this->$col || !isset($extra_defs['fd'][$this->$col])) |
158 | 158 | { |
@@ -177,23 +177,23 @@ discard block |
||
177 | 177 | * @param array $field_names =null custom fields to read, default all |
178 | 178 | * @return array id => $this->cf_field(name) => value |
179 | 179 | */ |
180 | - function read_customfields($ids,$field_names=null) |
|
180 | + function read_customfields($ids, $field_names = null) |
|
181 | 181 | { |
182 | 182 | if (is_null($field_names)) $field_names = array_keys($this->customfields); |
183 | 183 | |
184 | - foreach((array)$ids as $key => $id) |
|
184 | + foreach ((array)$ids as $key => $id) |
|
185 | 185 | { |
186 | 186 | if (!(int)$id && is_array($ids)) unset($ids[$key]); |
187 | 187 | } |
188 | - if (!$ids || !$field_names) return array(); // nothing to do |
|
188 | + if (!$ids || !$field_names) return array(); // nothing to do |
|
189 | 189 | |
190 | 190 | $entries = array(); |
191 | - foreach($this->db->select($this->extra_table,'*',array( |
|
191 | + foreach ($this->db->select($this->extra_table, '*', array( |
|
192 | 192 | $this->extra_id => $ids, |
193 | 193 | $this->extra_key => $field_names, |
194 | - ),__LINE__,__FILE__,false,'',$this->app) as $row) |
|
194 | + ), __LINE__, __FILE__, false, '', $this->app) as $row) |
|
195 | 195 | { |
196 | - $entry =& $entries[$row[$this->extra_id]]; |
|
196 | + $entry = & $entries[$row[$this->extra_id]]; |
|
197 | 197 | if (!is_array($entry)) $entry = array(); |
198 | 198 | $field = $this->get_cf_field($row[$this->extra_key]); |
199 | 199 | |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | * @param array $extra_cols =array() extra-data to be saved |
217 | 217 | * @return bool false on success, errornumber on failure |
218 | 218 | */ |
219 | - function save_customfields($data, array $extra_cols=array()) |
|
219 | + function save_customfields($data, array $extra_cols = array()) |
|
220 | 220 | { |
221 | 221 | foreach (array_keys((array)$this->customfields) as $name) |
222 | 222 | { |
@@ -229,22 +229,21 @@ discard block |
||
229 | 229 | $is_multiple = $this->is_multiple($name); |
230 | 230 | |
231 | 231 | // we explicitly need to delete fields, if value is empty or field allows multiple values or we have no unique index |
232 | - if(empty($data[$field]) || $is_multiple || !$this->extra_has_unique_index) |
|
232 | + if (empty($data[$field]) || $is_multiple || !$this->extra_has_unique_index) |
|
233 | 233 | { |
234 | - $this->db->delete($this->extra_table,$where,__LINE__,__FILE__,$this->app); |
|
235 | - if (empty($data[$field])) continue; // nothing else to do for empty values |
|
234 | + $this->db->delete($this->extra_table, $where, __LINE__, __FILE__, $this->app); |
|
235 | + if (empty($data[$field])) continue; // nothing else to do for empty values |
|
236 | 236 | } |
237 | - foreach($is_multiple && !is_array($data[$field]) ? explode(',',$data[$field]) : |
|
238 | - // regular custom fields (!$is_multiple) eg. addressbook store multiple values comma-separated |
|
237 | + foreach ($is_multiple && !is_array($data[$field]) ? explode(',', $data[$field]) : // regular custom fields (!$is_multiple) eg. addressbook store multiple values comma-separated |
|
239 | 238 | (array)(!$is_multiple && is_array($data[$field]) ? implode(',', $data[$field]) : $data[$field]) as $value) |
240 | 239 | { |
241 | - if (!$this->db->insert($this->extra_table,array($this->extra_value => $value)+$extra_cols,$where,__LINE__,__FILE__,$this->app)) |
|
240 | + if (!$this->db->insert($this->extra_table, array($this->extra_value => $value) + $extra_cols, $where, __LINE__, __FILE__, $this->app)) |
|
242 | 241 | { |
243 | 242 | return $this->db->Errno; |
244 | 243 | } |
245 | 244 | } |
246 | 245 | } |
247 | - return false; // no error |
|
246 | + return false; // no error |
|
248 | 247 | } |
249 | 248 | |
250 | 249 | /** |
@@ -260,7 +259,7 @@ discard block |
||
260 | 259 | |
261 | 260 | if ($this->customfields) |
262 | 261 | { |
263 | - foreach(array_keys($this->customfields) as $name) |
|
262 | + foreach (array_keys($this->customfields) as $name) |
|
264 | 263 | { |
265 | 264 | if (isset($new[$field = $this->get_cf_field($name)])) |
266 | 265 | { |
@@ -280,16 +279,16 @@ discard block |
||
280 | 279 | * @param string $join sql to do a join, added as is after the table-name, eg. ", table2 WHERE x=y" or |
281 | 280 | * @return array|boolean data if row could be retrived else False |
282 | 281 | */ |
283 | - function read($keys,$extra_cols='',$join='') |
|
282 | + function read($keys, $extra_cols = '', $join = '') |
|
284 | 283 | { |
285 | - if (!parent::read($keys,$extra_cols,$join)) |
|
284 | + if (!parent::read($keys, $extra_cols, $join)) |
|
286 | 285 | { |
287 | 286 | return false; |
288 | 287 | } |
289 | 288 | if (($id = (int)$this->data[$this->db_key_cols[$this->autoinc_id]]) && $this->customfields && |
290 | 289 | ($cfs = $this->read_customfields($id))) |
291 | 290 | { |
292 | - $this->data = array_merge($this->data,$cfs[$id]); |
|
291 | + $this->data = array_merge($this->data, $cfs[$id]); |
|
293 | 292 | } |
294 | 293 | return $this->data; |
295 | 294 | } |
@@ -303,14 +302,14 @@ discard block |
||
303 | 302 | * @param string|array $extra_where =null extra where clause, eg. to check an etag, returns true if no affected rows! |
304 | 303 | * @return int|boolean 0 on success, or errno != 0 on error, or true if $extra_where is given and no rows affected |
305 | 304 | */ |
306 | - function save($keys=null,$extra_where=null) |
|
305 | + function save($keys = null, $extra_where = null) |
|
307 | 306 | { |
308 | 307 | if (is_array($keys) && count($keys) && !isset($keys[0])) // allow to use an etag, eg array('etag=etag+1') |
309 | 308 | { |
310 | 309 | $this->data_merge($keys); |
311 | 310 | $keys = null; |
312 | 311 | } |
313 | - $ret = parent::save($keys,$extra_where); |
|
312 | + $ret = parent::save($keys, $extra_where); |
|
314 | 313 | |
315 | 314 | if ($ret == 0 && $this->customfields) |
316 | 315 | { |
@@ -328,26 +327,26 @@ discard block |
||
328 | 327 | * @param boolean $only_return_ids =false return $ids of delete call to db object, but not run it (can be used by extending classes!) |
329 | 328 | * @return int|array affected rows, should be 1 if ok, 0 if an error or array with id's if $only_return_ids |
330 | 329 | */ |
331 | - function delete($keys=null,$only_return_ids=false) |
|
330 | + function delete($keys = null, $only_return_ids = false) |
|
332 | 331 | { |
333 | 332 | if ($this->customfields || $only_return_ids) |
334 | 333 | { |
335 | - $query = parent::delete($keys,true); |
|
334 | + $query = parent::delete($keys, true); |
|
336 | 335 | // check if query contains more then the id's |
337 | 336 | if (!isset($query[$this->autoinc_id]) || count($query) != 1) |
338 | 337 | { |
339 | - foreach($this->db->select($this->table_name,$this->autoinc_id,$query,__LINE__,__FILE__,false,'',$this->app) as $row) |
|
338 | + foreach ($this->db->select($this->table_name, $this->autoinc_id, $query, __LINE__, __FILE__, false, '', $this->app) as $row) |
|
340 | 339 | { |
341 | 340 | $ids[] = $row[$this->autoinc_id]; |
342 | 341 | } |
343 | - if (!$ids) return 0; // no rows affected |
|
342 | + if (!$ids) return 0; // no rows affected |
|
344 | 343 | } |
345 | 344 | else |
346 | 345 | { |
347 | 346 | $ids = (array)$query[$this->autoinc_id]; |
348 | 347 | } |
349 | 348 | if ($only_return_ids) return $ids; |
350 | - $this->db->delete($this->extra_table,array($this->extra_id => $ids),__LINE__,__FILE__); |
|
349 | + $this->db->delete($this->extra_table, array($this->extra_id => $ids), __LINE__, __FILE__); |
|
351 | 350 | } |
352 | 351 | return parent::delete($keys); |
353 | 352 | } |
@@ -370,32 +369,32 @@ discard block |
||
370 | 369 | * @param string|array $extra_cols =array() |
371 | 370 | * @return int total number of rows |
372 | 371 | */ |
373 | - function get_rows($query,&$rows,&$readonlys,$join='',$need_full_no_count=false,$only_keys=false,$extra_cols=array()) |
|
372 | + function get_rows($query, &$rows, &$readonlys, $join = '', $need_full_no_count = false, $only_keys = false, $extra_cols = array()) |
|
374 | 373 | { |
375 | - parent::get_rows($query,$rows,$readonlys,$join,$need_full_no_count,$only_keys,$extra_cols); |
|
374 | + parent::get_rows($query, $rows, $readonlys, $join, $need_full_no_count, $only_keys, $extra_cols); |
|
376 | 375 | |
377 | - $selectcols = $query['selectcols'] ? explode(',',$query['selectcols']) : array(); |
|
376 | + $selectcols = $query['selectcols'] ? explode(',', $query['selectcols']) : array(); |
|
378 | 377 | |
379 | - if ($rows && $this->customfields && (!$selectcols || in_array('customfields',$selectcols))) |
|
378 | + if ($rows && $this->customfields && (!$selectcols || in_array('customfields', $selectcols))) |
|
380 | 379 | { |
381 | 380 | $id2keys = array(); |
382 | - foreach($rows as $key => $row) |
|
381 | + foreach ($rows as $key => $row) |
|
383 | 382 | { |
384 | 383 | $id2keys[$row[$this->db_key_cols[$this->autoinc_id]]] = $key; |
385 | 384 | } |
386 | 385 | // check if only certain cf's to show |
387 | 386 | if (!in_array('customfields', $selectcols)) |
388 | 387 | { |
389 | - foreach($selectcols as $col) |
|
388 | + foreach ($selectcols as $col) |
|
390 | 389 | { |
391 | 390 | if ($this->is_cf($col)) $fields[] = $this->get_cf_name($col); |
392 | 391 | } |
393 | 392 | } |
394 | - if (($cfs = $this->read_customfields(array_keys($id2keys),$fields))) |
|
393 | + if (($cfs = $this->read_customfields(array_keys($id2keys), $fields))) |
|
395 | 394 | { |
396 | - foreach($cfs as $id => $data) |
|
395 | + foreach ($cfs as $id => $data) |
|
397 | 396 | { |
398 | - $rows[$id2keys[$id]] = array_merge($rows[$id2keys[$id]],$data); |
|
397 | + $rows[$id2keys[$id]] = array_merge($rows[$id2keys[$id]], $data); |
|
399 | 398 | } |
400 | 399 | } |
401 | 400 | } |
@@ -422,12 +421,12 @@ discard block |
||
422 | 421 | * @param boolean $need_full_no_count =false If true an unlimited query is run to determine the total number of rows, default false |
423 | 422 | * @return array|NULL array of matching rows (the row is an array of the cols) or NULL |
424 | 423 | */ |
425 | - function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false) |
|
424 | + function &search($criteria, $only_keys = True, $order_by = '', $extra_cols = '', $wildcard = '', $empty = False, $op = 'AND', $start = false, $filter = null, $join = '', $need_full_no_count = false) |
|
426 | 425 | { |
427 | 426 | //error_log(__METHOD__.'('.array2string(array_combine(array_slice(array('criteria','only_keys','order_by','extra_cols','wildcard','empty','op','start','filter','join','need_full_no_count'), 0, count(func_get_args())), func_get_args())).')'); |
428 | 427 | if (!$this->customfields) |
429 | 428 | { |
430 | - return parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count); |
|
429 | + return parent::search($criteria, $only_keys, $order_by, $extra_cols, $wildcard, $empty, $op, $start, $filter, $join, $need_full_no_count); |
|
431 | 430 | } |
432 | 431 | if ($only_keys === false) |
433 | 432 | { |
@@ -436,7 +435,7 @@ discard block |
||
436 | 435 | // if string given as criteria --> search in all (or $this->columns_to_search) columns including custom fields |
437 | 436 | if ($criteria && is_string($criteria)) |
438 | 437 | { |
439 | - $criteria = $this->search2criteria($criteria,$wildcard,$op); |
|
438 | + $criteria = $this->search2criteria($criteria, $wildcard, $op); |
|
440 | 439 | } |
441 | 440 | if ($criteria && is_array($criteria)) |
442 | 441 | { |
@@ -445,10 +444,10 @@ discard block |
||
445 | 444 | { |
446 | 445 | if (($negate = $criteria[$this->extra_value][0] === '!')) |
447 | 446 | { |
448 | - $criteria[$this->extra_value] = substr($criteria[$this->extra_value],1); |
|
447 | + $criteria[$this->extra_value] = substr($criteria[$this->extra_value], 1); |
|
449 | 448 | } |
450 | - $criteria[] = $this->extra_table.'.'.$this->extra_value . ' ' .($negate ? 'NOT ' : ''). |
|
451 | - $this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE]. ' ' . |
|
449 | + $criteria[] = $this->extra_table.'.'.$this->extra_value.' '.($negate ? 'NOT ' : ''). |
|
450 | + $this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '. |
|
452 | 451 | $this->db->quote($wildcard.$criteria[$this->extra_value].$wildcard); |
453 | 452 | unset($criteria[$this->extra_value]); |
454 | 453 | } |
@@ -457,14 +456,14 @@ discard block |
||
457 | 456 | { |
458 | 457 | if ($criteria[$this->autoinc_id]) |
459 | 458 | { |
460 | - $criteria[] = $this->db->expression($this->table_name,$this->table_name.'.', |
|
459 | + $criteria[] = $this->db->expression($this->table_name, $this->table_name.'.', |
|
461 | 460 | array($this->autoinc_id => $criteria[$this->autoinc_id])); |
462 | 461 | } |
463 | 462 | unset($criteria[$this->autoinc_id]); |
464 | 463 | } |
465 | 464 | // replace ambiguous column with (an exact match of) table_name.column |
466 | 465 | $extra_join_added = $join && strpos($join, $this->extra_join) !== false; |
467 | - foreach($criteria as $name => $val) |
|
466 | + foreach ($criteria as $name => $val) |
|
468 | 467 | { |
469 | 468 | // only add extra_join, if we really need it |
470 | 469 | if (!$extra_join_added && ( |
@@ -476,9 +475,9 @@ discard block |
||
476 | 475 | $extra_join_added = true; |
477 | 476 | } |
478 | 477 | $extra_columns = $this->db->get_table_definitions($this->app, $this->extra_table); |
479 | - if(is_string($name) && $extra_columns['fd'][array_search($name, $this->db_cols)]) |
|
478 | + if (is_string($name) && $extra_columns['fd'][array_search($name, $this->db_cols)]) |
|
480 | 479 | { |
481 | - $criteria[] = $this->db->expression($this->table_name,$this->table_name.'.',array( |
|
480 | + $criteria[] = $this->db->expression($this->table_name, $this->table_name.'.', array( |
|
482 | 481 | array_search($name, $this->db_cols) => $val, |
483 | 482 | )); |
484 | 483 | unset($criteria[$name]); |
@@ -490,12 +489,12 @@ discard block |
||
490 | 489 | $name = substr($name, 1); |
491 | 490 | if (($negate = $criteria[$name][0] === '!')) |
492 | 491 | { |
493 | - $val = substr($val,1); |
|
492 | + $val = substr($val, 1); |
|
494 | 493 | } |
495 | - $cfcriteria[] = '(' . $this->extra_table.'.'.$this->extra_value . ' ' .($negate ? 'NOT ' : ''). |
|
496 | - $this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE]. ' ' . |
|
497 | - $this->db->quote($wildcard.$val.$wildcard) . ' AND ' . |
|
498 | - $this->extra_table.'.'.$this->extra_key . ' = ' . $this->db->quote($name) . |
|
494 | + $cfcriteria[] = '('.$this->extra_table.'.'.$this->extra_value.' '.($negate ? 'NOT ' : ''). |
|
495 | + $this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '. |
|
496 | + $this->db->quote($wildcard.$val.$wildcard).' AND '. |
|
497 | + $this->extra_table.'.'.$this->extra_key.' = '.$this->db->quote($name). |
|
499 | 498 | ')'; |
500 | 499 | unset($criteria[self::CF_PREFIX.$name]); |
501 | 500 | } |
@@ -507,38 +506,38 @@ discard block |
||
507 | 506 | } |
508 | 507 | } |
509 | 508 | } |
510 | - if ($cfcriteria && $op =='OR') $criteria[] = implode(' OR ',$cfcriteria); |
|
509 | + if ($cfcriteria && $op == 'OR') $criteria[] = implode(' OR ', $cfcriteria); |
|
511 | 510 | } |
512 | - if($only_keys === true) |
|
511 | + if ($only_keys === true) |
|
513 | 512 | { |
514 | 513 | // Expand to keys here, so table_name can be prepended below |
515 | 514 | $only_keys = array_values($this->db_key_cols); |
516 | 515 | } |
517 | 516 | // replace ambiguous column with (an exact match of) table_name.column |
518 | - if(is_array($only_keys)) |
|
517 | + if (is_array($only_keys)) |
|
519 | 518 | { |
520 | - foreach($only_keys as $key => &$col) |
|
519 | + foreach ($only_keys as $key => &$col) |
|
521 | 520 | { |
522 | - if(is_numeric($key) && in_array($col, $this->db_cols, true)) |
|
521 | + if (is_numeric($key) && in_array($col, $this->db_cols, true)) |
|
523 | 522 | { |
524 | - $col = $this->table_name .'.'.array_search($col, $this->db_cols).' AS '.$col; |
|
523 | + $col = $this->table_name.'.'.array_search($col, $this->db_cols).' AS '.$col; |
|
525 | 524 | } |
526 | 525 | } |
527 | 526 | } |
528 | 527 | // check if we order by a custom field --> join cf table for given cf and order by it's value |
529 | - if (strpos($order_by,self::CF_PREFIX) !== false) |
|
528 | + if (strpos($order_by, self::CF_PREFIX) !== false) |
|
530 | 529 | { |
531 | 530 | // fields to order by, as cutomfields may have names with spaces, we examine each order by criteria |
532 | - $fields2order = explode(',',$order_by); |
|
533 | - foreach($fields2order as $v) |
|
531 | + $fields2order = explode(',', $order_by); |
|
532 | + foreach ($fields2order as $v) |
|
534 | 533 | { |
535 | - if (strpos($v,self::CF_PREFIX) !== false) |
|
534 | + if (strpos($v, self::CF_PREFIX) !== false) |
|
536 | 535 | { |
537 | 536 | // we found a customfield, so we split that part by space char in order to get Sorting Direction and Fieldname |
538 | - $buff = explode(' ',trim($v)); |
|
537 | + $buff = explode(' ', trim($v)); |
|
539 | 538 | $orderDir = array_pop($buff); |
540 | - $key = substr(trim(implode(' ',$buff)), 1); |
|
541 | - switch($this->customfields[$key]['type']) |
|
539 | + $key = substr(trim(implode(' ', $buff)), 1); |
|
540 | + switch ($this->customfields[$key]['type']) |
|
542 | 541 | { |
543 | 542 | case 'int': |
544 | 543 | $order_by = str_replace($v, 'extra_order.'.$this->extra_value.' IS NULL,'. |
@@ -571,26 +570,26 @@ discard block |
||
571 | 570 | { |
572 | 571 | $_cfnames = array_keys($this->customfields); |
573 | 572 | $extra_filter = null; |
574 | - foreach($filter as $name => $val) |
|
573 | + foreach ($filter as $name => $val) |
|
575 | 574 | { |
576 | 575 | // replace ambiguous auto-id with (an exact match of) table_name.autoid |
577 | 576 | if (is_string($name) && $name == $this->autoinc_id) |
578 | 577 | { |
579 | 578 | if ((int)$filter[$this->autoinc_id]) |
580 | 579 | { |
581 | - $filter[] = $this->db->expression($this->table_name,$this->table_name.'.',array( |
|
580 | + $filter[] = $this->db->expression($this->table_name, $this->table_name.'.', array( |
|
582 | 581 | $this->autoinc_id => $filter[$this->autoinc_id], |
583 | 582 | )); |
584 | 583 | } |
585 | 584 | unset($filter[$this->autoinc_id]); |
586 | 585 | } |
587 | 586 | // replace ambiguous column with (an exact match of) table_name.column |
588 | - elseif (is_string($name) && $val!=null && in_array($name, $this->db_cols)) |
|
587 | + elseif (is_string($name) && $val != null && in_array($name, $this->db_cols)) |
|
589 | 588 | { |
590 | 589 | $extra_columns = $this->db->get_table_definitions($this->app, $this->extra_table); |
591 | 590 | if ($extra_columns['fd'][array_search($name, $this->db_cols)]) |
592 | 591 | { |
593 | - $filter[] = $this->db->expression($this->table_name,$this->table_name.'.',array( |
|
592 | + $filter[] = $this->db->expression($this->table_name, $this->table_name.'.', array( |
|
594 | 593 | array_search($name, $this->db_cols) => $val, |
595 | 594 | )); |
596 | 595 | unset($filter[$name]); |
@@ -602,61 +601,61 @@ discard block |
||
602 | 601 | { |
603 | 602 | if ($val[0] === '!') // negative filter |
604 | 603 | { |
605 | - $sql_filter = 'extra_filter.'.$this->extra_value.'!='.$this->db->quote(substr($val,1)); |
|
604 | + $sql_filter = 'extra_filter.'.$this->extra_value.'!='.$this->db->quote(substr($val, 1)); |
|
606 | 605 | } |
607 | 606 | else // using Db::expression to allow to use array() with possible values or NULL |
608 | 607 | { |
609 | - if($this->customfields[$this->get_cf_name($name)]['type'] == 'select' && |
|
608 | + if ($this->customfields[$this->get_cf_name($name)]['type'] == 'select' && |
|
610 | 609 | $this->customfields[$this->get_cf_name($name)]['rows'] > 1) |
611 | 610 | { |
612 | 611 | // Multi-select - any entry with the filter value selected matches |
613 | - $sql_filter = str_replace($this->extra_value,'extra_filter.'. |
|
614 | - $this->extra_value,$this->db->expression($this->extra_table,array( |
|
615 | - $this->db->concat("','",$this->extra_value,"','").' '.$this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote('%,'.$val.',%') |
|
612 | + $sql_filter = str_replace($this->extra_value, 'extra_filter.'. |
|
613 | + $this->extra_value, $this->db->expression($this->extra_table, array( |
|
614 | + $this->db->concat("','", $this->extra_value, "','").' '.$this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote('%,'.$val.',%') |
|
616 | 615 | )) |
617 | 616 | ); |
618 | 617 | } |
619 | 618 | elseif ($this->customfields[$this->get_cf_name($name)]['type'] == 'text') |
620 | 619 | { |
621 | - $sql_filter = str_replace($this->extra_value,'extra_filter.'.$this->extra_value, |
|
622 | - $this->db->expression($this->extra_table,array( |
|
620 | + $sql_filter = str_replace($this->extra_value, 'extra_filter.'.$this->extra_value, |
|
621 | + $this->db->expression($this->extra_table, array( |
|
623 | 622 | $this->extra_value.' '.$this->db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote($wildcard.$val.$wildcard) |
624 | 623 | )) |
625 | 624 | ); |
626 | 625 | } |
627 | 626 | else |
628 | 627 | { |
629 | - $sql_filter = str_replace($this->extra_value,'extra_filter.'. |
|
630 | - $this->extra_value,$this->db->expression($this->extra_table,array($this->extra_value => $val))); |
|
628 | + $sql_filter = str_replace($this->extra_value, 'extra_filter.'. |
|
629 | + $this->extra_value, $this->db->expression($this->extra_table, array($this->extra_value => $val))); |
|
631 | 630 | } |
632 | 631 | } |
633 | 632 | // need to use a LEFT JOIN for negative search or to allow NULL values |
634 | - $need_left_join = $val[0] === '!' || strpos($sql_filter,'IS NULL') !== false ? ' LEFT ' : ''; |
|
635 | - $join .= str_replace('extra_filter','extra_filter'.$extra_filter,$need_left_join.$this->extra_join_filter. |
|
633 | + $need_left_join = $val[0] === '!' || strpos($sql_filter, 'IS NULL') !== false ? ' LEFT ' : ''; |
|
634 | + $join .= str_replace('extra_filter', 'extra_filter'.$extra_filter, $need_left_join.$this->extra_join_filter. |
|
636 | 635 | ' AND extra_filter.'.$this->extra_key.'='.$this->db->quote($this->get_cf_name($name)). |
637 | 636 | ' AND '.$sql_filter); |
638 | 637 | ++$extra_filter; |
639 | 638 | } |
640 | 639 | unset($filter[$name]); |
641 | 640 | } |
642 | - elseif(is_int($name) && $this->is_cf($val)) // lettersearch: #cfname LIKE 's%' |
|
641 | + elseif (is_int($name) && $this->is_cf($val)) // lettersearch: #cfname LIKE 's%' |
|
643 | 642 | { |
644 | - $_cf = explode(' ',$val); |
|
645 | - foreach($_cf as $cf_np) |
|
643 | + $_cf = explode(' ', $val); |
|
644 | + foreach ($_cf as $cf_np) |
|
646 | 645 | { |
647 | 646 | // building cf_name by glueing parts together (, in case someone used whitespace in their custom field names) |
648 | - $tcf_name = ($tcf_name?$tcf_name.' ':'').$cf_np; |
|
647 | + $tcf_name = ($tcf_name ? $tcf_name.' ' : '').$cf_np; |
|
649 | 648 | // reacts on the first one found that matches an existing customfield, should be better then the old behavior of |
650 | 649 | // simply splitting by " " and using the first part |
651 | - if ($this->is_cf($tcf_name) && ($cfn = $this->get_cf_name($tcf_name)) && array_search($cfn,(array)$_cfnames,true)!==false ) |
|
650 | + if ($this->is_cf($tcf_name) && ($cfn = $this->get_cf_name($tcf_name)) && array_search($cfn, (array)$_cfnames, true) !== false) |
|
652 | 651 | { |
653 | 652 | $cf = $tcf_name; |
654 | 653 | break; |
655 | 654 | } |
656 | 655 | } |
657 | - $join .= str_replace('extra_filter','extra_filter'.$extra_filter,$this->extra_join_filter. |
|
656 | + $join .= str_replace('extra_filter', 'extra_filter'.$extra_filter, $this->extra_join_filter. |
|
658 | 657 | ' AND extra_filter.'.$this->extra_key.'='.$this->db->quote($this->get_cf_name($cf)). |
659 | - ' AND '.str_replace($cf,'extra_filter.'.$this->extra_value,$val)); |
|
658 | + ' AND '.str_replace($cf, 'extra_filter.'.$this->extra_value, $val)); |
|
660 | 659 | ++$extra_filter; |
661 | 660 | unset($filter[$name]); |
662 | 661 | } |
@@ -668,15 +667,14 @@ discard block |
||
668 | 667 | if (is_array($only_keys)) |
669 | 668 | { |
670 | 669 | $only_keys = array_values($only_keys); |
671 | - $only_keys[0] = 'DISTINCT '.($only_keys[0] != $this->autoinc_id ? $only_keys[0] : |
|
672 | - $this->table_name.'.'.$this->autoinc_id.' AS '.$this->autoinc_id); |
|
670 | + $only_keys[0] = 'DISTINCT '.($only_keys[0] != $this->autoinc_id ? $only_keys[0] : $this->table_name.'.'.$this->autoinc_id.' AS '.$this->autoinc_id); |
|
673 | 671 | } |
674 | 672 | else |
675 | 673 | { |
676 | 674 | $only_keys = 'DISTINCT '.$only_keys; |
677 | 675 | } |
678 | 676 | } |
679 | - return parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count); |
|
677 | + return parent::search($criteria, $only_keys, $order_by, $extra_cols, $wildcard, $empty, $op, $start, $filter, $join, $need_full_no_count); |
|
680 | 678 | } |
681 | 679 | |
682 | 680 | /** |
@@ -716,7 +714,7 @@ discard block |
||
716 | 714 | */ |
717 | 715 | function get_cf_name($field) |
718 | 716 | { |
719 | - return substr($field,1); |
|
717 | + return substr($field, 1); |
|
720 | 718 | } |
721 | 719 | |
722 | 720 | /** |
@@ -738,7 +736,7 @@ discard block |
||
738 | 736 | */ |
739 | 737 | function is_multiple($name) |
740 | 738 | { |
741 | - return $this->allow_multiple_values && in_array($this->customfields[$name]['type'],array('select','select-account')) && |
|
739 | + return $this->allow_multiple_values && in_array($this->customfields[$name]['type'], array('select', 'select-account')) && |
|
742 | 740 | $this->customfields[$name]['rows'] > 1; |
743 | 741 | } |
744 | 742 | } |
@@ -127,7 +127,11 @@ discard block |
||
127 | 127 | |
128 | 128 | $this->allow_multiple_values = $allow_multiple_values; |
129 | 129 | $this->extra_table = $extra_table; |
130 | - if (!$this->extra_id) $this->extra_id = $this->autoinc_id; // default to auto id of regular table |
|
130 | + if (!$this->extra_id) |
|
131 | + { |
|
132 | + $this->extra_id = $this->autoinc_id; |
|
133 | + } |
|
134 | + // default to auto id of regular table |
|
131 | 135 | |
132 | 136 | // if names from columns of extra table are only postfixes (starting with _), prepend column prefix |
133 | 137 | if (!($prefix=$column_prefix)) |
@@ -145,7 +149,10 @@ discard block |
||
145 | 149 | ) as $col => $val) |
146 | 150 | { |
147 | 151 | $this->$col = $col_name = $val; |
148 | - if ($col_name[0] == '_') $this->$col = $prefix . $val; |
|
152 | + if ($col_name[0] == '_') |
|
153 | + { |
|
154 | + $this->$col = $prefix . $val; |
|
155 | + } |
|
149 | 156 | } |
150 | 157 | // some sanity checks, maybe they should be active only for development |
151 | 158 | if (!($extra_defs = $this->db->get_table_definitions($app,$extra_table))) |
@@ -179,13 +186,23 @@ discard block |
||
179 | 186 | */ |
180 | 187 | function read_customfields($ids,$field_names=null) |
181 | 188 | { |
182 | - if (is_null($field_names)) $field_names = array_keys($this->customfields); |
|
189 | + if (is_null($field_names)) |
|
190 | + { |
|
191 | + $field_names = array_keys($this->customfields); |
|
192 | + } |
|
183 | 193 | |
184 | 194 | foreach((array)$ids as $key => $id) |
185 | 195 | { |
186 | - if (!(int)$id && is_array($ids)) unset($ids[$key]); |
|
196 | + if (!(int)$id && is_array($ids)) |
|
197 | + { |
|
198 | + unset($ids[$key]); |
|
199 | + } |
|
187 | 200 | } |
188 | - if (!$ids || !$field_names) return array(); // nothing to do |
|
201 | + if (!$ids || !$field_names) |
|
202 | + { |
|
203 | + return array(); |
|
204 | + } |
|
205 | + // nothing to do |
|
189 | 206 | |
190 | 207 | $entries = array(); |
191 | 208 | foreach($this->db->select($this->extra_table,'*',array( |
@@ -194,7 +211,10 @@ discard block |
||
194 | 211 | ),__LINE__,__FILE__,false,'',$this->app) as $row) |
195 | 212 | { |
196 | 213 | $entry =& $entries[$row[$this->extra_id]]; |
197 | - if (!is_array($entry)) $entry = array(); |
|
214 | + if (!is_array($entry)) |
|
215 | + { |
|
216 | + $entry = array(); |
|
217 | + } |
|
198 | 218 | $field = $this->get_cf_field($row[$this->extra_key]); |
199 | 219 | |
200 | 220 | if ($this->allow_multiple_values && $this->is_multiple($row[$this->extra_key])) |
@@ -220,7 +240,10 @@ discard block |
||
220 | 240 | { |
221 | 241 | foreach (array_keys((array)$this->customfields) as $name) |
222 | 242 | { |
223 | - if (!isset($data[$field = $this->get_cf_field($name)])) continue; |
|
243 | + if (!isset($data[$field = $this->get_cf_field($name)])) |
|
244 | + { |
|
245 | + continue; |
|
246 | + } |
|
224 | 247 | |
225 | 248 | $where = array( |
226 | 249 | $this->extra_id => isset($data[$this->autoinc_id]) ? $data[$this->autoinc_id] : $data[$this->db_key_cols[$this->autoinc_id]], |
@@ -232,7 +255,11 @@ discard block |
||
232 | 255 | if(empty($data[$field]) || $is_multiple || !$this->extra_has_unique_index) |
233 | 256 | { |
234 | 257 | $this->db->delete($this->extra_table,$where,__LINE__,__FILE__,$this->app); |
235 | - if (empty($data[$field])) continue; // nothing else to do for empty values |
|
258 | + if (empty($data[$field])) |
|
259 | + { |
|
260 | + continue; |
|
261 | + } |
|
262 | + // nothing else to do for empty values |
|
236 | 263 | } |
237 | 264 | foreach($is_multiple && !is_array($data[$field]) ? explode(',',$data[$field]) : |
238 | 265 | // regular custom fields (!$is_multiple) eg. addressbook store multiple values comma-separated |
@@ -305,9 +332,12 @@ discard block |
||
305 | 332 | */ |
306 | 333 | function save($keys=null,$extra_where=null) |
307 | 334 | { |
308 | - if (is_array($keys) && count($keys) && !isset($keys[0])) // allow to use an etag, eg array('etag=etag+1') |
|
335 | + if (is_array($keys) && count($keys) && !isset($keys[0])) |
|
336 | + { |
|
337 | + // allow to use an etag, eg array('etag=etag+1') |
|
309 | 338 | { |
310 | 339 | $this->data_merge($keys); |
340 | + } |
|
311 | 341 | $keys = null; |
312 | 342 | } |
313 | 343 | $ret = parent::save($keys,$extra_where); |
@@ -340,13 +370,20 @@ discard block |
||
340 | 370 | { |
341 | 371 | $ids[] = $row[$this->autoinc_id]; |
342 | 372 | } |
343 | - if (!$ids) return 0; // no rows affected |
|
373 | + if (!$ids) |
|
374 | + { |
|
375 | + return 0; |
|
376 | + } |
|
377 | + // no rows affected |
|
344 | 378 | } |
345 | 379 | else |
346 | 380 | { |
347 | 381 | $ids = (array)$query[$this->autoinc_id]; |
348 | 382 | } |
349 | - if ($only_return_ids) return $ids; |
|
383 | + if ($only_return_ids) |
|
384 | + { |
|
385 | + return $ids; |
|
386 | + } |
|
350 | 387 | $this->db->delete($this->extra_table,array($this->extra_id => $ids),__LINE__,__FILE__); |
351 | 388 | } |
352 | 389 | return parent::delete($keys); |
@@ -388,7 +425,10 @@ discard block |
||
388 | 425 | { |
389 | 426 | foreach($selectcols as $col) |
390 | 427 | { |
391 | - if ($this->is_cf($col)) $fields[] = $this->get_cf_name($col); |
|
428 | + if ($this->is_cf($col)) |
|
429 | + { |
|
430 | + $fields[] = $this->get_cf_name($col); |
|
431 | + } |
|
392 | 432 | } |
393 | 433 | } |
394 | 434 | if (($cfs = $this->read_customfields(array_keys($id2keys),$fields))) |
@@ -507,7 +547,10 @@ discard block |
||
507 | 547 | } |
508 | 548 | } |
509 | 549 | } |
510 | - if ($cfcriteria && $op =='OR') $criteria[] = implode(' OR ',$cfcriteria); |
|
550 | + if ($cfcriteria && $op =='OR') |
|
551 | + { |
|
552 | + $criteria[] = implode(' OR ',$cfcriteria); |
|
553 | + } |
|
511 | 554 | } |
512 | 555 | if($only_keys === true) |
513 | 556 | { |
@@ -598,11 +641,14 @@ discard block |
||
598 | 641 | } |
599 | 642 | elseif (is_string($name) && $this->is_cf($name)) |
600 | 643 | { |
601 | - if (!empty($val)) // empty -> dont filter |
|
644 | + if (!empty($val)) |
|
645 | + { |
|
646 | + // empty -> dont filter |
|
602 | 647 | { |
603 | 648 | if ($val[0] === '!') // negative filter |
604 | 649 | { |
605 | 650 | $sql_filter = 'extra_filter.'.$this->extra_value.'!='.$this->db->quote(substr($val,1)); |
651 | + } |
|
606 | 652 | } |
607 | 653 | else // using Db::expression to allow to use array() with possible values or NULL |
608 | 654 | { |
@@ -639,9 +685,12 @@ discard block |
||
639 | 685 | } |
640 | 686 | unset($filter[$name]); |
641 | 687 | } |
642 | - elseif(is_int($name) && $this->is_cf($val)) // lettersearch: #cfname LIKE 's%' |
|
688 | + elseif(is_int($name) && $this->is_cf($val)) |
|
689 | + { |
|
690 | + // lettersearch: #cfname LIKE 's%' |
|
643 | 691 | { |
644 | 692 | $_cf = explode(' ',$val); |
693 | + } |
|
645 | 694 | foreach($_cf as $cf_np) |
646 | 695 | { |
647 | 696 | // building cf_name by glueing parts together (, in case someone used whitespace in their custom field names) |
@@ -159,7 +159,7 @@ |
||
159 | 159 | * @param string $app |
160 | 160 | * @param boolean $all_private_too =false should all the private fields be returned too, default no |
161 | 161 | * @param string $only_type2 =null if given only return fields of type2 == $only_type2 |
162 | - * @return boolen true: if there is a custom field useing html, false if not |
|
162 | + * @return boolean true: if there is a custom field useing html, false if not |
|
163 | 163 | */ |
164 | 164 | public static function use_html($app, $all_private_too=false, $only_type2=null) |
165 | 165 | { |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * |
43 | 43 | * @var boolean |
44 | 44 | */ |
45 | - protected $all_private_too=false; |
|
45 | + protected $all_private_too = false; |
|
46 | 46 | |
47 | 47 | /** |
48 | 48 | * Iterator initialised for custom fields |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * @param Api\Db $db =null reference to database instance to use |
63 | 63 | * @return array with customfields |
64 | 64 | */ |
65 | - function __construct($app, $all_private_too=false, $only_type2=null, $start=0, $num_rows=null, Api\Db $db=null) |
|
65 | + function __construct($app, $all_private_too = false, $only_type2 = null, $start = 0, $num_rows = null, Api\Db $db = null) |
|
66 | 66 | { |
67 | 67 | $this->app = $app; |
68 | 68 | $this->all_private_too = $all_private_too; |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | protected function commasep_match($column, $values) |
117 | 117 | { |
118 | 118 | $to_or = array($column.' IS NULL'); |
119 | - foreach((array) $values as $value) |
|
119 | + foreach ((array)$values as $value) |
|
120 | 120 | { |
121 | 121 | $to_or[] = self::$db->concat("','", $column, "','").' LIKE '.self::$db->quote('%,'.$value.',%'); |
122 | 122 | } |
@@ -132,9 +132,9 @@ discard block |
||
132 | 132 | * @param Api\Db $db =null reference to database to use |
133 | 133 | * @return array with customfields |
134 | 134 | */ |
135 | - public static function get($app, $all_private_too=false, $only_type2=null, Api\Db $db=null) |
|
135 | + public static function get($app, $all_private_too = false, $only_type2 = null, Api\Db $db = null) |
|
136 | 136 | { |
137 | - $cache_key = $app.':'.($all_private_too?'all':$GLOBALS['egw_info']['user']['account_id']).':'.$only_type2; |
|
137 | + $cache_key = $app.':'.($all_private_too ? 'all' : $GLOBALS['egw_info']['user']['account_id']).':'.$only_type2; |
|
138 | 138 | $cfs = Api\Cache::getInstance(__CLASS__, $cache_key); |
139 | 139 | |
140 | 140 | if (!isset($cfs)) |
@@ -161,9 +161,9 @@ discard block |
||
161 | 161 | * @param string $only_type2 =null if given only return fields of type2 == $only_type2 |
162 | 162 | * @return boolen true: if there is a custom field useing html, false if not |
163 | 163 | */ |
164 | - public static function use_html($app, $all_private_too=false, $only_type2=null) |
|
164 | + public static function use_html($app, $all_private_too = false, $only_type2 = null) |
|
165 | 165 | { |
166 | - foreach(self::get($app, $all_private_too, $only_type2) as $data) |
|
166 | + foreach (self::get($app, $all_private_too, $only_type2) as $data) |
|
167 | 167 | { |
168 | 168 | if ($data['type'] == 'htmlarea') return true; |
169 | 169 | } |
@@ -186,17 +186,17 @@ discard block |
||
186 | 186 | */ |
187 | 187 | public static function format(array $field, $value) |
188 | 188 | { |
189 | - switch($field['type']) |
|
189 | + switch ($field['type']) |
|
190 | 190 | { |
191 | 191 | case 'select-account': |
192 | 192 | if ($value) |
193 | 193 | { |
194 | 194 | $values = array(); |
195 | - foreach($field['rows'] > 1 ? explode(',', $value) : (array) $value as $value) |
|
195 | + foreach ($field['rows'] > 1 ? explode(',', $value) : (array)$value as $value) |
|
196 | 196 | { |
197 | 197 | $values[] = Api\Accounts::username($value); |
198 | 198 | } |
199 | - $value = implode(', ',$values); |
|
199 | + $value = implode(', ', $values); |
|
200 | 200 | } |
201 | 201 | break; |
202 | 202 | |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | $field['values'] = self::get_options_from_file($field['values']['@']); |
212 | 212 | } |
213 | 213 | $values = array(); |
214 | - foreach($field['rows'] > 1 ? explode(',', $value) : (array) $value as $value) |
|
214 | + foreach ($field['rows'] > 1 ? explode(',', $value) : (array)$value as $value) |
|
215 | 215 | { |
216 | 216 | $values[] = isset($field['values'][$value]) ? $field['values'][$value] : '#'.$value; |
217 | 217 | } |
@@ -275,12 +275,12 @@ discard block |
||
275 | 275 | { |
276 | 276 | $options = array(); |
277 | 277 | |
278 | - if (!($path = realpath($file[0] == '/' ? $file : EGW_SERVER_ROOT.'/'.$file)) || // file does not exist |
|
279 | - substr($path,0,strlen(EGW_SERVER_ROOT)+1) != EGW_SERVER_ROOT.'/' || // we are NOT inside the eGW root |
|
280 | - basename($path,'.php').'.php' != basename($path) || // extension is NOT .php |
|
278 | + if (!($path = realpath($file[0] == '/' ? $file : EGW_SERVER_ROOT.'/'.$file)) || // file does not exist |
|
279 | + substr($path, 0, strlen(EGW_SERVER_ROOT) + 1) != EGW_SERVER_ROOT.'/' || // we are NOT inside the eGW root |
|
280 | + basename($path, '.php').'.php' != basename($path) || // extension is NOT .php |
|
281 | 281 | basename($path) == 'header.inc.php') // dont allow to include our header again |
282 | 282 | { |
283 | - return array(lang("'%1' is no php file in the eGW server root (%2)!".': '.$path,$file,EGW_SERVER_ROOT)); |
|
283 | + return array(lang("'%1' is no php file in the eGW server root (%2)!".': '.$path, $file, EGW_SERVER_ROOT)); |
|
284 | 284 | } |
285 | 285 | include($path); |
286 | 286 | |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | |
299 | 299 | if (is_null($link_types)) |
300 | 300 | { |
301 | - $link_types = array_keys(array_intersect(Api\Link::app_list('query'),Api\Link::app_list('title'))); |
|
301 | + $link_types = array_keys(array_intersect(Api\Link::app_list('query'), Api\Link::app_list('title'))); |
|
302 | 302 | $link_types[] = 'link-entry'; |
303 | 303 | } |
304 | 304 | return $link_types; |
@@ -315,31 +315,31 @@ discard block |
||
315 | 315 | * @param array $old =null old values before the update, if existing |
316 | 316 | * @param string $id_name ='id' name/key of the (link-)id in $values |
317 | 317 | */ |
318 | - public static function update_links($own_app,array $values,array $old=null,$id_name='id') |
|
318 | + public static function update_links($own_app, array $values, array $old = null, $id_name = 'id') |
|
319 | 319 | { |
320 | 320 | $link_types = self::get_link_types(); |
321 | 321 | |
322 | - foreach(self::get($own_app) as $name => $data) |
|
322 | + foreach (self::get($own_app) as $name => $data) |
|
323 | 323 | { |
324 | - if (!in_array($data['type'],$link_types)) continue; |
|
324 | + if (!in_array($data['type'], $link_types)) continue; |
|
325 | 325 | |
326 | 326 | // do we have a different old value --> delete that link |
327 | 327 | if ($old && $old['#'.$name] && $old['#'.$name] != $values['#'.$name]) |
328 | 328 | { |
329 | 329 | if ($data['type'] == 'link-entry') |
330 | 330 | { |
331 | - list($app,$id) = explode(':',$old['#'.$name]); |
|
331 | + list($app, $id) = explode(':', $old['#'.$name]); |
|
332 | 332 | } |
333 | 333 | else |
334 | 334 | { |
335 | 335 | $app = $data['type']; |
336 | 336 | $id = $old['#'.$name]; |
337 | 337 | } |
338 | - Api\Link::unlink(false,$own_app,$values[$id_name],'',$app,$id); |
|
338 | + Api\Link::unlink(false, $own_app, $values[$id_name], '', $app, $id); |
|
339 | 339 | } |
340 | 340 | if ($data['type'] == 'link-entry') |
341 | 341 | { |
342 | - list($app,$id) = explode(':',$values['#'.$name]); |
|
342 | + list($app, $id) = explode(':', $values['#'.$name]); |
|
343 | 343 | } |
344 | 344 | else |
345 | 345 | { |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | } |
349 | 349 | if ($id) // create new link, does nothing for already existing links |
350 | 350 | { |
351 | - Api\Link::link($own_app,$values[$id_name],$app,$id); |
|
351 | + Api\Link::link($own_app, $values[$id_name], $app, $id); |
|
352 | 352 | } |
353 | 353 | } |
354 | 354 | } |
@@ -369,25 +369,25 @@ discard block |
||
369 | 369 | $old = $cfs[$cf['name']]; |
370 | 370 | |
371 | 371 | // Add new one in for numbering |
372 | - if(!$cf['id']) |
|
372 | + if (!$cf['id']) |
|
373 | 373 | { |
374 | 374 | $cfs[$cf['name']] = $cf; |
375 | 375 | } |
376 | 376 | |
377 | - if($old['order'] != $cf['order'] || $cf['order'] % 10 !== 0) |
|
377 | + if ($old['order'] != $cf['order'] || $cf['order'] % 10 !== 0) |
|
378 | 378 | { |
379 | 379 | $cfs[$cf['name']]['order'] = $cf['order']; |
380 | - uasort($cfs, function($a1, $a2){ |
|
380 | + uasort($cfs, function($a1, $a2) { |
|
381 | 381 | return $a1['order'] - $a2['order']; |
382 | 382 | }); |
383 | 383 | $n = 0; |
384 | - foreach($cfs as $old_cf) |
|
384 | + foreach ($cfs as $old_cf) |
|
385 | 385 | { |
386 | 386 | $n += 10; |
387 | - if($old_cf['order'] != $n) |
|
387 | + if ($old_cf['order'] != $n) |
|
388 | 388 | { |
389 | 389 | $old_cf['order'] = $n; |
390 | - if($old_cf['name'] != $cf['name']) |
|
390 | + if ($old_cf['name'] != $cf['name']) |
|
391 | 391 | { |
392 | 392 | $update[] = $old_cf; |
393 | 393 | } |
@@ -417,7 +417,7 @@ discard block |
||
417 | 417 | 'cf_app' => $cf['app'], |
418 | 418 | ), __LINE__, __FILE__); |
419 | 419 | |
420 | - foreach($update as $old_cf) |
|
420 | + foreach ($update as $old_cf) |
|
421 | 421 | { |
422 | 422 | self::$db->$op(self::TABLE, array( |
423 | 423 | 'cf_order' => $old_cf['order'], |
@@ -442,7 +442,7 @@ discard block |
||
442 | 442 | if ($cfs) $query[] = self::$db->expression(self::TABLE, 'NOT ', array('cf_name' => array_keys($cfs))); |
443 | 443 | self::$db->delete(self::TABLE, $query, __LINE__, __FILE__); |
444 | 444 | |
445 | - foreach($cfs as $name => $cf) |
|
445 | + foreach ($cfs as $name => $cf) |
|
446 | 446 | { |
447 | 447 | if (empty($cf['name'])) $cf['name'] = $name; |
448 | 448 | if (empty($cf['app'])) $cf['app'] = $app; |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | { |
462 | 462 | if (($cached = Api\Cache::getInstance(__CLASS__, $app))) |
463 | 463 | { |
464 | - foreach($cached as $key) |
|
464 | + foreach ($cached as $key) |
|
465 | 465 | { |
466 | 466 | Api\Cache::unsetInstance(__CLASS__, $key); |
467 | 467 | } |
@@ -481,12 +481,12 @@ discard block |
||
481 | 481 | $total = 0; |
482 | 482 | if (($cfs = self::get($app, true))) |
483 | 483 | { |
484 | - foreach($cfs as &$data) |
|
484 | + foreach ($cfs as &$data) |
|
485 | 485 | { |
486 | 486 | if ($data['private']) |
487 | 487 | { |
488 | 488 | $changed = 0; |
489 | - foreach($data['private'] as &$id) |
|
489 | + foreach ($data['private'] as &$id) |
|
490 | 490 | { |
491 | 491 | if (isset($ids2change[$id])) |
492 | 492 | { |
@@ -516,7 +516,7 @@ discard block |
||
516 | 516 | $types = array(); |
517 | 517 | if (($cfs = self::get($app, true))) |
518 | 518 | { |
519 | - foreach($cfs as $name => $data) |
|
519 | + foreach ($cfs as $name => $data) |
|
520 | 520 | { |
521 | 521 | if ($data['type'] == 'select-account' || $data['type'] == 'api-accounts') |
522 | 522 | { |
@@ -80,7 +80,10 @@ discard block |
||
80 | 80 | { |
81 | 81 | $query[] = $this->commasep_match('cf_type2', $only_type2); |
82 | 82 | } |
83 | - if (!$db) $db = self::$db; |
|
83 | + if (!$db) |
|
84 | + { |
|
85 | + $db = self::$db; |
|
86 | + } |
|
84 | 87 | $this->iterator = $db->select(self::TABLE, '*', $query, __LINE__, __FILE__, |
85 | 88 | !isset($num_rows) ? false : $start, 'ORDER BY cf_order ASC', 'phpgwapi', $num_rows); |
86 | 89 | } |
@@ -165,7 +168,10 @@ discard block |
||
165 | 168 | { |
166 | 169 | foreach(self::get($app, $all_private_too, $only_type2) as $data) |
167 | 170 | { |
168 | - if ($data['type'] == 'htmlarea') return true; |
|
171 | + if ($data['type'] == 'htmlarea') |
|
172 | + { |
|
173 | + return true; |
|
174 | + } |
|
169 | 175 | } |
170 | 176 | return false; |
171 | 177 | } |
@@ -227,7 +233,10 @@ discard block |
||
227 | 233 | break; |
228 | 234 | |
229 | 235 | case 'htmlarea': // ToDo: EMail probably has a nicer html2text method |
230 | - if ($value) $value = strip_tags(preg_replace('/<(br|p)[^>]*>/i', "\r\n", str_replace(array("\r", "\n"), '', $value))); |
|
236 | + if ($value) |
|
237 | + { |
|
238 | + $value = strip_tags(preg_replace('/<(br|p)[^>]*>/i', "\r\n", str_replace(array("\r", "\n"), '', $value))); |
|
239 | + } |
|
231 | 240 | break; |
232 | 241 | |
233 | 242 | case 'ajax_select': // ToDo: returns unchanged value for now |
@@ -245,7 +254,10 @@ discard block |
||
245 | 254 | { |
246 | 255 | $app = $field['type']; |
247 | 256 | } |
248 | - if ($value) $value = Api\Link::title($app, $value); |
|
257 | + if ($value) |
|
258 | + { |
|
259 | + $value = Api\Link::title($app, $value); |
|
260 | + } |
|
249 | 261 | } |
250 | 262 | break; |
251 | 263 | } |
@@ -278,10 +290,13 @@ discard block |
||
278 | 290 | if (!($path = realpath($file[0] == '/' ? $file : EGW_SERVER_ROOT.'/'.$file)) || // file does not exist |
279 | 291 | substr($path,0,strlen(EGW_SERVER_ROOT)+1) != EGW_SERVER_ROOT.'/' || // we are NOT inside the eGW root |
280 | 292 | basename($path,'.php').'.php' != basename($path) || // extension is NOT .php |
281 | - basename($path) == 'header.inc.php') // dont allow to include our header again |
|
293 | + basename($path) == 'header.inc.php') |
|
294 | + { |
|
295 | + // dont allow to include our header again |
|
282 | 296 | { |
283 | 297 | return array(lang("'%1' is no php file in the eGW server root (%2)!".': '.$path,$file,EGW_SERVER_ROOT)); |
284 | 298 | } |
299 | + } |
|
285 | 300 | include($path); |
286 | 301 | |
287 | 302 | return $options; |
@@ -321,7 +336,10 @@ discard block |
||
321 | 336 | |
322 | 337 | foreach(self::get($own_app) as $name => $data) |
323 | 338 | { |
324 | - if (!in_array($data['type'],$link_types)) continue; |
|
339 | + if (!in_array($data['type'],$link_types)) |
|
340 | + { |
|
341 | + continue; |
|
342 | + } |
|
325 | 343 | |
326 | 344 | // do we have a different old value --> delete that link |
327 | 345 | if ($old && $old['#'.$name] && $old['#'.$name] != $values['#'.$name]) |
@@ -346,10 +364,13 @@ discard block |
||
346 | 364 | $app = $data['type']; |
347 | 365 | $id = $values['#'.$name]; |
348 | 366 | } |
349 | - if ($id) // create new link, does nothing for already existing links |
|
367 | + if ($id) |
|
368 | + { |
|
369 | + // create new link, does nothing for already existing links |
|
350 | 370 | { |
351 | 371 | Api\Link::link($own_app,$values[$id_name],$app,$id); |
352 | 372 | } |
373 | + } |
|
353 | 374 | } |
354 | 375 | } |
355 | 376 | |
@@ -377,7 +398,8 @@ discard block |
||
377 | 398 | if($old['order'] != $cf['order'] || $cf['order'] % 10 !== 0) |
378 | 399 | { |
379 | 400 | $cfs[$cf['name']]['order'] = $cf['order']; |
380 | - uasort($cfs, function($a1, $a2){ |
|
401 | + uasort($cfs, function($a1, $a2) |
|
402 | + { |
|
381 | 403 | return $a1['order'] - $a2['order']; |
382 | 404 | }); |
383 | 405 | $n = 0; |
@@ -439,13 +461,22 @@ discard block |
||
439 | 461 | public static function save($app, array $cfs) |
440 | 462 | { |
441 | 463 | $query = array('cf_app' => $app); |
442 | - if ($cfs) $query[] = self::$db->expression(self::TABLE, 'NOT ', array('cf_name' => array_keys($cfs))); |
|
464 | + if ($cfs) |
|
465 | + { |
|
466 | + $query[] = self::$db->expression(self::TABLE, 'NOT ', array('cf_name' => array_keys($cfs))); |
|
467 | + } |
|
443 | 468 | self::$db->delete(self::TABLE, $query, __LINE__, __FILE__); |
444 | 469 | |
445 | 470 | foreach($cfs as $name => $cf) |
446 | 471 | { |
447 | - if (empty($cf['name'])) $cf['name'] = $name; |
|
448 | - if (empty($cf['app'])) $cf['app'] = $app; |
|
472 | + if (empty($cf['name'])) |
|
473 | + { |
|
474 | + $cf['name'] = $name; |
|
475 | + } |
|
476 | + if (empty($cf['app'])) |
|
477 | + { |
|
478 | + $cf['app'] = $app; |
|
479 | + } |
|
449 | 480 | |
450 | 481 | self::update($cf); |
451 | 482 | } |
@@ -112,6 +112,8 @@ |
||
112 | 112 | |
113 | 113 | /** |
114 | 114 | * Static function to add a history record |
115 | + * @param string $field_code |
|
116 | + * @param string $new_value |
|
115 | 117 | */ |
116 | 118 | public static function static_add($appname, $id, $user, $field_code, $new_value, $old_value = '') |
117 | 119 | { |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | * @param string $appname app name this instance operates on |
52 | 52 | * @return historylog |
53 | 53 | */ |
54 | - function __construct($appname='',$user=null) |
|
54 | + function __construct($appname = '', $user = null) |
|
55 | 55 | { |
56 | 56 | $this->appname = $appname ? $appname : $GLOBALS['egw_info']['flags']['currentapp']; |
57 | 57 | $this->user = !is_null($user) ? $user : $GLOBALS['egw_info']['user']['account_id']; |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | { |
81 | 81 | $where['history_record_id'] = $record_id; |
82 | 82 | } |
83 | - $this->db->delete(self::TABLE,$where,__LINE__,__FILE__); |
|
83 | + $this->db->delete(self::TABLE, $where, __LINE__, __FILE__); |
|
84 | 84 | |
85 | 85 | return $this->db->affected_rows(); |
86 | 86 | } |
@@ -93,11 +93,11 @@ discard block |
||
93 | 93 | * @param string $new_value new value |
94 | 94 | * @param string $old_value old value |
95 | 95 | */ |
96 | - function add($status,$record_id,$new_value,$old_value) |
|
96 | + function add($status, $record_id, $new_value, $old_value) |
|
97 | 97 | { |
98 | 98 | if ($new_value != $old_value) |
99 | 99 | { |
100 | - $this->db->insert(self::TABLE,array( |
|
100 | + $this->db->insert(self::TABLE, array( |
|
101 | 101 | 'history_record_id' => $record_id, |
102 | 102 | 'history_appname' => $this->appname, |
103 | 103 | 'history_owner' => $this->user, |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | 'history_old_value' => $old_value, |
107 | 107 | 'history_timestamp' => time(), |
108 | 108 | 'sessionid' => $GLOBALS['egw']->session->sessionid_access_log, |
109 | - ),false,__LINE__,__FILE__); |
|
109 | + ), false, __LINE__, __FILE__); |
|
110 | 110 | } |
111 | 111 | } |
112 | 112 | |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | { |
118 | 118 | if ($new_value != $old_value) |
119 | 119 | { |
120 | - $GLOBALS['egw']->db->insert(self::TABLE,array( |
|
120 | + $GLOBALS['egw']->db->insert(self::TABLE, array( |
|
121 | 121 | 'history_record_id' => $id, |
122 | 122 | 'history_appname' => $appname, |
123 | 123 | 'history_owner' => (int)$user, |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | 'history_old_value' => $old_value, |
127 | 127 | 'history_timestamp' => time(), |
128 | 128 | 'sessionid' => $GLOBALS['egw']->session->sessionid_access_log, |
129 | - ),false,__LINE__,__FILE__); |
|
129 | + ), false, __LINE__, __FILE__); |
|
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
@@ -140,11 +140,11 @@ discard block |
||
140 | 140 | * @return array of arrays with keys id, record_id, appname, owner (account_id), status, new_value, old_value, |
141 | 141 | * timestamp (Y-m-d H:i:s in servertime), user_ts (timestamp in user-time) |
142 | 142 | */ |
143 | - function search($filter,$order='history_id',$sort='DESC',$limit=null) |
|
143 | + function search($filter, $order = 'history_id', $sort = 'DESC', $limit = null) |
|
144 | 144 | { |
145 | 145 | if (!is_array($filter)) $filter = is_numeric($filter) ? array('history_record_id' => $filter) : array(); |
146 | 146 | |
147 | - if (!$order || !preg_match('/^[a-z0-9_]+$/i',$order) || !preg_match('/^(asc|desc)?$/i',$sort)) |
|
147 | + if (!$order || !preg_match('/^[a-z0-9_]+$/i', $order) || !preg_match('/^(asc|desc)?$/i', $sort)) |
|
148 | 148 | { |
149 | 149 | $orderby = 'ORDER BY history_id DESC'; |
150 | 150 | } |
@@ -152,9 +152,9 @@ discard block |
||
152 | 152 | { |
153 | 153 | $orderby = "ORDER BY $order $sort"; |
154 | 154 | } |
155 | - foreach($filter as $col => $value) |
|
155 | + foreach ($filter as $col => $value) |
|
156 | 156 | { |
157 | - if (!is_numeric($col) && substr($col,0,8) != 'history_') |
|
157 | + if (!is_numeric($col) && substr($col, 0, 8) != 'history_') |
|
158 | 158 | { |
159 | 159 | $filter['history_'.$col] = $value; |
160 | 160 | unset($filter[$col]); |
@@ -166,11 +166,11 @@ discard block |
||
166 | 166 | if (!$filter['history_record_id']) return array(); |
167 | 167 | |
168 | 168 | $rows = array(); |
169 | - foreach($this->db->select(self::TABLE, '*', $filter, __LINE__, __FILE__, |
|
169 | + foreach ($this->db->select(self::TABLE, '*', $filter, __LINE__, __FILE__, |
|
170 | 170 | isset($limit) ? 0 : false, $orderby, 'phpgwapi', $limit) as $row) |
171 | 171 | { |
172 | 172 | $row['user_ts'] = $this->db->from_timestamp($row['history_timestamp']) + 3600 * $GLOBALS['egw_info']['user']['preferences']['common']['tz_offset']; |
173 | - $rows[] = Api\Db::strip_array_keys($row,'history_'); |
|
173 | + $rows[] = Api\Db::strip_array_keys($row, 'history_'); |
|
174 | 174 | } |
175 | 175 | return $rows; |
176 | 176 | } |
@@ -188,8 +188,8 @@ discard block |
||
188 | 188 | $rows = array(); |
189 | 189 | $filter['history_appname'] = $query['appname']; |
190 | 190 | $filter['history_record_id'] = $query['record_id']; |
191 | - if(is_array($query['colfilter'])) { |
|
192 | - foreach($query['colfilter'] as $column => $value) { |
|
191 | + if (is_array($query['colfilter'])) { |
|
192 | + foreach ($query['colfilter'] as $column => $value) { |
|
193 | 193 | $filter[$column] = $value; |
194 | 194 | } |
195 | 195 | } |
@@ -199,20 +199,20 @@ discard block |
||
199 | 199 | } |
200 | 200 | else |
201 | 201 | { |
202 | - $total = $GLOBALS['egw']->db->select(self::TABLE,'COUNT(*)',$filter,__LINE__,__FILE__,false,'','phpgwapi',0)->fetchColumn(); |
|
202 | + $total = $GLOBALS['egw']->db->select(self::TABLE, 'COUNT(*)', $filter, __LINE__, __FILE__, false, '', 'phpgwapi', 0)->fetchColumn(); |
|
203 | 203 | } |
204 | 204 | // filter out private (or no longer defined) custom fields |
205 | 205 | if ($filter['history_appname']) |
206 | 206 | { |
207 | 207 | $to_or[] = "history_status NOT LIKE '#%'"; |
208 | 208 | // explicitly allow "##" used to store iCal/vCard X-attributes |
209 | - if (in_array($filter['history_appname'], array('calendar','infolog','addressbook'))) |
|
209 | + if (in_array($filter['history_appname'], array('calendar', 'infolog', 'addressbook'))) |
|
210 | 210 | { |
211 | 211 | $to_or[] = "history_status LIKE '##%'"; |
212 | 212 | } |
213 | 213 | if (($cfs = Customfields::get($filter['history_appname']))) |
214 | 214 | { |
215 | - $to_or[] = 'history_status IN ('.implode(',', array_map(function($str) |
|
215 | + $to_or[] = 'history_status IN ('.implode(',', array_map(function($str) |
|
216 | 216 | { |
217 | 217 | return $GLOBALS['egw']->db->quote('#'.$str); |
218 | 218 | }, array_keys($cfs))).')'; |
@@ -221,25 +221,25 @@ discard block |
||
221 | 221 | } |
222 | 222 | $_query = array(array( |
223 | 223 | 'table' => self::TABLE, |
224 | - 'cols' => array('history_id', 'history_record_id','history_appname','history_owner','history_status','history_new_value', 'history_timestamp','history_old_value'), |
|
224 | + 'cols' => array('history_id', 'history_record_id', 'history_appname', 'history_owner', 'history_status', 'history_new_value', 'history_timestamp', 'history_old_value'), |
|
225 | 225 | 'where' => $filter, |
226 | 226 | )); |
227 | 227 | |
228 | 228 | // Add in files, if possible |
229 | - if($GLOBALS['egw_info']['user']['apps']['filemanager'] && |
|
230 | - $file = Api\Vfs\Sqlfs\StreamWrapper::url_stat("/apps/{$query['appname']}/{$query['record_id']}",STREAM_URL_STAT_LINK)) |
|
229 | + if ($GLOBALS['egw_info']['user']['apps']['filemanager'] && |
|
230 | + $file = Api\Vfs\Sqlfs\StreamWrapper::url_stat("/apps/{$query['appname']}/{$query['record_id']}", STREAM_URL_STAT_LINK)) |
|
231 | 231 | { |
232 | 232 | $_query[] = array( |
233 | 233 | 'table' => Api\Vfs\Sqlfs\StreamWrapper::TABLE, |
234 | - 'cols' =>array('fs_id', 'fs_dir', "'filemanager'",'COALESCE(fs_modifier,fs_creator)',"'~file~'",'fs_name','fs_modified', 'fs_mime'), |
|
234 | + 'cols' =>array('fs_id', 'fs_dir', "'filemanager'", 'COALESCE(fs_modifier,fs_creator)', "'~file~'", 'fs_name', 'fs_modified', 'fs_mime'), |
|
235 | 235 | 'where' => array('fs_dir' => $file['ino']) |
236 | 236 | ); |
237 | 237 | } |
238 | 238 | $new_file_id = array(); |
239 | - foreach($GLOBALS['egw']->db->union( |
|
239 | + foreach ($GLOBALS['egw']->db->union( |
|
240 | 240 | $_query, |
241 | 241 | __LINE__, __FILE__, |
242 | - ' ORDER BY ' . ($query['order'] ? $query['order'] : 'history_timestamp') . ' ' . ($query['sort'] ? $query['sort'] : 'DESC'), |
|
242 | + ' ORDER BY '.($query['order'] ? $query['order'] : 'history_timestamp').' '.($query['sort'] ? $query['sort'] : 'DESC'), |
|
243 | 243 | $query['start'], |
244 | 244 | $query['num_rows'] |
245 | 245 | ) as $row) |
@@ -247,15 +247,15 @@ discard block |
||
247 | 247 | $row['user_ts'] = $GLOBALS['egw']->db->from_timestamp($row['history_timestamp']) + 3600 * $GLOBALS['egw_info']['user']['preferences']['common']['tz_offset']; |
248 | 248 | |
249 | 249 | // Explode multi-part values |
250 | - foreach(array('history_new_value','history_old_value') as $field) |
|
250 | + foreach (array('history_new_value', 'history_old_value') as $field) |
|
251 | 251 | { |
252 | - if(strpos($row[$field],Tracking::ONE2N_SEPERATOR) !== false) |
|
252 | + if (strpos($row[$field], Tracking::ONE2N_SEPERATOR) !== false) |
|
253 | 253 | { |
254 | - $row[$field] = explode(Tracking::ONE2N_SEPERATOR,$row[$field]); |
|
254 | + $row[$field] = explode(Tracking::ONE2N_SEPERATOR, $row[$field]); |
|
255 | 255 | } |
256 | 256 | } |
257 | 257 | // Get information needed for proper display |
258 | - if($row['history_appname'] == 'filemanager') |
|
258 | + if ($row['history_appname'] == 'filemanager') |
|
259 | 259 | { |
260 | 260 | $new_version = $new_file_id[$row['history_new_value']]; |
261 | 261 | $new_file_id[$row['history_new_value']] = count($rows); |
@@ -271,12 +271,12 @@ discard block |
||
271 | 271 | 'mime' => $row['history_old_value'] |
272 | 272 | ); |
273 | 273 | $row['history_old_value'] = ''; |
274 | - if($new_version !== null) |
|
274 | + if ($new_version !== null) |
|
275 | 275 | { |
276 | 276 | $rows[$new_version]['old_value'] = $row['history_new_value']; |
277 | 277 | } |
278 | 278 | } |
279 | - $rows[] = Api\Db::strip_array_keys($row,'history_'); |
|
279 | + $rows[] = Api\Db::strip_array_keys($row, 'history_'); |
|
280 | 280 | } |
281 | 281 | if ($mysql_calc_rows) |
282 | 282 | { |
@@ -142,7 +142,10 @@ discard block |
||
142 | 142 | */ |
143 | 143 | function search($filter,$order='history_id',$sort='DESC',$limit=null) |
144 | 144 | { |
145 | - if (!is_array($filter)) $filter = is_numeric($filter) ? array('history_record_id' => $filter) : array(); |
|
145 | + if (!is_array($filter)) |
|
146 | + { |
|
147 | + $filter = is_numeric($filter) ? array('history_record_id' => $filter) : array(); |
|
148 | + } |
|
146 | 149 | |
147 | 150 | if (!$order || !preg_match('/^[a-z0-9_]+$/i',$order) || !preg_match('/^(asc|desc)?$/i',$sort)) |
148 | 151 | { |
@@ -160,10 +163,16 @@ discard block |
||
160 | 163 | unset($filter[$col]); |
161 | 164 | } |
162 | 165 | } |
163 | - if (!isset($filter['history_appname'])) $filter['history_appname'] = $this->appname; |
|
166 | + if (!isset($filter['history_appname'])) |
|
167 | + { |
|
168 | + $filter['history_appname'] = $this->appname; |
|
169 | + } |
|
164 | 170 | |
165 | 171 | // do not try to read all history entries of an app |
166 | - if (!$filter['history_record_id']) return array(); |
|
172 | + if (!$filter['history_record_id']) |
|
173 | + { |
|
174 | + return array(); |
|
175 | + } |
|
167 | 176 | |
168 | 177 | $rows = array(); |
169 | 178 | foreach($this->db->select(self::TABLE, '*', $filter, __LINE__, __FILE__, |
@@ -188,8 +197,10 @@ discard block |
||
188 | 197 | $rows = array(); |
189 | 198 | $filter['history_appname'] = $query['appname']; |
190 | 199 | $filter['history_record_id'] = $query['record_id']; |
191 | - if(is_array($query['colfilter'])) { |
|
192 | - foreach($query['colfilter'] as $column => $value) { |
|
200 | + if(is_array($query['colfilter'])) |
|
201 | + { |
|
202 | + foreach($query['colfilter'] as $column => $value) |
|
203 | + { |
|
193 | 204 | $filter[$column] = $value; |
194 | 205 | } |
195 | 206 | } |
@@ -528,7 +528,7 @@ discard block |
||
528 | 528 | * @param array $data current entry |
529 | 529 | * @param array $old = null old/last state of the entry or null for a new entry |
530 | 530 | * @param boolean $deleted = null can be set to true to let the tracking know the item got deleted or undelted |
531 | - * @param array $email_notified=null if present will return the emails notified, if given emails in that list will not be notified |
|
531 | + * @param array $email_notified if present will return the emails notified, if given emails in that list will not be notified |
|
532 | 532 | * @return boolean true on success, false on error (error messages are in $this->errors) |
533 | 533 | */ |
534 | 534 | public function do_notifications($data,$old,$deleted=null,&$email_notified=null) |
@@ -824,7 +824,6 @@ discard block |
||
824 | 824 | * The default implementation prefers depending on the prefer_user_as_sender class-var the user over |
825 | 825 | * what is returned by get_config('sender'). |
826 | 826 | * |
827 | - * @param int $user account_lid of user |
|
828 | 827 | * @param array $data |
829 | 828 | * @param array $old |
830 | 829 | * @param bool $prefer_id returns the userid rather than email |
@@ -194,12 +194,12 @@ discard block |
||
194 | 194 | { |
195 | 195 | if ($cf_app) |
196 | 196 | { |
197 | - $linkable_cf_types = array('link-entry')+array_keys(Api\Link::app_list()); |
|
198 | - foreach(Customfields::get($cf_app, true) as $cf_name => $cf_data) |
|
197 | + $linkable_cf_types = array('link-entry') + array_keys(Api\Link::app_list()); |
|
198 | + foreach (Customfields::get($cf_app, true) as $cf_name => $cf_data) |
|
199 | 199 | { |
200 | 200 | $this->field2history['#'.$cf_name] = '#'.$cf_name; |
201 | 201 | |
202 | - if (in_array($cf_data['type'],$linkable_cf_types)) |
|
202 | + if (in_array($cf_data['type'], $linkable_cf_types)) |
|
203 | 203 | { |
204 | 204 | $this->cf_link_fields['#'.$cf_name] = $cf_data['type'] == 'link-entry' ? '' : $cf_data['type']; |
205 | 205 | } |
@@ -216,9 +216,9 @@ discard block |
||
216 | 216 | * @param int|string $receiver nummeric account_id or email address |
217 | 217 | * @return array of details as array with values for keys 'label','value','type' |
218 | 218 | */ |
219 | - function get_details($data,$receiver=null) |
|
219 | + function get_details($data, $receiver = null) |
|
220 | 220 | { |
221 | - unset($data, $receiver); // not uses as just a stub |
|
221 | + unset($data, $receiver); // not uses as just a stub |
|
222 | 222 | |
223 | 223 | return array(); |
224 | 224 | } |
@@ -230,14 +230,14 @@ discard block |
||
230 | 230 | * @param string $only_type2 = null if given only return fields of type2 == $only_type2 |
231 | 231 | * @return array of details as array with values for keys 'label','value','type' |
232 | 232 | */ |
233 | - function get_customfields($data, $only_type2=null) |
|
233 | + function get_customfields($data, $only_type2 = null) |
|
234 | 234 | { |
235 | 235 | $details = array(); |
236 | 236 | |
237 | - if (($cfs = Customfields::get($this->app, $all_private_too=false, $only_type2))) |
|
237 | + if (($cfs = Customfields::get($this->app, $all_private_too = false, $only_type2))) |
|
238 | 238 | { |
239 | 239 | $header_done = false; |
240 | - foreach($cfs as $name => $field) |
|
240 | + foreach ($cfs as $name => $field) |
|
241 | 241 | { |
242 | 242 | if (in_array($field['type'], Customfields::$non_printable_fields)) continue; |
243 | 243 | |
@@ -278,9 +278,9 @@ discard block |
||
278 | 278 | * @param array $old = null old/last state of the entry or null for a new entry |
279 | 279 | * @return mixed |
280 | 280 | */ |
281 | - protected function get_config($name,$data,$old=null) |
|
281 | + protected function get_config($name, $data, $old = null) |
|
282 | 282 | { |
283 | - unset($name, $data, $old); // not used as just a stub |
|
283 | + unset($name, $data, $old); // not used as just a stub |
|
284 | 284 | |
285 | 285 | return null; |
286 | 286 | } |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | * @param boolean $skip_notification = false do NOT send any notification |
297 | 297 | * @return int|boolean false on error, integer number of changes logged or true for new entries ($old == null) |
298 | 298 | */ |
299 | - public function track(array $data,array $old=null,$user=null,$deleted=null,array $changed_fields=null,$skip_notification=false) |
|
299 | + public function track(array $data, array $old = null, $user = null, $deleted = null, array $changed_fields = null, $skip_notification = false) |
|
300 | 300 | { |
301 | 301 | $this->user = !is_null($user) ? $user : $GLOBALS['egw_info']['user']['account_id']; |
302 | 302 | |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | if ($old && $this->field2history) |
306 | 306 | { |
307 | 307 | //error_log(__METHOD__.__LINE__.' Changedfields:'.print_r($changed_fields,true)); |
308 | - $changes = $this->save_history($data,$old,$deleted,$changed_fields); |
|
308 | + $changes = $this->save_history($data, $old, $deleted, $changed_fields); |
|
309 | 309 | //error_log(__METHOD__.__LINE__.' Changedfields:'.print_r($changed_fields,true)); |
310 | 310 | //error_log(__METHOD__.__LINE__.' Changes:'.print_r($changes,true)); |
311 | 311 | } |
@@ -313,10 +313,10 @@ discard block |
||
313 | 313 | //error_log(__METHOD__.__LINE__.' LinkFields:'.array2string($this->cf_link_fields)); |
314 | 314 | if ($changes && $this->cf_link_fields) |
315 | 315 | { |
316 | - $this->update_links($data,(array)$old); |
|
316 | + $this->update_links($data, (array)$old); |
|
317 | 317 | } |
318 | 318 | // do not run do_notifications if we have no changes |
319 | - if ($changes && !$skip_notification && !$this->do_notifications($data,$old,$deleted)) |
|
319 | + if ($changes && !$skip_notification && !$this->do_notifications($data, $old, $deleted)) |
|
320 | 320 | { |
321 | 321 | $changes = false; |
322 | 322 | } |
@@ -333,45 +333,45 @@ discard block |
||
333 | 333 | { |
334 | 334 | //error_log(__METHOD__.__LINE__.array2string($data).function_backtrace()); |
335 | 335 | //error_log(__METHOD__.__LINE__.array2string($this->cf_link_fields)); |
336 | - foreach(array_keys((array)$this->cf_link_fields) as $name) |
|
336 | + foreach (array_keys((array)$this->cf_link_fields) as $name) |
|
337 | 337 | { |
338 | 338 | //error_log(__METHOD__.__LINE__.' Field:'.$name. ' Value (new):'.array2string($data[$name])); |
339 | 339 | //error_log(__METHOD__.__LINE__.' Field:'.$name. ' Value (old):'.array2string($old[$name])); |
340 | - if (is_array($data[$name]) && array_key_exists('id',$data[$name])) $data[$name] = $data[$name]['id']; |
|
341 | - if (is_array($old[$name]) && array_key_exists('id',$old[$name])) $old[$name] = $old[$name]['id']; |
|
340 | + if (is_array($data[$name]) && array_key_exists('id', $data[$name])) $data[$name] = $data[$name]['id']; |
|
341 | + if (is_array($old[$name]) && array_key_exists('id', $old[$name])) $old[$name] = $old[$name]['id']; |
|
342 | 342 | //error_log(__METHOD__.__LINE__.'(After processing) Field:'.$name. ' Value (new):'.array2string($data[$name])); |
343 | 343 | //error_log(__METHOD__.__LINE__.'(After processing) Field:'.$name. ' Value (old):'.array2string($old[$name])); |
344 | 344 | } |
345 | - $current_ids = array_unique(array_diff(array_intersect_key($data,$this->cf_link_fields),array('',0,NULL))); |
|
346 | - $old_ids = $old ? array_unique(array_diff(array_intersect_key($old,$this->cf_link_fields),array('',0,NULL))) : array(); |
|
345 | + $current_ids = array_unique(array_diff(array_intersect_key($data, $this->cf_link_fields), array('', 0, NULL))); |
|
346 | + $old_ids = $old ? array_unique(array_diff(array_intersect_key($old, $this->cf_link_fields), array('', 0, NULL))) : array(); |
|
347 | 347 | //error_log(__METHOD__.__LINE__.array2string($current_ids)); |
348 | 348 | //error_log(__METHOD__.__LINE__.array2string($old_ids)); |
349 | 349 | // create links for added application entry |
350 | - foreach(array_diff($current_ids,$old_ids) as $name => $id) |
|
350 | + foreach (array_diff($current_ids, $old_ids) as $name => $id) |
|
351 | 351 | { |
352 | 352 | if (!($app = $this->cf_link_fields[$name])) |
353 | 353 | { |
354 | - list($app,$id) = explode(':',$id); |
|
355 | - if (!$id) continue; // can be eg. 'addressbook:', if no contact selected |
|
354 | + list($app, $id) = explode(':', $id); |
|
355 | + if (!$id) continue; // can be eg. 'addressbook:', if no contact selected |
|
356 | 356 | } |
357 | 357 | $source_id = $data[$this->id_field]; |
358 | 358 | //error_log(__METHOD__.__LINE__.array2string($source_id)); |
359 | - if ($source_id) Api\Link::link($this->app,$source_id,$app,$id); |
|
359 | + if ($source_id) Api\Link::link($this->app, $source_id, $app, $id); |
|
360 | 360 | //error_log(__METHOD__.__LINE__."Api\Link::link('$this->app',".array2string($source_id).",'$app',$id);"); |
361 | 361 | //echo "<p>Api\Link::link('$this->app',{$data[$this->id_field]},'$app',$id);</p>\n"; |
362 | 362 | } |
363 | 363 | |
364 | 364 | // unlink removed application entries |
365 | - foreach(array_diff($old_ids,$current_ids) as $name => $id) |
|
365 | + foreach (array_diff($old_ids, $current_ids) as $name => $id) |
|
366 | 366 | { |
367 | - if (!isset($data[$name])) continue; // ignore not set link cf's, eg. from sync clients |
|
367 | + if (!isset($data[$name])) continue; // ignore not set link cf's, eg. from sync clients |
|
368 | 368 | if (!($app = $this->cf_link_fields[$name])) |
369 | 369 | { |
370 | - list($app,$id) = explode(':',$id); |
|
370 | + list($app, $id) = explode(':', $id); |
|
371 | 371 | if (!$id) continue; |
372 | 372 | } |
373 | 373 | $source_id = $data[$this->id_field]; |
374 | - if ($source_id) Api\Link::unlink(null,$this->app,$source_id,0,$app,$id); |
|
374 | + if ($source_id) Api\Link::unlink(null, $this->app, $source_id, 0, $app, $id); |
|
375 | 375 | //echo "<p>Api\Link::unlink(NULL,'$this->app',{$data[$this->id_field]},0,'$app',$id);</p>\n"; |
376 | 376 | } |
377 | 377 | } |
@@ -386,14 +386,14 @@ discard block |
||
386 | 386 | * @param array $changed_fields = null changed fields from ealier call to $this->changed_fields($data,$old), to not compute it again |
387 | 387 | * @return int number of log-entries made |
388 | 388 | */ |
389 | - protected function save_history(array $data,array $old=null,$deleted=null,array $changed_fields=null) |
|
389 | + protected function save_history(array $data, array $old = null, $deleted = null, array $changed_fields = null) |
|
390 | 390 | { |
391 | - unset($deleted); // not used, but required by function signature |
|
391 | + unset($deleted); // not used, but required by function signature |
|
392 | 392 | |
393 | 393 | //error_log(__METHOD__.__LINE__.' Changedfields:'.array2string($changed_fields)); |
394 | 394 | if (is_null($changed_fields)) |
395 | 395 | { |
396 | - $changed_fields = self::changed_fields($data,$old); |
|
396 | + $changed_fields = self::changed_fields($data, $old); |
|
397 | 397 | //error_log(__METHOD__.__LINE__.' Changedfields:'.array2string($changed_fields)); |
398 | 398 | } |
399 | 399 | if (!$changed_fields && ($old || !$GLOBALS['egw_info']['server']['log_user_agent_action'])) return 0; |
@@ -408,30 +408,30 @@ discard block |
||
408 | 408 | $this->historylog->add('user_agent_action', $data[$this->id_field], |
409 | 409 | $_SERVER['HTTP_USER_AGENT'], $_SESSION[Api\Session::EGW_SESSION_VAR]['session_action']); |
410 | 410 | } |
411 | - foreach($changed_fields as $name) |
|
411 | + foreach ($changed_fields as $name) |
|
412 | 412 | { |
413 | 413 | $status = isset($this->field2history[$name]) ? $this->field2history[$name] : $name; |
414 | 414 | //error_log(__METHOD__.__LINE__." Name $name,".' Status:'.array2string($status)); |
415 | 415 | if (is_array($status)) // 1:N relation --> remove common rows |
416 | 416 | { |
417 | 417 | //error_log(__METHOD__.__LINE__.' is Array'); |
418 | - self::compact_1_N_relation($data[$name],$status); |
|
419 | - self::compact_1_N_relation($old[$name],$status); |
|
420 | - $added = array_values(array_diff($data[$name],$old[$name])); |
|
421 | - $removed = array_values(array_diff($old[$name],$data[$name])); |
|
422 | - $n = max(array(count($added),count($removed))); |
|
423 | - for($i = 0; $i < $n; ++$i) |
|
418 | + self::compact_1_N_relation($data[$name], $status); |
|
419 | + self::compact_1_N_relation($old[$name], $status); |
|
420 | + $added = array_values(array_diff($data[$name], $old[$name])); |
|
421 | + $removed = array_values(array_diff($old[$name], $data[$name])); |
|
422 | + $n = max(array(count($added), count($removed))); |
|
423 | + for ($i = 0; $i < $n; ++$i) |
|
424 | 424 | { |
425 | 425 | //error_log(__METHOD__."() $i: historylog->add('$name',data['$this->id_field']={$data[$this->id_field]},".array2string($added[$i]).','.array2string($removed[$i])); |
426 | - $this->historylog->add($name,$data[$this->id_field],$added[$i],$removed[$i]); |
|
426 | + $this->historylog->add($name, $data[$this->id_field], $added[$i], $removed[$i]); |
|
427 | 427 | } |
428 | 428 | } |
429 | 429 | else |
430 | 430 | { |
431 | 431 | //error_log(__METHOD__.__LINE__.' IDField:'.array2string($this->id_field).' ->'.$data[$this->id_field].' New:'.$data[$name].' Old:'.$old[$name]); |
432 | - $this->historylog->add($status,$data[$this->id_field], |
|
433 | - is_array($data[$name]) ? implode(',',$data[$name]) : $data[$name], |
|
434 | - is_array($old[$name]) ? implode(',',$old[$name]) : $old[$name]); |
|
432 | + $this->historylog->add($status, $data[$this->id_field], |
|
433 | + is_array($data[$name]) ? implode(',', $data[$name]) : $data[$name], |
|
434 | + is_array($old[$name]) ? implode(',', $old[$name]) : $old[$name]); |
|
435 | 435 | } |
436 | 436 | } |
437 | 437 | //error_log(__METHOD__.__LINE__.' return:'.count($changed_fields)); |
@@ -447,28 +447,28 @@ discard block |
||
447 | 447 | * @param array $old = null |
448 | 448 | * @return array of keys with different values in $data and $old |
449 | 449 | */ |
450 | - public function changed_fields(array $data,array $old=null) |
|
450 | + public function changed_fields(array $data, array $old = null) |
|
451 | 451 | { |
452 | 452 | if (is_null($old)) return array_keys($data); |
453 | 453 | $changed_fields = array(); |
454 | - foreach($this->field2history as $name => $status) |
|
454 | + foreach ($this->field2history as $name => $status) |
|
455 | 455 | { |
456 | - if (!$old[$name] && !$data[$name]) continue; // treat all sorts of empty equally |
|
456 | + if (!$old[$name] && !$data[$name]) continue; // treat all sorts of empty equally |
|
457 | 457 | |
458 | - if ($name[0] == '#' && !isset($data[$name])) continue; // no set customfields are not stored, therefore not changed |
|
458 | + if ($name[0] == '#' && !isset($data[$name])) continue; // no set customfields are not stored, therefore not changed |
|
459 | 459 | |
460 | 460 | if (is_array($status)) // 1:N relation |
461 | 461 | { |
462 | - self::compact_1_N_relation($data[$name],$status); |
|
463 | - self::compact_1_N_relation($old[$name],$status); |
|
462 | + self::compact_1_N_relation($data[$name], $status); |
|
463 | + self::compact_1_N_relation($old[$name], $status); |
|
464 | 464 | } |
465 | 465 | if ($old[$name] != $data[$name]) |
466 | 466 | { |
467 | 467 | // normalize arrays, we do NOT care for the order of multiselections |
468 | 468 | if (is_array($data[$name]) || is_array($old[$name])) |
469 | 469 | { |
470 | - if (!is_array($data[$name])) $data[$name] = explode(',',$data[$name]); |
|
471 | - if (!is_array($old[$name])) $old[$name] = explode(',',$old[$name]); |
|
470 | + if (!is_array($data[$name])) $data[$name] = explode(',', $data[$name]); |
|
471 | + if (!is_array($old[$name])) $old[$name] = explode(',', $old[$name]); |
|
472 | 472 | if (count($data[$name]) == count($old[$name])) |
473 | 473 | { |
474 | 474 | sort($data[$name]); |
@@ -478,13 +478,13 @@ discard block |
||
478 | 478 | } |
479 | 479 | elseif (str_replace("\r", '', $old[$name]) == str_replace("\r", '', $data[$name])) |
480 | 480 | { |
481 | - continue; // change only in CR (eg. different OS) --> ignore |
|
481 | + continue; // change only in CR (eg. different OS) --> ignore |
|
482 | 482 | } |
483 | 483 | $changed_fields[] = $name; |
484 | 484 | //echo "<p>$name: ".array2string($data[$name]).' != '.array2string($old[$name])."</p>\n"; |
485 | 485 | } |
486 | 486 | } |
487 | - foreach($data as $name => $value) |
|
487 | + foreach ($data as $name => $value) |
|
488 | 488 | { |
489 | 489 | if ($name[0] == '#' && $name[1] == '#' && $value !== $old[$name]) |
490 | 490 | { |
@@ -501,18 +501,18 @@ discard block |
||
501 | 501 | * @param array &$rows rows of the 1:N relation |
502 | 502 | * @param array $cols field names as values |
503 | 503 | */ |
504 | - private static function compact_1_N_relation(&$rows,array $cols) |
|
504 | + private static function compact_1_N_relation(&$rows, array $cols) |
|
505 | 505 | { |
506 | 506 | if (is_array($rows)) |
507 | 507 | { |
508 | - foreach($rows as &$row) |
|
508 | + foreach ($rows as &$row) |
|
509 | 509 | { |
510 | 510 | $values = array(); |
511 | - foreach($cols as $col) |
|
511 | + foreach ($cols as $col) |
|
512 | 512 | { |
513 | 513 | $values[] = $row[$col]; |
514 | 514 | } |
515 | - $row = implode(self::ONE2N_SEPERATOR,$values); |
|
515 | + $row = implode(self::ONE2N_SEPERATOR, $values); |
|
516 | 516 | } |
517 | 517 | } |
518 | 518 | else |
@@ -531,7 +531,7 @@ discard block |
||
531 | 531 | * @param array $email_notified=null if present will return the emails notified, if given emails in that list will not be notified |
532 | 532 | * @return boolean true on success, false on error (error messages are in $this->errors) |
533 | 533 | */ |
534 | - public function do_notifications($data,$old,$deleted=null,&$email_notified=null) |
|
534 | + public function do_notifications($data, $old, $deleted = null, &$email_notified = null) |
|
535 | 535 | { |
536 | 536 | $this->errors = $email_sent = array(); |
537 | 537 | if (!empty($email_notified) && is_array($email_notified)) $email_sent = $email_notified; |
@@ -539,19 +539,19 @@ discard block |
||
539 | 539 | if (!$this->notify_current_user && $this->user) // do we have a current user and should we notify the current user about his own changes |
540 | 540 | { |
541 | 541 | //error_log("do_notificaton() adding user=$this->user to email_sent, to not notify him"); |
542 | - $email_sent[] = $GLOBALS['egw']->accounts->id2name($this->user,'account_email'); |
|
542 | + $email_sent[] = $GLOBALS['egw']->accounts->id2name($this->user, 'account_email'); |
|
543 | 543 | } |
544 | - $skip_notify = $this->get_config('skip_notify',$data,$old); |
|
545 | - if($skip_notify && is_array($skip_notify)) |
|
544 | + $skip_notify = $this->get_config('skip_notify', $data, $old); |
|
545 | + if ($skip_notify && is_array($skip_notify)) |
|
546 | 546 | { |
547 | 547 | $email_sent = array_merge($email_sent, $skip_notify); |
548 | 548 | } |
549 | 549 | |
550 | 550 | // entry creator |
551 | - if ($this->creator_field && ($email = $GLOBALS['egw']->accounts->id2name($data[$this->creator_field],'account_email')) && |
|
551 | + if ($this->creator_field && ($email = $GLOBALS['egw']->accounts->id2name($data[$this->creator_field], 'account_email')) && |
|
552 | 552 | !in_array($email, $email_sent)) |
553 | 553 | { |
554 | - if ($this->send_notification($data,$old,$email,$data[$this->creator_field],'notify_creator')) |
|
554 | + if ($this->send_notification($data, $old, $email, $data[$this->creator_field], 'notify_creator')) |
|
555 | 555 | { |
556 | 556 | $email_sent[] = $email; |
557 | 557 | } |
@@ -560,12 +560,12 @@ discard block |
||
560 | 560 | // members of group when entry owned by group |
561 | 561 | if ($this->creator_field && $GLOBALS['egw']->accounts->get_type($data[$this->creator_field]) == 'g') |
562 | 562 | { |
563 | - foreach($GLOBALS['egw']->accounts->members($data[$this->creator_field],true) as $u) |
|
563 | + foreach ($GLOBALS['egw']->accounts->members($data[$this->creator_field], true) as $u) |
|
564 | 564 | { |
565 | - if (($email = $GLOBALS['egw']->accounts->id2name($u,'account_email')) && |
|
565 | + if (($email = $GLOBALS['egw']->accounts->id2name($u, 'account_email')) && |
|
566 | 566 | !in_array($email, $email_sent)) |
567 | 567 | { |
568 | - if ($this->send_notification($data,$old,$email,$u,'notify_owner_group_member')) |
|
568 | + if ($this->send_notification($data, $old, $email, $u, 'notify_owner_group_member')) |
|
569 | 569 | { |
570 | 570 | $email_sent[] = $email; |
571 | 571 | } |
@@ -582,14 +582,14 @@ discard block |
||
582 | 582 | if ($data[$this->assigned_field]) // current assignments |
583 | 583 | { |
584 | 584 | $assignees = is_array($data[$this->assigned_field]) ? |
585 | - $data[$this->assigned_field] : explode(',',$data[$this->assigned_field]); |
|
585 | + $data[$this->assigned_field] : explode(',', $data[$this->assigned_field]); |
|
586 | 586 | } |
587 | 587 | if ($old && $old[$this->assigned_field]) |
588 | 588 | { |
589 | 589 | $old_assignees = is_array($old[$this->assigned_field]) ? |
590 | - $old[$this->assigned_field] : explode(',',$old[$this->assigned_field]); |
|
590 | + $old[$this->assigned_field] : explode(',', $old[$this->assigned_field]); |
|
591 | 591 | } |
592 | - foreach(array_unique(array_merge($assignees,$old_assignees)) as $assignee) |
|
592 | + foreach (array_unique(array_merge($assignees, $old_assignees)) as $assignee) |
|
593 | 593 | { |
594 | 594 | //error_log(__METHOD__."() assignee=$assignee, type=".$GLOBALS['egw']->accounts->get_type($assignee).", email=".$GLOBALS['egw']->accounts->id2name($assignee,'account_email')); |
595 | 595 | if (!$assignee) continue; |
@@ -597,10 +597,10 @@ discard block |
||
597 | 597 | // item assignee is a user |
598 | 598 | if ($GLOBALS['egw']->accounts->get_type($assignee) == 'u') |
599 | 599 | { |
600 | - if (($email = $GLOBALS['egw']->accounts->id2name($assignee,'account_email')) && !in_array($email, $email_sent)) |
|
600 | + if (($email = $GLOBALS['egw']->accounts->id2name($assignee, 'account_email')) && !in_array($email, $email_sent)) |
|
601 | 601 | { |
602 | - if ($this->send_notification($data,$old,$email,$assignee,'notify_assigned', |
|
603 | - in_array($assignee,$assignees) !== in_array($assignee,$old_assignees) || $deleted)) // assignment changed |
|
602 | + if ($this->send_notification($data, $old, $email, $assignee, 'notify_assigned', |
|
603 | + in_array($assignee, $assignees) !== in_array($assignee, $old_assignees) || $deleted)) // assignment changed |
|
604 | 604 | { |
605 | 605 | $email_sent[] = $email; |
606 | 606 | } |
@@ -608,12 +608,12 @@ discard block |
||
608 | 608 | } |
609 | 609 | else // item assignee is a group |
610 | 610 | { |
611 | - foreach($GLOBALS['egw']->accounts->members($assignee,true) as $u) |
|
611 | + foreach ($GLOBALS['egw']->accounts->members($assignee, true) as $u) |
|
612 | 612 | { |
613 | - if (($email = $GLOBALS['egw']->accounts->id2name($u,'account_email')) && !in_array($email, $email_sent)) |
|
613 | + if (($email = $GLOBALS['egw']->accounts->id2name($u, 'account_email')) && !in_array($email, $email_sent)) |
|
614 | 614 | { |
615 | - if ($this->send_notification($data,$old,$email,$u,'notify_assigned', |
|
616 | - in_array($u,$assignees) !== in_array($u,$old_assignees) || $deleted)) // assignment changed |
|
615 | + if ($this->send_notification($data, $old, $email, $u, 'notify_assigned', |
|
616 | + in_array($u, $assignees) !== in_array($u, $old_assignees) || $deleted)) // assignment changed |
|
617 | 617 | { |
618 | 618 | $email_sent[] = $email; |
619 | 619 | } |
@@ -624,14 +624,14 @@ discard block |
||
624 | 624 | } |
625 | 625 | |
626 | 626 | // notification copies |
627 | - if (($copies = $this->get_config('copy',$data,$old))) |
|
627 | + if (($copies = $this->get_config('copy', $data, $old))) |
|
628 | 628 | { |
629 | - $lang = $this->get_config('lang',$data,$old); |
|
630 | - foreach($copies as $email) |
|
629 | + $lang = $this->get_config('lang', $data, $old); |
|
630 | + foreach ($copies as $email) |
|
631 | 631 | { |
632 | - if (strchr($email,'@') !== false && !in_array($email, $email_sent)) |
|
632 | + if (strchr($email, '@') !== false && !in_array($email, $email_sent)) |
|
633 | 633 | { |
634 | - if ($this->send_notification($data,$old,$email,$lang,'notify_copy')) |
|
634 | + if ($this->send_notification($data, $old, $email, $lang, 'notify_copy')) |
|
635 | 635 | { |
636 | 636 | $email_sent[] = $email; |
637 | 637 | } |
@@ -676,7 +676,7 @@ discard block |
||
676 | 676 | * @param boolean $deleted = null can be set to true to let the tracking know the item got deleted or undelted |
677 | 677 | * @return boolean true on success or false if notification not requested or error (error-message is in $this->errors) |
678 | 678 | */ |
679 | - public function send_notification($data,$old,$email,$user_or_lang,$check=null,$assignment_changed=true,$deleted=null) |
|
679 | + public function send_notification($data, $old, $email, $user_or_lang, $check = null, $assignment_changed = true, $deleted = null) |
|
680 | 680 | { |
681 | 681 | //error_log(__METHOD__."(,,'$email',$user_or_lang,$check,$assignment_changed,$deleted)"); |
682 | 682 | if (!$email) return false; |
@@ -688,16 +688,16 @@ discard block |
||
688 | 688 | { |
689 | 689 | $GLOBALS['egw_info']['user']['account_id'] = $user_or_lang; |
690 | 690 | $GLOBALS['egw']->preferences->__construct($user_or_lang); |
691 | - $GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(false); // no session prefs! |
|
691 | + $GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(false); // no session prefs! |
|
692 | 692 | |
693 | 693 | if ($check && $this->check2pref) $check = $this->check2pref[$check]; |
694 | 694 | |
695 | - if ($check && !$GLOBALS['egw_info']['user']['preferences'][$this->app][$check] || // no notification requested |
|
695 | + if ($check && !$GLOBALS['egw_info']['user']['preferences'][$this->app][$check] || // no notification requested |
|
696 | 696 | // only notification about changed assignment requested |
697 | 697 | $check && $GLOBALS['egw_info']['user']['preferences'][$this->app][$check] === 'assignment' && !$assignment_changed || |
698 | 698 | $this->user == $user_or_lang && !$this->notify_current_user) // no popup for own actions |
699 | 699 | { |
700 | - $do_notify = false; // no notification requested / necessary |
|
700 | + $do_notify = false; // no notification requested / necessary |
|
701 | 701 | } |
702 | 702 | } |
703 | 703 | else |
@@ -720,33 +720,33 @@ discard block |
||
720 | 720 | |
721 | 721 | // Cache message body to not have to re-generate it every time |
722 | 722 | $lang = Api\Translation::$userlang; |
723 | - $date_format = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'] . |
|
723 | + $date_format = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat']. |
|
724 | 724 | $GLOBALS['egw_info']['user']['preferences']['common']['timeformat']; |
725 | 725 | |
726 | 726 | // Cache text body |
727 | - $body_cache =& $this->body_cache[$data[$this->id_field]][$lang][$date_format]; |
|
728 | - if(empty($data[$this->id_field]) || !isset($body_cache['text'])) |
|
727 | + $body_cache = & $this->body_cache[$data[$this->id_field]][$lang][$date_format]; |
|
728 | + if (empty($data[$this->id_field]) || !isset($body_cache['text'])) |
|
729 | 729 | { |
730 | - $body_cache['text'] = $this->get_body(false,$data,$old,false,$receiver); |
|
730 | + $body_cache['text'] = $this->get_body(false, $data, $old, false, $receiver); |
|
731 | 731 | } |
732 | 732 | // Cache HTML body |
733 | - if(empty($data[$this->id_field]) || !isset($body_cache['html'])) |
|
733 | + if (empty($data[$this->id_field]) || !isset($body_cache['html'])) |
|
734 | 734 | { |
735 | - $body_cache['html'] = $this->get_body(true,$data,$old,false,$receiver); |
|
735 | + $body_cache['html'] = $this->get_body(true, $data, $old, false, $receiver); |
|
736 | 736 | } |
737 | 737 | |
738 | 738 | // get rest of notification message |
739 | - $sender = $this->get_sender($data,$old,true,$receiver); |
|
740 | - $subject = $this->get_subject($data,$old,$deleted,$receiver); |
|
741 | - $link = $this->get_notification_link($data,$old,$receiver); |
|
742 | - $attachments = $this->get_attachments($data,$old,$receiver); |
|
739 | + $sender = $this->get_sender($data, $old, true, $receiver); |
|
740 | + $subject = $this->get_subject($data, $old, $deleted, $receiver); |
|
741 | + $link = $this->get_notification_link($data, $old, $receiver); |
|
742 | + $attachments = $this->get_attachments($data, $old, $receiver); |
|
743 | 743 | } |
744 | 744 | |
745 | 745 | // restore user enviroment BEFORE calling notification class or returning |
746 | 746 | $GLOBALS['egw_info']['user'] = $save_user; |
747 | 747 | // need to call preferences constructor and read_repository, to set user timezone again |
748 | 748 | $GLOBALS['egw']->preferences->__construct($GLOBALS['egw_info']['user']['account_id']); |
749 | - $GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(false); // no session prefs! |
|
749 | + $GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(false); // no session prefs! |
|
750 | 750 | |
751 | 751 | // Re-load date/time preferences |
752 | 752 | Api\DateTime::init(); |
@@ -801,11 +801,11 @@ discard block |
||
801 | 801 | * |
802 | 802 | * @return string |
803 | 803 | */ |
804 | - public function datetime($timestamp,$do_time=true) |
|
804 | + public function datetime($timestamp, $do_time = true) |
|
805 | 805 | { |
806 | - if (!is_a($timestamp,'DateTime')) |
|
806 | + if (!is_a($timestamp, 'DateTime')) |
|
807 | 807 | { |
808 | - $timestamp = new Api\DateTime($timestamp,Api\DateTime::$server_timezone); |
|
808 | + $timestamp = new Api\DateTime($timestamp, Api\DateTime::$server_timezone); |
|
809 | 809 | } |
810 | 810 | $timestamp->setTimezone(Api\DateTime::$user_timezone); |
811 | 811 | if (is_null($do_time)) |
@@ -831,25 +831,25 @@ discard block |
||
831 | 831 | * @param int|string $receiver nummeric account_id or email address |
832 | 832 | * @return string or userid |
833 | 833 | */ |
834 | - protected function get_sender($data,$old,$prefer_id=false,$receiver=null) |
|
834 | + protected function get_sender($data, $old, $prefer_id = false, $receiver = null) |
|
835 | 835 | { |
836 | - unset($receiver); // not used, but required by function signature |
|
836 | + unset($receiver); // not used, but required by function signature |
|
837 | 837 | |
838 | - $sender = $this->get_config('sender',$data,$old); |
|
838 | + $sender = $this->get_config('sender', $data, $old); |
|
839 | 839 | //echo "<p>".__METHOD__."() get_config('sender',...)='".htmlspecialchars($sender)."'</p>\n"; |
840 | 840 | |
841 | 841 | if (($this->prefer_user_as_sender || !$sender) && $this->user && |
842 | - ($email = $GLOBALS['egw']->accounts->id2name($this->user,'account_email'))) |
|
842 | + ($email = $GLOBALS['egw']->accounts->id2name($this->user, 'account_email'))) |
|
843 | 843 | { |
844 | - $name = $GLOBALS['egw']->accounts->id2name($this->user,'account_fullname'); |
|
844 | + $name = $GLOBALS['egw']->accounts->id2name($this->user, 'account_fullname'); |
|
845 | 845 | |
846 | - if($prefer_id) { |
|
846 | + if ($prefer_id) { |
|
847 | 847 | $sender = $this->user; |
848 | 848 | } else { |
849 | 849 | $sender = $name ? $name.' <'.$email.'>' : $email; |
850 | 850 | } |
851 | 851 | } |
852 | - elseif(!$sender) |
|
852 | + elseif (!$sender) |
|
853 | 853 | { |
854 | 854 | $sender = 'eGroupWare '.lang($this->app).' <noreply@'.$GLOBALS['egw_info']['server']['mail_suffix'].'>'; |
855 | 855 | } |
@@ -864,11 +864,11 @@ discard block |
||
864 | 864 | * @param array $old |
865 | 865 | * @return string |
866 | 866 | */ |
867 | - protected function get_title($data,$old) |
|
867 | + protected function get_title($data, $old) |
|
868 | 868 | { |
869 | - unset($old); // not used, but required by function signature |
|
869 | + unset($old); // not used, but required by function signature |
|
870 | 870 | |
871 | - return Api\Link::title($this->app,$data[$this->id_field]); |
|
871 | + return Api\Link::title($this->app, $data[$this->id_field]); |
|
872 | 872 | } |
873 | 873 | |
874 | 874 | /** |
@@ -882,11 +882,11 @@ discard block |
||
882 | 882 | * @param int|string $receiver nummeric account_id or email address |
883 | 883 | * @return string |
884 | 884 | */ |
885 | - protected function get_subject($data,$old,$deleted=null,$receiver=null) |
|
885 | + protected function get_subject($data, $old, $deleted = null, $receiver = null) |
|
886 | 886 | { |
887 | - unset($old, $deleted, $receiver); // not used, but required by function signature |
|
887 | + unset($old, $deleted, $receiver); // not used, but required by function signature |
|
888 | 888 | |
889 | - return Api\Link::title($this->app,$data[$this->id_field]); |
|
889 | + return Api\Link::title($this->app, $data[$this->id_field]); |
|
890 | 890 | } |
891 | 891 | |
892 | 892 | /** |
@@ -899,9 +899,9 @@ discard block |
||
899 | 899 | * @param int|string $receiver nummeric account_id or email address |
900 | 900 | * @return string |
901 | 901 | */ |
902 | - protected function get_message($data,$old,$receiver=null) |
|
902 | + protected function get_message($data, $old, $receiver = null) |
|
903 | 903 | { |
904 | - unset($data, $old, $receiver); // not used, but required by function signature |
|
904 | + unset($data, $old, $receiver); // not used, but required by function signature |
|
905 | 905 | |
906 | 906 | return ''; |
907 | 907 | } |
@@ -917,24 +917,24 @@ discard block |
||
917 | 917 | * @param int|string $receiver nummeric account_id or email address |
918 | 918 | * @return string|array string with link (!$allow_popup) or array(link,popup-size), popup size is something like '640x480' |
919 | 919 | */ |
920 | - protected function get_link($data,$old,$allow_popup=false,$receiver=null) |
|
920 | + protected function get_link($data, $old, $allow_popup = false, $receiver = null) |
|
921 | 921 | { |
922 | - unset($receiver); // not used, but required by function signature |
|
922 | + unset($receiver); // not used, but required by function signature |
|
923 | 923 | |
924 | - if (($link = $this->get_config('link',$data,$old))) |
|
924 | + if (($link = $this->get_config('link', $data, $old))) |
|
925 | 925 | { |
926 | - if (!$this->get_config('link_no_id', $data) && strpos($link,$this->id_field.'=') === false && isset($data[$this->id_field])) |
|
926 | + if (!$this->get_config('link_no_id', $data) && strpos($link, $this->id_field.'=') === false && isset($data[$this->id_field])) |
|
927 | 927 | { |
928 | - $link .= strpos($link,'?') === false ? '?' : '&'; |
|
928 | + $link .= strpos($link, '?') === false ? '?' : '&'; |
|
929 | 929 | $link .= $this->id_field.'='.$data[$this->id_field]; |
930 | 930 | } |
931 | 931 | } |
932 | 932 | else |
933 | 933 | { |
934 | - if (($view = Api\Link::view($this->app,$data[$this->id_field]))) |
|
934 | + if (($view = Api\Link::view($this->app, $data[$this->id_field]))) |
|
935 | 935 | { |
936 | - $link = $GLOBALS['egw']->link('/index.php',$view); |
|
937 | - $popup = Api\Link::is_popup($this->app,'view'); |
|
936 | + $link = $GLOBALS['egw']->link('/index.php', $view); |
|
937 | + $popup = Api\Link::is_popup($this->app, 'view'); |
|
938 | 938 | } |
939 | 939 | } |
940 | 940 | if ($link[0] == '/') |
@@ -945,12 +945,12 @@ discard block |
||
945 | 945 | if (!$allow_popup) |
946 | 946 | { |
947 | 947 | // remove the session-id in the notification mail! |
948 | - $link = preg_replace('/(sessionid|kp3|domain)=[^&]+&?/','',$link); |
|
948 | + $link = preg_replace('/(sessionid|kp3|domain)=[^&]+&?/', '', $link); |
|
949 | 949 | |
950 | 950 | if ($popup) $link .= '&nopopup=1'; |
951 | 951 | } |
952 | 952 | //error_log(__METHOD__."(..., $allow_popup, $receiver) returning ".array2string($allow_popup ? array($link,$popup) : $link)); |
953 | - return $allow_popup ? array($link,$popup) : $link; |
|
953 | + return $allow_popup ? array($link, $popup) : $link; |
|
954 | 954 | } |
955 | 955 | |
956 | 956 | /** |
@@ -961,18 +961,18 @@ discard block |
||
961 | 961 | * @param int|string $receiver nummeric account_id or email address |
962 | 962 | * @return array with link |
963 | 963 | */ |
964 | - protected function get_notification_link($data,$old,$receiver=null) |
|
964 | + protected function get_notification_link($data, $old, $receiver = null) |
|
965 | 965 | { |
966 | - unset($receiver); // not used, but required by function signature |
|
966 | + unset($receiver); // not used, but required by function signature |
|
967 | 967 | |
968 | - if (($view = Api\Link::view($this->app,$data[$this->id_field]))) |
|
968 | + if (($view = Api\Link::view($this->app, $data[$this->id_field]))) |
|
969 | 969 | { |
970 | 970 | return array( |
971 | - 'text' => $this->get_title($data,$old), |
|
971 | + 'text' => $this->get_title($data, $old), |
|
972 | 972 | 'app' => $this->app, |
973 | 973 | 'id' => $data[$this->id_field], |
974 | 974 | 'view' => $view, |
975 | - 'popup' => Api\Link::is_popup($this->app,'view'), |
|
975 | + 'popup' => Api\Link::is_popup($this->app, 'view'), |
|
976 | 976 | ); |
977 | 977 | } |
978 | 978 | return false; |
@@ -988,15 +988,15 @@ discard block |
||
988 | 988 | * @param int|string $receiver nummeric account_id or email address |
989 | 989 | * @return string |
990 | 990 | */ |
991 | - public function get_body($html_email,$data,$old,$integrate_link = true,$receiver=null) |
|
991 | + public function get_body($html_email, $data, $old, $integrate_link = true, $receiver = null) |
|
992 | 992 | { |
993 | 993 | $body = ''; |
994 | - if($this->get_config(self::CUSTOM_NOTIFICATION, $data, $old)) |
|
994 | + if ($this->get_config(self::CUSTOM_NOTIFICATION, $data, $old)) |
|
995 | 995 | { |
996 | - $body = $this->get_custom_message($data,$old); |
|
997 | - if(($sig = $this->get_signature($data,$old,$receiver))) |
|
996 | + $body = $this->get_custom_message($data, $old); |
|
997 | + if (($sig = $this->get_signature($data, $old, $receiver))) |
|
998 | 998 | { |
999 | - $body .= ($html_email ? '<br />':'') . "\n$sig"; |
|
999 | + $body .= ($html_email ? '<br />' : '')."\n$sig"; |
|
1000 | 1000 | } |
1001 | 1001 | return $body; |
1002 | 1002 | } |
@@ -1005,35 +1005,35 @@ discard block |
||
1005 | 1005 | $body = '<table cellspacing="2" cellpadding="0" border="0" width="100%">'."\n"; |
1006 | 1006 | } |
1007 | 1007 | // new or modified message |
1008 | - if (($message = $this->get_message($data,$old,$receiver))) |
|
1008 | + if (($message = $this->get_message($data, $old, $receiver))) |
|
1009 | 1009 | { |
1010 | 1010 | foreach ((array)$message as $_message) |
1011 | 1011 | { |
1012 | - $body .= $this->format_line($html_email,'message',false,($_message=='---'?($html_email?'<hr/>':$_message):$_message)); |
|
1012 | + $body .= $this->format_line($html_email, 'message', false, ($_message == '---' ? ($html_email ? '<hr/>' : $_message) : $_message)); |
|
1013 | 1013 | } |
1014 | 1014 | } |
1015 | - if ($integrate_link && ($link = $this->get_link($data,$old,false,$receiver))) |
|
1015 | + if ($integrate_link && ($link = $this->get_link($data, $old, false, $receiver))) |
|
1016 | 1016 | { |
1017 | - $body .= $this->format_line($html_email,'link',false,$integrate_link === true ? lang('You can respond by visiting:') : $integrate_link,$link); |
|
1017 | + $body .= $this->format_line($html_email, 'link', false, $integrate_link === true ? lang('You can respond by visiting:') : $integrate_link, $link); |
|
1018 | 1018 | } |
1019 | - foreach($this->get_details($data,$receiver) as $name => $detail) |
|
1019 | + foreach ($this->get_details($data, $receiver) as $name => $detail) |
|
1020 | 1020 | { |
1021 | 1021 | // if there's no old entry, the entry is not modified by definition |
1022 | 1022 | // if both values are '', 0 or null, we count them as equal too |
1023 | 1023 | $modified = $old && $data[$name] != $old[$name] && !(!$data[$name] && !$old[$name]); |
1024 | 1024 | //if ($modified) error_log("data[$name]=".print_r($data[$name],true).", old[$name]=".print_r($old[$name],true)." --> modified=".(int)$modified); |
1025 | - if (empty($detail['value']) && !$modified) continue; // skip unchanged, empty values |
|
1025 | + if (empty($detail['value']) && !$modified) continue; // skip unchanged, empty values |
|
1026 | 1026 | |
1027 | - $body .= $this->format_line($html_email,$detail['type'],$modified, |
|
1027 | + $body .= $this->format_line($html_email, $detail['type'], $modified, |
|
1028 | 1028 | $detail['label'] ? $detail['label'] : '', $detail['value']); |
1029 | 1029 | } |
1030 | 1030 | if ($html_email) |
1031 | 1031 | { |
1032 | 1032 | $body .= "</table>\n"; |
1033 | 1033 | } |
1034 | - if(($sig = $this->get_signature($data,$old,$receiver))) |
|
1034 | + if (($sig = $this->get_signature($data, $old, $receiver))) |
|
1035 | 1035 | { |
1036 | - $body .= ($html_email ? '<br />':'') . "\n$sig"; |
|
1036 | + $body .= ($html_email ? '<br />' : '')."\n$sig"; |
|
1037 | 1037 | } |
1038 | 1038 | return $body; |
1039 | 1039 | } |
@@ -1049,20 +1049,20 @@ discard block |
||
1049 | 1049 | * @param string $data = null data or null to display just $line over 2 columns |
1050 | 1050 | * @return string |
1051 | 1051 | */ |
1052 | - protected function format_line($html_mail,$type,$modified,$line,$data=null) |
|
1052 | + protected function format_line($html_mail, $type, $modified, $line, $data = null) |
|
1053 | 1053 | { |
1054 | 1054 | //error_log(__METHOD__.'('.array2string($html_mail).",'$type',".array2string($modified).",'$line',".array2string($data).')'); |
1055 | 1055 | $content = ''; |
1056 | 1056 | |
1057 | 1057 | if ($html_mail) |
1058 | 1058 | { |
1059 | - if (!$this->html_content_allow) $line = Api\Html::htmlspecialchars($line); // XSS |
|
1059 | + if (!$this->html_content_allow) $line = Api\Html::htmlspecialchars($line); // XSS |
|
1060 | 1060 | |
1061 | 1061 | $color = $modified ? 'red' : false; |
1062 | 1062 | $size = '110%'; |
1063 | 1063 | $bold = false; |
1064 | 1064 | $background = '#FFFFF1'; |
1065 | - switch($type) |
|
1065 | + switch ($type) |
|
1066 | 1066 | { |
1067 | 1067 | case 'message': |
1068 | 1068 | $background = '#D3DCE3;'; |
@@ -1080,7 +1080,7 @@ discard block |
||
1080 | 1080 | if (strpos($data, '<br') === false) |
1081 | 1081 | { |
1082 | 1082 | $data = nl2br($this->html_content_allow ? $data : Api\Html::htmlspecialchars($data)); |
1083 | - $this->html_content_allow = true; // to NOT do htmlspecialchars again |
|
1083 | + $this->html_content_allow = true; // to NOT do htmlspecialchars again |
|
1084 | 1084 | } |
1085 | 1085 | break; |
1086 | 1086 | case 'reply': |
@@ -1089,13 +1089,13 @@ discard block |
||
1089 | 1089 | default: |
1090 | 1090 | $size = false; |
1091 | 1091 | } |
1092 | - $style = ($bold ? 'font-weight:bold;' : '').($size ? 'font-size:'.$size.';' : '').($color?'color:'.$color:''); |
|
1092 | + $style = ($bold ? 'font-weight:bold;' : '').($size ? 'font-size:'.$size.';' : '').($color ? 'color:'.$color : ''); |
|
1093 | 1093 | |
1094 | - $content = '<tr style="background-color: '.$background.';"><td style="'.$style.($line && $data?'" width="20%':'" colspan="2').'">'; |
|
1094 | + $content = '<tr style="background-color: '.$background.';"><td style="'.$style.($line && $data ? '" width="20%' : '" colspan="2').'">'; |
|
1095 | 1095 | } |
1096 | 1096 | else // text-mail |
1097 | 1097 | { |
1098 | - if ($type == 'reply') $content = str_repeat('-',64)."\n"; |
|
1098 | + if ($type == 'reply') $content = str_repeat('-', 64)."\n"; |
|
1099 | 1099 | |
1100 | 1100 | if ($modified) $content .= '> '; |
1101 | 1101 | } |
@@ -1107,7 +1107,7 @@ discard block |
||
1107 | 1107 | if ($type == 'link') |
1108 | 1108 | { |
1109 | 1109 | // the link is often too long for html boxes chunk-split allows to break lines if needed |
1110 | - $content .= Api\Html::a_href(chunk_split(rawurldecode($data),40,'​'),$data,'','target="_blank"'); |
|
1110 | + $content .= Api\Html::a_href(chunk_split(rawurldecode($data), 40, '​'), $data, '', 'target="_blank"'); |
|
1111 | 1111 | } |
1112 | 1112 | elseif ($this->html_content_allow) |
1113 | 1113 | { |
@@ -1120,7 +1120,7 @@ discard block |
||
1120 | 1120 | } |
1121 | 1121 | else |
1122 | 1122 | { |
1123 | - $content .= ($content&&$data?': ':'').$data; |
|
1123 | + $content .= ($content && $data ? ': ' : '').$data; |
|
1124 | 1124 | } |
1125 | 1125 | if ($html_mail) $content .= '</td></tr>'; |
1126 | 1126 | |
@@ -1137,9 +1137,9 @@ discard block |
||
1137 | 1137 | * @param int|string $receiver nummeric account_id or email address |
1138 | 1138 | * @return array or array with values for either 'string' or 'path' and optionally (mime-)'type', 'filename' and 'encoding' |
1139 | 1139 | */ |
1140 | - protected function get_attachments($data,$old,$receiver=null) |
|
1140 | + protected function get_attachments($data, $old, $receiver = null) |
|
1141 | 1141 | { |
1142 | - unset($data, $old, $receiver); // not used, but required by function signature |
|
1142 | + unset($data, $old, $receiver); // not used, but required by function signature |
|
1143 | 1143 | |
1144 | 1144 | return array(); |
1145 | 1145 | } |
@@ -1152,20 +1152,20 @@ discard block |
||
1152 | 1152 | */ |
1153 | 1153 | protected function get_signature($data, $old, $receiver) |
1154 | 1154 | { |
1155 | - unset($old, $receiver); // not used, but required by function signature |
|
1155 | + unset($old, $receiver); // not used, but required by function signature |
|
1156 | 1156 | |
1157 | 1157 | $config = Api\Config::read('notifications'); |
1158 | - if(!isset($data[$this->id_field])) |
|
1158 | + if (!isset($data[$this->id_field])) |
|
1159 | 1159 | { |
1160 | - error_log($this->app . ' did not properly implement bo_tracking->id_field. Merge skipped.'); |
|
1160 | + error_log($this->app.' did not properly implement bo_tracking->id_field. Merge skipped.'); |
|
1161 | 1161 | } |
1162 | - elseif(class_exists($this->app. '_merge')) |
|
1162 | + elseif (class_exists($this->app.'_merge')) |
|
1163 | 1163 | { |
1164 | 1164 | $merge_class = $this->app.'_merge'; |
1165 | 1165 | $merge = new $merge_class(); |
1166 | 1166 | $error = null; |
1167 | 1167 | $sig = $merge->merge_string($config['signature'], array($data[$this->id_field]), $error, 'text/html'); |
1168 | - if($error) |
|
1168 | + if ($error) |
|
1169 | 1169 | { |
1170 | 1170 | error_log($error); |
1171 | 1171 | return $config['signature']; |
@@ -1182,27 +1182,27 @@ discard block |
||
1182 | 1182 | protected function get_custom_message($data, $old, $merge_class = null) |
1183 | 1183 | { |
1184 | 1184 | $message = $this->get_config(self::CUSTOM_NOTIFICATION, $data, $old); |
1185 | - if(!$message) |
|
1185 | + if (!$message) |
|
1186 | 1186 | { |
1187 | 1187 | return ''; |
1188 | 1188 | } |
1189 | 1189 | |
1190 | 1190 | // Automatically set merge class from naming conventions |
1191 | - if($merge_class == null) |
|
1191 | + if ($merge_class == null) |
|
1192 | 1192 | { |
1193 | 1193 | $merge_class = $this->app.'_merge'; |
1194 | 1194 | } |
1195 | - if(!isset($data[$this->id_field])) |
|
1195 | + if (!isset($data[$this->id_field])) |
|
1196 | 1196 | { |
1197 | - error_log($this->app . ' did not properly implement bo_tracking->id_field. Merge skipped.'); |
|
1197 | + error_log($this->app.' did not properly implement bo_tracking->id_field. Merge skipped.'); |
|
1198 | 1198 | return $message; |
1199 | 1199 | } |
1200 | - elseif(class_exists($merge_class)) |
|
1200 | + elseif (class_exists($merge_class)) |
|
1201 | 1201 | { |
1202 | 1202 | $merge = new $merge_class(); |
1203 | 1203 | $error = null; |
1204 | 1204 | $merged_message = $merge->merge_string($message, array($data[$this->id_field]), $error, 'text/html'); |
1205 | - if($error) |
|
1205 | + if ($error) |
|
1206 | 1206 | { |
1207 | 1207 | error_log($error); |
1208 | 1208 | return $message; |
@@ -239,7 +239,10 @@ discard block |
||
239 | 239 | $header_done = false; |
240 | 240 | foreach($cfs as $name => $field) |
241 | 241 | { |
242 | - if (in_array($field['type'], Customfields::$non_printable_fields)) continue; |
|
242 | + if (in_array($field['type'], Customfields::$non_printable_fields)) |
|
243 | + { |
|
244 | + continue; |
|
245 | + } |
|
243 | 246 | |
244 | 247 | if (!$header_done) |
245 | 248 | { |
@@ -337,8 +340,14 @@ discard block |
||
337 | 340 | { |
338 | 341 | //error_log(__METHOD__.__LINE__.' Field:'.$name. ' Value (new):'.array2string($data[$name])); |
339 | 342 | //error_log(__METHOD__.__LINE__.' Field:'.$name. ' Value (old):'.array2string($old[$name])); |
340 | - if (is_array($data[$name]) && array_key_exists('id',$data[$name])) $data[$name] = $data[$name]['id']; |
|
341 | - if (is_array($old[$name]) && array_key_exists('id',$old[$name])) $old[$name] = $old[$name]['id']; |
|
343 | + if (is_array($data[$name]) && array_key_exists('id',$data[$name])) |
|
344 | + { |
|
345 | + $data[$name] = $data[$name]['id']; |
|
346 | + } |
|
347 | + if (is_array($old[$name]) && array_key_exists('id',$old[$name])) |
|
348 | + { |
|
349 | + $old[$name] = $old[$name]['id']; |
|
350 | + } |
|
342 | 351 | //error_log(__METHOD__.__LINE__.'(After processing) Field:'.$name. ' Value (new):'.array2string($data[$name])); |
343 | 352 | //error_log(__METHOD__.__LINE__.'(After processing) Field:'.$name. ' Value (old):'.array2string($old[$name])); |
344 | 353 | } |
@@ -352,11 +361,18 @@ discard block |
||
352 | 361 | if (!($app = $this->cf_link_fields[$name])) |
353 | 362 | { |
354 | 363 | list($app,$id) = explode(':',$id); |
355 | - if (!$id) continue; // can be eg. 'addressbook:', if no contact selected |
|
364 | + if (!$id) |
|
365 | + { |
|
366 | + continue; |
|
367 | + } |
|
368 | + // can be eg. 'addressbook:', if no contact selected |
|
356 | 369 | } |
357 | 370 | $source_id = $data[$this->id_field]; |
358 | 371 | //error_log(__METHOD__.__LINE__.array2string($source_id)); |
359 | - if ($source_id) Api\Link::link($this->app,$source_id,$app,$id); |
|
372 | + if ($source_id) |
|
373 | + { |
|
374 | + Api\Link::link($this->app,$source_id,$app,$id); |
|
375 | + } |
|
360 | 376 | //error_log(__METHOD__.__LINE__."Api\Link::link('$this->app',".array2string($source_id).",'$app',$id);"); |
361 | 377 | //echo "<p>Api\Link::link('$this->app',{$data[$this->id_field]},'$app',$id);</p>\n"; |
362 | 378 | } |
@@ -364,14 +380,24 @@ discard block |
||
364 | 380 | // unlink removed application entries |
365 | 381 | foreach(array_diff($old_ids,$current_ids) as $name => $id) |
366 | 382 | { |
367 | - if (!isset($data[$name])) continue; // ignore not set link cf's, eg. from sync clients |
|
383 | + if (!isset($data[$name])) |
|
384 | + { |
|
385 | + continue; |
|
386 | + } |
|
387 | + // ignore not set link cf's, eg. from sync clients |
|
368 | 388 | if (!($app = $this->cf_link_fields[$name])) |
369 | 389 | { |
370 | 390 | list($app,$id) = explode(':',$id); |
371 | - if (!$id) continue; |
|
391 | + if (!$id) |
|
392 | + { |
|
393 | + continue; |
|
394 | + } |
|
372 | 395 | } |
373 | 396 | $source_id = $data[$this->id_field]; |
374 | - if ($source_id) Api\Link::unlink(null,$this->app,$source_id,0,$app,$id); |
|
397 | + if ($source_id) |
|
398 | + { |
|
399 | + Api\Link::unlink(null,$this->app,$source_id,0,$app,$id); |
|
400 | + } |
|
375 | 401 | //echo "<p>Api\Link::unlink(NULL,'$this->app',{$data[$this->id_field]},0,'$app',$id);</p>\n"; |
376 | 402 | } |
377 | 403 | } |
@@ -396,7 +422,10 @@ discard block |
||
396 | 422 | $changed_fields = self::changed_fields($data,$old); |
397 | 423 | //error_log(__METHOD__.__LINE__.' Changedfields:'.array2string($changed_fields)); |
398 | 424 | } |
399 | - if (!$changed_fields && ($old || !$GLOBALS['egw_info']['server']['log_user_agent_action'])) return 0; |
|
425 | + if (!$changed_fields && ($old || !$GLOBALS['egw_info']['server']['log_user_agent_action'])) |
|
426 | + { |
|
427 | + return 0; |
|
428 | + } |
|
400 | 429 | |
401 | 430 | if (!is_object($this->historylog) || $this->historylog->user != $this->user) |
402 | 431 | { |
@@ -412,10 +441,13 @@ discard block |
||
412 | 441 | { |
413 | 442 | $status = isset($this->field2history[$name]) ? $this->field2history[$name] : $name; |
414 | 443 | //error_log(__METHOD__.__LINE__." Name $name,".' Status:'.array2string($status)); |
415 | - if (is_array($status)) // 1:N relation --> remove common rows |
|
444 | + if (is_array($status)) |
|
445 | + { |
|
446 | + // 1:N relation --> remove common rows |
|
416 | 447 | { |
417 | 448 | //error_log(__METHOD__.__LINE__.' is Array'); |
418 | 449 | self::compact_1_N_relation($data[$name],$status); |
450 | + } |
|
419 | 451 | self::compact_1_N_relation($old[$name],$status); |
420 | 452 | $added = array_values(array_diff($data[$name],$old[$name])); |
421 | 453 | $removed = array_values(array_diff($old[$name],$data[$name])); |
@@ -449,17 +481,31 @@ discard block |
||
449 | 481 | */ |
450 | 482 | public function changed_fields(array $data,array $old=null) |
451 | 483 | { |
452 | - if (is_null($old)) return array_keys($data); |
|
484 | + if (is_null($old)) |
|
485 | + { |
|
486 | + return array_keys($data); |
|
487 | + } |
|
453 | 488 | $changed_fields = array(); |
454 | 489 | foreach($this->field2history as $name => $status) |
455 | 490 | { |
456 | - if (!$old[$name] && !$data[$name]) continue; // treat all sorts of empty equally |
|
491 | + if (!$old[$name] && !$data[$name]) |
|
492 | + { |
|
493 | + continue; |
|
494 | + } |
|
495 | + // treat all sorts of empty equally |
|
457 | 496 | |
458 | - if ($name[0] == '#' && !isset($data[$name])) continue; // no set customfields are not stored, therefore not changed |
|
497 | + if ($name[0] == '#' && !isset($data[$name])) |
|
498 | + { |
|
499 | + continue; |
|
500 | + } |
|
501 | + // no set customfields are not stored, therefore not changed |
|
459 | 502 | |
460 | - if (is_array($status)) // 1:N relation |
|
503 | + if (is_array($status)) |
|
504 | + { |
|
505 | + // 1:N relation |
|
461 | 506 | { |
462 | 507 | self::compact_1_N_relation($data[$name],$status); |
508 | + } |
|
463 | 509 | self::compact_1_N_relation($old[$name],$status); |
464 | 510 | } |
465 | 511 | if ($old[$name] != $data[$name]) |
@@ -467,13 +513,22 @@ discard block |
||
467 | 513 | // normalize arrays, we do NOT care for the order of multiselections |
468 | 514 | if (is_array($data[$name]) || is_array($old[$name])) |
469 | 515 | { |
470 | - if (!is_array($data[$name])) $data[$name] = explode(',',$data[$name]); |
|
471 | - if (!is_array($old[$name])) $old[$name] = explode(',',$old[$name]); |
|
516 | + if (!is_array($data[$name])) |
|
517 | + { |
|
518 | + $data[$name] = explode(',',$data[$name]); |
|
519 | + } |
|
520 | + if (!is_array($old[$name])) |
|
521 | + { |
|
522 | + $old[$name] = explode(',',$old[$name]); |
|
523 | + } |
|
472 | 524 | if (count($data[$name]) == count($old[$name])) |
473 | 525 | { |
474 | 526 | sort($data[$name]); |
475 | 527 | sort($old[$name]); |
476 | - if ($data[$name] == $old[$name]) continue; |
|
528 | + if ($data[$name] == $old[$name]) |
|
529 | + { |
|
530 | + continue; |
|
531 | + } |
|
477 | 532 | } |
478 | 533 | } |
479 | 534 | elseif (str_replace("\r", '', $old[$name]) == str_replace("\r", '', $data[$name])) |
@@ -534,13 +589,19 @@ discard block |
||
534 | 589 | public function do_notifications($data,$old,$deleted=null,&$email_notified=null) |
535 | 590 | { |
536 | 591 | $this->errors = $email_sent = array(); |
537 | - if (!empty($email_notified) && is_array($email_notified)) $email_sent = $email_notified; |
|
592 | + if (!empty($email_notified) && is_array($email_notified)) |
|
593 | + { |
|
594 | + $email_sent = $email_notified; |
|
595 | + } |
|
538 | 596 | |
539 | - if (!$this->notify_current_user && $this->user) // do we have a current user and should we notify the current user about his own changes |
|
597 | + if (!$this->notify_current_user && $this->user) |
|
598 | + { |
|
599 | + // do we have a current user and should we notify the current user about his own changes |
|
540 | 600 | { |
541 | 601 | //error_log("do_notificaton() adding user=$this->user to email_sent, to not notify him"); |
542 | 602 | $email_sent[] = $GLOBALS['egw']->accounts->id2name($this->user,'account_email'); |
543 | 603 | } |
604 | + } |
|
544 | 605 | $skip_notify = $this->get_config('skip_notify',$data,$old); |
545 | 606 | if($skip_notify && is_array($skip_notify)) |
546 | 607 | { |
@@ -579,11 +640,14 @@ discard block |
||
579 | 640 | //error_log(__METHOD__."() data[$this->assigned_field]=".print_r($data[$this->assigned_field],true).", old[$this->assigned_field]=".print_r($old[$this->assigned_field],true)); |
580 | 641 | $old_assignees = array(); |
581 | 642 | $assignees = $assigned ? $assigned : array(); |
582 | - if ($data[$this->assigned_field]) // current assignments |
|
643 | + if ($data[$this->assigned_field]) |
|
644 | + { |
|
645 | + // current assignments |
|
583 | 646 | { |
584 | 647 | $assignees = is_array($data[$this->assigned_field]) ? |
585 | 648 | $data[$this->assigned_field] : explode(',',$data[$this->assigned_field]); |
586 | 649 | } |
650 | + } |
|
587 | 651 | if ($old && $old[$this->assigned_field]) |
588 | 652 | { |
589 | 653 | $old_assignees = is_array($old[$this->assigned_field]) ? |
@@ -592,7 +656,10 @@ discard block |
||
592 | 656 | foreach(array_unique(array_merge($assignees,$old_assignees)) as $assignee) |
593 | 657 | { |
594 | 658 | //error_log(__METHOD__."() assignee=$assignee, type=".$GLOBALS['egw']->accounts->get_type($assignee).", email=".$GLOBALS['egw']->accounts->id2name($assignee,'account_email')); |
595 | - if (!$assignee) continue; |
|
659 | + if (!$assignee) |
|
660 | + { |
|
661 | + continue; |
|
662 | + } |
|
596 | 663 | |
597 | 664 | // item assignee is a user |
598 | 665 | if ($GLOBALS['egw']->accounts->get_type($assignee) == 'u') |
@@ -600,10 +667,13 @@ discard block |
||
600 | 667 | if (($email = $GLOBALS['egw']->accounts->id2name($assignee,'account_email')) && !in_array($email, $email_sent)) |
601 | 668 | { |
602 | 669 | if ($this->send_notification($data,$old,$email,$assignee,'notify_assigned', |
603 | - in_array($assignee,$assignees) !== in_array($assignee,$old_assignees) || $deleted)) // assignment changed |
|
670 | + in_array($assignee,$assignees) !== in_array($assignee,$old_assignees) || $deleted)) |
|
671 | + { |
|
672 | + // assignment changed |
|
604 | 673 | { |
605 | 674 | $email_sent[] = $email; |
606 | 675 | } |
676 | + } |
|
607 | 677 | } |
608 | 678 | } |
609 | 679 | else // item assignee is a group |
@@ -613,10 +683,13 @@ discard block |
||
613 | 683 | if (($email = $GLOBALS['egw']->accounts->id2name($u,'account_email')) && !in_array($email, $email_sent)) |
614 | 684 | { |
615 | 685 | if ($this->send_notification($data,$old,$email,$u,'notify_assigned', |
616 | - in_array($u,$assignees) !== in_array($u,$old_assignees) || $deleted)) // assignment changed |
|
686 | + in_array($u,$assignees) !== in_array($u,$old_assignees) || $deleted)) |
|
687 | + { |
|
688 | + // assignment changed |
|
617 | 689 | { |
618 | 690 | $email_sent[] = $email; |
619 | 691 | } |
692 | + } |
|
620 | 693 | } |
621 | 694 | } |
622 | 695 | } |
@@ -679,25 +752,38 @@ discard block |
||
679 | 752 | public function send_notification($data,$old,$email,$user_or_lang,$check=null,$assignment_changed=true,$deleted=null) |
680 | 753 | { |
681 | 754 | //error_log(__METHOD__."(,,'$email',$user_or_lang,$check,$assignment_changed,$deleted)"); |
682 | - if (!$email) return false; |
|
755 | + if (!$email) |
|
756 | + { |
|
757 | + return false; |
|
758 | + } |
|
683 | 759 | |
684 | 760 | $save_user = $GLOBALS['egw_info']['user']; |
685 | 761 | $do_notify = true; |
686 | 762 | |
687 | - if (is_numeric($user_or_lang)) // user --> read everything from his prefs |
|
763 | + if (is_numeric($user_or_lang)) |
|
764 | + { |
|
765 | + // user --> read everything from his prefs |
|
688 | 766 | { |
689 | 767 | $GLOBALS['egw_info']['user']['account_id'] = $user_or_lang; |
768 | + } |
|
690 | 769 | $GLOBALS['egw']->preferences->__construct($user_or_lang); |
691 | 770 | $GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->read_repository(false); // no session prefs! |
692 | 771 | |
693 | - if ($check && $this->check2pref) $check = $this->check2pref[$check]; |
|
772 | + if ($check && $this->check2pref) |
|
773 | + { |
|
774 | + $check = $this->check2pref[$check]; |
|
775 | + } |
|
694 | 776 | |
695 | 777 | if ($check && !$GLOBALS['egw_info']['user']['preferences'][$this->app][$check] || // no notification requested |
696 | 778 | // only notification about changed assignment requested |
697 | 779 | $check && $GLOBALS['egw_info']['user']['preferences'][$this->app][$check] === 'assignment' && !$assignment_changed || |
698 | - $this->user == $user_or_lang && !$this->notify_current_user) // no popup for own actions |
|
780 | + $this->user == $user_or_lang && !$this->notify_current_user) |
|
699 | 781 | { |
700 | - $do_notify = false; // no notification requested / necessary |
|
782 | + // no popup for own actions |
|
783 | + { |
|
784 | + $do_notify = false; |
|
785 | + } |
|
786 | + // no notification requested / necessary |
|
701 | 787 | } |
702 | 788 | } |
703 | 789 | else |
@@ -706,10 +792,13 @@ discard block |
||
706 | 792 | $GLOBALS['egw_info']['user']['preferences'] = $GLOBALS['egw']->preferences->default_prefs(); |
707 | 793 | $GLOBALS['egw_info']['user']['preferences']['common']['lang'] = $user_or_lang; |
708 | 794 | } |
709 | - if ($GLOBALS['egw_info']['user']['preferences']['common']['lang'] != Api\Translation::$userlang) // load the right language if needed |
|
795 | + if ($GLOBALS['egw_info']['user']['preferences']['common']['lang'] != Api\Translation::$userlang) |
|
796 | + { |
|
797 | + // load the right language if needed |
|
710 | 798 | { |
711 | 799 | Api\Translation::init(); |
712 | 800 | } |
801 | + } |
|
713 | 802 | |
714 | 803 | $receiver = is_numeric($user_or_lang) ? $user_or_lang : $email; |
715 | 804 | |
@@ -813,7 +902,10 @@ discard block |
||
813 | 902 | $do_time = ($timestamp->format('Hi') != '0000'); |
814 | 903 | } |
815 | 904 | $format = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat']; |
816 | - if ($do_time) $format .= ' '.($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] != 12 ? 'H:i' : 'h:i a'); |
|
905 | + if ($do_time) |
|
906 | + { |
|
907 | + $format .= ' '.($GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] != 12 ? 'H:i' : 'h:i a'); |
|
908 | + } |
|
817 | 909 | |
818 | 910 | return $timestamp->format($format); |
819 | 911 | } |
@@ -843,9 +935,12 @@ discard block |
||
843 | 935 | { |
844 | 936 | $name = $GLOBALS['egw']->accounts->id2name($this->user,'account_fullname'); |
845 | 937 | |
846 | - if($prefer_id) { |
|
938 | + if($prefer_id) |
|
939 | + { |
|
847 | 940 | $sender = $this->user; |
848 | - } else { |
|
941 | + } |
|
942 | + else |
|
943 | + { |
|
849 | 944 | $sender = $name ? $name.' <'.$email.'>' : $email; |
850 | 945 | } |
851 | 946 | } |
@@ -947,7 +1042,10 @@ discard block |
||
947 | 1042 | // remove the session-id in the notification mail! |
948 | 1043 | $link = preg_replace('/(sessionid|kp3|domain)=[^&]+&?/','',$link); |
949 | 1044 | |
950 | - if ($popup) $link .= '&nopopup=1'; |
|
1045 | + if ($popup) |
|
1046 | + { |
|
1047 | + $link .= '&nopopup=1'; |
|
1048 | + } |
|
951 | 1049 | } |
952 | 1050 | //error_log(__METHOD__."(..., $allow_popup, $receiver) returning ".array2string($allow_popup ? array($link,$popup) : $link)); |
953 | 1051 | return $allow_popup ? array($link,$popup) : $link; |
@@ -1022,7 +1120,11 @@ discard block |
||
1022 | 1120 | // if both values are '', 0 or null, we count them as equal too |
1023 | 1121 | $modified = $old && $data[$name] != $old[$name] && !(!$data[$name] && !$old[$name]); |
1024 | 1122 | //if ($modified) error_log("data[$name]=".print_r($data[$name],true).", old[$name]=".print_r($old[$name],true)." --> modified=".(int)$modified); |
1025 | - if (empty($detail['value']) && !$modified) continue; // skip unchanged, empty values |
|
1123 | + if (empty($detail['value']) && !$modified) |
|
1124 | + { |
|
1125 | + continue; |
|
1126 | + } |
|
1127 | + // skip unchanged, empty values |
|
1026 | 1128 | |
1027 | 1129 | $body .= $this->format_line($html_email,$detail['type'],$modified, |
1028 | 1130 | $detail['label'] ? $detail['label'] : '', $detail['value']); |
@@ -1056,7 +1158,11 @@ discard block |
||
1056 | 1158 | |
1057 | 1159 | if ($html_mail) |
1058 | 1160 | { |
1059 | - if (!$this->html_content_allow) $line = Api\Html::htmlspecialchars($line); // XSS |
|
1161 | + if (!$this->html_content_allow) |
|
1162 | + { |
|
1163 | + $line = Api\Html::htmlspecialchars($line); |
|
1164 | + } |
|
1165 | + // XSS |
|
1060 | 1166 | |
1061 | 1167 | $color = $modified ? 'red' : false; |
1062 | 1168 | $size = '110%'; |
@@ -1095,15 +1201,24 @@ discard block |
||
1095 | 1201 | } |
1096 | 1202 | else // text-mail |
1097 | 1203 | { |
1098 | - if ($type == 'reply') $content = str_repeat('-',64)."\n"; |
|
1204 | + if ($type == 'reply') |
|
1205 | + { |
|
1206 | + $content = str_repeat('-',64)."\n"; |
|
1207 | + } |
|
1099 | 1208 | |
1100 | - if ($modified) $content .= '> '; |
|
1209 | + if ($modified) |
|
1210 | + { |
|
1211 | + $content .= '> '; |
|
1212 | + } |
|
1101 | 1213 | } |
1102 | 1214 | $content .= $line; |
1103 | 1215 | |
1104 | 1216 | if ($html_mail) |
1105 | 1217 | { |
1106 | - if ($line && $data) $content .= '</td><td style="'.$style.'">'; |
|
1218 | + if ($line && $data) |
|
1219 | + { |
|
1220 | + $content .= '</td><td style="'.$style.'">'; |
|
1221 | + } |
|
1107 | 1222 | if ($type == 'link') |
1108 | 1223 | { |
1109 | 1224 | // the link is often too long for html boxes chunk-split allows to break lines if needed |
@@ -1122,7 +1237,10 @@ discard block |
||
1122 | 1237 | { |
1123 | 1238 | $content .= ($content&&$data?': ':'').$data; |
1124 | 1239 | } |
1125 | - if ($html_mail) $content .= '</td></tr>'; |
|
1240 | + if ($html_mail) |
|
1241 | + { |
|
1242 | + $content .= '</td></tr>'; |
|
1243 | + } |
|
1126 | 1244 | |
1127 | 1245 | $content .= "\n"; |
1128 | 1246 |
@@ -742,7 +742,7 @@ |
||
742 | 742 | * |
743 | 743 | * @param string $app application name |
744 | 744 | * @param string $lang language code |
745 | - * @return the full path of the filename for the requested app and language |
|
745 | + * @return string full path of the filename for the requested app and language |
|
746 | 746 | */ |
747 | 747 | static function get_lang_file($app,$lang) |
748 | 748 | { |
@@ -738,12 +738,12 @@ discard block |
||
738 | 738 | } |
739 | 739 | |
740 | 740 | /** |
741 | - * provides centralization and compatibility to locate the lang files |
|
742 | - * |
|
743 | - * @param string $app application name |
|
744 | - * @param string $lang language code |
|
745 | - * @return the full path of the filename for the requested app and language |
|
746 | - */ |
|
741 | + * provides centralization and compatibility to locate the lang files |
|
742 | + * |
|
743 | + * @param string $app application name |
|
744 | + * @param string $lang language code |
|
745 | + * @return the full path of the filename for the requested app and language |
|
746 | + */ |
|
747 | 747 | static function get_lang_file($app,$lang) |
748 | 748 | { |
749 | 749 | if ($app == 'common') $app = 'phpgwapi'; |
@@ -1074,13 +1074,13 @@ discard block |
||
1074 | 1074 | } |
1075 | 1075 | |
1076 | 1076 | /** |
1077 | - * detect_encoding - try to detect the encoding |
|
1078 | - * only to be used if the string in question has no structure that determines his encoding |
|
1079 | - * |
|
1080 | - * @param string - to be evaluated |
|
1081 | - * @param string $verify =null encoding to verify, get checked first and have a match for only ascii or no detection available |
|
1082 | - * @return string - encoding |
|
1083 | - */ |
|
1077 | + * detect_encoding - try to detect the encoding |
|
1078 | + * only to be used if the string in question has no structure that determines his encoding |
|
1079 | + * |
|
1080 | + * @param string - to be evaluated |
|
1081 | + * @param string $verify =null encoding to verify, get checked first and have a match for only ascii or no detection available |
|
1082 | + * @return string - encoding |
|
1083 | + */ |
|
1084 | 1084 | static function detect_encoding($string, $verify=null) |
1085 | 1085 | { |
1086 | 1086 | if (function_exists('iconv')) |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * |
100 | 100 | * @var array |
101 | 101 | */ |
102 | - static $instance_specific_translations = array('loginscreen','mainscreen','custom'); |
|
102 | + static $instance_specific_translations = array('loginscreen', 'mainscreen', 'custom'); |
|
103 | 103 | |
104 | 104 | /** |
105 | 105 | * returns the charset to use (!$lang) or the charset of the lang-files or $lang |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | * @param string|boolean $lang =False return charset of the active user-lang, or $lang if specified |
108 | 108 | * @return string charset |
109 | 109 | */ |
110 | - static function charset($lang=False) |
|
110 | + static function charset($lang = False) |
|
111 | 111 | { |
112 | 112 | static $charsets = array(); |
113 | 113 | |
@@ -115,11 +115,11 @@ discard block |
||
115 | 115 | { |
116 | 116 | if (!isset($charsets[$lang])) |
117 | 117 | { |
118 | - if (!($charsets[$lang] = self::$db->select(self::LANG_TABLE,'content',array( |
|
118 | + if (!($charsets[$lang] = self::$db->select(self::LANG_TABLE, 'content', array( |
|
119 | 119 | 'lang' => $lang, |
120 | 120 | 'message_id'=> 'charset', |
121 | 121 | 'app_name' => 'common', |
122 | - ),__LINE__,__FILE__)->fetchColumn())) |
|
122 | + ), __LINE__, __FILE__)->fetchColumn())) |
|
123 | 123 | { |
124 | 124 | $charsets[$lang] = 'utf-8'; |
125 | 125 | } |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * |
154 | 154 | * @param boolean $load_translations =true should we also load translations for common and currentapp |
155 | 155 | */ |
156 | - static function init($load_translations=true) |
|
156 | + static function init($load_translations = true) |
|
157 | 157 | { |
158 | 158 | if (!isset(self::$db)) |
159 | 159 | { |
@@ -165,11 +165,11 @@ discard block |
||
165 | 165 | } |
166 | 166 | else |
167 | 167 | { |
168 | - self::$system_charset =& $GLOBALS['egw_setup']->system_charset; |
|
168 | + self::$system_charset = & $GLOBALS['egw_setup']->system_charset; |
|
169 | 169 | } |
170 | 170 | if ((self::$mbstring = check_load_extension('mbstring'))) |
171 | 171 | { |
172 | - if(!empty(self::$system_charset)) |
|
172 | + if (!empty(self::$system_charset)) |
|
173 | 173 | { |
174 | 174 | $ini_default_charset = version_compare(PHP_VERSION, '5.6', '<') ? 'mbstring.internal_encoding' : 'default_charset'; |
175 | 175 | ini_set($ini_default_charset, self::$system_charset); |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | |
179 | 179 | // try loading load_via from tree-wide cache and check if it contains more rules |
180 | 180 | if (($load_via = Cache::getTree(__CLASS__, 'load_via')) && |
181 | - $load_via >= self::$load_via && // > for array --> contains more elements |
|
181 | + $load_via >= self::$load_via && // > for array --> contains more elements |
|
182 | 182 | // little sanity check: cached array contains all stock keys, otherwise ignore it |
183 | 183 | !array_diff_key(self::$load_via, $load_via)) |
184 | 184 | { |
@@ -217,13 +217,13 @@ discard block |
||
217 | 217 | * @param string $not_found ='*' what to add to not found phrases, default '*' |
218 | 218 | * @return string with translation |
219 | 219 | */ |
220 | - static function translate($key, $vars=null, $not_found='' ) |
|
220 | + static function translate($key, $vars = null, $not_found = '') |
|
221 | 221 | { |
222 | 222 | if (!self::$lang_arr) |
223 | 223 | { |
224 | 224 | self::init(); |
225 | 225 | } |
226 | - $ret = $key; // save key if we dont find a translation |
|
226 | + $ret = $key; // save key if we dont find a translation |
|
227 | 227 | if ($not_found) $ret .= $not_found; |
228 | 228 | |
229 | 229 | if (isset(self::$lang_arr[$key])) |
@@ -243,16 +243,16 @@ discard block |
||
243 | 243 | { |
244 | 244 | if (count($vars) > 1) |
245 | 245 | { |
246 | - static $placeholders = array('%3','%2','%1','|%2|','|%3|','%4','%5','%6','%7','%8','%9','%10'); |
|
246 | + static $placeholders = array('%3', '%2', '%1', '|%2|', '|%3|', '%4', '%5', '%6', '%7', '%8', '%9', '%10'); |
|
247 | 247 | // to cope with $vars[0] containing '%2' (eg. an urlencoded path like a referer), |
248 | 248 | // we first replace '%2' in $ret with '|%2|' and then use that as 2. placeholder |
249 | 249 | // we do that for %3 as well, ... |
250 | - $vars = array_merge(array('|%3|','|%2|'),$vars); // push '|%2|' (and such) as first replacement on $vars |
|
251 | - $ret = str_replace($placeholders,$vars,$ret); |
|
250 | + $vars = array_merge(array('|%3|', '|%2|'), $vars); // push '|%2|' (and such) as first replacement on $vars |
|
251 | + $ret = str_replace($placeholders, $vars, $ret); |
|
252 | 252 | } |
253 | 253 | else |
254 | 254 | { |
255 | - $ret = str_replace('%1',$vars[0],$ret); |
|
255 | + $ret = str_replace('%1', $vars[0], $ret); |
|
256 | 256 | } |
257 | 257 | } |
258 | 258 | return $ret; |
@@ -267,14 +267,14 @@ discard block |
||
267 | 267 | * if multiple names given, they are requested in one request from cache and loaded in given order |
268 | 268 | * @param string $lang =false 2 or 5 char lang-code or false for the users language |
269 | 269 | */ |
270 | - static function add_app($apps, $lang=null) |
|
270 | + static function add_app($apps, $lang = null) |
|
271 | 271 | { |
272 | 272 | //error_log(__METHOD__."(".array2string($apps).", $lang) count(self::\$lang_arr)=".count(self::$lang_arr)); |
273 | 273 | //$start = microtime(true); |
274 | 274 | if (!$lang) $lang = self::$userlang; |
275 | 275 | $tree_level = $instance_level = array(); |
276 | 276 | if (!is_array($apps)) $apps = (array)$apps; |
277 | - foreach($apps as $key => $app) |
|
277 | + foreach ($apps as $key => $app) |
|
278 | 278 | { |
279 | 279 | if (!isset(self::$loaded_apps[$app]) || self::$loaded_apps[$app] != $lang && $app != 'common') |
280 | 280 | { |
@@ -298,26 +298,26 @@ discard block |
||
298 | 298 | |
299 | 299 | // merging loaded translations together |
300 | 300 | $updated_load_via = false; |
301 | - foreach((array)$apps as $app) |
|
301 | + foreach ((array)$apps as $app) |
|
302 | 302 | { |
303 | 303 | $l = $app == 'custom' ? 'en' : $lang; |
304 | 304 | if (isset($tree_level[$app.':'.$l])) |
305 | 305 | { |
306 | - $loaded =& $tree_level[$app.':'.$l]; |
|
306 | + $loaded = & $tree_level[$app.':'.$l]; |
|
307 | 307 | } |
308 | 308 | elseif (isset($instance_level[$app.':'.$l])) |
309 | 309 | { |
310 | - $loaded =& $instance_level[$app.':'.$l]; |
|
310 | + $loaded = & $instance_level[$app.':'.$l]; |
|
311 | 311 | } |
312 | 312 | else |
313 | 313 | { |
314 | 314 | if (($instance_specific = in_array($app, self::$instance_specific_translations))) |
315 | 315 | { |
316 | - $loaded =& self::load_app($app, $l); |
|
316 | + $loaded = & self::load_app($app, $l); |
|
317 | 317 | } |
318 | 318 | else |
319 | 319 | { |
320 | - $loaded =& self::load_app_files($app, $l, null, $updated_load_via); |
|
320 | + $loaded = & self::load_app_files($app, $l, null, $updated_load_via); |
|
321 | 321 | } |
322 | 322 | //error_log(__METHOD__."('$app', '$lang') instance_specific=$instance_specific, load_app(_files)() returned ".(is_array($loaded)?'Array('.count($loaded).')':array2string($loaded))); |
323 | 323 | if ($loaded || $instance_specific) |
@@ -330,14 +330,14 @@ discard block |
||
330 | 330 | if ($loaded) |
331 | 331 | { |
332 | 332 | self::$lang_arr = array_merge(self::$lang_arr, $loaded); |
333 | - self::$loaded_apps[$app] = $l; // dont set something not existing to $loaded_apps, no need to load client-side |
|
333 | + self::$loaded_apps[$app] = $l; // dont set something not existing to $loaded_apps, no need to load client-side |
|
334 | 334 | } |
335 | 335 | } |
336 | 336 | // Re-merge custom over instance level, they have higher precidence |
337 | - if($tree_level && !$instance_level && self::$instance_specific_translations) |
|
337 | + if ($tree_level && !$instance_level && self::$instance_specific_translations) |
|
338 | 338 | { |
339 | 339 | $custom = Cache::getInstance(__CLASS__, 'custom:en'); |
340 | - if($custom) |
|
340 | + if ($custom) |
|
341 | 341 | { |
342 | 342 | self::$lang_arr = array_merge(self::$lang_arr, $custom); |
343 | 343 | } |
@@ -358,15 +358,15 @@ discard block |
||
358 | 358 | * @param string $lang =false 2 or 5 char lang-code or false for the users language |
359 | 359 | * @return array the loaded strings |
360 | 360 | */ |
361 | - static function &load_app($app,$lang) |
|
361 | + static function &load_app($app, $lang) |
|
362 | 362 | { |
363 | 363 | //$start = microtime(true); |
364 | 364 | if (is_null(self::$db)) self::init(false); |
365 | 365 | $loaded = array(); |
366 | - foreach(self::$db->select(self::LANG_TABLE,'message_id,content',array( |
|
366 | + foreach (self::$db->select(self::LANG_TABLE, 'message_id,content', array( |
|
367 | 367 | 'lang' => $lang, |
368 | 368 | 'app_name' => $app, |
369 | - ),__LINE__,__FILE__) as $row) |
|
369 | + ), __LINE__, __FILE__) as $row) |
|
370 | 370 | { |
371 | 371 | $loaded[strtolower($row['message_id'])] = $row['content']; |
372 | 372 | } |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | 'sitemgr-link' => array('sitemgr'), |
391 | 391 | 'groupdav' => array('api'), |
392 | 392 | 'developer_tools' => array('etemplate'), |
393 | - 'login' => array('api','registration'), |
|
393 | + 'login' => array('api', 'registration'), |
|
394 | 394 | ); |
395 | 395 | |
396 | 396 | /** |
@@ -402,7 +402,7 @@ discard block |
||
402 | 402 | { |
403 | 403 | $lang = $GLOBALS['egw_info']['user']['preferences']['common']['lang']; |
404 | 404 | $apps = array_keys($GLOBALS['egw_info']['apps']); |
405 | - foreach($apps as $app) |
|
405 | + foreach ($apps as $app) |
|
406 | 406 | { |
407 | 407 | $file = self::get_lang_file($app, $lang); |
408 | 408 | // check if file has changed compared to what's cached |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | Cache::unsetTree(__CLASS__, $app.':'.$lang); |
433 | 433 | Cache::unsetTree(__CLASS__, self::get_lang_file($app, $lang)); |
434 | 434 | |
435 | - foreach(self::$load_via as $load => $via) |
|
435 | + foreach (self::$load_via as $load => $via) |
|
436 | 436 | { |
437 | 437 | //error_log("load_via[load='$load'] = via = ".array2string($via)); |
438 | 438 | if ($via === 'all-apps' || in_array($app, (array)$via)) |
@@ -454,7 +454,7 @@ discard block |
||
454 | 454 | * @param string $_lang =null |
455 | 455 | * @return array $lang or $app => number pairs |
456 | 456 | */ |
457 | - static function statistics($_lang=null) |
|
457 | + static function statistics($_lang = null) |
|
458 | 458 | { |
459 | 459 | $cache = Cache::getTree(__CLASS__, 'statistics'); |
460 | 460 | |
@@ -465,7 +465,7 @@ discard block |
||
465 | 465 | { |
466 | 466 | $en_phrases = array_keys(self::load_app_files(null, 'en', 'all-apps')); |
467 | 467 | $cache['']['en'] = count($en_phrases); |
468 | - foreach(array_keys(self::get_available_langs()) as $lang) |
|
468 | + foreach (array_keys(self::get_available_langs()) as $lang) |
|
469 | 469 | { |
470 | 470 | if ($lang == 'en') continue; |
471 | 471 | $lang_phrases = array_keys(self::load_app_files(null, $lang, 'all-apps')); |
@@ -476,7 +476,7 @@ discard block |
||
476 | 476 | else |
477 | 477 | { |
478 | 478 | $cache['en'] = array(); |
479 | - foreach(scandir(EGW_SERVER_ROOT) as $app) |
|
479 | + foreach (scandir(EGW_SERVER_ROOT) as $app) |
|
480 | 480 | { |
481 | 481 | if ($app[0] == '.' || !is_dir(EGW_SERVER_ROOT.'/'.$app) || |
482 | 482 | !file_exists(self::get_lang_file($app, 'en'))) |
@@ -514,7 +514,7 @@ discard block |
||
514 | 514 | if (!in_array($_app, self::$instance_specific_translations)) |
515 | 515 | { |
516 | 516 | // check if cache is NOT invalided by checking if we have a modification time for concerned lang-file |
517 | - $time = Cache::getTree(__CLASS__, $file=self::get_lang_file($_app, $_lang)); |
|
517 | + $time = Cache::getTree(__CLASS__, $file = self::get_lang_file($_app, $_lang)); |
|
518 | 518 | // if we dont have one, cache has been invalidated and we need to load translations |
519 | 519 | if (!isset($time)) self::add_app($_app, $_lang); |
520 | 520 | |
@@ -534,7 +534,7 @@ discard block |
||
534 | 534 | * @param type $time |
535 | 535 | * @return type |
536 | 536 | */ |
537 | - static function max_lang_time($time=null) |
|
537 | + static function max_lang_time($time = null) |
|
538 | 538 | { |
539 | 539 | static $max_lang_time = null; |
540 | 540 | |
@@ -545,7 +545,7 @@ discard block |
||
545 | 545 | if (isset($time) && $time > $max_lang_time) |
546 | 546 | { |
547 | 547 | //error_log(__METHOD__."($time) updating previous max_lang_time=$max_lang_time to $time"); |
548 | - Cache::setTree(__CLASS__, 'max_lang_time', $max_lang_time=$time); |
|
548 | + Cache::setTree(__CLASS__, 'max_lang_time', $max_lang_time = $time); |
|
549 | 549 | } |
550 | 550 | return $max_lang_time; |
551 | 551 | } |
@@ -561,34 +561,34 @@ discard block |
||
561 | 561 | * @param boolean $updated_load_via =false on return true if self::$load_via was updated |
562 | 562 | * @return array the loaded strings |
563 | 563 | */ |
564 | - static function &load_app_files($app, $lang, $just_app_file=null, &$updated_load_via=false) |
|
564 | + static function &load_app_files($app, $lang, $just_app_file = null, &$updated_load_via = false) |
|
565 | 565 | { |
566 | 566 | //$start = microtime(true); |
567 | 567 | $load_app = isset($just_app_file) ? $just_app_file : (isset(self::$load_via[$app]) ? self::$load_via[$app] : $app); |
568 | 568 | $loaded = array(); |
569 | - foreach($load_app == 'all-apps' ? scandir(EGW_SERVER_ROOT) : (array)$load_app as $app_dir) |
|
569 | + foreach ($load_app == 'all-apps' ? scandir(EGW_SERVER_ROOT) : (array)$load_app as $app_dir) |
|
570 | 570 | { |
571 | - if ($load_app == 'all-apps' && $app_dir=='..') continue; // do not try to break out of egw server root |
|
571 | + if ($load_app == 'all-apps' && $app_dir == '..') continue; // do not try to break out of egw server root |
|
572 | 572 | if ($app_dir[0] == '.' || !is_dir(EGW_SERVER_ROOT.'/'.$app_dir) || |
573 | - !@file_exists($file=self::get_lang_file($app_dir, $lang)) || |
|
573 | + !@file_exists($file = self::get_lang_file($app_dir, $lang)) || |
|
574 | 574 | !($f = fopen($file, 'r'))) |
575 | 575 | { |
576 | 576 | continue; |
577 | 577 | } |
578 | 578 | // store ctime of file we parse |
579 | - Cache::setTree(__CLASS__, $file, $time=filemtime($file)); |
|
579 | + Cache::setTree(__CLASS__, $file, $time = filemtime($file)); |
|
580 | 580 | self::max_lang_time($time); |
581 | 581 | |
582 | 582 | $line_nr = 0; |
583 | 583 | //use fgets and split the line, as php5.3.3 with squeeze does not support splitting lines with fgetcsv while reading properly |
584 | 584 | //if the first letter after the delimiter is a german umlaut (UTF8 representation thereoff) |
585 | 585 | //while(($line = fgetcsv($f, 1024, "\t"))) |
586 | - while(($read = fgets($f))) |
|
586 | + while (($read = fgets($f))) |
|
587 | 587 | { |
588 | 588 | $line = explode("\t", trim($read)); |
589 | 589 | ++$line_nr; |
590 | 590 | if (count($line) != 4) continue; |
591 | - list($l_id,$l_app,$l_lang,$l_translation) = $line; |
|
591 | + list($l_id, $l_app, $l_lang, $l_translation) = $line; |
|
592 | 592 | if ($l_lang != $lang) continue; |
593 | 593 | if (!isset($just_app_file) && $l_app != $app) |
594 | 594 | { |
@@ -629,7 +629,7 @@ discard block |
||
629 | 629 | // little sanity check: cached array contains all stock keys, otherwise ignore it |
630 | 630 | !array_diff_key(self::$load_via, $load_via)) |
631 | 631 | { |
632 | - foreach($load_via as $app => $via) |
|
632 | + foreach ($load_via as $app => $via) |
|
633 | 633 | { |
634 | 634 | if (self::$load_via[$app] != $via) |
635 | 635 | { |
@@ -655,15 +655,15 @@ discard block |
||
655 | 655 | * @param boolean $force_read =false force a re-read of the languages |
656 | 656 | * @return array with lang-code => descriptiv lang-name pairs |
657 | 657 | */ |
658 | - static function get_available_langs($translate=true, $force_read=false) |
|
658 | + static function get_available_langs($translate = true, $force_read = false) |
|
659 | 659 | { |
660 | 660 | if (!is_array(self::$langs) || $force_read) |
661 | 661 | { |
662 | - if (!($f = fopen($file=EGW_SERVER_ROOT.'/setup/lang/languages','rb'))) |
|
662 | + if (!($f = fopen($file = EGW_SERVER_ROOT.'/setup/lang/languages', 'rb'))) |
|
663 | 663 | { |
664 | 664 | throw new Exception("List of available languages (%1) missing!", $file); |
665 | 665 | } |
666 | - while(($line = fgetcsv($f, null, "\t"))) |
|
666 | + while (($line = fgetcsv($f, null, "\t"))) |
|
667 | 667 | { |
668 | 668 | self::$langs[$line[0]] = $line[1]; |
669 | 669 | } |
@@ -673,12 +673,12 @@ discard block |
||
673 | 673 | { |
674 | 674 | if (is_null(self::$db)) self::init(false); |
675 | 675 | |
676 | - foreach(self::$langs as $lang => $name) |
|
676 | + foreach (self::$langs as $lang => $name) |
|
677 | 677 | { |
678 | - self::$langs[$lang] = self::translate($name,False,''); |
|
678 | + self::$langs[$lang] = self::translate($name, False, ''); |
|
679 | 679 | } |
680 | 680 | } |
681 | - uasort(self::$langs,'strcasecmp'); |
|
681 | + uasort(self::$langs, 'strcasecmp'); |
|
682 | 682 | } |
683 | 683 | return self::$langs; |
684 | 684 | } |
@@ -691,7 +691,7 @@ discard block |
||
691 | 691 | * @param boolean $force_read =false force a re-read of the languages |
692 | 692 | * @return array with lang-code => descriptiv lang-name pairs |
693 | 693 | */ |
694 | - static function get_installed_langs($force_read=false) |
|
694 | + static function get_installed_langs($force_read = false) |
|
695 | 695 | { |
696 | 696 | return self::get_available_langs($force_read); |
697 | 697 | } |
@@ -708,7 +708,7 @@ discard block |
||
708 | 708 | { |
709 | 709 | return self::$langs[$lang]; |
710 | 710 | } |
711 | - return self::$db->select(self::LANGUAGES_TABLE,'lang_name',array('lang_id' => $lang),__LINE__,__FILE__)->fetchColumn(); |
|
711 | + return self::$db->select(self::LANGUAGES_TABLE, 'lang_name', array('lang_id' => $lang), __LINE__, __FILE__)->fetchColumn(); |
|
712 | 712 | } |
713 | 713 | |
714 | 714 | /** |
@@ -717,20 +717,20 @@ discard block |
||
717 | 717 | * @param boolean $force_read =false |
718 | 718 | * @return array with lang_id => lang_name pairs |
719 | 719 | */ |
720 | - static function list_langs($force_read=false) |
|
720 | + static function list_langs($force_read = false) |
|
721 | 721 | { |
722 | 722 | if (!$force_read) |
723 | 723 | { |
724 | - return Cache::getInstance(__CLASS__,'list_langs',array(__CLASS__,'list_langs'),array(true)); |
|
724 | + return Cache::getInstance(__CLASS__, 'list_langs', array(__CLASS__, 'list_langs'), array(true)); |
|
725 | 725 | } |
726 | - $languages = self::get_installed_langs(); // available languages |
|
727 | - $availible = "('".implode("','",array_keys($languages))."')"; |
|
726 | + $languages = self::get_installed_langs(); // available languages |
|
727 | + $availible = "('".implode("','", array_keys($languages))."')"; |
|
728 | 728 | |
729 | 729 | // this shows first the installed, then the available and then the rest |
730 | - foreach(self::$db->select(self::LANGUAGES_TABLE,array( |
|
731 | - 'lang_id','lang_name', |
|
730 | + foreach (self::$db->select(self::LANGUAGES_TABLE, array( |
|
731 | + 'lang_id', 'lang_name', |
|
732 | 732 | "CASE WHEN lang_id IN $availible THEN 1 ELSE 0 END AS availible", |
733 | - ),"lang_id NOT IN ('".implode("','",array_keys($languages))."')",__LINE__,__FILE__,false,' ORDER BY availible DESC,lang_name') as $row) |
|
733 | + ), "lang_id NOT IN ('".implode("','", array_keys($languages))."')", __LINE__, __FILE__, false, ' ORDER BY availible DESC,lang_name') as $row) |
|
734 | 734 | { |
735 | 735 | $languages[$row['lang_id']] = $row['lang_name']; |
736 | 736 | } |
@@ -744,7 +744,7 @@ discard block |
||
744 | 744 | * @param string $lang language code |
745 | 745 | * @return the full path of the filename for the requested app and language |
746 | 746 | */ |
747 | - static function get_lang_file($app,$lang) |
|
747 | + static function get_lang_file($app, $lang) |
|
748 | 748 | { |
749 | 749 | if ($app == 'common') $app = 'phpgwapi'; |
750 | 750 | return EGW_SERVER_ROOT.'/'.$app.'/'.self::LANG_DIR.'/'.self::LANGFILE_PREFIX.$lang.self::LANGFILE_EXTENSION; |
@@ -757,7 +757,7 @@ discard block |
||
757 | 757 | */ |
758 | 758 | static function get_installed_charsets() |
759 | 759 | { |
760 | - static $charsets=null; |
|
760 | + static $charsets = null; |
|
761 | 761 | |
762 | 762 | if (!isset($charsets)) |
763 | 763 | { |
@@ -787,13 +787,13 @@ discard block |
||
787 | 787 | static $extra = array( |
788 | 788 | 'ß' => 'ss', |
789 | 789 | ); |
790 | - $entities = htmlentities($_str,ENT_QUOTES,self::charset()); |
|
790 | + $entities = htmlentities($_str, ENT_QUOTES, self::charset()); |
|
791 | 791 | |
792 | - $estr = str_replace(array_keys($extra),array_values($extra), $entities); |
|
793 | - $ustr = preg_replace('/&([aAuUoO])uml;/','\\1e', $estr); // replace german umlauts with the letter plus one 'e' |
|
794 | - $astr = preg_replace('/&([a-zA-Z])(grave|acute|circ|ring|cedil|tilde|slash|uml);/','\\1', $ustr); // remove all types of accents |
|
792 | + $estr = str_replace(array_keys($extra), array_values($extra), $entities); |
|
793 | + $ustr = preg_replace('/&([aAuUoO])uml;/', '\\1e', $estr); // replace german umlauts with the letter plus one 'e' |
|
794 | + $astr = preg_replace('/&([a-zA-Z])(grave|acute|circ|ring|cedil|tilde|slash|uml);/', '\\1', $ustr); // remove all types of accents |
|
795 | 795 | |
796 | - return preg_replace('/&([a-zA-Z]+|#[0-9]+|);/','', $astr); // remove all other entities |
|
796 | + return preg_replace('/&([a-zA-Z]+|#[0-9]+|);/', '', $astr); // remove all other entities |
|
797 | 797 | } |
798 | 798 | |
799 | 799 | /** |
@@ -805,7 +805,7 @@ discard block |
||
805 | 805 | * @param boolean $check_to_from =true internal to bypass all charset replacements |
806 | 806 | * @return string|array converted string(s) from $data |
807 | 807 | */ |
808 | - static function convert($data,$from=False,$to=False,$check_to_from=true) |
|
808 | + static function convert($data, $from = False, $to = False, $check_to_from = true) |
|
809 | 809 | { |
810 | 810 | if ($check_to_from) |
811 | 811 | { |
@@ -816,7 +816,7 @@ discard block |
||
816 | 816 | if (!$from) |
817 | 817 | { |
818 | 818 | $from = self::$mbstring ? strtolower(mb_detect_encoding($data)) : 'iso-8859-1'; |
819 | - if($from == 'ascii') |
|
819 | + if ($from == 'ascii') |
|
820 | 820 | { |
821 | 821 | $from = 'iso-8859-1'; |
822 | 822 | } |
@@ -826,7 +826,7 @@ discard block |
||
826 | 826 | php does not seem to support gb2312 |
827 | 827 | but seems to be able to decode it as EUC-CN |
828 | 828 | */ |
829 | - switch($from) |
|
829 | + switch ($from) |
|
830 | 830 | { |
831 | 831 | case 'ks_c_5601-1987': |
832 | 832 | $from = 'CP949'; |
@@ -872,9 +872,9 @@ discard block |
||
872 | 872 | } |
873 | 873 | if (is_array($data)) |
874 | 874 | { |
875 | - foreach($data as $key => $str) |
|
875 | + foreach ($data as $key => $str) |
|
876 | 876 | { |
877 | - $ret[$key] = self::convert($str,$from,$to,false); // false = bypass the above checks, as they are already done |
|
877 | + $ret[$key] = self::convert($str, $from, $to, false); // false = bypass the above checks, as they are already done |
|
878 | 878 | } |
879 | 879 | return $ret; |
880 | 880 | } |
@@ -886,7 +886,7 @@ discard block |
||
886 | 886 | { |
887 | 887 | return utf8_decode($data); |
888 | 888 | } |
889 | - if (self::$mbstring && !$prefer_iconv && ($data = @mb_convert_encoding($data,$to,$from)) != '') |
|
889 | + if (self::$mbstring && !$prefer_iconv && ($data = @mb_convert_encoding($data, $to, $from)) != '') |
|
890 | 890 | { |
891 | 891 | return $data; |
892 | 892 | } |
@@ -914,12 +914,12 @@ discard block |
||
914 | 914 | // in an email on the first Traditional/Japanese/Korean character, |
915 | 915 | // but in reality when people send mails in GB2312, UMA mostly use |
916 | 916 | // extended GB13000/GB18030 which allow T/Jap/Korean characters. |
917 | - if($from == 'euc-cn') |
|
917 | + if ($from == 'euc-cn') |
|
918 | 918 | { |
919 | 919 | $from = 'gb18030'; |
920 | 920 | } |
921 | 921 | |
922 | - if (($convertedData = iconv($from,$to,$data))) |
|
922 | + if (($convertedData = iconv($from, $to, $data))) |
|
923 | 923 | { |
924 | 924 | return $convertedData; |
925 | 925 | } |
@@ -934,9 +934,9 @@ discard block |
||
934 | 934 | * @param string|boolean $from charset $data is in or False if it should be detected |
935 | 935 | * @return string|array converted string(s) from $data |
936 | 936 | */ |
937 | - static function convert_jsonsafe($_data,$from=False) |
|
937 | + static function convert_jsonsafe($_data, $from = False) |
|
938 | 938 | { |
939 | - if ($from===false) $from = self::detect_encoding($_data); |
|
939 | + if ($from === false) $from = self::detect_encoding($_data); |
|
940 | 940 | |
941 | 941 | $data = self::convert($_data, strtolower($from)); |
942 | 942 | |
@@ -945,12 +945,12 @@ discard block |
||
945 | 945 | { |
946 | 946 | $test = @json_encode($data); |
947 | 947 | //error_log(__METHOD__.__LINE__.' ->'.strlen($data).' Error:'.json_last_error().'<- data:#'.$test.'#'); |
948 | - if (($test=="null" || $test === false || is_null($test)) && strlen($data)>0) |
|
948 | + if (($test == "null" || $test === false || is_null($test)) && strlen($data) > 0) |
|
949 | 949 | { |
950 | 950 | // try to fix broken utf8 |
951 | - $x = (function_exists('mb_convert_encoding')?mb_convert_encoding($data,'UTF-8','UTF-8'):(function_exists('iconv')?@iconv("UTF-8","UTF-8//IGNORE",$data):$data)); |
|
951 | + $x = (function_exists('mb_convert_encoding') ? mb_convert_encoding($data, 'UTF-8', 'UTF-8') : (function_exists('iconv') ? @iconv("UTF-8", "UTF-8//IGNORE", $data) : $data)); |
|
952 | 952 | $test = @json_encode($x); |
953 | - if (($test=="null" || $test === false || is_null($test)) && strlen($data)>0) |
|
953 | + if (($test == "null" || $test === false || is_null($test)) && strlen($data) > 0) |
|
954 | 954 | { |
955 | 955 | // this should not be needed, unless something fails with charset detection/ wrong charset passed |
956 | 956 | error_log(__METHOD__.__LINE__.' Charset Reported:'.$from.' Charset Detected:'.self::detect_encoding($data)); |
@@ -973,36 +973,36 @@ discard block |
||
973 | 973 | * @param string $message_id |
974 | 974 | * @param string $content translation or null to delete translation |
975 | 975 | */ |
976 | - static function write($lang,$app,$message_id,$content) |
|
976 | + static function write($lang, $app, $message_id, $content) |
|
977 | 977 | { |
978 | 978 | if ($content) |
979 | 979 | { |
980 | - self::$db->insert(self::LANG_TABLE,array( |
|
980 | + self::$db->insert(self::LANG_TABLE, array( |
|
981 | 981 | 'content' => $content, |
982 | - ),array( |
|
982 | + ), array( |
|
983 | 983 | 'lang' => $lang, |
984 | 984 | 'app_name' => $app, |
985 | 985 | 'message_id' => $message_id, |
986 | - ),__LINE__,__FILE__); |
|
986 | + ), __LINE__, __FILE__); |
|
987 | 987 | } |
988 | 988 | else |
989 | 989 | { |
990 | - self::$db->delete(self::LANG_TABLE,array( |
|
990 | + self::$db->delete(self::LANG_TABLE, array( |
|
991 | 991 | 'lang' => $lang, |
992 | 992 | 'app_name' => $app, |
993 | 993 | 'message_id' => $message_id, |
994 | - ),__LINE__,__FILE__); |
|
994 | + ), __LINE__, __FILE__); |
|
995 | 995 | } |
996 | 996 | // invalidate the cache |
997 | - if(!in_array($app,self::$instance_specific_translations)) |
|
997 | + if (!in_array($app, self::$instance_specific_translations)) |
|
998 | 998 | { |
999 | - Cache::unsetCache(Cache::TREE,__CLASS__,$app.':'.$lang); |
|
999 | + Cache::unsetCache(Cache::TREE, __CLASS__, $app.':'.$lang); |
|
1000 | 1000 | } |
1001 | 1001 | else |
1002 | 1002 | { |
1003 | - foreach(array_keys((array)self::get_installed_langs()) as $key) |
|
1003 | + foreach (array_keys((array)self::get_installed_langs()) as $key) |
|
1004 | 1004 | { |
1005 | - Cache::unsetCache(Cache::INSTANCE,__CLASS__,$app.':'.$key); |
|
1005 | + Cache::unsetCache(Cache::INSTANCE, __CLASS__, $app.':'.$key); |
|
1006 | 1006 | } |
1007 | 1007 | } |
1008 | 1008 | } |
@@ -1015,13 +1015,13 @@ discard block |
||
1015 | 1015 | * @param string $message_id |
1016 | 1016 | * @return string|boolean content or false if not found |
1017 | 1017 | */ |
1018 | - static function read($lang,$app_name,$message_id) |
|
1018 | + static function read($lang, $app_name, $message_id) |
|
1019 | 1019 | { |
1020 | - return self::$db->select(self::LANG_TABLE,'content',array( |
|
1020 | + return self::$db->select(self::LANG_TABLE, 'content', array( |
|
1021 | 1021 | 'lang' => $lang, |
1022 | 1022 | 'app_name' => $app_name, |
1023 | 1023 | 'message_id' => $message_id, |
1024 | - ),__LINE__,__FILE__)->fetchColumn(); |
|
1024 | + ), __LINE__, __FILE__)->fetchColumn(); |
|
1025 | 1025 | } |
1026 | 1026 | |
1027 | 1027 | /** |
@@ -1032,22 +1032,22 @@ discard block |
||
1032 | 1032 | * @param string $lang ='' default check all langs |
1033 | 1033 | * @return string |
1034 | 1034 | */ |
1035 | - static function get_message_id($translation,$app=null,$lang=null) |
|
1035 | + static function get_message_id($translation, $app = null, $lang = null) |
|
1036 | 1036 | { |
1037 | 1037 | $where = array('content '.self::$db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.self::$db->quote($translation)); |
1038 | 1038 | if ($app) $where['app_name'] = $app; |
1039 | 1039 | if ($lang) $where['lang'] = $lang; |
1040 | 1040 | |
1041 | - $id = self::$db->select(self::LANG_TABLE,'message_id',$where,__LINE__,__FILE__)->fetchColumn(); |
|
1041 | + $id = self::$db->select(self::LANG_TABLE, 'message_id', $where, __LINE__, __FILE__)->fetchColumn(); |
|
1042 | 1042 | |
1043 | 1043 | // Check cache, since most things aren't in the DB anymore |
1044 | - if(!$id) |
|
1044 | + if (!$id) |
|
1045 | 1045 | { |
1046 | 1046 | $ids = array_filter(array_keys(self::$lang_arr), function($haystack) use($translation) { |
1047 | - return stripos(self::$lang_arr[$haystack],$translation) !== false; |
|
1047 | + return stripos(self::$lang_arr[$haystack], $translation) !== false; |
|
1048 | 1048 | }); |
1049 | 1049 | $id = array_shift($ids); |
1050 | - if(!$id && ($lang && $lang !== 'en' || self::$userlang != 'en')) |
|
1050 | + if (!$id && ($lang && $lang !== 'en' || self::$userlang != 'en')) |
|
1051 | 1051 | { |
1052 | 1052 | // Try english |
1053 | 1053 | if (in_array($app, self::$instance_specific_translations)) |
@@ -1064,7 +1064,7 @@ discard block |
||
1064 | 1064 | if ($instance_level) $lang_arr = Cache::getInstance(__CLASS__, $instance_level); |
1065 | 1065 | $lang_arr = $lang_arr[$app.':en']; |
1066 | 1066 | $ids = array_filter(array_keys($lang_arr), function($haystack) use($translation, $lang_arr) { |
1067 | - return stripos($lang_arr[$haystack],$translation) !== false; |
|
1067 | + return stripos($lang_arr[$haystack], $translation) !== false; |
|
1068 | 1068 | }); |
1069 | 1069 | $id = array_shift($ids); |
1070 | 1070 | } |
@@ -1081,7 +1081,7 @@ discard block |
||
1081 | 1081 | * @param string $verify =null encoding to verify, get checked first and have a match for only ascii or no detection available |
1082 | 1082 | * @return string - encoding |
1083 | 1083 | */ |
1084 | - static function detect_encoding($string, $verify=null) |
|
1084 | + static function detect_encoding($string, $verify = null) |
|
1085 | 1085 | { |
1086 | 1086 | if (function_exists('iconv')) |
1087 | 1087 | { |
@@ -1104,7 +1104,7 @@ discard block |
||
1104 | 1104 | } |
1105 | 1105 | if ($verify && (!isset($detected) || $detected === 'ascii')) |
1106 | 1106 | { |
1107 | - return $verify; // ascii matches all charsets |
|
1107 | + return $verify; // ascii matches all charsets |
|
1108 | 1108 | } |
1109 | 1109 | return isset($detected) ? $detected : 'iso-8859-1'; // we choose to return iso-8859-1 as default |
1110 | 1110 | } |
@@ -126,17 +126,23 @@ discard block |
||
126 | 126 | } |
127 | 127 | return $charsets[$lang]; |
128 | 128 | } |
129 | - if (self::$system_charset) // do we have a system-charset ==> return it |
|
129 | + if (self::$system_charset) |
|
130 | + { |
|
131 | + // do we have a system-charset ==> return it |
|
130 | 132 | { |
131 | 133 | $charset = self::$system_charset; |
132 | 134 | } |
135 | + } |
|
133 | 136 | else |
134 | 137 | { |
135 | 138 | // if no translations are loaded (system-startup) use a default, else lang('charset') |
136 | 139 | $charset = !self::$lang_arr ? 'utf-8' : strtolower(self::translate('charset')); |
137 | 140 | } |
138 | 141 | // in case no charset is set, default to utf-8 |
139 | - if (empty($charset) || $charset == 'charset') $charset = 'utf-8'; |
|
142 | + if (empty($charset) || $charset == 'charset') |
|
143 | + { |
|
144 | + $charset = 'utf-8'; |
|
145 | + } |
|
140 | 146 | |
141 | 147 | // we need to set our charset as mbstring.internal_encoding if mbstring.func_overlaod > 0 |
142 | 148 | // else we get problems for a charset is different from the default utf-8 |
@@ -195,8 +201,14 @@ discard block |
||
195 | 201 | } |
196 | 202 | $apps = array('common'); |
197 | 203 | // for eTemplate apps, load etemplate before app itself (allowing app to overwrite etemplate translations) |
198 | - if (class_exists('EGroupware\\Api\\Etemplate', false) || class_exists('etemplate', false)) $apps[] = 'etemplate'; |
|
199 | - if ($GLOBALS['egw_info']['flags']['currentapp']) $apps[] = $GLOBALS['egw_info']['flags']['currentapp']; |
|
204 | + if (class_exists('EGroupware\\Api\\Etemplate', false) || class_exists('etemplate', false)) |
|
205 | + { |
|
206 | + $apps[] = 'etemplate'; |
|
207 | + } |
|
208 | + if ($GLOBALS['egw_info']['flags']['currentapp']) |
|
209 | + { |
|
210 | + $apps[] = $GLOBALS['egw_info']['flags']['currentapp']; |
|
211 | + } |
|
200 | 212 | // load instance specific translations last, so they can overwrite everything |
201 | 213 | $apps[] = 'custom'; |
202 | 214 | self::add_app($apps); |
@@ -224,7 +236,10 @@ discard block |
||
224 | 236 | self::init(); |
225 | 237 | } |
226 | 238 | $ret = $key; // save key if we dont find a translation |
227 | - if ($not_found) $ret .= $not_found; |
|
239 | + if ($not_found) |
|
240 | + { |
|
241 | + $ret .= $not_found; |
|
242 | + } |
|
228 | 243 | |
229 | 244 | if (isset(self::$lang_arr[$key])) |
230 | 245 | { |
@@ -271,9 +286,15 @@ discard block |
||
271 | 286 | { |
272 | 287 | //error_log(__METHOD__."(".array2string($apps).", $lang) count(self::\$lang_arr)=".count(self::$lang_arr)); |
273 | 288 | //$start = microtime(true); |
274 | - if (!$lang) $lang = self::$userlang; |
|
289 | + if (!$lang) |
|
290 | + { |
|
291 | + $lang = self::$userlang; |
|
292 | + } |
|
275 | 293 | $tree_level = $instance_level = array(); |
276 | - if (!is_array($apps)) $apps = (array)$apps; |
|
294 | + if (!is_array($apps)) |
|
295 | + { |
|
296 | + $apps = (array)$apps; |
|
297 | + } |
|
277 | 298 | foreach($apps as $key => $app) |
278 | 299 | { |
279 | 300 | if (!isset(self::$loaded_apps[$app]) || self::$loaded_apps[$app] != $lang && $app != 'common') |
@@ -293,8 +314,14 @@ discard block |
||
293 | 314 | } |
294 | 315 | } |
295 | 316 | // load all translations from cache at once |
296 | - if ($tree_level) $tree_level = Cache::getTree(__CLASS__, $tree_level); |
|
297 | - if ($instance_level) $instance_level = Cache::getInstance(__CLASS__, $instance_level); |
|
317 | + if ($tree_level) |
|
318 | + { |
|
319 | + $tree_level = Cache::getTree(__CLASS__, $tree_level); |
|
320 | + } |
|
321 | + if ($instance_level) |
|
322 | + { |
|
323 | + $instance_level = Cache::getInstance(__CLASS__, $instance_level); |
|
324 | + } |
|
298 | 325 | |
299 | 326 | // merging loaded translations together |
300 | 327 | $updated_load_via = false; |
@@ -361,7 +388,10 @@ discard block |
||
361 | 388 | static function &load_app($app,$lang) |
362 | 389 | { |
363 | 390 | //$start = microtime(true); |
364 | - if (is_null(self::$db)) self::init(false); |
|
391 | + if (is_null(self::$db)) |
|
392 | + { |
|
393 | + self::init(false); |
|
394 | + } |
|
365 | 395 | $loaded = array(); |
366 | 396 | foreach(self::$db->select(self::LANG_TABLE,'message_id,content',array( |
367 | 397 | 'lang' => $lang, |
@@ -467,7 +497,10 @@ discard block |
||
467 | 497 | $cache['']['en'] = count($en_phrases); |
468 | 498 | foreach(array_keys(self::get_available_langs()) as $lang) |
469 | 499 | { |
470 | - if ($lang == 'en') continue; |
|
500 | + if ($lang == 'en') |
|
501 | + { |
|
502 | + continue; |
|
503 | + } |
|
471 | 504 | $lang_phrases = array_keys(self::load_app_files(null, $lang, 'all-apps')); |
472 | 505 | $valid_phrases = array_intersect($lang_phrases, $en_phrases); |
473 | 506 | $cache[''][$lang] = count($valid_phrases); |
@@ -484,7 +517,10 @@ discard block |
||
484 | 517 | continue; |
485 | 518 | } |
486 | 519 | $en_phrases = array_keys(self::load_app_files(null, 'en', $app)); |
487 | - if (count($en_phrases) <= 2) continue; |
|
520 | + if (count($en_phrases) <= 2) |
|
521 | + { |
|
522 | + continue; |
|
523 | + } |
|
488 | 524 | $cache['en'][$app] = count($en_phrases); |
489 | 525 | $lang_phrases = array_keys(self::load_app_files(null, $_lang, $app)); |
490 | 526 | $valid_phrases = array_intersect($lang_phrases, $en_phrases); |
@@ -516,7 +552,10 @@ discard block |
||
516 | 552 | // check if cache is NOT invalided by checking if we have a modification time for concerned lang-file |
517 | 553 | $time = Cache::getTree(__CLASS__, $file=self::get_lang_file($_app, $_lang)); |
518 | 554 | // if we dont have one, cache has been invalidated and we need to load translations |
519 | - if (!isset($time)) self::add_app($_app, $_lang); |
|
555 | + if (!isset($time)) |
|
556 | + { |
|
557 | + self::add_app($_app, $_lang); |
|
558 | + } |
|
520 | 559 | |
521 | 560 | $etag = self::max_lang_time(); |
522 | 561 | } |
@@ -568,7 +607,11 @@ discard block |
||
568 | 607 | $loaded = array(); |
569 | 608 | foreach($load_app == 'all-apps' ? scandir(EGW_SERVER_ROOT) : (array)$load_app as $app_dir) |
570 | 609 | { |
571 | - if ($load_app == 'all-apps' && $app_dir=='..') continue; // do not try to break out of egw server root |
|
610 | + if ($load_app == 'all-apps' && $app_dir=='..') |
|
611 | + { |
|
612 | + continue; |
|
613 | + } |
|
614 | + // do not try to break out of egw server root |
|
572 | 615 | if ($app_dir[0] == '.' || !is_dir(EGW_SERVER_ROOT.'/'.$app_dir) || |
573 | 616 | !@file_exists($file=self::get_lang_file($app_dir, $lang)) || |
574 | 617 | !($f = fopen($file, 'r'))) |
@@ -587,9 +630,15 @@ discard block |
||
587 | 630 | { |
588 | 631 | $line = explode("\t", trim($read)); |
589 | 632 | ++$line_nr; |
590 | - if (count($line) != 4) continue; |
|
633 | + if (count($line) != 4) |
|
634 | + { |
|
635 | + continue; |
|
636 | + } |
|
591 | 637 | list($l_id,$l_app,$l_lang,$l_translation) = $line; |
592 | - if ($l_lang != $lang) continue; |
|
638 | + if ($l_lang != $lang) |
|
639 | + { |
|
640 | + continue; |
|
641 | + } |
|
593 | 642 | if (!isset($just_app_file) && $l_app != $app) |
594 | 643 | { |
595 | 644 | // check if $l_app contained in file in $app_dir is mentioned in $load_via |
@@ -603,8 +652,14 @@ discard block |
||
603 | 652 | } |
604 | 653 | // if not update load_via accordingly and store it as config |
605 | 654 | //error_log(__METHOD__."() load_via does not contain $l_app => $app_dir"); |
606 | - if (!isset(self::$load_via[$l_app])) self::$load_via[$l_app] = array($l_app); |
|
607 | - if (!is_array(self::$load_via[$l_app])) self::$load_via[$l_app] = array(self::$load_via[$l_app]); |
|
655 | + if (!isset(self::$load_via[$l_app])) |
|
656 | + { |
|
657 | + self::$load_via[$l_app] = array($l_app); |
|
658 | + } |
|
659 | + if (!is_array(self::$load_via[$l_app])) |
|
660 | + { |
|
661 | + self::$load_via[$l_app] = array(self::$load_via[$l_app]); |
|
662 | + } |
|
608 | 663 | self::$load_via[$l_app][] = $app_dir; |
609 | 664 | $updated_load_via = true; |
610 | 665 | } |
@@ -671,7 +726,10 @@ discard block |
||
671 | 726 | |
672 | 727 | if ($translate) |
673 | 728 | { |
674 | - if (is_null(self::$db)) self::init(false); |
|
729 | + if (is_null(self::$db)) |
|
730 | + { |
|
731 | + self::init(false); |
|
732 | + } |
|
675 | 733 | |
676 | 734 | foreach(self::$langs as $lang => $name) |
677 | 735 | { |
@@ -704,10 +762,13 @@ discard block |
||
704 | 762 | */ |
705 | 763 | static function lang2language($lang) |
706 | 764 | { |
707 | - if (isset(self::$langs[$lang])) // no need to query the DB |
|
765 | + if (isset(self::$langs[$lang])) |
|
766 | + { |
|
767 | + // no need to query the DB |
|
708 | 768 | { |
709 | 769 | return self::$langs[$lang]; |
710 | 770 | } |
771 | + } |
|
711 | 772 | return self::$db->select(self::LANGUAGES_TABLE,'lang_name',array('lang_id' => $lang),__LINE__,__FILE__)->fetchColumn(); |
712 | 773 | } |
713 | 774 | |
@@ -746,7 +807,10 @@ discard block |
||
746 | 807 | */ |
747 | 808 | static function get_lang_file($app,$lang) |
748 | 809 | { |
749 | - if ($app == 'common') $app = 'phpgwapi'; |
|
810 | + if ($app == 'common') |
|
811 | + { |
|
812 | + $app = 'phpgwapi'; |
|
813 | + } |
|
750 | 814 | return EGW_SERVER_ROOT.'/'.$app.'/'.self::LANG_DIR.'/'.self::LANGFILE_PREFIX.$lang.self::LANGFILE_EXTENSION; |
751 | 815 | } |
752 | 816 | |
@@ -809,9 +873,15 @@ discard block |
||
809 | 873 | { |
810 | 874 | if ($check_to_from) |
811 | 875 | { |
812 | - if ($from) $from = strtolower($from); |
|
876 | + if ($from) |
|
877 | + { |
|
878 | + $from = strtolower($from); |
|
879 | + } |
|
813 | 880 | |
814 | - if ($to) $to = strtolower($to); |
|
881 | + if ($to) |
|
882 | + { |
|
883 | + $to = strtolower($to); |
|
884 | + } |
|
815 | 885 | |
816 | 886 | if (!$from) |
817 | 887 | { |
@@ -936,7 +1006,10 @@ discard block |
||
936 | 1006 | */ |
937 | 1007 | static function convert_jsonsafe($_data,$from=False) |
938 | 1008 | { |
939 | - if ($from===false) $from = self::detect_encoding($_data); |
|
1009 | + if ($from===false) |
|
1010 | + { |
|
1011 | + $from = self::detect_encoding($_data); |
|
1012 | + } |
|
940 | 1013 | |
941 | 1014 | $data = self::convert($_data, strtolower($from)); |
942 | 1015 | |
@@ -1035,15 +1108,22 @@ discard block |
||
1035 | 1108 | static function get_message_id($translation,$app=null,$lang=null) |
1036 | 1109 | { |
1037 | 1110 | $where = array('content '.self::$db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.self::$db->quote($translation)); |
1038 | - if ($app) $where['app_name'] = $app; |
|
1039 | - if ($lang) $where['lang'] = $lang; |
|
1111 | + if ($app) |
|
1112 | + { |
|
1113 | + $where['app_name'] = $app; |
|
1114 | + } |
|
1115 | + if ($lang) |
|
1116 | + { |
|
1117 | + $where['lang'] = $lang; |
|
1118 | + } |
|
1040 | 1119 | |
1041 | 1120 | $id = self::$db->select(self::LANG_TABLE,'message_id',$where,__LINE__,__FILE__)->fetchColumn(); |
1042 | 1121 | |
1043 | 1122 | // Check cache, since most things aren't in the DB anymore |
1044 | 1123 | if(!$id) |
1045 | 1124 | { |
1046 | - $ids = array_filter(array_keys(self::$lang_arr), function($haystack) use($translation) { |
|
1125 | + $ids = array_filter(array_keys(self::$lang_arr), function($haystack) use($translation) |
|
1126 | + { |
|
1047 | 1127 | return stripos(self::$lang_arr[$haystack],$translation) !== false; |
1048 | 1128 | }); |
1049 | 1129 | $id = array_shift($ids); |
@@ -1060,10 +1140,17 @@ discard block |
||
1060 | 1140 | } |
1061 | 1141 | |
1062 | 1142 | // load all translations from cache at once |
1063 | - if ($tree_level) $lang_arr = Cache::getTree(__CLASS__, $tree_level); |
|
1064 | - if ($instance_level) $lang_arr = Cache::getInstance(__CLASS__, $instance_level); |
|
1143 | + if ($tree_level) |
|
1144 | + { |
|
1145 | + $lang_arr = Cache::getTree(__CLASS__, $tree_level); |
|
1146 | + } |
|
1147 | + if ($instance_level) |
|
1148 | + { |
|
1149 | + $lang_arr = Cache::getInstance(__CLASS__, $instance_level); |
|
1150 | + } |
|
1065 | 1151 | $lang_arr = $lang_arr[$app.':en']; |
1066 | - $ids = array_filter(array_keys($lang_arr), function($haystack) use($translation, $lang_arr) { |
|
1152 | + $ids = array_filter(array_keys($lang_arr), function($haystack) use($translation, $lang_arr) |
|
1153 | + { |
|
1067 | 1154 | return stripos($lang_arr[$haystack],$translation) !== false; |
1068 | 1155 | }); |
1069 | 1156 | $id = array_shift($ids); |
@@ -1087,7 +1174,10 @@ discard block |
||
1087 | 1174 | { |
1088 | 1175 | $list = array('utf-8', 'iso-8859-1', 'windows-1251'); // list may be extended |
1089 | 1176 | |
1090 | - if ($verify) array_unshift($list, $verify); |
|
1177 | + if ($verify) |
|
1178 | + { |
|
1179 | + array_unshift($list, $verify); |
|
1180 | + } |
|
1091 | 1181 | |
1092 | 1182 | foreach ($list as $item) |
1093 | 1183 | { |