@@ -126,17 +126,23 @@ discard block |
||
| 126 | 126 | } |
| 127 | 127 | return $charsets[$lang]; |
| 128 | 128 | } |
| 129 | - if (self::$system_charset) // do we have a system-charset ==> return it |
|
| 129 | + if (self::$system_charset) |
|
| 130 | + { |
|
| 131 | + // do we have a system-charset ==> return it |
|
| 130 | 132 | { |
| 131 | 133 | $charset = self::$system_charset; |
| 132 | 134 | } |
| 135 | + } |
|
| 133 | 136 | else |
| 134 | 137 | { |
| 135 | 138 | // if no translations are loaded (system-startup) use a default, else lang('charset') |
| 136 | 139 | $charset = !self::$lang_arr ? 'utf-8' : strtolower(self::translate('charset')); |
| 137 | 140 | } |
| 138 | 141 | // in case no charset is set, default to utf-8 |
| 139 | - if (empty($charset) || $charset == 'charset') $charset = 'utf-8'; |
|
| 142 | + if (empty($charset) || $charset == 'charset') |
|
| 143 | + { |
|
| 144 | + $charset = 'utf-8'; |
|
| 145 | + } |
|
| 140 | 146 | |
| 141 | 147 | // we need to set our charset as mbstring.internal_encoding if mbstring.func_overlaod > 0 |
| 142 | 148 | // else we get problems for a charset is different from the default utf-8 |
@@ -195,8 +201,14 @@ discard block |
||
| 195 | 201 | } |
| 196 | 202 | $apps = array('common'); |
| 197 | 203 | // for eTemplate apps, load etemplate before app itself (allowing app to overwrite etemplate translations) |
| 198 | - if (class_exists('EGroupware\\Api\\Etemplate', false) || class_exists('etemplate', false)) $apps[] = 'etemplate'; |
|
| 199 | - if ($GLOBALS['egw_info']['flags']['currentapp']) $apps[] = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 204 | + if (class_exists('EGroupware\\Api\\Etemplate', false) || class_exists('etemplate', false)) |
|
| 205 | + { |
|
| 206 | + $apps[] = 'etemplate'; |
|
| 207 | + } |
|
| 208 | + if ($GLOBALS['egw_info']['flags']['currentapp']) |
|
| 209 | + { |
|
| 210 | + $apps[] = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 211 | + } |
|
| 200 | 212 | // load instance specific translations last, so they can overwrite everything |
| 201 | 213 | $apps[] = 'custom'; |
| 202 | 214 | self::add_app($apps); |
@@ -224,7 +236,10 @@ discard block |
||
| 224 | 236 | self::init(); |
| 225 | 237 | } |
| 226 | 238 | $ret = $key; // save key if we dont find a translation |
| 227 | - if ($not_found) $ret .= $not_found; |
|
| 239 | + if ($not_found) |
|
| 240 | + { |
|
| 241 | + $ret .= $not_found; |
|
| 242 | + } |
|
| 228 | 243 | |
| 229 | 244 | if (isset(self::$lang_arr[$key])) |
| 230 | 245 | { |
@@ -271,9 +286,15 @@ discard block |
||
| 271 | 286 | { |
| 272 | 287 | //error_log(__METHOD__."(".array2string($apps).", $lang) count(self::\$lang_arr)=".count(self::$lang_arr)); |
| 273 | 288 | //$start = microtime(true); |
| 274 | - if (!$lang) $lang = self::$userlang; |
|
| 289 | + if (!$lang) |
|
| 290 | + { |
|
| 291 | + $lang = self::$userlang; |
|
| 292 | + } |
|
| 275 | 293 | $tree_level = $instance_level = array(); |
| 276 | - if (!is_array($apps)) $apps = (array)$apps; |
|
| 294 | + if (!is_array($apps)) |
|
| 295 | + { |
|
| 296 | + $apps = (array)$apps; |
|
| 297 | + } |
|
| 277 | 298 | foreach($apps as $key => $app) |
| 278 | 299 | { |
| 279 | 300 | if (!isset(self::$loaded_apps[$app]) || self::$loaded_apps[$app] != $lang && $app != 'common') |
@@ -293,8 +314,14 @@ discard block |
||
| 293 | 314 | } |
| 294 | 315 | } |
| 295 | 316 | // load all translations from cache at once |
| 296 | - if ($tree_level) $tree_level = Cache::getTree(__CLASS__, $tree_level); |
|
| 297 | - if ($instance_level) $instance_level = Cache::getInstance(__CLASS__, $instance_level); |
|
| 317 | + if ($tree_level) |
|
| 318 | + { |
|
| 319 | + $tree_level = Cache::getTree(__CLASS__, $tree_level); |
|
| 320 | + } |
|
| 321 | + if ($instance_level) |
|
| 322 | + { |
|
| 323 | + $instance_level = Cache::getInstance(__CLASS__, $instance_level); |
|
| 324 | + } |
|
| 298 | 325 | |
| 299 | 326 | // merging loaded translations together |
| 300 | 327 | $updated_load_via = false; |
@@ -361,7 +388,10 @@ discard block |
||
| 361 | 388 | static function &load_app($app,$lang) |
| 362 | 389 | { |
| 363 | 390 | //$start = microtime(true); |
| 364 | - if (is_null(self::$db)) self::init(false); |
|
| 391 | + if (is_null(self::$db)) |
|
| 392 | + { |
|
| 393 | + self::init(false); |
|
| 394 | + } |
|
| 365 | 395 | $loaded = array(); |
| 366 | 396 | foreach(self::$db->select(self::LANG_TABLE,'message_id,content',array( |
| 367 | 397 | 'lang' => $lang, |
@@ -467,7 +497,10 @@ discard block |
||
| 467 | 497 | $cache['']['en'] = count($en_phrases); |
| 468 | 498 | foreach(array_keys(self::get_available_langs()) as $lang) |
| 469 | 499 | { |
| 470 | - if ($lang == 'en') continue; |
|
| 500 | + if ($lang == 'en') |
|
| 501 | + { |
|
| 502 | + continue; |
|
| 503 | + } |
|
| 471 | 504 | $lang_phrases = array_keys(self::load_app_files(null, $lang, 'all-apps')); |
| 472 | 505 | $valid_phrases = array_intersect($lang_phrases, $en_phrases); |
| 473 | 506 | $cache[''][$lang] = count($valid_phrases); |
@@ -484,7 +517,10 @@ discard block |
||
| 484 | 517 | continue; |
| 485 | 518 | } |
| 486 | 519 | $en_phrases = array_keys(self::load_app_files(null, 'en', $app)); |
| 487 | - if (count($en_phrases) <= 2) continue; |
|
| 520 | + if (count($en_phrases) <= 2) |
|
| 521 | + { |
|
| 522 | + continue; |
|
| 523 | + } |
|
| 488 | 524 | $cache['en'][$app] = count($en_phrases); |
| 489 | 525 | $lang_phrases = array_keys(self::load_app_files(null, $_lang, $app)); |
| 490 | 526 | $valid_phrases = array_intersect($lang_phrases, $en_phrases); |
@@ -516,7 +552,10 @@ discard block |
||
| 516 | 552 | // check if cache is NOT invalided by checking if we have a modification time for concerned lang-file |
| 517 | 553 | $time = Cache::getTree(__CLASS__, $file=self::get_lang_file($_app, $_lang)); |
| 518 | 554 | // if we dont have one, cache has been invalidated and we need to load translations |
| 519 | - if (!isset($time)) self::add_app($_app, $_lang); |
|
| 555 | + if (!isset($time)) |
|
| 556 | + { |
|
| 557 | + self::add_app($_app, $_lang); |
|
| 558 | + } |
|
| 520 | 559 | |
| 521 | 560 | $etag = self::max_lang_time(); |
| 522 | 561 | } |
@@ -568,7 +607,11 @@ discard block |
||
| 568 | 607 | $loaded = array(); |
| 569 | 608 | foreach($load_app == 'all-apps' ? scandir(EGW_SERVER_ROOT) : (array)$load_app as $app_dir) |
| 570 | 609 | { |
| 571 | - if ($load_app == 'all-apps' && $app_dir=='..') continue; // do not try to break out of egw server root |
|
| 610 | + if ($load_app == 'all-apps' && $app_dir=='..') |
|
| 611 | + { |
|
| 612 | + continue; |
|
| 613 | + } |
|
| 614 | + // do not try to break out of egw server root |
|
| 572 | 615 | if ($app_dir[0] == '.' || !is_dir(EGW_SERVER_ROOT.'/'.$app_dir) || |
| 573 | 616 | !@file_exists($file=self::get_lang_file($app_dir, $lang)) || |
| 574 | 617 | !($f = fopen($file, 'r'))) |
@@ -587,9 +630,15 @@ discard block |
||
| 587 | 630 | { |
| 588 | 631 | $line = explode("\t", trim($read)); |
| 589 | 632 | ++$line_nr; |
| 590 | - if (count($line) != 4) continue; |
|
| 633 | + if (count($line) != 4) |
|
| 634 | + { |
|
| 635 | + continue; |
|
| 636 | + } |
|
| 591 | 637 | list($l_id,$l_app,$l_lang,$l_translation) = $line; |
| 592 | - if ($l_lang != $lang) continue; |
|
| 638 | + if ($l_lang != $lang) |
|
| 639 | + { |
|
| 640 | + continue; |
|
| 641 | + } |
|
| 593 | 642 | if (!isset($just_app_file) && $l_app != $app) |
| 594 | 643 | { |
| 595 | 644 | // check if $l_app contained in file in $app_dir is mentioned in $load_via |
@@ -603,8 +652,14 @@ discard block |
||
| 603 | 652 | } |
| 604 | 653 | // if not update load_via accordingly and store it as config |
| 605 | 654 | //error_log(__METHOD__."() load_via does not contain $l_app => $app_dir"); |
| 606 | - if (!isset(self::$load_via[$l_app])) self::$load_via[$l_app] = array($l_app); |
|
| 607 | - if (!is_array(self::$load_via[$l_app])) self::$load_via[$l_app] = array(self::$load_via[$l_app]); |
|
| 655 | + if (!isset(self::$load_via[$l_app])) |
|
| 656 | + { |
|
| 657 | + self::$load_via[$l_app] = array($l_app); |
|
| 658 | + } |
|
| 659 | + if (!is_array(self::$load_via[$l_app])) |
|
| 660 | + { |
|
| 661 | + self::$load_via[$l_app] = array(self::$load_via[$l_app]); |
|
| 662 | + } |
|
| 608 | 663 | self::$load_via[$l_app][] = $app_dir; |
| 609 | 664 | $updated_load_via = true; |
| 610 | 665 | } |
@@ -671,7 +726,10 @@ discard block |
||
| 671 | 726 | |
| 672 | 727 | if ($translate) |
| 673 | 728 | { |
| 674 | - if (is_null(self::$db)) self::init(false); |
|
| 729 | + if (is_null(self::$db)) |
|
| 730 | + { |
|
| 731 | + self::init(false); |
|
| 732 | + } |
|
| 675 | 733 | |
| 676 | 734 | foreach(self::$langs as $lang => $name) |
| 677 | 735 | { |
@@ -704,10 +762,13 @@ discard block |
||
| 704 | 762 | */ |
| 705 | 763 | static function lang2language($lang) |
| 706 | 764 | { |
| 707 | - if (isset(self::$langs[$lang])) // no need to query the DB |
|
| 765 | + if (isset(self::$langs[$lang])) |
|
| 766 | + { |
|
| 767 | + // no need to query the DB |
|
| 708 | 768 | { |
| 709 | 769 | return self::$langs[$lang]; |
| 710 | 770 | } |
| 771 | + } |
|
| 711 | 772 | return self::$db->select(self::LANGUAGES_TABLE,'lang_name',array('lang_id' => $lang),__LINE__,__FILE__)->fetchColumn(); |
| 712 | 773 | } |
| 713 | 774 | |
@@ -746,7 +807,10 @@ discard block |
||
| 746 | 807 | */ |
| 747 | 808 | static function get_lang_file($app,$lang) |
| 748 | 809 | { |
| 749 | - if ($app == 'common') $app = 'phpgwapi'; |
|
| 810 | + if ($app == 'common') |
|
| 811 | + { |
|
| 812 | + $app = 'phpgwapi'; |
|
| 813 | + } |
|
| 750 | 814 | return EGW_SERVER_ROOT.'/'.$app.'/'.self::LANG_DIR.'/'.self::LANGFILE_PREFIX.$lang.self::LANGFILE_EXTENSION; |
| 751 | 815 | } |
| 752 | 816 | |
@@ -809,9 +873,15 @@ discard block |
||
| 809 | 873 | { |
| 810 | 874 | if ($check_to_from) |
| 811 | 875 | { |
| 812 | - if ($from) $from = strtolower($from); |
|
| 876 | + if ($from) |
|
| 877 | + { |
|
| 878 | + $from = strtolower($from); |
|
| 879 | + } |
|
| 813 | 880 | |
| 814 | - if ($to) $to = strtolower($to); |
|
| 881 | + if ($to) |
|
| 882 | + { |
|
| 883 | + $to = strtolower($to); |
|
| 884 | + } |
|
| 815 | 885 | |
| 816 | 886 | if (!$from) |
| 817 | 887 | { |
@@ -936,7 +1006,10 @@ discard block |
||
| 936 | 1006 | */ |
| 937 | 1007 | static function convert_jsonsafe($_data,$from=False) |
| 938 | 1008 | { |
| 939 | - if ($from===false) $from = self::detect_encoding($_data); |
|
| 1009 | + if ($from===false) |
|
| 1010 | + { |
|
| 1011 | + $from = self::detect_encoding($_data); |
|
| 1012 | + } |
|
| 940 | 1013 | |
| 941 | 1014 | $data = self::convert($_data, strtolower($from)); |
| 942 | 1015 | |
@@ -1035,15 +1108,22 @@ discard block |
||
| 1035 | 1108 | static function get_message_id($translation,$app=null,$lang=null) |
| 1036 | 1109 | { |
| 1037 | 1110 | $where = array('content '.self::$db->capabilities[Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.self::$db->quote($translation)); |
| 1038 | - if ($app) $where['app_name'] = $app; |
|
| 1039 | - if ($lang) $where['lang'] = $lang; |
|
| 1111 | + if ($app) |
|
| 1112 | + { |
|
| 1113 | + $where['app_name'] = $app; |
|
| 1114 | + } |
|
| 1115 | + if ($lang) |
|
| 1116 | + { |
|
| 1117 | + $where['lang'] = $lang; |
|
| 1118 | + } |
|
| 1040 | 1119 | |
| 1041 | 1120 | $id = self::$db->select(self::LANG_TABLE,'message_id',$where,__LINE__,__FILE__)->fetchColumn(); |
| 1042 | 1121 | |
| 1043 | 1122 | // Check cache, since most things aren't in the DB anymore |
| 1044 | 1123 | if(!$id) |
| 1045 | 1124 | { |
| 1046 | - $ids = array_filter(array_keys(self::$lang_arr), function($haystack) use($translation) { |
|
| 1125 | + $ids = array_filter(array_keys(self::$lang_arr), function($haystack) use($translation) |
|
| 1126 | + { |
|
| 1047 | 1127 | return stripos(self::$lang_arr[$haystack],$translation) !== false; |
| 1048 | 1128 | }); |
| 1049 | 1129 | $id = array_shift($ids); |
@@ -1060,10 +1140,17 @@ discard block |
||
| 1060 | 1140 | } |
| 1061 | 1141 | |
| 1062 | 1142 | // load all translations from cache at once |
| 1063 | - if ($tree_level) $lang_arr = Cache::getTree(__CLASS__, $tree_level); |
|
| 1064 | - if ($instance_level) $lang_arr = Cache::getInstance(__CLASS__, $instance_level); |
|
| 1143 | + if ($tree_level) |
|
| 1144 | + { |
|
| 1145 | + $lang_arr = Cache::getTree(__CLASS__, $tree_level); |
|
| 1146 | + } |
|
| 1147 | + if ($instance_level) |
|
| 1148 | + { |
|
| 1149 | + $lang_arr = Cache::getInstance(__CLASS__, $instance_level); |
|
| 1150 | + } |
|
| 1065 | 1151 | $lang_arr = $lang_arr[$app.':en']; |
| 1066 | - $ids = array_filter(array_keys($lang_arr), function($haystack) use($translation, $lang_arr) { |
|
| 1152 | + $ids = array_filter(array_keys($lang_arr), function($haystack) use($translation, $lang_arr) |
|
| 1153 | + { |
|
| 1067 | 1154 | return stripos($lang_arr[$haystack],$translation) !== false; |
| 1068 | 1155 | }); |
| 1069 | 1156 | $id = array_shift($ids); |
@@ -1087,7 +1174,10 @@ discard block |
||
| 1087 | 1174 | { |
| 1088 | 1175 | $list = array('utf-8', 'iso-8859-1', 'windows-1251'); // list may be extended |
| 1089 | 1176 | |
| 1090 | - if ($verify) array_unshift($list, $verify); |
|
| 1177 | + if ($verify) |
|
| 1178 | + { |
|
| 1179 | + array_unshift($list, $verify); |
|
| 1180 | + } |
|
| 1091 | 1181 | |
| 1092 | 1182 | foreach ($list as $item) |
| 1093 | 1183 | { |
@@ -111,7 +111,10 @@ discard block |
||
| 111 | 111 | else |
| 112 | 112 | { |
| 113 | 113 | $acl_acc_list = (array)$GLOBALS['egw']->accounts->memberships($this->account_id, true); |
| 114 | - if (is_array($no_groups)) $acl_acc_list = array_diff($acl_acc_list,$no_groups); |
|
| 114 | + if (is_array($no_groups)) |
|
| 115 | + { |
|
| 116 | + $acl_acc_list = array_diff($acl_acc_list,$no_groups); |
|
| 117 | + } |
|
| 115 | 118 | array_unshift($acl_acc_list,$this->account_id); |
| 116 | 119 | } |
| 117 | 120 | |
@@ -149,7 +152,10 @@ discard block |
||
| 149 | 152 | */ |
| 150 | 153 | function add($appname,$location,$rights) |
| 151 | 154 | { |
| 152 | - if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 155 | + if (!$appname) |
|
| 156 | + { |
|
| 157 | + $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 158 | + } |
|
| 153 | 159 | |
| 154 | 160 | $row = array( |
| 155 | 161 | 'appname' => $appname, |
@@ -171,7 +177,10 @@ discard block |
||
| 171 | 177 | */ |
| 172 | 178 | function delete($appname,$location) |
| 173 | 179 | { |
| 174 | - if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 180 | + if (!$appname) |
|
| 181 | + { |
|
| 182 | + $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 183 | + } |
|
| 175 | 184 | |
| 176 | 185 | foreach($this->data as $idx => $value) |
| 177 | 186 | { |
@@ -209,10 +218,13 @@ discard block |
||
| 209 | 218 | } |
| 210 | 219 | } |
| 211 | 220 | if ($this->account_id == $GLOBALS['egw_info']['user']['account_id'] && |
| 212 | - method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
| 221 | + method_exists($GLOBALS['egw'],'invalidate_session_cache')) |
|
| 222 | + { |
|
| 223 | + // egw object in setup is limited |
|
| 213 | 224 | { |
| 214 | 225 | $GLOBALS['egw']->invalidate_session_cache(); |
| 215 | 226 | } |
| 227 | + } |
|
| 216 | 228 | return $this->data; |
| 217 | 229 | } |
| 218 | 230 | |
@@ -240,7 +252,10 @@ discard block |
||
| 240 | 252 | { |
| 241 | 253 | $this->read_repository(); |
| 242 | 254 | } |
| 243 | - if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 255 | + if (!$appname) |
|
| 256 | + { |
|
| 257 | + $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 258 | + } |
|
| 244 | 259 | |
| 245 | 260 | if (!count($this->data) && $GLOBALS['egw_info']['server']['acl_default'] != 'deny') |
| 246 | 261 | { |
@@ -289,7 +304,10 @@ discard block |
||
| 289 | 304 | */ |
| 290 | 305 | function get_specific_rights($location, $appname = '', $memberships=array()) |
| 291 | 306 | { |
| 292 | - if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 307 | + if (!$appname) |
|
| 308 | + { |
|
| 309 | + $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 310 | + } |
|
| 293 | 311 | |
| 294 | 312 | if (!count($this->data) && $GLOBALS['egw_info']['server']['acl_default'] != 'deny') |
| 295 | 313 | { |
@@ -353,10 +371,13 @@ discard block |
||
| 353 | 371 | ),__LINE__,__FILE__); |
| 354 | 372 | |
| 355 | 373 | if ($account_id == $GLOBALS['egw_info']['user']['account_id'] && |
| 356 | - method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
| 374 | + method_exists($GLOBALS['egw'],'invalidate_session_cache')) |
|
| 375 | + { |
|
| 376 | + // egw object in setup is limited |
|
| 357 | 377 | { |
| 358 | 378 | $GLOBALS['egw']->invalidate_session_cache(); |
| 359 | 379 | } |
| 380 | + } |
|
| 360 | 381 | return True; |
| 361 | 382 | } |
| 362 | 383 | |
@@ -387,11 +408,17 @@ discard block |
||
| 387 | 408 | $where['acl_account'] = $cache_accountid[$accountid] = get_account_id($accountid,$this->account_id); |
| 388 | 409 | } |
| 389 | 410 | } |
| 390 | - if (method_exists($GLOBALS['egw'],'invalidate_session_cache')) // egw object in setup is limited |
|
| 411 | + if (method_exists($GLOBALS['egw'],'invalidate_session_cache')) |
|
| 412 | + { |
|
| 413 | + // egw object in setup is limited |
|
| 391 | 414 | { |
| 392 | 415 | $GLOBALS['egw']->invalidate_session_cache(); |
| 393 | 416 | } |
| 394 | - if ($app == '%' || $app == '%%') unset($where['acl_appname']); |
|
| 417 | + } |
|
| 418 | + if ($app == '%' || $app == '%%') |
|
| 419 | + { |
|
| 420 | + unset($where['acl_appname']); |
|
| 421 | + } |
|
| 395 | 422 | |
| 396 | 423 | $this->db->delete(self::TABLE,$where,__LINE__,__FILE__); |
| 397 | 424 | |
@@ -408,7 +435,10 @@ discard block |
||
| 408 | 435 | */ |
| 409 | 436 | function get_specific_rights_for_account($account_id,$location,$appname='') |
| 410 | 437 | { |
| 411 | - if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 438 | + if (!$appname) |
|
| 439 | + { |
|
| 440 | + $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 441 | + } |
|
| 412 | 442 | |
| 413 | 443 | return $this->db->select(self::TABLE,'acl_rights',array( |
| 414 | 444 | 'acl_location' => $location, |
@@ -426,7 +456,10 @@ discard block |
||
| 426 | 456 | */ |
| 427 | 457 | function get_all_rights($location,$appname='') |
| 428 | 458 | { |
| 429 | - if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 459 | + if (!$appname) |
|
| 460 | + { |
|
| 461 | + $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 462 | + } |
|
| 430 | 463 | |
| 431 | 464 | $rights = array(); |
| 432 | 465 | foreach($this->db->select(self::TABLE,'acl_account,acl_rights',array( |
@@ -449,7 +482,10 @@ discard block |
||
| 449 | 482 | */ |
| 450 | 483 | function get_all_location_rights($account_id,$appname='',$use_memberships=true) |
| 451 | 484 | { |
| 452 | - if (!$appname) $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 485 | + if (!$appname) |
|
| 486 | + { |
|
| 487 | + $appname = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 488 | + } |
|
| 453 | 489 | |
| 454 | 490 | $accounts = array($account_id); |
| 455 | 491 | if ($use_memberships && (int)$account_id > 0) |
@@ -553,7 +589,10 @@ discard block |
||
| 553 | 589 | */ |
| 554 | 590 | function get_ids_for_location($location, $required, $app = '') |
| 555 | 591 | { |
| 556 | - if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 592 | + if (!$app) |
|
| 593 | + { |
|
| 594 | + $app = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 595 | + } |
|
| 557 | 596 | |
| 558 | 597 | $accounts = false; |
| 559 | 598 | foreach($this->db->select(self::TABLE,array('acl_account','acl_rights'),array( |
@@ -577,7 +616,10 @@ discard block |
||
| 577 | 616 | */ |
| 578 | 617 | function get_locations_for_app($app='') |
| 579 | 618 | { |
| 580 | - if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 619 | + if (!$app) |
|
| 620 | + { |
|
| 621 | + $app = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 622 | + } |
|
| 581 | 623 | |
| 582 | 624 | $locations = false; |
| 583 | 625 | foreach($this->db->select(self::TABLE,'DISTINCT '.'acl_location',array( |
@@ -613,7 +655,10 @@ discard block |
||
| 613 | 655 | $account_id = get_account_id($accountid,$this->account_id); |
| 614 | 656 | $cache_accountid[$accountid] = $account_id; |
| 615 | 657 | } |
| 616 | - if ($use_memberships && (int)$account_id > 0) $memberships = $GLOBALS['egw']->accounts->memberships($account_id, true); |
|
| 658 | + if ($use_memberships && (int)$account_id > 0) |
|
| 659 | + { |
|
| 660 | + $memberships = $GLOBALS['egw']->accounts->memberships($account_id, true); |
|
| 661 | + } |
|
| 617 | 662 | $memberships[] = (int)$account_id; |
| 618 | 663 | |
| 619 | 664 | $apps = array(); |
@@ -647,15 +692,24 @@ discard block |
||
| 647 | 692 | */ |
| 648 | 693 | function get_grants($app='',$enum_group_acls=true,$user=null) |
| 649 | 694 | { |
| 650 | - if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 651 | - if (!$user) $user = $this->account_id; |
|
| 695 | + if (!$app) |
|
| 696 | + { |
|
| 697 | + $app = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 698 | + } |
|
| 699 | + if (!$user) |
|
| 700 | + { |
|
| 701 | + $user = $this->account_id; |
|
| 702 | + } |
|
| 652 | 703 | |
| 653 | 704 | static $cache = array(); // some caching withing the request |
| 654 | 705 | |
| 655 | 706 | $grants =& $cache[$app][$user]; |
| 656 | 707 | if (!isset($grants)) |
| 657 | 708 | { |
| 658 | - if ((int)$user > 0) $memberships = $GLOBALS['egw']->accounts->memberships($user, true); |
|
| 709 | + if ((int)$user > 0) |
|
| 710 | + { |
|
| 711 | + $memberships = $GLOBALS['egw']->accounts->memberships($user, true); |
|
| 712 | + } |
|
| 659 | 713 | $memberships[] = $user; |
| 660 | 714 | |
| 661 | 715 | $grants = $accounts = Array(); |
@@ -680,7 +734,11 @@ discard block |
||
| 680 | 734 | // return the grant for each member of the group (false = also for no longer active users) |
| 681 | 735 | foreach((array)$GLOBALS['egw']->accounts->members($grantor, true, false) as $grantor) |
| 682 | 736 | { |
| 683 | - if (!$grantor) continue; // can happen if group has no members |
|
| 737 | + if (!$grantor) |
|
| 738 | + { |
|
| 739 | + continue; |
|
| 740 | + } |
|
| 741 | + // can happen if group has no members |
|
| 684 | 742 | |
| 685 | 743 | // Don't allow to override private with group ACL's! |
| 686 | 744 | $rights &= ~self::PRIVAT; |
@@ -734,7 +792,10 @@ discard block |
||
| 734 | 792 | */ |
| 735 | 793 | function get_location_grants($location,$app='') |
| 736 | 794 | { |
| 737 | - if (!$app) $app = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 795 | + if (!$app) |
|
| 796 | + { |
|
| 797 | + $app = $GLOBALS['egw_info']['flags']['currentapp']; |
|
| 798 | + } |
|
| 738 | 799 | |
| 739 | 800 | $locations = array(); |
| 740 | 801 | foreach($this->db->select(self::TABLE,'acl_location,acl_account,acl_rights',array( |
@@ -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 | { |
@@ -95,7 +95,11 @@ discard block |
||
| 95 | 95 | */ |
| 96 | 96 | public function __construct($time='now',DateTimeZone $tz=null,&$type=null) |
| 97 | 97 | { |
| 98 | - if (is_null($tz)) $tz = self::$user_timezone; // default user timezone |
|
| 98 | + if (is_null($tz)) |
|
| 99 | + { |
|
| 100 | + $tz = self::$user_timezone; |
|
| 101 | + } |
|
| 102 | + // default user timezone |
|
| 99 | 103 | |
| 100 | 104 | switch(($type = gettype($time))) |
| 101 | 105 | { |
@@ -108,7 +112,11 @@ discard block |
||
| 108 | 112 | if (!(is_numeric($time) && ($time > 21000000 || $time < 19000000))) |
| 109 | 113 | { |
| 110 | 114 | $t_str = $time; |
| 111 | - if (is_numeric($time) && strlen($time) == 8) $t_str .= 'T000000'; // 'Ymd' string used in calendar to represent a date |
|
| 115 | + if (is_numeric($time) && strlen($time) == 8) |
|
| 116 | + { |
|
| 117 | + $t_str .= 'T000000'; |
|
| 118 | + } |
|
| 119 | + // 'Ymd' string used in calendar to represent a date |
|
| 112 | 120 | // $time ending in a Z (Zulu or UTC time), is unterstood by DateTime class itself |
| 113 | 121 | try { |
| 114 | 122 | parent::__construct($t_str,$tz); |
@@ -116,7 +124,10 @@ discard block |
||
| 116 | 124 | } |
| 117 | 125 | catch(Exception $e) { |
| 118 | 126 | // if string is nummeric, ignore the exception and treat string as timestamp |
| 119 | - if (!is_numeric($time)) throw $e; |
|
| 127 | + if (!is_numeric($time)) |
|
| 128 | + { |
|
| 129 | + throw $e; |
|
| 130 | + } |
|
| 120 | 131 | } |
| 121 | 132 | } |
| 122 | 133 | $type = 'integer'; |
@@ -137,7 +148,9 @@ discard block |
||
| 137 | 148 | |
| 138 | 149 | case 'array': |
| 139 | 150 | parent::__construct('now',$tz); |
| 140 | - if (isset($time['Y'])) // array format used in eTemplate |
|
| 151 | + if (isset($time['Y'])) |
|
| 152 | + { |
|
| 153 | + // array format used in eTemplate |
|
| 141 | 154 | { |
| 142 | 155 | $time = array( |
| 143 | 156 | 'year' => $time['Y'], |
@@ -148,13 +161,17 @@ discard block |
||
| 148 | 161 | 'second' => $time['s'], |
| 149 | 162 | ); |
| 150 | 163 | } |
| 164 | + } |
|
| 151 | 165 | if (!empty($time['full']) && empty($time['year'])) |
| 152 | 166 | { |
| 153 | 167 | $time['year'] = (int)substr($time['full'],0,4); |
| 154 | 168 | $time['month'] = (int)substr($time['full'],4,2); |
| 155 | 169 | $time['day'] = (int)substr($time['full'],6,2); |
| 156 | 170 | } |
| 157 | - if (isset($time['year'])) $this->setDate((int)$time['year'],(int)$time['month'],isset($time['day']) ? (int)$time['day'] : (int)$time['mday']); |
|
| 171 | + if (isset($time['year'])) |
|
| 172 | + { |
|
| 173 | + $this->setDate((int)$time['year'],(int)$time['month'],isset($time['day']) ? (int)$time['day'] : (int)$time['mday']); |
|
| 174 | + } |
|
| 158 | 175 | $this->setTime((int)$time['hour'],(int)$time['minute'],(int)$time['second']); |
| 159 | 176 | break; |
| 160 | 177 | |
@@ -178,7 +195,10 @@ discard block |
||
| 178 | 195 | */ |
| 179 | 196 | public function add($interval) |
| 180 | 197 | { |
| 181 | - if (is_string($interval)) $interval = DateInterval::createFromDateString($interval); |
|
| 198 | + if (is_string($interval)) |
|
| 199 | + { |
|
| 200 | + $interval = DateInterval::createFromDateString($interval); |
|
| 201 | + } |
|
| 182 | 202 | |
| 183 | 203 | parent::add($interval); |
| 184 | 204 | } |
@@ -202,7 +222,10 @@ discard block |
||
| 202 | 222 | $wstart = -($wday ? $wday-1 : 6); |
| 203 | 223 | break; |
| 204 | 224 | } |
| 205 | - if ($wstart) $this->add($wstart.'days'); |
|
| 225 | + if ($wstart) |
|
| 226 | + { |
|
| 227 | + $this->add($wstart.'days'); |
|
| 228 | + } |
|
| 206 | 229 | } |
| 207 | 230 | |
| 208 | 231 | /** |
@@ -263,15 +286,27 @@ discard block |
||
| 263 | 286 | } |
| 264 | 287 | elseif ($sday || $eday) |
| 265 | 288 | { |
| 266 | - if ($sday) $start->add($sday.'days'); |
|
| 267 | - if ($eday) $end->add($eday.'days'); |
|
| 289 | + if ($sday) |
|
| 290 | + { |
|
| 291 | + $start->add($sday.'days'); |
|
| 292 | + } |
|
| 293 | + if ($eday) |
|
| 294 | + { |
|
| 295 | + $end->add($eday.'days'); |
|
| 296 | + } |
|
| 268 | 297 | } |
| 269 | 298 | elseif ($sweek || $eweek) |
| 270 | 299 | { |
| 271 | 300 | $start->setWeekstart(); |
| 272 | - if ($sweek) $start->add($sweek.'weeks'); |
|
| 301 | + if ($sweek) |
|
| 302 | + { |
|
| 303 | + $start->add($sweek.'weeks'); |
|
| 304 | + } |
|
| 273 | 305 | $end->setWeekstart(); |
| 274 | - if ($eweek) $end->add($eweek.'weeks'); |
|
| 306 | + if ($eweek) |
|
| 307 | + { |
|
| 308 | + $end->add($eweek.'weeks'); |
|
| 309 | + } |
|
| 275 | 310 | } |
| 276 | 311 | } |
| 277 | 312 | // convert start + end from user to servertime for the filter |
@@ -416,7 +451,10 @@ discard block |
||
| 416 | 451 | } |
| 417 | 452 | $time->setUser(); |
| 418 | 453 | |
| 419 | - if (is_null($type)) $type = $typeof; |
|
| 454 | + if (is_null($type)) |
|
| 455 | + { |
|
| 456 | + $type = $typeof; |
|
| 457 | + } |
|
| 420 | 458 | |
| 421 | 459 | //echo "<p>".__METHOD__."($time,$type) = ".print_r($format->format($type),true)."</p>\n"; |
| 422 | 460 | return $time->format($type); |
@@ -446,7 +484,10 @@ discard block |
||
| 446 | 484 | } |
| 447 | 485 | $time->setServer(); |
| 448 | 486 | |
| 449 | - if (is_null($type)) $type = $typeof; |
|
| 487 | + if (is_null($type)) |
|
| 488 | + { |
|
| 489 | + $type = $typeof; |
|
| 490 | + } |
|
| 450 | 491 | |
| 451 | 492 | //echo "<p>".__METHOD__."($time,$type) = ".print_r($format->format($type),true)."</p>\n"; |
| 452 | 493 | return $time->format($type); |
@@ -489,7 +530,10 @@ discard block |
||
| 489 | 530 | public static function setUserPrefs($tz,$dateformat='',$timeformat='') |
| 490 | 531 | { |
| 491 | 532 | //echo "<p>".__METHOD__."('$tz','$dateformat','$timeformat') ".function_backtrace()."</p>\n"; |
| 492 | - if (!empty($dateformat)) self::$user_dateformat = $dateformat; |
|
| 533 | + if (!empty($dateformat)) |
|
| 534 | + { |
|
| 535 | + self::$user_dateformat = $dateformat; |
|
| 536 | + } |
|
| 493 | 537 | |
| 494 | 538 | switch($timeformat) |
| 495 | 539 | { |
@@ -527,7 +571,10 @@ discard block |
||
| 527 | 571 | */ |
| 528 | 572 | public static function tz_offset_s($time='now') |
| 529 | 573 | { |
| 530 | - if (!($time instanceof DateTime)) $time = new DateTime($time); |
|
| 574 | + if (!($time instanceof DateTime)) |
|
| 575 | + { |
|
| 576 | + $time = new DateTime($time); |
|
| 577 | + } |
|
| 531 | 578 | |
| 532 | 579 | return self::$user_timezone->getOffset($time) - self::$server_timezone->getOffset($time); |
| 533 | 580 | } |
@@ -635,9 +682,17 @@ discard block |
||
| 635 | 682 | ); |
| 636 | 683 | foreach(DateTimeZone::listIdentifiers() as $name) |
| 637 | 684 | { |
| 638 | - if (in_array($name,$no_vtimezone)) continue; // do NOT allow to set in EGroupware, as we have not VTIMEZONE component for it |
|
| 685 | + if (in_array($name,$no_vtimezone)) |
|
| 686 | + { |
|
| 687 | + continue; |
|
| 688 | + } |
|
| 689 | + // do NOT allow to set in EGroupware, as we have not VTIMEZONE component for it |
|
| 639 | 690 | list($continent) = explode('/',$name,2); |
| 640 | - if (!isset($tzs[$continent])) continue; // old depricated timezones |
|
| 691 | + if (!isset($tzs[$continent])) |
|
| 692 | + { |
|
| 693 | + continue; |
|
| 694 | + } |
|
| 695 | + // old depricated timezones |
|
| 641 | 696 | $datetime = new DateTime('now',new DateTimeZone($name)); |
| 642 | 697 | $tzs[$continent][$name] = str_replace(array('_','/'),array(' ',' / '),$name)." ".$datetime->format(); |
| 643 | 698 | unset($datetime); |
@@ -676,10 +731,13 @@ discard block |
||
| 676 | 731 | { |
| 677 | 732 | $user_tzs = array_merge(array($tz),$user_tzs); |
| 678 | 733 | } |
| 679 | - if (!$user_tzs) // if we have no user timezones, eg. user set no pref --> use server default |
|
| 734 | + if (!$user_tzs) |
|
| 735 | + { |
|
| 736 | + // if we have no user timezones, eg. user set no pref --> use server default |
|
| 680 | 737 | { |
| 681 | 738 | $user_tzs = array($GLOBALS['egw_info']['server']['server_timezone']); |
| 682 | 739 | } |
| 740 | + } |
|
| 683 | 741 | if ($extra && !in_array($extra,$user_tzs)) |
| 684 | 742 | { |
| 685 | 743 | $user_tzs = array_merge(array($extra),$user_tzs); |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | |
| 249 | 249 | // set session_timeout from global php.ini and default to 14400=4h, if not set |
| 250 | 250 | if (!($GLOBALS['egw_info']['server']['sessions_timeout'] = ini_get('session.gc_maxlifetime'))) |
| 251 | - { |
|
| 251 | + { |
|
| 252 | 252 | ini_set('session.gc_maxlifetime', $GLOBALS['egw_info']['server']['sessions_timeout']=14400); |
| 253 | 253 | } |
| 254 | 254 | } |
@@ -282,7 +282,10 @@ discard block |
||
| 282 | 282 | */ |
| 283 | 283 | function commit_session() |
| 284 | 284 | { |
| 285 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() sessionid=$this->sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]).' '.function_backtrace()); |
|
| 285 | + if (self::ERROR_LOG_DEBUG) |
|
| 286 | + { |
|
| 287 | + error_log(__METHOD__."() sessionid=$this->sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR]).' '.function_backtrace()); |
|
| 288 | + } |
|
| 286 | 289 | self::encrypt($this->kp3); |
| 287 | 290 | |
| 288 | 291 | session_write_close(); |
@@ -344,7 +347,10 @@ discard block |
||
| 344 | 347 | */ |
| 345 | 348 | static function log_session_usage(&$arr,$label,$recursion=true,$limit=1000) |
| 346 | 349 | { |
| 347 | - if (!is_array($arr)) return; |
|
| 350 | + if (!is_array($arr)) |
|
| 351 | + { |
|
| 352 | + return; |
|
| 353 | + } |
|
| 348 | 354 | |
| 349 | 355 | $sizes = array(); |
| 350 | 356 | foreach($arr as $key => &$data) |
@@ -359,7 +365,10 @@ discard block |
||
| 359 | 365 | if ($diff > $limit) |
| 360 | 366 | { |
| 361 | 367 | error_log("strlen({$label}[$key])=".Vfs::hsize($size).", diff=".Vfs::hsize($diff)); |
| 362 | - if ($recursion) self::log_session_usage($arr[$key],$label.'['.$key.']',$recursion,$limit); |
|
| 368 | + if ($recursion) |
|
| 369 | + { |
|
| 370 | + self::log_session_usage($arr[$key],$label.'['.$key.']',$recursion,$limit); |
|
| 371 | + } |
|
| 363 | 372 | } |
| 364 | 373 | } |
| 365 | 374 | } |
@@ -457,7 +466,10 @@ discard block |
||
| 457 | 466 | $this->passwd = $passwd; |
| 458 | 467 | $this->passwd_type = $passwd_type; |
| 459 | 468 | } |
| 460 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) starting ..."); |
|
| 469 | + if (self::ERROR_LOG_DEBUG) |
|
| 470 | + { |
|
| 471 | + error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) starting ..."); |
|
| 472 | + } |
|
| 461 | 473 | |
| 462 | 474 | self::split_login_domain($login,$this->account_lid,$this->account_domain); |
| 463 | 475 | // add domain to the login, if not already there |
@@ -501,7 +513,10 @@ discard block |
||
| 501 | 513 | { |
| 502 | 514 | $this->log_access($this->reason,$login,$user_ip,0); // log unsuccessfull login |
| 503 | 515 | } |
| 504 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)"); |
|
| 516 | + if (self::ERROR_LOG_DEBUG) |
|
| 517 | + { |
|
| 518 | + error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)"); |
|
| 519 | + } |
|
| 505 | 520 | return false; |
| 506 | 521 | } |
| 507 | 522 | if ($fail_on_forced_password_change && Auth::check_password_change($this->reason) === false) |
@@ -551,7 +566,10 @@ discard block |
||
| 551 | 566 | $this->reason = 'account is expired'; |
| 552 | 567 | $this->cd_reason = self::CD_ACCOUNT_EXPIRED; |
| 553 | 568 | |
| 554 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)"); |
|
| 569 | + if (self::ERROR_LOG_DEBUG) |
|
| 570 | + { |
|
| 571 | + error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)"); |
|
| 572 | + } |
|
| 555 | 573 | return false; |
| 556 | 574 | } |
| 557 | 575 | |
@@ -575,25 +593,34 @@ discard block |
||
| 575 | 593 | 'passwd' => $this->passwd, |
| 576 | 594 | 'account_domain' => $this->account_domain, |
| 577 | 595 | 'user_ip' => $user_ip, |
| 578 | - ),'',true))) // true = run hooks from all apps, not just the ones the current user has perms to run |
|
| 596 | + ),'',true))) |
|
| 597 | + { |
|
| 598 | + // true = run hooks from all apps, not just the ones the current user has perms to run |
|
| 579 | 599 | { |
| 580 | 600 | foreach($hook_result as $reason) |
| 581 | 601 | { |
| 582 | 602 | if ($reason) // called hook requests to deny the session |
| 583 | 603 | { |
| 584 | 604 | $this->reason = $this->cd_reason = $reason; |
| 605 | + } |
|
| 585 | 606 | $this->log_access($this->reason,$login,$user_ip,0); // log unsuccessfull login |
| 586 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)"); |
|
| 607 | + if (self::ERROR_LOG_DEBUG) |
|
| 608 | + { |
|
| 609 | + error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) UNSUCCESSFULL ($this->reason)"); |
|
| 610 | + } |
|
| 587 | 611 | return false; |
| 588 | 612 | } |
| 589 | 613 | } |
| 590 | 614 | } |
| 591 | 615 | $GLOBALS['egw']->db->transaction_begin(); |
| 592 | 616 | $this->register_session($this->login,$user_ip,$now,$this->session_flags); |
| 593 | - if ($this->session_flags != 'A') // dont log anonymous sessions |
|
| 617 | + if ($this->session_flags != 'A') |
|
| 618 | + { |
|
| 619 | + // dont log anonymous sessions |
|
| 594 | 620 | { |
| 595 | 621 | $this->sessionid_access_log = $this->log_access($this->sessionid,$login,$user_ip,$this->account_id); |
| 596 | 622 | } |
| 623 | + } |
|
| 597 | 624 | Cache::setSession('phpgwapi', 'account_previous_login', $GLOBALS['egw']->auth->previous_login); |
| 598 | 625 | $GLOBALS['egw']->accounts->update_lastlogin($this->account_id,$user_ip); |
| 599 | 626 | $GLOBALS['egw']->db->transaction_commit(); |
@@ -609,7 +636,10 @@ discard block |
||
| 609 | 636 | self::egw_setcookie('last_loginid', $this->account_lid ,$now+1209600); /* For 2 weeks */ |
| 610 | 637 | self::egw_setcookie('last_domain',$this->account_domain,$now+1209600); |
| 611 | 638 | } |
| 612 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) successfull sessionid=$this->sessionid"); |
|
| 639 | + if (self::ERROR_LOG_DEBUG) |
|
| 640 | + { |
|
| 641 | + error_log(__METHOD__."($this->login,$this->passwd,$this->passwd_type,$no_session,$auth_check) successfull sessionid=$this->sessionid"); |
|
| 642 | + } |
|
| 613 | 643 | |
| 614 | 644 | return $this->sessionid; |
| 615 | 645 | } |
@@ -763,10 +793,13 @@ discard block |
||
| 763 | 793 | //error_log(__METHOD__."('$login', '$ip') false_ip=$false_ip, false_id=$false_id --> blocked=".array2string($blocked)); |
| 764 | 794 | |
| 765 | 795 | if ($blocked && $GLOBALS['egw_info']['server']['admin_mails'] && |
| 766 | - $GLOBALS['egw_info']['server']['login_blocked_mail_time'] < time()-5*60) // max. one mail every 5mins |
|
| 796 | + $GLOBALS['egw_info']['server']['login_blocked_mail_time'] < time()-5*60) |
|
| 797 | + { |
|
| 798 | + // max. one mail every 5mins |
|
| 767 | 799 | { |
| 768 | 800 | try { |
| 769 | 801 | $mailer = new Mailer(); |
| 802 | + } |
|
| 770 | 803 | // notify admin(s) via email |
| 771 | 804 | $mailer->setFrom('eGroupWare@'.$GLOBALS['egw_info']['server']['mail_suffix']); |
| 772 | 805 | $mailer->addHeader('Subject', lang("eGroupWare: login blocked for user '%1', IP %2",$login,$ip)); |
@@ -844,7 +877,10 @@ discard block |
||
| 844 | 877 | { |
| 845 | 878 | $sessionid = false; |
| 846 | 879 | } |
| 847 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() _SERVER[REQUEST_URI]='$_SERVER[REQUEST_URI]' returning ".print_r($sessionid,true)); |
|
| 880 | + if (self::ERROR_LOG_DEBUG) |
|
| 881 | + { |
|
| 882 | + error_log(__METHOD__."() _SERVER[REQUEST_URI]='$_SERVER[REQUEST_URI]' returning ".print_r($sessionid,true)); |
|
| 883 | + } |
|
| 848 | 884 | return $sessionid; |
| 849 | 885 | } |
| 850 | 886 | |
@@ -874,7 +910,10 @@ discard block |
||
| 874 | 910 | */ |
| 875 | 911 | function verify($sessionid=null,$kp3=null) |
| 876 | 912 | { |
| 877 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid','$kp3') ".function_backtrace()); |
|
| 913 | + if (self::ERROR_LOG_DEBUG) |
|
| 914 | + { |
|
| 915 | + error_log(__METHOD__."('$sessionid','$kp3') ".function_backtrace()); |
|
| 916 | + } |
|
| 878 | 917 | |
| 879 | 918 | $fill_egw_info_and_repositories = !$GLOBALS['egw_info']['flags']['restored_from_session']; |
| 880 | 919 | |
@@ -890,7 +929,10 @@ discard block |
||
| 890 | 929 | |
| 891 | 930 | if (!$this->sessionid) |
| 892 | 931 | { |
| 893 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') get_sessionid()='".self::get_sessionid()."' No session ID"); |
|
| 932 | + if (self::ERROR_LOG_DEBUG) |
|
| 933 | + { |
|
| 934 | + error_log(__METHOD__."('$sessionid') get_sessionid()='".self::get_sessionid()."' No session ID"); |
|
| 935 | + } |
|
| 894 | 936 | return false; |
| 895 | 937 | } |
| 896 | 938 | |
@@ -902,14 +944,20 @@ discard block |
||
| 902 | 944 | // check if we have a eGroupware session --> return false if not (but dont destroy it!) |
| 903 | 945 | if (is_null($_SESSION) || !isset($_SESSION[self::EGW_SESSION_VAR])) |
| 904 | 946 | { |
| 905 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') session does NOT exist!"); |
|
| 947 | + if (self::ERROR_LOG_DEBUG) |
|
| 948 | + { |
|
| 949 | + error_log(__METHOD__."('$sessionid') session does NOT exist!"); |
|
| 950 | + } |
|
| 906 | 951 | return false; |
| 907 | 952 | } |
| 908 | 953 | $session =& $_SESSION[self::EGW_SESSION_VAR]; |
| 909 | 954 | |
| 910 | 955 | if ($session['session_dla'] <= time() - $GLOBALS['egw_info']['server']['sessions_timeout']) |
| 911 | 956 | { |
| 912 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$sessionid') session timed out!"); |
|
| 957 | + if (self::ERROR_LOG_DEBUG) |
|
| 958 | + { |
|
| 959 | + error_log(__METHOD__."('$sessionid') session timed out!"); |
|
| 960 | + } |
|
| 913 | 961 | $this->destroy($sessionid,$kp3); |
| 914 | 962 | return false; |
| 915 | 963 | } |
@@ -937,7 +985,10 @@ discard block |
||
| 937 | 985 | $this->account_id = $GLOBALS['egw']->accounts->name2id($this->account_lid,'account_lid','u'); |
| 938 | 986 | if (!$this->account_id) |
| 939 | 987 | { |
| 940 | - if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) !accounts::name2id('$this->account_lid')"); |
|
| 988 | + if (self::ERROR_LOG_DEBUG) |
|
| 989 | + { |
|
| 990 | + error_log("*** Session::verify($sessionid) !accounts::name2id('$this->account_lid')"); |
|
| 991 | + } |
|
| 941 | 992 | return false; |
| 942 | 993 | } |
| 943 | 994 | |
@@ -955,7 +1006,10 @@ discard block |
||
| 955 | 1006 | |
| 956 | 1007 | if ($GLOBALS['egw']->accounts->is_expired($GLOBALS['egw_info']['user'])) |
| 957 | 1008 | { |
| 958 | - if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) accounts is expired"); |
|
| 1009 | + if (self::ERROR_LOG_DEBUG) |
|
| 1010 | + { |
|
| 1011 | + error_log("*** Session::verify($sessionid) accounts is expired"); |
|
| 1012 | + } |
|
| 959 | 1013 | return false; |
| 960 | 1014 | } |
| 961 | 1015 | $this->passwd = base64_decode(Cache::getSession('phpgwapi', 'password')); |
@@ -966,7 +1020,10 @@ discard block |
||
| 966 | 1020 | } |
| 967 | 1021 | if ($this->account_domain != $GLOBALS['egw_info']['user']['domain']) |
| 968 | 1022 | { |
| 969 | - if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) wrong domain"); |
|
| 1023 | + if (self::ERROR_LOG_DEBUG) |
|
| 1024 | + { |
|
| 1025 | + error_log("*** Session::verify($sessionid) wrong domain"); |
|
| 1026 | + } |
|
| 970 | 1027 | return false; |
| 971 | 1028 | } |
| 972 | 1029 | |
@@ -975,7 +1032,10 @@ discard block |
||
| 975 | 1032 | if (strtoupper(substr(PHP_OS,0,3)) != 'WIN' && (!$GLOBALS['egw_info']['user']['session_ip'] || |
| 976 | 1033 | $GLOBALS['egw_info']['user']['session_ip'] != $this->getuser_ip())) |
| 977 | 1034 | { |
| 978 | - if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) wrong IP"); |
|
| 1035 | + if (self::ERROR_LOG_DEBUG) |
|
| 1036 | + { |
|
| 1037 | + error_log("*** Session::verify($sessionid) wrong IP"); |
|
| 1038 | + } |
|
| 979 | 1039 | return false; |
| 980 | 1040 | } |
| 981 | 1041 | } |
@@ -988,7 +1048,10 @@ discard block |
||
| 988 | 1048 | } |
| 989 | 1049 | if (!$this->account_lid) |
| 990 | 1050 | { |
| 991 | - if (self::ERROR_LOG_DEBUG) error_log("*** Session::verify($sessionid) !account_lid"); |
|
| 1051 | + if (self::ERROR_LOG_DEBUG) |
|
| 1052 | + { |
|
| 1053 | + error_log("*** Session::verify($sessionid) !account_lid"); |
|
| 1054 | + } |
|
| 992 | 1055 | return false; |
| 993 | 1056 | } |
| 994 | 1057 | |
@@ -1007,13 +1070,19 @@ discard block |
||
| 1007 | 1070 | $_REQUEST[self::EGW_SESSION_NAME] === $this->sessionid && |
| 1008 | 1071 | (!isset($_COOKIE[self::EGW_SESSION_NAME]) || $_COOKIE[self::EGW_SESSION_NAME] !== $_REQUEST[self::EGW_SESSION_NAME])) |
| 1009 | 1072 | { |
| 1010 | - if (self::ERROR_LOG_DEBUG) error_log("--> Session::verify($sessionid) SUCCESS, but NO required cookies set --> setting them now"); |
|
| 1073 | + if (self::ERROR_LOG_DEBUG) |
|
| 1074 | + { |
|
| 1075 | + error_log("--> Session::verify($sessionid) SUCCESS, but NO required cookies set --> setting them now"); |
|
| 1076 | + } |
|
| 1011 | 1077 | self::egw_setcookie(self::EGW_SESSION_NAME,$this->sessionid); |
| 1012 | 1078 | self::egw_setcookie('kp3',$this->kp3); |
| 1013 | 1079 | self::egw_setcookie('domain',$this->account_domain); |
| 1014 | 1080 | } |
| 1015 | 1081 | |
| 1016 | - if (self::ERROR_LOG_DEBUG) error_log("--> Session::verify($sessionid) SUCCESS"); |
|
| 1082 | + if (self::ERROR_LOG_DEBUG) |
|
| 1083 | + { |
|
| 1084 | + error_log("--> Session::verify($sessionid) SUCCESS"); |
|
| 1085 | + } |
|
| 1017 | 1086 | |
| 1018 | 1087 | return true; |
| 1019 | 1088 | } |
@@ -1033,14 +1102,20 @@ discard block |
||
| 1033 | 1102 | } |
| 1034 | 1103 | $this->log_access($sessionid); // log logout-time |
| 1035 | 1104 | |
| 1036 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($sessionid,$kp3)"); |
|
| 1105 | + if (self::ERROR_LOG_DEBUG) |
|
| 1106 | + { |
|
| 1107 | + error_log(__METHOD__."($sessionid,$kp3)"); |
|
| 1108 | + } |
|
| 1037 | 1109 | |
| 1038 | - if (is_numeric($sessionid)) // do we have a access-log-id --> get PHP session id |
|
| 1110 | + if (is_numeric($sessionid)) |
|
| 1111 | + { |
|
| 1112 | + // do we have a access-log-id --> get PHP session id |
|
| 1039 | 1113 | { |
| 1040 | 1114 | $sessionid = $GLOBALS['egw']->db->select(self::ACCESS_LOG_TABLE,'session_php',array( |
| 1041 | 1115 | 'sessionid' => $sessionid, |
| 1042 | 1116 | ),__LINE__,__FILE__)->fetchColumn(); |
| 1043 | 1117 | } |
| 1118 | + } |
|
| 1044 | 1119 | |
| 1045 | 1120 | Hooks::process(array( |
| 1046 | 1121 | 'location' => 'session_destroyed', |
@@ -1050,7 +1125,10 @@ discard block |
||
| 1050 | 1125 | // Only do the following, if where working with the current user |
| 1051 | 1126 | if (!$GLOBALS['egw_info']['user']['sessionid'] || $sessionid == $GLOBALS['egw_info']['user']['sessionid']) |
| 1052 | 1127 | { |
| 1053 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__." ********* about to call session_destroy!"); |
|
| 1128 | + if (self::ERROR_LOG_DEBUG) |
|
| 1129 | + { |
|
| 1130 | + error_log(__METHOD__." ********* about to call session_destroy!"); |
|
| 1131 | + } |
|
| 1054 | 1132 | session_unset(); |
| 1055 | 1133 | @session_destroy(); |
| 1056 | 1134 | // we need to (re-)load the eGW session-handler, as session_destroy unloads custom session-handlers |
@@ -1145,7 +1223,10 @@ discard block |
||
| 1145 | 1223 | } |
| 1146 | 1224 | else |
| 1147 | 1225 | { |
| 1148 | - if ($othervars) $extravars .= ($extravars?'&':'').$othervars; |
|
| 1226 | + if ($othervars) |
|
| 1227 | + { |
|
| 1228 | + $extravars .= ($extravars?'&':'').$othervars; |
|
| 1229 | + } |
|
| 1149 | 1230 | } |
| 1150 | 1231 | |
| 1151 | 1232 | // parse extravars string into the vars array |
@@ -1154,7 +1235,11 @@ discard block |
||
| 1154 | 1235 | foreach(explode('&',$extravars) as $expr) |
| 1155 | 1236 | { |
| 1156 | 1237 | list($var,$val) = explode('=', $expr,2); |
| 1157 | - if (strpos($val,'%26') != false) $val = str_replace('%26','&',$val); // make sure to not double encode & |
|
| 1238 | + if (strpos($val,'%26') != false) |
|
| 1239 | + { |
|
| 1240 | + $val = str_replace('%26','&',$val); |
|
| 1241 | + } |
|
| 1242 | + // make sure to not double encode & |
|
| 1158 | 1243 | if (substr($var,-2) == '[]') |
| 1159 | 1244 | { |
| 1160 | 1245 | $vars[substr($var,0,-2)][] = $val; |
@@ -1235,14 +1320,22 @@ discard block |
||
| 1235 | 1320 | { |
| 1236 | 1321 | self::set_cookiedomain(); |
| 1237 | 1322 | } |
| 1238 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."($cookiename,$cookievalue,$cookietime,$cookiepath,".self::$cookie_domain.")"); |
|
| 1323 | + if (self::ERROR_LOG_DEBUG) |
|
| 1324 | + { |
|
| 1325 | + error_log(__METHOD__."($cookiename,$cookievalue,$cookietime,$cookiepath,".self::$cookie_domain.")"); |
|
| 1326 | + } |
|
| 1239 | 1327 | |
| 1240 | 1328 | // if we are installed in iOS as web-app, we must not set a cookietime==0 (session-cookie), |
| 1241 | 1329 | // as every change between apps will cause the cookie to get lost |
| 1242 | 1330 | static $is_iOS = null; |
| 1243 | - if (!$cookietime && !isset($is_iOS)) $is_iOS = (bool)preg_match('/^(iPhone|iPad|iPod)/i', Header\UserAgent::mobile()); |
|
| 1331 | + if (!$cookietime && !isset($is_iOS)) |
|
| 1332 | + { |
|
| 1333 | + $is_iOS = (bool)preg_match('/^(iPhone|iPad|iPod)/i', Header\UserAgent::mobile()); |
|
| 1334 | + } |
|
| 1244 | 1335 | |
| 1245 | - if(!headers_sent()) // gives only a warning, but can not send the cookie anyway |
|
| 1336 | + if(!headers_sent()) |
|
| 1337 | + { |
|
| 1338 | + // gives only a warning, but can not send the cookie anyway |
|
| 1246 | 1339 | { |
| 1247 | 1340 | setcookie($cookiename, $cookievalue, |
| 1248 | 1341 | !$cookietime && $is_iOS ? time()+self::IOS_SESSION_COOKIE_LIFETIME : $cookietime, |
@@ -1250,6 +1343,7 @@ discard block |
||
| 1250 | 1343 | // if called via HTTPS, only send cookie for https and only allow cookie access via HTTP (true) |
| 1251 | 1344 | empty($GLOBALS['egw_info']['server']['insecure_cookies']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off', true); |
| 1252 | 1345 | } |
| 1346 | + } |
|
| 1253 | 1347 | } |
| 1254 | 1348 | |
| 1255 | 1349 | /** |
@@ -1301,15 +1395,25 @@ discard block |
||
| 1301 | 1395 | */ |
| 1302 | 1396 | public static function search_instance($login,$domain_requested,&$default_domain,$server_names,array $domains=null) |
| 1303 | 1397 | { |
| 1304 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."('$login','$domain_requested',".array2string($default_domain).".".array2string($server_names).".".array2string($domains).")"); |
|
| 1398 | + if (self::ERROR_LOG_DEBUG) |
|
| 1399 | + { |
|
| 1400 | + error_log(__METHOD__."('$login','$domain_requested',".array2string($default_domain).".".array2string($server_names).".".array2string($domains).")"); |
|
| 1401 | + } |
|
| 1305 | 1402 | |
| 1306 | - if (is_null($domains)) $domains = $GLOBALS['egw_domain']; |
|
| 1403 | + if (is_null($domains)) |
|
| 1404 | + { |
|
| 1405 | + $domains = $GLOBALS['egw_domain']; |
|
| 1406 | + } |
|
| 1307 | 1407 | |
| 1308 | - if (!isset($default_domain) || !isset($domains[$default_domain])) // allow to overwrite the default domain |
|
| 1408 | + if (!isset($default_domain) || !isset($domains[$default_domain])) |
|
| 1409 | + { |
|
| 1410 | + // allow to overwrite the default domain |
|
| 1309 | 1411 | { |
| 1310 | 1412 | foreach((array)$server_names as $server_name) |
| 1311 | 1413 | { |
| 1312 | - list($server_name) = explode(':', $server_name); // remove port from HTTP_HOST |
|
| 1414 | + list($server_name) = explode(':', $server_name); |
|
| 1415 | + } |
|
| 1416 | + // remove port from HTTP_HOST |
|
| 1313 | 1417 | if(isset($domains[$server_name])) |
| 1314 | 1418 | { |
| 1315 | 1419 | $default_domain = $server_name; |
@@ -1334,11 +1438,14 @@ discard block |
||
| 1334 | 1438 | } |
| 1335 | 1439 | } |
| 1336 | 1440 | } |
| 1337 | - if (isset($login)) // on login |
|
| 1441 | + if (isset($login)) |
|
| 1442 | + { |
|
| 1443 | + // on login |
|
| 1338 | 1444 | { |
| 1339 | 1445 | if (strpos($login,'@') === false || count($domains) == 1) |
| 1340 | 1446 | { |
| 1341 | 1447 | $login .= '@' . (isset($_POST['logindomain']) ? $_POST['logindomain'] : $default_domain); |
| 1448 | + } |
|
| 1342 | 1449 | } |
| 1343 | 1450 | $parts = explode('@',$login); |
| 1344 | 1451 | $domain = array_pop($parts); |
@@ -1352,7 +1459,10 @@ discard block |
||
| 1352 | 1459 | { |
| 1353 | 1460 | $domain = $default_domain; |
| 1354 | 1461 | } |
| 1355 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() default_domain=".array2string($default_domain).', login='.array2string($login)." returning ".array2string($domain)); |
|
| 1462 | + if (self::ERROR_LOG_DEBUG) |
|
| 1463 | + { |
|
| 1464 | + error_log(__METHOD__."() default_domain=".array2string($default_domain).', login='.array2string($login)." returning ".array2string($domain)); |
|
| 1465 | + } |
|
| 1356 | 1466 | |
| 1357 | 1467 | return $domain; |
| 1358 | 1468 | } |
@@ -1379,7 +1489,10 @@ discard block |
||
| 1379 | 1489 | $action = $_SERVER['PHP_SELF']; |
| 1380 | 1490 | // remove EGroupware path, if not installed in webroot |
| 1381 | 1491 | $egw_path = $GLOBALS['egw_info']['server']['webserver_url']; |
| 1382 | - if ($egw_path[0] != '/') $egw_path = parse_url($egw_path,PHP_URL_PATH); |
|
| 1492 | + if ($egw_path[0] != '/') |
|
| 1493 | + { |
|
| 1494 | + $egw_path = parse_url($egw_path,PHP_URL_PATH); |
|
| 1495 | + } |
|
| 1383 | 1496 | if ($action == '/Microsoft-Server-ActiveSync') |
| 1384 | 1497 | { |
| 1385 | 1498 | $action .= '?Cmd='.$_GET['Cmd'].'&DeviceId='.$_GET['DeviceId']; |
@@ -1404,7 +1517,10 @@ discard block |
||
| 1404 | 1517 | |
| 1405 | 1518 | $_SESSION[self::EGW_SESSION_VAR]['session_dla'] = time(); |
| 1406 | 1519 | $_SESSION[self::EGW_SESSION_VAR]['session_action'] = $action; |
| 1407 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__.'() _SESSION['.self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR])); |
|
| 1520 | + if (self::ERROR_LOG_DEBUG) |
|
| 1521 | + { |
|
| 1522 | + error_log(__METHOD__.'() _SESSION['.self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR])); |
|
| 1523 | + } |
|
| 1408 | 1524 | |
| 1409 | 1525 | return $action; |
| 1410 | 1526 | } |
@@ -1530,7 +1646,10 @@ discard block |
||
| 1530 | 1646 | */ |
| 1531 | 1647 | public static function init_handler() |
| 1532 | 1648 | { |
| 1533 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__.'() session_handler='.self::$session_handler.', egw_info[server][session_handler]='.$GLOBALS['egw_info']['server']['session_handler'].' called from:'.function_backtrace()); |
|
| 1649 | + if (self::ERROR_LOG_DEBUG) |
|
| 1650 | + { |
|
| 1651 | + error_log(__METHOD__.'() session_handler='.self::$session_handler.', egw_info[server][session_handler]='.$GLOBALS['egw_info']['server']['session_handler'].' called from:'.function_backtrace()); |
|
| 1652 | + } |
|
| 1534 | 1653 | |
| 1535 | 1654 | ini_set('session.use_cookies',0); // disable the automatic use of cookies, as it uses the path / by default |
| 1536 | 1655 | session_name(self::EGW_SESSION_NAME); |
@@ -1540,10 +1659,16 @@ discard block |
||
| 1540 | 1659 | self::cache_control(); |
| 1541 | 1660 | $ok = session_start(); |
| 1542 | 1661 | self::decrypt(); |
| 1543 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() sessionid=$sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR])); |
|
| 1662 | + if (self::ERROR_LOG_DEBUG) |
|
| 1663 | + { |
|
| 1664 | + error_log(__METHOD__."() sessionid=$sessionid, _SESSION[".self::EGW_SESSION_VAR.']='.array2string($_SESSION[self::EGW_SESSION_VAR])); |
|
| 1665 | + } |
|
| 1544 | 1666 | return $ok; |
| 1545 | 1667 | } |
| 1546 | - if (self::ERROR_LOG_DEBUG) error_log(__METHOD__."() no active session!"); |
|
| 1668 | + if (self::ERROR_LOG_DEBUG) |
|
| 1669 | + { |
|
| 1670 | + error_log(__METHOD__."() no active session!"); |
|
| 1671 | + } |
|
| 1547 | 1672 | |
| 1548 | 1673 | return false; |
| 1549 | 1674 | } |
@@ -1601,9 +1726,12 @@ discard block |
||
| 1601 | 1726 | error_log(__METHOD__."($expire) called, but header already sent in $file: $line"); |
| 1602 | 1727 | return; |
| 1603 | 1728 | } |
| 1604 | - if($expire === true) // same behavior as session_cache_limiter('private_no_expire') |
|
| 1729 | + if($expire === true) |
|
| 1730 | + { |
|
| 1731 | + // same behavior as session_cache_limiter('private_no_expire') |
|
| 1605 | 1732 | { |
| 1606 | 1733 | header('Cache-Control: private, max-age='.(60*session_cache_expire())); |
| 1734 | + } |
|
| 1607 | 1735 | header_remove('Expires'); |
| 1608 | 1736 | } |
| 1609 | 1737 | elseif ($private) |
@@ -1617,10 +1745,13 @@ discard block |
||
| 1617 | 1745 | header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expire) . ' GMT'); |
| 1618 | 1746 | } |
| 1619 | 1747 | // remove Pragma header, might be set by old header |
| 1620 | - if (function_exists('header_remove')) // PHP 5.3+ |
|
| 1748 | + if (function_exists('header_remove')) |
|
| 1749 | + { |
|
| 1750 | + // PHP 5.3+ |
|
| 1621 | 1751 | { |
| 1622 | 1752 | header_remove('Pragma'); |
| 1623 | 1753 | } |
| 1754 | + } |
|
| 1624 | 1755 | else |
| 1625 | 1756 | { |
| 1626 | 1757 | header('Pragma:'); |
@@ -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; |
@@ -383,7 +383,10 @@ discard block |
||
| 383 | 383 | if ($state['wsrep_local_state_comment'] == 'Synced' || |
| 384 | 384 | // if we have only 2 nodes (2. one starting), we can only use the donor |
| 385 | 385 | $state['wsrep_local_state_comment'] == 'Donor/Desynced' && |
| 386 | - $state['wsrep_cluster_size'] == 2) return; |
|
| 386 | + $state['wsrep_cluster_size'] == 2) |
|
| 387 | + { |
|
| 388 | + return; |
|
| 389 | + } |
|
| 387 | 390 | |
| 388 | 391 | throw new Db\Exception\Connection('Node is NOT Synced! '.array2string($state)); |
| 389 | 392 | } |
@@ -402,7 +405,10 @@ discard block |
||
| 402 | 405 | $hosts = explode(';', $this->Host[0] == '@' ? getenv(substr($this->Host, 1)) : $this->Host); |
| 403 | 406 | $num_hosts = count($hosts); |
| 404 | 407 | $n =& Cache::getSession(__CLASS__, $this->Host); |
| 405 | - if (!isset($n)) $n = 0; |
|
| 408 | + if (!isset($n)) |
|
| 409 | + { |
|
| 410 | + $n = 0; |
|
| 411 | + } |
|
| 406 | 412 | |
| 407 | 413 | if ($next && ++$n >= $num_hosts+2) |
| 408 | 414 | { |
@@ -432,7 +438,10 @@ discard block |
||
| 432 | 438 | foreach(array('Database','User','Password','Port','Type') as $name) |
| 433 | 439 | { |
| 434 | 440 | $$name = $this->$name; |
| 435 | - if (${$name}[0] == '@' && $name != 'Password') $$name = getenv(substr($$name, 1)); |
|
| 441 | + if (${$name}[0] == '@' && $name != 'Password') |
|
| 442 | + { |
|
| 443 | + $$name = getenv(substr($$name, 1)); |
|
| 444 | + } |
|
| 436 | 445 | } |
| 437 | 446 | $this->setupType = $php_extension = $Type; |
| 438 | 447 | |
@@ -451,7 +460,10 @@ discard block |
||
| 451 | 460 | $Type = 'mssql'; |
| 452 | 461 | // fall through |
| 453 | 462 | case 'mssql': |
| 454 | - if ($Port) $Host .= ','.$Port; |
|
| 463 | + if ($Port) |
|
| 464 | + { |
|
| 465 | + $Host .= ','.$Port; |
|
| 466 | + } |
|
| 455 | 467 | break; |
| 456 | 468 | |
| 457 | 469 | case 'odbc_oracle': |
@@ -486,7 +498,10 @@ discard block |
||
| 486 | 498 | $this->Type = 'mysql'; // need to be "mysql", so apps can check just for "mysql"! |
| 487 | 499 | // fall through |
| 488 | 500 | default: |
| 489 | - if ($Port) $Host .= ':'.$Port; |
|
| 501 | + if ($Port) |
|
| 502 | + { |
|
| 503 | + $Host .= ':'.$Port; |
|
| 504 | + } |
|
| 490 | 505 | break; |
| 491 | 506 | } |
| 492 | 507 | if (!isset($GLOBALS['egw']->ADOdb) || // we have no connection so far |
@@ -501,10 +516,13 @@ discard block |
||
| 501 | 516 | { |
| 502 | 517 | throw new Db\Exception\Connection("Necessary php database support for $this->Type (".PHP_SHLIB_PREFIX.$php_extension.'.'.PHP_SHLIB_SUFFIX.") not loaded and can't be loaded, exiting !!!"); |
| 503 | 518 | } |
| 504 | - if (!isset($GLOBALS['egw']->ADOdb)) // use the global object to store the connection |
|
| 519 | + if (!isset($GLOBALS['egw']->ADOdb)) |
|
| 520 | + { |
|
| 521 | + // use the global object to store the connection |
|
| 505 | 522 | { |
| 506 | 523 | $this->Link_ID =& $GLOBALS['egw']->ADOdb; |
| 507 | 524 | } |
| 525 | + } |
|
| 508 | 526 | else |
| 509 | 527 | { |
| 510 | 528 | $this->privat_Link_ID = True; // remember that we use a privat Link_ID for disconnect |
@@ -600,7 +618,11 @@ discard block |
||
| 600 | 618 | */ |
| 601 | 619 | function __sleep() |
| 602 | 620 | { |
| 603 | - if (!empty($this->setupType)) $this->Type = $this->setupType; // restore Type eg. to mysqli |
|
| 621 | + if (!empty($this->setupType)) |
|
| 622 | + { |
|
| 623 | + $this->Type = $this->setupType; |
|
| 624 | + } |
|
| 625 | + // restore Type eg. to mysqli |
|
| 604 | 626 | |
| 605 | 627 | $vars = get_object_vars($this); |
| 606 | 628 | unset($vars['Link_ID']); |
@@ -663,7 +685,10 @@ discard block |
||
| 663 | 685 | unset($this->Link_ID); |
| 664 | 686 | $this->Link_ID = 0; |
| 665 | 687 | |
| 666 | - if (!empty($this->setupType)) $this->Type = $this->setupType; |
|
| 688 | + if (!empty($this->setupType)) |
|
| 689 | + { |
|
| 690 | + $this->Type = $this->setupType; |
|
| 691 | + } |
|
| 667 | 692 | } |
| 668 | 693 | |
| 669 | 694 | /** |
@@ -772,16 +797,22 @@ discard block |
||
| 772 | 797 | } |
| 773 | 798 | if (!$rs) |
| 774 | 799 | { |
| 775 | - if ($reconnect && $this->Type == 'mysql' && $this->Errno == 2006) // Server has gone away |
|
| 800 | + if ($reconnect && $this->Type == 'mysql' && $this->Errno == 2006) |
|
| 801 | + { |
|
| 802 | + // Server has gone away |
|
| 776 | 803 | { |
| 777 | 804 | $this->disconnect(); |
| 805 | + } |
|
| 778 | 806 | return $this->query($Query_String, $line, $file, $offset, $num_rows, $inputarr, $fetchmode, false); |
| 779 | 807 | } |
| 780 | 808 | throw new Db\Exception\InvalidSql("Invalid SQL: ".(is_array($Query_String)?$Query_String[0]:$Query_String). |
| 781 | 809 | "\n$this->Error ($this->Errno)". |
| 782 | 810 | ($inputarr ? "\nParameters: '".implode("','",$inputarr)."'":''), $this->Errno); |
| 783 | 811 | } |
| 784 | - elseif(empty($rs->sql)) $rs->sql = $Query_String; |
|
| 812 | + elseif(empty($rs->sql)) |
|
| 813 | + { |
|
| 814 | + $rs->sql = $Query_String; |
|
| 815 | + } |
|
| 785 | 816 | return $rs; |
| 786 | 817 | } |
| 787 | 818 | |
@@ -865,9 +896,12 @@ discard block |
||
| 865 | 896 | } |
| 866 | 897 | $id = $this->Link_ID->PO_Insert_ID($table,$field); // simulates Insert_ID with "SELECT MAX($field) FROM $table" if not native availible |
| 867 | 898 | |
| 868 | - if ($id === False) // function not supported |
|
| 899 | + if ($id === False) |
|
| 900 | + { |
|
| 901 | + // function not supported |
|
| 869 | 902 | { |
| 870 | 903 | echo "<p>db::get_last_insert_id(table='$table',field='$field') not yet implemented for db-type '$this->Type' OR no insert operation before</p>\n"; |
| 904 | + } |
|
| 871 | 905 | echo '<p>'.function_backtrace()."</p>\n"; |
| 872 | 906 | return -1; |
| 873 | 907 | } |
@@ -881,7 +915,10 @@ discard block |
||
| 881 | 915 | */ |
| 882 | 916 | function affected_rows() |
| 883 | 917 | { |
| 884 | - if ($this->log_updates) return 0; |
|
| 918 | + if ($this->log_updates) |
|
| 919 | + { |
|
| 920 | + return 0; |
|
| 921 | + } |
|
| 885 | 922 | |
| 886 | 923 | if (!$this->Link_ID && !$this->connect()) |
| 887 | 924 | { |
@@ -915,9 +952,18 @@ discard block |
||
| 915 | 952 | { |
| 916 | 953 | // for backwards compatibilty (depreciated) |
| 917 | 954 | $flags = null; |
| 918 | - if($column->auto_increment) $flags .= "auto_increment "; |
|
| 919 | - if($column->primary_key) $flags .= "primary_key "; |
|
| 920 | - if($column->binary) $flags .= "binary "; |
|
| 955 | + if($column->auto_increment) |
|
| 956 | + { |
|
| 957 | + $flags .= "auto_increment "; |
|
| 958 | + } |
|
| 959 | + if($column->primary_key) |
|
| 960 | + { |
|
| 961 | + $flags .= "primary_key "; |
|
| 962 | + } |
|
| 963 | + if($column->binary) |
|
| 964 | + { |
|
| 965 | + $flags .= "binary "; |
|
| 966 | + } |
|
| 921 | 967 | |
| 922 | 968 | $metadata[$i] = array( |
| 923 | 969 | 'table' => $table, |
@@ -954,7 +1000,10 @@ discard block |
||
| 954 | 1000 | */ |
| 955 | 1001 | function table_names($just_name=false) |
| 956 | 1002 | { |
| 957 | - if (!$this->Link_ID) $this->connect(); |
|
| 1003 | + if (!$this->Link_ID) |
|
| 1004 | + { |
|
| 1005 | + $this->connect(); |
|
| 1006 | + } |
|
| 958 | 1007 | if (!$this->Link_ID) |
| 959 | 1008 | { |
| 960 | 1009 | return False; |
@@ -1105,8 +1154,14 @@ discard block |
||
| 1105 | 1154 | { |
| 1106 | 1155 | case 'mysql': |
| 1107 | 1156 | $sql = 'GROUP_CONCAT('.$expr; |
| 1108 | - if ($order_by) $sql .= ' ORDER BY '.$order_by; |
|
| 1109 | - if ($separator != ',') $sql .= ' SEPARATOR '.$this->quote($separator); |
|
| 1157 | + if ($order_by) |
|
| 1158 | + { |
|
| 1159 | + $sql .= ' ORDER BY '.$order_by; |
|
| 1160 | + } |
|
| 1161 | + if ($separator != ',') |
|
| 1162 | + { |
|
| 1163 | + $sql .= ' SEPARATOR '.$this->quote($separator); |
|
| 1164 | + } |
|
| 1110 | 1165 | $sql .= ')'; |
| 1111 | 1166 | break; |
| 1112 | 1167 | |
@@ -1116,7 +1171,10 @@ discard block |
||
| 1116 | 1171 | return false; |
| 1117 | 1172 | } |
| 1118 | 1173 | $sql = 'ARRAY_TO_STRING(ARRAY_AGG('.$expr; |
| 1119 | - if ($order_by) $sql .= ' ORDER BY '.$order_by; |
|
| 1174 | + if ($order_by) |
|
| 1175 | + { |
|
| 1176 | + $sql .= ' ORDER BY '.$order_by; |
|
| 1177 | + } |
|
| 1120 | 1178 | $sql .= '), '.$this->quote($separator).')'; |
| 1121 | 1179 | break; |
| 1122 | 1180 | |
@@ -1339,12 +1397,18 @@ discard block |
||
| 1339 | 1397 | */ |
| 1340 | 1398 | function quote($value,$type=False,$not_null=true,$length=null,$glue=',') |
| 1341 | 1399 | { |
| 1342 | - if ($this->Debug) echo "<p>db::quote(".(is_null($value)?'NULL':"'$value'").",'$type','$not_null')</p>\n"; |
|
| 1400 | + if ($this->Debug) |
|
| 1401 | + { |
|
| 1402 | + echo "<p>db::quote(".(is_null($value)?'NULL':"'$value'").",'$type','$not_null')</p>\n"; |
|
| 1403 | + } |
|
| 1343 | 1404 | |
| 1344 | - if (!$not_null && is_null($value)) // writing unset php-variables and those set to NULL now as SQL NULL |
|
| 1405 | + if (!$not_null && is_null($value)) |
|
| 1406 | + { |
|
| 1407 | + // writing unset php-variables and those set to NULL now as SQL NULL |
|
| 1345 | 1408 | { |
| 1346 | 1409 | return 'NULL'; |
| 1347 | 1410 | } |
| 1411 | + } |
|
| 1348 | 1412 | switch($type) |
| 1349 | 1413 | { |
| 1350 | 1414 | case 'int': |
@@ -1359,10 +1423,13 @@ discard block |
||
| 1359 | 1423 | // There for we have to keep it as float by using round instead the int cast. |
| 1360 | 1424 | return is_float($value) ? round($value) : (int) $value; |
| 1361 | 1425 | case 'bool': |
| 1362 | - if ($this->Type == 'mysql') // maybe it's not longer necessary with mysql5 |
|
| 1426 | + if ($this->Type == 'mysql') |
|
| 1427 | + { |
|
| 1428 | + // maybe it's not longer necessary with mysql5 |
|
| 1363 | 1429 | { |
| 1364 | 1430 | return $value ? 1 : 0; |
| 1365 | 1431 | } |
| 1432 | + } |
|
| 1366 | 1433 | return $value ? 'true' : 'false'; |
| 1367 | 1434 | case 'float': |
| 1368 | 1435 | case 'decimal': |
@@ -1410,7 +1477,10 @@ discard block |
||
| 1410 | 1477 | } |
| 1411 | 1478 | // casting boolean explicitly to string, as ADODB_postgres64::qstr() has an unwanted special handling |
| 1412 | 1479 | // for boolean types, causing it to return "true" or "false" and not a quoted string like "'1'"! |
| 1413 | - if (is_bool($value)) $value = (string)$value; |
|
| 1480 | + if (is_bool($value)) |
|
| 1481 | + { |
|
| 1482 | + $value = (string)$value; |
|
| 1483 | + } |
|
| 1414 | 1484 | |
| 1415 | 1485 | // need to cast to string, as ADOdb 5.20 would return NULL instead of '' for NULL, causing us to write that into NOT NULL columns |
| 1416 | 1486 | return $this->Link_ID->qstr((string)$value); |
@@ -1440,15 +1510,21 @@ discard block |
||
| 1440 | 1510 | */ |
| 1441 | 1511 | function column_data_implode($glue,$array,$use_key=True,$only=False,$column_definitions=False) |
| 1442 | 1512 | { |
| 1443 | - if (!is_array($array)) // this allows to give an SQL-string for delete or update |
|
| 1513 | + if (!is_array($array)) |
|
| 1514 | + { |
|
| 1515 | + // this allows to give an SQL-string for delete or update |
|
| 1444 | 1516 | { |
| 1445 | 1517 | return $array; |
| 1446 | 1518 | } |
| 1519 | + } |
|
| 1447 | 1520 | if (!$column_definitions) |
| 1448 | 1521 | { |
| 1449 | 1522 | $column_definitions = $this->column_definitions; |
| 1450 | 1523 | } |
| 1451 | - if ($this->Debug) echo "<p>db::column_data_implode('$glue',".print_r($array,True).",'$use_key',".print_r($only,True).",<pre>".print_r($column_definitions,True)."</pre>\n"; |
|
| 1524 | + if ($this->Debug) |
|
| 1525 | + { |
|
| 1526 | + echo "<p>db::column_data_implode('$glue',".print_r($array,True).",'$use_key',".print_r($only,True).",<pre>".print_r($column_definitions,True)."</pre>\n"; |
|
| 1527 | + } |
|
| 1452 | 1528 | |
| 1453 | 1529 | // do we need to truncate varchars to their max length (INSERT and UPDATE on Postgres) |
| 1454 | 1530 | $truncate_varchar = $glue == ',' && $this->capabilities[self::CAPABILITY_REQUIRE_TRUNCATE_VARCHAR]; |
@@ -1465,7 +1541,10 @@ discard block |
||
| 1465 | 1541 | // fix "table.column" expressions, to not trigger exception, if column alone would work |
| 1466 | 1542 | if (!is_int($key) && is_array($column_definitions) && !isset($column_definitions[$key])) |
| 1467 | 1543 | { |
| 1468 | - if (strpos($key, '.') !== false) list(, $col) = explode('.', $key); |
|
| 1544 | + if (strpos($key, '.') !== false) |
|
| 1545 | + { |
|
| 1546 | + list(, $col) = explode('.', $key); |
|
| 1547 | + } |
|
| 1469 | 1548 | if (!isset($column_definitions[$col])) |
| 1470 | 1549 | { |
| 1471 | 1550 | throw new Db\Exception\InvalidSql("db::column_data_implode('$glue',".print_r($array,True).",'$use_key',".print_r($only,True).",<pre>".print_r($column_definitions,True)."</pre><b>nothing known about column '$key'!</b>"); |
@@ -1505,7 +1584,11 @@ discard block |
||
| 1505 | 1584 | } |
| 1506 | 1585 | elseif (is_int($key) && $use_key===True) |
| 1507 | 1586 | { |
| 1508 | - if (empty($data)) continue; // would give SQL error |
|
| 1587 | + if (empty($data)) |
|
| 1588 | + { |
|
| 1589 | + continue; |
|
| 1590 | + } |
|
| 1591 | + // would give SQL error |
|
| 1509 | 1592 | $values[] = $data; |
| 1510 | 1593 | } |
| 1511 | 1594 | elseif ($glue != ',' && $use_key === True && !$not_null && is_null($data)) |
@@ -1559,7 +1642,10 @@ discard block |
||
| 1559 | 1642 | function set_app($app) |
| 1560 | 1643 | { |
| 1561 | 1644 | // ease the transition to api |
| 1562 | - if ($app == 'phpgwapi') $app = 'api'; |
|
| 1645 | + if ($app == 'phpgwapi') |
|
| 1646 | + { |
|
| 1647 | + $app = 'api'; |
|
| 1648 | + } |
|
| 1563 | 1649 | |
| 1564 | 1650 | if ($this === $GLOBALS['egw']->db && $app != self::API_APPNAME) |
| 1565 | 1651 | { |
@@ -1584,7 +1670,10 @@ discard block |
||
| 1584 | 1670 | function get_table_definitions($app=False,$table=False) |
| 1585 | 1671 | { |
| 1586 | 1672 | // ease the transition to api |
| 1587 | - if ($app === 'phpgwapi') $app = 'api'; |
|
| 1673 | + if ($app === 'phpgwapi') |
|
| 1674 | + { |
|
| 1675 | + $app = 'api'; |
|
| 1676 | + } |
|
| 1588 | 1677 | |
| 1589 | 1678 | static $all_app_data = array(); |
| 1590 | 1679 | if ($app === true && $table) |
@@ -1642,10 +1731,16 @@ discard block |
||
| 1642 | 1731 | } |
| 1643 | 1732 | if ($table && (!$app_data || !isset($app_data[$table]))) |
| 1644 | 1733 | { |
| 1645 | - if ($this->Debug) echo "<p>!!!get_table_definitions($app,$table) failed!!!</p>\n"; |
|
| 1734 | + if ($this->Debug) |
|
| 1735 | + { |
|
| 1736 | + echo "<p>!!!get_table_definitions($app,$table) failed!!!</p>\n"; |
|
| 1737 | + } |
|
| 1646 | 1738 | return False; |
| 1647 | 1739 | } |
| 1648 | - if ($this->Debug) echo "<p>get_table_definitions($app,$table) succeeded</p>\n"; |
|
| 1740 | + if ($this->Debug) |
|
| 1741 | + { |
|
| 1742 | + echo "<p>get_table_definitions($app,$table) succeeded</p>\n"; |
|
| 1743 | + } |
|
| 1649 | 1744 | return $table ? $app_data[$table] : $app_data; |
| 1650 | 1745 | } |
| 1651 | 1746 | |
@@ -1670,7 +1765,10 @@ discard block |
||
| 1670 | 1765 | $table_def = $db->get_table_definitions($app,$table); |
| 1671 | 1766 | $cached_columns = is_array($table_def) ? $table_def['fd'] : false; |
| 1672 | 1767 | } |
| 1673 | - if ($cached_columns === false) return null; |
|
| 1768 | + if ($cached_columns === false) |
|
| 1769 | + { |
|
| 1770 | + return null; |
|
| 1771 | + } |
|
| 1674 | 1772 | |
| 1675 | 1773 | return is_null($attribute) ? $cached_columns[$column] : $cached_columns[$column][$attribute]; |
| 1676 | 1774 | } |
@@ -1693,9 +1791,15 @@ discard block |
||
| 1693 | 1791 | */ |
| 1694 | 1792 | function insert($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false,$table_def=False) |
| 1695 | 1793 | { |
| 1696 | - if ($this->Debug) echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app')</p>\n"; |
|
| 1794 | + if ($this->Debug) |
|
| 1795 | + { |
|
| 1796 | + echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app')</p>\n"; |
|
| 1797 | + } |
|
| 1697 | 1798 | |
| 1698 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
| 1799 | + if (!$table_def) |
|
| 1800 | + { |
|
| 1801 | + $table_def = $this->get_table_definitions($app,$table); |
|
| 1802 | + } |
|
| 1699 | 1803 | |
| 1700 | 1804 | $sql_append = ''; |
| 1701 | 1805 | $cmd = 'INSERT'; |
@@ -1737,9 +1841,12 @@ discard block |
||
| 1737 | 1841 | $table = self::$tablealiases[$table]; |
| 1738 | 1842 | } |
| 1739 | 1843 | $inputarr = false; |
| 1740 | - if (isset($data[0]) && is_array($data[0])) // multiple data rows |
|
| 1844 | + if (isset($data[0]) && is_array($data[0])) |
|
| 1845 | + { |
|
| 1846 | + // multiple data rows |
|
| 1741 | 1847 | { |
| 1742 | 1848 | if ($where) throw new Exception\WrongParameter('Can NOT use $where together with multiple data rows in $data!'); |
| 1849 | + } |
|
| 1743 | 1850 | |
| 1744 | 1851 | $sql = "$cmd INTO $table "; |
| 1745 | 1852 | foreach($data as $k => $d) |
@@ -1755,15 +1862,22 @@ discard block |
||
| 1755 | 1862 | } |
| 1756 | 1863 | $sql .= $sql_append; |
| 1757 | 1864 | } |
| 1758 | - elseif ($use_prepared_statement && $this->Link_ID->_bindInputArray) // eg. MaxDB |
|
| 1865 | + elseif ($use_prepared_statement && $this->Link_ID->_bindInputArray) |
|
| 1759 | 1866 | { |
| 1760 | - $this->Link_ID->Param(false); // reset param-counter |
|
| 1867 | + // eg. MaxDB |
|
| 1868 | + { |
|
| 1869 | + $this->Link_ID->Param(false); |
|
| 1870 | + } |
|
| 1871 | + // reset param-counter |
|
| 1761 | 1872 | $cols = array_keys($data); |
| 1762 | 1873 | foreach($cols as $k => $col) |
| 1763 | 1874 | { |
| 1764 | - if (!isset($table_def['fd'][$col])) // ignore columns not in this table |
|
| 1875 | + if (!isset($table_def['fd'][$col])) |
|
| 1876 | + { |
|
| 1877 | + // ignore columns not in this table |
|
| 1765 | 1878 | { |
| 1766 | 1879 | unset($cols[$k]); |
| 1880 | + } |
|
| 1767 | 1881 | continue; |
| 1768 | 1882 | } |
| 1769 | 1883 | $params[] = $this->Link_ID->Param($col); |
@@ -1781,7 +1895,10 @@ discard block |
||
| 1781 | 1895 | { |
| 1782 | 1896 | $sql = "$cmd INTO $table ".$this->column_data_implode(',',$data,'VALUES',true,$table_def['fd']).$sql_append; |
| 1783 | 1897 | } |
| 1784 | - if ($this->Debug) echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app') sql='$sql'</p>\n"; |
|
| 1898 | + if ($this->Debug) |
|
| 1899 | + { |
|
| 1900 | + echo "<p>db::insert('$table',".print_r($data,True).",".print_r($where,True).",$line,$file,'$app') sql='$sql'</p>\n"; |
|
| 1901 | + } |
|
| 1785 | 1902 | return $this->query($sql,$line,$file,0,-1,$inputarr); |
| 1786 | 1903 | } |
| 1787 | 1904 | |
@@ -1802,8 +1919,14 @@ discard block |
||
| 1802 | 1919 | */ |
| 1803 | 1920 | function update($table,$data,$where,$line,$file,$app=False,$use_prepared_statement=false,$table_def=False) |
| 1804 | 1921 | { |
| 1805 | - if ($this->Debug) echo "<p>db::update('$table',".print_r($data,true).','.print_r($where,true).",$line,$file,'$app')</p>\n"; |
|
| 1806 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
| 1922 | + if ($this->Debug) |
|
| 1923 | + { |
|
| 1924 | + echo "<p>db::update('$table',".print_r($data,true).','.print_r($where,true).",$line,$file,'$app')</p>\n"; |
|
| 1925 | + } |
|
| 1926 | + if (!$table_def) |
|
| 1927 | + { |
|
| 1928 | + $table_def = $this->get_table_definitions($app,$table); |
|
| 1929 | + } |
|
| 1807 | 1930 | |
| 1808 | 1931 | $blobs2update = array(); |
| 1809 | 1932 | // SapDB/MaxDB cant update LONG columns / blob's: if a blob-column is included in the update we remember it in $blobs2update |
@@ -1812,7 +1935,10 @@ discard block |
||
| 1812 | 1935 | { |
| 1813 | 1936 | case 'sapdb': |
| 1814 | 1937 | case 'maxdb': |
| 1815 | - if ($use_prepared_statement) break; |
|
| 1938 | + if ($use_prepared_statement) |
|
| 1939 | + { |
|
| 1940 | + break; |
|
| 1941 | + } |
|
| 1816 | 1942 | // check if data contains any LONG columns |
| 1817 | 1943 | foreach($data as $col => $val) |
| 1818 | 1944 | { |
@@ -1837,12 +1963,20 @@ discard block |
||
| 1837 | 1963 | if (count($data)) |
| 1838 | 1964 | { |
| 1839 | 1965 | $inputarr = false; |
| 1840 | - if ($use_prepared_statement && $this->Link_ID->_bindInputArray) // eg. MaxDB |
|
| 1966 | + if ($use_prepared_statement && $this->Link_ID->_bindInputArray) |
|
| 1967 | + { |
|
| 1968 | + // eg. MaxDB |
|
| 1841 | 1969 | { |
| 1842 | - $this->Link_ID->Param(false); // reset param-counter |
|
| 1970 | + $this->Link_ID->Param(false); |
|
| 1971 | + } |
|
| 1972 | + // reset param-counter |
|
| 1843 | 1973 | foreach($data as $col => $val) |
| 1844 | 1974 | { |
| 1845 | - if (!isset($table_def['fd'][$col])) continue; // ignore columns not in this table |
|
| 1975 | + if (!isset($table_def['fd'][$col])) |
|
| 1976 | + { |
|
| 1977 | + continue; |
|
| 1978 | + } |
|
| 1979 | + // ignore columns not in this table |
|
| 1846 | 1980 | $params[] = $this->name_quote($col).'='.$this->Link_ID->Param($col); |
| 1847 | 1981 | } |
| 1848 | 1982 | $sql = "UPDATE $table SET ".implode(',',$params).' WHERE '.$where_str; |
@@ -1860,7 +1994,10 @@ discard block |
||
| 1860 | 1994 | $this->column_data_implode(',',$data,True,true,$table_def['fd']).' WHERE '.$where_str; |
| 1861 | 1995 | } |
| 1862 | 1996 | $ret = $this->query($sql,$line,$file,0,-1,$inputarr); |
| 1863 | - if ($this->Debug) echo "<p>db::query('$sql',$line,$file)</p>\n"; |
|
| 1997 | + if ($this->Debug) |
|
| 1998 | + { |
|
| 1999 | + echo "<p>db::query('$sql',$line,$file)</p>\n"; |
|
| 2000 | + } |
|
| 1864 | 2001 | } |
| 1865 | 2002 | // if we have any blobs to update, we do so now |
| 1866 | 2003 | if (($ret || !count($data)) && count($blobs2update)) |
@@ -1868,8 +2005,14 @@ discard block |
||
| 1868 | 2005 | foreach($blobs2update as $col => $val) |
| 1869 | 2006 | { |
| 1870 | 2007 | $ret = $this->Link_ID->UpdateBlob($table,$col,$val,$where_str,$table_def['fd'][$col]['type'] == 'blob' ? 'BLOB' : 'CLOB'); |
| 1871 | - if ($this->Debug) echo "<p>adodb::UpdateBlob('$table','$col','$val','$where_str') = '$ret'</p>\n"; |
|
| 1872 | - if (!$ret) throw new Db\Exception\InvalidSql("Error in UpdateBlob($table,$col,\$val,$where_str)",$line,$file); |
|
| 2008 | + if ($this->Debug) |
|
| 2009 | + { |
|
| 2010 | + echo "<p>adodb::UpdateBlob('$table','$col','$val','$where_str') = '$ret'</p>\n"; |
|
| 2011 | + } |
|
| 2012 | + if (!$ret) |
|
| 2013 | + { |
|
| 2014 | + throw new Db\Exception\InvalidSql("Error in UpdateBlob($table,$col,\$val,$where_str)",$line,$file); |
|
| 2015 | + } |
|
| 1873 | 2016 | } |
| 1874 | 2017 | } |
| 1875 | 2018 | return $ret; |
@@ -1890,7 +2033,10 @@ discard block |
||
| 1890 | 2033 | */ |
| 1891 | 2034 | function delete($table,$where,$line,$file,$app=False,$table_def=False) |
| 1892 | 2035 | { |
| 1893 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
| 2036 | + if (!$table_def) |
|
| 2037 | + { |
|
| 2038 | + $table_def = $this->get_table_definitions($app,$table); |
|
| 2039 | + } |
|
| 1894 | 2040 | |
| 1895 | 2041 | if (self::$tablealiases && isset(self::$tablealiases[$table])) |
| 1896 | 2042 | { |
@@ -1922,19 +2068,29 @@ discard block |
||
| 1922 | 2068 | */ |
| 1923 | 2069 | function expression($table_def/*,$args, ...*/) |
| 1924 | 2070 | { |
| 1925 | - if (!is_array($table_def)) $table_def = $this->get_table_definitions(true,$table_def); |
|
| 2071 | + if (!is_array($table_def)) |
|
| 2072 | + { |
|
| 2073 | + $table_def = $this->get_table_definitions(true,$table_def); |
|
| 2074 | + } |
|
| 1926 | 2075 | $sql = ''; |
| 1927 | 2076 | $ignore_next = 0; |
| 1928 | 2077 | foreach(func_get_args() as $n => $arg) |
| 1929 | 2078 | { |
| 1930 | - if ($n < 1) continue; // table-name |
|
| 2079 | + if ($n < 1) |
|
| 2080 | + { |
|
| 2081 | + continue; |
|
| 2082 | + } |
|
| 2083 | + // table-name |
|
| 1931 | 2084 | |
| 1932 | 2085 | if ($ignore_next) |
| 1933 | 2086 | { |
| 1934 | 2087 | --$ignore_next; |
| 1935 | 2088 | continue; |
| 1936 | 2089 | } |
| 1937 | - if (is_null($arg)) $arg = False; |
|
| 2090 | + if (is_null($arg)) |
|
| 2091 | + { |
|
| 2092 | + $arg = False; |
|
| 2093 | + } |
|
| 1938 | 2094 | |
| 1939 | 2095 | switch(gettype($arg)) |
| 1940 | 2096 | { |
@@ -1974,9 +2130,15 @@ discard block |
||
| 1974 | 2130 | */ |
| 1975 | 2131 | function select($table,$cols,$where,$line,$file,$offset=False,$append='',$app=False,$num_rows=0,$join='',$table_def=False,$fetchmode=self::FETCH_ASSOC) |
| 1976 | 2132 | { |
| 1977 | - if ($this->Debug) echo "<p>db::select('$table',".print_r($cols,True).",".print_r($where,True).",$line,$file,$offset,'$app',$num_rows,'$join')</p>\n"; |
|
| 2133 | + if ($this->Debug) |
|
| 2134 | + { |
|
| 2135 | + echo "<p>db::select('$table',".print_r($cols,True).",".print_r($where,True).",$line,$file,$offset,'$app',$num_rows,'$join')</p>\n"; |
|
| 2136 | + } |
|
| 1978 | 2137 | |
| 1979 | - if (!$table_def) $table_def = $this->get_table_definitions($app,$table); |
|
| 2138 | + if (!$table_def) |
|
| 2139 | + { |
|
| 2140 | + $table_def = $this->get_table_definitions($app,$table); |
|
| 2141 | + } |
|
| 1980 | 2142 | if (is_array($cols)) |
| 1981 | 2143 | { |
| 1982 | 2144 | $cols = implode(',',$cols); |
@@ -1992,16 +2154,28 @@ discard block |
||
| 1992 | 2154 | $sql = "SELECT $cols FROM $table $join"; |
| 1993 | 2155 | |
| 1994 | 2156 | // if we have a where clause, we need to add it together with the WHERE statement, if thats not in the join |
| 1995 | - if ($where) $sql .= (strpos($join,"WHERE")!==false) ? ' AND ('.$where.')' : ' WHERE '.$where; |
|
| 2157 | + if ($where) |
|
| 2158 | + { |
|
| 2159 | + $sql .= (strpos($join,"WHERE")!==false) ? ' AND ('.$where.')' : ' WHERE '.$where; |
|
| 2160 | + } |
|
| 1996 | 2161 | |
| 1997 | - if ($append) $sql .= ' '.$append; |
|
| 2162 | + if ($append) |
|
| 2163 | + { |
|
| 2164 | + $sql .= ' '.$append; |
|
| 2165 | + } |
|
| 1998 | 2166 | |
| 1999 | - if ($this->Debug) echo "<p>sql='$sql'</p>"; |
|
| 2167 | + if ($this->Debug) |
|
| 2168 | + { |
|
| 2169 | + echo "<p>sql='$sql'</p>"; |
|
| 2170 | + } |
|
| 2000 | 2171 | |
| 2001 | - if ($line === false && $file === false) // call by union, to return the sql rather then run the query |
|
| 2172 | + if ($line === false && $file === false) |
|
| 2173 | + { |
|
| 2174 | + // call by union, to return the sql rather then run the query |
|
| 2002 | 2175 | { |
| 2003 | 2176 | return $sql; |
| 2004 | 2177 | } |
| 2178 | + } |
|
| 2005 | 2179 | return $this->query($sql,$line,$file,$offset,$offset===False ? -1 : (int)$num_rows,false,$fetchmode); |
| 2006 | 2180 | } |
| 2007 | 2181 | |
@@ -2022,7 +2196,10 @@ discard block |
||
| 2022 | 2196 | */ |
| 2023 | 2197 | function union($selects,$line,$file,$order_by='',$offset=false,$num_rows=0,$fetchmode=self::FETCH_ASSOC) |
| 2024 | 2198 | { |
| 2025 | - if ($this->Debug) echo "<p>db::union(".print_r($selects,True).",$line,$file,$order_by,$offset,$num_rows)</p>\n"; |
|
| 2199 | + if ($this->Debug) |
|
| 2200 | + { |
|
| 2201 | + echo "<p>db::union(".print_r($selects,True).",$line,$file,$order_by,$offset,$num_rows)</p>\n"; |
|
| 2202 | + } |
|
| 2026 | 2203 | |
| 2027 | 2204 | $union = array(); |
| 2028 | 2205 | foreach($selects as $select) |
@@ -2043,9 +2220,15 @@ discard block |
||
| 2043 | 2220 | } |
| 2044 | 2221 | $sql = count($union) > 1 ? '(' . implode(")\nUNION\n(",$union).')' : 'SELECT DISTINCT'.substr($union[0],6); |
| 2045 | 2222 | |
| 2046 | - if ($order_by) $sql .= (!stristr($order_by,'ORDER BY') ? "\nORDER BY " : '').$order_by; |
|
| 2223 | + if ($order_by) |
|
| 2224 | + { |
|
| 2225 | + $sql .= (!stristr($order_by,'ORDER BY') ? "\nORDER BY " : '').$order_by; |
|
| 2226 | + } |
|
| 2047 | 2227 | |
| 2048 | - if ($this->Debug) echo "<p>sql='$sql'</p>"; |
|
| 2228 | + if ($this->Debug) |
|
| 2229 | + { |
|
| 2230 | + echo "<p>sql='$sql'</p>"; |
|
| 2231 | + } |
|
| 2049 | 2232 | |
| 2050 | 2233 | return $this->query($sql,$line,$file,$offset,$offset===False ? -1 : (int)$num_rows,false,$fetchmode); |
| 2051 | 2234 | } |
@@ -114,7 +114,8 @@ discard block |
||
| 114 | 114 | echo "<p>next_run("; print_r($times); echo ",'$debug', " . date('Y-m-d H:i', $now) . ")</p>\n"; |
| 115 | 115 | $debug = True; // enable syntax-error messages too |
| 116 | 116 | } |
| 117 | - if(is_null($now)) { |
|
| 117 | + if(is_null($now)) |
|
| 118 | + { |
|
| 118 | 119 | $now = time(); |
| 119 | 120 | } |
| 120 | 121 | |
@@ -179,12 +180,17 @@ discard block |
||
| 179 | 180 | foreach($units as $u => $date_pattern) |
| 180 | 181 | { |
| 181 | 182 | ++$n; |
| 182 | - if ($this->debug) { echo "<p>n=$n, $u: isset(times[$u]="; print_r($times[$u]); echo ")=".(isset($times[$u])?'True':'False')."</p>\n"; } |
|
| 183 | + if ($this->debug) |
|
| 184 | + { |
|
| 185 | +echo "<p>n=$n, $u: isset(times[$u]="; print_r($times[$u]); echo ")=".(isset($times[$u])?'True':'False')."</p>\n"; } |
|
| 183 | 186 | if (isset($times[$u])) |
| 184 | 187 | { |
| 185 | - if(is_array($times[$u])) { |
|
| 188 | + if(is_array($times[$u])) |
|
| 189 | + { |
|
| 186 | 190 | $time = array_keys($times[$u]); |
| 187 | - } else { |
|
| 191 | + } |
|
| 192 | + else |
|
| 193 | + { |
|
| 188 | 194 | $time = explode(',',$times[$u]); |
| 189 | 195 | } |
| 190 | 196 | $times[$u] = array(); |
@@ -197,7 +203,10 @@ discard block |
||
| 197 | 203 | |
| 198 | 204 | if (count($arr) != 2 || !is_numeric($min) || !is_numeric($max) || $min > $max) |
| 199 | 205 | { |
| 200 | - if ($debug) echo "<p>Syntax error in $u='$t', allowed is 'min-max', min <= max, min='$min', max='$max'</p>\n"; |
|
| 206 | + if ($debug) |
|
| 207 | + { |
|
| 208 | + echo "<p>Syntax error in $u='$t', allowed is 'min-max', min <= max, min='$min', max='$max'</p>\n"; |
|
| 209 | + } |
|
| 201 | 210 | |
| 202 | 211 | return False; |
| 203 | 212 | } |
@@ -208,14 +217,20 @@ discard block |
||
| 208 | 217 | } |
| 209 | 218 | else |
| 210 | 219 | { |
| 211 | - if ((string)$t == '*') $t = '*/1'; |
|
| 220 | + if ((string)$t == '*') |
|
| 221 | + { |
|
| 222 | + $t = '*/1'; |
|
| 223 | + } |
|
| 212 | 224 | |
| 213 | 225 | list($one,$inc) = $arr = explode('/',$t); |
| 214 | 226 | |
| 215 | 227 | if (!(is_numeric($one) && count($arr) == 1 || |
| 216 | 228 | count($arr) == 2 && is_numeric($inc))) |
| 217 | 229 | { |
| 218 | - if ($debug) echo "<p>Syntax error in $u='$t', allowed is a number or '{*|range}/inc', inc='$inc'</p>\n"; |
|
| 230 | + if ($debug) |
|
| 231 | + { |
|
| 232 | + echo "<p>Syntax error in $u='$t', allowed is a number or '{*|range}/inc', inc='$inc'</p>\n"; |
|
| 233 | + } |
|
| 219 | 234 | |
| 220 | 235 | return False; |
| 221 | 236 | } |
@@ -233,7 +248,10 @@ discard block |
||
| 233 | 248 | } |
| 234 | 249 | elseif (count($arr) != 2 || $min > $max) |
| 235 | 250 | { |
| 236 | - if ($debug) echo "<p>Syntax error in $u='$t', allowed is '{*|min-max}/inc', min='$min',max='$max', inc='$inc'</p>\n"; |
|
| 251 | + if ($debug) |
|
| 252 | + { |
|
| 253 | + echo "<p>Syntax error in $u='$t', allowed is '{*|min-max}/inc', min='$min',max='$max', inc='$inc'</p>\n"; |
|
| 254 | + } |
|
| 237 | 255 | return False; |
| 238 | 256 | } |
| 239 | 257 | for ($i = $min; $i <= $max; $i += $inc) |
@@ -244,9 +262,13 @@ discard block |
||
| 244 | 262 | } |
| 245 | 263 | } |
| 246 | 264 | } |
| 247 | - elseif ($n < $last_set || $u == 'dow') // before last value set (or dow) => empty gets enumerated |
|
| 265 | + elseif ($n < $last_set || $u == 'dow') |
|
| 266 | + { |
|
| 267 | + // before last value set (or dow) => empty gets enumerated |
|
| 248 | 268 | { |
| 249 | - for ($i = $min_unit[$u]; $i <= $max_unit[$u]; ++$i) |
|
| 269 | + for ($i = $min_unit[$u]; |
|
| 270 | + } |
|
| 271 | + $i <= $max_unit[$u]; ++$i) |
|
| 250 | 272 | { |
| 251 | 273 | $times[$u][$i] = True; |
| 252 | 274 | } |
@@ -256,7 +278,9 @@ discard block |
||
| 256 | 278 | $times[$u][$min_unit[$u]] = True; |
| 257 | 279 | } |
| 258 | 280 | } |
| 259 | - if ($this->debug) { echo "enumerated times=<pre>"; print_r($times); echo "</pre>\n"; } |
|
| 281 | + if ($this->debug) |
|
| 282 | + { |
|
| 283 | +echo "enumerated times=<pre>"; print_r($times); echo "</pre>\n"; } |
|
| 260 | 284 | |
| 261 | 285 | // now we have the times enumerated, lets find the first not expired one |
| 262 | 286 | // |
@@ -274,7 +298,10 @@ discard block |
||
| 274 | 298 | if (isset($found[$u])) |
| 275 | 299 | { |
| 276 | 300 | $future = $future || $found[$u] > $unit_now; |
| 277 | - if ($this->debug) echo "--> already have a $u = ".$found[$u].", future='$future'<br>\n"; |
|
| 301 | + if ($this->debug) |
|
| 302 | + { |
|
| 303 | + echo "--> already have a $u = ".$found[$u].", future='$future'<br>\n"; |
|
| 304 | + } |
|
| 278 | 305 | continue; // already set |
| 279 | 306 | } |
| 280 | 307 | foreach(array_keys($times[$u]) as $unit_value) |
@@ -292,30 +319,44 @@ discard block |
||
| 292 | 319 | break; |
| 293 | 320 | |
| 294 | 321 | } |
| 295 | - if ($valid && ($u != $next || $unit_value > $over)) // valid and not over |
|
| 322 | + if ($valid && ($u != $next || $unit_value > $over)) |
|
| 323 | + { |
|
| 324 | + // valid and not over |
|
| 296 | 325 | { |
| 297 | 326 | $found[$u] = $unit_value; |
| 327 | + } |
|
| 298 | 328 | $future = $future || $unit_value > $unit_now; |
| 299 | 329 | break; |
| 300 | 330 | } |
| 301 | 331 | } |
| 302 | - if (!isset($found[$u])) // we have to try the next one, if it exists |
|
| 332 | + if (!isset($found[$u])) |
|
| 333 | + { |
|
| 334 | + // we have to try the next one, if it exists |
|
| 303 | 335 | { |
| 304 | 336 | $nexts = array_keys($units); |
| 337 | + } |
|
| 305 | 338 | if (!isset($nexts[count($found)-1])) |
| 306 | 339 | { |
| 307 | - if ($this->debug) echo "<p>Nothing found, exiting !!!</p>\n"; |
|
| 340 | + if ($this->debug) |
|
| 341 | + { |
|
| 342 | + echo "<p>Nothing found, exiting !!!</p>\n"; |
|
| 343 | + } |
|
| 308 | 344 | return False; |
| 309 | 345 | } |
| 310 | 346 | $next = $nexts[count($found)-1]; |
| 311 | 347 | $over = $found[$next]; |
| 312 | 348 | unset($found[$next]); |
| 313 | - if ($this->debug) echo "<p>Have to try the next $next, $u's are over for $next=$over !!!</p>\n"; |
|
| 349 | + if ($this->debug) |
|
| 350 | + { |
|
| 351 | + echo "<p>Have to try the next $next, $u's are over for $next=$over !!!</p>\n"; |
|
| 352 | + } |
|
| 314 | 353 | break; |
| 315 | 354 | } |
| 316 | 355 | } |
| 317 | 356 | } |
| 318 | - if ($this->debug) { echo "<p>next="; print_r($found); echo "</p>\n"; } |
|
| 357 | + if ($this->debug) |
|
| 358 | + { |
|
| 359 | +echo "<p>next="; print_r($found); echo "</p>\n"; } |
|
| 319 | 360 | |
| 320 | 361 | return mktime($found['hour'],$found['min'],0,$found['month'],$found['day'],$found['year']); |
| 321 | 362 | } |
@@ -377,7 +418,10 @@ discard block |
||
| 377 | 418 | ); |
| 378 | 419 | // as the async_next column is used as a semaphore we only update it, |
| 379 | 420 | // if it is 0 (semaphore released) or older then 10min to recover from failed or crashed attempts |
| 380 | - if ($exists) $where = array('async_next=0 OR async_next<'.(time()-600)); |
|
| 421 | + if ($exists) |
|
| 422 | + { |
|
| 423 | + $where = array('async_next=0 OR async_next<'.(time()-600)); |
|
| 424 | + } |
|
| 381 | 425 | } |
| 382 | 426 | //echo "last_run=<pre>"; print_r($last_run); echo "</pre>\n"; |
| 383 | 427 | return $this->write($last_run, !!$exists, $where) > 0; |
@@ -388,7 +432,10 @@ discard block |
||
| 388 | 432 | */ |
| 389 | 433 | function check_run($run_by='') |
| 390 | 434 | { |
| 391 | - if ($run_by === 'fallback') flush(); |
|
| 435 | + if ($run_by === 'fallback') |
|
| 436 | + { |
|
| 437 | + flush(); |
|
| 438 | + } |
|
| 392 | 439 | |
| 393 | 440 | if (!$this->last_check_run(True,False,$run_by)) |
| 394 | 441 | { |
@@ -410,7 +457,10 @@ discard block |
||
| 410 | 457 | // unset all objects in $GLOBALS, which are created and used by ExecMethod, as they can contain user-data |
| 411 | 458 | foreach($GLOBALS as $name => $value) |
| 412 | 459 | { |
| 413 | - if ($name !== 'egw' && is_object($value)) unset($GLOBALS[$name]); |
|
| 460 | + if ($name !== 'egw' && is_object($value)) |
|
| 461 | + { |
|
| 462 | + unset($GLOBALS[$name]); |
|
| 463 | + } |
|
| 414 | 464 | } |
| 415 | 465 | $domain = $GLOBALS['egw_info']['user']['domain']; |
| 416 | 466 | $lang = $GLOBALS['egw_info']['user']['preferences']['common']['lang']; |
@@ -480,7 +530,10 @@ discard block |
||
| 480 | 530 | */ |
| 481 | 531 | function read($id=0,$cols='*',$offset=False,$append='ORDER BY async_next',$num_rows=0) |
| 482 | 532 | { |
| 483 | - if (!is_a($this->db, 'EGroupware\\Api\\Db')) return false; |
|
| 533 | + if (!is_a($this->db, 'EGroupware\\Api\\Db')) |
|
| 534 | + { |
|
| 535 | + return false; |
|
| 536 | + } |
|
| 484 | 537 | |
| 485 | 538 | if ($id === '%') |
| 486 | 539 | { |
@@ -533,9 +586,15 @@ discard block |
||
| 533 | 586 | */ |
| 534 | 587 | function write($job, $exists = False, $where=array()) |
| 535 | 588 | { |
| 536 | - if (!is_a($this->db, 'EGroupware\\Api\\Db')) return 0; |
|
| 589 | + if (!is_a($this->db, 'EGroupware\\Api\\Db')) |
|
| 590 | + { |
|
| 591 | + return 0; |
|
| 592 | + } |
|
| 537 | 593 | |
| 538 | - if (is_array($job['data']) && isset($job['data']['next']) && isset($job['next'])) $job['data']['next'] = $job['next']; |
|
| 594 | + if (is_array($job['data']) && isset($job['data']['next']) && isset($job['next'])) |
|
| 595 | + { |
|
| 596 | + $job['data']['next'] = $job['next']; |
|
| 597 | + } |
|
| 539 | 598 | $data = array( |
| 540 | 599 | 'async_next' => $job['next'], |
| 541 | 600 | 'async_times' => json_encode($job['times']), |
@@ -600,9 +659,12 @@ discard block |
||
| 600 | 659 | { |
| 601 | 660 | echo '<p>'.lang('%1 is not executable by the webserver !!!',$this->$name)."</p>\n"; |
| 602 | 661 | $perms = fileperms($this->$name); |
| 603 | - if (!($perms & 0x0001) && ($perms & 0x0008) && function_exists('posix_getuid')) // only executable by group |
|
| 662 | + if (!($perms & 0x0001) && ($perms & 0x0008) && function_exists('posix_getuid')) |
|
| 663 | + { |
|
| 664 | + // only executable by group |
|
| 604 | 665 | { |
| 605 | 666 | $group = posix_getgrgid(filegroup($this->$name)); |
| 667 | + } |
|
| 606 | 668 | $webserver = posix_getpwuid(posix_getuid ()); |
| 607 | 669 | echo '<p>'.lang("You need to add the webserver user '%1' to the group '%2'.",$webserver['name'],$group['name'])."</p>\n"; } |
| 608 | 670 | } |
@@ -622,10 +684,13 @@ discard block |
||
| 622 | 684 | } |
| 623 | 685 | //echo "<p>$name = '".$this->$name."'</p>\n"; |
| 624 | 686 | } |
| 625 | - if ($this->php5[0] == '/') // we found a php5 binary |
|
| 687 | + if ($this->php5[0] == '/') |
|
| 688 | + { |
|
| 689 | + // we found a php5 binary |
|
| 626 | 690 | { |
| 627 | 691 | $this->php = $this->php5; |
| 628 | 692 | } |
| 693 | + } |
|
| 629 | 694 | } |
| 630 | 695 | } |
| 631 | 696 | |
@@ -637,7 +702,8 @@ discard block |
||
| 637 | 702 | */ |
| 638 | 703 | function installed() |
| 639 | 704 | { |
| 640 | - if ($this->only_fallback) { |
|
| 705 | + if ($this->only_fallback) |
|
| 706 | + { |
|
| 641 | 707 | return 0; |
| 642 | 708 | } |
| 643 | 709 | $this->find_binarys(); |
@@ -654,7 +720,10 @@ discard block |
||
| 654 | 720 | $n = 0; |
| 655 | 721 | while ($line = fgets($crontab,256)) |
| 656 | 722 | { |
| 657 | - if ($this->debug) echo 'line '.++$n.": $line<br>\n"; |
|
| 723 | + if ($this->debug) |
|
| 724 | + { |
|
| 725 | + echo 'line '.++$n.": $line<br>\n"; |
|
| 726 | + } |
|
| 658 | 727 | $parts = explode(' ',$line,6); |
| 659 | 728 | |
| 660 | 729 | if ($line{0} == '#' || count($parts) < 6 || ($parts[5]{0} != '/' && substr($parts[5],0,3) != 'php')) |
@@ -698,7 +767,8 @@ discard block |
||
| 698 | 767 | */ |
| 699 | 768 | function install($times) |
| 700 | 769 | { |
| 701 | - if ($this->only_fallback && $times !== False) { |
|
| 770 | + if ($this->only_fallback && $times !== False) |
|
| 771 | + { |
|
| 702 | 772 | return 0; |
| 703 | 773 | } |
| 704 | 774 | $this->installed(); // find other installed cronlines |
@@ -302,7 +302,10 @@ |
||
| 302 | 302 | } |
| 303 | 303 | if ($owner) |
| 304 | 304 | { |
| 305 | - if ($app) $where = array($where); |
|
| 305 | + if ($app) |
|
| 306 | + { |
|
| 307 | + $where = array($where); |
|
| 308 | + } |
|
| 306 | 309 | $where['link_owner'] = $owner; |
| 307 | 310 | } |
| 308 | 311 | } |