@@ -491,6 +491,10 @@ |
||
| 491 | 491 | protected static function call_hook() |
| 492 | 492 | { |
| 493 | 493 | self::$hook_data = array(); |
| 494 | + |
|
| 495 | + /** |
|
| 496 | + * @param string $appname |
|
| 497 | + */ |
|
| 494 | 498 | function display_section($appname,$file,$file2=False) |
| 495 | 499 | { |
| 496 | 500 | admin_ui::$hook_data[$appname] = $file2 ? $file2 : $file; |
@@ -48,7 +48,10 @@ discard block |
||
| 48 | 48 | } |
| 49 | 49 | $tpl = new Etemplate('admin.index'); |
| 50 | 50 | |
| 51 | - if (!is_array($content)) $content = array(); |
|
| 51 | + if (!is_array($content)) |
|
| 52 | + { |
|
| 53 | + $content = array(); |
|
| 54 | + } |
|
| 52 | 55 | $content['nm'] = array( |
| 53 | 56 | 'get_rows' => 'admin_ui::get_users', |
| 54 | 57 | 'no_cat' => true, |
@@ -176,7 +179,10 @@ discard block |
||
| 176 | 179 | { |
| 177 | 180 | $GLOBALS['menuData'] = $data = array(); |
| 178 | 181 | $data = Api\Hooks::single('edit_user', $app); |
| 179 | - if (!is_array($data)) $data = $GLOBALS['menuData']; |
|
| 182 | + if (!is_array($data)) |
|
| 183 | + { |
|
| 184 | + $data = $GLOBALS['menuData']; |
|
| 185 | + } |
|
| 180 | 186 | foreach($data as $item) |
| 181 | 187 | { |
| 182 | 188 | // allow hook to return "real" actions, but still support legacy: description, url, extradata, options |
@@ -194,15 +200,30 @@ discard block |
||
| 194 | 200 | if ($item['options'] && preg_match('/(egw_openWindowCentered2?|window.open)\([^)]+,(\d+),(\d+).*(title="([^"]+)")?/', $item['options'], $matches)) |
| 195 | 201 | { |
| 196 | 202 | $item['popup'] = $matches[2].'x'.$matches[3]; |
| 197 | - if (isset($matches[5])) $item['tooltip'] = $matches[5]; |
|
| 203 | + if (isset($matches[5])) |
|
| 204 | + { |
|
| 205 | + $item['tooltip'] = $matches[5]; |
|
| 206 | + } |
|
| 198 | 207 | unset($item['options']); |
| 199 | 208 | } |
| 200 | 209 | } |
| 201 | - if (empty($item['icon'])) $item['icon'] = $app.'/navbar'; |
|
| 202 | - if (empty($item['group'])) $item['group'] = $group; |
|
| 203 | - if (empty($item['onExecute'])) $item['onExecute'] = $item['popup'] ? |
|
| 210 | + if (empty($item['icon'])) |
|
| 211 | + { |
|
| 212 | + $item['icon'] = $app.'/navbar'; |
|
| 213 | + } |
|
| 214 | + if (empty($item['group'])) |
|
| 215 | + { |
|
| 216 | + $item['group'] = $group; |
|
| 217 | + } |
|
| 218 | + if (empty($item['onExecute'])) |
|
| 219 | + { |
|
| 220 | + $item['onExecute'] = $item['popup'] ? |
|
| 204 | 221 | 'javaScript:nm_action' : 'javaScript:app.admin.iframe_location'; |
| 205 | - if (!isset($item['allowOnMultiple'])) $item['allowOnMultiple'] = false; |
|
| 222 | + } |
|
| 223 | + if (!isset($item['allowOnMultiple'])) |
|
| 224 | + { |
|
| 225 | + $item['allowOnMultiple'] = false; |
|
| 226 | + } |
|
| 206 | 227 | |
| 207 | 228 | $actions[$item['id']] = $item; |
| 208 | 229 | } |
@@ -248,7 +269,9 @@ discard block |
||
| 248 | 269 | 'allowOnMultiple' => false |
| 249 | 270 | ), |
| 250 | 271 | ); |
| 251 | - if (!$GLOBALS['egw']->acl->check('account_access',64,'admin')) // no rights to set ACL-rights |
|
| 272 | + if (!$GLOBALS['egw']->acl->check('account_access',64,'admin')) |
|
| 273 | + { |
|
| 274 | + // no rights to set ACL-rights |
|
| 252 | 275 | { |
| 253 | 276 | $actions['deny'] = array( |
| 254 | 277 | 'caption' => 'Deny access', |
@@ -259,6 +282,7 @@ discard block |
||
| 259 | 282 | 'allowOnMultiple' => false |
| 260 | 283 | ); |
| 261 | 284 | } |
| 285 | + } |
|
| 262 | 286 | |
| 263 | 287 | $group = 5; // allow to place actions in different groups by hook, this is the default |
| 264 | 288 | |
@@ -268,7 +292,10 @@ discard block |
||
| 268 | 292 | { |
| 269 | 293 | $GLOBALS['menuData'] = $data = array(); |
| 270 | 294 | $data = Api\Hooks::single('edit_group', $app); |
| 271 | - if (!is_array($data)) $data = $GLOBALS['menuData']; |
|
| 295 | + if (!is_array($data)) |
|
| 296 | + { |
|
| 297 | + $data = $GLOBALS['menuData']; |
|
| 298 | + } |
|
| 272 | 299 | |
| 273 | 300 | foreach($data as $item) |
| 274 | 301 | { |
@@ -288,14 +315,29 @@ discard block |
||
| 288 | 315 | { |
| 289 | 316 | $item['popup'] = $matches[2].'x'.$matches[3]; |
| 290 | 317 | $item['onExecute'] = 'javaScript:nm_action'; |
| 291 | - if (isset($matches[5])) $item['tooltip'] = $matches[5]; |
|
| 318 | + if (isset($matches[5])) |
|
| 319 | + { |
|
| 320 | + $item['tooltip'] = $matches[5]; |
|
| 321 | + } |
|
| 292 | 322 | unset($item['options']); |
| 293 | 323 | } |
| 294 | 324 | } |
| 295 | - if (empty($item['icon'])) $item['icon'] = $app.'/navbar'; |
|
| 296 | - if (empty($item['group'])) $item['group'] = $group; |
|
| 297 | - if (empty($item['onExecute'])) $item['onExecute'] = 'javaScript:app.admin.group'; |
|
| 298 | - if (!isset($item['allowOnMultiple'])) $item['allowOnMultiple'] = false; |
|
| 325 | + if (empty($item['icon'])) |
|
| 326 | + { |
|
| 327 | + $item['icon'] = $app.'/navbar'; |
|
| 328 | + } |
|
| 329 | + if (empty($item['group'])) |
|
| 330 | + { |
|
| 331 | + $item['group'] = $group; |
|
| 332 | + } |
|
| 333 | + if (empty($item['onExecute'])) |
|
| 334 | + { |
|
| 335 | + $item['onExecute'] = 'javaScript:app.admin.group'; |
|
| 336 | + } |
|
| 337 | + if (!isset($item['allowOnMultiple'])) |
|
| 338 | + { |
|
| 339 | + $item['allowOnMultiple'] = false; |
|
| 340 | + } |
|
| 299 | 341 | |
| 300 | 342 | $actions[$item['id']] = $item; |
| 301 | 343 | } |
@@ -342,7 +384,10 @@ discard block |
||
| 342 | 384 | ($row['account_expires'] != -1 ? lang('Expires').' '.Api\DateTime::to($row['account_expires'], true) : |
| 343 | 385 | lang('Enabled'))); |
| 344 | 386 | |
| 345 | - if (!self::$accounts->is_active($row)) $row['status_class'] = 'adminAccountInactive'; |
|
| 387 | + if (!self::$accounts->is_active($row)) |
|
| 388 | + { |
|
| 389 | + $row['status_class'] = 'adminAccountInactive'; |
|
| 390 | + } |
|
| 346 | 391 | } |
| 347 | 392 | |
| 348 | 393 | return self::$accounts->total; |
@@ -439,7 +484,10 @@ discard block |
||
| 439 | 484 | 'link' => $data, |
| 440 | 485 | ); |
| 441 | 486 | } |
| 442 | - if (empty($data['text'])) $data['text'] = $text; |
|
| 487 | + if (empty($data['text'])) |
|
| 488 | + { |
|
| 489 | + $data['text'] = $text; |
|
| 490 | + } |
|
| 443 | 491 | if (empty($data['id'])) |
| 444 | 492 | { |
| 445 | 493 | $data['id'] = $root.($app == 'admin' ? 'admin' : 'apps/'.$app).'/'; |
@@ -464,7 +512,11 @@ discard block |
||
| 464 | 512 | unset($data['icon']); |
| 465 | 513 | $parent =& $tree['item']; |
| 466 | 514 | $parts = explode('/', $data['id']); |
| 467 | - if ($data['id'][0] == '/') array_shift($parts); // remove root |
|
| 515 | + if ($data['id'][0] == '/') |
|
| 516 | + { |
|
| 517 | + array_shift($parts); |
|
| 518 | + } |
|
| 519 | + // remove root |
|
| 468 | 520 | array_pop($parts); |
| 469 | 521 | $path = ''; |
| 470 | 522 | foreach($parts as $part) |
@@ -483,14 +535,23 @@ discard block |
||
| 483 | 535 | 'item' => array(), |
| 484 | 536 | 'child' => 1, |
| 485 | 537 | ); |
| 486 | - if ($path == '/admin') $parent[$path]['open'] = true; |
|
| 538 | + if ($path == '/admin') |
|
| 539 | + { |
|
| 540 | + $parent[$path]['open'] = true; |
|
| 541 | + } |
|
| 487 | 542 | } |
| 488 | 543 | $parent =& $parent[$path]['item']; |
| 489 | 544 | } |
| 490 | 545 | $data['text'] = lang($data['text']); |
| 491 | - if (!empty($data['tooltip'])) $data['tooltip'] = lang($data['tooltip']); |
|
| 546 | + if (!empty($data['tooltip'])) |
|
| 547 | + { |
|
| 548 | + $data['tooltip'] = lang($data['tooltip']); |
|
| 549 | + } |
|
| 492 | 550 | // make sure keys are unique, as we overwrite tree entries otherwise |
| 493 | - if (isset($parent[$data['id']])) $data['id'] .= md5($data['link']); |
|
| 551 | + if (isset($parent[$data['id']])) |
|
| 552 | + { |
|
| 553 | + $data['id'] .= md5($data['link']); |
|
| 554 | + } |
|
| 494 | 555 | $parent[$data['id']] = self::fix_userdata($data); |
| 495 | 556 | } |
| 496 | 557 | } |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * |
| 41 | 41 | * @param array $content |
| 42 | 42 | */ |
| 43 | - public function index(array $content=null) |
|
| 43 | + public function index(array $content = null) |
|
| 44 | 44 | { |
| 45 | 45 | if (admin_statistics::check(false)) |
| 46 | 46 | { |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | //$content['msg'] = 'Hi Ralf ;-)'; |
| 76 | 76 | $sel_options['tree'] = $this->tree_data(); |
| 77 | 77 | $sel_options['filter'] = array('' => lang('All groups')); |
| 78 | - foreach(self::$accounts->search(array( |
|
| 78 | + foreach (self::$accounts->search(array( |
|
| 79 | 79 | 'type' => 'groups', |
| 80 | 80 | 'start' => false, |
| 81 | 81 | 'order' => 'account_lid', |
@@ -96,13 +96,13 @@ discard block |
||
| 96 | 96 | // important for first time load eg. from an other application calling it's site configuration |
| 97 | 97 | $tpl->setElementAttribute('nm', 'disabled', !empty($_GET['load'])); |
| 98 | 98 | $tpl->setElementAttribute('iframe', 'disabled', empty($_GET['load'])); |
| 99 | - $content['iframe'] = 'about:blank'; // we show accounts-list be default now |
|
| 99 | + $content['iframe'] = 'about:blank'; // we show accounts-list be default now |
|
| 100 | 100 | if (!empty($_GET['load'])) |
| 101 | 101 | { |
| 102 | 102 | $vars = $_GET; |
| 103 | 103 | $vars['menuaction'] = $vars['load']; |
| 104 | 104 | unset($vars['load']); |
| 105 | - $content[$vars['ajax'] ? 'ajax_target':'iframe'] = Egw::link('/index.php', $vars); |
|
| 105 | + $content[$vars['ajax'] ? 'ajax_target' : 'iframe'] = Egw::link('/index.php', $vars); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | $tpl->exec('admin.admin_ui.index', $content, $sel_options); |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | { |
| 118 | 118 | $actions = static::group_actions(); |
| 119 | 119 | |
| 120 | - foreach($actions as $action_id => &$action) |
|
| 120 | + foreach ($actions as $action_id => &$action) |
|
| 121 | 121 | { |
| 122 | 122 | if (!isset($action['enableId']) && !in_array($action_id, array('add'))) |
| 123 | 123 | { |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | 'default' => true, |
| 146 | 146 | 'allowOnMultiple' => false, |
| 147 | 147 | 'onExecute' => 'javaScript:app.admin.account', |
| 148 | - 'group' => $group=0, |
|
| 148 | + 'group' => $group = 0, |
|
| 149 | 149 | ), |
| 150 | 150 | 'add' => array( |
| 151 | 151 | 'caption' => 'Add user', |
@@ -156,25 +156,25 @@ discard block |
||
| 156 | 156 | // generate urls for add/edit accounts via addressbook |
| 157 | 157 | $edit = Link::get_registry('addressbook', 'edit'); |
| 158 | 158 | $edit['account_id'] = '$id'; |
| 159 | - foreach($edit as $name => $val) |
|
| 159 | + foreach ($edit as $name => $val) |
|
| 160 | 160 | { |
| 161 | 161 | $actions['edit']['url'] .= ($actions['edit']['url'] ? '&' : '').$name.'='.$val; |
| 162 | 162 | } |
| 163 | 163 | unset($edit['account_id']); |
| 164 | 164 | $edit['owner'] = 0; |
| 165 | - foreach($edit as $name => $val) |
|
| 165 | + foreach ($edit as $name => $val) |
|
| 166 | 166 | { |
| 167 | 167 | $actions['add']['url'] .= ($actions['edit']['url'] ? '&' : '').$name.'='.$val; |
| 168 | 168 | } |
| 169 | 169 | ++$group; |
| 170 | 170 | // supporting both old way using $GLOBALS['menuData'] and new just returning data in hook |
| 171 | 171 | $apps = array_unique(array_merge(array('admin'), Api\Hooks::implemented('edit_user'))); |
| 172 | - foreach($apps as $app) |
|
| 172 | + foreach ($apps as $app) |
|
| 173 | 173 | { |
| 174 | 174 | $GLOBALS['menuData'] = $data = array(); |
| 175 | 175 | $data = Api\Hooks::single('edit_user', $app); |
| 176 | 176 | if (!is_array($data)) $data = $GLOBALS['menuData']; |
| 177 | - foreach($data as $item) |
|
| 177 | + foreach ($data as $item) |
|
| 178 | 178 | { |
| 179 | 179 | // allow hook to return "real" actions, but still support legacy: description, url, extradata, options |
| 180 | 180 | if (empty($item['caption'])) |
@@ -229,12 +229,12 @@ discard block |
||
| 229 | 229 | 'onExecute' => 'javaScript:app.admin.group', |
| 230 | 230 | 'caption' => 'Show members', |
| 231 | 231 | 'default' => true, |
| 232 | - 'group' => $group=1, |
|
| 232 | + 'group' => $group = 1, |
|
| 233 | 233 | 'allowOnMultiple' => false |
| 234 | 234 | ), |
| 235 | 235 | 'add' => array( |
| 236 | 236 | 'group' => $group, |
| 237 | - )+$user_actions['add'], |
|
| 237 | + ) + $user_actions['add'], |
|
| 238 | 238 | 'acl' => array( |
| 239 | 239 | 'onExecute' => 'javaScript:app.admin.group', |
| 240 | 240 | 'caption' => 'Access control', |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | 'allowOnMultiple' => false |
| 246 | 246 | ), |
| 247 | 247 | ); |
| 248 | - if (!$GLOBALS['egw']->acl->check('account_access',64,'admin')) // no rights to set ACL-rights |
|
| 248 | + if (!$GLOBALS['egw']->acl->check('account_access', 64, 'admin')) // no rights to set ACL-rights |
|
| 249 | 249 | { |
| 250 | 250 | $actions['deny'] = array( |
| 251 | 251 | 'caption' => 'Deny access', |
@@ -257,17 +257,17 @@ discard block |
||
| 257 | 257 | ); |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | - $group = 5; // allow to place actions in different groups by hook, this is the default |
|
| 260 | + $group = 5; // allow to place actions in different groups by hook, this is the default |
|
| 261 | 261 | |
| 262 | 262 | // supporting both old way using $GLOBALS['menuData'] and new just returning data in hook |
| 263 | 263 | $apps = array_unique(array_merge(array('admin'), Api\Hooks::implemented('edit_group'))); |
| 264 | - foreach($apps as $app) |
|
| 264 | + foreach ($apps as $app) |
|
| 265 | 265 | { |
| 266 | 266 | $GLOBALS['menuData'] = $data = array(); |
| 267 | 267 | $data = Api\Hooks::single('edit_group', $app); |
| 268 | 268 | if (!is_array($data)) $data = $GLOBALS['menuData']; |
| 269 | 269 | |
| 270 | - foreach($data as $item) |
|
| 270 | + foreach ($data as $item) |
|
| 271 | 271 | { |
| 272 | 272 | // allow hook to return "real" actions, but still support legacy: description, url, extradata, options |
| 273 | 273 | if (empty($item['caption'])) |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | * @param array &$rows=null |
| 308 | 308 | * @return int total number of rows available |
| 309 | 309 | */ |
| 310 | - public static function get_users(array $query, array &$rows=null) |
|
| 310 | + public static function get_users(array $query, array &$rows = null) |
|
| 311 | 311 | { |
| 312 | 312 | $params = array( |
| 313 | 313 | 'type' => (int)$query['filter'] ? (int)$query['filter'] : 'accounts', |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | $params['query'] = $query['searchletter']; |
| 323 | 323 | $params['query_type'] = 'start'; |
| 324 | 324 | } |
| 325 | - elseif($query['search']) |
|
| 325 | + elseif ($query['search']) |
|
| 326 | 326 | { |
| 327 | 327 | $params['query'] = $query['search']; |
| 328 | 328 | $params['query_type'] = 'all'; |
@@ -331,13 +331,10 @@ discard block |
||
| 331 | 331 | $rows = array_values(self::$accounts->search($params)); |
| 332 | 332 | //error_log(__METHOD__."() accounts->search(".array2string($params).") total=".self::$accounts->total); |
| 333 | 333 | |
| 334 | - foreach($rows as &$row) |
|
| 334 | + foreach ($rows as &$row) |
|
| 335 | 335 | { |
| 336 | 336 | $row['status'] = self::$accounts->is_expired($row) ? |
| 337 | - lang('Expired').' '.Api\DateTime::to($row['account_expires'], true) : |
|
| 338 | - (!self::$accounts->is_active($row) ? lang('Disabled') : |
|
| 339 | - ($row['account_expires'] != -1 ? lang('Expires').' '.Api\DateTime::to($row['account_expires'], true) : |
|
| 340 | - lang('Enabled'))); |
|
| 337 | + lang('Expired').' '.Api\DateTime::to($row['account_expires'], true) : (!self::$accounts->is_active($row) ? lang('Disabled') : ($row['account_expires'] != -1 ? lang('Expires').' '.Api\DateTime::to($row['account_expires'], true) : lang('Enabled'))); |
|
| 341 | 338 | |
| 342 | 339 | if (!self::$accounts->is_active($row)) $row['status_class'] = 'adminAccountInactive'; |
| 343 | 340 | } |
@@ -360,29 +357,29 @@ discard block |
||
| 360 | 357 | )); |
| 361 | 358 | |
| 362 | 359 | $apps = array(); |
| 363 | - foreach($GLOBALS['egw_info']['apps'] as $app => $data) |
|
| 360 | + foreach ($GLOBALS['egw_info']['apps'] as $app => $data) |
|
| 364 | 361 | { |
| 365 | 362 | if (!$data['enabled'] || !$data['status'] || $data['status'] == 3) |
| 366 | 363 | { |
| 367 | - continue; // do NOT show disabled apps, or our API (status = 3) |
|
| 364 | + continue; // do NOT show disabled apps, or our API (status = 3) |
|
| 368 | 365 | } |
| 369 | 366 | |
| 370 | 367 | $apps[] = $app; |
| 371 | 368 | } |
| 372 | 369 | |
| 373 | 370 | $rows = array(); |
| 374 | - foreach($groups as &$group) |
|
| 371 | + foreach ($groups as &$group) |
|
| 375 | 372 | { |
| 376 | 373 | $run_rights = $GLOBALS['egw']->acl->get_user_applications($group['account_id'], false, false); |
| 377 | - foreach($apps as $app) |
|
| 374 | + foreach ($apps as $app) |
|
| 378 | 375 | { |
| 379 | - if((boolean)$run_rights[$app]) |
|
| 376 | + if ((boolean)$run_rights[$app]) |
|
| 380 | 377 | { |
| 381 | 378 | $group['apps'][] = $app; |
| 382 | 379 | } |
| 383 | 380 | } |
| 384 | 381 | |
| 385 | - $group['members'] = $GLOBALS['egw']->accounts->members($group['account_id'],true); |
|
| 382 | + $group['members'] = $GLOBALS['egw']->accounts->members($group['account_id'], true); |
|
| 386 | 383 | $rows[] = $group; |
| 387 | 384 | } |
| 388 | 385 | |
@@ -422,14 +419,14 @@ discard block |
||
| 422 | 419 | if ($root == '/') |
| 423 | 420 | { |
| 424 | 421 | $hook_data = self::call_hook(); |
| 425 | - foreach($hook_data as $app => $app_data) |
|
| 422 | + foreach ($hook_data as $app => $app_data) |
|
| 426 | 423 | { |
| 427 | - if(!is_array($app_data)) |
|
| 424 | + if (!is_array($app_data)) |
|
| 428 | 425 | { |
| 429 | 426 | // Application has no data |
| 430 | 427 | continue; |
| 431 | 428 | } |
| 432 | - foreach($app_data as $text => $data) |
|
| 429 | + foreach ($app_data as $text => $data) |
|
| 433 | 430 | { |
| 434 | 431 | if (!is_array($data)) |
| 435 | 432 | { |
@@ -460,18 +457,17 @@ discard block |
||
| 460 | 457 | } |
| 461 | 458 | } |
| 462 | 459 | unset($data['icon']); |
| 463 | - $parent =& $tree['item']; |
|
| 460 | + $parent = & $tree['item']; |
|
| 464 | 461 | $parts = explode('/', $data['id']); |
| 465 | - if ($data['id'][0] == '/') array_shift($parts); // remove root |
|
| 462 | + if ($data['id'][0] == '/') array_shift($parts); // remove root |
|
| 466 | 463 | array_pop($parts); |
| 467 | 464 | $path = ''; |
| 468 | - foreach($parts as $part) |
|
| 465 | + foreach ($parts as $part) |
|
| 469 | 466 | { |
| 470 | 467 | $path .= ($path == '/' ? '' : '/').$part; |
| 471 | 468 | if (!isset($parent[$path])) |
| 472 | 469 | { |
| 473 | - $icon = Etemplate\Widget\Tree::imagePath($part == 'apps' ? Api\Image::find('api', 'home') : |
|
| 474 | - (($i=Api\Image::find($part, 'navbar')) ? $i : Api\Image::find('api', 'nonav'))); |
|
| 470 | + $icon = Etemplate\Widget\Tree::imagePath($part == 'apps' ? Api\Image::find('api', 'home') : (($i = Api\Image::find($part, 'navbar')) ? $i : Api\Image::find('api', 'nonav'))); |
|
| 475 | 471 | $parent[$path] = array( |
| 476 | 472 | 'id' => $path, |
| 477 | 473 | 'text' => $part == 'apps' ? lang('Applications') : lang($part), |
@@ -483,7 +479,7 @@ discard block |
||
| 483 | 479 | ); |
| 484 | 480 | if ($path == '/admin') $parent[$path]['open'] = true; |
| 485 | 481 | } |
| 486 | - $parent =& $parent[$path]['item']; |
|
| 482 | + $parent = & $parent[$path]['item']; |
|
| 487 | 483 | } |
| 488 | 484 | $data['text'] = lang($data['text']); |
| 489 | 485 | if (!empty($data['tooltip'])) $data['tooltip'] = lang($data['tooltip']); |
@@ -495,7 +491,7 @@ discard block |
||
| 495 | 491 | } |
| 496 | 492 | elseif ($root == '/groups') |
| 497 | 493 | { |
| 498 | - foreach($GLOBALS['egw']->accounts->search(array( |
|
| 494 | + foreach ($GLOBALS['egw']->accounts->search(array( |
|
| 499 | 495 | 'type' => 'groups', |
| 500 | 496 | 'order' => 'account_lid', |
| 501 | 497 | 'sort' => 'ASC', |
@@ -522,8 +518,8 @@ discard block |
||
| 522 | 518 | private static function fix_userdata(array $data) |
| 523 | 519 | { |
| 524 | 520 | // store link as userdata, maybe we should store everything not directly understood by tree this way ... |
| 525 | - foreach(array_diff_key($data, array_flip(array( |
|
| 526 | - 'id','text','tooltip','im0','im1','im2','item','child','select','open','call', |
|
| 521 | + foreach (array_diff_key($data, array_flip(array( |
|
| 522 | + 'id', 'text', 'tooltip', 'im0', 'im1', 'im2', 'item', 'child', 'select', 'open', 'call', |
|
| 527 | 523 | ))) as $name => $content) |
| 528 | 524 | { |
| 529 | 525 | $data['userdata'][] = array( |
@@ -543,7 +539,7 @@ discard block |
||
| 543 | 539 | private static function strip_item_keys(array &$items) |
| 544 | 540 | { |
| 545 | 541 | $items = array_values($items); |
| 546 | - foreach($items as &$item) |
|
| 542 | + foreach ($items as &$item) |
|
| 547 | 543 | { |
| 548 | 544 | if (is_array($item) && isset($item['item'])) |
| 549 | 545 | { |
@@ -561,7 +557,7 @@ discard block |
||
| 561 | 557 | protected static function call_hook() |
| 562 | 558 | { |
| 563 | 559 | self::$hook_data = array(); |
| 564 | - function display_section($appname,$file,$file2=False) |
|
| 560 | + function display_section($appname, $file, $file2 = False) |
|
| 565 | 561 | { |
| 566 | 562 | admin_ui::$hook_data[$appname] = $file2 ? $file2 : $file; |
| 567 | 563 | //error_log(__METHOD__."(".array2string(func_get_args()).")"); |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | * Delete ACL record in the repository of the class |
| 167 | 167 | * |
| 168 | 168 | * @param string $appname appname or '' for $GLOBALS['egw_info']['flags']['currentapp'] |
| 169 | - * @param string/boolean $location location or false for all locations |
|
| 169 | + * @param boolean $location location or false for all locations |
|
| 170 | 170 | * @return array all ACL records from $this->data. |
| 171 | 171 | */ |
| 172 | 172 | function delete($appname,$location) |
@@ -267,8 +267,8 @@ discard block |
||
| 267 | 267 | /** |
| 268 | 268 | * check required rights agains the internal repository (included rights of $this->account_id and all it's memberships) |
| 269 | 269 | * |
| 270 | - * @param $location app location |
|
| 271 | - * @param $required required right to check against |
|
| 270 | + * @param string $location app location |
|
| 271 | + * @param integer $required required right to check against |
|
| 272 | 272 | * @param $appname optional defaults to currentapp |
| 273 | 273 | * @return boolean |
| 274 | 274 | */ |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | /** |
| 33 | 33 | * @var array $data internal repository with acl rows for the given app and account-id (incl. memberships) |
| 34 | 34 | */ |
| 35 | - var $data = Array(); |
|
| 35 | + var $data = array(); |
|
| 36 | 36 | /** |
| 37 | 37 | * internal reference to global db-object |
| 38 | 38 | * |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | array_unshift($acl_acc_list,$this->account_id); |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - $this->data = Array(); |
|
| 136 | + $this->data = array(); |
|
| 137 | 137 | foreach($this->db->select(self::TABLE,'*',array('acl_account' => $acl_acc_list ),__LINE__,__FILE__) as $row) |
| 138 | 138 | { |
| 139 | 139 | $this->data[$row['acl_appname'].'-'.$row['acl_location'].'-'.$row['acl_account']] = Db::strip_array_keys($row,'acl_'); |
@@ -676,7 +676,7 @@ discard block |
||
| 676 | 676 | if ((int)$user > 0) $memberships = $GLOBALS['egw']->accounts->memberships($user, true); |
| 677 | 677 | $memberships[] = $user; |
| 678 | 678 | |
| 679 | - $grants = $accounts = Array(); |
|
| 679 | + $grants = $accounts = array(); |
|
| 680 | 680 | foreach($this->db->select(self::TABLE,array('acl_account','acl_rights','acl_location'),array( |
| 681 | 681 | 'acl_appname' => $app, |
| 682 | 682 | 'acl_location' => $memberships, |
@@ -47,15 +47,15 @@ discard block |
||
| 47 | 47 | /** |
| 48 | 48 | * Constants for acl rights, like old EGW_ACL_* defines |
| 49 | 49 | */ |
| 50 | - const READ = 1; // EGW_ACL_READ |
|
| 51 | - const ADD = 2; // EGW_ACL_ADD |
|
| 52 | - const EDIT = 4; // EGW_ACL_EDIT |
|
| 53 | - const DELETE = 8; // EGW_ACL_DELETE |
|
| 54 | - const PRIVAT = 16; // EGW_ACL_PRIVATE can NOT use PRIVATE as it is a PHP keyword, using German PRIVAT instead! |
|
| 55 | - const GROUPMGRS = 32; // EGW_ACL_GROUP_MANAGERS |
|
| 56 | - const CUSTOM1 = 64; // EGW_ACL_CUSTOM_1 |
|
| 57 | - const CUSTOM2 = 128; // EGW_ACL_CUSTOM_2 |
|
| 58 | - const CUSTOM3 = 256; // EGW_ACL_CUSTOM_3 |
|
| 50 | + const READ = 1; // EGW_ACL_READ |
|
| 51 | + const ADD = 2; // EGW_ACL_ADD |
|
| 52 | + const EDIT = 4; // EGW_ACL_EDIT |
|
| 53 | + const DELETE = 8; // EGW_ACL_DELETE |
|
| 54 | + const PRIVAT = 16; // EGW_ACL_PRIVATE can NOT use PRIVATE as it is a PHP keyword, using German PRIVAT instead! |
|
| 55 | + const GROUPMGRS = 32; // EGW_ACL_GROUP_MANAGERS |
|
| 56 | + const CUSTOM1 = 64; // EGW_ACL_CUSTOM_1 |
|
| 57 | + const CUSTOM2 = 128; // EGW_ACL_CUSTOM_2 |
|
| 58 | + const CUSTOM3 = 256; // EGW_ACL_CUSTOM_3 |
|
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | 61 | * ACL constructor for setting account id |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | } |
| 79 | 79 | if ((int)$this->account_id != (int)$account_id) |
| 80 | 80 | { |
| 81 | - $this->account_id = get_account_id((int)$account_id,@$GLOBALS['egw_info']['user']['account_id']); |
|
| 81 | + $this->account_id = get_account_id((int)$account_id, @$GLOBALS['egw_info']['user']['account_id']); |
|
| 82 | 82 | } |
| 83 | 83 | $this->data = array(); |
| 84 | 84 | } |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | function __sleep() |
| 93 | 93 | { |
| 94 | - return array('account_id','db'); |
|
| 94 | + return array('account_id', 'db'); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /**************************************************************************\ |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | * @param boolean|array $no_groups = false if true, do not use memberships, if array do not use given groups |
| 105 | 105 | * @return array along with storing it in $acl->data. <br> |
| 106 | 106 | */ |
| 107 | - function read_repository($no_groups=false) |
|
| 107 | + function read_repository($no_groups = false) |
|
| 108 | 108 | { |
| 109 | 109 | // For some reason, calling this via XML-RPC doesn't call the constructor. |
| 110 | 110 | // Here is yet another work around(tm) (jengo) |
@@ -119,14 +119,14 @@ discard block |
||
| 119 | 119 | else |
| 120 | 120 | { |
| 121 | 121 | $acl_acc_list = (array)$GLOBALS['egw']->accounts->memberships($this->account_id, true); |
| 122 | - if (is_array($no_groups)) $acl_acc_list = array_diff($acl_acc_list,$no_groups); |
|
| 123 | - array_unshift($acl_acc_list,$this->account_id); |
|
| 122 | + if (is_array($no_groups)) $acl_acc_list = array_diff($acl_acc_list, $no_groups); |
|
| 123 | + array_unshift($acl_acc_list, $this->account_id); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | $this->data = Array(); |
| 127 | - foreach($this->db->select(self::TABLE,'*',array('acl_account' => $acl_acc_list ),__LINE__,__FILE__) as $row) |
|
| 127 | + foreach ($this->db->select(self::TABLE, '*', array('acl_account' => $acl_acc_list), __LINE__, __FILE__) as $row) |
|
| 128 | 128 | { |
| 129 | - $this->data[$row['acl_appname'].'-'.$row['acl_location'].'-'.$row['acl_account']] = Db::strip_array_keys($row,'acl_'); |
|
| 129 | + $this->data[$row['acl_appname'].'-'.$row['acl_location'].'-'.$row['acl_account']] = Db::strip_array_keys($row, 'acl_'); |
|
| 130 | 130 | } |
| 131 | 131 | return $this->data; |
| 132 | 132 | } |
@@ -155,15 +155,15 @@ discard block |
||
| 155 | 155 | * @param int $rights rights |
| 156 | 156 | * @return array all ACL records from $this->data. |
| 157 | 157 | */ |
| 158 | - function add($appname,$location,$rights) |
|
| 158 | + function add($appname, $location, $rights) |
|
| 159 | 159 | { |
| 160 | 160 | if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
| 161 | 161 | |
| 162 | 162 | $row = array( |
| 163 | 163 | 'appname' => $appname, |
| 164 | 164 | 'location' => $location, |
| 165 | - 'account' => (int) $this->account_id, |
|
| 166 | - 'rights' => (int) $rights |
|
| 165 | + 'account' => (int)$this->account_id, |
|
| 166 | + 'rights' => (int)$rights |
|
| 167 | 167 | ); |
| 168 | 168 | $this->data[$row['appname'].'-'.$row['location'].'-'.$row['account']] = $row; |
| 169 | 169 | |
@@ -177,11 +177,11 @@ discard block |
||
| 177 | 177 | * @param string/boolean $location location or false for all locations |
| 178 | 178 | * @return array all ACL records from $this->data. |
| 179 | 179 | */ |
| 180 | - function delete($appname,$location) |
|
| 180 | + function delete($appname, $location) |
|
| 181 | 181 | { |
| 182 | 182 | if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
| 183 | 183 | |
| 184 | - foreach($this->data as $idx => $value) |
|
| 184 | + foreach ($this->data as $idx => $value) |
|
| 185 | 185 | { |
| 186 | 186 | if ($value['appname'] == $appname && |
| 187 | 187 | ($location === false || $value['location'] == $location) && |
@@ -200,24 +200,24 @@ discard block |
||
| 200 | 200 | */ |
| 201 | 201 | function save_repository() |
| 202 | 202 | { |
| 203 | - $this->db->delete(self::TABLE,array( |
|
| 203 | + $this->db->delete(self::TABLE, array( |
|
| 204 | 204 | 'acl_account' => $this->account_id, |
| 205 | - ),__LINE__,__FILE__); |
|
| 205 | + ), __LINE__, __FILE__); |
|
| 206 | 206 | |
| 207 | - foreach($this->data as $value) |
|
| 207 | + foreach ($this->data as $value) |
|
| 208 | 208 | { |
| 209 | 209 | if ($value['account'] == $this->account_id) |
| 210 | 210 | { |
| 211 | - $this->db->insert(self::TABLE,array( |
|
| 211 | + $this->db->insert(self::TABLE, array( |
|
| 212 | 212 | 'acl_appname' => $value['appname'], |
| 213 | 213 | 'acl_location' => $value['location'], |
| 214 | 214 | 'acl_account' => $this->account_id, |
| 215 | 215 | 'acl_rights' => $value['rights'], |
| 216 | - ),false,__LINE__,__FILE__); |
|
| 216 | + ), false, __LINE__, __FILE__); |
|
| 217 | 217 | } |
| 218 | 218 | } |
| 219 | 219 | if ($this->account_id == $GLOBALS['egw_info']['user']['account_id'] && |
| 220 | - method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
| 220 | + method_exists($GLOBALS['egw'], 'invalidate_session_cache')) // egw object in setup is limited |
|
| 221 | 221 | { |
| 222 | 222 | $GLOBALS['egw']->invalidate_session_cache(); |
| 223 | 223 | } |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | * @param string $appname optional defaults to $GLOBALS['egw_info']['flags']['currentapp']; |
| 236 | 236 | * @return int all rights or'ed together |
| 237 | 237 | */ |
| 238 | - function get_rights($location,$appname = '') |
|
| 238 | + function get_rights($location, $appname = '') |
|
| 239 | 239 | { |
| 240 | 240 | // For XML-RPC, change this once its working correctly for passing parameters (jengo) |
| 241 | 241 | if (is_array($location)) |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | return True; |
| 256 | 256 | } |
| 257 | 257 | $rights = 0; |
| 258 | - foreach($this->data as $value) |
|
| 258 | + foreach ($this->data as $value) |
|
| 259 | 259 | { |
| 260 | 260 | if ($value['appname'] == $appname) |
| 261 | 261 | { |
@@ -282,9 +282,9 @@ discard block |
||
| 282 | 282 | */ |
| 283 | 283 | function check($location, $required, $appname = False) |
| 284 | 284 | { |
| 285 | - $rights = $this->get_rights($location,$appname); |
|
| 285 | + $rights = $this->get_rights($location, $appname); |
|
| 286 | 286 | |
| 287 | - return !!($rights & $required); |
|
| 287 | + return !!($rights&$required); |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | /** |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | * @param array $memberships = array() additional account_id, eg. memberships to match beside $this->account_id, default none |
| 296 | 296 | * @return int $rights |
| 297 | 297 | */ |
| 298 | - function get_specific_rights($location, $appname = '', $memberships=array()) |
|
| 298 | + function get_specific_rights($location, $appname = '', $memberships = array()) |
|
| 299 | 299 | { |
| 300 | 300 | if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
| 301 | 301 | |
@@ -305,10 +305,10 @@ discard block |
||
| 305 | 305 | } |
| 306 | 306 | $rights = 0; |
| 307 | 307 | |
| 308 | - foreach($this->data as $value) |
|
| 308 | + foreach ($this->data as $value) |
|
| 309 | 309 | { |
| 310 | 310 | if ($value['appname'] == $appname && |
| 311 | - ($value['location'] == $location || $value['location'] == 'everywhere') && |
|
| 311 | + ($value['location'] == $location || $value['location'] == 'everywhere') && |
|
| 312 | 312 | ($value['account'] == $this->account_id || $memberships && in_array($value['account'], $memberships))) |
| 313 | 313 | { |
| 314 | 314 | if ($value['rights'] == 0) |
@@ -331,9 +331,9 @@ discard block |
||
| 331 | 331 | */ |
| 332 | 332 | function check_specific($location, $required, $appname = '') |
| 333 | 333 | { |
| 334 | - $rights = $this->get_specific_rights($location,$appname); |
|
| 334 | + $rights = $this->get_specific_rights($location, $appname); |
|
| 335 | 335 | |
| 336 | - return !!($rights & $required); |
|
| 336 | + return !!($rights&$required); |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | /**************************************************************************\ |
@@ -350,19 +350,19 @@ discard block |
||
| 350 | 350 | * @param boolean $invalidate_session =true false: do NOT invalidate session |
| 351 | 351 | * @return boolean allways true |
| 352 | 352 | */ |
| 353 | - function add_repository($app, $location, $account_id, $rights, $invalidate_session=true) |
|
| 353 | + function add_repository($app, $location, $account_id, $rights, $invalidate_session = true) |
|
| 354 | 354 | { |
| 355 | 355 | //echo "<p>self::add_repository('$app','$location',$account_id,$rights);</p>\n"; |
| 356 | - $this->db->insert(self::TABLE,array( |
|
| 356 | + $this->db->insert(self::TABLE, array( |
|
| 357 | 357 | 'acl_rights' => $rights, |
| 358 | - ),array( |
|
| 358 | + ), array( |
|
| 359 | 359 | 'acl_appname' => $app, |
| 360 | 360 | 'acl_location' => $location, |
| 361 | 361 | 'acl_account' => $account_id, |
| 362 | - ),__LINE__,__FILE__); |
|
| 362 | + ), __LINE__, __FILE__); |
|
| 363 | 363 | |
| 364 | 364 | if ($invalidate_session && $account_id == $GLOBALS['egw_info']['user']['account_id'] && |
| 365 | - method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
| 365 | + method_exists($GLOBALS['egw'], 'invalidate_session_cache')) // egw object in setup is limited |
|
| 366 | 366 | { |
| 367 | 367 | $GLOBALS['egw']->invalidate_session_cache(); |
| 368 | 368 | } |
@@ -378,7 +378,7 @@ discard block |
||
| 378 | 378 | * @param boolean $invalidate_session =true false: do NOT invalidate session |
| 379 | 379 | * @return int number of rows deleted |
| 380 | 380 | */ |
| 381 | - function delete_repository($app, $location, $accountid='', $invalidate_session=true) |
|
| 381 | + function delete_repository($app, $location, $accountid = '', $invalidate_session = true) |
|
| 382 | 382 | { |
| 383 | 383 | static $cache_accountid = array(); |
| 384 | 384 | |
@@ -388,22 +388,22 @@ discard block |
||
| 388 | 388 | ); |
| 389 | 389 | if ($accountid !== false) |
| 390 | 390 | { |
| 391 | - if(isset($cache_accountid[$accountid]) && $cache_accountid[$accountid]) |
|
| 391 | + if (isset($cache_accountid[$accountid]) && $cache_accountid[$accountid]) |
|
| 392 | 392 | { |
| 393 | 393 | $where['acl_account'] = $cache_accountid[$accountid]; |
| 394 | 394 | } |
| 395 | 395 | else |
| 396 | 396 | { |
| 397 | - $where['acl_account'] = $cache_accountid[$accountid] = get_account_id($accountid,$this->account_id); |
|
| 397 | + $where['acl_account'] = $cache_accountid[$accountid] = get_account_id($accountid, $this->account_id); |
|
| 398 | 398 | } |
| 399 | 399 | } |
| 400 | 400 | if ($app == '%' || $app == '%%') unset($where['acl_appname']); |
| 401 | 401 | |
| 402 | - $this->db->delete(self::TABLE,$where,__LINE__,__FILE__); |
|
| 402 | + $this->db->delete(self::TABLE, $where, __LINE__, __FILE__); |
|
| 403 | 403 | |
| 404 | 404 | $deleted = $this->db->affected_rows(); |
| 405 | 405 | |
| 406 | - if ($invalidate_session && $deleted && method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
| 406 | + if ($invalidate_session && $deleted && method_exists($GLOBALS['egw'], 'invalidate_session_cache')) // egw object in setup is limited |
|
| 407 | 407 | { |
| 408 | 408 | $GLOBALS['egw']->invalidate_session_cache(); |
| 409 | 409 | } |
@@ -418,15 +418,15 @@ discard block |
||
| 418 | 418 | * @param string $appname = '' defaults to current app |
| 419 | 419 | * @return int/boolean rights or false if none exist |
| 420 | 420 | */ |
| 421 | - function get_specific_rights_for_account($account_id,$location,$appname='') |
|
| 421 | + function get_specific_rights_for_account($account_id, $location, $appname = '') |
|
| 422 | 422 | { |
| 423 | 423 | if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
| 424 | 424 | |
| 425 | - return $this->db->select(self::TABLE,'acl_rights',array( |
|
| 425 | + return $this->db->select(self::TABLE, 'acl_rights', array( |
|
| 426 | 426 | 'acl_location' => $location, |
| 427 | 427 | 'acl_account' => $account_id, |
| 428 | 428 | 'acl_appname' => $appname, |
| 429 | - ),__LINE__,__FILE__)->fetchColumn(); |
|
| 429 | + ), __LINE__, __FILE__)->fetchColumn(); |
|
| 430 | 430 | } |
| 431 | 431 | |
| 432 | 432 | /** |
@@ -436,15 +436,15 @@ discard block |
||
| 436 | 436 | * @param string $appname = '' defaults to current app |
| 437 | 437 | * @return array with account => rights pairs |
| 438 | 438 | */ |
| 439 | - function get_all_rights($location,$appname='') |
|
| 439 | + function get_all_rights($location, $appname = '') |
|
| 440 | 440 | { |
| 441 | 441 | if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
| 442 | 442 | |
| 443 | 443 | $rights = array(); |
| 444 | - foreach($this->db->select(self::TABLE,'acl_account,acl_rights',array( |
|
| 444 | + foreach ($this->db->select(self::TABLE, 'acl_account,acl_rights', array( |
|
| 445 | 445 | 'acl_location' => $location, |
| 446 | 446 | 'acl_appname' => $appname, |
| 447 | - ),__LINE__,__FILE__) as $row) |
|
| 447 | + ), __LINE__, __FILE__) as $row) |
|
| 448 | 448 | { |
| 449 | 449 | $rights[$row['acl_account']] = $row['acl_rights']; |
| 450 | 450 | } |
@@ -459,7 +459,7 @@ discard block |
||
| 459 | 459 | * @param boolean $use_memberships = true |
| 460 | 460 | * @return array with location => rights pairs |
| 461 | 461 | */ |
| 462 | - function get_all_location_rights($account_id,$appname='',$use_memberships=true) |
|
| 462 | + function get_all_location_rights($account_id, $appname = '', $use_memberships = true) |
|
| 463 | 463 | { |
| 464 | 464 | if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
| 465 | 465 | |
@@ -470,10 +470,10 @@ discard block |
||
| 470 | 470 | $accounts[] = $account_id; |
| 471 | 471 | } |
| 472 | 472 | $rights = array(); |
| 473 | - foreach($this->db->select(self::TABLE,'acl_location,acl_rights',array( |
|
| 473 | + foreach ($this->db->select(self::TABLE, 'acl_location,acl_rights', array( |
|
| 474 | 474 | 'acl_account' => $accounts, |
| 475 | 475 | 'acl_appname' => $appname, |
| 476 | - ),__LINE__,__FILE__) as $row) |
|
| 476 | + ), __LINE__, __FILE__) as $row) |
|
| 477 | 477 | { |
| 478 | 478 | $rights[$row['acl_location']] |= $row['acl_rights']; |
| 479 | 479 | } |
@@ -492,28 +492,28 @@ discard block |
||
| 492 | 492 | { |
| 493 | 493 | static $cache_accountid = array(); |
| 494 | 494 | |
| 495 | - if(isset($cache_accountid[$accountid])) |
|
| 495 | + if (isset($cache_accountid[$accountid])) |
|
| 496 | 496 | { |
| 497 | 497 | $account_id = $cache_accountid[$accountid]; |
| 498 | 498 | } |
| 499 | 499 | else |
| 500 | 500 | { |
| 501 | - $account_id = get_account_id($accountid,$this->account_id); |
|
| 501 | + $account_id = get_account_id($accountid, $this->account_id); |
|
| 502 | 502 | $cache_accountid[$accountid] = $account_id; |
| 503 | 503 | } |
| 504 | 504 | $rights = 0; |
| 505 | 505 | $apps = false; |
| 506 | - foreach($this->db->select(self::TABLE,array('acl_appname','acl_rights'),array( |
|
| 506 | + foreach ($this->db->select(self::TABLE, array('acl_appname', 'acl_rights'), array( |
|
| 507 | 507 | 'acl_location' => $location, |
| 508 | 508 | 'acl_account' => $account_id, |
| 509 | - ),__LINE__,__FILE__) as $row) |
|
| 509 | + ), __LINE__, __FILE__) as $row) |
|
| 510 | 510 | { |
| 511 | 511 | if ($row['acl_rights'] == 0) |
| 512 | 512 | { |
| 513 | 513 | return False; |
| 514 | 514 | } |
| 515 | 515 | $rights |= $row['acl_rights']; |
| 516 | - if (!!($rights & $required)) |
|
| 516 | + if (!!($rights&$required)) |
|
| 517 | 517 | { |
| 518 | 518 | $apps[] = $row['acl_appname']; |
| 519 | 519 | } |
@@ -533,21 +533,21 @@ discard block |
||
| 533 | 533 | { |
| 534 | 534 | static $cache_accountid = array(); |
| 535 | 535 | |
| 536 | - if(isset($cache_accountid[$accountid])) |
|
| 536 | + if (isset($cache_accountid[$accountid])) |
|
| 537 | 537 | { |
| 538 | 538 | $accountid = $cache_accountid[$accountid]; |
| 539 | 539 | } |
| 540 | 540 | else |
| 541 | 541 | { |
| 542 | - $accountid = $cache_accountid[$accountid] = get_account_id($accountid,$this->account_id); |
|
| 542 | + $accountid = $cache_accountid[$accountid] = get_account_id($accountid, $this->account_id); |
|
| 543 | 543 | } |
| 544 | 544 | $locations = false; |
| 545 | - foreach($this->db->select(self::TABLE,'acl_location,acl_rights',array( |
|
| 545 | + foreach ($this->db->select(self::TABLE, 'acl_location,acl_rights', array( |
|
| 546 | 546 | 'acl_appname' => $app, |
| 547 | 547 | 'acl_account' => $accountid, |
| 548 | - ),__LINE__,__FILE__) as $row) |
|
| 548 | + ), __LINE__, __FILE__) as $row) |
|
| 549 | 549 | { |
| 550 | - if ($row['acl_rights'] & $required) |
|
| 550 | + if ($row['acl_rights']&$required) |
|
| 551 | 551 | { |
| 552 | 552 | $locations[] = $row['acl_location']; |
| 553 | 553 | } |
@@ -568,14 +568,14 @@ discard block |
||
| 568 | 568 | if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp']; |
| 569 | 569 | |
| 570 | 570 | $accounts = false; |
| 571 | - foreach($this->db->select(self::TABLE,array('acl_account','acl_rights'),array( |
|
| 571 | + foreach ($this->db->select(self::TABLE, array('acl_account', 'acl_rights'), array( |
|
| 572 | 572 | 'acl_appname' => $app, |
| 573 | 573 | 'acl_location' => $location, |
| 574 | - ),__LINE__,__FILE__) as $row) |
|
| 574 | + ), __LINE__, __FILE__) as $row) |
|
| 575 | 575 | { |
| 576 | - if (!!($row['acl_rights'] & $required)) |
|
| 576 | + if (!!($row['acl_rights']&$required)) |
|
| 577 | 577 | { |
| 578 | - $accounts[] = (int) $row['acl_account']; |
|
| 578 | + $accounts[] = (int)$row['acl_account']; |
|
| 579 | 579 | } |
| 580 | 580 | } |
| 581 | 581 | return $accounts; |
@@ -587,14 +587,14 @@ discard block |
||
| 587 | 587 | * @param string $app app optional defaults to $GLOBALS['egw_info']['flags']['currentapp']; |
| 588 | 588 | * @return boolean/array false if there are no matching location in the db or array of locations |
| 589 | 589 | */ |
| 590 | - function get_locations_for_app($app='') |
|
| 590 | + function get_locations_for_app($app = '') |
|
| 591 | 591 | { |
| 592 | 592 | if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp']; |
| 593 | 593 | |
| 594 | 594 | $locations = false; |
| 595 | - foreach($this->db->select(self::TABLE,'DISTINCT '.'acl_location',array( |
|
| 595 | + foreach ($this->db->select(self::TABLE, 'DISTINCT '.'acl_location', array( |
|
| 596 | 596 | 'acl_appname' => $app, |
| 597 | - ),__LINE__,__FILE__) as $row) |
|
| 597 | + ), __LINE__, __FILE__) as $row) |
|
| 598 | 598 | { |
| 599 | 599 | if (($location = $row['acl_location']) != 'run') |
| 600 | 600 | { |
@@ -612,38 +612,38 @@ discard block |
||
| 612 | 612 | * @param boolean $add_implicit_apps = true true: add apps every user has implicit rights |
| 613 | 613 | * @return array containing list of apps |
| 614 | 614 | */ |
| 615 | - function get_user_applications($accountid = '', $use_memberships=true, $add_implicit_apps=true) |
|
| 615 | + function get_user_applications($accountid = '', $use_memberships = true, $add_implicit_apps = true) |
|
| 616 | 616 | { |
| 617 | 617 | static $cache_accountid = array(); |
| 618 | 618 | |
| 619 | - if(isset($cache_accountid[$accountid])) |
|
| 619 | + if (isset($cache_accountid[$accountid])) |
|
| 620 | 620 | { |
| 621 | 621 | $account_id = $cache_accountid[$accountid]; |
| 622 | 622 | } |
| 623 | 623 | else |
| 624 | 624 | { |
| 625 | - $account_id = get_account_id($accountid,$this->account_id); |
|
| 625 | + $account_id = get_account_id($accountid, $this->account_id); |
|
| 626 | 626 | $cache_accountid[$accountid] = $account_id; |
| 627 | 627 | } |
| 628 | 628 | if ($use_memberships && (int)$account_id > 0) $memberships = $GLOBALS['egw']->accounts->memberships($account_id, true); |
| 629 | 629 | $memberships[] = (int)$account_id; |
| 630 | 630 | |
| 631 | 631 | $apps = array(); |
| 632 | - foreach($this->db->select(self::TABLE,array('acl_appname','acl_rights'),array( |
|
| 632 | + foreach ($this->db->select(self::TABLE, array('acl_appname', 'acl_rights'), array( |
|
| 633 | 633 | 'acl_location' => 'run', |
| 634 | 634 | 'acl_account' => $memberships, |
| 635 | - ),__LINE__,__FILE__) as $row) |
|
| 635 | + ), __LINE__, __FILE__) as $row) |
|
| 636 | 636 | { |
| 637 | 637 | $app = $row['acl_appname']; |
| 638 | - if(!isset($apps[$app])) |
|
| 638 | + if (!isset($apps[$app])) |
|
| 639 | 639 | { |
| 640 | 640 | $apps[$app] = 0; |
| 641 | 641 | } |
| 642 | - $apps[$app] |= (int) $row['acl_rights']; |
|
| 642 | + $apps[$app] |= (int)$row['acl_rights']; |
|
| 643 | 643 | } |
| 644 | 644 | if ($add_implicit_apps) |
| 645 | 645 | { |
| 646 | - $apps['api'] = 1; // give everyone implicit rights for the home app |
|
| 646 | + $apps['api'] = 1; // give everyone implicit rights for the home app |
|
| 647 | 647 | } |
| 648 | 648 | return $apps; |
| 649 | 649 | } |
@@ -657,29 +657,29 @@ discard block |
||
| 657 | 657 | * @param int $user = null user whos grants to return, default current user |
| 658 | 658 | * @return array with account-ids (of owners) and granted rights as values |
| 659 | 659 | */ |
| 660 | - function get_grants($app='',$enum_group_acls=true,$user=null) |
|
| 660 | + function get_grants($app = '', $enum_group_acls = true, $user = null) |
|
| 661 | 661 | { |
| 662 | 662 | if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp']; |
| 663 | 663 | if (!$user) $user = $this->account_id; |
| 664 | 664 | |
| 665 | - static $cache = array(); // some caching withing the request |
|
| 665 | + static $cache = array(); // some caching withing the request |
|
| 666 | 666 | |
| 667 | - $grants =& $cache[$app][$user]; |
|
| 667 | + $grants = & $cache[$app][$user]; |
|
| 668 | 668 | if (!isset($grants)) |
| 669 | 669 | { |
| 670 | 670 | if ((int)$user > 0) $memberships = $GLOBALS['egw']->accounts->memberships($user, true); |
| 671 | 671 | $memberships[] = $user; |
| 672 | 672 | |
| 673 | 673 | $grants = $accounts = Array(); |
| 674 | - foreach($this->db->select(self::TABLE,array('acl_account','acl_rights','acl_location'),array( |
|
| 674 | + foreach ($this->db->select(self::TABLE, array('acl_account', 'acl_rights', 'acl_location'), array( |
|
| 675 | 675 | 'acl_appname' => $app, |
| 676 | 676 | 'acl_location' => $memberships, |
| 677 | - ),__LINE__,__FILE__) as $row) |
|
| 677 | + ), __LINE__, __FILE__) as $row) |
|
| 678 | 678 | { |
| 679 | 679 | $grantor = $row['acl_account']; |
| 680 | 680 | $rights = $row['acl_rights']; |
| 681 | 681 | |
| 682 | - if(!isset($grants[$grantor])) |
|
| 682 | + if (!isset($grants[$grantor])) |
|
| 683 | 683 | { |
| 684 | 684 | $grants[$grantor] = 0; |
| 685 | 685 | } |
@@ -687,17 +687,17 @@ discard block |
||
| 687 | 687 | |
| 688 | 688 | // if the right is granted from a group and we enummerated group ACL's |
| 689 | 689 | if ($GLOBALS['egw']->accounts->get_type($grantor) == 'g' && $enum_group_acls && |
| 690 | - (!is_array($enum_group_acls) || !in_array($grantor,$enum_group_acls))) |
|
| 690 | + (!is_array($enum_group_acls) || !in_array($grantor, $enum_group_acls))) |
|
| 691 | 691 | { |
| 692 | 692 | // return the grant for each member of the group (false = also for no longer active users) |
| 693 | - foreach((array)$GLOBALS['egw']->accounts->members($grantor, true, false) as $grantor) |
|
| 693 | + foreach ((array)$GLOBALS['egw']->accounts->members($grantor, true, false) as $grantor) |
|
| 694 | 694 | { |
| 695 | - if (!$grantor) continue; // can happen if group has no members |
|
| 695 | + if (!$grantor) continue; // can happen if group has no members |
|
| 696 | 696 | |
| 697 | 697 | // Don't allow to override private with group ACL's! |
| 698 | 698 | $rights &= ~self::PRIVAT; |
| 699 | 699 | |
| 700 | - if(!isset($grants[$grantor])) |
|
| 700 | + if (!isset($grants[$grantor])) |
|
| 701 | 701 | { |
| 702 | 702 | $grants[$grantor] = 0; |
| 703 | 703 | } |
@@ -719,21 +719,21 @@ discard block |
||
| 719 | 719 | */ |
| 720 | 720 | function delete_account($account_id) |
| 721 | 721 | { |
| 722 | - if ((int) $account_id) |
|
| 722 | + if ((int)$account_id) |
|
| 723 | 723 | { |
| 724 | 724 | // Delete all grants from this account |
| 725 | - $this->db->delete(self::TABLE,array( |
|
| 725 | + $this->db->delete(self::TABLE, array( |
|
| 726 | 726 | 'acl_account' => $account_id |
| 727 | - ),__LINE__,__FILE__); |
|
| 727 | + ), __LINE__, __FILE__); |
|
| 728 | 728 | // Delete all grants to this account |
| 729 | - $this->db->delete(self::TABLE,array( |
|
| 729 | + $this->db->delete(self::TABLE, array( |
|
| 730 | 730 | 'acl_location' => $account_id |
| 731 | - ),__LINE__, __FILE__); |
|
| 731 | + ), __LINE__, __FILE__); |
|
| 732 | 732 | // delete all memberships in account_id (if it is a group) |
| 733 | - $this->db->delete(self::TABLE,array( |
|
| 733 | + $this->db->delete(self::TABLE, array( |
|
| 734 | 734 | 'acl_appname' => 'phpgw_group', |
| 735 | 735 | 'acl_location' => $account_id, |
| 736 | - ),__LINE__,__FILE__); |
|
| 736 | + ), __LINE__, __FILE__); |
|
| 737 | 737 | } |
| 738 | 738 | } |
| 739 | 739 | |
@@ -744,15 +744,15 @@ discard block |
||
| 744 | 744 | * @param string $app app optional defaults to $GLOBALS['egw_info']['flags']['currentapp']; |
| 745 | 745 | * @return array with location => array(account => rights) pairs |
| 746 | 746 | */ |
| 747 | - function get_location_grants($location,$app='') |
|
| 747 | + function get_location_grants($location, $app = '') |
|
| 748 | 748 | { |
| 749 | 749 | if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp']; |
| 750 | 750 | |
| 751 | 751 | $locations = array(); |
| 752 | - foreach($this->db->select(self::TABLE,'acl_location,acl_account,acl_rights',array( |
|
| 752 | + foreach ($this->db->select(self::TABLE, 'acl_location,acl_account,acl_rights', array( |
|
| 753 | 753 | 'acl_appname' => $app, |
| 754 | 754 | 'acl_location LIKE '.$this->db->quote($location), |
| 755 | - ),__LINE__,__FILE__) as $row) |
|
| 755 | + ), __LINE__, __FILE__) as $row) |
|
| 756 | 756 | { |
| 757 | 757 | if (($location = $row['acl_location']) != 'run') |
| 758 | 758 | { |
@@ -119,7 +119,10 @@ discard block |
||
| 119 | 119 | else |
| 120 | 120 | { |
| 121 | 121 | $acl_acc_list = (array)$GLOBALS['egw']->accounts->memberships($this->account_id, true); |
| 122 | - if (is_array($no_groups)) $acl_acc_list = array_diff($acl_acc_list,$no_groups); |
|
| 122 | + if (is_array($no_groups)) |
|
| 123 | + { |
|
| 124 | + $acl_acc_list = array_diff($acl_acc_list,$no_groups); |
|
| 125 | + } |
|
| 123 | 126 | array_unshift($acl_acc_list,$this->account_id); |
| 124 | 127 | } |
| 125 | 128 | |
@@ -157,7 +160,10 @@ discard block |
||
| 157 | 160 | */ |
| 158 | 161 | function add($appname,$location,$rights) |
| 159 | 162 | { |
| 160 | - if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 163 | + if (!$appname) |
|
| 164 | + { |
|
| 165 | + $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 166 | + } |
|
| 161 | 167 | |
| 162 | 168 | $row = array( |
| 163 | 169 | 'appname' => $appname, |
@@ -179,7 +185,10 @@ discard block |
||
| 179 | 185 | */ |
| 180 | 186 | function delete($appname,$location) |
| 181 | 187 | { |
| 182 | - if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 188 | + if (!$appname) |
|
| 189 | + { |
|
| 190 | + $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 191 | + } |
|
| 183 | 192 | |
| 184 | 193 | foreach($this->data as $idx => $value) |
| 185 | 194 | { |
@@ -217,10 +226,13 @@ discard block |
||
| 217 | 226 | } |
| 218 | 227 | } |
| 219 | 228 | if ($this->account_id == $GLOBALS['egw_info']['user']['account_id'] && |
| 220 | - method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
| 229 | + method_exists($GLOBALS['egw'],'invalidate_session_cache')) |
|
| 230 | + { |
|
| 231 | + // egw object in setup is limited |
|
| 221 | 232 | { |
| 222 | 233 | $GLOBALS['egw']->invalidate_session_cache(); |
| 223 | 234 | } |
| 235 | + } |
|
| 224 | 236 | return $this->data; |
| 225 | 237 | } |
| 226 | 238 | |
@@ -248,7 +260,10 @@ discard block |
||
| 248 | 260 | { |
| 249 | 261 | $this->read_repository(); |
| 250 | 262 | } |
| 251 | - if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 263 | + if (!$appname) |
|
| 264 | + { |
|
| 265 | + $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 266 | + } |
|
| 252 | 267 | |
| 253 | 268 | if (!count($this->data) && $GLOBALS['egw_info']['server']['acl_default'] != 'deny') |
| 254 | 269 | { |
@@ -297,7 +312,10 @@ discard block |
||
| 297 | 312 | */ |
| 298 | 313 | function get_specific_rights($location, $appname = '', $memberships=array()) |
| 299 | 314 | { |
| 300 | - if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 315 | + if (!$appname) |
|
| 316 | + { |
|
| 317 | + $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 318 | + } |
|
| 301 | 319 | |
| 302 | 320 | if (!count($this->data) && $GLOBALS['egw_info']['server']['acl_default'] != 'deny') |
| 303 | 321 | { |
@@ -362,10 +380,13 @@ discard block |
||
| 362 | 380 | ),__LINE__,__FILE__); |
| 363 | 381 | |
| 364 | 382 | if ($invalidate_session && $account_id == $GLOBALS['egw_info']['user']['account_id'] && |
| 365 | - method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
| 383 | + method_exists($GLOBALS['egw'],'invalidate_session_cache')) |
|
| 384 | + { |
|
| 385 | + // egw object in setup is limited |
|
| 366 | 386 | { |
| 367 | 387 | $GLOBALS['egw']->invalidate_session_cache(); |
| 368 | 388 | } |
| 389 | + } |
|
| 369 | 390 | return True; |
| 370 | 391 | } |
| 371 | 392 | |
@@ -397,16 +418,22 @@ discard block |
||
| 397 | 418 | $where['acl_account'] = $cache_accountid[$accountid] = get_account_id($accountid,$this->account_id); |
| 398 | 419 | } |
| 399 | 420 | } |
| 400 | - if ($app == '%' || $app == '%%') unset($where['acl_appname']); |
|
| 421 | + if ($app == '%' || $app == '%%') |
|
| 422 | + { |
|
| 423 | + unset($where['acl_appname']); |
|
| 424 | + } |
|
| 401 | 425 | |
| 402 | 426 | $this->db->delete(self::TABLE,$where,__LINE__,__FILE__); |
| 403 | 427 | |
| 404 | 428 | $deleted = $this->db->affected_rows(); |
| 405 | 429 | |
| 406 | - if ($invalidate_session && $deleted && method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
| 430 | + if ($invalidate_session && $deleted && method_exists($GLOBALS['egw'],'invalidate_session_cache')) |
|
| 431 | + { |
|
| 432 | + // egw object in setup is limited |
|
| 407 | 433 | { |
| 408 | 434 | $GLOBALS['egw']->invalidate_session_cache(); |
| 409 | 435 | } |
| 436 | + } |
|
| 410 | 437 | return $deleted; |
| 411 | 438 | } |
| 412 | 439 | |
@@ -420,7 +447,10 @@ discard block |
||
| 420 | 447 | */ |
| 421 | 448 | function get_specific_rights_for_account($account_id,$location,$appname='') |
| 422 | 449 | { |
| 423 | - if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 450 | + if (!$appname) |
|
| 451 | + { |
|
| 452 | + $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 453 | + } |
|
| 424 | 454 | |
| 425 | 455 | return $this->db->select(self::TABLE,'acl_rights',array( |
| 426 | 456 | 'acl_location' => $location, |
@@ -438,7 +468,10 @@ discard block |
||
| 438 | 468 | */ |
| 439 | 469 | function get_all_rights($location,$appname='') |
| 440 | 470 | { |
| 441 | - if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 471 | + if (!$appname) |
|
| 472 | + { |
|
| 473 | + $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 474 | + } |
|
| 442 | 475 | |
| 443 | 476 | $rights = array(); |
| 444 | 477 | foreach($this->db->select(self::TABLE,'acl_account,acl_rights',array( |
@@ -461,7 +494,10 @@ discard block |
||
| 461 | 494 | */ |
| 462 | 495 | function get_all_location_rights($account_id,$appname='',$use_memberships=true) |
| 463 | 496 | { |
| 464 | - if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 497 | + if (!$appname) |
|
| 498 | + { |
|
| 499 | + $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 500 | + } |
|
| 465 | 501 | |
| 466 | 502 | $accounts = array($account_id); |
| 467 | 503 | if ($use_memberships && (int)$account_id > 0) |
@@ -565,7 +601,10 @@ discard block |
||
| 565 | 601 | */ |
| 566 | 602 | function get_ids_for_location($location, $required, $app = '') |
| 567 | 603 | { |
| 568 | - if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 604 | + if (!$app) |
|
| 605 | + { |
|
| 606 | + $app = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 607 | + } |
|
| 569 | 608 | |
| 570 | 609 | $accounts = false; |
| 571 | 610 | foreach($this->db->select(self::TABLE,array('acl_account','acl_rights'),array( |
@@ -589,7 +628,10 @@ discard block |
||
| 589 | 628 | */ |
| 590 | 629 | function get_locations_for_app($app='') |
| 591 | 630 | { |
| 592 | - if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 631 | + if (!$app) |
|
| 632 | + { |
|
| 633 | + $app = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 634 | + } |
|
| 593 | 635 | |
| 594 | 636 | $locations = false; |
| 595 | 637 | foreach($this->db->select(self::TABLE,'DISTINCT '.'acl_location',array( |
@@ -625,7 +667,10 @@ discard block |
||
| 625 | 667 | $account_id = get_account_id($accountid,$this->account_id); |
| 626 | 668 | $cache_accountid[$accountid] = $account_id; |
| 627 | 669 | } |
| 628 | - if ($use_memberships && (int)$account_id > 0) $memberships = $GLOBALS['egw']->accounts->memberships($account_id, true); |
|
| 670 | + if ($use_memberships && (int)$account_id > 0) |
|
| 671 | + { |
|
| 672 | + $memberships = $GLOBALS['egw']->accounts->memberships($account_id, true); |
|
| 673 | + } |
|
| 629 | 674 | $memberships[] = (int)$account_id; |
| 630 | 675 | |
| 631 | 676 | $apps = array(); |
@@ -659,15 +704,24 @@ discard block |
||
| 659 | 704 | */ |
| 660 | 705 | function get_grants($app='',$enum_group_acls=true,$user=null) |
| 661 | 706 | { |
| 662 | - if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 663 | - if (!$user) $user = $this->account_id; |
|
| 707 | + if (!$app) |
|
| 708 | + { |
|
| 709 | + $app = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 710 | + } |
|
| 711 | + if (!$user) |
|
| 712 | + { |
|
| 713 | + $user = $this->account_id; |
|
| 714 | + } |
|
| 664 | 715 | |
| 665 | 716 | static $cache = array(); // some caching withing the request |
| 666 | 717 | |
| 667 | 718 | $grants =& $cache[$app][$user]; |
| 668 | 719 | if (!isset($grants)) |
| 669 | 720 | { |
| 670 | - if ((int)$user > 0) $memberships = $GLOBALS['egw']->accounts->memberships($user, true); |
|
| 721 | + if ((int)$user > 0) |
|
| 722 | + { |
|
| 723 | + $memberships = $GLOBALS['egw']->accounts->memberships($user, true); |
|
| 724 | + } |
|
| 671 | 725 | $memberships[] = $user; |
| 672 | 726 | |
| 673 | 727 | $grants = $accounts = Array(); |
@@ -692,7 +746,11 @@ discard block |
||
| 692 | 746 | // return the grant for each member of the group (false = also for no longer active users) |
| 693 | 747 | foreach((array)$GLOBALS['egw']->accounts->members($grantor, true, false) as $grantor) |
| 694 | 748 | { |
| 695 | - if (!$grantor) continue; // can happen if group has no members |
|
| 749 | + if (!$grantor) |
|
| 750 | + { |
|
| 751 | + continue; |
|
| 752 | + } |
|
| 753 | + // can happen if group has no members |
|
| 696 | 754 | |
| 697 | 755 | // Don't allow to override private with group ACL's! |
| 698 | 756 | $rights &= ~self::PRIVAT; |
@@ -746,7 +804,10 @@ discard block |
||
| 746 | 804 | */ |
| 747 | 805 | function get_location_grants($location,$app='') |
| 748 | 806 | { |
| 749 | - if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 807 | + if (!$app) |
|
| 808 | + { |
|
| 809 | + $app = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 810 | + } |
|
| 750 | 811 | |
| 751 | 812 | $locations = array(); |
| 752 | 813 | foreach($this->db->select(self::TABLE,'acl_location,acl_account,acl_rights',array( |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | * cancels a timer |
| 325 | 325 | * |
| 326 | 326 | * @param string $id has to be the one used to set it. |
| 327 | - * @return boolean True if the timer exists and is not expired. |
|
| 327 | + * @return integer True if the timer exists and is not expired. |
|
| 328 | 328 | */ |
| 329 | 329 | function cancel_timer($id) |
| 330 | 330 | { |
@@ -470,7 +470,7 @@ discard block |
||
| 470 | 470 | /** |
| 471 | 471 | * reads all matching db-rows / jobs |
| 472 | 472 | * |
| 473 | - * @param string $id =0 reads all expired rows / jobs ready to run\ |
|
| 473 | + * @param integer $id =0 reads all expired rows / jobs ready to run\ |
|
| 474 | 474 | * != 0 reads all rows/jobs matching $id (sql-wildcards '%' and '_' can be used) |
| 475 | 475 | * @param array|string $cols ='*' string or array of column-names / select-expressions |
| 476 | 476 | * @param int|bool $offset =False offset for a limited query or False (default) |
@@ -558,7 +558,7 @@ discard block |
||
| 558 | 558 | /** |
| 559 | 559 | * delete db-row / job with $id |
| 560 | 560 | * |
| 561 | - * @return boolean False if $id not found else True |
|
| 561 | + * @return integer False if $id not found else True |
|
| 562 | 562 | */ |
| 563 | 563 | function delete($id) |
| 564 | 564 | { |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | /** |
| 44 | 44 | * Time to keep expired jobs marked as "keep", until they got finally deleted |
| 45 | 45 | */ |
| 46 | - const DEFAULT_KEEP_TIME = 86400; // 1day |
|
| 46 | + const DEFAULT_KEEP_TIME = 86400; // 1day |
|
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | 49 | * constructor of the class |
@@ -58,9 +58,9 @@ discard block |
||
| 58 | 58 | { |
| 59 | 59 | $this->db = $GLOBALS['egw_setup']->db; |
| 60 | 60 | } |
| 61 | - $this->cronline = EGW_SERVER_ROOT . '/api/asyncservices.php '.$GLOBALS['egw_info']['user']['domain']; |
|
| 61 | + $this->cronline = EGW_SERVER_ROOT.'/api/asyncservices.php '.$GLOBALS['egw_info']['user']['domain']; |
|
| 62 | 62 | |
| 63 | - $this->only_fallback = substr(php_uname(), 0, 7) == "Windows"; // atm cron-jobs dont work on win |
|
| 63 | + $this->only_fallback = substr(php_uname(), 0, 7) == "Windows"; // atm cron-jobs dont work on win |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
@@ -83,10 +83,10 @@ discard block |
||
| 83 | 83 | * @param boolean $allow_past =false allow to set alarms in the past eg. with times===0 to not trigger it in next run |
| 84 | 84 | * @return boolean False if $id already exists, else True |
| 85 | 85 | */ |
| 86 | - function set_timer($times, $id, $method, $data=null, $account_id=False, $debug=false, $allow_past=false) |
|
| 86 | + function set_timer($times, $id, $method, $data = null, $account_id = False, $debug = false, $allow_past = false) |
|
| 87 | 87 | { |
| 88 | 88 | if (empty($id) || empty($method) || $this->read($id) || |
| 89 | - !($next = $this->next_run($times,$debug))) |
|
| 89 | + !($next = $this->next_run($times, $debug))) |
|
| 90 | 90 | { |
| 91 | 91 | // allow to set "keep" alarms in the past ($next === false) |
| 92 | 92 | if ($next === false && !is_array($times) && $allow_past) |
@@ -129,14 +129,14 @@ discard block |
||
| 129 | 129 | * @param int $now Use this time to calculate then next run from. Defaults to time(). |
| 130 | 130 | * @return int a unix timestamp of the next execution time or False if no more executions |
| 131 | 131 | */ |
| 132 | - function next_run($times,$debug=False, $now = null) |
|
| 132 | + function next_run($times, $debug = False, $now = null) |
|
| 133 | 133 | { |
| 134 | 134 | if ($this->debug) |
| 135 | 135 | { |
| 136 | - error_log(__METHOD__."(".array2string($times).", '$debug', " . date('Y-m-d H:i', $now) . ")"); |
|
| 137 | - $debug = True; // enable syntax-error messages too |
|
| 136 | + error_log(__METHOD__."(".array2string($times).", '$debug', ".date('Y-m-d H:i', $now).")"); |
|
| 137 | + $debug = True; // enable syntax-error messages too |
|
| 138 | 138 | } |
| 139 | - if(is_null($now)) { |
|
| 139 | + if (is_null($now)) { |
|
| 140 | 140 | $now = time(); |
| 141 | 141 | } |
| 142 | 142 | |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | 'dow' => 6, |
| 165 | 165 | 'day' => 31, |
| 166 | 166 | 'month' => 12, |
| 167 | - 'year' => date('Y')+10 // else */[0-9] would never stop returning numbers |
|
| 167 | + 'year' => date('Y') + 10 // else */[0-9] would never stop returning numbers |
|
| 168 | 168 | ); |
| 169 | 169 | $min_unit = array( |
| 170 | 170 | 'min' => 0, |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | // get set to the minimum after |
| 181 | 181 | // |
| 182 | 182 | $i = $first_set = $last_set = 0; |
| 183 | - foreach($units as $u => $date_pattern) |
|
| 183 | + foreach ($units as $u => $date_pattern) |
|
| 184 | 184 | { |
| 185 | 185 | ++$i; |
| 186 | 186 | if (isset($times[$u])) |
@@ -198,24 +198,24 @@ discard block |
||
| 198 | 198 | // (as descript above), enumerations are arrays with unit-values as keys |
| 199 | 199 | // |
| 200 | 200 | $n = 0; |
| 201 | - foreach($units as $u => $date_pattern) |
|
| 201 | + foreach ($units as $u => $date_pattern) |
|
| 202 | 202 | { |
| 203 | 203 | ++$n; |
| 204 | - if ($this->debug) error_log("n=$n, $u: isset(times[$u]=".array2string($times[$u]).")=".(isset($times[$u])?'True':'False')); |
|
| 204 | + if ($this->debug) error_log("n=$n, $u: isset(times[$u]=".array2string($times[$u]).")=".(isset($times[$u]) ? 'True' : 'False')); |
|
| 205 | 205 | if (isset($times[$u])) |
| 206 | 206 | { |
| 207 | - if(is_array($times[$u])) { |
|
| 207 | + if (is_array($times[$u])) { |
|
| 208 | 208 | $time = array_keys($times[$u]); |
| 209 | 209 | } else { |
| 210 | - $time = explode(',',$times[$u]); |
|
| 210 | + $time = explode(',', $times[$u]); |
|
| 211 | 211 | } |
| 212 | 212 | $times[$u] = array(); |
| 213 | 213 | |
| 214 | - foreach($time as $t) |
|
| 214 | + foreach ($time as $t) |
|
| 215 | 215 | { |
| 216 | - if (strpos($t,'-') !== False && strpos($t,'/') === False) |
|
| 216 | + if (strpos($t, '-') !== False && strpos($t, '/') === False) |
|
| 217 | 217 | { |
| 218 | - list($min,$max) = $arr = explode('-',$t); |
|
| 218 | + list($min, $max) = $arr = explode('-', $t); |
|
| 219 | 219 | |
| 220 | 220 | if (count($arr) != 2 || !is_numeric($min) || !is_numeric($max) || $min > $max) |
| 221 | 221 | { |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | { |
| 233 | 233 | if ((string)$t == '*') $t = '*/1'; |
| 234 | 234 | |
| 235 | - list($one,$inc) = $arr = explode('/',$t); |
|
| 235 | + list($one, $inc) = $arr = explode('/', $t); |
|
| 236 | 236 | |
| 237 | 237 | if (!(is_numeric($one) && count($arr) == 1 || |
| 238 | 238 | count($arr) == 2 && is_numeric($inc))) |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | } |
| 248 | 248 | else |
| 249 | 249 | { |
| 250 | - list($min,$max) = $arr = explode('-',$one); |
|
| 250 | + list($min, $max) = $arr = explode('-', $one); |
|
| 251 | 251 | if (empty($one) || $one == '*') |
| 252 | 252 | { |
| 253 | 253 | $min = $min_unit[$u]; |
@@ -288,20 +288,19 @@ discard block |
||
| 288 | 288 | { |
| 289 | 289 | $future = False; |
| 290 | 290 | |
| 291 | - foreach($units as $u => $date_pattern) |
|
| 291 | + foreach ($units as $u => $date_pattern) |
|
| 292 | 292 | { |
| 293 | - $unit_now = $u != 'dow' ? (int)date($date_pattern, $now) : |
|
| 294 | - (int)date($date_pattern,mktime(12,0,0,$found['month'],$found['day'],$found['year'])); |
|
| 293 | + $unit_now = $u != 'dow' ? (int)date($date_pattern, $now) : (int)date($date_pattern, mktime(12, 0, 0, $found['month'], $found['day'], $found['year'])); |
|
| 295 | 294 | |
| 296 | 295 | if (isset($found[$u])) |
| 297 | 296 | { |
| 298 | 297 | $future = $future || $found[$u] > $unit_now; |
| 299 | 298 | if ($this->debug) error_log("--> already have a $u = ".$found[$u].", future='$future'"); |
| 300 | - continue; // already set |
|
| 299 | + continue; // already set |
|
| 301 | 300 | } |
| 302 | - foreach(array_keys($times[$u]) as $unit_value) |
|
| 301 | + foreach (array_keys($times[$u]) as $unit_value) |
|
| 303 | 302 | { |
| 304 | - switch($u) |
|
| 303 | + switch ($u) |
|
| 305 | 304 | { |
| 306 | 305 | case 'dow': |
| 307 | 306 | $valid = $unit_value == $unit_now; |
@@ -324,12 +323,12 @@ discard block |
||
| 324 | 323 | if (!isset($found[$u])) // we have to try the next one, if it exists |
| 325 | 324 | { |
| 326 | 325 | $nexts = array_keys($units); |
| 327 | - if (!isset($nexts[count($found)-1])) |
|
| 326 | + if (!isset($nexts[count($found) - 1])) |
|
| 328 | 327 | { |
| 329 | 328 | if ($this->debug) error_log("Nothing found, exiting !!!"); |
| 330 | 329 | return False; |
| 331 | 330 | } |
| 332 | - $next = $nexts[count($found)-1]; |
|
| 331 | + $next = $nexts[count($found) - 1]; |
|
| 333 | 332 | $over = $found[$next]; |
| 334 | 333 | unset($found[$next]); |
| 335 | 334 | if ($this->debug) error_log("Have to try the next $next, $u's are over for $next=$over !!!"); |
@@ -339,7 +338,7 @@ discard block |
||
| 339 | 338 | } |
| 340 | 339 | if ($this->debug) error_log("next=".array2string($found)); |
| 341 | 340 | |
| 342 | - return mktime($found['hour'],$found['min'],0,$found['month'],$found['day'],$found['year']); |
|
| 341 | + return mktime($found['hour'], $found['min'], 0, $found['month'], $found['day'], $found['year']); |
|
| 343 | 342 | } |
| 344 | 343 | |
| 345 | 344 | /** |
@@ -361,7 +360,7 @@ discard block |
||
| 361 | 360 | * @return mixed if !$set array('start' => $start,'end' => $end) with timestamps of last check_run start and end, \ |
| 362 | 361 | * !$end means check_run is just running. If $set returns True if it was able to get the semaphore, else False |
| 363 | 362 | */ |
| 364 | - function last_check_run($semaphore=False,$release=False,$run_by='') |
|
| 363 | + function last_check_run($semaphore = False, $release = False, $run_by = '') |
|
| 365 | 364 | { |
| 366 | 365 | //echo "<p>last_check_run(semaphore=".($semaphore?'True':'False').",release=".($release?'True':'False').")</p>\n"; |
| 367 | 366 | if (($exists = $this->read('##last-check-run##'))) |
@@ -383,7 +382,7 @@ discard block |
||
| 383 | 382 | } |
| 384 | 383 | else |
| 385 | 384 | { |
| 386 | - @set_time_limit(0); // dont stop for an execution-time-limit |
|
| 385 | + @set_time_limit(0); // dont stop for an execution-time-limit |
|
| 387 | 386 | ignore_user_abort(True); |
| 388 | 387 | |
| 389 | 388 | $last_run = array( |
@@ -399,7 +398,7 @@ discard block |
||
| 399 | 398 | ); |
| 400 | 399 | // as the async_next column is used as a semaphore we only update it, |
| 401 | 400 | // if it is 0 (semaphore released) or older then 10min to recover from failed or crashed attempts |
| 402 | - if ($exists) $where = array('(async_next=0 OR async_next<'.(time()-600).')'); |
|
| 401 | + if ($exists) $where = array('(async_next=0 OR async_next<'.(time() - 600).')'); |
|
| 403 | 402 | } |
| 404 | 403 | //echo "last_run=<pre>"; print_r($last_run); echo "</pre>\n"; |
| 405 | 404 | return $this->write($last_run, !!$exists, $where) > 0; |
@@ -408,20 +407,20 @@ discard block |
||
| 408 | 407 | /** |
| 409 | 408 | * checks if there are any jobs ready to run (timer expired) and executes them |
| 410 | 409 | */ |
| 411 | - function check_run($run_by='') |
|
| 410 | + function check_run($run_by = '') |
|
| 412 | 411 | { |
| 413 | 412 | if ($run_by === 'fallback') flush(); |
| 414 | 413 | |
| 415 | - if (!$this->last_check_run(True,False,$run_by)) |
|
| 414 | + if (!$this->last_check_run(True, False, $run_by)) |
|
| 416 | 415 | { |
| 417 | - return False; // cant obtain semaphore |
|
| 416 | + return False; // cant obtain semaphore |
|
| 418 | 417 | } |
| 419 | 418 | // mark enviroment as async-service, check with isset()! |
| 420 | 419 | $GLOBALS['egw_info']['flags']['async-service'] = $run_by; |
| 421 | 420 | |
| 422 | 421 | if (($jobs = $this->read())) |
| 423 | 422 | { |
| 424 | - foreach($jobs as $job) |
|
| 423 | + foreach ($jobs as $job) |
|
| 425 | 424 | { |
| 426 | 425 | // checking / setting up egw_info/user |
| 427 | 426 | // |
@@ -430,7 +429,7 @@ discard block |
||
| 430 | 429 | // run notifications, before changing account_id of enviroment |
| 431 | 430 | Link::run_notifies(); |
| 432 | 431 | // unset all objects in $GLOBALS, which are created and used by ExecMethod, as they can contain user-data |
| 433 | - foreach($GLOBALS as $name => $value) |
|
| 432 | + foreach ($GLOBALS as $name => $value) |
|
| 434 | 433 | { |
| 435 | 434 | if ($name !== 'egw' && is_object($value)) unset($GLOBALS[$name]); |
| 436 | 435 | } |
@@ -442,7 +441,7 @@ discard block |
||
| 442 | 441 | { |
| 443 | 442 | $GLOBALS['egw']->session->account_lid = $GLOBALS['egw']->accounts->id2name($job['account_id']); |
| 444 | 443 | $GLOBALS['egw']->session->account_domain = $domain; |
| 445 | - $GLOBALS['egw_info']['user'] = $GLOBALS['egw']->session->read_repositories(); |
|
| 444 | + $GLOBALS['egw_info']['user'] = $GLOBALS['egw']->session->read_repositories(); |
|
| 446 | 445 | |
| 447 | 446 | if ($lang != $GLOBALS['egw_info']['user']['preferences']['common']['lang']) |
| 448 | 447 | { |
@@ -457,12 +456,11 @@ discard block |
||
| 457 | 456 | $GLOBALS['egw_info']['user']['domain'] = $domain; |
| 458 | 457 | } |
| 459 | 458 | } |
| 460 | - list($app) = strpos($job['method'],'::') !== false ? explode('_',$job['method']) : |
|
| 461 | - explode('.',$job['method']); |
|
| 459 | + list($app) = strpos($job['method'], '::') !== false ? explode('_', $job['method']) : explode('.', $job['method']); |
|
| 462 | 460 | Translation::add_app($app); |
| 463 | 461 | if (is_array($job['data'])) |
| 464 | 462 | { |
| 465 | - $job['data'] += array_diff_key($job,array('data' => false)); |
|
| 463 | + $job['data'] += array_diff_key($job, array('data' => false)); |
|
| 466 | 464 | } |
| 467 | 465 | |
| 468 | 466 | if ($this->debug) error_log(__METHOD__."() processing job ".array2string($job)); |
@@ -498,16 +496,16 @@ discard block |
||
| 498 | 496 | try |
| 499 | 497 | { |
| 500 | 498 | if ($this->debug) error_log(__METHOD__."() running job ".array2string($job)); |
| 501 | - ExecMethod($job['method'],$job['data']); |
|
| 499 | + ExecMethod($job['method'], $job['data']); |
|
| 502 | 500 | } |
| 503 | - catch(Exception $e) |
|
| 501 | + catch (Exception $e) |
|
| 504 | 502 | { |
| 505 | 503 | // log the exception to error_log, but continue running other async jobs |
| 506 | 504 | _egw_log_exception($e); |
| 507 | 505 | } |
| 508 | 506 | } |
| 509 | 507 | } |
| 510 | - $this->last_check_run(True,True,$run_by); // release semaphore |
|
| 508 | + $this->last_check_run(True, True, $run_by); // release semaphore |
|
| 511 | 509 | |
| 512 | 510 | return $jobs ? count($jobs) : 0; |
| 513 | 511 | } |
@@ -523,7 +521,7 @@ discard block |
||
| 523 | 521 | * @param int $num_rows =0 number of rows to return if offset set, default 0 = use default in user prefs |
| 524 | 522 | * @return array/boolean db-rows / jobs as array or False if no matches |
| 525 | 523 | */ |
| 526 | - function read($id=0,$cols='*',$offset=False,$append='ORDER BY async_next',$num_rows=0) |
|
| 524 | + function read($id = 0, $cols = '*', $offset = False, $append = 'ORDER BY async_next', $num_rows = 0) |
|
| 527 | 525 | { |
| 528 | 526 | if (!is_a($this->db, 'EGroupware\\Api\\Db')) return false; |
| 529 | 527 | |
@@ -531,7 +529,7 @@ discard block |
||
| 531 | 529 | { |
| 532 | 530 | $where = "async_id != '##last-check-run##'"; |
| 533 | 531 | } |
| 534 | - elseif (!is_array($id) && (strpos($id,'%') !== False || strpos($id,'_') !== False)) |
|
| 532 | + elseif (!is_array($id) && (strpos($id, '%') !== False || strpos($id, '_') !== False)) |
|
| 535 | 533 | { |
| 536 | 534 | $id = $this->db->quote($id); |
| 537 | 535 | $where = "async_id LIKE $id AND async_id != '##last-check-run##'"; |
@@ -545,21 +543,21 @@ discard block |
||
| 545 | 543 | $where = array('async_id' => $id); |
| 546 | 544 | } |
| 547 | 545 | $jobs = array(); |
| 548 | - foreach($this->db->select($this->db_table,$cols,$where,__LINE__,__FILE__,$offset,$append,False,$num_rows) as $row) |
|
| 546 | + foreach ($this->db->select($this->db_table, $cols, $where, __LINE__, __FILE__, $offset, $append, False, $num_rows) as $row) |
|
| 549 | 547 | { |
| 550 | 548 | $row['async_times'] = json_php_unserialize($row['async_times']); |
| 551 | 549 | // check for broken value during migration |
| 552 | 550 | if ($row['async_data'][0] == '"' && substr($row['async_data'], 0, 7) == '"\\"\\\\\\"') |
| 553 | 551 | { |
| 554 | 552 | $row['async_data'] = null; |
| 555 | - $this->write(Db::strip_array_keys($row,'async_'), true); |
|
| 553 | + $this->write(Db::strip_array_keys($row, 'async_'), true); |
|
| 556 | 554 | } |
| 557 | 555 | else |
| 558 | 556 | { |
| 559 | 557 | $row['async_data'] = !empty($row['async_data']) ? |
| 560 | - json_php_unserialize($row['async_data'], true) : null; // allow non-serialized data |
|
| 558 | + json_php_unserialize($row['async_data'], true) : null; // allow non-serialized data |
|
| 561 | 559 | } |
| 562 | - $jobs[$row['async_id']] = Db::strip_array_keys($row,'async_'); |
|
| 560 | + $jobs[$row['async_id']] = Db::strip_array_keys($row, 'async_'); |
|
| 563 | 561 | } |
| 564 | 562 | if (!count($jobs)) |
| 565 | 563 | { |
@@ -576,7 +574,7 @@ discard block |
||
| 576 | 574 | * @param array $where additional where statemetn to update only if a certain condition is met, used for the semaphore |
| 577 | 575 | * @return int affected rows, can be 0 if an additional where statement is given |
| 578 | 576 | */ |
| 579 | - function write($job, $exists = False, $where=array()) |
|
| 577 | + function write($job, $exists = False, $where = array()) |
|
| 580 | 578 | { |
| 581 | 579 | if (!is_a($this->db, 'EGroupware\\Api\\Db')) return 0; |
| 582 | 580 | |
@@ -608,7 +606,7 @@ discard block |
||
| 608 | 606 | function delete($id) |
| 609 | 607 | { |
| 610 | 608 | if ($this->debug) error_log(__METHOD__."('$id') ".function_backtrace()); |
| 611 | - $this->db->delete($this->db_table,array('async_id' => $id),__LINE__,__FILE__); |
|
| 609 | + $this->db->delete($this->db_table, array('async_id' => $id), __LINE__, __FILE__); |
|
| 612 | 610 | |
| 613 | 611 | return $this->db->affected_rows(); |
| 614 | 612 | } |
@@ -633,38 +631,38 @@ discard block |
||
| 633 | 631 | { |
| 634 | 632 | $binarys = array( |
| 635 | 633 | 'php' => '/usr/bin/php', |
| 636 | - 'php5' => '/usr/bin/php5', // SuSE 9.3 with php5 |
|
| 634 | + 'php5' => '/usr/bin/php5', // SuSE 9.3 with php5 |
|
| 637 | 635 | 'crontab' => '/usr/bin/crontab' |
| 638 | 636 | ); |
| 639 | 637 | foreach ($binarys as $name => $path) |
| 640 | 638 | { |
| 641 | - $this->$name = $path; // a reasonable default for *nix |
|
| 639 | + $this->$name = $path; // a reasonable default for *nix |
|
| 642 | 640 | |
| 643 | 641 | if (!($Ok = @is_executable($this->$name))) |
| 644 | 642 | { |
| 645 | 643 | if (file_exists($this->$name)) |
| 646 | 644 | { |
| 647 | - echo '<p>'.lang('%1 is not executable by the webserver !!!',$this->$name)."</p>\n"; |
|
| 645 | + echo '<p>'.lang('%1 is not executable by the webserver !!!', $this->$name)."</p>\n"; |
|
| 648 | 646 | $perms = fileperms($this->$name); |
| 649 | - if (!($perms & 0x0001) && ($perms & 0x0008) && function_exists('posix_getuid')) // only executable by group |
|
| 647 | + if (!($perms&0x0001) && ($perms&0x0008) && function_exists('posix_getuid')) // only executable by group |
|
| 650 | 648 | { |
| 651 | 649 | $group = posix_getgrgid(filegroup($this->$name)); |
| 652 | - $webserver = posix_getpwuid(posix_getuid ()); |
|
| 653 | - echo '<p>'.lang("You need to add the webserver user '%1' to the group '%2'.",$webserver['name'],$group['name'])."</p>\n"; } |
|
| 650 | + $webserver = posix_getpwuid(posix_getuid()); |
|
| 651 | + echo '<p>'.lang("You need to add the webserver user '%1' to the group '%2'.", $webserver['name'], $group['name'])."</p>\n"; } |
|
| 654 | 652 | } |
| 655 | - if (($fd = popen('/bin/sh -c "type -p '.$name.'"','r'))) |
|
| 653 | + if (($fd = popen('/bin/sh -c "type -p '.$name.'"', 'r'))) |
|
| 656 | 654 | { |
| 657 | - $this->$name = fgets($fd,256); |
|
| 655 | + $this->$name = fgets($fd, 256); |
|
| 658 | 656 | @pclose($fd); |
| 659 | 657 | } |
| 660 | - if (($pos = strpos($this->$name,"\n"))) |
|
| 658 | + if (($pos = strpos($this->$name, "\n"))) |
|
| 661 | 659 | { |
| 662 | - $this->$name = substr($this->$name,0,$pos); |
|
| 660 | + $this->$name = substr($this->$name, 0, $pos); |
|
| 663 | 661 | } |
| 664 | 662 | } |
| 665 | 663 | if (!$Ok && !@is_executable($this->$name)) |
| 666 | 664 | { |
| 667 | - $this->$name = $name; // hopefully its in the path |
|
| 665 | + $this->$name = $name; // hopefully its in the path |
|
| 668 | 666 | } |
| 669 | 667 | //echo "<p>$name = '".$this->$name."'</p>\n"; |
| 670 | 668 | } |
@@ -686,7 +684,7 @@ discard block |
||
| 686 | 684 | * |
| 687 | 685 | * @return int |
| 688 | 686 | */ |
| 689 | - function installed(array &$other_cronlines=array()) |
|
| 687 | + function installed(array &$other_cronlines = array()) |
|
| 690 | 688 | { |
| 691 | 689 | if ($this->only_fallback) { |
| 692 | 690 | return 0; |
@@ -700,15 +698,15 @@ discard block |
||
| 700 | 698 | } |
| 701 | 699 | $times = False; |
| 702 | 700 | $other_cronlines = array(); |
| 703 | - if (($crontab = popen('/bin/sh -c "'.$this->crontab.' -l" 2>&1','r')) !== False) |
|
| 701 | + if (($crontab = popen('/bin/sh -c "'.$this->crontab.' -l" 2>&1', 'r')) !== False) |
|
| 704 | 702 | { |
| 705 | 703 | $n = 0; |
| 706 | - while ($line = fgets($crontab,256)) |
|
| 704 | + while ($line = fgets($crontab, 256)) |
|
| 707 | 705 | { |
| 708 | 706 | if ($this->debug) error_log(__METHOD__.'() line '.++$n.": $line"); |
| 709 | - $parts = explode(' ',$line,6); |
|
| 707 | + $parts = explode(' ', $line, 6); |
|
| 710 | 708 | |
| 711 | - if ($line{0} == '#' || count($parts) < 6 || ($parts[5]{0} != '/' && substr($parts[5],0,3) != 'php')) |
|
| 709 | + if ($line{0} == '#' || count($parts) < 6 || ($parts[5]{0} != '/' && substr($parts[5], 0, 3) != 'php')) |
|
| 712 | 710 | { |
| 713 | 711 | // ignore comments |
| 714 | 712 | if ($line{0} != '#') |
@@ -716,12 +714,12 @@ discard block |
||
| 716 | 714 | $times['error'] .= $line; |
| 717 | 715 | } |
| 718 | 716 | } |
| 719 | - elseif (strpos($line,$this->cronline) !== False || |
|
| 717 | + elseif (strpos($line, $this->cronline) !== False || |
|
| 720 | 718 | // also check of old phpgwapi/cron path |
| 721 | 719 | strpos($line, str_replace('/api/', '/phpgwapi/cron/', $this->cronline)) !== False) |
| 722 | 720 | { |
| 723 | - $cron_units = array('min','hour','day','month','dow'); |
|
| 724 | - foreach($cron_units as $n => $u) |
|
| 721 | + $cron_units = array('min', 'hour', 'day', 'month', 'dow'); |
|
| 722 | + foreach ($cron_units as $n => $u) |
|
| 725 | 723 | { |
| 726 | 724 | $times[$u] = $parts[$n]; |
| 727 | 725 | } |
@@ -753,26 +751,26 @@ discard block |
||
| 753 | 751 | return 0; |
| 754 | 752 | } |
| 755 | 753 | $other_cronlines = array(); |
| 756 | - $this->installed($other_cronlines); // find other installed cronlines |
|
| 754 | + $this->installed($other_cronlines); // find other installed cronlines |
|
| 757 | 755 | |
| 758 | - if (($crontab = popen('/bin/sh -c "'.$this->crontab.' -" 2>&1','w')) !== False) |
|
| 756 | + if (($crontab = popen('/bin/sh -c "'.$this->crontab.' -" 2>&1', 'w')) !== False) |
|
| 759 | 757 | { |
| 760 | 758 | foreach ($other_cronlines as $cronline) |
| 761 | 759 | { |
| 762 | - fwrite($crontab,$cronline); // preserv the other lines on install |
|
| 760 | + fwrite($crontab, $cronline); // preserv the other lines on install |
|
| 763 | 761 | } |
| 764 | 762 | if ($times !== False) |
| 765 | 763 | { |
| 766 | - $cron_units = array('min','hour','day','month','dow'); |
|
| 764 | + $cron_units = array('min', 'hour', 'day', 'month', 'dow'); |
|
| 767 | 765 | $cronline = ''; |
| 768 | - foreach($cron_units as $cu) |
|
| 766 | + foreach ($cron_units as $cu) |
|
| 769 | 767 | { |
| 770 | - $cronline .= (isset($times[$cu]) ? $times[$cu] : '*') . ' '; |
|
| 768 | + $cronline .= (isset($times[$cu]) ? $times[$cu] : '*').' '; |
|
| 771 | 769 | } |
| 772 | 770 | // -d memory_limit=-1 --> no memory limit |
| 773 | 771 | $cronline .= $this->php.' -q -d memory_limit=-1 '.$this->cronline."\n"; |
| 774 | 772 | //echo "<p>Installing: '$cronline'</p>\n"; |
| 775 | - fwrite($crontab,$cronline); |
|
| 773 | + fwrite($crontab, $cronline); |
|
| 776 | 774 | } |
| 777 | 775 | @pclose($crontab); |
| 778 | 776 | } |
@@ -95,7 +95,10 @@ discard block |
||
| 95 | 95 | } |
| 96 | 96 | else |
| 97 | 97 | { |
| 98 | - if ($this->debug) error_log(__METHOD__."(".array2string($times).", '$id', '$method', ".array2string($data).", $account_id, $debug, $allow_past) returning FALSE"); |
|
| 98 | + if ($this->debug) |
|
| 99 | + { |
|
| 100 | + error_log(__METHOD__."(".array2string($times).", '$id', '$method', ".array2string($data).", $account_id, $debug, $allow_past) returning FALSE"); |
|
| 101 | + } |
|
| 99 | 102 | return False; |
| 100 | 103 | } |
| 101 | 104 | } |
@@ -113,7 +116,10 @@ discard block |
||
| 113 | 116 | ); |
| 114 | 117 | $this->write($job); |
| 115 | 118 | |
| 116 | - if ($this->debug) error_log(__METHOD__."(".array2string($times).", '$id', '$method', ".array2string($data).", $account_id, $debug, $allow_past) returning TRUE"); |
|
| 119 | + if ($this->debug) |
|
| 120 | + { |
|
| 121 | + error_log(__METHOD__."(".array2string($times).", '$id', '$method', ".array2string($data).", $account_id, $debug, $allow_past) returning TRUE"); |
|
| 122 | + } |
|
| 117 | 123 | return True; |
| 118 | 124 | } |
| 119 | 125 | |
@@ -136,7 +142,8 @@ discard block |
||
| 136 | 142 | error_log(__METHOD__."(".array2string($times).", '$debug', " . date('Y-m-d H:i', $now) . ")"); |
| 137 | 143 | $debug = True; // enable syntax-error messages too |
| 138 | 144 | } |
| 139 | - if(is_null($now)) { |
|
| 145 | + if(is_null($now)) |
|
| 146 | + { |
|
| 140 | 147 | $now = time(); |
| 141 | 148 | } |
| 142 | 149 | |
@@ -201,12 +208,18 @@ discard block |
||
| 201 | 208 | foreach($units as $u => $date_pattern) |
| 202 | 209 | { |
| 203 | 210 | ++$n; |
| 204 | - if ($this->debug) error_log("n=$n, $u: isset(times[$u]=".array2string($times[$u]).")=".(isset($times[$u])?'True':'False')); |
|
| 211 | + if ($this->debug) |
|
| 212 | + { |
|
| 213 | + error_log("n=$n, $u: isset(times[$u]=".array2string($times[$u]).")=".(isset($times[$u])?'True':'False')); |
|
| 214 | + } |
|
| 205 | 215 | if (isset($times[$u])) |
| 206 | 216 | { |
| 207 | - if(is_array($times[$u])) { |
|
| 217 | + if(is_array($times[$u])) |
|
| 218 | + { |
|
| 208 | 219 | $time = array_keys($times[$u]); |
| 209 | - } else { |
|
| 220 | + } |
|
| 221 | + else |
|
| 222 | + { |
|
| 210 | 223 | $time = explode(',',$times[$u]); |
| 211 | 224 | } |
| 212 | 225 | $times[$u] = array(); |
@@ -219,7 +232,10 @@ discard block |
||
| 219 | 232 | |
| 220 | 233 | if (count($arr) != 2 || !is_numeric($min) || !is_numeric($max) || $min > $max) |
| 221 | 234 | { |
| 222 | - if ($debug) error_log("Syntax error in $u='$t', allowed is 'min-max', min <= max, min='$min', max='$max'"); |
|
| 235 | + if ($debug) |
|
| 236 | + { |
|
| 237 | + error_log("Syntax error in $u='$t', allowed is 'min-max', min <= max, min='$min', max='$max'"); |
|
| 238 | + } |
|
| 223 | 239 | |
| 224 | 240 | return False; |
| 225 | 241 | } |
@@ -230,14 +246,20 @@ discard block |
||
| 230 | 246 | } |
| 231 | 247 | else |
| 232 | 248 | { |
| 233 | - if ((string)$t == '*') $t = '*/1'; |
|
| 249 | + if ((string)$t == '*') |
|
| 250 | + { |
|
| 251 | + $t = '*/1'; |
|
| 252 | + } |
|
| 234 | 253 | |
| 235 | 254 | list($one,$inc) = $arr = explode('/',$t); |
| 236 | 255 | |
| 237 | 256 | if (!(is_numeric($one) && count($arr) == 1 || |
| 238 | 257 | count($arr) == 2 && is_numeric($inc))) |
| 239 | 258 | { |
| 240 | - if ($debug) error_log("Syntax error in $u='$t', allowed is a number or '{*|range}/inc', inc='$inc'"); |
|
| 259 | + if ($debug) |
|
| 260 | + { |
|
| 261 | + error_log("Syntax error in $u='$t', allowed is a number or '{*|range}/inc', inc='$inc'"); |
|
| 262 | + } |
|
| 241 | 263 | |
| 242 | 264 | return False; |
| 243 | 265 | } |
@@ -255,7 +277,10 @@ discard block |
||
| 255 | 277 | } |
| 256 | 278 | elseif (count($arr) != 2 || $min > $max) |
| 257 | 279 | { |
| 258 | - if ($debug) error_log("Syntax error in $u='$t', allowed is '{*|min-max}/inc', min='$min',max='$max', inc='$inc'"); |
|
| 280 | + if ($debug) |
|
| 281 | + { |
|
| 282 | + error_log("Syntax error in $u='$t', allowed is '{*|min-max}/inc', min='$min',max='$max', inc='$inc'"); |
|
| 283 | + } |
|
| 259 | 284 | return False; |
| 260 | 285 | } |
| 261 | 286 | for ($i = $min; $i <= $max; $i += $inc) |
@@ -266,9 +291,13 @@ discard block |
||
| 266 | 291 | } |
| 267 | 292 | } |
| 268 | 293 | } |
| 269 | - elseif ($n < $last_set || $u == 'dow') // before last value set (or dow) => empty gets enumerated |
|
| 294 | + elseif ($n < $last_set || $u == 'dow') |
|
| 270 | 295 | { |
| 271 | - for ($i = $min_unit[$u]; $i <= $max_unit[$u]; ++$i) |
|
| 296 | + // before last value set (or dow) => empty gets enumerated |
|
| 297 | + { |
|
| 298 | + for ($i = $min_unit[$u]; |
|
| 299 | + } |
|
| 300 | + $i <= $max_unit[$u]; ++$i) |
|
| 272 | 301 | { |
| 273 | 302 | $times[$u][$i] = True; |
| 274 | 303 | } |
@@ -278,7 +307,10 @@ discard block |
||
| 278 | 307 | $times[$u][$min_unit[$u]] = True; |
| 279 | 308 | } |
| 280 | 309 | } |
| 281 | - if ($this->debug) error_log("enumerated times=".array2string($times)); |
|
| 310 | + if ($this->debug) |
|
| 311 | + { |
|
| 312 | + error_log("enumerated times=".array2string($times)); |
|
| 313 | + } |
|
| 282 | 314 | |
| 283 | 315 | // now we have the times enumerated, lets find the first not expired one |
| 284 | 316 | // |
@@ -296,7 +328,10 @@ discard block |
||
| 296 | 328 | if (isset($found[$u])) |
| 297 | 329 | { |
| 298 | 330 | $future = $future || $found[$u] > $unit_now; |
| 299 | - if ($this->debug) error_log("--> already have a $u = ".$found[$u].", future='$future'"); |
|
| 331 | + if ($this->debug) |
|
| 332 | + { |
|
| 333 | + error_log("--> already have a $u = ".$found[$u].", future='$future'"); |
|
| 334 | + } |
|
| 300 | 335 | continue; // already set |
| 301 | 336 | } |
| 302 | 337 | foreach(array_keys($times[$u]) as $unit_value) |
@@ -314,30 +349,45 @@ discard block |
||
| 314 | 349 | break; |
| 315 | 350 | |
| 316 | 351 | } |
| 317 | - if ($valid && ($u != $next || $unit_value > $over)) // valid and not over |
|
| 352 | + if ($valid && ($u != $next || $unit_value > $over)) |
|
| 353 | + { |
|
| 354 | + // valid and not over |
|
| 318 | 355 | { |
| 319 | 356 | $found[$u] = $unit_value; |
| 357 | + } |
|
| 320 | 358 | $future = $future || $unit_value > $unit_now; |
| 321 | 359 | break; |
| 322 | 360 | } |
| 323 | 361 | } |
| 324 | - if (!isset($found[$u])) // we have to try the next one, if it exists |
|
| 362 | + if (!isset($found[$u])) |
|
| 363 | + { |
|
| 364 | + // we have to try the next one, if it exists |
|
| 325 | 365 | { |
| 326 | 366 | $nexts = array_keys($units); |
| 367 | + } |
|
| 327 | 368 | if (!isset($nexts[count($found)-1])) |
| 328 | 369 | { |
| 329 | - if ($this->debug) error_log("Nothing found, exiting !!!"); |
|
| 370 | + if ($this->debug) |
|
| 371 | + { |
|
| 372 | + error_log("Nothing found, exiting !!!"); |
|
| 373 | + } |
|
| 330 | 374 | return False; |
| 331 | 375 | } |
| 332 | 376 | $next = $nexts[count($found)-1]; |
| 333 | 377 | $over = $found[$next]; |
| 334 | 378 | unset($found[$next]); |
| 335 | - if ($this->debug) error_log("Have to try the next $next, $u's are over for $next=$over !!!"); |
|
| 379 | + if ($this->debug) |
|
| 380 | + { |
|
| 381 | + error_log("Have to try the next $next, $u's are over for $next=$over !!!"); |
|
| 382 | + } |
|
| 336 | 383 | break; |
| 337 | 384 | } |
| 338 | 385 | } |
| 339 | 386 | } |
| 340 | - if ($this->debug) error_log("next=".array2string($found)); |
|
| 387 | + if ($this->debug) |
|
| 388 | + { |
|
| 389 | + error_log("next=".array2string($found)); |
|
| 390 | + } |
|
| 341 | 391 | |
| 342 | 392 | return mktime($found['hour'],$found['min'],0,$found['month'],$found['day'],$found['year']); |
| 343 | 393 | } |
@@ -399,7 +449,10 @@ discard block |
||
| 399 | 449 | ); |
| 400 | 450 | // as the async_next column is used as a semaphore we only update it, |
| 401 | 451 | // if it is 0 (semaphore released) or older then 10min to recover from failed or crashed attempts |
| 402 | - if ($exists) $where = array('(async_next=0 OR async_next<'.(time()-600).')'); |
|
| 452 | + if ($exists) |
|
| 453 | + { |
|
| 454 | + $where = array('(async_next=0 OR async_next<'.(time()-600).')'); |
|
| 455 | + } |
|
| 403 | 456 | } |
| 404 | 457 | //echo "last_run=<pre>"; print_r($last_run); echo "</pre>\n"; |
| 405 | 458 | return $this->write($last_run, !!$exists, $where) > 0; |
@@ -410,7 +463,10 @@ discard block |
||
| 410 | 463 | */ |
| 411 | 464 | function check_run($run_by='') |
| 412 | 465 | { |
| 413 | - if ($run_by === 'fallback') flush(); |
|
| 466 | + if ($run_by === 'fallback') |
|
| 467 | + { |
|
| 468 | + flush(); |
|
| 469 | + } |
|
| 414 | 470 | |
| 415 | 471 | if (!$this->last_check_run(True,False,$run_by)) |
| 416 | 472 | { |
@@ -432,7 +488,10 @@ discard block |
||
| 432 | 488 | // unset all objects in $GLOBALS, which are created and used by ExecMethod, as they can contain user-data |
| 433 | 489 | foreach($GLOBALS as $name => $value) |
| 434 | 490 | { |
| 435 | - if ($name !== 'egw' && is_object($value)) unset($GLOBALS[$name]); |
|
| 491 | + if ($name !== 'egw' && is_object($value)) |
|
| 492 | + { |
|
| 493 | + unset($GLOBALS[$name]); |
|
| 494 | + } |
|
| 436 | 495 | } |
| 437 | 496 | $domain = $GLOBALS['egw_info']['user']['domain']; |
| 438 | 497 | $lang = $GLOBALS['egw_info']['user']['preferences']['common']['lang']; |
@@ -465,24 +524,36 @@ discard block |
||
| 465 | 524 | $job['data'] += array_diff_key($job,array('data' => false)); |
| 466 | 525 | } |
| 467 | 526 | |
| 468 | - if ($this->debug) error_log(__METHOD__."() processing job ".array2string($job)); |
|
| 527 | + if ($this->debug) |
|
| 528 | + { |
|
| 529 | + error_log(__METHOD__."() processing job ".array2string($job)); |
|
| 530 | + } |
|
| 469 | 531 | |
| 470 | 532 | // purge keeped jobs, if they are due |
| 471 | 533 | if (is_array($job['data']) && !empty($job['data']['keep_time'])) |
| 472 | 534 | { |
| 473 | 535 | if ($job['data']['keep_time'] <= time()) |
| 474 | 536 | { |
| 475 | - if ($this->debug) error_log(__METHOD__."() finally deleting job ".array2string($job)); |
|
| 537 | + if ($this->debug) |
|
| 538 | + { |
|
| 539 | + error_log(__METHOD__."() finally deleting job ".array2string($job)); |
|
| 540 | + } |
|
| 476 | 541 | $this->delete($job['id']); |
| 477 | 542 | } |
| 478 | 543 | // fix somehow created async-job with a next time before the keep time, eg. not updated alarm trigger time in the past |
| 479 | 544 | if ($job['next'] < $job['data']['keep_time']) |
| 480 | 545 | { |
| 481 | 546 | $job['next'] = $job['data']['keep_time']; |
| 482 | - if ($this->debug) error_log(__METHOD__."() setting next to keep_time (".date('Y-m-d H:i:s', $job['data']['keep_time']).') for job '.array2string($job)); |
|
| 547 | + if ($this->debug) |
|
| 548 | + { |
|
| 549 | + error_log(__METHOD__."() setting next to keep_time (".date('Y-m-d H:i:s', $job['data']['keep_time']).') for job '.array2string($job)); |
|
| 550 | + } |
|
| 483 | 551 | $this->write($job, True); |
| 484 | 552 | } |
| 485 | - if ($this->debug) error_log(__METHOD__."() keeping job ".array2string($job)); |
|
| 553 | + if ($this->debug) |
|
| 554 | + { |
|
| 555 | + error_log(__METHOD__."() keeping job ".array2string($job)); |
|
| 556 | + } |
|
| 486 | 557 | continue; |
| 487 | 558 | } |
| 488 | 559 | |
@@ -494,7 +565,10 @@ discard block |
||
| 494 | 565 | if (!$job['next']) |
| 495 | 566 | { |
| 496 | 567 | $job['next'] = $job['data']['keep_time'] = time() + ((int)$job['data']['keep'] > 1 ? $job['data']['keep'] : self::DEFAULT_KEEP_TIME); |
| 497 | - if ($this->debug) error_log(__METHOD__."() setting keep_time to ".date('Y-m-d H:i:s', $job['data']['keep_time']).' for job '.array2string($job)); |
|
| 568 | + if ($this->debug) |
|
| 569 | + { |
|
| 570 | + error_log(__METHOD__."() setting keep_time to ".date('Y-m-d H:i:s', $job['data']['keep_time']).' for job '.array2string($job)); |
|
| 571 | + } |
|
| 498 | 572 | } |
| 499 | 573 | $this->write($job, True); |
| 500 | 574 | } |
@@ -504,7 +578,10 @@ discard block |
||
| 504 | 578 | } |
| 505 | 579 | try |
| 506 | 580 | { |
| 507 | - if ($this->debug) error_log(__METHOD__."() running job ".array2string($job)); |
|
| 581 | + if ($this->debug) |
|
| 582 | + { |
|
| 583 | + error_log(__METHOD__."() running job ".array2string($job)); |
|
| 584 | + } |
|
| 508 | 585 | ExecMethod($job['method'],$job['data']); |
| 509 | 586 | } |
| 510 | 587 | catch(Exception $e) |
@@ -532,7 +609,10 @@ discard block |
||
| 532 | 609 | */ |
| 533 | 610 | function read($id=0,$cols='*',$offset=False,$append='ORDER BY async_next',$num_rows=0) |
| 534 | 611 | { |
| 535 | - if (!is_a($this->db, 'EGroupware\\Api\\Db')) return false; |
|
| 612 | + if (!is_a($this->db, 'EGroupware\\Api\\Db')) |
|
| 613 | + { |
|
| 614 | + return false; |
|
| 615 | + } |
|
| 536 | 616 | |
| 537 | 617 | if ($id === '%') |
| 538 | 618 | { |
@@ -585,9 +665,15 @@ discard block |
||
| 585 | 665 | */ |
| 586 | 666 | function write($job, $exists = False, $where=array()) |
| 587 | 667 | { |
| 588 | - if (!is_a($this->db, 'EGroupware\\Api\\Db')) return 0; |
|
| 668 | + if (!is_a($this->db, 'EGroupware\\Api\\Db')) |
|
| 669 | + { |
|
| 670 | + return 0; |
|
| 671 | + } |
|
| 589 | 672 | |
| 590 | - if (is_array($job['data']) && isset($job['data']['next']) && isset($job['next'])) $job['data']['next'] = $job['next']; |
|
| 673 | + if (is_array($job['data']) && isset($job['data']['next']) && isset($job['next'])) |
|
| 674 | + { |
|
| 675 | + $job['data']['next'] = $job['next']; |
|
| 676 | + } |
|
| 591 | 677 | $data = array( |
| 592 | 678 | 'async_next' => $job['next'], |
| 593 | 679 | 'async_times' => json_encode($job['times']), |
@@ -614,7 +700,10 @@ discard block |
||
| 614 | 700 | */ |
| 615 | 701 | function delete($id) |
| 616 | 702 | { |
| 617 | - if ($this->debug) error_log(__METHOD__."('$id') ".function_backtrace()); |
|
| 703 | + if ($this->debug) |
|
| 704 | + { |
|
| 705 | + error_log(__METHOD__."('$id') ".function_backtrace()); |
|
| 706 | + } |
|
| 618 | 707 | $this->db->delete($this->db_table,array('async_id' => $id),__LINE__,__FILE__); |
| 619 | 708 | |
| 620 | 709 | return $this->db->affected_rows(); |
@@ -653,9 +742,12 @@ discard block |
||
| 653 | 742 | { |
| 654 | 743 | echo '<p>'.lang('%1 is not executable by the webserver !!!',$this->$name)."</p>\n"; |
| 655 | 744 | $perms = fileperms($this->$name); |
| 656 | - if (!($perms & 0x0001) && ($perms & 0x0008) && function_exists('posix_getuid')) // only executable by group |
|
| 745 | + if (!($perms & 0x0001) && ($perms & 0x0008) && function_exists('posix_getuid')) |
|
| 746 | + { |
|
| 747 | + // only executable by group |
|
| 657 | 748 | { |
| 658 | 749 | $group = posix_getgrgid(filegroup($this->$name)); |
| 750 | + } |
|
| 659 | 751 | $webserver = posix_getpwuid(posix_getuid ()); |
| 660 | 752 | echo '<p>'.lang("You need to add the webserver user '%1' to the group '%2'.",$webserver['name'],$group['name'])."</p>\n"; } |
| 661 | 753 | } |
@@ -675,10 +767,13 @@ discard block |
||
| 675 | 767 | } |
| 676 | 768 | //echo "<p>$name = '".$this->$name."'</p>\n"; |
| 677 | 769 | } |
| 678 | - if ($this->php5[0] == '/') // we found a php5 binary |
|
| 770 | + if ($this->php5[0] == '/') |
|
| 771 | + { |
|
| 772 | + // we found a php5 binary |
|
| 679 | 773 | { |
| 680 | 774 | $this->php = $this->php5; |
| 681 | 775 | } |
| 776 | + } |
|
| 682 | 777 | } |
| 683 | 778 | } |
| 684 | 779 | |
@@ -695,7 +790,8 @@ discard block |
||
| 695 | 790 | */ |
| 696 | 791 | function installed(array &$other_cronlines=array()) |
| 697 | 792 | { |
| 698 | - if ($this->only_fallback) { |
|
| 793 | + if ($this->only_fallback) |
|
| 794 | + { |
|
| 699 | 795 | return 0; |
| 700 | 796 | } |
| 701 | 797 | $this->find_binarys(); |
@@ -712,7 +808,10 @@ discard block |
||
| 712 | 808 | $n = 0; |
| 713 | 809 | while ($line = fgets($crontab,256)) |
| 714 | 810 | { |
| 715 | - if ($this->debug) error_log(__METHOD__.'() line '.++$n.": $line"); |
|
| 811 | + if ($this->debug) |
|
| 812 | + { |
|
| 813 | + error_log(__METHOD__.'() line '.++$n.": $line"); |
|
| 814 | + } |
|
| 716 | 815 | $parts = explode(' ',$line,6); |
| 717 | 816 | |
| 718 | 817 | if ($line{0} == '#' || count($parts) < 6 || ($parts[5]{0} != '/' && substr($parts[5],0,3) != 'php')) |
@@ -756,7 +855,8 @@ discard block |
||
| 756 | 855 | */ |
| 757 | 856 | function install($times) |
| 758 | 857 | { |
| 759 | - if ($this->only_fallback && $times !== False) { |
|
| 858 | + if ($this->only_fallback && $times !== False) |
|
| 859 | + { |
|
| 760 | 860 | return 0; |
| 761 | 861 | } |
| 762 | 862 | $other_cronlines = array(); |
@@ -84,8 +84,8 @@ discard block |
||
| 84 | 84 | * check if users are supposed to change their password every x sdays, then check if password is of old age |
| 85 | 85 | * or the devil-admin reset the users password and forced the user to change his password on next login. |
| 86 | 86 | * |
| 87 | - * @param string& $message =null on return false: message why password needs to be changed |
|
| 88 | - * @return boolean true: all good, false: password change required, null: password expires in N days |
|
| 87 | + * @param string $message =null on return false: message why password needs to be changed |
|
| 88 | + * @return boolean|null true: all good, false: password change required, null: password expires in N days |
|
| 89 | 89 | */ |
| 90 | 90 | static function check_password_change(&$message=null) |
| 91 | 91 | { |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | * |
| 295 | 295 | * uses the encryption type set in setup and calls the appropriate encryption functions |
| 296 | 296 | * |
| 297 | - * @param $password password to encrypt |
|
| 297 | + * @param string $password password to encrypt |
|
| 298 | 298 | */ |
| 299 | 299 | static function encrypt_password($password,$sql=False) |
| 300 | 300 | { |
@@ -406,6 +406,7 @@ discard block |
||
| 406 | 406 | * @param string $form_val user input value for comparison |
| 407 | 407 | * @param string $db_val stored value / hash (from database) |
| 408 | 408 | * @param string &$type detected crypt type on return |
| 409 | + * @param string $type |
|
| 409 | 410 | * @return boolean True on successful comparison |
| 410 | 411 | */ |
| 411 | 412 | static function crypt_compare($form_val, $db_val, &$type) |
@@ -618,7 +619,7 @@ discard block |
||
| 618 | 619 | * @param string $forbid_name =null if "yes" username or full-name split by delimiters AND longer then 3 chars are |
| 619 | 620 | * forbidden to be included in password, default to whatever set in config for "passwd_forbid_name" |
| 620 | 621 | * @param array|int $account =null array with account_lid and account_fullname or account_id for $forbid_name check |
| 621 | - * @return mixed false if password is considered "safe" (or no requirements) or a string $message if "unsafe" |
|
| 622 | + * @return string|false false if password is considered "safe" (or no requirements) or a string $message if "unsafe" |
|
| 622 | 623 | */ |
| 623 | 624 | static function crackcheck($passwd, $reqstrength=null, $minlength=null, $forbid_name=null, $account=null) |
| 624 | 625 | { |
@@ -407,7 +407,7 @@ discard block |
||
| 407 | 407 | * @param string $db_val stored value / hash (from database) |
| 408 | 408 | * @param string &$type detected crypt type on return |
| 409 | 409 | * @return boolean True on successful comparison |
| 410 | - */ |
|
| 410 | + */ |
|
| 411 | 411 | static function crypt_compare($form_val, $db_val, &$type) |
| 412 | 412 | { |
| 413 | 413 | // detect type of hash by salt part of $db_val |
@@ -706,7 +706,7 @@ discard block |
||
| 706 | 706 | * @param string $form_val user input value for comparison |
| 707 | 707 | * @param string $db_val stored value (from database) |
| 708 | 708 | * @return boolean True on successful comparison |
| 709 | - */ |
|
| 709 | + */ |
|
| 710 | 710 | static function smd5_compare($form_val,$db_val) |
| 711 | 711 | { |
| 712 | 712 | /* Start with the first char after {SMD5} */ |
@@ -728,7 +728,7 @@ discard block |
||
| 728 | 728 | * @param string $form_val user input value for comparison |
| 729 | 729 | * @param string $db_val stored value (from database) |
| 730 | 730 | * @return boolean True on successful comparison |
| 731 | - */ |
|
| 731 | + */ |
|
| 732 | 732 | static function sha_compare($form_val,$db_val) |
| 733 | 733 | { |
| 734 | 734 | /* Start with the first char after {SHA} */ |
@@ -745,7 +745,7 @@ discard block |
||
| 745 | 745 | * @param string $form_val user input value for comparison |
| 746 | 746 | * @param string $db_val stored value (from database) |
| 747 | 747 | * @return boolean True on successful comparison |
| 748 | - */ |
|
| 748 | + */ |
|
| 749 | 749 | static function ssha_compare($form_val,$db_val) |
| 750 | 750 | { |
| 751 | 751 | /* Start with the first char after {SSHA} */ |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | { |
| 21 | 21 | $GLOBALS['egw_info']['server']['auth_type'] = $GLOBALS['egw_info']['server']['auth_type_'.$GLOBALS['egw_info']['flags']['currentapp']]; |
| 22 | 22 | } |
| 23 | -if(empty($GLOBALS['egw_info']['server']['auth_type'])) |
|
| 23 | +if (empty($GLOBALS['egw_info']['server']['auth_type'])) |
|
| 24 | 24 | { |
| 25 | 25 | $GLOBALS['egw_info']['server']['auth_type'] = 'sql'; |
| 26 | 26 | } |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | * |
| 66 | 66 | * @param Backend $type =null |
| 67 | 67 | */ |
| 68 | - static function backend($type=null) |
|
| 68 | + static function backend($type = null) |
|
| 69 | 69 | { |
| 70 | 70 | if (is_null($type)) $type = $GLOBALS['egw_info']['server']['auth_type']; |
| 71 | 71 | |
@@ -92,29 +92,29 @@ discard block |
||
| 92 | 92 | * @param string& $message =null on return false: message why password needs to be changed |
| 93 | 93 | * @return boolean true: all good, false: password change required, null: password expires in N days |
| 94 | 94 | */ |
| 95 | - static function check_password_change(&$message=null) |
|
| 95 | + static function check_password_change(&$message = null) |
|
| 96 | 96 | { |
| 97 | 97 | // dont check anything for anonymous sessions/ users that are flagged as anonymous |
| 98 | 98 | if (is_object($GLOBALS['egw']->session) && $GLOBALS['egw']->session->session_flags == 'A') return true; |
| 99 | 99 | |
| 100 | 100 | // some statics (and initialisation to make information and timecalculation a) more readable in conditions b) persistent per request |
| 101 | 101 | // if user has to be warned about an upcomming passwordchange, remember for the session, that he was informed |
| 102 | - static $UserKnowsAboutPwdChange=null; |
|
| 103 | - if (is_null($UserKnowsAboutPwdChange)) $UserKnowsAboutPwdChange =& Cache::getSession('phpgwapi','auth_UserKnowsAboutPwdChange'); |
|
| 102 | + static $UserKnowsAboutPwdChange = null; |
|
| 103 | + if (is_null($UserKnowsAboutPwdChange)) $UserKnowsAboutPwdChange = & Cache::getSession('phpgwapi', 'auth_UserKnowsAboutPwdChange'); |
|
| 104 | 104 | |
| 105 | 105 | // retrieve the timestamp regarding the last change of the password from auth system and store it with the session |
| 106 | - static $alpwchange_val=null; |
|
| 107 | - static $pwdTsChecked=null; |
|
| 106 | + static $alpwchange_val = null; |
|
| 107 | + static $pwdTsChecked = null; |
|
| 108 | 108 | if (is_null($pwdTsChecked) && is_null($alpwchange_val) || (string)$alpwchange_val === '0') |
| 109 | 109 | { |
| 110 | - $alpwchange_val =& Cache::getSession('phpgwapi','auth_alpwchange_val'); // set that one with the session stored value |
|
| 110 | + $alpwchange_val = & Cache::getSession('phpgwapi', 'auth_alpwchange_val'); // set that one with the session stored value |
|
| 111 | 111 | // initalize statics - better readability of conditions |
| 112 | 112 | if (is_null($alpwchange_val) || (string)$alpwchange_val === '0') |
| 113 | 113 | { |
| 114 | 114 | $backend = self::backend(); |
| 115 | 115 | // this may change behavior, as it should detect forced PasswordChanges from your Authentication System too. |
| 116 | 116 | // on the other side, if your auth system does not require an forcedPasswordChange, you will not be asked. |
| 117 | - if (method_exists($backend,'getLastPwdChange')) |
|
| 117 | + if (method_exists($backend, 'getLastPwdChange')) |
|
| 118 | 118 | { |
| 119 | 119 | $alpwchange_val = $backend->getLastPwdChange($GLOBALS['egw']->session->account_lid); |
| 120 | 120 | $pwdTsChecked = true; |
@@ -128,8 +128,8 @@ discard block |
||
| 128 | 128 | //error_log(__METHOD__.__LINE__.'#'.$alpwchange_val.'# is null:'.is_null($alpwchange_val).'# is empty:'.empty($alpwchange_val).'# is set:'.isset($alpwchange_val)); |
| 129 | 129 | } |
| 130 | 130 | } |
| 131 | - static $passwordAgeBorder=null; |
|
| 132 | - static $daysLeftUntilChangeReq=null; |
|
| 131 | + static $passwordAgeBorder = null; |
|
| 132 | + static $daysLeftUntilChangeReq = null; |
|
| 133 | 133 | |
| 134 | 134 | // if neither timestamp isset return true, nothing to do (exept this means the password is too old) |
| 135 | 135 | if (is_null($alpwchange_val) && |
@@ -139,15 +139,15 @@ discard block |
||
| 139 | 139 | } |
| 140 | 140 | if (is_null($passwordAgeBorder) && $GLOBALS['egw_info']['server']['change_pwd_every_x_days']) |
| 141 | 141 | { |
| 142 | - $passwordAgeBorder = (DateTime::to('now','ts')-($GLOBALS['egw_info']['server']['change_pwd_every_x_days']*86400)); |
|
| 142 | + $passwordAgeBorder = (DateTime::to('now', 'ts') - ($GLOBALS['egw_info']['server']['change_pwd_every_x_days'] * 86400)); |
|
| 143 | 143 | } |
| 144 | 144 | if (is_null($daysLeftUntilChangeReq) && $GLOBALS['egw_info']['server']['warn_about_upcoming_pwd_change']) |
| 145 | 145 | { |
| 146 | 146 | // maxage - passwordage = days left until change is required |
| 147 | - $daysLeftUntilChangeReq = ($GLOBALS['egw_info']['server']['change_pwd_every_x_days'] - ((DateTime::to('now','ts')-($alpwchange_val?$alpwchange_val:0))/86400)); |
|
| 147 | + $daysLeftUntilChangeReq = ($GLOBALS['egw_info']['server']['change_pwd_every_x_days'] - ((DateTime::to('now', 'ts') - ($alpwchange_val ? $alpwchange_val : 0)) / 86400)); |
|
| 148 | 148 | } |
| 149 | - if ($alpwchange_val == 0 || // admin requested password change |
|
| 150 | - $passwordAgeBorder > $alpwchange_val || // change password every N days policy requests change |
|
| 149 | + if ($alpwchange_val == 0 || // admin requested password change |
|
| 150 | + $passwordAgeBorder > $alpwchange_val || // change password every N days policy requests change |
|
| 151 | 151 | // user should be warned N days in advance about change and is not yet |
| 152 | 152 | $GLOBALS['egw_info']['server']['change_pwd_every_x_days'] && |
| 153 | 153 | $GLOBALS['egw_info']['user']['apps']['preferences'] && |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | error_log(__METHOD__.' Password of '.$GLOBALS['egw_info']['user']['account_lid'].' ('.$GLOBALS['egw_info']['user']['account_fullname'].') is of old age.'.array2string(array( |
| 165 | 165 | 'ts'=> $alpwchange_val, |
| 166 | 166 | 'date'=>DateTime::to($alpwchange_val)))); |
| 167 | - $message = lang('It has been more then %1 days since you changed your password',$GLOBALS['egw_info']['server']['change_pwd_every_x_days']); |
|
| 167 | + $message = lang('It has been more then %1 days since you changed your password', $GLOBALS['egw_info']['server']['change_pwd_every_x_days']); |
|
| 168 | 168 | } |
| 169 | 169 | else |
| 170 | 170 | { |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | { |
| 176 | 176 | $UserKnowsAboutPwdChange = true; |
| 177 | 177 | } |
| 178 | - $message = lang('Your password is about to expire in %1 days, you may change your password now',round($daysLeftUntilChangeReq)); |
|
| 178 | + $message = lang('Your password is about to expire in %1 days, you may change your password now', round($daysLeftUntilChangeReq)); |
|
| 179 | 179 | // user has no rights to change password --> do NOT warn, as only forced check ignores rights |
| 180 | 180 | if ($GLOBALS['egw']->acl->check('nopasswordchange', 1, 'preferences')) return true; |
| 181 | 181 | return null; |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | */ |
| 194 | 194 | function getLastPwdChange($username) |
| 195 | 195 | { |
| 196 | - if (method_exists($this->backend,'getLastPwdChange')) |
|
| 196 | + if (method_exists($this->backend, 'getLastPwdChange')) |
|
| 197 | 197 | { |
| 198 | 198 | return $this->backend->getLastPwdChange($username); |
| 199 | 199 | } |
@@ -208,9 +208,9 @@ discard block |
||
| 208 | 208 | * @param int $lastpwdchange must be a unixtimestamp |
| 209 | 209 | * @return boolean true if account_lastpwd_change successful changed, false otherwise |
| 210 | 210 | */ |
| 211 | - function setLastPwdChange($account_id=0, $passwd=NULL, $lastpwdchange=NULL) |
|
| 211 | + function setLastPwdChange($account_id = 0, $passwd = NULL, $lastpwdchange = NULL) |
|
| 212 | 212 | { |
| 213 | - if (method_exists($this->backend,'setLastPwdChange')) |
|
| 213 | + if (method_exists($this->backend, 'setLastPwdChange')) |
|
| 214 | 214 | { |
| 215 | 215 | return $this->backend->setLastPwdChange($account_id, $passwd, $lastpwdchange); |
| 216 | 216 | } |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | * @param string $passwd_type ='text' 'text' for cleartext passwords (default) |
| 226 | 226 | * @return boolean true if successful authenticated, false otherwise |
| 227 | 227 | */ |
| 228 | - function authenticate($username, $passwd, $passwd_type='text') |
|
| 228 | + function authenticate($username, $passwd, $passwd_type = 'text') |
|
| 229 | 229 | { |
| 230 | 230 | return $this->backend->authenticate($username, $passwd, $passwd_type); |
| 231 | 231 | } |
@@ -240,9 +240,9 @@ discard block |
||
| 240 | 240 | * @throws Exception from backends having extra requirements |
| 241 | 241 | * @return boolean true if password successful changed, false otherwise |
| 242 | 242 | */ |
| 243 | - function change_password($old_passwd, $new_passwd, $account_id=0) |
|
| 243 | + function change_password($old_passwd, $new_passwd, $account_id = 0) |
|
| 244 | 244 | { |
| 245 | - if (($err = self::crackcheck($new_passwd,null,null,null,$account_id))) |
|
| 245 | + if (($err = self::crackcheck($new_passwd, null, null, null, $account_id))) |
|
| 246 | 246 | { |
| 247 | 247 | throw new Exception\WrongUserinput($err); |
| 248 | 248 | } |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | // need to change current users password in session |
| 254 | 254 | Cache::setSession('phpgwapi', 'password', base64_encode($new_passwd)); |
| 255 | 255 | $GLOBALS['egw_info']['user']['passwd'] = $new_passwd; |
| 256 | - $GLOBALS['egw_info']['user']['account_lastpwd_change'] = DateTime::to('now','ts'); |
|
| 256 | + $GLOBALS['egw_info']['user']['account_lastpwd_change'] = DateTime::to('now', 'ts'); |
|
| 257 | 257 | // invalidate EGroupware session, as password is stored in egw_info in session |
| 258 | 258 | Egw::invalidate_session_cache(); |
| 259 | 259 | } |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | * @param string $new_passwd =null new password, default session password |
| 274 | 274 | * @param int $account_id =null account_id, default current user |
| 275 | 275 | */ |
| 276 | - static function changepwd($old_passwd, $new_passwd=null, $account_id=null) |
|
| 276 | + static function changepwd($old_passwd, $new_passwd = null, $account_id = null) |
|
| 277 | 277 | { |
| 278 | 278 | if (!isset($account_id)) $account_id = $GLOBALS['egw']->session->account_id; |
| 279 | 279 | if (!isset($new_passwd)) $new_passwd = $GLOBALS['egw']->session->passwd; |
@@ -285,9 +285,9 @@ discard block |
||
| 285 | 285 | 'old_passwd' => $old_passwd, |
| 286 | 286 | 'new_passwd' => $new_passwd, |
| 287 | 287 | ); |
| 288 | - Hooks::process($GLOBALS['hook_values']+array( |
|
| 288 | + Hooks::process($GLOBALS['hook_values'] + array( |
|
| 289 | 289 | 'location' => 'changepassword' |
| 290 | - ),False,True); // called for every app now, not only enabled ones) |
|
| 290 | + ), False, True); // called for every app now, not only enabled ones) |
|
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | /** |
@@ -295,13 +295,13 @@ discard block |
||
| 295 | 295 | * |
| 296 | 296 | * @param $size int-size of random string to return |
| 297 | 297 | */ |
| 298 | - static function randomstring($size, $use_specialchars=false) |
|
| 298 | + static function randomstring($size, $use_specialchars = false) |
|
| 299 | 299 | { |
| 300 | 300 | $random_char = array( |
| 301 | - '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f', |
|
| 302 | - 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v', |
|
| 303 | - 'w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L', |
|
| 304 | - 'M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' |
|
| 301 | + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', |
|
| 302 | + 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', |
|
| 303 | + 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', |
|
| 304 | + 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' |
|
| 305 | 305 | ); |
| 306 | 306 | |
| 307 | 307 | // we need special chars |
@@ -314,9 +314,9 @@ discard block |
||
| 314 | 314 | $func = function_exists('random_int') ? 'random_int' : 'mt_rand'; |
| 315 | 315 | |
| 316 | 316 | $s = ''; |
| 317 | - for ($i=0; $i < $size; $i++) |
|
| 317 | + for ($i = 0; $i < $size; $i++) |
|
| 318 | 318 | { |
| 319 | - $s .= $random_char[$func(0, count($random_char)-1)]; |
|
| 319 | + $s .= $random_char[$func(0, count($random_char) - 1)]; |
|
| 320 | 320 | } |
| 321 | 321 | return $s; |
| 322 | 322 | } |
@@ -328,9 +328,9 @@ discard block |
||
| 328 | 328 | * |
| 329 | 329 | * @param $password password to encrypt |
| 330 | 330 | */ |
| 331 | - static function encrypt_password($password,$sql=False) |
|
| 331 | + static function encrypt_password($password, $sql = False) |
|
| 332 | 332 | { |
| 333 | - if($sql) |
|
| 333 | + if ($sql) |
|
| 334 | 334 | { |
| 335 | 335 | return self::encrypt_sql($password); |
| 336 | 336 | } |
@@ -349,21 +349,21 @@ discard block |
||
| 349 | 349 | * @param string &$type =null on return detected type of hash |
| 350 | 350 | * @return boolean |
| 351 | 351 | */ |
| 352 | - static function compare_password($cleartext, $encrypted, $type_in, $username='', &$type=null) |
|
| 352 | + static function compare_password($cleartext, $encrypted, $type_in, $username = '', &$type = null) |
|
| 353 | 353 | { |
| 354 | 354 | // allow to specify the hash type to prefix the hash, to easy migrate passwords from ldap |
| 355 | 355 | $type = $type_in; |
| 356 | 356 | $saved_enc = $encrypted; |
| 357 | 357 | $matches = null; |
| 358 | - if (preg_match('/^\\{([a-z_5]+)\\}(.+)$/i',$encrypted,$matches)) |
|
| 358 | + if (preg_match('/^\\{([a-z_5]+)\\}(.+)$/i', $encrypted, $matches)) |
|
| 359 | 359 | { |
| 360 | 360 | $type = strtolower($matches[1]); |
| 361 | 361 | $encrypted = $matches[2]; |
| 362 | 362 | |
| 363 | - switch($type) // some hashs are specially "packed" in ldap |
|
| 363 | + switch ($type) // some hashs are specially "packed" in ldap |
|
| 364 | 364 | { |
| 365 | 365 | case 'md5': |
| 366 | - $encrypted = implode('',unpack('H*',base64_decode($encrypted))); |
|
| 366 | + $encrypted = implode('', unpack('H*', base64_decode($encrypted))); |
|
| 367 | 367 | break; |
| 368 | 368 | case 'plain': |
| 369 | 369 | case 'crypt': |
@@ -374,24 +374,24 @@ discard block |
||
| 374 | 374 | break; |
| 375 | 375 | } |
| 376 | 376 | } |
| 377 | - elseif($encrypted[0] == '$') |
|
| 377 | + elseif ($encrypted[0] == '$') |
|
| 378 | 378 | { |
| 379 | 379 | $type = 'crypt'; |
| 380 | 380 | } |
| 381 | 381 | |
| 382 | - switch($type) |
|
| 382 | + switch ($type) |
|
| 383 | 383 | { |
| 384 | 384 | case 'plain': |
| 385 | 385 | $ret = $cleartext === $encrypted; |
| 386 | 386 | break; |
| 387 | 387 | case 'smd5': |
| 388 | - $ret = self::smd5_compare($cleartext,$encrypted); |
|
| 388 | + $ret = self::smd5_compare($cleartext, $encrypted); |
|
| 389 | 389 | break; |
| 390 | 390 | case 'sha': |
| 391 | - $ret = self::sha_compare($cleartext,$encrypted); |
|
| 391 | + $ret = self::sha_compare($cleartext, $encrypted); |
|
| 392 | 392 | break; |
| 393 | 393 | case 'ssha': |
| 394 | - $ret = self::ssha_compare($cleartext,$encrypted); |
|
| 394 | + $ret = self::ssha_compare($cleartext, $encrypted); |
|
| 395 | 395 | break; |
| 396 | 396 | case 'crypt': |
| 397 | 397 | case 'des': |
@@ -404,7 +404,7 @@ discard block |
||
| 404 | 404 | $ret = self::crypt_compare($cleartext, $encrypted, $type); |
| 405 | 405 | break; |
| 406 | 406 | case 'md5_hmac': |
| 407 | - $ret = self::md5_hmac_compare($cleartext,$encrypted,$username); |
|
| 407 | + $ret = self::md5_hmac_compare($cleartext, $encrypted, $username); |
|
| 408 | 408 | break; |
| 409 | 409 | default: |
| 410 | 410 | $type = 'md5'; |
@@ -427,9 +427,9 @@ discard block |
||
| 427 | 427 | 'ext_crypt' => array('CRYPT_EXT_DES', '_J9..', 4, ''), |
| 428 | 428 | 'md5_crypt' => array('CRYPT_MD5', '$1$', 8, '$'), |
| 429 | 429 | //'old_blowfish_crypt' => array('CRYPT_BLOWFISH', '$2$', 13, ''), // old blowfish hash not in line with php.net docu, but could be in use |
| 430 | - 'blowfish_crypt' => array('CRYPT_BLOWFISH', '$2a$12$', 22, ''), // $2a$12$ = 2^12 = 4096 rounds |
|
| 431 | - 'sha256_crypt' => array('CRYPT_SHA256', '$5$', 16, '$'), // no "round=N$" --> default of 5000 rounds |
|
| 432 | - 'sha512_crypt' => array('CRYPT_SHA512', '$6$', 16, '$'), // no "round=N$" --> default of 5000 rounds |
|
| 430 | + 'blowfish_crypt' => array('CRYPT_BLOWFISH', '$2a$12$', 22, ''), // $2a$12$ = 2^12 = 4096 rounds |
|
| 431 | + 'sha256_crypt' => array('CRYPT_SHA256', '$5$', 16, '$'), // no "round=N$" --> default of 5000 rounds |
|
| 432 | + 'sha512_crypt' => array('CRYPT_SHA512', '$6$', 16, '$'), // no "round=N$" --> default of 5000 rounds |
|
| 433 | 433 | ); |
| 434 | 434 | |
| 435 | 435 | /** |
@@ -444,17 +444,17 @@ discard block |
||
| 444 | 444 | { |
| 445 | 445 | // detect type of hash by salt part of $db_val |
| 446 | 446 | list($first, $dollar, $salt, $salt2) = explode('$', $db_val); |
| 447 | - foreach(self::$crypt_params as $type => $params) |
|
| 447 | + foreach (self::$crypt_params as $type => $params) |
|
| 448 | 448 | { |
| 449 | 449 | list(,$prefix, $random, $postfix) = $params; |
| 450 | 450 | list(,$d) = explode('$', $prefix); |
| 451 | 451 | if ($dollar === $d || !$dollar && ($first[0] === $prefix[0] || $first[0] !== '_' && !$prefix)) |
| 452 | 452 | { |
| 453 | - $len = !$postfix ? strlen($prefix)+$random : strlen($prefix.$salt.$postfix); |
|
| 453 | + $len = !$postfix ? strlen($prefix) + $random : strlen($prefix.$salt.$postfix); |
|
| 454 | 454 | // sha(256|512) might contain options, explicit $rounds=N$ prefix in salt |
| 455 | 455 | if (($type == 'sha256_crypt' || $type == 'sha512_crypt') && substr($salt, 0, 7) === 'rounds=') |
| 456 | 456 | { |
| 457 | - $len += strlen($salt2)+1; |
|
| 457 | + $len += strlen($salt2) + 1; |
|
| 458 | 458 | } |
| 459 | 459 | break; |
| 460 | 460 | } |
@@ -476,12 +476,12 @@ discard block |
||
| 476 | 476 | * @param string $type =null default to $GLOBALS['egw_info']['server']['ldap_encryption_type'] |
| 477 | 477 | * @return string |
| 478 | 478 | */ |
| 479 | - static function encrypt_ldap($password, $type=null) |
|
| 479 | + static function encrypt_ldap($password, $type = null) |
|
| 480 | 480 | { |
| 481 | 481 | if (is_null($type)) $type = $GLOBALS['egw_info']['server']['ldap_encryption_type']; |
| 482 | 482 | |
| 483 | 483 | $salt = ''; |
| 484 | - switch(strtolower($type)) |
|
| 484 | + switch (strtolower($type)) |
|
| 485 | 485 | { |
| 486 | 486 | default: // eg. setup >> config never saved |
| 487 | 487 | case 'des': |
@@ -495,7 +495,7 @@ discard block |
||
| 495 | 495 | case 'md5_crypt': |
| 496 | 496 | case 'ext_crypt': |
| 497 | 497 | list($const, $prefix, $len, $postfix) = self::$crypt_params[$type]; |
| 498 | - if(defined($const) && constant($const) == 1) |
|
| 498 | + if (defined($const) && constant($const) == 1) |
|
| 499 | 499 | { |
| 500 | 500 | $salt = $prefix.self::randomstring($len).$postfix; |
| 501 | 501 | $e_password = '{crypt}'.crypt($password, $salt); |
@@ -508,20 +508,20 @@ discard block |
||
| 508 | 508 | /* New method taken from the openldap-software list as recommended by |
| 509 | 509 | * Kervin L. Pierre" <[email protected]> |
| 510 | 510 | */ |
| 511 | - $e_password = '{md5}' . base64_encode(pack("H*",md5($password))); |
|
| 511 | + $e_password = '{md5}'.base64_encode(pack("H*", md5($password))); |
|
| 512 | 512 | break; |
| 513 | 513 | case 'smd5': |
| 514 | 514 | $salt = self::randomstring(16); |
| 515 | - $hash = md5($password . $salt, true); |
|
| 516 | - $e_password = '{SMD5}' . base64_encode($hash . $salt); |
|
| 515 | + $hash = md5($password.$salt, true); |
|
| 516 | + $e_password = '{SMD5}'.base64_encode($hash.$salt); |
|
| 517 | 517 | break; |
| 518 | 518 | case 'sha': |
| 519 | - $e_password = '{SHA}' . base64_encode(sha1($password,true)); |
|
| 519 | + $e_password = '{SHA}'.base64_encode(sha1($password, true)); |
|
| 520 | 520 | break; |
| 521 | 521 | case 'ssha': |
| 522 | 522 | $salt = self::randomstring(16); |
| 523 | - $hash = sha1($password . $salt, true); |
|
| 524 | - $e_password = '{SSHA}' . base64_encode($hash . $salt); |
|
| 523 | + $hash = sha1($password.$salt, true); |
|
| 524 | + $e_password = '{SSHA}'.base64_encode($hash.$salt); |
|
| 525 | 525 | break; |
| 526 | 526 | case 'plain': |
| 527 | 527 | // if plain no type is prepended |
@@ -539,7 +539,7 @@ discard block |
||
| 539 | 539 | * @param string $type =null default $GLOBALS['egw_info']['server']['sql_encryption_type'], if valid otherwise blowfish_crypt |
| 540 | 540 | * @return string hash |
| 541 | 541 | */ |
| 542 | - static function encrypt_sql($password, $type=null) |
|
| 542 | + static function encrypt_sql($password, $type = null) |
|
| 543 | 543 | { |
| 544 | 544 | /* Grab configured type, or default to md5() (old method) */ |
| 545 | 545 | if (is_null($type)) |
@@ -547,7 +547,7 @@ discard block |
||
| 547 | 547 | $type = @$GLOBALS['egw_info']['server']['sql_encryption_type'] ? |
| 548 | 548 | strtolower($GLOBALS['egw_info']['server']['sql_encryption_type']) : 'md5'; |
| 549 | 549 | } |
| 550 | - switch($type) |
|
| 550 | + switch ($type) |
|
| 551 | 551 | { |
| 552 | 552 | case 'plain': |
| 553 | 553 | // since md5 is the default, type plain must be prepended, for eGroupware to understand |
@@ -587,28 +587,28 @@ discard block |
||
| 587 | 587 | * @param string &$securest =null on return securest available hash |
| 588 | 588 | * @return array hash => label |
| 589 | 589 | */ |
| 590 | - public static function passwdhashes(&$securest=null) |
|
| 590 | + public static function passwdhashes(&$securest = null) |
|
| 591 | 591 | { |
| 592 | 592 | $hashes = array(); |
| 593 | 593 | |
| 594 | 594 | /* Check for available crypt methods based on what is defined by php */ |
| 595 | - if(defined('CRYPT_BLOWFISH') && CRYPT_BLOWFISH == 1) |
|
| 595 | + if (defined('CRYPT_BLOWFISH') && CRYPT_BLOWFISH == 1) |
|
| 596 | 596 | { |
| 597 | 597 | $hashes['blowfish_crypt'] = 'blowfish_crypt'; |
| 598 | 598 | } |
| 599 | - if(defined('CRYPT_SHA512') && CRYPT_SHA512 == 1) |
|
| 599 | + if (defined('CRYPT_SHA512') && CRYPT_SHA512 == 1) |
|
| 600 | 600 | { |
| 601 | 601 | $hashes['sha512_crypt'] = 'sha512_crypt'; |
| 602 | 602 | } |
| 603 | - if(defined('CRYPT_SHA256') && CRYPT_SHA256 == 1) |
|
| 603 | + if (defined('CRYPT_SHA256') && CRYPT_SHA256 == 1) |
|
| 604 | 604 | { |
| 605 | 605 | $hashes['sha256_crypt'] = 'sha256_crypt'; |
| 606 | 606 | } |
| 607 | - if(defined('CRYPT_MD5') && CRYPT_MD5 == 1) |
|
| 607 | + if (defined('CRYPT_MD5') && CRYPT_MD5 == 1) |
|
| 608 | 608 | { |
| 609 | 609 | $hashes['md5_crypt'] = 'md5_crypt'; |
| 610 | 610 | } |
| 611 | - if(defined('CRYPT_EXT_DES') && CRYPT_EXT_DES == 1) |
|
| 611 | + if (defined('CRYPT_EXT_DES') && CRYPT_EXT_DES == 1) |
|
| 612 | 612 | { |
| 613 | 613 | $hashes['ext_crypt'] = 'ext_crypt'; |
| 614 | 614 | } |
@@ -617,7 +617,7 @@ discard block |
||
| 617 | 617 | 'smd5' => 'smd5', |
| 618 | 618 | 'sha' => 'sha', |
| 619 | 619 | ); |
| 620 | - if(@defined('CRYPT_STD_DES') && CRYPT_STD_DES == 1) |
|
| 620 | + if (@defined('CRYPT_STD_DES') && CRYPT_STD_DES == 1) |
|
| 621 | 621 | { |
| 622 | 622 | $hashes['crypt'] = 'crypt'; |
| 623 | 623 | } |
@@ -650,7 +650,7 @@ discard block |
||
| 650 | 650 | * @param array|int $account =null array with account_lid and account_fullname or account_id for $forbid_name check |
| 651 | 651 | * @return mixed false if password is considered "safe" (or no requirements) or a string $message if "unsafe" |
| 652 | 652 | */ |
| 653 | - static function crackcheck($passwd, $reqstrength=null, $minlength=null, $forbid_name=null, $account=null) |
|
| 653 | + static function crackcheck($passwd, $reqstrength = null, $minlength = null, $forbid_name = null, $account = null) |
|
| 654 | 654 | { |
| 655 | 655 | if (!isset($reqstrength)) $reqstrength = $GLOBALS['egw_info']['server']['force_pwd_strength']; |
| 656 | 656 | if (!isset($minlength)) $minlength = $GLOBALS['egw_info']['server']['force_pwd_length']; |
@@ -664,11 +664,11 @@ discard block |
||
| 664 | 664 | { |
| 665 | 665 | if (!isset($reqstrength) || $reqstrength == 5) |
| 666 | 666 | { |
| 667 | - Config::save_value('force_pwd_strength', $reqstrength=4, 'phpgwapi'); |
|
| 667 | + Config::save_value('force_pwd_strength', $reqstrength = 4, 'phpgwapi'); |
|
| 668 | 668 | } |
| 669 | 669 | if (!isset($minlength)) |
| 670 | 670 | { |
| 671 | - Config::save_value('force_pwd_length', $minlength=7, 'phpgwapi'); |
|
| 671 | + Config::save_value('force_pwd_length', $minlength = 7, 'phpgwapi'); |
|
| 672 | 672 | } |
| 673 | 673 | Config::save_value('check_save_passwd', null, 'phpgwapi'); |
| 674 | 674 | } |
@@ -687,7 +687,7 @@ discard block |
||
| 687 | 687 | throw new Exception\WrongParameter('crackcheck(..., forbid_name=true, account) requires account-data!'); |
| 688 | 688 | } |
| 689 | 689 | $parts = preg_split("/[,._ \t0-9-]+/", $account['account_fullname'].','.$account['account_lid']); |
| 690 | - foreach($parts as $part) |
|
| 690 | + foreach ($parts as $part) |
|
| 691 | 691 | { |
| 692 | 692 | if (strlen($part) > 2 && stripos($passwd, $part) !== false) |
| 693 | 693 | { |
@@ -700,15 +700,15 @@ discard block |
||
| 700 | 700 | if ($reqstrength) |
| 701 | 701 | { |
| 702 | 702 | $missing = array(); |
| 703 | - if (!preg_match('/(.*\d.*){'. ($non=1). ',}/',$passwd)) |
|
| 703 | + if (!preg_match('/(.*\d.*){'.($non = 1).',}/', $passwd)) |
|
| 704 | 704 | { |
| 705 | 705 | $missing[] = lang('numbers'); |
| 706 | 706 | } |
| 707 | - if (!preg_match('/(.*[[:upper:]].*){'. ($nou=1). ',}/',$passwd)) |
|
| 707 | + if (!preg_match('/(.*[[:upper:]].*){'.($nou = 1).',}/', $passwd)) |
|
| 708 | 708 | { |
| 709 | 709 | $missing[] = lang('uppercase letters'); |
| 710 | 710 | } |
| 711 | - if (!preg_match('/(.*[[:lower:]].*){'. ($nol=1). ',}/',$passwd)) |
|
| 711 | + if (!preg_match('/(.*[[:lower:]].*){'.($nol = 1).',}/', $passwd)) |
|
| 712 | 712 | { |
| 713 | 713 | $missing[] = lang('lowercase letters'); |
| 714 | 714 | } |
@@ -719,7 +719,7 @@ discard block |
||
| 719 | 719 | if (4 - count($missing) < $reqstrength) |
| 720 | 720 | { |
| 721 | 721 | $errors[] = lang('password contains only %1 of required %2 character classes: no %3', |
| 722 | - 4-count($missing), $reqstrength, implode(', ', $missing)); |
|
| 722 | + 4 - count($missing), $reqstrength, implode(', ', $missing)); |
|
| 723 | 723 | } |
| 724 | 724 | } |
| 725 | 725 | if ($errors) |
@@ -737,19 +737,19 @@ discard block |
||
| 737 | 737 | * @param string $db_val stored value (from database) |
| 738 | 738 | * @return boolean True on successful comparison |
| 739 | 739 | */ |
| 740 | - static function smd5_compare($form_val,$db_val) |
|
| 740 | + static function smd5_compare($form_val, $db_val) |
|
| 741 | 741 | { |
| 742 | 742 | /* Start with the first char after {SMD5} */ |
| 743 | - $hash = base64_decode(substr($db_val,6)); |
|
| 743 | + $hash = base64_decode(substr($db_val, 6)); |
|
| 744 | 744 | |
| 745 | 745 | /* SMD5 hashes are 16 bytes long */ |
| 746 | - $orig_hash = cut_bytes($hash, 0, 16); // binary string need to use cut_bytes, not mb_substr(,,'utf-8')! |
|
| 746 | + $orig_hash = cut_bytes($hash, 0, 16); // binary string need to use cut_bytes, not mb_substr(,,'utf-8')! |
|
| 747 | 747 | $salt = cut_bytes($hash, 16); |
| 748 | 748 | |
| 749 | - $new_hash = md5($form_val . $salt,true); |
|
| 749 | + $new_hash = md5($form_val.$salt, true); |
|
| 750 | 750 | //echo '<br> DB: ' . base64_encode($orig_hash) . '<br>FORM: ' . base64_encode($new_hash); |
| 751 | 751 | |
| 752 | - return strcmp($orig_hash,$new_hash) == 0; |
|
| 752 | + return strcmp($orig_hash, $new_hash) == 0; |
|
| 753 | 753 | } |
| 754 | 754 | |
| 755 | 755 | /** |
@@ -759,14 +759,14 @@ discard block |
||
| 759 | 759 | * @param string $db_val stored value (from database) |
| 760 | 760 | * @return boolean True on successful comparison |
| 761 | 761 | */ |
| 762 | - static function sha_compare($form_val,$db_val) |
|
| 762 | + static function sha_compare($form_val, $db_val) |
|
| 763 | 763 | { |
| 764 | 764 | /* Start with the first char after {SHA} */ |
| 765 | - $hash = base64_decode(substr($db_val,5)); |
|
| 766 | - $new_hash = sha1($form_val,true); |
|
| 765 | + $hash = base64_decode(substr($db_val, 5)); |
|
| 766 | + $new_hash = sha1($form_val, true); |
|
| 767 | 767 | //echo '<br> DB: ' . base64_encode($orig_hash) . '<br>FORM: ' . base64_encode($new_hash); |
| 768 | 768 | |
| 769 | - return strcmp($hash,$new_hash) == 0; |
|
| 769 | + return strcmp($hash, $new_hash) == 0; |
|
| 770 | 770 | } |
| 771 | 771 | |
| 772 | 772 | /** |
@@ -776,18 +776,18 @@ discard block |
||
| 776 | 776 | * @param string $db_val stored value (from database) |
| 777 | 777 | * @return boolean True on successful comparison |
| 778 | 778 | */ |
| 779 | - static function ssha_compare($form_val,$db_val) |
|
| 779 | + static function ssha_compare($form_val, $db_val) |
|
| 780 | 780 | { |
| 781 | 781 | /* Start with the first char after {SSHA} */ |
| 782 | 782 | $hash = base64_decode(substr($db_val, 6)); |
| 783 | 783 | |
| 784 | 784 | // SHA-1 hashes are 160 bits long |
| 785 | - $orig_hash = cut_bytes($hash, 0, 20); // binary string need to use cut_bytes, not mb_substr(,,'utf-8')! |
|
| 785 | + $orig_hash = cut_bytes($hash, 0, 20); // binary string need to use cut_bytes, not mb_substr(,,'utf-8')! |
|
| 786 | 786 | $salt = cut_bytes($hash, 20); |
| 787 | - $new_hash = sha1($form_val . $salt,true); |
|
| 787 | + $new_hash = sha1($form_val.$salt, true); |
|
| 788 | 788 | |
| 789 | 789 | //error_log(__METHOD__."('$form_val', '$db_val') hash='$hash', orig_hash='$orig_hash', salt='$salt', new_hash='$new_hash' returning ".array2string(strcmp($orig_hash,$new_hash) == 0)); |
| 790 | - return strcmp($orig_hash,$new_hash) == 0; |
|
| 790 | + return strcmp($orig_hash, $new_hash) == 0; |
|
| 791 | 791 | } |
| 792 | 792 | |
| 793 | 793 | /** |
@@ -798,11 +798,11 @@ discard block |
||
| 798 | 798 | * @param string $_key key for md5_hmac-encryption (username for imported smf users) |
| 799 | 799 | * @return boolean True on successful comparison |
| 800 | 800 | */ |
| 801 | - static function md5_hmac_compare($form_val,$db_val,$_key) |
|
| 801 | + static function md5_hmac_compare($form_val, $db_val, $_key) |
|
| 802 | 802 | { |
| 803 | 803 | $key = str_pad(strlen($_key) <= 64 ? $_key : pack('H*', md5($_key)), 64, chr(0x00)); |
| 804 | - $md5_hmac = md5(($key ^ str_repeat(chr(0x5c), 64)) . pack('H*', md5(($key ^ str_repeat(chr(0x36), 64)). $form_val))); |
|
| 804 | + $md5_hmac = md5(($key^str_repeat(chr(0x5c), 64)).pack('H*', md5(($key^str_repeat(chr(0x36), 64)).$form_val))); |
|
| 805 | 805 | |
| 806 | - return strcmp($md5_hmac,$db_val) == 0; |
|
| 806 | + return strcmp($md5_hmac, $db_val) == 0; |
|
| 807 | 807 | } |
| 808 | 808 | } |
@@ -67,7 +67,10 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | static function backend($type=null) |
| 69 | 69 | { |
| 70 | - if (is_null($type)) $type = $GLOBALS['egw_info']['server']['auth_type']; |
|
| 70 | + if (is_null($type)) |
|
| 71 | + { |
|
| 72 | + $type = $GLOBALS['egw_info']['server']['auth_type']; |
|
| 73 | + } |
|
| 71 | 74 | |
| 72 | 75 | $backend_class = __CLASS__.'\\'.ucfirst($type); |
| 73 | 76 | |
@@ -95,12 +98,18 @@ discard block |
||
| 95 | 98 | static function check_password_change(&$message=null) |
| 96 | 99 | { |
| 97 | 100 | // dont check anything for anonymous sessions/ users that are flagged as anonymous |
| 98 | - if (is_object($GLOBALS['egw']->session) && $GLOBALS['egw']->session->session_flags == 'A') return true; |
|
| 101 | + if (is_object($GLOBALS['egw']->session) && $GLOBALS['egw']->session->session_flags == 'A') |
|
| 102 | + { |
|
| 103 | + return true; |
|
| 104 | + } |
|
| 99 | 105 | |
| 100 | 106 | // some statics (and initialisation to make information and timecalculation a) more readable in conditions b) persistent per request |
| 101 | 107 | // if user has to be warned about an upcomming passwordchange, remember for the session, that he was informed |
| 102 | 108 | static $UserKnowsAboutPwdChange=null; |
| 103 | - if (is_null($UserKnowsAboutPwdChange)) $UserKnowsAboutPwdChange =& Cache::getSession('phpgwapi','auth_UserKnowsAboutPwdChange'); |
|
| 109 | + if (is_null($UserKnowsAboutPwdChange)) |
|
| 110 | + { |
|
| 111 | + $UserKnowsAboutPwdChange =& Cache::getSession('phpgwapi','auth_UserKnowsAboutPwdChange'); |
|
| 112 | + } |
|
| 104 | 113 | |
| 105 | 114 | // retrieve the timestamp regarding the last change of the password from auth system and store it with the session |
| 106 | 115 | static $alpwchange_val=null; |
@@ -177,7 +186,10 @@ discard block |
||
| 177 | 186 | } |
| 178 | 187 | $message = lang('Your password is about to expire in %1 days, you may change your password now',round($daysLeftUntilChangeReq)); |
| 179 | 188 | // user has no rights to change password --> do NOT warn, as only forced check ignores rights |
| 180 | - if ($GLOBALS['egw']->acl->check('nopasswordchange', 1, 'preferences')) return true; |
|
| 189 | + if ($GLOBALS['egw']->acl->check('nopasswordchange', 1, 'preferences')) |
|
| 190 | + { |
|
| 191 | + return true; |
|
| 192 | + } |
|
| 181 | 193 | return null; |
| 182 | 194 | } |
| 183 | 195 | return false; |
@@ -275,8 +287,14 @@ discard block |
||
| 275 | 287 | */ |
| 276 | 288 | static function changepwd($old_passwd, $new_passwd=null, $account_id=null) |
| 277 | 289 | { |
| 278 | - if (!isset($account_id)) $account_id = $GLOBALS['egw']->session->account_id; |
|
| 279 | - if (!isset($new_passwd)) $new_passwd = $GLOBALS['egw']->session->passwd; |
|
| 290 | + if (!isset($account_id)) |
|
| 291 | + { |
|
| 292 | + $account_id = $GLOBALS['egw']->session->account_id; |
|
| 293 | + } |
|
| 294 | + if (!isset($new_passwd)) |
|
| 295 | + { |
|
| 296 | + $new_passwd = $GLOBALS['egw']->session->passwd; |
|
| 297 | + } |
|
| 280 | 298 | |
| 281 | 299 | // run changepwasswd hook |
| 282 | 300 | $GLOBALS['hook_values'] = array( |
@@ -478,7 +496,10 @@ discard block |
||
| 478 | 496 | */ |
| 479 | 497 | static function encrypt_ldap($password, $type=null) |
| 480 | 498 | { |
| 481 | - if (is_null($type)) $type = $GLOBALS['egw_info']['server']['ldap_encryption_type']; |
|
| 499 | + if (is_null($type)) |
|
| 500 | + { |
|
| 501 | + $type = $GLOBALS['egw_info']['server']['ldap_encryption_type']; |
|
| 502 | + } |
|
| 482 | 503 | |
| 483 | 504 | $salt = ''; |
| 484 | 505 | switch(strtolower($type)) |
@@ -652,9 +673,18 @@ discard block |
||
| 652 | 673 | */ |
| 653 | 674 | static function crackcheck($passwd, $reqstrength=null, $minlength=null, $forbid_name=null, $account=null) |
| 654 | 675 | { |
| 655 | - if (!isset($reqstrength)) $reqstrength = $GLOBALS['egw_info']['server']['force_pwd_strength']; |
|
| 656 | - if (!isset($minlength)) $minlength = $GLOBALS['egw_info']['server']['force_pwd_length']; |
|
| 657 | - if (!isset($forbid_name)) $forbid_name = $GLOBALS['egw_info']['server']['passwd_forbid_name']; |
|
| 676 | + if (!isset($reqstrength)) |
|
| 677 | + { |
|
| 678 | + $reqstrength = $GLOBALS['egw_info']['server']['force_pwd_strength']; |
|
| 679 | + } |
|
| 680 | + if (!isset($minlength)) |
|
| 681 | + { |
|
| 682 | + $minlength = $GLOBALS['egw_info']['server']['force_pwd_length']; |
|
| 683 | + } |
|
| 684 | + if (!isset($forbid_name)) |
|
| 685 | + { |
|
| 686 | + $forbid_name = $GLOBALS['egw_info']['server']['passwd_forbid_name']; |
|
| 687 | + } |
|
| 658 | 688 | |
| 659 | 689 | // load preferences translations, as changepassword get's called from admin too |
| 660 | 690 | Translation::add_app('preferences'); |
@@ -94,6 +94,7 @@ |
||
| 94 | 94 | * @param Handler $handler |
| 95 | 95 | * @param array $filter filter for propfind call |
| 96 | 96 | * @param array $files =array() extra files/responses to return too |
| 97 | + * @param string $path |
|
| 97 | 98 | */ |
| 98 | 99 | public function __construct(Handler $handler, $path, array $filter,array &$files=array()) |
| 99 | 100 | { |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | * |
| 72 | 72 | * @var int |
| 73 | 73 | */ |
| 74 | - protected $start=0; |
|
| 74 | + protected $start = 0; |
|
| 75 | 75 | |
| 76 | 76 | /** |
| 77 | 77 | * Number of entries queried from callback in one call |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | * @param array $filter filter for propfind call |
| 96 | 96 | * @param array $files =array() extra files/responses to return too |
| 97 | 97 | */ |
| 98 | - public function __construct(Handler $handler, $path, array $filter,array &$files=array()) |
|
| 98 | + public function __construct(Handler $handler, $path, array $filter, array &$files = array()) |
|
| 99 | 99 | { |
| 100 | 100 | if ($this->debug) error_log(__METHOD__."('$path', ".array2string($filter).",)"); |
| 101 | 101 | $this->path = $path; |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | $current = current($this->files); |
| 127 | 127 | |
| 128 | 128 | if ($this->debug) error_log(__METHOD__."() returning ".array2string($current['path'])); |
| 129 | - return $current['path']; // we return path as key |
|
| 129 | + return $current['path']; // we return path as key |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | /** |
@@ -146,11 +146,11 @@ discard block |
||
| 146 | 146 | return false; |
| 147 | 147 | } |
| 148 | 148 | // try query further files via propfind callback of handler and store result in $this->files |
| 149 | - $this->files = $this->handler->propfind_callback($this->path,$this->filter,array($this->start,self::CHUNK_SIZE)); |
|
| 149 | + $this->files = $this->handler->propfind_callback($this->path, $this->filter, array($this->start, self::CHUNK_SIZE)); |
|
| 150 | 150 | if (!is_array($this->files) || !($entries = count($this->files))) |
| 151 | 151 | { |
| 152 | 152 | if ($this->debug) error_log(__METHOD__."() returning FALSE (no more entries)"); |
| 153 | - return false; // no further entries |
|
| 153 | + return false; // no further entries |
|
| 154 | 154 | } |
| 155 | 155 | $this->start += self::CHUNK_SIZE; |
| 156 | 156 | reset($this->files); |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | |
| 170 | 170 | $this->start = 0; |
| 171 | 171 | $this->files = $this->common_files; |
| 172 | - if (!$this->files) $this->next(); // otherwise valid will return false and nothing get returned |
|
| 172 | + if (!$this->files) $this->next(); // otherwise valid will return false and nothing get returned |
|
| 173 | 173 | reset($this->files); |
| 174 | 174 | } |
| 175 | 175 | |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | * |
| 179 | 179 | * @return boolean |
| 180 | 180 | */ |
| 181 | - public function valid () |
|
| 181 | + public function valid() |
|
| 182 | 182 | { |
| 183 | 183 | if ($this->debug) error_log(__METHOD__."() returning ".array2string(current($this->files) !== false)); |
| 184 | 184 | return current($this->files) !== false; |
@@ -97,7 +97,10 @@ discard block |
||
| 97 | 97 | */ |
| 98 | 98 | public function __construct(Handler $handler, $path, array $filter,array &$files=array()) |
| 99 | 99 | { |
| 100 | - if ($this->debug) error_log(__METHOD__."('$path', ".array2string($filter).",)"); |
|
| 100 | + if ($this->debug) |
|
| 101 | + { |
|
| 102 | + error_log(__METHOD__."('$path', ".array2string($filter).",)"); |
|
| 103 | + } |
|
| 101 | 104 | $this->path = $path; |
| 102 | 105 | $this->handler = $handler; |
| 103 | 106 | $this->filter = $filter; |
@@ -112,7 +115,10 @@ discard block |
||
| 112 | 115 | */ |
| 113 | 116 | public function current() |
| 114 | 117 | { |
| 115 | - if ($this->debug) error_log(__METHOD__."() returning ".array2string(current($this->files))); |
|
| 118 | + if ($this->debug) |
|
| 119 | + { |
|
| 120 | + error_log(__METHOD__."() returning ".array2string(current($this->files))); |
|
| 121 | + } |
|
| 116 | 122 | return current($this->files); |
| 117 | 123 | } |
| 118 | 124 | |
@@ -125,7 +131,10 @@ discard block |
||
| 125 | 131 | { |
| 126 | 132 | $current = current($this->files); |
| 127 | 133 | |
| 128 | - if ($this->debug) error_log(__METHOD__."() returning ".array2string($current['path'])); |
|
| 134 | + if ($this->debug) |
|
| 135 | + { |
|
| 136 | + error_log(__METHOD__."() returning ".array2string($current['path'])); |
|
| 137 | + } |
|
| 129 | 138 | return $current['path']; // we return path as key |
| 130 | 139 | } |
| 131 | 140 | |
@@ -136,26 +145,38 @@ discard block |
||
| 136 | 145 | { |
| 137 | 146 | if (next($this->files) !== false) |
| 138 | 147 | { |
| 139 | - if ($this->debug) error_log(__METHOD__."() returning TRUE"); |
|
| 148 | + if ($this->debug) |
|
| 149 | + { |
|
| 150 | + error_log(__METHOD__."() returning TRUE"); |
|
| 151 | + } |
|
| 140 | 152 | return true; |
| 141 | 153 | } |
| 142 | 154 | // check if previous query gave less then CHUNK_SIZE entries --> we're done |
| 143 | 155 | if ($this->start && count($this->files) < self::CHUNK_SIZE) |
| 144 | 156 | { |
| 145 | - if ($this->debug) error_log(__METHOD__."() returning FALSE (no more entries)"); |
|
| 157 | + if ($this->debug) |
|
| 158 | + { |
|
| 159 | + error_log(__METHOD__."() returning FALSE (no more entries)"); |
|
| 160 | + } |
|
| 146 | 161 | return false; |
| 147 | 162 | } |
| 148 | 163 | // try query further files via propfind callback of handler and store result in $this->files |
| 149 | 164 | $this->files = $this->handler->propfind_callback($this->path,$this->filter,array($this->start,self::CHUNK_SIZE)); |
| 150 | 165 | if (!is_array($this->files) || !($entries = count($this->files))) |
| 151 | 166 | { |
| 152 | - if ($this->debug) error_log(__METHOD__."() returning FALSE (no more entries)"); |
|
| 167 | + if ($this->debug) |
|
| 168 | + { |
|
| 169 | + error_log(__METHOD__."() returning FALSE (no more entries)"); |
|
| 170 | + } |
|
| 153 | 171 | return false; // no further entries |
| 154 | 172 | } |
| 155 | 173 | $this->start += self::CHUNK_SIZE; |
| 156 | 174 | reset($this->files); |
| 157 | 175 | |
| 158 | - if ($this->debug) error_log(__METHOD__."() this->start=$this->start, entries=$entries, count(this->files)=".count($this->files)." returning ".array2string(current($this->files) !== false)); |
|
| 176 | + if ($this->debug) |
|
| 177 | + { |
|
| 178 | + error_log(__METHOD__."() this->start=$this->start, entries=$entries, count(this->files)=".count($this->files)." returning ".array2string(current($this->files) !== false)); |
|
| 179 | + } |
|
| 159 | 180 | |
| 160 | 181 | return current($this->files) !== false; |
| 161 | 182 | } |
@@ -165,11 +186,18 @@ discard block |
||
| 165 | 186 | */ |
| 166 | 187 | public function rewind() |
| 167 | 188 | { |
| 168 | - if ($this->debug) error_log(__METHOD__."()"); |
|
| 189 | + if ($this->debug) |
|
| 190 | + { |
|
| 191 | + error_log(__METHOD__."()"); |
|
| 192 | + } |
|
| 169 | 193 | |
| 170 | 194 | $this->start = 0; |
| 171 | 195 | $this->files = $this->common_files; |
| 172 | - if (!$this->files) $this->next(); // otherwise valid will return false and nothing get returned |
|
| 196 | + if (!$this->files) |
|
| 197 | + { |
|
| 198 | + $this->next(); |
|
| 199 | + } |
|
| 200 | + // otherwise valid will return false and nothing get returned |
|
| 173 | 201 | reset($this->files); |
| 174 | 202 | } |
| 175 | 203 | |
@@ -180,7 +208,10 @@ discard block |
||
| 180 | 208 | */ |
| 181 | 209 | public function valid () |
| 182 | 210 | { |
| 183 | - if ($this->debug) error_log(__METHOD__."() returning ".array2string(current($this->files) !== false)); |
|
| 211 | + if ($this->debug) |
|
| 212 | + { |
|
| 213 | + error_log(__METHOD__."() returning ".array2string(current($this->files) !== false)); |
|
| 214 | + } |
|
| 184 | 215 | return current($this->files) !== false; |
| 185 | 216 | } |
| 186 | 217 | } |
@@ -322,13 +322,13 @@ discard block |
||
| 322 | 322 | * return a sorted array populated with categories (main sorting criteria is hierachy!) |
| 323 | 323 | * |
| 324 | 324 | * @param int $start =0 see $limit |
| 325 | - * @param boolean|int $limit if true limited query to maxmatches rows (starting with $start) |
|
| 325 | + * @param boolean $limit if true limited query to maxmatches rows (starting with $start) |
|
| 326 | 326 | * @param string $query ='' query-pattern |
| 327 | 327 | * @param string $sort ='ASC' sort order, either defaults to 'ASC' |
| 328 | 328 | * @param string $order ='cat_name' order by |
| 329 | 329 | * @param boolean|string $globals includes the global egroupware categories or not, |
| 330 | 330 | * 'all_no_acl' to return global and all non-private user categories independent of ACL |
| 331 | - * @param array|int $parent_id =0 return only subcats of $parent_id(s) |
|
| 331 | + * @param integer $parent_id =0 return only subcats of $parent_id(s) |
|
| 332 | 332 | * @param boolean $unserialize_data =true return $cat['data'] as array (not serialized array) |
| 333 | 333 | * @return array with cats |
| 334 | 334 | */ |
@@ -507,7 +507,7 @@ discard block |
||
| 507 | 507 | * @param mixed $category category as array or the category_id |
| 508 | 508 | * @param boolean $no_acl_check =false if true, grants are NOT checked, gives access to all non-private categories of all users |
| 509 | 509 | * @param boolean $allow_global_read if true, global cats are allowed (independent of app) for reading |
| 510 | - * @return boolean true permission granted, false for permission denied, null for category does not exist |
|
| 510 | + * @return null|boolean true permission granted, false for permission denied, null for category does not exist |
|
| 511 | 511 | */ |
| 512 | 512 | public function check_perms($needed, $category, $no_acl_check=false, $allow_global_read=false) |
| 513 | 513 | { |
@@ -675,7 +675,7 @@ discard block |
||
| 675 | 675 | * check_consistency4update - for edit |
| 676 | 676 | * |
| 677 | 677 | * @param array $values array with cat-data (it need to be complete, as everything get's written) |
| 678 | - * @return mixed string/boolean errorstring if consitency check failed / true if the consistency check did not fail |
|
| 678 | + * @return string|boolean string/boolean errorstring if consitency check failed / true if the consistency check did not fail |
|
| 679 | 679 | */ |
| 680 | 680 | function check_consistency4update($values) |
| 681 | 681 | { |
@@ -822,7 +822,7 @@ discard block |
||
| 822 | 822 | * |
| 823 | 823 | * @param int|array $cat |
| 824 | 824 | * @param boolean $application_global =false true check for application global categories only (appname == 'phpgw') |
| 825 | - * @return boolean |
|
| 825 | + * @return null|boolean |
|
| 826 | 826 | */ |
| 827 | 827 | static function is_global($cat,$application_global=false) |
| 828 | 828 | { |
@@ -1030,7 +1030,7 @@ discard block |
||
| 1030 | 1030 | * |
| 1031 | 1031 | * @param string appname |
| 1032 | 1032 | * |
| 1033 | - * @return Returns the URL, but you do not need to do anything with it. |
|
| 1033 | + * @return string the URL, but you do not need to do anything with it. |
|
| 1034 | 1034 | */ |
| 1035 | 1035 | public static function css($appname) |
| 1036 | 1036 | { |
@@ -1044,13 +1044,13 @@ |
||
| 1044 | 1044 | } |
| 1045 | 1045 | |
| 1046 | 1046 | /** |
| 1047 | - * Get the color of a category |
|
| 1048 | - * |
|
| 1049 | - * For multiple cats, the first with a color is used |
|
| 1050 | - * |
|
| 1051 | - * @param int|string $_cats multiple comma-separated cat_id's |
|
| 1052 | - * @return string |
|
| 1053 | - */ |
|
| 1047 | + * Get the color of a category |
|
| 1048 | + * |
|
| 1049 | + * For multiple cats, the first with a color is used |
|
| 1050 | + * |
|
| 1051 | + * @param int|string $_cats multiple comma-separated cat_id's |
|
| 1052 | + * @return string |
|
| 1053 | + */ |
|
| 1054 | 1054 | static function cats2color($_cats) |
| 1055 | 1055 | { |
| 1056 | 1056 | static $cat2color = array(); |
@@ -122,7 +122,10 @@ discard block |
||
| 122 | 122 | */ |
| 123 | 123 | function __construct($accountid='',$app_name = '') |
| 124 | 124 | { |
| 125 | - if (!$app_name) $app_name = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 125 | + if (!$app_name) |
|
| 126 | + { |
|
| 127 | + $app_name = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 128 | + } |
|
| 126 | 129 | |
| 127 | 130 | if ($accountid === self::GLOBAL_ACCOUNT || |
| 128 | 131 | $accountid < 0 && $GLOBALS['egw']->accounts->exists($accountid) == 2) |
@@ -138,10 +141,13 @@ discard block |
||
| 138 | 141 | $this->app_name = $app_name; |
| 139 | 142 | $this->db = $GLOBALS['egw']->db; |
| 140 | 143 | |
| 141 | - if (is_null(self::$cache)) // should not be necessary, as cache is load and restored by egw object |
|
| 144 | + if (is_null(self::$cache)) |
|
| 145 | + { |
|
| 146 | + // should not be necessary, as cache is load and restored by egw object |
|
| 142 | 147 | { |
| 143 | 148 | self::init_cache(); |
| 144 | 149 | } |
| 150 | + } |
|
| 145 | 151 | if (is_null(self::$global_marker)) |
| 146 | 152 | { |
| 147 | 153 | // as et2 adds options with .text(), it can't be entities, but php knows no string literals with utf-8 |
@@ -189,7 +195,9 @@ discard block |
||
| 189 | 195 | $cats = array(); |
| 190 | 196 | foreach(self::$cache as $cat) |
| 191 | 197 | { |
| 192 | - if ($filter) foreach($filter as $col => $val) |
|
| 198 | + if ($filter) |
|
| 199 | + { |
|
| 200 | + foreach($filter as $col => $val) |
|
| 193 | 201 | { |
| 194 | 202 | if (!is_array($val) && $val[0] === '!') |
| 195 | 203 | { |
@@ -197,10 +205,14 @@ discard block |
||
| 197 | 205 | if (($col == 'name' || $col == 'description') && is_string($cat[$col])) |
| 198 | 206 | { |
| 199 | 207 | if ($cat[$col] == substr($val,1) || trim($cat[$col]) == substr($val,1)) continue 2; |
| 208 | + } |
|
| 200 | 209 | } |
| 201 | 210 | else |
| 202 | 211 | { |
| 203 | - if ($cat[$col] == substr($val,1)) continue 2; |
|
| 212 | + if ($cat[$col] == substr($val,1)) |
|
| 213 | + { |
|
| 214 | + continue 2; |
|
| 215 | + } |
|
| 204 | 216 | } |
| 205 | 217 | } |
| 206 | 218 | elseif (is_array($val)) |
@@ -208,11 +220,17 @@ discard block |
||
| 208 | 220 | // also match against trimmed database entry on name and description fields |
| 209 | 221 | if (($col == 'name' || $col == 'description') && is_string($cat[$col])) |
| 210 | 222 | { |
| 211 | - if (!in_array($cat[$col],$val) && !in_array(trim($cat[$col]),$val)) continue 2; |
|
| 223 | + if (!in_array($cat[$col],$val) && !in_array(trim($cat[$col]),$val)) |
|
| 224 | + { |
|
| 225 | + continue 2; |
|
| 226 | + } |
|
| 212 | 227 | } |
| 213 | 228 | else |
| 214 | 229 | { |
| 215 | - if (!in_array($cat[$col],$val)) continue 2; |
|
| 230 | + if (!in_array($cat[$col],$val)) |
|
| 231 | + { |
|
| 232 | + continue 2; |
|
| 233 | + } |
|
| 216 | 234 | } |
| 217 | 235 | } |
| 218 | 236 | else |
@@ -220,16 +238,25 @@ discard block |
||
| 220 | 238 | // also match against trimmed database entry on name and description fields |
| 221 | 239 | if (($col == 'name' || $col == 'description') && is_string($cat[$col])) |
| 222 | 240 | { |
| 223 | - if ($cat[$col] != $val && trim($cat[$col]) != $val) continue 2; |
|
| 241 | + if ($cat[$col] != $val && trim($cat[$col]) != $val) |
|
| 242 | + { |
|
| 243 | + continue 2; |
|
| 244 | + } |
|
| 224 | 245 | } |
| 225 | 246 | else |
| 226 | 247 | { |
| 227 | - if ($cat[$col] != $val) continue 2; |
|
| 248 | + if ($cat[$col] != $val) |
|
| 249 | + { |
|
| 250 | + continue 2; |
|
| 251 | + } |
|
| 228 | 252 | } |
| 229 | 253 | } |
| 230 | 254 | } |
| 231 | 255 | // check if certain parent required |
| 232 | - if ($parent_id && !in_array($cat['parent'],(array)$parent_id)) continue; |
|
| 256 | + if ($parent_id && !in_array($cat['parent'],(array)$parent_id)) |
|
| 257 | + { |
|
| 258 | + continue; |
|
| 259 | + } |
|
| 233 | 260 | |
| 234 | 261 | // return global categories just if $globals is set |
| 235 | 262 | if (!$globals && $cat['appname'] == self::GLOBAL_APPNAME) |
@@ -247,30 +274,55 @@ discard block |
||
| 247 | 274 | switch ($type) |
| 248 | 275 | { |
| 249 | 276 | case 'subs': |
| 250 | - if (!$cat['parent']) continue 2; // 2 for switch AND foreach! |
|
| 277 | + if (!$cat['parent']) |
|
| 278 | + { |
|
| 279 | + continue 2; |
|
| 280 | + } |
|
| 281 | + // 2 for switch AND foreach! |
|
| 251 | 282 | break; |
| 252 | 283 | case 'mains': |
| 253 | - if ($cat['parent']) continue 2; |
|
| 284 | + if ($cat['parent']) |
|
| 285 | + { |
|
| 286 | + continue 2; |
|
| 287 | + } |
|
| 254 | 288 | break; |
| 255 | 289 | case 'appandmains': |
| 256 | - if ($cat['appname'] != $this->app_name || $cat['parent']) continue 2; |
|
| 290 | + if ($cat['appname'] != $this->app_name || $cat['parent']) |
|
| 291 | + { |
|
| 292 | + continue 2; |
|
| 293 | + } |
|
| 257 | 294 | break; |
| 258 | 295 | case 'appandsubs': |
| 259 | - if ($cat['appname'] != $this->app_name || !$cat['parent']) continue 2; |
|
| 296 | + if ($cat['appname'] != $this->app_name || !$cat['parent']) |
|
| 297 | + { |
|
| 298 | + continue 2; |
|
| 299 | + } |
|
| 260 | 300 | break; |
| 261 | 301 | case 'noglobal': |
| 262 | - if ($cat['appname'] == $this->app_name) continue 2; |
|
| 302 | + if ($cat['appname'] == $this->app_name) |
|
| 303 | + { |
|
| 304 | + continue 2; |
|
| 305 | + } |
|
| 263 | 306 | break; |
| 264 | 307 | case 'noglobalapp': |
| 265 | - if ($cat['appname'] != $this->app_name || $cat['owner'] == (int)$this->account_id) continue 2; |
|
| 308 | + if ($cat['appname'] != $this->app_name || $cat['owner'] == (int)$this->account_id) |
|
| 309 | + { |
|
| 310 | + continue 2; |
|
| 311 | + } |
|
| 266 | 312 | break; |
| 267 | 313 | } |
| 268 | 314 | |
| 269 | 315 | // check name and description for $query |
| 270 | - if ($query && stristr($cat['name'],$query) === false && stristr($cat['description'],$query) === false) continue; |
|
| 316 | + if ($query && stristr($cat['name'],$query) === false && stristr($cat['description'],$query) === false) |
|
| 317 | + { |
|
| 318 | + continue; |
|
| 319 | + } |
|
| 271 | 320 | |
| 272 | 321 | // check if last modified since |
| 273 | - if ($lastmod > 0 && $cat['last_mod'] <= $lastmod) continue; |
|
| 322 | + if ($lastmod > 0 && $cat['last_mod'] <= $lastmod) |
|
| 323 | + { |
|
| 324 | + continue; |
|
| 325 | + } |
|
| 274 | 326 | |
| 275 | 327 | $cat['data'] = $cat['data'] ? json_php_unserialize($cat['data'], true) : array(); |
| 276 | 328 | |
@@ -281,13 +333,23 @@ discard block |
||
| 281 | 333 | //error_log(__METHOD__."($type,$start,$limit,$query,$sort,$order,$globals,parent=$parent_id,$lastmod,$column) account_id=$this->account_id, appname=$this->app_name = FALSE"); |
| 282 | 334 | return array(); |
| 283 | 335 | } |
| 284 | - if (!$sort) $sort = 'ASC'; |
|
| 336 | + if (!$sort) |
|
| 337 | + { |
|
| 338 | + $sort = 'ASC'; |
|
| 339 | + } |
|
| 285 | 340 | // order the entries if necessary (cache is already ordered in or default order: cat_main, cat_level, cat_name ASC) |
| 286 | 341 | if ($this->total_records > 1 && !empty($order) && |
| 287 | 342 | preg_match('/^[a-zA-Z_(), ]+$/',$order) && preg_match('/^(ASC|DESC|asc|desc)$/',$sort)) |
| 288 | 343 | { |
| 289 | - if (strstr($order,'cat_data') !== false) $order = 'cat_data'; // sitemgr orders by round(cat_data)! |
|
| 290 | - if (substr($order,0,4) == 'cat_') $order = substr($order,4); |
|
| 344 | + if (strstr($order,'cat_data') !== false) |
|
| 345 | + { |
|
| 346 | + $order = 'cat_data'; |
|
| 347 | + } |
|
| 348 | + // sitemgr orders by round(cat_data)! |
|
| 349 | + if (substr($order,0,4) == 'cat_') |
|
| 350 | + { |
|
| 351 | + $order = substr($order,4); |
|
| 352 | + } |
|
| 291 | 353 | $sign = strtoupper($sort) == 'DESC' ? -1 : 1; |
| 292 | 354 | usort($cats, function($a, $b) use ($order, $sign) |
| 293 | 355 | { |
@@ -301,7 +363,10 @@ discard block |
||
| 301 | 363 | // limit the number of returned rows |
| 302 | 364 | if ($limit) |
| 303 | 365 | { |
| 304 | - if (!is_int($limit)) $limit = (int)$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']; |
|
| 366 | + if (!is_int($limit)) |
|
| 367 | + { |
|
| 368 | + $limit = (int)$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']; |
|
| 369 | + } |
|
| 305 | 370 | $cats = array_slice($cats,(int)$start,$limit); |
| 306 | 371 | } |
| 307 | 372 | // return only a certain column (why not return is as value?) |
@@ -334,15 +399,24 @@ discard block |
||
| 334 | 399 | */ |
| 335 | 400 | function return_sorted_array($start=0,$limit=True,$query='',$sort='ASC',$order='cat_name',$globals=False, $parent_id=0,$unserialize_data=true,$filter=null) |
| 336 | 401 | { |
| 337 | - if (!$sort) $sort = 'ASC'; |
|
| 338 | - if (!$order) $order = 'cat_name'; |
|
| 402 | + if (!$sort) |
|
| 403 | + { |
|
| 404 | + $sort = 'ASC'; |
|
| 405 | + } |
|
| 406 | + if (!$order) |
|
| 407 | + { |
|
| 408 | + $order = 'cat_name'; |
|
| 409 | + } |
|
| 339 | 410 | |
| 340 | 411 | //error_log(__METHOD__."($start,$limit,$query,$sort,$order,globals=$globals,parent=$parent_id,$unserialize_data) account_id=$this->account_id, appname=$this->app_name: ".function_backtrace()); |
| 341 | 412 | |
| 342 | 413 | $parents = $cats = array(); |
| 343 | 414 | |
| 344 | 415 | // Cast parent_id to array, but only if there is one |
| 345 | - if($parent_id !== false && $parent_id !== null) $parent_id = (array)$parent_id; |
|
| 416 | + if($parent_id !== false && $parent_id !== null) |
|
| 417 | + { |
|
| 418 | + $parent_id = (array)$parent_id; |
|
| 419 | + } |
|
| 346 | 420 | if (!($cats = $this->return_array('all',0,false,$query,$sort,$order,$globals,$parent_id,-1,'',$filter,$unserialize_data))) |
| 347 | 421 | { |
| 348 | 422 | $cats = array(); |
@@ -352,7 +426,9 @@ discard block |
||
| 352 | 426 | $parents[] = $cat['id']; |
| 353 | 427 | } |
| 354 | 428 | |
| 355 | - if($parent_id || !$cats) // Avoid wiping search results |
|
| 429 | + if($parent_id || !$cats) |
|
| 430 | + { |
|
| 431 | + // Avoid wiping search results |
|
| 356 | 432 | { |
| 357 | 433 | // Go find the children |
| 358 | 434 | while (count($parents)) |
@@ -360,6 +436,7 @@ discard block |
||
| 360 | 436 | if (!($subs = $this->return_array('all',0,false,$query,$sort,$order,$globals,$parents,-1,'',$filter,$unserialize_data))) |
| 361 | 437 | { |
| 362 | 438 | break; |
| 439 | + } |
|
| 363 | 440 | } |
| 364 | 441 | $parents = $children = array(); |
| 365 | 442 | foreach($subs as $cat) |
@@ -391,7 +468,10 @@ discard block |
||
| 391 | 468 | // limit the number of returned rows |
| 392 | 469 | if ($limit) |
| 393 | 470 | { |
| 394 | - if (!is_int($limit)) $limit = (int)$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']; |
|
| 471 | + if (!is_int($limit)) |
|
| 472 | + { |
|
| 473 | + $limit = (int)$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']; |
|
| 474 | + } |
|
| 395 | 475 | $cats = array_slice($cats,(int)$start,$limit); |
| 396 | 476 | } |
| 397 | 477 | reset($cats); // some old code (eg. sitemgr) relies on the array-pointer! |
@@ -410,9 +490,15 @@ discard block |
||
| 410 | 490 | */ |
| 411 | 491 | static function read($id) |
| 412 | 492 | { |
| 413 | - if (is_null(self::$cache)) self::init_cache(); |
|
| 493 | + if (is_null(self::$cache)) |
|
| 494 | + { |
|
| 495 | + self::init_cache(); |
|
| 496 | + } |
|
| 414 | 497 | |
| 415 | - if (!isset(self::$cache[$id])) return false; |
|
| 498 | + if (!isset(self::$cache[$id])) |
|
| 499 | + { |
|
| 500 | + return false; |
|
| 501 | + } |
|
| 416 | 502 | |
| 417 | 503 | $cat = self::$cache[$id]; |
| 418 | 504 | $cat['data'] = $cat['data'] ? ((($arr=json_php_unserialize($cat['data'], true)) !== false || $cat['data'] === 'b:0;') ? |
@@ -475,8 +561,11 @@ discard block |
||
| 475 | 561 | * @return string truncated commaseparated list of category ids |
| 476 | 562 | */ |
| 477 | 563 | function check_list($needed, $cat_list) |
| 478 | - { |
|
| 479 | - if (empty($cat_list)) return $cat_list; |
|
| 564 | + { |
|
| 565 | + if (empty($cat_list)) |
|
| 566 | + { |
|
| 567 | + return $cat_list; |
|
| 568 | + } |
|
| 480 | 569 | if (is_array($cat_list)) |
| 481 | 570 | { |
| 482 | 571 | $cat_list = implode(',',$cat_list); |
@@ -487,10 +576,13 @@ discard block |
||
| 487 | 576 | { |
| 488 | 577 | foreach($cat_arr as $id=>$cat_id) |
| 489 | 578 | { |
| 490 | - if (!$this->check_perms($needed, $cat_id, false, $needed == Acl::READ)) // allow reading all global cats |
|
| 579 | + if (!$this->check_perms($needed, $cat_id, false, $needed == Acl::READ)) |
|
| 580 | + { |
|
| 581 | + // allow reading all global cats |
|
| 491 | 582 | { |
| 492 | 583 | unset($cat_arr[$id]); |
| 493 | 584 | } |
| 585 | + } |
|
| 494 | 586 | } |
| 495 | 587 | $cat_list = implode(',',$cat_arr); |
| 496 | 588 | } |
@@ -596,9 +688,15 @@ discard block |
||
| 596 | 688 | { |
| 597 | 689 | $update = array('cat_level' => $cat['level']-1); |
| 598 | 690 | |
| 599 | - if ($new_main) $update['cat_main'] = $new_main; |
|
| 691 | + if ($new_main) |
|
| 692 | + { |
|
| 693 | + $update['cat_main'] = $new_main; |
|
| 694 | + } |
|
| 600 | 695 | |
| 601 | - if ($cat['parent'] == $cat_id) $update['cat_parent'] = $new_parent; |
|
| 696 | + if ($cat['parent'] == $cat_id) |
|
| 697 | + { |
|
| 698 | + $update['cat_parent'] = $new_parent; |
|
| 699 | + } |
|
| 602 | 700 | |
| 603 | 701 | $this->db->update(self::TABLE,$update,array( |
| 604 | 702 | 'cat_id' => $cat['id'], |
@@ -624,9 +722,13 @@ discard block |
||
| 624 | 722 | 'modify_subs' => $modify_subs, |
| 625 | 723 | 'location' => 'delete_category' |
| 626 | 724 | ); |
| 627 | - if($this->is_global($cat_id, true)) // true = application global (otherwise eg. global addressbook categories call all apps) |
|
| 725 | + if($this->is_global($cat_id, true)) |
|
| 726 | + { |
|
| 727 | + // true = application global (otherwise eg. global addressbook categories call all apps) |
|
| 628 | 728 | { |
| 629 | - Hooks::process($GLOBALS['hook_values'],False,True); // called for every app now, not only enabled ones) |
|
| 729 | + Hooks::process($GLOBALS['hook_values'],False,True); |
|
| 730 | + } |
|
| 731 | + // called for every app now, not only enabled ones) |
|
| 630 | 732 | } |
| 631 | 733 | else |
| 632 | 734 | { |
@@ -682,12 +784,22 @@ discard block |
||
| 682 | 784 | // check if we try to move an element down its own subtree, which will fail |
| 683 | 785 | foreach ($this->return_sorted_array('',False,'','','',False, $values['id']) as $cat) |
| 684 | 786 | { |
| 685 | - if ($cat['id'] == $values['parent']) return lang('Cannot set a category as parent, which is part of this categorys subtree!'); |
|
| 787 | + if ($cat['id'] == $values['parent']) |
|
| 788 | + { |
|
| 789 | + return lang('Cannot set a category as parent, which is part of this categorys subtree!'); |
|
| 790 | + } |
|
| 686 | 791 | } |
| 687 | 792 | // check if we try to be our own parent |
| 688 | - if ($values['parent']==$values['id']) return lang('Cannot set this cat as its own parent!'); // deny to be our own parent |
|
| 793 | + if ($values['parent']==$values['id']) |
|
| 794 | + { |
|
| 795 | + return lang('Cannot set this cat as its own parent!'); |
|
| 796 | + } |
|
| 797 | + // deny to be our own parent |
|
| 689 | 798 | // check if parent still exists |
| 690 | - if ((int)$values['parent']>0 && !$this->read($values['parent'])) return lang('Chosen parent category no longer exists'); |
|
| 799 | + if ((int)$values['parent']>0 && !$this->read($values['parent'])) |
|
| 800 | + { |
|
| 801 | + return lang('Chosen parent category no longer exists'); |
|
| 802 | + } |
|
| 691 | 803 | return true; |
| 692 | 804 | } |
| 693 | 805 | |
@@ -704,7 +816,10 @@ discard block |
||
| 704 | 816 | if (isset($values['old_parent']) && (int)$values['old_parent'] != (int)$values['parent']) |
| 705 | 817 | { |
| 706 | 818 | $ret = $this->check_consistency4update($values); |
| 707 | - if ($ret !== true) throw new Exception\WrongUserinput($ret); |
|
| 819 | + if ($ret !== true) |
|
| 820 | + { |
|
| 821 | + throw new Exception\WrongUserinput($ret); |
|
| 822 | + } |
|
| 708 | 823 | // everything seems in order -> proceed |
| 709 | 824 | $values['level'] = ($values['parent'] ? $this->id2name($values['parent'],'level')+1:0); |
| 710 | 825 | $this->adapt_level_in_subtree($values); |
@@ -717,7 +832,10 @@ discard block |
||
| 717 | 832 | if ($values['parent'] > 0) |
| 718 | 833 | { |
| 719 | 834 | $ret = $this->check_consistency4update($values); |
| 720 | - if ($ret !== true) throw new Exception\WrongUserinput($ret); |
|
| 835 | + if ($ret !== true) |
|
| 836 | + { |
|
| 837 | + throw new Exception\WrongUserinput($ret); |
|
| 838 | + } |
|
| 721 | 839 | |
| 722 | 840 | // everything seems in order -> proceed |
| 723 | 841 | $values['main'] = $this->id2name($values['parent'],'main'); |
@@ -773,7 +891,10 @@ discard block |
||
| 773 | 891 | { |
| 774 | 892 | static $cache = array(); // a litle bit of caching |
| 775 | 893 | |
| 776 | - if (isset($cache[$cat_name])) return $cache[$cat_name]; |
|
| 894 | + if (isset($cache[$cat_name])) |
|
| 895 | + { |
|
| 896 | + return $cache[$cat_name]; |
|
| 897 | + } |
|
| 777 | 898 | |
| 778 | 899 | if ($strip === true) |
| 779 | 900 | { |
@@ -826,7 +947,11 @@ discard block |
||
| 826 | 947 | */ |
| 827 | 948 | static function is_global($cat,$application_global=false) |
| 828 | 949 | { |
| 829 | - if (!is_array($cat) && !($cat = self::read($cat))) return null; // cat not found |
|
| 950 | + if (!is_array($cat) && !($cat = self::read($cat))) |
|
| 951 | + { |
|
| 952 | + return null; |
|
| 953 | + } |
|
| 954 | + // cat not found |
|
| 830 | 955 | |
| 831 | 956 | $global_owner = false; |
| 832 | 957 | foreach(explode(',',$cat['owner']) as $owner) |
@@ -848,10 +973,19 @@ discard block |
||
| 848 | 973 | */ |
| 849 | 974 | static function id2name($cat_id=0, $item='name') |
| 850 | 975 | { |
| 851 | - if(!$cat_id) return '--'; |
|
| 852 | - if (!$item) $item = 'parent'; |
|
| 976 | + if(!$cat_id) |
|
| 977 | + { |
|
| 978 | + return '--'; |
|
| 979 | + } |
|
| 980 | + if (!$item) |
|
| 981 | + { |
|
| 982 | + $item = 'parent'; |
|
| 983 | + } |
|
| 853 | 984 | |
| 854 | - if (is_null(self::$cache)) self::init_cache(); |
|
| 985 | + if (is_null(self::$cache)) |
|
| 986 | + { |
|
| 987 | + self::init_cache(); |
|
| 988 | + } |
|
| 855 | 989 | |
| 856 | 990 | $cat = self::$cache[$cat_id]; |
| 857 | 991 | if ($item == 'path') |
@@ -892,7 +1026,10 @@ discard block |
||
| 892 | 1026 | if ($cat_name) |
| 893 | 1027 | { |
| 894 | 1028 | $filter['name'] = $cat_name; |
| 895 | - if ($cat_id) $filter['id'] = '!'.(int)$cat_id; |
|
| 1029 | + if ($cat_id) |
|
| 1030 | + { |
|
| 1031 | + $filter['id'] = '!'.(int)$cat_id; |
|
| 1032 | + } |
|
| 896 | 1033 | } |
| 897 | 1034 | elseif ($cat_id) |
| 898 | 1035 | { |
@@ -921,7 +1058,10 @@ discard block |
||
| 921 | 1058 | { |
| 922 | 1059 | $where = array('cat_owner' => $owner); |
| 923 | 1060 | |
| 924 | - if ($app) $where['cat_appname'] = $app; |
|
| 1061 | + if ($app) |
|
| 1062 | + { |
|
| 1063 | + $where['cat_appname'] = $app; |
|
| 1064 | + } |
|
| 925 | 1065 | |
| 926 | 1066 | if ((int)$to) |
| 927 | 1067 | { |
@@ -967,7 +1107,11 @@ discard block |
||
| 967 | 1107 | false,'ORDER BY cat_main, cat_level, cat_name ASC') as $cat) |
| 968 | 1108 | { |
| 969 | 1109 | $cat = Db::strip_array_keys($cat,'cat_'); |
| 970 | - if ($cat['appname'] == '*update*') continue; // --> ignore update marker |
|
| 1110 | + if ($cat['appname'] == '*update*') |
|
| 1111 | + { |
|
| 1112 | + continue; |
|
| 1113 | + } |
|
| 1114 | + // --> ignore update marker |
|
| 971 | 1115 | $cat['app_name'] = $cat['appname']; |
| 972 | 1116 | // backlink children to their parent |
| 973 | 1117 | if ($cat['parent']) |
@@ -1058,7 +1202,10 @@ discard block |
||
| 1058 | 1202 | // ACL check |
| 1059 | 1203 | $cats = $GLOBALS['egw']->categories->check_list(Acl::READ, $_cats); |
| 1060 | 1204 | |
| 1061 | - if (!$cats) return null; |
|
| 1205 | + if (!$cats) |
|
| 1206 | + { |
|
| 1207 | + return null; |
|
| 1208 | + } |
|
| 1062 | 1209 | |
| 1063 | 1210 | if (isset($cat2color[$cats])) |
| 1064 | 1211 | { |
@@ -1090,7 +1237,10 @@ discard block |
||
| 1090 | 1237 | */ |
| 1091 | 1238 | public static function delete_account($account_id, $new_owner=null) |
| 1092 | 1239 | { |
| 1093 | - if (is_null(self::$cache)) self::init_cache(); |
|
| 1240 | + if (is_null(self::$cache)) |
|
| 1241 | + { |
|
| 1242 | + self::init_cache(); |
|
| 1243 | + } |
|
| 1094 | 1244 | |
| 1095 | 1245 | $deleted = 0; |
| 1096 | 1246 | $cat = null; |
@@ -1110,7 +1260,10 @@ discard block |
||
| 1110 | 1260 | else |
| 1111 | 1261 | { |
| 1112 | 1262 | unset($owners[$owner_key]); |
| 1113 | - if ($new_owner && $account_id > 0) $owners[] = $new_owner; |
|
| 1263 | + if ($new_owner && $account_id > 0) |
|
| 1264 | + { |
|
| 1265 | + $owners[] = $new_owner; |
|
| 1266 | + } |
|
| 1114 | 1267 | $data['owner'] = implode(',', $owners); |
| 1115 | 1268 | // app_name have to match cat to update! |
| 1116 | 1269 | if (!isset($cat) || $cat->app_name != $data['appname']) |
@@ -1132,7 +1285,10 @@ discard block |
||
| 1132 | 1285 | */ |
| 1133 | 1286 | public static function delete_orphans() |
| 1134 | 1287 | { |
| 1135 | - if (is_null(self::$cache)) self::init_cache(); |
|
| 1288 | + if (is_null(self::$cache)) |
|
| 1289 | + { |
|
| 1290 | + self::init_cache(); |
|
| 1291 | + } |
|
| 1136 | 1292 | |
| 1137 | 1293 | $checked = array(); |
| 1138 | 1294 | $deleted = 0; |
@@ -120,23 +120,23 @@ discard block |
||
| 120 | 120 | * @param int|string $accountid ='' account id or lid, default to current user |
| 121 | 121 | * @param string $app_name ='' app name defaults to current app |
| 122 | 122 | */ |
| 123 | - function __construct($accountid='',$app_name = '') |
|
| 123 | + function __construct($accountid = '', $app_name = '') |
|
| 124 | 124 | { |
| 125 | 125 | if (!$app_name) $app_name = $GLOBALS['egw_info']['flags']['currentapp']; |
| 126 | 126 | |
| 127 | 127 | if ($accountid === self::GLOBAL_ACCOUNT || |
| 128 | 128 | $accountid < 0 && $GLOBALS['egw']->accounts->exists($accountid) == 2) |
| 129 | 129 | { |
| 130 | - $this->account_id = (int) $accountid; |
|
| 130 | + $this->account_id = (int)$accountid; |
|
| 131 | 131 | } |
| 132 | 132 | else |
| 133 | 133 | { |
| 134 | - $this->account_id = (int) get_account_id($accountid); |
|
| 134 | + $this->account_id = (int)get_account_id($accountid); |
|
| 135 | 135 | $this->global_owners = $this->account_id ? $GLOBALS['egw']->accounts->memberships($this->account_id, true) : array(); |
| 136 | 136 | $this->global_owners[] = self::GLOBAL_ACCOUNT; |
| 137 | 137 | } |
| 138 | - $this->app_name = $app_name; |
|
| 139 | - $this->db = $GLOBALS['egw']->db; |
|
| 138 | + $this->app_name = $app_name; |
|
| 139 | + $this->db = $GLOBALS['egw']->db; |
|
| 140 | 140 | |
| 141 | 141 | if (is_null(self::$cache)) // should not be necessary, as cache is load and restored by egw object |
| 142 | 142 | { |
@@ -158,10 +158,10 @@ discard block |
||
| 158 | 158 | { |
| 159 | 159 | $all_children = array_map('intval', (array)$cat_id); |
| 160 | 160 | |
| 161 | - $children = $this->return_array('subs',0,False,'','','',True,$cat_id,-1,'id'); |
|
| 161 | + $children = $this->return_array('subs', 0, False, '', '', '', True, $cat_id, -1, 'id'); |
|
| 162 | 162 | if (is_array($children) && count($children)) |
| 163 | 163 | { |
| 164 | - $all_children = array_merge($all_children,$this->return_all_children($children)); |
|
| 164 | + $all_children = array_merge($all_children, $this->return_all_children($children)); |
|
| 165 | 165 | } |
| 166 | 166 | return $all_children; |
| 167 | 167 | } |
@@ -183,24 +183,24 @@ discard block |
||
| 183 | 183 | * @param array $filter =null array with column-name (without cat_-prefix) => value pairs (! negates the value) |
| 184 | 184 | * @return array of cat-arrays or $column values |
| 185 | 185 | */ |
| 186 | - function return_array($type='all', $start=0, $limit=true, $query='', $sort='ASC',$order='',$globals=false, $parent_id=null, $lastmod=-1, $column='', $filter=null) |
|
| 186 | + function return_array($type = 'all', $start = 0, $limit = true, $query = '', $sort = 'ASC', $order = '', $globals = false, $parent_id = null, $lastmod = -1, $column = '', $filter = null) |
|
| 187 | 187 | { |
| 188 | 188 | //error_log(__METHOD__."($type,$start,$limit,$query,$sort,$order,globals=$globals,parent=".array2string($parent_id).",$lastmod,$column,filter=".array2string($filter).") account_id=$this->account_id, appname=$this->app_name: ".function_backtrace()); |
| 189 | 189 | $cats = array(); |
| 190 | - foreach(self::$cache as $cat) |
|
| 190 | + foreach (self::$cache as $cat) |
|
| 191 | 191 | { |
| 192 | - if ($filter) foreach($filter as $col => $val) |
|
| 192 | + if ($filter) foreach ($filter as $col => $val) |
|
| 193 | 193 | { |
| 194 | 194 | if (!is_array($val) && $val[0] === '!') |
| 195 | 195 | { |
| 196 | 196 | // also match against trimmed database entry on name and description fields |
| 197 | 197 | if (($col == 'name' || $col == 'description') && is_string($cat[$col])) |
| 198 | 198 | { |
| 199 | - if ($cat[$col] == substr($val,1) || trim($cat[$col]) == substr($val,1)) continue 2; |
|
| 199 | + if ($cat[$col] == substr($val, 1) || trim($cat[$col]) == substr($val, 1)) continue 2; |
|
| 200 | 200 | } |
| 201 | 201 | else |
| 202 | 202 | { |
| 203 | - if ($cat[$col] == substr($val,1)) continue 2; |
|
| 203 | + if ($cat[$col] == substr($val, 1)) continue 2; |
|
| 204 | 204 | } |
| 205 | 205 | } |
| 206 | 206 | elseif (is_array($val)) |
@@ -208,11 +208,11 @@ discard block |
||
| 208 | 208 | // also match against trimmed database entry on name and description fields |
| 209 | 209 | if (($col == 'name' || $col == 'description') && is_string($cat[$col])) |
| 210 | 210 | { |
| 211 | - if (!in_array($cat[$col],$val) && !in_array(trim($cat[$col]),$val)) continue 2; |
|
| 211 | + if (!in_array($cat[$col], $val) && !in_array(trim($cat[$col]), $val)) continue 2; |
|
| 212 | 212 | } |
| 213 | 213 | else |
| 214 | 214 | { |
| 215 | - if (!in_array($cat[$col],$val)) continue 2; |
|
| 215 | + if (!in_array($cat[$col], $val)) continue 2; |
|
| 216 | 216 | } |
| 217 | 217 | } |
| 218 | 218 | else |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | } |
| 230 | 230 | } |
| 231 | 231 | // check if certain parent required |
| 232 | - if ($parent_id && !in_array($cat['parent'],(array)$parent_id)) continue; |
|
| 232 | + if ($parent_id && !in_array($cat['parent'], (array)$parent_id)) continue; |
|
| 233 | 233 | |
| 234 | 234 | // return global categories just if $globals is set |
| 235 | 235 | if (!$globals && $cat['appname'] == self::GLOBAL_APPNAME) |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | // check for read permission |
| 241 | - if(!$this->check_perms(Acl::READ, $cat, $globals === 'all_no_acl')) |
|
| 241 | + if (!$this->check_perms(Acl::READ, $cat, $globals === 'all_no_acl')) |
|
| 242 | 242 | { |
| 243 | 243 | continue; |
| 244 | 244 | } |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | switch ($type) |
| 248 | 248 | { |
| 249 | 249 | case 'subs': |
| 250 | - if (!$cat['parent']) continue 2; // 2 for switch AND foreach! |
|
| 250 | + if (!$cat['parent']) continue 2; // 2 for switch AND foreach! |
|
| 251 | 251 | break; |
| 252 | 252 | case 'mains': |
| 253 | 253 | if ($cat['parent']) continue 2; |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | // check name and description for $query |
| 270 | - if ($query && stristr($cat['name'],$query) === false && stristr($cat['description'],$query) === false) continue; |
|
| 270 | + if ($query && stristr($cat['name'], $query) === false && stristr($cat['description'], $query) === false) continue; |
|
| 271 | 271 | |
| 272 | 272 | // check if last modified since |
| 273 | 273 | if ($lastmod > 0 && $cat['last_mod'] <= $lastmod) continue; |
@@ -284,37 +284,37 @@ discard block |
||
| 284 | 284 | if (!$sort) $sort = 'ASC'; |
| 285 | 285 | // order the entries if necessary (cache is already ordered in or default order: cat_main, cat_level, cat_name ASC) |
| 286 | 286 | if ($this->total_records > 1 && !empty($order) && |
| 287 | - preg_match('/^[a-zA-Z_(), ]+$/',$order) && preg_match('/^(ASC|DESC|asc|desc)$/',$sort)) |
|
| 287 | + preg_match('/^[a-zA-Z_(), ]+$/', $order) && preg_match('/^(ASC|DESC|asc|desc)$/', $sort)) |
|
| 288 | 288 | { |
| 289 | - if (strstr($order,'cat_data') !== false) $order = 'cat_data'; // sitemgr orders by round(cat_data)! |
|
| 290 | - if (substr($order,0,4) == 'cat_') $order = substr($order,4); |
|
| 289 | + if (strstr($order, 'cat_data') !== false) $order = 'cat_data'; // sitemgr orders by round(cat_data)! |
|
| 290 | + if (substr($order, 0, 4) == 'cat_') $order = substr($order, 4); |
|
| 291 | 291 | $sign = strtoupper($sort) == 'DESC' ? -1 : 1; |
| 292 | 292 | usort($cats, function($a, $b) use ($order, $sign) |
| 293 | 293 | { |
| 294 | - if (in_array($order, array('name','description','appname','app_name'))) |
|
| 294 | + if (in_array($order, array('name', 'description', 'appname', 'app_name'))) |
|
| 295 | 295 | { |
| 296 | 296 | return $sign * strcasecmp($a[$order], $b[$order]); |
| 297 | 297 | } |
| 298 | - return $sign*(int)$a[$order] - $sign*(int)$b[$order]; |
|
| 298 | + return $sign * (int)$a[$order] - $sign * (int)$b[$order]; |
|
| 299 | 299 | }); |
| 300 | 300 | } |
| 301 | 301 | // limit the number of returned rows |
| 302 | 302 | if ($limit) |
| 303 | 303 | { |
| 304 | 304 | if (!is_int($limit)) $limit = (int)$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']; |
| 305 | - $cats = array_slice($cats,(int)$start,$limit); |
|
| 305 | + $cats = array_slice($cats, (int)$start, $limit); |
|
| 306 | 306 | } |
| 307 | 307 | // return only a certain column (why not return is as value?) |
| 308 | 308 | if ($column) |
| 309 | 309 | { |
| 310 | - foreach($cats as $k => $cat) |
|
| 310 | + foreach ($cats as $k => $cat) |
|
| 311 | 311 | { |
| 312 | 312 | $cats[$k] = $cat[$column]; |
| 313 | 313 | } |
| 314 | 314 | } |
| 315 | 315 | //error_log(__METHOD__."($type,$start,$limit,$query,$sort,$order,$globals,parent=".array2string($parent_id).",$lastmod,$column,filter=".array2string($filter).",$unserialize_data) account_id=$this->account_id, appname=$this->app_name = ".array2string($cats)); |
| 316 | 316 | |
| 317 | - reset($cats); // some old code (eg. sitemgr) relies on the array-pointer! |
|
| 317 | + reset($cats); // some old code (eg. sitemgr) relies on the array-pointer! |
|
| 318 | 318 | return $cats; |
| 319 | 319 | } |
| 320 | 320 | |
@@ -332,7 +332,7 @@ discard block |
||
| 332 | 332 | * @param boolean $unserialize_data =true return $cat['data'] as array (not serialized array) |
| 333 | 333 | * @return array with cats |
| 334 | 334 | */ |
| 335 | - function return_sorted_array($start=0,$limit=True,$query='',$sort='ASC',$order='cat_name',$globals=False, $parent_id=0,$unserialize_data=true,$filter=null) |
|
| 335 | + function return_sorted_array($start = 0, $limit = True, $query = '', $sort = 'ASC', $order = 'cat_name', $globals = False, $parent_id = 0, $unserialize_data = true, $filter = null) |
|
| 336 | 336 | { |
| 337 | 337 | if (!$sort) $sort = 'ASC'; |
| 338 | 338 | if (!$order) $order = 'cat_name'; |
@@ -342,27 +342,27 @@ discard block |
||
| 342 | 342 | $parents = $cats = array(); |
| 343 | 343 | |
| 344 | 344 | // Cast parent_id to array, but only if there is one |
| 345 | - if($parent_id !== false && $parent_id !== null) $parent_id = (array)$parent_id; |
|
| 346 | - if (!($cats = $this->return_array('all',0,false,$query,$sort,$order,$globals,$parent_id,-1,'',$filter,$unserialize_data))) |
|
| 345 | + if ($parent_id !== false && $parent_id !== null) $parent_id = (array)$parent_id; |
|
| 346 | + if (!($cats = $this->return_array('all', 0, false, $query, $sort, $order, $globals, $parent_id, -1, '', $filter, $unserialize_data))) |
|
| 347 | 347 | { |
| 348 | 348 | $cats = array(); |
| 349 | 349 | } |
| 350 | - foreach($cats as $cat) |
|
| 350 | + foreach ($cats as $cat) |
|
| 351 | 351 | { |
| 352 | 352 | $parents[] = $cat['id']; |
| 353 | 353 | } |
| 354 | 354 | |
| 355 | - if($parent_id || !$cats) // Avoid wiping search results |
|
| 355 | + if ($parent_id || !$cats) // Avoid wiping search results |
|
| 356 | 356 | { |
| 357 | 357 | // Go find the children |
| 358 | 358 | while (count($parents)) |
| 359 | 359 | { |
| 360 | - if (!($subs = $this->return_array('all',0,false,$query,$sort,$order,$globals,$parents,-1,'',$filter,$unserialize_data))) |
|
| 360 | + if (!($subs = $this->return_array('all', 0, false, $query, $sort, $order, $globals, $parents, -1, '', $filter, $unserialize_data))) |
|
| 361 | 361 | { |
| 362 | 362 | break; |
| 363 | 363 | } |
| 364 | 364 | $parents = $children = array(); |
| 365 | - foreach($subs as $cat) |
|
| 365 | + foreach ($subs as $cat) |
|
| 366 | 366 | { |
| 367 | 367 | $parents[] = $cat['id']; |
| 368 | 368 | $children[$cat['parent']][] = $cat; |
@@ -372,12 +372,12 @@ discard block |
||
| 372 | 372 | { |
| 373 | 373 | $cats2 = $cats; |
| 374 | 374 | $cats = array(); |
| 375 | - foreach($cats2 as $cat) |
|
| 375 | + foreach ($cats2 as $cat) |
|
| 376 | 376 | { |
| 377 | 377 | $cats[] = $cat; |
| 378 | 378 | if (isset($children[$cat['id']])) |
| 379 | 379 | { |
| 380 | - foreach($children[$cat['id']] as $child) |
|
| 380 | + foreach ($children[$cat['id']] as $child) |
|
| 381 | 381 | { |
| 382 | 382 | $cats[] = $child; |
| 383 | 383 | } |
@@ -392,9 +392,9 @@ discard block |
||
| 392 | 392 | if ($limit) |
| 393 | 393 | { |
| 394 | 394 | if (!is_int($limit)) $limit = (int)$GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']; |
| 395 | - $cats = array_slice($cats,(int)$start,$limit); |
|
| 395 | + $cats = array_slice($cats, (int)$start, $limit); |
|
| 396 | 396 | } |
| 397 | - reset($cats); // some old code (eg. sitemgr) relies on the array-pointer! |
|
| 397 | + reset($cats); // some old code (eg. sitemgr) relies on the array-pointer! |
|
| 398 | 398 | return $cats; |
| 399 | 399 | } |
| 400 | 400 | |
@@ -415,7 +415,7 @@ discard block |
||
| 415 | 415 | if (!isset(self::$cache[$id])) return false; |
| 416 | 416 | |
| 417 | 417 | $cat = self::$cache[$id]; |
| 418 | - $cat['data'] = $cat['data'] ? ((($arr=json_php_unserialize($cat['data'], true)) !== false || $cat['data'] === 'b:0;') ? |
|
| 418 | + $cat['data'] = $cat['data'] ? ((($arr = json_php_unserialize($cat['data'], true)) !== false || $cat['data'] === 'b:0;') ? |
|
| 419 | 419 | $arr : $cat['data']) : array(); |
| 420 | 420 | |
| 421 | 421 | return $cat; |
@@ -433,31 +433,31 @@ discard block |
||
| 433 | 433 | { |
| 434 | 434 | if ((int)$values['parent'] > 0) |
| 435 | 435 | { |
| 436 | - $values['level'] = $this->id2name($values['parent'],'level')+1; |
|
| 437 | - $values['main'] = $this->id2name($values['parent'],'main'); |
|
| 436 | + $values['level'] = $this->id2name($values['parent'], 'level') + 1; |
|
| 437 | + $values['main'] = $this->id2name($values['parent'], 'main'); |
|
| 438 | 438 | } |
| 439 | 439 | else |
| 440 | 440 | { |
| 441 | 441 | $values['level'] = 0; |
| 442 | 442 | } |
| 443 | - $this->db->insert(self::TABLE,$cat=array( |
|
| 443 | + $this->db->insert(self::TABLE, $cat = array( |
|
| 444 | 444 | 'cat_parent' => $values['parent'], |
| 445 | 445 | 'cat_owner' => isset($values['owner']) ? $values['owner'] : $this->account_id, |
| 446 | 446 | 'cat_access' => isset($values['access']) ? $values['access'] : 'public', |
| 447 | 447 | 'cat_appname' => $this->app_name, |
| 448 | 448 | 'cat_name' => $values['name'], |
| 449 | - 'cat_description' => isset($values['description']) ? $values['description'] : $values['descr'], // support old name different from returned one |
|
| 449 | + 'cat_description' => isset($values['description']) ? $values['description'] : $values['descr'], // support old name different from returned one |
|
| 450 | 450 | 'cat_data' => is_array($values['data']) ? json_encode($values['data']) : $values['data'], |
| 451 | 451 | 'cat_main' => $values['main'], |
| 452 | 452 | 'cat_level' => $values['level'], |
| 453 | 453 | 'last_mod' => time(), |
| 454 | - ),(int)$values['id'] > 0 ? array('cat_id' => $values['id']) : array(),__LINE__,__FILE__); |
|
| 454 | + ), (int)$values['id'] > 0 ? array('cat_id' => $values['id']) : array(), __LINE__, __FILE__); |
|
| 455 | 455 | |
| 456 | - $cat['cat_id'] = $id = (int)$values['id'] > 0 ? (int)$values['id'] : $this->db->get_last_insert_id(self::TABLE,'cat_id'); |
|
| 456 | + $cat['cat_id'] = $id = (int)$values['id'] > 0 ? (int)$values['id'] : $this->db->get_last_insert_id(self::TABLE, 'cat_id'); |
|
| 457 | 457 | |
| 458 | 458 | if (!(int)$values['parent'] && $id != $values['main']) |
| 459 | 459 | { |
| 460 | - $this->db->update(self::TABLE,array('cat_main' => $id),array('cat_id' => $id),__LINE__,__FILE__); |
|
| 460 | + $this->db->update(self::TABLE, array('cat_main' => $id), array('cat_id' => $id), __LINE__, __FILE__); |
|
| 461 | 461 | $cat['cat_main'] = $id; |
| 462 | 462 | } |
| 463 | 463 | // update cache accordingly |
@@ -479,20 +479,20 @@ discard block |
||
| 479 | 479 | if (empty($cat_list)) return $cat_list; |
| 480 | 480 | if (is_array($cat_list)) |
| 481 | 481 | { |
| 482 | - $cat_list = implode(',',$cat_list); |
|
| 482 | + $cat_list = implode(',', $cat_list); |
|
| 483 | 483 | //error_log(__METHOD__.__LINE__.' string expected, array found for cat_list. Converted to:'.$cat_list); |
| 484 | 484 | } |
| 485 | - $cat_arr = explode(',',$cat_list); |
|
| 485 | + $cat_arr = explode(',', $cat_list); |
|
| 486 | 486 | if (!empty($cat_arr) && is_array($cat_arr) && count($cat_arr) > 0) |
| 487 | 487 | { |
| 488 | - foreach($cat_arr as $id=>$cat_id) |
|
| 488 | + foreach ($cat_arr as $id=>$cat_id) |
|
| 489 | 489 | { |
| 490 | 490 | if (!$this->check_perms($needed, $cat_id, false, $needed == Acl::READ)) // allow reading all global cats |
| 491 | 491 | { |
| 492 | 492 | unset($cat_arr[$id]); |
| 493 | 493 | } |
| 494 | 494 | } |
| 495 | - $cat_list = implode(',',$cat_arr); |
|
| 495 | + $cat_list = implode(',', $cat_arr); |
|
| 496 | 496 | } |
| 497 | 497 | |
| 498 | 498 | return $cat_list; |
@@ -509,7 +509,7 @@ discard block |
||
| 509 | 509 | * @param boolean $allow_global_read if true, global cats are allowed (independent of app) for reading |
| 510 | 510 | * @return boolean true permission granted, false for permission denied, null for category does not exist |
| 511 | 511 | */ |
| 512 | - public function check_perms($needed, $category, $no_acl_check=false, $allow_global_read=false) |
|
| 512 | + public function check_perms($needed, $category, $no_acl_check = false, $allow_global_read = false) |
|
| 513 | 513 | { |
| 514 | 514 | if (!is_array($category) && !($category = self::read($category))) |
| 515 | 515 | { |
@@ -525,8 +525,8 @@ discard block |
||
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | // Read access to global categories |
| 528 | - if ($needed == Acl::READ && (($is_global=array_intersect(explode(',',$category['owner']),$this->global_owners)) || |
|
| 529 | - $no_acl_check && $category['access'] == 'public') && // no_acl_check only means public cats |
|
| 528 | + if ($needed == Acl::READ && (($is_global = array_intersect(explode(',', $category['owner']), $this->global_owners)) || |
|
| 529 | + $no_acl_check && $category['access'] == 'public') && // no_acl_check only means public cats |
|
| 530 | 530 | ($category['appname'] == self::GLOBAL_APPNAME || $category['appname'] == $this->app_name || |
| 531 | 531 | $is_global && $allow_global_read)) |
| 532 | 532 | { |
@@ -549,16 +549,16 @@ discard block |
||
| 549 | 549 | // Load the application grants |
| 550 | 550 | if ($category['appname'] == $this->app_name && is_null($this->grants)) |
| 551 | 551 | { |
| 552 | - $this->grants = $GLOBALS['egw']->acl->get_grants($this->app_name,true); |
|
| 552 | + $this->grants = $GLOBALS['egw']->acl->get_grants($this->app_name, true); |
|
| 553 | 553 | } |
| 554 | 554 | |
| 555 | 555 | // Check for ACL granted access, the self::GLOBAL_ACCOUNT user must not get access by ACL to keep old behaviour |
| 556 | 556 | $acl_grant = $this->account_id != self::GLOBAL_ACCOUNT && $category['appname'] == $this->app_name; |
| 557 | 557 | $owner_grant = false; |
| 558 | - foreach(explode(',',$category['owner']) as $owner) |
|
| 558 | + foreach (explode(',', $category['owner']) as $owner) |
|
| 559 | 559 | { |
| 560 | - $owner_grant = $owner_grant || (($this->grants[$owner] & $needed) && |
|
| 561 | - ($category['access'] == 'public' || ($this->grants[$owner] & Acl::PRIVAT))); |
|
| 560 | + $owner_grant = $owner_grant || (($this->grants[$owner]&$needed) && |
|
| 561 | + ($category['access'] == 'public' || ($this->grants[$owner]&Acl::PRIVAT))); |
|
| 562 | 562 | } |
| 563 | 563 | return $acl_grant && $owner_grant; |
| 564 | 564 | } |
@@ -575,35 +575,35 @@ discard block |
||
| 575 | 575 | //error_log(__METHOD__."(".array2string($cat_id).', drop_subs='.array2string($drop_subs).', modify_subs='.array2string($modify_subs).') '.function_backtrace()); |
| 576 | 576 | if ($modify_subs) |
| 577 | 577 | { |
| 578 | - $new_parent = $this->id2name($cat_id,'parent'); |
|
| 578 | + $new_parent = $this->id2name($cat_id, 'parent'); |
|
| 579 | 579 | |
| 580 | - foreach ((array) $this->return_sorted_array('',False,'','','',False, $cat_id) as $cat) |
|
| 580 | + foreach ((array)$this->return_sorted_array('', False, '', '', '', False, $cat_id) as $cat) |
|
| 581 | 581 | { |
| 582 | 582 | if ($cat['level'] == 1) |
| 583 | 583 | { |
| 584 | - $this->db->update(self::TABLE,array( |
|
| 584 | + $this->db->update(self::TABLE, array( |
|
| 585 | 585 | 'cat_level' => 0, |
| 586 | 586 | 'cat_parent' => 0, |
| 587 | 587 | 'cat_main' => $cat['id'], |
| 588 | - ),array( |
|
| 588 | + ), array( |
|
| 589 | 589 | 'cat_id' => $cat['id'], |
| 590 | 590 | 'cat_appname' => $this->app_name, |
| 591 | - ),__LINE__,__FILE__); |
|
| 591 | + ), __LINE__, __FILE__); |
|
| 592 | 592 | |
| 593 | 593 | $new_main = $cat['id']; |
| 594 | 594 | } |
| 595 | 595 | else |
| 596 | 596 | { |
| 597 | - $update = array('cat_level' => $cat['level']-1); |
|
| 597 | + $update = array('cat_level' => $cat['level'] - 1); |
|
| 598 | 598 | |
| 599 | 599 | if ($new_main) $update['cat_main'] = $new_main; |
| 600 | 600 | |
| 601 | 601 | if ($cat['parent'] == $cat_id) $update['cat_parent'] = $new_parent; |
| 602 | 602 | |
| 603 | - $this->db->update(self::TABLE,$update,array( |
|
| 603 | + $this->db->update(self::TABLE, $update, array( |
|
| 604 | 604 | 'cat_id' => $cat['id'], |
| 605 | 605 | 'cat_appname' => $this->app_name, |
| 606 | - ),__LINE__,__FILE__); |
|
| 606 | + ), __LINE__, __FILE__); |
|
| 607 | 607 | } |
| 608 | 608 | } |
| 609 | 609 | } |
@@ -624,16 +624,16 @@ discard block |
||
| 624 | 624 | 'modify_subs' => $modify_subs, |
| 625 | 625 | 'location' => 'delete_category' |
| 626 | 626 | ); |
| 627 | - if($this->is_global($cat_id, true)) // true = application global (otherwise eg. global addressbook categories call all apps) |
|
| 627 | + if ($this->is_global($cat_id, true)) // true = application global (otherwise eg. global addressbook categories call all apps) |
|
| 628 | 628 | { |
| 629 | - Hooks::process($GLOBALS['hook_values'],False,True); // called for every app now, not only enabled ones) |
|
| 629 | + Hooks::process($GLOBALS['hook_values'], False, True); // called for every app now, not only enabled ones) |
|
| 630 | 630 | } |
| 631 | 631 | else |
| 632 | 632 | { |
| 633 | - Hooks::single($GLOBALS['hook_values'], self::id2name($cat_id,'appname')); |
|
| 633 | + Hooks::single($GLOBALS['hook_values'], self::id2name($cat_id, 'appname')); |
|
| 634 | 634 | } |
| 635 | 635 | |
| 636 | - $this->db->delete(self::TABLE,$where,__LINE__,__FILE__); |
|
| 636 | + $this->db->delete(self::TABLE, $where, __LINE__, __FILE__); |
|
| 637 | 637 | |
| 638 | 638 | // update cache accordingly |
| 639 | 639 | self::invalidate_cache($modify_subs ? null : $where['cat_id']); |
@@ -649,17 +649,17 @@ discard block |
||
| 649 | 649 | */ |
| 650 | 650 | function adapt_level_in_subtree($values) |
| 651 | 651 | { |
| 652 | - foreach ((array) $this->return_sorted_array('',False,'','','',False, $values['id']) as $cat) |
|
| 652 | + foreach ((array)$this->return_sorted_array('', False, '', '', '', False, $values['id']) as $cat) |
|
| 653 | 653 | { |
| 654 | 654 | if ($cat['parent'] == $values['id']) |
| 655 | 655 | { |
| 656 | - $this->db->update(self::TABLE,array( |
|
| 657 | - 'cat_level' => $values['level']+1, |
|
| 656 | + $this->db->update(self::TABLE, array( |
|
| 657 | + 'cat_level' => $values['level'] + 1, |
|
| 658 | 658 | 'last_mod' => time(), |
| 659 | - ),array( |
|
| 659 | + ), array( |
|
| 660 | 660 | 'cat_id' => $cat['id'], |
| 661 | 661 | 'cat_appname' => $this->app_name, |
| 662 | - ),__LINE__,__FILE__); |
|
| 662 | + ), __LINE__, __FILE__); |
|
| 663 | 663 | $cat['level'] = $values['level'] + 1; |
| 664 | 664 | self::invalidate_cache($cat['id']); |
| 665 | 665 | $this->adapt_level_in_subtree($cat); |
@@ -680,14 +680,14 @@ discard block |
||
| 680 | 680 | function check_consistency4update($values) |
| 681 | 681 | { |
| 682 | 682 | // check if we try to move an element down its own subtree, which will fail |
| 683 | - foreach ($this->return_sorted_array('',False,'','','',False, $values['id']) as $cat) |
|
| 683 | + foreach ($this->return_sorted_array('', False, '', '', '', False, $values['id']) as $cat) |
|
| 684 | 684 | { |
| 685 | 685 | if ($cat['id'] == $values['parent']) return lang('Cannot set a category as parent, which is part of this categorys subtree!'); |
| 686 | 686 | } |
| 687 | 687 | // check if we try to be our own parent |
| 688 | - if ($values['parent']==$values['id']) return lang('Cannot set this cat as its own parent!'); // deny to be our own parent |
|
| 688 | + if ($values['parent'] == $values['id']) return lang('Cannot set this cat as its own parent!'); // deny to be our own parent |
|
| 689 | 689 | // check if parent still exists |
| 690 | - if ((int)$values['parent']>0 && !$this->read($values['parent'])) return lang('Chosen parent category no longer exists'); |
|
| 690 | + if ((int)$values['parent'] > 0 && !$this->read($values['parent'])) return lang('Chosen parent category no longer exists'); |
|
| 691 | 691 | return true; |
| 692 | 692 | } |
| 693 | 693 | |
@@ -706,7 +706,7 @@ discard block |
||
| 706 | 706 | $ret = $this->check_consistency4update($values); |
| 707 | 707 | if ($ret !== true) throw new Exception\WrongUserinput($ret); |
| 708 | 708 | // everything seems in order -> proceed |
| 709 | - $values['level'] = ($values['parent'] ? $this->id2name($values['parent'],'level')+1:0); |
|
| 709 | + $values['level'] = ($values['parent'] ? $this->id2name($values['parent'], 'level') + 1 : 0); |
|
| 710 | 710 | $this->adapt_level_in_subtree($values); |
| 711 | 711 | |
| 712 | 712 | return $this->add($values); |
@@ -720,8 +720,8 @@ discard block |
||
| 720 | 720 | if ($ret !== true) throw new Exception\WrongUserinput($ret); |
| 721 | 721 | |
| 722 | 722 | // everything seems in order -> proceed |
| 723 | - $values['main'] = $this->id2name($values['parent'],'main'); |
|
| 724 | - $values['level'] = $this->id2name($values['parent'],'level') + 1; |
|
| 723 | + $values['main'] = $this->id2name($values['parent'], 'main'); |
|
| 724 | + $values['level'] = $this->id2name($values['parent'], 'level') + 1; |
|
| 725 | 725 | } |
| 726 | 726 | else |
| 727 | 727 | { |
@@ -732,9 +732,9 @@ discard block |
||
| 732 | 732 | // adapt the level info in each child |
| 733 | 733 | $this->adapt_level_in_subtree($values); |
| 734 | 734 | } |
| 735 | - $this->db->update(self::TABLE,$cat=array( |
|
| 735 | + $this->db->update(self::TABLE, $cat = array( |
|
| 736 | 736 | 'cat_name' => $values['name'], |
| 737 | - 'cat_description' => isset($values['description']) ? $values['description'] : $values['descr'], // support old name different from the one read |
|
| 737 | + 'cat_description' => isset($values['description']) ? $values['description'] : $values['descr'], // support old name different from the one read |
|
| 738 | 738 | 'cat_data' => is_array($values['data']) ? json_encode($values['data']) : $values['data'], |
| 739 | 739 | 'cat_parent' => $values['parent'], |
| 740 | 740 | 'cat_access' => $values['access'], |
@@ -742,10 +742,10 @@ discard block |
||
| 742 | 742 | 'cat_main' => $values['main'], |
| 743 | 743 | 'cat_level' => $values['level'], |
| 744 | 744 | 'last_mod' => time(), |
| 745 | - ),array( |
|
| 745 | + ), array( |
|
| 746 | 746 | 'cat_id' => $values['id'], |
| 747 | 747 | 'cat_appname' => $this->app_name, |
| 748 | - ),__LINE__,__FILE__); |
|
| 748 | + ), __LINE__, __FILE__); |
|
| 749 | 749 | |
| 750 | 750 | $cat['cat_id'] = $values['id']; |
| 751 | 751 | $cat['cat_appname'] = $this->app_name; |
@@ -769,9 +769,9 @@ discard block |
||
| 769 | 769 | * @param boolean|string $strip =false if true, strips 'X-' ($strip) from category names added by some SyncML clients |
| 770 | 770 | * @return int cat-id or 0 if not found |
| 771 | 771 | */ |
| 772 | - function name2id($cat_name, $strip=false) |
|
| 772 | + function name2id($cat_name, $strip = false) |
|
| 773 | 773 | { |
| 774 | - static $cache = array(); // a litle bit of caching |
|
| 774 | + static $cache = array(); // a litle bit of caching |
|
| 775 | 775 | |
| 776 | 776 | if (isset($cache[$cat_name])) return $cache[$cat_name]; |
| 777 | 777 | |
@@ -792,17 +792,17 @@ discard block |
||
| 792 | 792 | $cats[] = $stripped_cat_name; |
| 793 | 793 | } |
| 794 | 794 | |
| 795 | - if (!($cats = $this->return_array('all',0,false,'','','',true,null,-1,'',array( |
|
| 795 | + if (!($cats = $this->return_array('all', 0, false, '', '', '', true, null, -1, '', array( |
|
| 796 | 796 | 'name' => $cats, |
| 797 | 797 | 'appname' => array($this->app_name, self::GLOBAL_APPNAME), |
| 798 | 798 | )))) |
| 799 | 799 | { |
| 800 | - return 0; // cat not found, dont cache it, as it might be created in this request |
|
| 800 | + return 0; // cat not found, dont cache it, as it might be created in this request |
|
| 801 | 801 | } |
| 802 | 802 | if (count($cats) > 1) |
| 803 | 803 | { |
| 804 | 804 | // if more the one cat matches we weight them by: exact name match; own, global, other users cat; appplication cats |
| 805 | - foreach($cats as $k => $cat) |
|
| 805 | + foreach ($cats as $k => $cat) |
|
| 806 | 806 | { |
| 807 | 807 | $cats[$k]['weight'] = 100 * ($cat['name'] == $cat_name) + |
| 808 | 808 | 10 * ($cat['owner'] == $this->account_id ? 3 : ($cat['owner'] <= self::GLOBAL_ACCOUNT ? 2 : 1)) + |
@@ -814,7 +814,7 @@ discard block |
||
| 814 | 814 | return $b['weight'] - $a['weight']; |
| 815 | 815 | }); |
| 816 | 816 | } |
| 817 | - return $cache[$cat['cat_name']] = (int) $cats[0]['id']; |
|
| 817 | + return $cache[$cat['cat_name']] = (int)$cats[0]['id']; |
|
| 818 | 818 | } |
| 819 | 819 | |
| 820 | 820 | /** |
@@ -824,12 +824,12 @@ discard block |
||
| 824 | 824 | * @param boolean $application_global =false true check for application global categories only (appname == 'phpgw') |
| 825 | 825 | * @return boolean |
| 826 | 826 | */ |
| 827 | - static function is_global($cat,$application_global=false) |
|
| 827 | + static function is_global($cat, $application_global = false) |
|
| 828 | 828 | { |
| 829 | - if (!is_array($cat) && !($cat = self::read($cat))) return null; // cat not found |
|
| 829 | + if (!is_array($cat) && !($cat = self::read($cat))) return null; // cat not found |
|
| 830 | 830 | |
| 831 | 831 | $global_owner = false; |
| 832 | - foreach(explode(',',$cat['owner']) as $owner) |
|
| 832 | + foreach (explode(',', $cat['owner']) as $owner) |
|
| 833 | 833 | { |
| 834 | 834 | $global_owner = $global_owner || $owner <= self::GLOBAL_ACCOUNT; |
| 835 | 835 | } |
@@ -846,9 +846,9 @@ discard block |
||
| 846 | 846 | * @param string $item ='name' requested information, 'path' = / delimited path of category names (incl. parents) |
| 847 | 847 | * @return string information or '--' if not found or !$cat_id |
| 848 | 848 | */ |
| 849 | - static function id2name($cat_id=0, $item='name') |
|
| 849 | + static function id2name($cat_id = 0, $item = 'name') |
|
| 850 | 850 | { |
| 851 | - if(!$cat_id) return '--'; |
|
| 851 | + if (!$cat_id) return '--'; |
|
| 852 | 852 | if (!$item) $item = 'parent'; |
| 853 | 853 | |
| 854 | 854 | if (is_null(self::$cache)) self::init_cache(); |
@@ -858,7 +858,7 @@ discard block |
||
| 858 | 858 | { |
| 859 | 859 | if ($cat['parent']) |
| 860 | 860 | { |
| 861 | - return self::id2name($cat['parent'],'path').' / '.$cat['name']; |
|
| 861 | + return self::id2name($cat['parent'], 'path').' / '.$cat['name']; |
|
| 862 | 862 | } |
| 863 | 863 | $item = 'name'; |
| 864 | 864 | } |
@@ -887,7 +887,7 @@ discard block |
||
| 887 | 887 | * @param int $parent =0 category id of parent |
| 888 | 888 | * @return int/boolean cat_id or false if cat not exists |
| 889 | 889 | */ |
| 890 | - function exists($type,$cat_name = '',$cat_id = 0,$parent = 0) |
|
| 890 | + function exists($type, $cat_name = '', $cat_id = 0, $parent = 0) |
|
| 891 | 891 | { |
| 892 | 892 | if ($cat_name) |
| 893 | 893 | { |
@@ -898,7 +898,7 @@ discard block |
||
| 898 | 898 | { |
| 899 | 899 | $filter['id'] = $cat_id; |
| 900 | 900 | } |
| 901 | - if (!($cats = $this->return_array($type,0,false,'','','',true,$parent,-1,'id',$filter))) |
|
| 901 | + if (!($cats = $this->return_array($type, 0, false, '', '', '', true, $parent, -1, 'id', $filter))) |
|
| 902 | 902 | { |
| 903 | 903 | $ret = false; |
| 904 | 904 | } |
@@ -917,7 +917,7 @@ discard block |
||
| 917 | 917 | * @param int $to =0 new owner or 0 to delete the cats |
| 918 | 918 | * @param string $app ='' if given only cats matching $app are modifed/deleted |
| 919 | 919 | */ |
| 920 | - function change_owner($owner,$to=0,$app='') |
|
| 920 | + function change_owner($owner, $to = 0, $app = '') |
|
| 921 | 921 | { |
| 922 | 922 | $where = array('cat_owner' => $owner); |
| 923 | 923 | |
@@ -925,11 +925,11 @@ discard block |
||
| 925 | 925 | |
| 926 | 926 | if ((int)$to) |
| 927 | 927 | { |
| 928 | - $this->db->update(self::TABLE,array('cat_owner' => $to),$where,__LINE__,__FILE__); |
|
| 928 | + $this->db->update(self::TABLE, array('cat_owner' => $to), $where, __LINE__, __FILE__); |
|
| 929 | 929 | } |
| 930 | 930 | else |
| 931 | 931 | { |
| 932 | - $this->db->delete(self::TABLE,$where,__LINE__,__FILE__); |
|
| 932 | + $this->db->delete(self::TABLE, $where, __LINE__, __FILE__); |
|
| 933 | 933 | } |
| 934 | 934 | // update cache accordingly |
| 935 | 935 | self::invalidate_cache(); |
@@ -947,10 +947,10 @@ discard block |
||
| 947 | 947 | if (is_null(self::$cache)) |
| 948 | 948 | { |
| 949 | 949 | // check if we are already updated to global owner == 0, if not do it now |
| 950 | - if (!$GLOBALS['egw']->db->select(self::TABLE,'COUNT(*)',array('cat_owner'=>'0'),__LINE__,__FILE__)->fetchColumn()) |
|
| 950 | + if (!$GLOBALS['egw']->db->select(self::TABLE, 'COUNT(*)', array('cat_owner'=>'0'), __LINE__, __FILE__)->fetchColumn()) |
|
| 951 | 951 | { |
| 952 | - $GLOBALS['egw']->db->update(self::TABLE,array('cat_owner'=>'0'),"(cat_owner='-1' OR cat_appname='phpgw')",__LINE__,__FILE__); |
|
| 953 | - $GLOBALS['egw']->db->insert(self::TABLE,array( |
|
| 952 | + $GLOBALS['egw']->db->update(self::TABLE, array('cat_owner'=>'0'), "(cat_owner='-1' OR cat_appname='phpgw')", __LINE__, __FILE__); |
|
| 953 | + $GLOBALS['egw']->db->insert(self::TABLE, array( |
|
| 954 | 954 | 'cat_main' => 0, |
| 955 | 955 | 'cat_parent' => 0, |
| 956 | 956 | 'cat_level' => 0, |
@@ -959,15 +959,15 @@ discard block |
||
| 959 | 959 | 'cat_name' => 'global=0', |
| 960 | 960 | 'cat_description' => 'global=0', |
| 961 | 961 | 'last_mod' => time(), |
| 962 | - ),false,__LINE__,__FILE__); |
|
| 962 | + ), false, __LINE__, __FILE__); |
|
| 963 | 963 | } |
| 964 | 964 | self::$cache = array(); |
| 965 | 965 | // read all cats (cant use $this->db!) |
| 966 | - foreach($GLOBALS['egw']->db->select(self::TABLE,'*',false,__LINE__,__FILE__, |
|
| 967 | - false,'ORDER BY cat_main, cat_level, cat_name ASC') as $cat) |
|
| 966 | + foreach ($GLOBALS['egw']->db->select(self::TABLE, '*', false, __LINE__, __FILE__, |
|
| 967 | + false, 'ORDER BY cat_main, cat_level, cat_name ASC') as $cat) |
|
| 968 | 968 | { |
| 969 | - $cat = Db::strip_array_keys($cat,'cat_'); |
|
| 970 | - if ($cat['appname'] == '*update*') continue; // --> ignore update marker |
|
| 969 | + $cat = Db::strip_array_keys($cat, 'cat_'); |
|
| 970 | + if ($cat['appname'] == '*update*') continue; // --> ignore update marker |
|
| 971 | 971 | $cat['app_name'] = $cat['appname']; |
| 972 | 972 | // backlink children to their parent |
| 973 | 973 | if ($cat['parent']) |
@@ -977,7 +977,7 @@ discard block |
||
| 977 | 977 | if (isset(self::$cache[$cat['id']])) |
| 978 | 978 | { |
| 979 | 979 | $cat['children'] = self::$cache[$cat['id']]['children']; |
| 980 | - unset(self::$cache[$cat['id']]); // otherwise the order gets messed up! |
|
| 980 | + unset(self::$cache[$cat['id']]); // otherwise the order gets messed up! |
|
| 981 | 981 | } |
| 982 | 982 | self::$cache[$cat['id']] = $cat; |
| 983 | 983 | } |
@@ -994,7 +994,7 @@ discard block |
||
| 994 | 994 | * |
| 995 | 995 | * @param int|array $cat concerned id(s) or array with cat-data or null for all cats |
| 996 | 996 | */ |
| 997 | - public static function invalidate_cache($cat=null) |
|
| 997 | + public static function invalidate_cache($cat = null) |
|
| 998 | 998 | { |
| 999 | 999 | //error_log(__METHOD__."(".array2string($cat).') '.function_backtrace()); |
| 1000 | 1000 | |
@@ -1006,12 +1006,12 @@ discard block |
||
| 1006 | 1006 | { |
| 1007 | 1007 | if (!is_array($cat) || isset($cat[0])) |
| 1008 | 1008 | { |
| 1009 | - foreach((array)$cat as $cat_id) |
|
| 1009 | + foreach ((array)$cat as $cat_id) |
|
| 1010 | 1010 | { |
| 1011 | 1011 | unset(self::$cache[$cat_id]); |
| 1012 | 1012 | } |
| 1013 | 1013 | } |
| 1014 | - elseif($cat['id']) |
|
| 1014 | + elseif ($cat['id']) |
|
| 1015 | 1015 | { |
| 1016 | 1016 | self::$cache[$cat['id']] = $cat; |
| 1017 | 1017 | } |
@@ -1034,8 +1034,8 @@ discard block |
||
| 1034 | 1034 | */ |
| 1035 | 1035 | public static function css($appname) |
| 1036 | 1036 | { |
| 1037 | - $cats = new Categories('',$appname); |
|
| 1038 | - $last_mod = $cats->return_array('all',0,1,'','DESC','last_mod', $appname == self::GLOBAL_APPNAME); |
|
| 1037 | + $cats = new Categories('', $appname); |
|
| 1038 | + $last_mod = $cats->return_array('all', 0, 1, '', 'DESC', 'last_mod', $appname == self::GLOBAL_APPNAME); |
|
| 1039 | 1039 | $time = count($last_mod) ? $last_mod[0]['last_mod'] : time(); |
| 1040 | 1040 | $path = '/api/categories.php?app='.$appname.'&'.$time; |
| 1041 | 1041 | Framework::includeCSS($path); |
@@ -1065,7 +1065,7 @@ discard block |
||
| 1065 | 1065 | return $cat2color[$cats]; |
| 1066 | 1066 | } |
| 1067 | 1067 | |
| 1068 | - foreach(explode(',', $cats) as $cat) |
|
| 1068 | + foreach (explode(',', $cats) as $cat) |
|
| 1069 | 1069 | { |
| 1070 | 1070 | if (isset($cat2color[$cat])) |
| 1071 | 1071 | { |
@@ -1088,13 +1088,13 @@ discard block |
||
| 1088 | 1088 | * @param int $new_owner =null for users data can be transfered to new owner |
| 1089 | 1089 | * @return int number of deleted or modified categories |
| 1090 | 1090 | */ |
| 1091 | - public static function delete_account($account_id, $new_owner=null) |
|
| 1091 | + public static function delete_account($account_id, $new_owner = null) |
|
| 1092 | 1092 | { |
| 1093 | 1093 | if (is_null(self::$cache)) self::init_cache(); |
| 1094 | 1094 | |
| 1095 | 1095 | $deleted = 0; |
| 1096 | 1096 | $cat = null; |
| 1097 | - foreach(self::$cache as $cat_id => $data) |
|
| 1097 | + foreach (self::$cache as $cat_id => $data) |
|
| 1098 | 1098 | { |
| 1099 | 1099 | if ($data['owner'] && ($owners = explode(',', $data['owner'])) && ($owner_key = array_search($account_id, $owners)) !== false) |
| 1100 | 1100 | { |
@@ -1136,9 +1136,9 @@ discard block |
||
| 1136 | 1136 | |
| 1137 | 1137 | $checked = array(); |
| 1138 | 1138 | $deleted = 0; |
| 1139 | - foreach(self::$cache as $data) |
|
| 1139 | + foreach (self::$cache as $data) |
|
| 1140 | 1140 | { |
| 1141 | - foreach(explode(',', $data['owner']) as $owner) |
|
| 1141 | + foreach (explode(',', $data['owner']) as $owner) |
|
| 1142 | 1142 | { |
| 1143 | 1143 | if ($owner && !in_array($owner, $checked)) |
| 1144 | 1144 | { |
@@ -194,7 +194,7 @@ |
||
| 194 | 194 | /** |
| 195 | 195 | * sets a single value in the repositry, you need to call save_repository after |
| 196 | 196 | * |
| 197 | - * @param $variable_name string name of the config |
|
| 197 | + * @param string $variable_name string name of the config |
|
| 198 | 198 | * @param $variable_data mixed the content |
| 199 | 199 | */ |
| 200 | 200 | function value($variable_name,$variable_data) |
@@ -92,16 +92,23 @@ discard block |
||
| 92 | 92 | } |
| 93 | 93 | foreach(self::$configs[$this->appname] as $name => $value) |
| 94 | 94 | { |
| 95 | - if (!isset($this->config_data[$name])) // has been deleted |
|
| 95 | + if (!isset($this->config_data[$name])) |
|
| 96 | + { |
|
| 97 | + // has been deleted |
|
| 96 | 98 | { |
| 97 | 99 | self::save_value($name, null, $this->appname, false); |
| 100 | + } |
|
| 98 | 101 | //self::$db->delete(self::TABLE,array('config_app'=>$this->appname,'config_name'=>$name),__LINE__,__FILE__); |
| 99 | 102 | } |
| 100 | 103 | } |
| 101 | 104 | |
| 102 | - if ($this->appname == 'phpgwapi' && method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
| 105 | + if ($this->appname == 'phpgwapi' && method_exists($GLOBALS['egw'],'invalidate_session_cache')) |
|
| 106 | + { |
|
| 107 | + // egw object in setup is limited |
|
| 103 | 108 | { |
| 104 | - $GLOBALS['egw']->invalidate_session_cache(); // in case egw_info is cached in the session (phpgwapi is in egw_info[server]) |
|
| 109 | + $GLOBALS['egw']->invalidate_session_cache(); |
|
| 110 | + } |
|
| 111 | + // in case egw_info is cached in the session (phpgwapi is in egw_info[server]) |
|
| 105 | 112 | } |
| 106 | 113 | self::$configs[$this->appname] = $this->config_data; |
| 107 | 114 | |
@@ -145,20 +152,30 @@ discard block |
||
| 145 | 152 | |
| 146 | 153 | if (!isset($value) || $value === '') |
| 147 | 154 | { |
| 148 | - if (isset(self::$configs[$app])) unset(self::$configs[$app][$name]); |
|
| 155 | + if (isset(self::$configs[$app])) |
|
| 156 | + { |
|
| 157 | + unset(self::$configs[$app][$name]); |
|
| 158 | + } |
|
| 149 | 159 | self::$db->delete(self::TABLE,array('config_app'=>$app,'config_name'=>$name),__LINE__,__FILE__); |
| 150 | 160 | } |
| 151 | 161 | else |
| 152 | 162 | { |
| 153 | 163 | self::$configs[$app][$name] = $value; |
| 154 | - if(is_array($value)) $value = json_encode($value); |
|
| 164 | + if(is_array($value)) |
|
| 165 | + { |
|
| 166 | + $value = json_encode($value); |
|
| 167 | + } |
|
| 155 | 168 | self::$db->insert(self::TABLE,array('config_value'=>$value),array('config_app'=>$app,'config_name'=>$name),__LINE__,__FILE__); |
| 156 | 169 | } |
| 157 | 170 | if ($update_cache) |
| 158 | 171 | { |
| 159 | - if ($app == 'phpgwapi' && method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
| 172 | + if ($app == 'phpgwapi' && method_exists($GLOBALS['egw'],'invalidate_session_cache')) |
|
| 173 | + { |
|
| 174 | + // egw object in setup is limited |
|
| 160 | 175 | { |
| 161 | - $GLOBALS['egw']->invalidate_session_cache(); // in case egw_info is cached in the session (phpgwapi is in egw_info[server]) |
|
| 176 | + $GLOBALS['egw']->invalidate_session_cache(); |
|
| 177 | + } |
|
| 178 | + // in case egw_info is cached in the session (phpgwapi is in egw_info[server]) |
|
| 162 | 179 | } |
| 163 | 180 | Cache::setInstance(__CLASS__, 'configs', self::$configs); |
| 164 | 181 | } |
@@ -278,7 +295,10 @@ discard block |
||
| 278 | 295 | { |
| 279 | 296 | foreach($config as $name => $value) |
| 280 | 297 | { |
| 281 | - if (strpos($name, 'pass') !== false) continue; |
|
| 298 | + if (strpos($name, 'pass') !== false) |
|
| 299 | + { |
|
| 300 | + continue; |
|
| 301 | + } |
|
| 282 | 302 | |
| 283 | 303 | if (in_array($name, $white_list['all']) || isset($white_list[$app]) && in_array($name, $white_list[$app])) |
| 284 | 304 | { |
@@ -86,11 +86,11 @@ discard block |
||
| 86 | 86 | { |
| 87 | 87 | if (is_array($this->config_data)) |
| 88 | 88 | { |
| 89 | - foreach($this->config_data as $name => $value) |
|
| 89 | + foreach ($this->config_data as $name => $value) |
|
| 90 | 90 | { |
| 91 | 91 | self::save_value($name, $value, $this->appname, false); |
| 92 | 92 | } |
| 93 | - foreach(self::$configs[$this->appname] as $name => $value) |
|
| 93 | + foreach (self::$configs[$this->appname] as $name => $value) |
|
| 94 | 94 | { |
| 95 | 95 | if (!isset($this->config_data[$name])) // has been deleted |
| 96 | 96 | { |
@@ -99,9 +99,9 @@ discard block |
||
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - if ($this->appname == 'phpgwapi' && method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
| 102 | + if ($this->appname == 'phpgwapi' && method_exists($GLOBALS['egw'], 'invalidate_session_cache')) // egw object in setup is limited |
|
| 103 | 103 | { |
| 104 | - $GLOBALS['egw']->invalidate_session_cache(); // in case egw_info is cached in the session (phpgwapi is in egw_info[server]) |
|
| 104 | + $GLOBALS['egw']->invalidate_session_cache(); // in case egw_info is cached in the session (phpgwapi is in egw_info[server]) |
|
| 105 | 105 | } |
| 106 | 106 | self::$configs[$this->appname] = $this->config_data; |
| 107 | 107 | |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * @throws Exception\WrongParameter if no $app parameter given for static call |
| 123 | 123 | * @return boolean|int true if no change, else number of affected rows |
| 124 | 124 | */ |
| 125 | - static function save_value($name, $value, $app, $update_cache=true) |
|
| 125 | + static function save_value($name, $value, $app, $update_cache = true) |
|
| 126 | 126 | { |
| 127 | 127 | if (!$app) |
| 128 | 128 | { |
@@ -135,25 +135,25 @@ discard block |
||
| 135 | 135 | |
| 136 | 136 | if (isset(self::$configs[$app][$name]) && self::$configs[$app][$name] === $value) |
| 137 | 137 | { |
| 138 | - return True; // no change ==> exit |
|
| 138 | + return True; // no change ==> exit |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | if (!isset($value) || $value === '') |
| 142 | 142 | { |
| 143 | 143 | if (isset(self::$configs[$app])) unset(self::$configs[$app][$name]); |
| 144 | - self::$db->delete(self::TABLE,array('config_app'=>$app,'config_name'=>$name),__LINE__,__FILE__); |
|
| 144 | + self::$db->delete(self::TABLE, array('config_app'=>$app, 'config_name'=>$name), __LINE__, __FILE__); |
|
| 145 | 145 | } |
| 146 | 146 | else |
| 147 | 147 | { |
| 148 | 148 | self::$configs[$app][$name] = $value; |
| 149 | - if(is_array($value)) $value = json_encode($value); |
|
| 150 | - self::$db->insert(self::TABLE,array('config_value'=>$value),array('config_app'=>$app,'config_name'=>$name),__LINE__,__FILE__); |
|
| 149 | + if (is_array($value)) $value = json_encode($value); |
|
| 150 | + self::$db->insert(self::TABLE, array('config_value'=>$value), array('config_app'=>$app, 'config_name'=>$name), __LINE__, __FILE__); |
|
| 151 | 151 | } |
| 152 | 152 | if ($update_cache) |
| 153 | 153 | { |
| 154 | - if ($app == 'phpgwapi' && method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
| 154 | + if ($app == 'phpgwapi' && method_exists($GLOBALS['egw'], 'invalidate_session_cache')) // egw object in setup is limited |
|
| 155 | 155 | { |
| 156 | - $GLOBALS['egw']->invalidate_session_cache(); // in case egw_info is cached in the session (phpgwapi is in egw_info[server]) |
|
| 156 | + $GLOBALS['egw']->invalidate_session_cache(); // in case egw_info is cached in the session (phpgwapi is in egw_info[server]) |
|
| 157 | 157 | } |
| 158 | 158 | Cache::setInstance(__CLASS__, 'configs', self::$configs); |
| 159 | 159 | } |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | { |
| 171 | 171 | self::init_static(); |
| 172 | 172 | } |
| 173 | - self::$db->delete(self::TABLE,array('config_app' => $this->appname),__LINE__,__FILE__); |
|
| 173 | + self::$db->delete(self::TABLE, array('config_app' => $this->appname), __LINE__, __FILE__); |
|
| 174 | 174 | |
| 175 | 175 | unset(self::$configs[$this->appname]); |
| 176 | 176 | Cache::setInstance(__CLASS__, 'configs', self::$configs); |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | * @param $variable_name string name of the config |
| 193 | 193 | * @param $variable_data mixed the content |
| 194 | 194 | */ |
| 195 | - function value($variable_name,$variable_data) |
|
| 195 | + function value($variable_name, $variable_data) |
|
| 196 | 196 | { |
| 197 | 197 | $this->config_data[$variable_name] = $variable_data; |
| 198 | 198 | } |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | * @deprecated use Api\Storage\Customfields::get() |
| 224 | 224 | * @return array with customfields |
| 225 | 225 | */ |
| 226 | - static function get_customfields($app, $all_private_too=false, $only_type2=null) |
|
| 226 | + static function get_customfields($app, $all_private_too = false, $only_type2 = null) |
|
| 227 | 227 | { |
| 228 | 228 | //error_log(__METHOD__."('$app', $all_private_too, $only_type2) deprecated, use Storage\Customfields::get() in ". function_backtrace()); |
| 229 | 229 | return Storage\Customfields::get($app, $all_private_too, $only_type2); |
@@ -253,12 +253,12 @@ discard block |
||
| 253 | 253 | { |
| 254 | 254 | static $white_list = array( |
| 255 | 255 | 'all' => array('customfields', 'types'), |
| 256 | - 'phpgwapi' => array('webserver_url','server_timezone','enforce_ssl','system_charset', |
|
| 257 | - 'checkfornewversion','checkappversions','email_address_format', // admin >> site config |
|
| 258 | - 'site_title','login_logo_file','login_logo_url','login_logo_title','favicon_file', |
|
| 259 | - 'markuntranslated','link_list_thumbnail','enabled_spellcheck','debug_minify', |
|
| 260 | - 'call_link','call_popup','geolocation_url', // addressbook |
|
| 261 | - 'hide_birthdays','calview_no_consolidate', 'egw_tutorial_disable','fw_mobile_app_list'), // calendar |
|
| 256 | + 'phpgwapi' => array('webserver_url', 'server_timezone', 'enforce_ssl', 'system_charset', |
|
| 257 | + 'checkfornewversion', 'checkappversions', 'email_address_format', // admin >> site config |
|
| 258 | + 'site_title', 'login_logo_file', 'login_logo_url', 'login_logo_title', 'favicon_file', |
|
| 259 | + 'markuntranslated', 'link_list_thumbnail', 'enabled_spellcheck', 'debug_minify', |
|
| 260 | + 'call_link', 'call_popup', 'geolocation_url', // addressbook |
|
| 261 | + 'hide_birthdays', 'calview_no_consolidate', 'egw_tutorial_disable', 'fw_mobile_app_list'), // calendar |
|
| 262 | 262 | 'projectmanager' => array('hours_per_workday', 'duration_units'), |
| 263 | 263 | 'manual' => array('manual_remote_egw_url'), |
| 264 | 264 | 'infolog' => array('status'), |
@@ -269,9 +269,9 @@ discard block |
||
| 269 | 269 | self::init_static(); |
| 270 | 270 | } |
| 271 | 271 | $client_config = array(); |
| 272 | - foreach(self::$configs as $app => $config) |
|
| 272 | + foreach (self::$configs as $app => $config) |
|
| 273 | 273 | { |
| 274 | - foreach($config as $name => $value) |
|
| 274 | + foreach ($config as $name => $value) |
|
| 275 | 275 | { |
| 276 | 276 | if (strpos($name, 'pass') !== false) continue; |
| 277 | 277 | |
@@ -309,12 +309,12 @@ discard block |
||
| 309 | 309 | } |
| 310 | 310 | // handling of old PHP serialized config values |
| 311 | 311 | $data = php_safe_unserialize($str); |
| 312 | - if($data === false) |
|
| 312 | + if ($data === false) |
|
| 313 | 313 | { |
| 314 | 314 | // manually retrieve the string lengths of the serialized array if unserialize failed (iso / utf-8 conversation) |
| 315 | 315 | $data = php_safe_unserialize(preg_replace_callback('!s:(\d+):"(.*?)";!s', function($matches) |
| 316 | 316 | { |
| 317 | - return 's:'.mb_strlen($matches[2],'8bit').':"'.$matches[2].'";'; |
|
| 317 | + return 's:'.mb_strlen($matches[2], '8bit').':"'.$matches[2].'";'; |
|
| 318 | 318 | }, $str)); |
| 319 | 319 | } |
| 320 | 320 | // returning original string, if unserialize failed, eg. for "a:hello" |
@@ -339,7 +339,7 @@ discard block |
||
| 339 | 339 | if (!(self::$configs = Cache::getInstance(__CLASS__, 'configs')) || !is_array(self::$configs['phpgwapi'])) |
| 340 | 340 | { |
| 341 | 341 | self::$configs = array(); |
| 342 | - foreach(self::$db->select(self::TABLE,'*',false,__LINE__,__FILE__) as $row) |
|
| 342 | + foreach (self::$db->select(self::TABLE, '*', false, __LINE__, __FILE__) as $row) |
|
| 343 | 343 | { |
| 344 | 344 | self::$configs[$row['config_app']][$row['config_name']] = self::unserialize($row['config_value']); |
| 345 | 345 | //error_log(__METHOD__."() configs[$row[config_app]][$row[config_name]]=".array2string(self::$configs[$row['config_app']][$row['config_name']])); |
@@ -213,7 +213,6 @@ |
||
| 213 | 213 | /** |
| 214 | 214 | * Remove attributes we are not allowed to update |
| 215 | 215 | * |
| 216 | - * @param array $attributes |
|
| 217 | 216 | */ |
| 218 | 217 | function sanitize_update(array &$ldapContact) |
| 219 | 218 | { |
@@ -170,7 +170,7 @@ |
||
| 170 | 170 | * |
| 171 | 171 | * @param string/array $_contact_id contact_id or array with values for id or account_id |
| 172 | 172 | * @return array/boolean data if row could be retrived else False |
| 173 | - */ |
|
| 173 | + */ |
|
| 174 | 174 | function read($_contact_id) |
| 175 | 175 | { |
| 176 | 176 | if (is_array($_contact_id) && isset($_contact_id['account_id']) || |
@@ -35,8 +35,8 @@ discard block |
||
| 35 | 35 | * minimum: $this->columns_to_search = array('n_family','n_given','org_name','email'); |
| 36 | 36 | */ |
| 37 | 37 | var $search_attributes = array( |
| 38 | - 'n_family','n_middle','n_given','org_name','org_unit', |
|
| 39 | - 'adr_one_location','note','email','samaccountname', |
|
| 38 | + 'n_family', 'n_middle', 'n_given', 'org_name', 'org_unit', |
|
| 39 | + 'adr_one_location', 'note', 'email', 'samaccountname', |
|
| 40 | 40 | ); |
| 41 | 41 | |
| 42 | 42 | /** |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | * |
| 51 | 51 | * @var string |
| 52 | 52 | */ |
| 53 | - var $dn_attribute='cn'; |
|
| 53 | + var $dn_attribute = 'cn'; |
|
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | 56 | * Do NOT attempt to change DN (dn-attribute can NOT be part of schemas used in addressbook!) |
@@ -82,11 +82,11 @@ discard block |
||
| 82 | 82 | * @param array $ldap_config =null default use from $GLOBALS['egw_info']['server'] |
| 83 | 83 | * @param resource $ds =null ldap connection to use |
| 84 | 84 | */ |
| 85 | - function __construct(array $ldap_config=null, $ds=null) |
|
| 85 | + function __construct(array $ldap_config = null, $ds = null) |
|
| 86 | 86 | { |
| 87 | - if (false) parent::__construct (); // quiten IDE warning, we are explicitly NOT calling parrent constructor! |
|
| 87 | + if (false) parent::__construct(); // quiten IDE warning, we are explicitly NOT calling parrent constructor! |
|
| 88 | 88 | |
| 89 | - $this->accountName = $GLOBALS['egw_info']['user']['account_lid']; |
|
| 89 | + $this->accountName = $GLOBALS['egw_info']['user']['account_lid']; |
|
| 90 | 90 | |
| 91 | 91 | if ($ldap_config) |
| 92 | 92 | { |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | } |
| 95 | 95 | else |
| 96 | 96 | { |
| 97 | - $this->ldap_config =& $GLOBALS['egw_info']['server']; |
|
| 97 | + $this->ldap_config = & $GLOBALS['egw_info']['server']; |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | $this->accounts_ads = $GLOBALS['egw']->accounts->backend; |
@@ -119,15 +119,15 @@ discard block |
||
| 119 | 119 | 'account_id' => 'objectsid', |
| 120 | 120 | 'id' => 'objectguid', |
| 121 | 121 | 'uid' => 'objectguid', |
| 122 | - 'n_fn' => 'displayname', // leave CN used in DN untouched |
|
| 123 | - 'accountexpires', 'useraccountcontrol', // needed to exclude deactivated or expired accounts |
|
| 122 | + 'n_fn' => 'displayname', // leave CN used in DN untouched |
|
| 123 | + 'accountexpires', 'useraccountcontrol', // needed to exclude deactivated or expired accounts |
|
| 124 | 124 | )); |
| 125 | 125 | unset($this->schema2egw['user']['n_fileas']); |
| 126 | 126 | unset($this->schema2egw['inetorgperson']); |
| 127 | 127 | |
| 128 | - foreach($this->schema2egw as $attributes) |
|
| 128 | + foreach ($this->schema2egw as $attributes) |
|
| 129 | 129 | { |
| 130 | - $this->all_attributes = array_merge($this->all_attributes,array_values($attributes)); |
|
| 130 | + $this->all_attributes = array_merge($this->all_attributes, array_values($attributes)); |
|
| 131 | 131 | } |
| 132 | 132 | $this->all_attributes = array_values(array_unique($this->all_attributes)); |
| 133 | 133 | |
@@ -139,9 +139,9 @@ discard block |
||
| 139 | 139 | * |
| 140 | 140 | * @param boolean $admin =false true (re-)connect with admin not user credentials, eg. to modify accounts |
| 141 | 141 | */ |
| 142 | - function connect($admin=false) |
|
| 142 | + function connect($admin = false) |
|
| 143 | 143 | { |
| 144 | - unset($admin); // not used, but required by function signature |
|
| 144 | + unset($admin); // not used, but required by function signature |
|
| 145 | 145 | |
| 146 | 146 | $this->ds = $this->accounts_ads->ldap_connection(); |
| 147 | 147 | } |
@@ -174,15 +174,14 @@ discard block |
||
| 174 | 174 | function read($_contact_id) |
| 175 | 175 | { |
| 176 | 176 | if (is_array($_contact_id) && isset($_contact_id['account_id']) || |
| 177 | - !is_array($_contact_id) && substr($_contact_id,0,8) == 'account:') |
|
| 177 | + !is_array($_contact_id) && substr($_contact_id, 0, 8) == 'account:') |
|
| 178 | 178 | { |
| 179 | - $account_id = (int)(is_array($_contact_id) ? $_contact_id['account_id'] : substr($_contact_id,8)); |
|
| 179 | + $account_id = (int)(is_array($_contact_id) ? $_contact_id['account_id'] : substr($_contact_id, 8)); |
|
| 180 | 180 | $_contact_id = $GLOBALS['egw']->accounts->id2name($account_id, 'person_id'); |
| 181 | 181 | } |
| 182 | - $contact_id = !is_array($_contact_id) ? $_contact_id : |
|
| 183 | - (isset ($_contact_id['id']) ? $_contact_id['id'] : $_contact_id['uid']); |
|
| 182 | + $contact_id = !is_array($_contact_id) ? $_contact_id : (isset ($_contact_id['id']) ? $_contact_id['id'] : $_contact_id['uid']); |
|
| 184 | 183 | |
| 185 | - $rows = $this->_searchLDAP($this->allContactsDN, $filter=$this->id_filter($contact_id), $this->all_attributes, Ldap::ALL); |
|
| 184 | + $rows = $this->_searchLDAP($this->allContactsDN, $filter = $this->id_filter($contact_id), $this->all_attributes, Ldap::ALL); |
|
| 186 | 185 | //error_log(__METHOD__."('$contact_id') _searchLDAP($this->allContactsDN, '$filter',...)=".array2string($rows)); |
| 187 | 186 | return $rows ? $rows[0] : false; |
| 188 | 187 | } |
@@ -84,7 +84,11 @@ discard block |
||
| 84 | 84 | */ |
| 85 | 85 | function __construct(array $ldap_config=null, $ds=null) |
| 86 | 86 | { |
| 87 | - if (false) parent::__construct (); // quiten IDE warning, we are explicitly NOT calling parrent constructor! |
|
| 87 | + if (false) |
|
| 88 | + { |
|
| 89 | + parent::__construct (); |
|
| 90 | + } |
|
| 91 | + // quiten IDE warning, we are explicitly NOT calling parrent constructor! |
|
| 88 | 92 | |
| 89 | 93 | $this->accountName = $GLOBALS['egw_info']['user']['account_lid']; |
| 90 | 94 | |
@@ -202,10 +206,16 @@ discard block |
||
| 202 | 206 | $contact['id'] = $contact['uid'] = $this->accounts_ads->objectguid2str($data['objectguid']); |
| 203 | 207 | |
| 204 | 208 | // ignore system accounts |
| 205 | - if ($contact['account_id'] < Api\Accounts\Ads::MIN_ACCOUNT_ID) return false; |
|
| 209 | + if ($contact['account_id'] < Api\Accounts\Ads::MIN_ACCOUNT_ID) |
|
| 210 | + { |
|
| 211 | + return false; |
|
| 212 | + } |
|
| 206 | 213 | |
| 207 | 214 | // ignore deactivated or expired accounts |
| 208 | - if (!$this->accounts_ads->user_active($data)) return false; |
|
| 215 | + if (!$this->accounts_ads->user_active($data)) |
|
| 216 | + { |
|
| 217 | + return false; |
|
| 218 | + } |
|
| 209 | 219 | |
| 210 | 220 | $this->_inetorgperson2egw($contact, $data, 'displayname'); |
| 211 | 221 | } |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | * For a union-query you call search for each query with $start=='UNION' and one more with only $order_by and $start set to run the union-query. |
| 251 | 251 | * |
| 252 | 252 | * @param array|string $criteria array of key and data cols, OR a SQL query (content for WHERE), fully quoted (!) |
| 253 | - * @param boolean|string|array $only_keys =true True returns only keys, False returns all cols. or |
|
| 253 | + * @param boolean|string $only_keys =true True returns only keys, False returns all cols. or |
|
| 254 | 254 | * comma seperated list or array of columns to return |
| 255 | 255 | * @param string $order_by ='' fieldnames + {ASC|DESC} separated by colons ',', can also contain a GROUP BY (if it contains ORDER BY) |
| 256 | 256 | * @param string|array $extra_cols ='' string or array of strings to be added to the SELECT, eg. "count(*) as num" |
@@ -508,7 +508,7 @@ discard block |
||
| 508 | 508 | * or whole where array: column-name => value(s) pairs |
| 509 | 509 | * @param string $uid_column ='list_owner' column-name or null to use $uids as where array |
| 510 | 510 | * @param string $member_attr =null null: no members, 'contact_uid', 'contact_id', 'caldav_name' return members as that attribute |
| 511 | - * @param boolean|int|array $limit_in_ab =false if true only return members from the same owners addressbook, |
|
| 511 | + * @param boolean $limit_in_ab =false if true only return members from the same owners addressbook, |
|
| 512 | 512 | * if int|array only return members from the given owners addressbook(s) |
| 513 | 513 | * @return array with list_id => array(list_id,list_name,list_owner,...) pairs |
| 514 | 514 | */ |
@@ -858,9 +858,9 @@ |
||
| 858 | 858 | } |
| 859 | 859 | |
| 860 | 860 | /** |
| 861 | - * Deletes custom field data |
|
| 862 | - * Implemented to deal with LDAP backend, which saves CFs in SQL, but the account record is in LDAP |
|
| 863 | - */ |
|
| 861 | + * Deletes custom field data |
|
| 862 | + * Implemented to deal with LDAP backend, which saves CFs in SQL, but the account record is in LDAP |
|
| 863 | + */ |
|
| 864 | 864 | function delete_customfields($data) |
| 865 | 865 | { |
| 866 | 866 | $this->db->delete($this->extra_table,$data,__LINE__,__FILE__); |
@@ -336,18 +336,18 @@ discard block |
||
| 336 | 336 | $match_count = $GLOBALS['egw_info']['user']['preferences']['addressbook']['duplicate_threshold'] ? |
| 337 | 337 | $GLOBALS['egw_info']['user']['preferences']['addressbook']['duplicate_threshold'] : 3; |
| 338 | 338 | |
| 339 | - $columns = Array(); |
|
| 340 | - $extra = Array(); |
|
| 339 | + $columns = array(); |
|
| 340 | + $extra = array(); |
|
| 341 | 341 | $order = in_array($param['order'], $group) ? $param['order'] : $group[0]; |
| 342 | 342 | $join .= $this->table_name .'.contact_id != a2.contact_id AND ('; |
| 343 | - $join_fields = Array(); |
|
| 343 | + $join_fields = array(); |
|
| 344 | 344 | foreach($group as $field) |
| 345 | 345 | { |
| 346 | 346 | $extra[] = "IF({$this->table_name}.$field = a2.$field, 1, 0)"; |
| 347 | 347 | $join_fields[] = $this->table_name . ".$field = a2.$field"; |
| 348 | 348 | $columns[] = "IF({$this->table_name}.$field = a2.$field, {$this->table_name}.$field, '') AS $field"; |
| 349 | 349 | } |
| 350 | - $extra = Array( |
|
| 350 | + $extra = array( |
|
| 351 | 351 | implode('+', $extra) . ' AS match_count' |
| 352 | 352 | ); |
| 353 | 353 | $join .= $this->db->column_data_implode(' OR ',$join_fields) . ')'; |
@@ -382,7 +382,7 @@ discard block |
||
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | $rows = $this->db->query( |
| 385 | - "SELECT $mysql_calc_rows " . $columns. ', COUNT(contact_id) AS group_count' . |
|
| 385 | + "select $mysql_calc_rows " . $columns. ', COUNT(contact_id) AS group_count' . |
|
| 386 | 386 | ' FROM (' . $sub_query . ') AS matches GROUP BY ' . implode(',',$group) . |
| 387 | 387 | ' HAVING group_count > 1 ORDER BY ' . $order, |
| 388 | 388 | __LINE__, __FILE__, (int)$param['start'],$mysql_calc_rows ? (int)$param['num_rows'] : -1 |
@@ -720,7 +720,7 @@ discard block |
||
| 720 | 720 | foreach($this->db->select($this->ab2list_table,"$this->ab2list_table.list_id,$this->table_name.$member_attr", |
| 721 | 721 | $this->db->expression($this->ab2list_table, $this->ab2list_table.'.', array('list_id'=>array_keys($lists))), |
| 722 | 722 | __LINE__,__FILE__,false,$member_attr=='contact_id' ? '' : |
| 723 | - '',false,0,"JOIN $this->table_name ON $this->ab2list_table.contact_id=$this->table_name.contact_id".$in_ab_join) as $row) |
|
| 723 | + '',false,0,"join $this->table_name ON $this->ab2list_table.contact_id=$this->table_name.contact_id".$in_ab_join) as $row) |
|
| 724 | 724 | { |
| 725 | 725 | $lists[$row['list_id']]['members'][] = $row[$member_attr]; |
| 726 | 726 | } |
@@ -112,11 +112,20 @@ discard block |
||
| 112 | 112 | $filter = is_array($param['col_filter']) ? $param['col_filter'] : array(); |
| 113 | 113 | $join = ''; |
| 114 | 114 | $op = 'OR'; |
| 115 | - if (isset($param['op']) && !empty($param['op'])) $op = $param['op']; |
|
| 115 | + if (isset($param['op']) && !empty($param['op'])) |
|
| 116 | + { |
|
| 117 | + $op = $param['op']; |
|
| 118 | + } |
|
| 116 | 119 | $advanced_search = false; |
| 117 | - if (isset($param['advanced_search']) && !empty($param['advanced_search'])) $advanced_search = true; |
|
| 120 | + if (isset($param['advanced_search']) && !empty($param['advanced_search'])) |
|
| 121 | + { |
|
| 122 | + $advanced_search = true; |
|
| 123 | + } |
|
| 118 | 124 | $wildcard ='%'; |
| 119 | - if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) $wildcard = ($param['wildcard']?$param['wildcard']:''); |
|
| 125 | + if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) |
|
| 126 | + { |
|
| 127 | + $wildcard = ($param['wildcard']?$param['wildcard']:''); |
|
| 128 | + } |
|
| 120 | 129 | |
| 121 | 130 | // fix cat_id filter to search in comma-separated multiple cats and return subcats |
| 122 | 131 | if ($filter['cat_id']) |
@@ -134,7 +143,11 @@ discard block |
||
| 134 | 143 | // we have no private grants in addressbook at the moment, they have then to be added here too |
| 135 | 144 | if ($param['owner']) |
| 136 | 145 | { |
| 137 | - if (!$this->grants[(int) $filter['owner']]) return false; // we have no access to that addressbook |
|
| 146 | + if (!$this->grants[(int) $filter['owner']]) |
|
| 147 | + { |
|
| 148 | + return false; |
|
| 149 | + } |
|
| 150 | + // we have no access to that addressbook |
|
| 138 | 151 | |
| 139 | 152 | $filter['owner'] = $param['owner']; |
| 140 | 153 | $filter['private'] = 0; |
@@ -209,7 +222,10 @@ discard block |
||
| 209 | 222 | $rows = parent::search($param['search'],array('org_name'),$append,$extra,$wildcard,false,$op/*'OR'*/, |
| 210 | 223 | array($param['start'],$param['num_rows']),$filter,$join); |
| 211 | 224 | |
| 212 | - if (!$rows) return false; |
|
| 225 | + if (!$rows) |
|
| 226 | + { |
|
| 227 | + return false; |
|
| 228 | + } |
|
| 213 | 229 | |
| 214 | 230 | // query the values for *_count == 1, to display them instead |
| 215 | 231 | $filter['org_name'] = $orgs = array(); |
@@ -284,11 +300,20 @@ discard block |
||
| 284 | 300 | $join = 'JOIN ' . $this->table_name . ' AS a2 ON '; |
| 285 | 301 | $filter = $param['col_filter']; |
| 286 | 302 | $op = 'OR'; |
| 287 | - if (isset($param['op']) && !empty($param['op'])) $op = $param['op']; |
|
| 303 | + if (isset($param['op']) && !empty($param['op'])) |
|
| 304 | + { |
|
| 305 | + $op = $param['op']; |
|
| 306 | + } |
|
| 288 | 307 | $advanced_search = false; |
| 289 | - if (isset($param['advanced_search']) && !empty($param['advanced_search'])) $advanced_search = true; |
|
| 308 | + if (isset($param['advanced_search']) && !empty($param['advanced_search'])) |
|
| 309 | + { |
|
| 310 | + $advanced_search = true; |
|
| 311 | + } |
|
| 290 | 312 | $wildcard ='%'; |
| 291 | - if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) $wildcard = ($param['wildcard']?$param['wildcard']:''); |
|
| 313 | + if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) |
|
| 314 | + { |
|
| 315 | + $wildcard = ($param['wildcard']?$param['wildcard']:''); |
|
| 316 | + } |
|
| 292 | 317 | |
| 293 | 318 | // fix cat_id filter to search in comma-separated multiple cats and return subcats |
| 294 | 319 | if ($param['cat_id']) |
@@ -319,7 +344,11 @@ discard block |
||
| 319 | 344 | // we have no private grants in addressbook at the moment, they have then to be added here too |
| 320 | 345 | if (array_key_exists('owner', $param)) |
| 321 | 346 | { |
| 322 | - if (!$this->grants[(int) $param['owner']]) return false; // we have no access to that addressbook |
|
| 347 | + if (!$this->grants[(int) $param['owner']]) |
|
| 348 | + { |
|
| 349 | + return false; |
|
| 350 | + } |
|
| 351 | + // we have no access to that addressbook |
|
| 323 | 352 | |
| 324 | 353 | $filter[$this->table_name.'.contact_owner'] = $param['owner']; |
| 325 | 354 | $filter[$this->table_name.'.private'] = 0; |
@@ -459,7 +488,10 @@ discard block |
||
| 459 | 488 | */ |
| 460 | 489 | 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, $ignore_acl=false) |
| 461 | 490 | { |
| 462 | - if ((int) $this->debug >= 4) echo '<p>'.__METHOD__.'('.array2string($criteria).','.array2string($only_keys).",'$order_by','$extra_cols','$wildcard','$empty','$op',$start,".array2string($filter).",'$join')</p>\n"; |
|
| 491 | + if ((int) $this->debug >= 4) |
|
| 492 | + { |
|
| 493 | + echo '<p>'.__METHOD__.'('.array2string($criteria).','.array2string($only_keys).",'$order_by','$extra_cols','$wildcard','$empty','$op',$start,".array2string($filter).",'$join')</p>\n"; |
|
| 494 | + } |
|
| 463 | 495 | //error_log(__METHOD__.'('.array2string($criteria,true).','.array2string($only_keys).",'$order_by', ".array2string($extra_cols).",'$wildcard','$empty','$op',$start,".array2string($filter).",'$join')"); |
| 464 | 496 | |
| 465 | 497 | $owner = isset($filter['owner']) ? $filter['owner'] : (isset($criteria['owner']) ? $criteria['owner'] : null); |
@@ -508,7 +540,10 @@ discard block |
||
| 508 | 540 | // no grants for selected owner/addressbook |
| 509 | 541 | if (!($filter['owner'] = array_intersect((array)$filter['owner'],array_keys($this->grants)))) |
| 510 | 542 | { |
| 511 | - if (!isset($groupmember_sql)) return false; |
|
| 543 | + if (!isset($groupmember_sql)) |
|
| 544 | + { |
|
| 545 | + return false; |
|
| 546 | + } |
|
| 512 | 547 | $filter[] = substr($groupmember_sql,4); |
| 513 | 548 | unset($filter['owner']); |
| 514 | 549 | } |
@@ -560,13 +595,16 @@ discard block |
||
| 560 | 595 | $filter[] = str_replace('UNIX_TIMESTAMP(NOW())',time(),self::ACOUNT_ACTIVE_FILTER); |
| 561 | 596 | } |
| 562 | 597 | } |
| 563 | - if ($join || ($criteria && is_string($criteria)) || ($criteria && is_array($criteria) && $order_by)) // search also adds a join for custom fields! |
|
| 598 | + if ($join || ($criteria && is_string($criteria)) || ($criteria && is_array($criteria) && $order_by)) |
|
| 599 | + { |
|
| 600 | + // search also adds a join for custom fields! |
|
| 564 | 601 | { |
| 565 | 602 | switch(gettype($only_keys)) |
| 566 | 603 | { |
| 567 | 604 | case 'boolean': |
| 568 | 605 | // Correctly handled by parent class |
| 569 | 606 | break; |
| 607 | + } |
|
| 570 | 608 | case 'string': |
| 571 | 609 | $only_keys = explode(',',$only_keys); |
| 572 | 610 | // fall through |
@@ -576,13 +614,23 @@ discard block |
||
| 576 | 614 | if ($this->db->Type != 'mysql' && preg_match_all("/(#?[a-zA-Z_.]+) *(<> *''|IS NULL|IS NOT NULL)? *(ASC|DESC)?(,|$)/ui", |
| 577 | 615 | $order_by, $all_matches, PREG_SET_ORDER)) |
| 578 | 616 | { |
| 579 | - if (!is_array($extra_cols)) $extra_cols = $extra_cols ? explode(',',$extra_cols) : array(); |
|
| 617 | + if (!is_array($extra_cols)) |
|
| 618 | + { |
|
| 619 | + $extra_cols = $extra_cols ? explode(',',$extra_cols) : array(); |
|
| 620 | + } |
|
| 580 | 621 | foreach($all_matches as $matches) |
| 581 | 622 | { |
| 582 | 623 | $table = ''; |
| 583 | 624 | $column = $matches[1]; |
| 584 | - if ($column[0] == '#') continue; // order by custom field is handeled in so_sql_cf anyway |
|
| 585 | - if (($key = array_search($column, $this->db_cols)) !== false) $column = $key; |
|
| 625 | + if ($column[0] == '#') |
|
| 626 | + { |
|
| 627 | + continue; |
|
| 628 | + } |
|
| 629 | + // order by custom field is handeled in so_sql_cf anyway |
|
| 630 | + if (($key = array_search($column, $this->db_cols)) !== false) |
|
| 631 | + { |
|
| 632 | + $column = $key; |
|
| 633 | + } |
|
| 586 | 634 | if (strpos($column,'.') === false) |
| 587 | 635 | { |
| 588 | 636 | $table = $column == $this->extra_value ? $this->extra_table : $this->table_name; |
@@ -597,10 +645,13 @@ discard block |
||
| 597 | 645 | } |
| 598 | 646 | $extra_cols[] = $table.$column.' '.$matches[2]; |
| 599 | 647 | //_debug_array($matches); |
| 600 | - if (!empty($order_by) && $table) // postgres requires explizit order by |
|
| 648 | + if (!empty($order_by) && $table) |
|
| 649 | + { |
|
| 650 | + // postgres requires explizit order by |
|
| 601 | 651 | { |
| 602 | 652 | $order_by = str_replace($matches[0],$table.$column.' '.$matches[2].' '.$matches[3].$matches[4],$order_by); |
| 603 | 653 | } |
| 654 | + } |
|
| 604 | 655 | } |
| 605 | 656 | //_debug_array($order_by); _debug_array($extra_cols); |
| 606 | 657 | } |
@@ -626,7 +677,11 @@ discard block |
||
| 626 | 677 | } |
| 627 | 678 | $rows =& parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count); |
| 628 | 679 | |
| 629 | - if ($start === false) $this->total = is_array($rows) ? count($rows) : 0; // so_sql sets total only for $start !== false! |
|
| 680 | + if ($start === false) |
|
| 681 | + { |
|
| 682 | + $this->total = is_array($rows) ? count($rows) : 0; |
|
| 683 | + } |
|
| 684 | + // so_sql sets total only for $start !== false! |
|
| 630 | 685 | |
| 631 | 686 | return $rows; |
| 632 | 687 | } |
@@ -668,7 +723,10 @@ discard block |
||
| 668 | 723 | $cat_filter = array(); |
| 669 | 724 | foreach(is_array($cats) ? $cats : (is_numeric($cats) ? array($cats) : explode(',',$cats)) as $cat) |
| 670 | 725 | { |
| 671 | - if (is_numeric($cat)) $cat_filter[] = $this->db->concat("','",cat_id,"','")." LIKE '%,$cat,%'"; |
|
| 726 | + if (is_numeric($cat)) |
|
| 727 | + { |
|
| 728 | + $cat_filter[] = $this->db->concat("','",cat_id,"','")." LIKE '%,$cat,%'"; |
|
| 729 | + } |
|
| 672 | 730 | } |
| 673 | 731 | return $cat_filter; |
| 674 | 732 | } |
@@ -681,10 +739,13 @@ discard block |
||
| 681 | 739 | */ |
| 682 | 740 | function change_owner($account_id,$new_owner) |
| 683 | 741 | { |
| 684 | - if (!$new_owner) // otherwise we would create an account (contact_owner==0) |
|
| 742 | + if (!$new_owner) |
|
| 743 | + { |
|
| 744 | + // otherwise we would create an account (contact_owner==0) |
|
| 685 | 745 | { |
| 686 | 746 | throw Api\Exception\WrongParameter(__METHOD__."($account_id, $new_owner) new owner must not be 0!"); |
| 687 | 747 | } |
| 748 | + } |
|
| 688 | 749 | // contacts |
| 689 | 750 | $this->db->update($this->table_name,array( |
| 690 | 751 | 'contact_owner' => $new_owner, |
@@ -729,7 +790,10 @@ discard block |
||
| 729 | 790 | foreach($this->db->select($this->lists_table,'*',$uid_column?array($uid_column=>$uids):$uids,__LINE__,__FILE__, |
| 730 | 791 | false,'ORDER BY list_owner<>'.(int)$GLOBALS['egw_info']['user']['account_id'].',list_name') as $row) |
| 731 | 792 | { |
| 732 | - if ($member_attr) $row['members'] = array(); |
|
| 793 | + if ($member_attr) |
|
| 794 | + { |
|
| 795 | + $row['members'] = array(); |
|
| 796 | + } |
|
| 733 | 797 | $lists[$row['list_id']] = $row; |
| 734 | 798 | } |
| 735 | 799 | if ($lists && $member_attr && in_array($member_attr,array('contact_id','contact_uid','caldav_name'))) |
@@ -792,9 +856,15 @@ discard block |
||
| 792 | 856 | function add_list($keys,$owner,$contacts=array(),array &$data=array()) |
| 793 | 857 | { |
| 794 | 858 | //error_log(__METHOD__.'('.array2string($keys).", $owner, ".array2string($contacts).', '.array2string($data).') '.function_backtrace()); |
| 795 | - if (!$keys && !$data || !(int)$owner) return false; |
|
| 859 | + if (!$keys && !$data || !(int)$owner) |
|
| 860 | + { |
|
| 861 | + return false; |
|
| 862 | + } |
|
| 796 | 863 | |
| 797 | - if ($keys && !is_array($keys)) $keys = array('list_name' => $keys); |
|
| 864 | + if ($keys && !is_array($keys)) |
|
| 865 | + { |
|
| 866 | + $keys = array('list_name' => $keys); |
|
| 867 | + } |
|
| 798 | 868 | if ($keys) |
| 799 | 869 | { |
| 800 | 870 | $keys['list_owner'] = $owner; |
@@ -814,9 +884,15 @@ discard block |
||
| 814 | 884 | } |
| 815 | 885 | $data['list_modified'] = time(); |
| 816 | 886 | $data['list_modifier'] = $GLOBALS['egw_info']['user']['account_id']; |
| 817 | - if (!$data['list_id']) unset($data['list_id']); |
|
| 887 | + if (!$data['list_id']) |
|
| 888 | + { |
|
| 889 | + unset($data['list_id']); |
|
| 890 | + } |
|
| 818 | 891 | |
| 819 | - if (!$this->db->insert($this->lists_table,$data,$keys,__LINE__,__FILE__)) return false; |
|
| 892 | + if (!$this->db->insert($this->lists_table,$data,$keys,__LINE__,__FILE__)) |
|
| 893 | + { |
|
| 894 | + return false; |
|
| 895 | + } |
|
| 820 | 896 | |
| 821 | 897 | if (!$list_id && ($list_id = $this->db->get_last_insert_id($this->lists_table,'list_id')) && |
| 822 | 898 | (!isset($data['list_uid']) || !isset($data['list_carddav_name']))) |
@@ -834,7 +910,10 @@ discard block |
||
| 834 | 910 | |
| 835 | 911 | $this->add2list($list_id,$contacts,array()); |
| 836 | 912 | } |
| 837 | - if ($keys) $data += $keys; |
|
| 913 | + if ($keys) |
|
| 914 | + { |
|
| 915 | + $data += $keys; |
|
| 916 | + } |
|
| 838 | 917 | //error_log(__METHOD__.'('.array2string($keys).", $owner, ...) data=".array2string($data).' returning '.array2string($list_id)); |
| 839 | 918 | return $list_id; |
| 840 | 919 | } |
@@ -849,7 +928,10 @@ discard block |
||
| 849 | 928 | */ |
| 850 | 929 | function add2list($contact,$list,array $existing=null) |
| 851 | 930 | { |
| 852 | - if (!(int)$list || !is_array($contact) && !(int)$contact) return false; |
|
| 931 | + if (!(int)$list || !is_array($contact) && !(int)$contact) |
|
| 932 | + { |
|
| 933 | + return false; |
|
| 934 | + } |
|
| 853 | 935 | |
| 854 | 936 | if (!is_array($existing)) |
| 855 | 937 | { |
@@ -891,7 +973,10 @@ discard block |
||
| 891 | 973 | */ |
| 892 | 974 | function remove_from_list($contact,$list=null) |
| 893 | 975 | { |
| 894 | - if (!(int)$list && !is_null($list) || !is_array($contact) && !(int)$contact) return false; |
|
| 976 | + if (!(int)$list && !is_null($list) || !is_array($contact) && !(int)$contact) |
|
| 977 | + { |
|
| 978 | + return false; |
|
| 979 | + } |
|
| 895 | 980 | |
| 896 | 981 | $where = array( |
| 897 | 982 | 'contact_id' => $contact, |
@@ -933,7 +1018,10 @@ discard block |
||
| 933 | 1018 | */ |
| 934 | 1019 | function delete_list($list) |
| 935 | 1020 | { |
| 936 | - if (!$this->db->delete($this->lists_table,array('list_id' => $list),__LINE__,__FILE__)) return false; |
|
| 1021 | + if (!$this->db->delete($this->lists_table,array('list_id' => $list),__LINE__,__FILE__)) |
|
| 1022 | + { |
|
| 1023 | + return false; |
|
| 1024 | + } |
|
| 937 | 1025 | |
| 938 | 1026 | $this->db->delete($this->ab2list_table,array('list_id' => $list),__LINE__,__FILE__); |
| 939 | 1027 | |
@@ -948,7 +1036,10 @@ discard block |
||
| 948 | 1036 | */ |
| 949 | 1037 | function lists_ctag($owner=null) |
| 950 | 1038 | { |
| 951 | - if (is_null($owner)) $owner = array_keys($this->grants); |
|
| 1039 | + if (is_null($owner)) |
|
| 1040 | + { |
|
| 1041 | + $owner = array_keys($this->grants); |
|
| 1042 | + } |
|
| 952 | 1043 | |
| 953 | 1044 | if (!($modified = $this->db->select($this->lists_table,'MAX(list_modified)',array('list_owner'=>$owner), |
| 954 | 1045 | __LINE__,__FILE__)->fetchColumn())) |
@@ -968,9 +1059,12 @@ discard block |
||
| 968 | 1059 | */ |
| 969 | 1060 | function read($keys,$extra_cols='',$join='') |
| 970 | 1061 | { |
| 971 | - if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) { |
|
| 1062 | + if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) |
|
| 1063 | + { |
|
| 972 | 1064 | $minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']; |
| 973 | - } else { |
|
| 1065 | + } |
|
| 1066 | + else |
|
| 1067 | + { |
|
| 974 | 1068 | $minimum_uid_length = 8; |
| 975 | 1069 | } |
| 976 | 1070 | |
@@ -990,7 +1084,8 @@ discard block |
||
| 990 | 1084 | |
| 991 | 1085 | // enforce a minium uid strength |
| 992 | 1086 | if (is_array($contact) && (!isset($contact['uid']) |
| 993 | - || strlen($contact['uid']) < $minimum_uid_length)) { |
|
| 1087 | + || strlen($contact['uid']) < $minimum_uid_length)) |
|
| 1088 | + { |
|
| 994 | 1089 | parent::update(array('uid' => Api\CalDAV::generate_uid('addressbook',$contact['id']))); |
| 995 | 1090 | } |
| 996 | 1091 | return $contact; |
@@ -1007,19 +1102,28 @@ discard block |
||
| 1007 | 1102 | { |
| 1008 | 1103 | unset($extra_where); // not used, but required by function signature |
| 1009 | 1104 | |
| 1010 | - if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) { |
|
| 1105 | + if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) |
|
| 1106 | + { |
|
| 1011 | 1107 | $minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']; |
| 1012 | - } else { |
|
| 1108 | + } |
|
| 1109 | + else |
|
| 1110 | + { |
|
| 1013 | 1111 | $minimum_uid_length = 8; |
| 1014 | 1112 | } |
| 1015 | 1113 | |
| 1016 | - if (is_array($keys) && count($keys)) $this->data_merge($keys); |
|
| 1114 | + if (is_array($keys) && count($keys)) |
|
| 1115 | + { |
|
| 1116 | + $this->data_merge($keys); |
|
| 1117 | + } |
|
| 1017 | 1118 | |
| 1018 | 1119 | $new_entry = !$this->data['id']; |
| 1019 | 1120 | |
| 1020 | - if (isset($this->data['etag'])) // do we have an etag in the data to write |
|
| 1121 | + if (isset($this->data['etag'])) |
|
| 1122 | + { |
|
| 1123 | + // do we have an etag in the data to write |
|
| 1021 | 1124 | { |
| 1022 | 1125 | $etag = $this->data['etag']; |
| 1126 | + } |
|
| 1023 | 1127 | unset($this->data['etag']); |
| 1024 | 1128 | if (!($err = parent::save(array('contact_etag=contact_etag+1'),array('contact_etag' => $etag)))) |
| 1025 | 1129 | { |
@@ -1091,7 +1195,10 @@ discard block |
||
| 1091 | 1195 | */ |
| 1092 | 1196 | function read_list($list) |
| 1093 | 1197 | { |
| 1094 | - if (!$list) return false; |
|
| 1198 | + if (!$list) |
|
| 1199 | + { |
|
| 1200 | + return false; |
|
| 1201 | + } |
|
| 1095 | 1202 | |
| 1096 | 1203 | return $this->db->select($this->lists_table,'*',array('list_id'=>$list),__LINE__,__FILE__)->fetch(); |
| 1097 | 1204 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * |
| 45 | 45 | * @var string |
| 46 | 46 | */ |
| 47 | - var $contacts_id='id'; |
|
| 47 | + var $contacts_id = 'id'; |
|
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | 50 | * Name of the table for distribution lists |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | * |
| 68 | 68 | * @param Api\Db $db =null |
| 69 | 69 | */ |
| 70 | - function __construct(Api\Db $db=null) |
|
| 70 | + function __construct(Api\Db $db = null) |
|
| 71 | 71 | { |
| 72 | 72 | parent::__construct('api', 'egw_addressbook', self::EXTRA_TABLE, |
| 73 | 73 | 'contact_', '_name', '_value', '_id', $db); |
@@ -115,8 +115,8 @@ discard block |
||
| 115 | 115 | if (isset($param['op']) && !empty($param['op'])) $op = $param['op']; |
| 116 | 116 | $advanced_search = false; |
| 117 | 117 | if (isset($param['advanced_search']) && !empty($param['advanced_search'])) $advanced_search = true; |
| 118 | - $wildcard ='%'; |
|
| 119 | - if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) $wildcard = ($param['wildcard']?$param['wildcard']:''); |
|
| 118 | + $wildcard = '%'; |
|
| 119 | + if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) $wildcard = ($param['wildcard'] ? $param['wildcard'] : ''); |
|
| 120 | 120 | |
| 121 | 121 | // fix cat_id filter to search in comma-separated multiple cats and return subcats |
| 122 | 122 | if ($filter['cat_id']) |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | // we have no private grants in addressbook at the moment, they have then to be added here too |
| 135 | 135 | if ($param['owner']) |
| 136 | 136 | { |
| 137 | - if (!$this->grants[(int) $filter['owner']]) return false; // we have no access to that addressbook |
|
| 137 | + if (!$this->grants[(int)$filter['owner']]) return false; // we have no access to that addressbook |
|
| 138 | 138 | |
| 139 | 139 | $filter['owner'] = $param['owner']; |
| 140 | 140 | $filter['private'] = 0; |
@@ -143,18 +143,18 @@ discard block |
||
| 143 | 143 | { |
| 144 | 144 | if ($this->account_repository != 'sql' && $this->contact_repository != 'sql-ldap') |
| 145 | 145 | { |
| 146 | - $filter[] = $this->table_name.'.contact_owner != 0'; // in case there have been accounts in sql previously |
|
| 146 | + $filter[] = $this->table_name.'.contact_owner != 0'; // in case there have been accounts in sql previously |
|
| 147 | 147 | } |
| 148 | 148 | $filter[] = "(".$this->table_name.".contact_owner=".(int)$GLOBALS['egw_info']['user']['account_id']. |
| 149 | 149 | " OR contact_private=0 AND ".$this->table_name.".contact_owner IN (". |
| 150 | - implode(',',array_keys($this->grants))."))"; |
|
| 150 | + implode(',', array_keys($this->grants))."))"; |
|
| 151 | 151 | } |
| 152 | 152 | if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] !== 'none') |
| 153 | 153 | { |
| 154 | 154 | $join .= self::ACCOUNT_ACTIVE_JOIN; |
| 155 | 155 | if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] === '0') |
| 156 | 156 | { |
| 157 | - $filter[] = str_replace('UNIX_TIMESTAMP(NOW())',time(),self::ACOUNT_ACTIVE_FILTER); |
|
| 157 | + $filter[] = str_replace('UNIX_TIMESTAMP(NOW())', time(), self::ACOUNT_ACTIVE_FILTER); |
|
| 158 | 158 | } |
| 159 | 159 | else |
| 160 | 160 | { |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | } |
| 169 | 169 | else |
| 170 | 170 | { |
| 171 | - $filter[] = "org_name != ''";// AND org_name IS NOT NULL"; |
|
| 171 | + $filter[] = "org_name != ''"; // AND org_name IS NOT NULL"; |
|
| 172 | 172 | } |
| 173 | 173 | if (isset($filter['list'])) |
| 174 | 174 | { |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | } |
| 187 | 187 | $sort = $param['sort'] == 'DESC' ? 'DESC' : 'ASC'; |
| 188 | 188 | |
| 189 | - list(,$by) = explode(',',$param['org_view']); |
|
| 189 | + list(,$by) = explode(',', $param['org_view']); |
|
| 190 | 190 | if (!$by) |
| 191 | 191 | { |
| 192 | 192 | $extra = array( |
@@ -199,41 +199,40 @@ discard block |
||
| 199 | 199 | else // by adr_one_location or org_unit |
| 200 | 200 | { |
| 201 | 201 | // org total for more then one $by |
| 202 | - $by_expr = $by == 'org_unit_count' ? "COUNT(DISTINCT CASE WHEN org_unit IS NULL THEN '' ELSE org_unit END)" : |
|
| 203 | - "COUNT(DISTINCT CASE WHEN adr_one_locality IS NULL THEN '' ELSE adr_one_locality END)"; |
|
| 204 | - parent::search($param['search'],array('org_name'), |
|
| 202 | + $by_expr = $by == 'org_unit_count' ? "COUNT(DISTINCT CASE WHEN org_unit IS NULL THEN '' ELSE org_unit END)" : "COUNT(DISTINCT CASE WHEN adr_one_locality IS NULL THEN '' ELSE adr_one_locality END)"; |
|
| 203 | + parent::search($param['search'], array('org_name'), |
|
| 205 | 204 | "GROUP BY org_name HAVING $by_expr > 1 ORDER BY org_name $sort", array( |
| 206 | 205 | "NULL AS $by", |
| 207 | 206 | '1 AS is_main', |
| 208 | 207 | 'COUNT(DISTINCT egw_addressbook.contact_id) AS org_count', |
| 209 | 208 | "COUNT(DISTINCT CASE WHEN org_unit IS NULL THEN '' ELSE org_unit END) AS org_unit_count", |
| 210 | 209 | "COUNT(DISTINCT CASE WHEN adr_one_locality IS NULL THEN '' ELSE adr_one_locality END) AS adr_one_locality_count", |
| 211 | - ),$wildcard,false,$op/*'OR'*/,'UNION',$filter,$join); |
|
| 210 | + ), $wildcard, false, $op/*'OR'*/, 'UNION', $filter, $join); |
|
| 212 | 211 | // org by location |
| 213 | - parent::search($param['search'],array('org_name'), |
|
| 212 | + parent::search($param['search'], array('org_name'), |
|
| 214 | 213 | "GROUP BY org_name,$by ORDER BY org_name $sort,$by $sort", array( |
| 215 | 214 | "CASE WHEN $by IS NULL THEN '' ELSE $by END AS $by", |
| 216 | 215 | '0 AS is_main', |
| 217 | 216 | 'COUNT(DISTINCT egw_addressbook.contact_id) AS org_count', |
| 218 | 217 | "COUNT(DISTINCT CASE WHEN org_unit IS NULL THEN '' ELSE org_unit END) AS org_unit_count", |
| 219 | 218 | "COUNT(DISTINCT CASE WHEN adr_one_locality IS NULL THEN '' ELSE adr_one_locality END) AS adr_one_locality_count", |
| 220 | - ),$wildcard,false,$op/*'OR'*/,'UNION',$filter,$join); |
|
| 219 | + ), $wildcard, false, $op/*'OR'*/, 'UNION', $filter, $join); |
|
| 221 | 220 | $append = "ORDER BY org_name $sort,is_main DESC,$by $sort"; |
| 222 | 221 | } |
| 223 | - $rows = parent::search($param['search'],array('org_name'),$append,$extra,$wildcard,false,$op/*'OR'*/, |
|
| 224 | - array($param['start'],$param['num_rows']),$filter,$join); |
|
| 222 | + $rows = parent::search($param['search'], array('org_name'), $append, $extra, $wildcard, false, $op/*'OR'*/, |
|
| 223 | + array($param['start'], $param['num_rows']), $filter, $join); |
|
| 225 | 224 | |
| 226 | 225 | if (!$rows) return false; |
| 227 | 226 | |
| 228 | 227 | // query the values for *_count == 1, to display them instead |
| 229 | 228 | $filter['org_name'] = $orgs = array(); |
| 230 | - foreach($rows as $row) |
|
| 229 | + foreach ($rows as $row) |
|
| 231 | 230 | { |
| 232 | 231 | if ($row['org_unit_count'] == 1 || $row['adr_one_locality_count'] == 1) |
| 233 | 232 | { |
| 234 | - $filter['org_name'][$row['org_name']] = $row['org_name']; // use as key too to have every org only once |
|
| 233 | + $filter['org_name'][$row['org_name']] = $row['org_name']; // use as key too to have every org only once |
|
| 235 | 234 | } |
| 236 | - $org_key = $row['org_name'].($by ? '|||'.($row[$by] || $row[$by.'_count']==1 ? $row[$by] : '|||') : ''); |
|
| 235 | + $org_key = $row['org_name'].($by ? '|||'.($row[$by] || $row[$by.'_count'] == 1 ? $row[$by] : '|||') : ''); |
|
| 237 | 236 | $row['group_count'] = $row['org_count']; |
| 238 | 237 | $orgs[$org_key] = $row; |
| 239 | 238 | } |
@@ -241,9 +240,9 @@ discard block |
||
| 241 | 240 | |
| 242 | 241 | if (count($filter['org_name'])) |
| 243 | 242 | { |
| 244 | - foreach((array) parent::search(null, array('org_name','org_unit','adr_one_locality'), |
|
| 243 | + foreach ((array)parent::search(null, array('org_name', 'org_unit', 'adr_one_locality'), |
|
| 245 | 244 | 'GROUP BY org_name,org_unit,adr_one_locality', |
| 246 | - '',$wildcard,false,$op/*'AND'*/,false,$filter,$join) as $row) |
|
| 245 | + '', $wildcard, false, $op/*'AND'*/, false, $filter, $join) as $row) |
|
| 247 | 246 | { |
| 248 | 247 | $org_key = $row['org_name'].($by ? '|||'.$row[$by] : ''); |
| 249 | 248 | if ($orgs[$org_key]['org_unit_count'] == 1) |
@@ -295,27 +294,27 @@ discard block |
||
| 295 | 294 | */ |
| 296 | 295 | function duplicates($param) |
| 297 | 296 | { |
| 298 | - $join = 'JOIN ' . $this->table_name . ' AS a2 ON '; |
|
| 297 | + $join = 'JOIN '.$this->table_name.' AS a2 ON '; |
|
| 299 | 298 | $filter = $param['col_filter']; |
| 300 | 299 | $op = 'OR'; |
| 301 | 300 | if (isset($param['op']) && !empty($param['op'])) $op = $param['op']; |
| 302 | 301 | $advanced_search = false; |
| 303 | 302 | if (isset($param['advanced_search']) && !empty($param['advanced_search'])) $advanced_search = true; |
| 304 | - $wildcard ='%'; |
|
| 305 | - if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) $wildcard = ($param['wildcard']?$param['wildcard']:''); |
|
| 303 | + $wildcard = '%'; |
|
| 304 | + if ($advanced_search || (isset($param['wildcard']) && !empty($param['wildcard']))) $wildcard = ($param['wildcard'] ? $param['wildcard'] : ''); |
|
| 306 | 305 | |
| 307 | 306 | // fix cat_id filter to search in comma-separated multiple cats and return subcats |
| 308 | 307 | if ($param['cat_id']) |
| 309 | 308 | { |
| 310 | 309 | $cat_filter = $this->_cat_filter($filter['cat_id']); |
| 311 | - $filter[] = str_replace('cat_id', $this->table_name . '.cat_id', $cat_filter); |
|
| 312 | - $join .= str_replace('cat_id', 'a2.cat_id', $cat_filter) . ' AND '; |
|
| 310 | + $filter[] = str_replace('cat_id', $this->table_name.'.cat_id', $cat_filter); |
|
| 311 | + $join .= str_replace('cat_id', 'a2.cat_id', $cat_filter).' AND '; |
|
| 313 | 312 | unset($filter['cat_id']); |
| 314 | 313 | } |
| 315 | 314 | if ($filter['tid']) |
| 316 | 315 | { |
| 317 | - $filter[$this->table_name . '.contact_tid'] = $param['col_filter']['tid']; |
|
| 318 | - $join .= 'a2.contact_tid = ' . $this->db->quote($filter['tid']) . ' AND '; |
|
| 316 | + $filter[$this->table_name.'.contact_tid'] = $param['col_filter']['tid']; |
|
| 317 | + $join .= 'a2.contact_tid = '.$this->db->quote($filter['tid']).' AND '; |
|
| 319 | 318 | unset($filter['tid']); |
| 320 | 319 | } |
| 321 | 320 | else |
@@ -323,33 +322,33 @@ discard block |
||
| 323 | 322 | $join .= 'a2.contact_tid != \'D\' AND '; |
| 324 | 323 | } |
| 325 | 324 | // add filter for read ACL in sql, if user is NOT the owner of the addressbook |
| 326 | - if (array_key_exists('owner',$param) && $param['owner'] == $GLOBALS['egw_info']['user']['account_id']) |
|
| 325 | + if (array_key_exists('owner', $param) && $param['owner'] == $GLOBALS['egw_info']['user']['account_id']) |
|
| 327 | 326 | { |
| 328 | 327 | $filter[$this->table_name.'.contact_owner'] = $param['owner']; |
| 329 | - $join .= 'a2.contact_owner = ' . $this->db->quote($param['owner']) . ' AND '; |
|
| 328 | + $join .= 'a2.contact_owner = '.$this->db->quote($param['owner']).' AND '; |
|
| 330 | 329 | } |
| 331 | 330 | else |
| 332 | 331 | { |
| 333 | 332 | // we have no private grants in addressbook at the moment, they have then to be added here too |
| 334 | 333 | if (array_key_exists('owner', $param)) |
| 335 | 334 | { |
| 336 | - if (!$this->grants[(int) $param['owner']]) return false; // we have no access to that addressbook |
|
| 335 | + if (!$this->grants[(int)$param['owner']]) return false; // we have no access to that addressbook |
|
| 337 | 336 | |
| 338 | 337 | $filter[$this->table_name.'.contact_owner'] = $param['owner']; |
| 339 | 338 | $filter[$this->table_name.'.private'] = 0; |
| 340 | - $join .= 'a2.contact_owner = ' . $this->db->quote($param['owner']) . ' AND '; |
|
| 341 | - $join .= 'a2.contact_private = ' . $this->db->quote($filter['private']) . ' AND '; |
|
| 339 | + $join .= 'a2.contact_owner = '.$this->db->quote($param['owner']).' AND '; |
|
| 340 | + $join .= 'a2.contact_private = '.$this->db->quote($filter['private']).' AND '; |
|
| 342 | 341 | } |
| 343 | 342 | else // search all addressbooks, incl. accounts |
| 344 | 343 | { |
| 345 | 344 | if ($this->account_repository != 'sql' && $this->contact_repository != 'sql-ldap') |
| 346 | 345 | { |
| 347 | - $filter[] = $this->table_name.'.contact_owner != 0'; // in case there have been accounts in sql previously |
|
| 346 | + $filter[] = $this->table_name.'.contact_owner != 0'; // in case there have been accounts in sql previously |
|
| 348 | 347 | } |
| 349 | 348 | $filter[] = $access = "(".$this->table_name.".contact_owner=".(int)$GLOBALS['egw_info']['user']['account_id']. |
| 350 | 349 | " OR {$this->table_name}.contact_private=0 AND ".$this->table_name.".contact_owner IN (". |
| 351 | - implode(',',array_keys($this->grants))."))"; |
|
| 352 | - $join .= str_replace($this->table_name, 'a2', $access) . ' AND '; |
|
| 350 | + implode(',', array_keys($this->grants))."))"; |
|
| 351 | + $join .= str_replace($this->table_name, 'a2', $access).' AND '; |
|
| 353 | 352 | } |
| 354 | 353 | } |
| 355 | 354 | if ($param['searchletter']) |
@@ -358,34 +357,33 @@ discard block |
||
| 358 | 357 | } |
| 359 | 358 | $sort = $param['sort'] == 'DESC' ? 'DESC' : 'ASC'; |
| 360 | 359 | $group = $GLOBALS['egw_info']['user']['preferences']['addressbook']['duplicate_fields'] ? |
| 361 | - explode(',',$GLOBALS['egw_info']['user']['preferences']['addressbook']['duplicate_fields']): |
|
| 362 | - array('n_family', 'org_name', 'contact_email'); |
|
| 360 | + explode(',', $GLOBALS['egw_info']['user']['preferences']['addressbook']['duplicate_fields']) : array('n_family', 'org_name', 'contact_email'); |
|
| 363 | 361 | $match_count = $GLOBALS['egw_info']['user']['preferences']['addressbook']['duplicate_threshold'] ? |
| 364 | 362 | $GLOBALS['egw_info']['user']['preferences']['addressbook']['duplicate_threshold'] : 3; |
| 365 | 363 | |
| 366 | 364 | $columns = Array(); |
| 367 | 365 | $extra = Array(); |
| 368 | 366 | $order = in_array($param['order'], $group) ? $param['order'] : $group[0]; |
| 369 | - $join .= $this->table_name .'.contact_id != a2.contact_id AND ('; |
|
| 367 | + $join .= $this->table_name.'.contact_id != a2.contact_id AND ('; |
|
| 370 | 368 | $join_fields = Array(); |
| 371 | - foreach($group as $field) |
|
| 369 | + foreach ($group as $field) |
|
| 372 | 370 | { |
| 373 | 371 | $extra[] = "IF({$this->table_name}.$field = a2.$field, 1, 0)"; |
| 374 | - $join_fields[] = $this->table_name . ".$field = a2.$field"; |
|
| 372 | + $join_fields[] = $this->table_name.".$field = a2.$field"; |
|
| 375 | 373 | $columns[] = "IF({$this->table_name}.$field = a2.$field, {$this->table_name}.$field, '') AS $field"; |
| 376 | 374 | } |
| 377 | 375 | $extra = Array( |
| 378 | - implode('+', $extra) . ' AS match_count' |
|
| 376 | + implode('+', $extra).' AS match_count' |
|
| 379 | 377 | ); |
| 380 | - $join .= $this->db->column_data_implode(' OR ',$join_fields) . ')'; |
|
| 378 | + $join .= $this->db->column_data_implode(' OR ', $join_fields).')'; |
|
| 381 | 379 | if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] !== 'none') |
| 382 | 380 | { |
| 383 | 381 | if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] === '0') |
| 384 | 382 | { |
| 385 | - $join .=' LEFT JOIN egw_accounts AS account_1 ON egw_addressbook.account_id=account_1.account_id '; |
|
| 386 | - $join .=' LEFT JOIN egw_accounts AS account_2 ON egw_addressbook.account_id=account_2.account_id '; |
|
| 387 | - $filter[] = str_replace(array('UNIX_TIMESTAMP(NOW())', 'account_'),array(time(),'account_1.account_'),self::ACOUNT_ACTIVE_FILTER); |
|
| 388 | - $filter[] = str_replace(array('UNIX_TIMESTAMP(NOW())', 'account_'),array(time(),'account_2.account_'),self::ACOUNT_ACTIVE_FILTER); |
|
| 383 | + $join .= ' LEFT JOIN egw_accounts AS account_1 ON egw_addressbook.account_id=account_1.account_id '; |
|
| 384 | + $join .= ' LEFT JOIN egw_accounts AS account_2 ON egw_addressbook.account_id=account_2.account_id '; |
|
| 385 | + $filter[] = str_replace(array('UNIX_TIMESTAMP(NOW())', 'account_'), array(time(), 'account_1.account_'), self::ACOUNT_ACTIVE_FILTER); |
|
| 386 | + $filter[] = str_replace(array('UNIX_TIMESTAMP(NOW())', 'account_'), array(time(), 'account_2.account_'), self::ACOUNT_ACTIVE_FILTER); |
|
| 389 | 387 | } |
| 390 | 388 | else |
| 391 | 389 | { |
@@ -399,17 +397,17 @@ discard block |
||
| 399 | 397 | if ($param['search'] && !is_array($param['search'])) |
| 400 | 398 | { |
| 401 | 399 | $search_cols = array(); |
| 402 | - foreach($group as $col) |
|
| 400 | + foreach ($group as $col) |
|
| 403 | 401 | { |
| 404 | - $search_cols[] = $this->table_name . '.' . $col; |
|
| 402 | + $search_cols[] = $this->table_name.'.'.$col; |
|
| 405 | 403 | } |
| 406 | - $search = $this->search2criteria($param['search'],$wildcard,$op, null, $search_cols); |
|
| 404 | + $search = $this->search2criteria($param['search'], $wildcard, $op, null, $search_cols); |
|
| 407 | 405 | $criteria = array($search); |
| 408 | 406 | } |
| 409 | 407 | $query = $this->parse_search(array_merge($criteria, $filter), $wildcard, false, ' AND '); |
| 410 | 408 | |
| 411 | 409 | $sub_query = $this->db->select($this->table_name, |
| 412 | - 'DISTINCT ' . implode(', ',array_merge($columns, $extra)), |
|
| 410 | + 'DISTINCT '.implode(', ', array_merge($columns, $extra)), |
|
| 413 | 411 | $query, |
| 414 | 412 | False, False, 0, $append, False, -1, |
| 415 | 413 | $join |
@@ -422,15 +420,15 @@ discard block |
||
| 422 | 420 | } |
| 423 | 421 | |
| 424 | 422 | $rows = $this->db->query( |
| 425 | - "SELECT $mysql_calc_rows " . $columns. ', COUNT(contact_id) AS group_count' . |
|
| 426 | - ' FROM (' . $sub_query . ') AS matches GROUP BY ' . implode(',',$group) . |
|
| 427 | - ' HAVING group_count > 1 ORDER BY ' . $order, |
|
| 428 | - __LINE__, __FILE__, (int)$param['start'],$mysql_calc_rows ? (int)$param['num_rows'] : -1 |
|
| 423 | + "SELECT $mysql_calc_rows ".$columns.', COUNT(contact_id) AS group_count'. |
|
| 424 | + ' FROM ('.$sub_query.') AS matches GROUP BY '.implode(',', $group). |
|
| 425 | + ' HAVING group_count > 1 ORDER BY '.$order, |
|
| 426 | + __LINE__, __FILE__, (int)$param['start'], $mysql_calc_rows ? (int)$param['num_rows'] : -1 |
|
| 429 | 427 | ); |
| 430 | 428 | |
| 431 | 429 | // Go through rows and only return one for each pair/triplet/etc. of matches |
| 432 | 430 | $dupes = array(); |
| 433 | - foreach($rows as $key => $row) |
|
| 431 | + foreach ($rows as $key => $row) |
|
| 434 | 432 | { |
| 435 | 433 | $row['email'] = $row['contact_email']; |
| 436 | 434 | $row['email_home'] = $row['contact_email_home']; |
@@ -471,9 +469,9 @@ discard block |
||
| 471 | 469 | * @param boolean $ignore_acl =false true: no acl check |
| 472 | 470 | * @return boolean/array of matching rows (the row is an array of the cols) or False |
| 473 | 471 | */ |
| 474 | - 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, $ignore_acl=false) |
|
| 472 | + 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, $ignore_acl = false) |
|
| 475 | 473 | { |
| 476 | - if ((int) $this->debug >= 4) echo '<p>'.__METHOD__.'('.array2string($criteria).','.array2string($only_keys).",'$order_by','$extra_cols','$wildcard','$empty','$op',$start,".array2string($filter).",'$join')</p>\n"; |
|
| 474 | + if ((int)$this->debug >= 4) echo '<p>'.__METHOD__.'('.array2string($criteria).','.array2string($only_keys).",'$order_by','$extra_cols','$wildcard','$empty','$op',$start,".array2string($filter).",'$join')</p>\n"; |
|
| 477 | 475 | //error_log(__METHOD__.'('.array2string($criteria,true).','.array2string($only_keys).",'$order_by', ".array2string($extra_cols).",'$wildcard','$empty','$op',$start,".array2string($filter).",'$join')"); |
| 478 | 476 | |
| 479 | 477 | $owner = isset($filter['owner']) ? $filter['owner'] : (isset($criteria['owner']) ? $criteria['owner'] : null); |
@@ -489,10 +487,10 @@ discard block |
||
| 489 | 487 | { |
| 490 | 488 | if ($filter['cat_id'][0] == '!') |
| 491 | 489 | { |
| 492 | - $filter['cat_id'] = substr($filter['cat_id'],1); |
|
| 490 | + $filter['cat_id'] = substr($filter['cat_id'], 1); |
|
| 493 | 491 | $not = 'NOT'; |
| 494 | 492 | } |
| 495 | - $filter[] = $this->_cat_filter($filter['cat_id'],$not); |
|
| 493 | + $filter[] = $this->_cat_filter($filter['cat_id'], $not); |
|
| 496 | 494 | unset($filter['cat_id']); |
| 497 | 495 | } |
| 498 | 496 | |
@@ -502,17 +500,17 @@ discard block |
||
| 502 | 500 | { |
| 503 | 501 | // add read ACL for groupmembers (they have no |
| 504 | 502 | if ($GLOBALS['egw_info']['user']['preferences']['common']['account_selection'] == 'groupmembers' && |
| 505 | - (!isset($filter['owner']) || in_array('0',(array)$filter['owner']))) |
|
| 503 | + (!isset($filter['owner']) || in_array('0', (array)$filter['owner']))) |
|
| 506 | 504 | { |
| 507 | 505 | $groupmembers = array(); |
| 508 | - foreach($GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'],true) as $group_id) |
|
| 506 | + foreach ($GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'], true) as $group_id) |
|
| 509 | 507 | { |
| 510 | - if (($members = $GLOBALS['egw']->accounts->members($group_id,true))) |
|
| 508 | + if (($members = $GLOBALS['egw']->accounts->members($group_id, true))) |
|
| 511 | 509 | { |
| 512 | - $groupmembers = array_merge($groupmembers,$members); |
|
| 510 | + $groupmembers = array_merge($groupmembers, $members); |
|
| 513 | 511 | } |
| 514 | 512 | } |
| 515 | - $groupmember_sql = $this->db->expression($this->table_name, ' OR '.$this->table_name.'.',array( |
|
| 513 | + $groupmember_sql = $this->db->expression($this->table_name, ' OR '.$this->table_name.'.', array( |
|
| 516 | 514 | 'account_id' => array_unique($groupmembers), |
| 517 | 515 | )); |
| 518 | 516 | } |
@@ -520,34 +518,34 @@ discard block |
||
| 520 | 518 | if (isset($filter['owner'])) |
| 521 | 519 | { |
| 522 | 520 | // no grants for selected owner/addressbook |
| 523 | - if (!($filter['owner'] = array_intersect((array)$filter['owner'],array_keys($this->grants)))) |
|
| 521 | + if (!($filter['owner'] = array_intersect((array)$filter['owner'], array_keys($this->grants)))) |
|
| 524 | 522 | { |
| 525 | 523 | if (!isset($groupmember_sql)) return false; |
| 526 | - $filter[] = substr($groupmember_sql,4); |
|
| 524 | + $filter[] = substr($groupmember_sql, 4); |
|
| 527 | 525 | unset($filter['owner']); |
| 528 | 526 | } |
| 529 | 527 | // for an owner filter, which does NOT include current user, filter out private entries |
| 530 | - elseif (!in_array($GLOBALS['egw_info']['user']['account_id'],$filter['owner'])) |
|
| 528 | + elseif (!in_array($GLOBALS['egw_info']['user']['account_id'], $filter['owner'])) |
|
| 531 | 529 | { |
| 532 | 530 | $filter['private'] = 0; |
| 533 | 531 | } |
| 534 | 532 | // if multiple addressbooks (incl. current owner) are searched, we need full acl filter |
| 535 | - elseif(count($filter['owner']) > 1) |
|
| 533 | + elseif (count($filter['owner']) > 1) |
|
| 536 | 534 | { |
| 537 | 535 | $filter[] = "($this->table_name.contact_owner=".(int)$GLOBALS['egw_info']['user']['account_id']. |
| 538 | 536 | " OR contact_private=0 AND $this->table_name.contact_owner IN (". |
| 539 | - implode(',',array_keys($this->grants)).") $groupmember_sql OR $this->table_name.contact_owner IS NULL)"; |
|
| 537 | + implode(',', array_keys($this->grants)).") $groupmember_sql OR $this->table_name.contact_owner IS NULL)"; |
|
| 540 | 538 | } |
| 541 | 539 | } |
| 542 | 540 | else // search all addressbooks, incl. accounts |
| 543 | 541 | { |
| 544 | 542 | if ($this->account_repository != 'sql' && $this->contact_repository != 'sql-ldap') |
| 545 | 543 | { |
| 546 | - $filter[] = $this->table_name.'.contact_owner != 0'; // in case there have been accounts in sql previously |
|
| 544 | + $filter[] = $this->table_name.'.contact_owner != 0'; // in case there have been accounts in sql previously |
|
| 547 | 545 | } |
| 548 | 546 | $filter[] = "($this->table_name.contact_owner=".(int)$GLOBALS['egw_info']['user']['account_id']. |
| 549 | 547 | " OR contact_private=0 AND $this->table_name.contact_owner IN (". |
| 550 | - implode(',',array_keys($this->grants)).") $groupmember_sql OR $this->table_name.contact_owner IS NULL)"; |
|
| 548 | + implode(',', array_keys($this->grants)).") $groupmember_sql OR $this->table_name.contact_owner IS NULL)"; |
|
| 551 | 549 | } |
| 552 | 550 | } |
| 553 | 551 | if (isset($filter['list'])) |
@@ -565,24 +563,24 @@ discard block |
||
| 565 | 563 | unset($filter['list']); |
| 566 | 564 | } |
| 567 | 565 | // add join to show only active accounts (only if accounts are shown and in sql and we not already join the accounts table, eg. used by admin) |
| 568 | - if ((is_array($owner) ? in_array(0, $owner) : !$owner) && substr($this->account_repository,0,3) == 'sql' && |
|
| 569 | - strpos($join,$GLOBALS['egw']->accounts->backend->table) === false && !array_key_exists('account_id',$filter)) |
|
| 566 | + if ((is_array($owner) ? in_array(0, $owner) : !$owner) && substr($this->account_repository, 0, 3) == 'sql' && |
|
| 567 | + strpos($join, $GLOBALS['egw']->accounts->backend->table) === false && !array_key_exists('account_id', $filter)) |
|
| 570 | 568 | { |
| 571 | 569 | $join .= self::ACCOUNT_ACTIVE_JOIN; |
| 572 | 570 | if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] === '0') |
| 573 | 571 | { |
| 574 | - $filter[] = str_replace('UNIX_TIMESTAMP(NOW())',time(),self::ACOUNT_ACTIVE_FILTER); |
|
| 572 | + $filter[] = str_replace('UNIX_TIMESTAMP(NOW())', time(), self::ACOUNT_ACTIVE_FILTER); |
|
| 575 | 573 | } |
| 576 | 574 | } |
| 577 | 575 | if ($join || ($criteria && is_string($criteria)) || ($criteria && is_array($criteria) && $order_by)) // search also adds a join for custom fields! |
| 578 | 576 | { |
| 579 | - switch(gettype($only_keys)) |
|
| 577 | + switch (gettype($only_keys)) |
|
| 580 | 578 | { |
| 581 | 579 | case 'boolean': |
| 582 | 580 | // Correctly handled by parent class |
| 583 | 581 | break; |
| 584 | 582 | case 'string': |
| 585 | - $only_keys = explode(',',$only_keys); |
|
| 583 | + $only_keys = explode(',', $only_keys); |
|
| 586 | 584 | // fall through |
| 587 | 585 | } |
| 588 | 586 | // postgres requires that expressions in order by appear in the columns of a distinct select |
@@ -590,14 +588,14 @@ discard block |
||
| 590 | 588 | if ($this->db->Type != 'mysql' && preg_match_all("/(#?[a-zA-Z_.]+) *(<> *''|IS NULL|IS NOT NULL)? *(ASC|DESC)?(,|$)/ui", |
| 591 | 589 | $order_by, $all_matches, PREG_SET_ORDER)) |
| 592 | 590 | { |
| 593 | - if (!is_array($extra_cols)) $extra_cols = $extra_cols ? explode(',',$extra_cols) : array(); |
|
| 594 | - foreach($all_matches as $matches) |
|
| 591 | + if (!is_array($extra_cols)) $extra_cols = $extra_cols ? explode(',', $extra_cols) : array(); |
|
| 592 | + foreach ($all_matches as $matches) |
|
| 595 | 593 | { |
| 596 | 594 | $table = ''; |
| 597 | 595 | $column = $matches[1]; |
| 598 | - if ($column[0] == '#') continue; // order by custom field is handeled in so_sql_cf anyway |
|
| 596 | + if ($column[0] == '#') continue; // order by custom field is handeled in so_sql_cf anyway |
|
| 599 | 597 | if (($key = array_search($column, $this->db_cols)) !== false) $column = $key; |
| 600 | - if (strpos($column,'.') === false) |
|
| 598 | + if (strpos($column, '.') === false) |
|
| 601 | 599 | { |
| 602 | 600 | $table = $column == $this->extra_value ? $this->extra_table : $this->table_name; |
| 603 | 601 | if (isset($this->db_cols[$column])) |
@@ -613,34 +611,34 @@ discard block |
||
| 613 | 611 | //_debug_array($matches); |
| 614 | 612 | if (!empty($order_by) && $table) // postgres requires explizit order by |
| 615 | 613 | { |
| 616 | - $order_by = str_replace($matches[0],$table.$column.' '.$matches[2].' '.$matches[3].$matches[4],$order_by); |
|
| 614 | + $order_by = str_replace($matches[0], $table.$column.' '.$matches[2].' '.$matches[3].$matches[4], $order_by); |
|
| 617 | 615 | } |
| 618 | 616 | } |
| 619 | 617 | //_debug_array($order_by); _debug_array($extra_cols); |
| 620 | 618 | } |
| 621 | 619 | |
| 622 | 620 | // Understand search by date with wildcard (????.10.??) according to user date preference |
| 623 | - if(is_string($criteria) && strpos($criteria, '?') !== false) |
|
| 621 | + if (is_string($criteria) && strpos($criteria, '?') !== false) |
|
| 624 | 622 | { |
| 625 | 623 | // First, check for a 'date', with wildcards, in the user's format |
| 626 | - $date_regex = str_replace('Q','d', |
|
| 627 | - str_replace(array('Y','m','d','.','-'), |
|
| 628 | - array('(?P<Y>(?:\?|\Q){4})','(?P<m>(?:\?|\Q){2})','(?P<d>(?:\?|\Q){2})','\.','\-'), |
|
| 624 | + $date_regex = str_replace('Q', 'd', |
|
| 625 | + str_replace(array('Y', 'm', 'd', '.', '-'), |
|
| 626 | + array('(?P<Y>(?:\?|\Q){4})', '(?P<m>(?:\?|\Q){2})', '(?P<d>(?:\?|\Q){2})', '\.', '\-'), |
|
| 629 | 627 | $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'])); |
| 630 | 628 | |
| 631 | - if(preg_match_all('$'.$date_regex.'$', $criteria, $matches)) |
|
| 629 | + if (preg_match_all('$'.$date_regex.'$', $criteria, $matches)) |
|
| 632 | 630 | { |
| 633 | - foreach($matches[0] as $m_id => $match) |
|
| 631 | + foreach ($matches[0] as $m_id => $match) |
|
| 634 | 632 | { |
| 635 | 633 | // Birthday is Y-m-d |
| 636 | - $criteria = str_replace($match, "*{$matches['Y'][$m_id]}-{$matches['m'][$m_id]}-{$matches['d'][$m_id]}*",$criteria); |
|
| 634 | + $criteria = str_replace($match, "*{$matches['Y'][$m_id]}-{$matches['m'][$m_id]}-{$matches['d'][$m_id]}*", $criteria); |
|
| 637 | 635 | } |
| 638 | 636 | } |
| 639 | 637 | } |
| 640 | 638 | } |
| 641 | - $rows =& parent::search($criteria,$only_keys,$order_by,$extra_cols,$wildcard,$empty,$op,$start,$filter,$join,$need_full_no_count); |
|
| 639 | + $rows = & parent::search($criteria, $only_keys, $order_by, $extra_cols, $wildcard, $empty, $op, $start, $filter, $join, $need_full_no_count); |
|
| 642 | 640 | |
| 643 | - if ($start === false) $this->total = is_array($rows) ? count($rows) : 0; // so_sql sets total only for $start !== false! |
|
| 641 | + if ($start === false) $this->total = is_array($rows) ? count($rows) : 0; // so_sql sets total only for $start !== false! |
|
| 644 | 642 | |
| 645 | 643 | return $rows; |
| 646 | 644 | } |
@@ -652,18 +650,18 @@ discard block |
||
| 652 | 650 | * @param int|array $cat_id |
| 653 | 651 | * @return string sql to filter by given cat |
| 654 | 652 | */ |
| 655 | - function _cat_filter($cat_id, $not='') |
|
| 653 | + function _cat_filter($cat_id, $not = '') |
|
| 656 | 654 | { |
| 657 | 655 | if (!is_object($GLOBALS['egw']->categories)) |
| 658 | 656 | { |
| 659 | 657 | $GLOBALS['egw']->categories = new Api\Categories; |
| 660 | 658 | } |
| 661 | - foreach($GLOBALS['egw']->categories->return_all_children($cat_id) as $cat) |
|
| 659 | + foreach ($GLOBALS['egw']->categories->return_all_children($cat_id) as $cat) |
|
| 662 | 660 | { |
| 663 | - $cat_filter[] = $this->db->concat("','",cat_id,"','")." $not LIKE '%,$cat,%'"; |
|
| 661 | + $cat_filter[] = $this->db->concat("','", cat_id, "','")." $not LIKE '%,$cat,%'"; |
|
| 664 | 662 | } |
| 665 | - $cfilter = '('.implode(' OR ',$cat_filter).')'; |
|
| 666 | - if(!empty($not)) |
|
| 663 | + $cfilter = '('.implode(' OR ', $cat_filter).')'; |
|
| 664 | + if (!empty($not)) |
|
| 667 | 665 | { |
| 668 | 666 | $cfilter = "( $cfilter OR cat_id IS NULL )"; |
| 669 | 667 | } |
@@ -680,9 +678,9 @@ discard block |
||
| 680 | 678 | function _cat_search($cats) |
| 681 | 679 | { |
| 682 | 680 | $cat_filter = array(); |
| 683 | - foreach(is_array($cats) ? $cats : (is_numeric($cats) ? array($cats) : explode(',',$cats)) as $cat) |
|
| 681 | + foreach (is_array($cats) ? $cats : (is_numeric($cats) ? array($cats) : explode(',', $cats)) as $cat) |
|
| 684 | 682 | { |
| 685 | - if (is_numeric($cat)) $cat_filter[] = $this->db->concat("','",cat_id,"','")." LIKE '%,$cat,%'"; |
|
| 683 | + if (is_numeric($cat)) $cat_filter[] = $this->db->concat("','", cat_id, "','")." LIKE '%,$cat,%'"; |
|
| 686 | 684 | } |
| 687 | 685 | return $cat_filter; |
| 688 | 686 | } |
@@ -693,32 +691,32 @@ discard block |
||
| 693 | 691 | * @param int $account_id account-id of the old owner |
| 694 | 692 | * @param int $new_owner account-id of the new owner |
| 695 | 693 | */ |
| 696 | - function change_owner($account_id,$new_owner) |
|
| 694 | + function change_owner($account_id, $new_owner) |
|
| 697 | 695 | { |
| 698 | 696 | if (!$new_owner) // otherwise we would create an account (contact_owner==0) |
| 699 | 697 | { |
| 700 | 698 | throw Api\Exception\WrongParameter(__METHOD__."($account_id, $new_owner) new owner must not be 0!"); |
| 701 | 699 | } |
| 702 | 700 | // contacts |
| 703 | - $this->db->update($this->table_name,array( |
|
| 701 | + $this->db->update($this->table_name, array( |
|
| 704 | 702 | 'contact_owner' => $new_owner, |
| 705 | - ),array( |
|
| 703 | + ), array( |
|
| 706 | 704 | 'contact_owner' => $account_id, |
| 707 | - ),__LINE__,__FILE__); |
|
| 705 | + ), __LINE__, __FILE__); |
|
| 708 | 706 | |
| 709 | 707 | // cfs |
| 710 | 708 | $this->db->update(self::EXTRA_TABLE, array( |
| 711 | 709 | 'contact_owner' => $new_owner |
| 712 | - ),array( |
|
| 710 | + ), array( |
|
| 713 | 711 | 'contact_owner' => $account_id |
| 714 | 712 | ), __LINE__, __FILE__); |
| 715 | 713 | |
| 716 | 714 | // lists |
| 717 | 715 | $this->db->update($this->lists_table, array( |
| 718 | 716 | 'list_owner' => $new_owner, |
| 719 | - ),array( |
|
| 717 | + ), array( |
|
| 720 | 718 | 'list_owner' => $account_id, |
| 721 | - ),__LINE__,__FILE__); |
|
| 719 | + ), __LINE__, __FILE__); |
|
| 722 | 720 | } |
| 723 | 721 | |
| 724 | 722 | /** |
@@ -732,21 +730,21 @@ discard block |
||
| 732 | 730 | * if int|array only return members from the given owners addressbook(s) |
| 733 | 731 | * @return array with list_id => array(list_id,list_name,list_owner,...) pairs |
| 734 | 732 | */ |
| 735 | - function get_lists($uids,$uid_column='list_owner',$member_attr=null,$limit_in_ab=false) |
|
| 733 | + function get_lists($uids, $uid_column = 'list_owner', $member_attr = null, $limit_in_ab = false) |
|
| 736 | 734 | { |
| 737 | 735 | if (is_array($uids) && array_key_exists('list_id', $uids)) |
| 738 | 736 | { |
| 739 | - $uids[] = $this->db->expression($this->lists_table, $this->lists_table.'.',array('list_id' => $uids['list_id'])); |
|
| 737 | + $uids[] = $this->db->expression($this->lists_table, $this->lists_table.'.', array('list_id' => $uids['list_id'])); |
|
| 740 | 738 | unset($uids['list_id']); |
| 741 | 739 | } |
| 742 | 740 | $lists = array(); |
| 743 | - foreach($this->db->select($this->lists_table,'*',$uid_column?array($uid_column=>$uids):$uids,__LINE__,__FILE__, |
|
| 744 | - false,'ORDER BY list_owner<>'.(int)$GLOBALS['egw_info']['user']['account_id'].',list_name') as $row) |
|
| 741 | + foreach ($this->db->select($this->lists_table, '*', $uid_column ? array($uid_column=>$uids) : $uids, __LINE__, __FILE__, |
|
| 742 | + false, 'ORDER BY list_owner<>'.(int)$GLOBALS['egw_info']['user']['account_id'].',list_name') as $row) |
|
| 745 | 743 | { |
| 746 | 744 | if ($member_attr) $row['members'] = array(); |
| 747 | 745 | $lists[$row['list_id']] = $row; |
| 748 | 746 | } |
| 749 | - if ($lists && $member_attr && in_array($member_attr,array('contact_id','contact_uid','caldav_name'))) |
|
| 747 | + if ($lists && $member_attr && in_array($member_attr, array('contact_id', 'contact_uid', 'caldav_name'))) |
|
| 750 | 748 | { |
| 751 | 749 | if ($limit_in_ab) |
| 752 | 750 | { |
@@ -760,10 +758,9 @@ discard block |
||
| 760 | 758 | $in_ab_join .= "list_owner=$this->table_name.contact_owner"; |
| 761 | 759 | } |
| 762 | 760 | } |
| 763 | - foreach($this->db->select($this->ab2list_table,"$this->ab2list_table.list_id,$this->table_name.$member_attr", |
|
| 761 | + foreach ($this->db->select($this->ab2list_table, "$this->ab2list_table.list_id,$this->table_name.$member_attr", |
|
| 764 | 762 | $this->db->expression($this->ab2list_table, $this->ab2list_table.'.', array('list_id'=>array_keys($lists))), |
| 765 | - __LINE__,__FILE__,false,$member_attr=='contact_id' ? '' : |
|
| 766 | - '',false,0,"JOIN $this->table_name ON $this->ab2list_table.contact_id=$this->table_name.contact_id".$in_ab_join) as $row) |
|
| 763 | + __LINE__, __FILE__, false, $member_attr == 'contact_id' ? '' : '', false, 0, "JOIN $this->table_name ON $this->ab2list_table.contact_id=$this->table_name.contact_id".$in_ab_join) as $row) |
|
| 767 | 764 | { |
| 768 | 765 | $lists[$row['list_id']]['members'][] = $row[$member_attr]; |
| 769 | 766 | } |
@@ -803,7 +800,7 @@ discard block |
||
| 803 | 800 | * @param array &$data=array() values for keys 'list_uid', 'list_carddav_name', 'list_name' |
| 804 | 801 | * @return int|boolean integer list_id or false on error |
| 805 | 802 | */ |
| 806 | - function add_list($keys,$owner,$contacts=array(),array &$data=array()) |
|
| 803 | + function add_list($keys, $owner, $contacts = array(), array &$data = array()) |
|
| 807 | 804 | { |
| 808 | 805 | //error_log(__METHOD__.'('.array2string($keys).", $owner, ".array2string($contacts).', '.array2string($data).') '.function_backtrace()); |
| 809 | 806 | if (!$keys && !$data || !(int)$owner) return false; |
@@ -817,7 +814,7 @@ discard block |
||
| 817 | 814 | { |
| 818 | 815 | $data['list_owner'] = $owner; |
| 819 | 816 | } |
| 820 | - if (!$keys || !($list_id = $this->db->select($this->lists_table,'list_id',$keys,__LINE__,__FILE__)->fetchColumn())) |
|
| 817 | + if (!$keys || !($list_id = $this->db->select($this->lists_table, 'list_id', $keys, __LINE__, __FILE__)->fetchColumn())) |
|
| 821 | 818 | { |
| 822 | 819 | $data['list_created'] = time(); |
| 823 | 820 | $data['list_creator'] = $GLOBALS['egw_info']['user']['account_id']; |
@@ -830,9 +827,9 @@ discard block |
||
| 830 | 827 | $data['list_modifier'] = $GLOBALS['egw_info']['user']['account_id']; |
| 831 | 828 | if (!$data['list_id']) unset($data['list_id']); |
| 832 | 829 | |
| 833 | - if (!$this->db->insert($this->lists_table,$data,$keys,__LINE__,__FILE__)) return false; |
|
| 830 | + if (!$this->db->insert($this->lists_table, $data, $keys, __LINE__, __FILE__)) return false; |
|
| 834 | 831 | |
| 835 | - if (!$list_id && ($list_id = $this->db->get_last_insert_id($this->lists_table,'list_id')) && |
|
| 832 | + if (!$list_id && ($list_id = $this->db->get_last_insert_id($this->lists_table, 'list_id')) && |
|
| 836 | 833 | (!isset($data['list_uid']) || !isset($data['list_carddav_name']))) |
| 837 | 834 | { |
| 838 | 835 | $update = array(); |
@@ -844,9 +841,9 @@ discard block |
||
| 844 | 841 | { |
| 845 | 842 | $update['list_carddav_name'] = $data['list_carddav_name'] = $data['list_uid'].'.vcf'; |
| 846 | 843 | } |
| 847 | - $this->db->update($this->lists_table,$update,array('list_id'=>$list_id),__LINE__,__FILE__); |
|
| 844 | + $this->db->update($this->lists_table, $update, array('list_id'=>$list_id), __LINE__, __FILE__); |
|
| 848 | 845 | |
| 849 | - $this->add2list($list_id,$contacts,array()); |
|
| 846 | + $this->add2list($list_id, $contacts, array()); |
|
| 850 | 847 | } |
| 851 | 848 | if ($keys) $data += $keys; |
| 852 | 849 | //error_log(__METHOD__.'('.array2string($keys).", $owner, ...) data=".array2string($data).' returning '.array2string($list_id)); |
@@ -861,39 +858,39 @@ discard block |
||
| 861 | 858 | * @param array $existing =null array of existing contact-id(s) of list, to not reread it, eg. array() |
| 862 | 859 | * @return false on error |
| 863 | 860 | */ |
| 864 | - function add2list($contact,$list,array $existing=null) |
|
| 861 | + function add2list($contact, $list, array $existing = null) |
|
| 865 | 862 | { |
| 866 | 863 | if (!(int)$list || !is_array($contact) && !(int)$contact) return false; |
| 867 | 864 | |
| 868 | 865 | if (!is_array($existing)) |
| 869 | 866 | { |
| 870 | 867 | $existing = array(); |
| 871 | - foreach($this->db->select($this->ab2list_table,'contact_id',array('list_id'=>$list),__LINE__,__FILE__) as $row) |
|
| 868 | + foreach ($this->db->select($this->ab2list_table, 'contact_id', array('list_id'=>$list), __LINE__, __FILE__) as $row) |
|
| 872 | 869 | { |
| 873 | 870 | $existing[] = $row['contact_id']; |
| 874 | 871 | } |
| 875 | 872 | } |
| 876 | - if (!($to_add = array_diff((array)$contact,$existing))) |
|
| 873 | + if (!($to_add = array_diff((array)$contact, $existing))) |
|
| 877 | 874 | { |
| 878 | - return true; // no need to insert it, would give sql error |
|
| 875 | + return true; // no need to insert it, would give sql error |
|
| 879 | 876 | } |
| 880 | - foreach($to_add as $contact) |
|
| 877 | + foreach ($to_add as $contact) |
|
| 881 | 878 | { |
| 882 | - $this->db->insert($this->ab2list_table,array( |
|
| 879 | + $this->db->insert($this->ab2list_table, array( |
|
| 883 | 880 | 'contact_id' => $contact, |
| 884 | 881 | 'list_id' => $list, |
| 885 | 882 | 'list_added' => time(), |
| 886 | 883 | 'list_added_by' => $GLOBALS['egw_info']['user']['account_id'], |
| 887 | - ),array(),__LINE__,__FILE__); |
|
| 884 | + ), array(), __LINE__, __FILE__); |
|
| 888 | 885 | } |
| 889 | 886 | // update etag |
| 890 | - return $this->db->update($this->lists_table,array( |
|
| 887 | + return $this->db->update($this->lists_table, array( |
|
| 891 | 888 | 'list_etag=list_etag+1', |
| 892 | 889 | 'list_modified' => time(), |
| 893 | 890 | 'list_modifier' => $GLOBALS['egw_info']['user']['account_id'], |
| 894 | - ),array( |
|
| 891 | + ), array( |
|
| 895 | 892 | 'list_id' => $list, |
| 896 | - ),__LINE__,__FILE__); |
|
| 893 | + ), __LINE__, __FILE__); |
|
| 897 | 894 | } |
| 898 | 895 | |
| 899 | 896 | /** |
@@ -903,7 +900,7 @@ discard block |
||
| 903 | 900 | * @param int $list =null list-id or null to remove from all lists |
| 904 | 901 | * @return false on error |
| 905 | 902 | */ |
| 906 | - function remove_from_list($contact,$list=null) |
|
| 903 | + function remove_from_list($contact, $list = null) |
|
| 907 | 904 | { |
| 908 | 905 | if (!(int)$list && !is_null($list) || !is_array($contact) && !(int)$contact) return false; |
| 909 | 906 | |
@@ -917,24 +914,24 @@ discard block |
||
| 917 | 914 | else |
| 918 | 915 | { |
| 919 | 916 | $list = array(); |
| 920 | - foreach($this->db->select($this->ab2list_table,'list_id',$where,__LINE__,__FILE__) as $row) |
|
| 917 | + foreach ($this->db->select($this->ab2list_table, 'list_id', $where, __LINE__, __FILE__) as $row) |
|
| 921 | 918 | { |
| 922 | 919 | $list[] = $row['list_id']; |
| 923 | 920 | } |
| 924 | 921 | } |
| 925 | - if (!$this->db->delete($this->ab2list_table,$where,__LINE__,__FILE__)) |
|
| 922 | + if (!$this->db->delete($this->ab2list_table, $where, __LINE__, __FILE__)) |
|
| 926 | 923 | { |
| 927 | 924 | return false; |
| 928 | 925 | } |
| 929 | - foreach((array)$list as $list_id) |
|
| 926 | + foreach ((array)$list as $list_id) |
|
| 930 | 927 | { |
| 931 | - $this->db->update($this->lists_table,array( |
|
| 928 | + $this->db->update($this->lists_table, array( |
|
| 932 | 929 | 'list_etag=list_etag+1', |
| 933 | 930 | 'list_modified' => time(), |
| 934 | 931 | 'list_modifier' => $GLOBALS['egw_info']['user']['account_id'], |
| 935 | - ),array( |
|
| 932 | + ), array( |
|
| 936 | 933 | 'list_id' => $list_id, |
| 937 | - ),__LINE__,__FILE__); |
|
| 934 | + ), __LINE__, __FILE__); |
|
| 938 | 935 | } |
| 939 | 936 | return true; |
| 940 | 937 | } |
@@ -947,9 +944,9 @@ discard block |
||
| 947 | 944 | */ |
| 948 | 945 | function delete_list($list) |
| 949 | 946 | { |
| 950 | - if (!$this->db->delete($this->lists_table,array('list_id' => $list),__LINE__,__FILE__)) return false; |
|
| 947 | + if (!$this->db->delete($this->lists_table, array('list_id' => $list), __LINE__, __FILE__)) return false; |
|
| 951 | 948 | |
| 952 | - $this->db->delete($this->ab2list_table,array('list_id' => $list),__LINE__,__FILE__); |
|
| 949 | + $this->db->delete($this->ab2list_table, array('list_id' => $list), __LINE__, __FILE__); |
|
| 953 | 950 | |
| 954 | 951 | return $this->db->affected_rows(); |
| 955 | 952 | } |
@@ -960,12 +957,12 @@ discard block |
||
| 960 | 957 | * @param int|array $owner =null null for all lists user has access too |
| 961 | 958 | * @return int |
| 962 | 959 | */ |
| 963 | - function lists_ctag($owner=null) |
|
| 960 | + function lists_ctag($owner = null) |
|
| 964 | 961 | { |
| 965 | 962 | if (is_null($owner)) $owner = array_keys($this->grants); |
| 966 | 963 | |
| 967 | - if (!($modified = $this->db->select($this->lists_table,'MAX(list_modified)',array('list_owner'=>$owner), |
|
| 968 | - __LINE__,__FILE__)->fetchColumn())) |
|
| 964 | + if (!($modified = $this->db->select($this->lists_table, 'MAX(list_modified)', array('list_owner'=>$owner), |
|
| 965 | + __LINE__, __FILE__)->fetchColumn())) |
|
| 969 | 966 | { |
| 970 | 967 | return 0; |
| 971 | 968 | } |
@@ -980,7 +977,7 @@ discard block |
||
| 980 | 977 | * @param string $join |
| 981 | 978 | * @return array|boolean |
| 982 | 979 | */ |
| 983 | - function read($keys,$extra_cols='',$join='') |
|
| 980 | + function read($keys, $extra_cols = '', $join = '') |
|
| 984 | 981 | { |
| 985 | 982 | if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) { |
| 986 | 983 | $minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']; |
@@ -993,11 +990,11 @@ discard block |
||
| 993 | 990 | $keys = array('uid' => $keys); |
| 994 | 991 | } |
| 995 | 992 | try { |
| 996 | - $contact = parent::read($keys,$extra_cols,$join); |
|
| 993 | + $contact = parent::read($keys, $extra_cols, $join); |
|
| 997 | 994 | } |
| 998 | 995 | // catch Illegal mix of collations (ascii_general_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=' (1267) |
| 999 | 996 | // caused by non-ascii chars compared with ascii field uid |
| 1000 | - catch(Api\Db\Exception $e) { |
|
| 997 | + catch (Api\Db\Exception $e) { |
|
| 1001 | 998 | _egw_log_exception($e); |
| 1002 | 999 | return false; |
| 1003 | 1000 | } |
@@ -1005,7 +1002,7 @@ discard block |
||
| 1005 | 1002 | // enforce a minium uid strength |
| 1006 | 1003 | if (is_array($contact) && (!isset($contact['uid']) |
| 1007 | 1004 | || strlen($contact['uid']) < $minimum_uid_length)) { |
| 1008 | - parent::update(array('uid' => Api\CalDAV::generate_uid('addressbook',$contact['id']))); |
|
| 1005 | + parent::update(array('uid' => Api\CalDAV::generate_uid('addressbook', $contact['id']))); |
|
| 1009 | 1006 | } |
| 1010 | 1007 | return $contact; |
| 1011 | 1008 | } |
@@ -1019,7 +1016,7 @@ discard block |
||
| 1019 | 1016 | */ |
| 1020 | 1017 | function save($keys = NULL, $extra_where = NULL) |
| 1021 | 1018 | { |
| 1022 | - unset($extra_where); // not used, but required by function signature |
|
| 1019 | + unset($extra_where); // not used, but required by function signature |
|
| 1023 | 1020 | |
| 1024 | 1021 | if (isset($GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length'])) { |
| 1025 | 1022 | $minimum_uid_length = $GLOBALS['egw_info']['user']['preferences']['syncml']['minimum_uid_length']; |
@@ -1035,9 +1032,9 @@ discard block |
||
| 1035 | 1032 | { |
| 1036 | 1033 | $etag = $this->data['etag']; |
| 1037 | 1034 | unset($this->data['etag']); |
| 1038 | - if (!($err = parent::save(array('contact_etag=contact_etag+1'),array('contact_etag' => $etag)))) |
|
| 1035 | + if (!($err = parent::save(array('contact_etag=contact_etag+1'), array('contact_etag' => $etag)))) |
|
| 1039 | 1036 | { |
| 1040 | - $this->data['etag'] = $etag+1; |
|
| 1037 | + $this->data['etag'] = $etag + 1; |
|
| 1041 | 1038 | } |
| 1042 | 1039 | else |
| 1043 | 1040 | { |
@@ -1057,7 +1054,7 @@ discard block |
||
| 1057 | 1054 | // enforce a minium uid strength |
| 1058 | 1055 | if (!isset($this->data['uid']) || strlen($this->data['uid']) < $minimum_uid_length) |
| 1059 | 1056 | { |
| 1060 | - $update['uid'] = Api\CalDAV::generate_uid('addressbook',$this->data['id']); |
|
| 1057 | + $update['uid'] = Api\CalDAV::generate_uid('addressbook', $this->data['id']); |
|
| 1061 | 1058 | //echo "<p>set uid={$this->data['uid']}, etag={$this->data['etag']}</p>"; |
| 1062 | 1059 | } |
| 1063 | 1060 | // set carddav_name, if not given by caller |
@@ -1075,17 +1072,17 @@ discard block |
||
| 1075 | 1072 | 'contact_id' => $this->data['id'], |
| 1076 | 1073 | ), __LINE__, __FILE__)->fetchColumn(); |
| 1077 | 1074 | } |
| 1078 | - $path = Api\Link::vfs_path('addressbook', $this->data['id'], Api\Contacts::FILES_PHOTO); |
|
| 1075 | + $path = Api\Link::vfs_path('addressbook', $this->data['id'], Api\Contacts::FILES_PHOTO); |
|
| 1079 | 1076 | $backup = Api\Vfs::$is_root; Api\Vfs::$is_root = true; |
| 1080 | 1077 | if (empty($this->data['jpegphoto'])) |
| 1081 | 1078 | { |
| 1082 | 1079 | unlink($path); |
| 1083 | - $update['files'] = $this->data['files'] & ~Api\Contacts::FILES_BIT_PHOTO; |
|
| 1080 | + $update['files'] = $this->data['files']&~Api\Contacts::FILES_BIT_PHOTO; |
|
| 1084 | 1081 | } |
| 1085 | 1082 | else |
| 1086 | 1083 | { |
| 1087 | 1084 | file_put_contents($path, $this->data['jpegphoto']); |
| 1088 | - $update['files'] = $this->data['files'] | Api\Contacts::FILES_BIT_PHOTO; |
|
| 1085 | + $update['files'] = $this->data['files']|Api\Contacts::FILES_BIT_PHOTO; |
|
| 1089 | 1086 | } |
| 1090 | 1087 | Api\Vfs::$is_root = $backup; |
| 1091 | 1088 | } |
@@ -1107,7 +1104,7 @@ discard block |
||
| 1107 | 1104 | { |
| 1108 | 1105 | if (!$list) return false; |
| 1109 | 1106 | |
| 1110 | - return $this->db->select($this->lists_table,'*',array('list_id'=>$list),__LINE__,__FILE__)->fetch(); |
|
| 1107 | + return $this->db->select($this->lists_table, '*', array('list_id'=>$list), __LINE__, __FILE__)->fetch(); |
|
| 1111 | 1108 | } |
| 1112 | 1109 | |
| 1113 | 1110 | /** |
@@ -1118,9 +1115,9 @@ discard block |
||
| 1118 | 1115 | * @param array $extra_cols =array() extra-data to be saved |
| 1119 | 1116 | * @return bool false on success, errornumber on failure |
| 1120 | 1117 | */ |
| 1121 | - function save_customfields(&$data, array $extra_cols=array()) |
|
| 1118 | + function save_customfields(&$data, array $extra_cols = array()) |
|
| 1122 | 1119 | { |
| 1123 | - return parent::save_customfields($data, array('contact_owner' => $data['owner'])+$extra_cols); |
|
| 1120 | + return parent::save_customfields($data, array('contact_owner' => $data['owner']) + $extra_cols); |
|
| 1124 | 1121 | } |
| 1125 | 1122 | |
| 1126 | 1123 | /** |
@@ -1129,6 +1126,6 @@ discard block |
||
| 1129 | 1126 | */ |
| 1130 | 1127 | function delete_customfields($data) |
| 1131 | 1128 | { |
| 1132 | - $this->db->delete($this->extra_table,$data,__LINE__,__FILE__); |
|
| 1129 | + $this->db->delete($this->extra_table, $data, __LINE__, __FILE__); |
|
| 1133 | 1130 | } |
| 1134 | 1131 | } |