@@ -62,16 +62,16 @@ discard block |
||
62 | 62 | var $template_dirs = array(); |
63 | 63 | |
64 | 64 | /** |
65 | - * true if $this->header() was called |
|
66 | - * |
|
67 | - * @var boolean |
|
68 | - */ |
|
65 | + * true if $this->header() was called |
|
66 | + * |
|
67 | + * @var boolean |
|
68 | + */ |
|
69 | 69 | static $header_done = false; |
70 | 70 | /** |
71 | - * true if $this->navbar() was called |
|
72 | - * |
|
73 | - * @var boolean |
|
74 | - */ |
|
71 | + * true if $this->navbar() was called |
|
72 | + * |
|
73 | + * @var boolean |
|
74 | + */ |
|
75 | 75 | static $navbar_done = false; |
76 | 76 | |
77 | 77 | /** |
@@ -1044,13 +1044,13 @@ discard block |
||
1044 | 1044 | } |
1045 | 1045 | |
1046 | 1046 | /** |
1047 | - * Compile entries for topmenu: |
|
1048 | - * - regular items: links |
|
1049 | - * - info items |
|
1050 | - * |
|
1051 | - * @param array $vars |
|
1052 | - * @param array $apps |
|
1053 | - */ |
|
1047 | + * Compile entries for topmenu: |
|
1048 | + * - regular items: links |
|
1049 | + * - info items |
|
1050 | + * |
|
1051 | + * @param array $vars |
|
1052 | + * @param array $apps |
|
1053 | + */ |
|
1054 | 1054 | function topmenu(array $vars,array $apps) |
1055 | 1055 | { |
1056 | 1056 | if($GLOBALS['egw_info']['user']['apps']['home'] && isset($apps['home'])) |
@@ -1154,39 +1154,39 @@ discard block |
||
1154 | 1154 | } |
1155 | 1155 | |
1156 | 1156 | /** |
1157 | - * Add menu items to the topmenu template class to be displayed |
|
1158 | - * |
|
1159 | - * @param array $app application data |
|
1160 | - * @param mixed $alt_label string with alternative menu item label default value = null |
|
1161 | - * @param string $urlextra string with alternate additional code inside <a>-tag |
|
1162 | - * @access protected |
|
1163 | - * @return void |
|
1164 | - */ |
|
1157 | + * Add menu items to the topmenu template class to be displayed |
|
1158 | + * |
|
1159 | + * @param array $app application data |
|
1160 | + * @param mixed $alt_label string with alternative menu item label default value = null |
|
1161 | + * @param string $urlextra string with alternate additional code inside <a>-tag |
|
1162 | + * @access protected |
|
1163 | + * @return void |
|
1164 | + */ |
|
1165 | 1165 | abstract function _add_topmenu_item(array $app_data,$alt_label=null); |
1166 | 1166 | |
1167 | 1167 | /** |
1168 | - * Add info items to the topmenu template class to be displayed |
|
1169 | - * |
|
1170 | - * @param string $content Html of item |
|
1171 | - * @param string $id =null |
|
1172 | - * @access protected |
|
1173 | - * @return void |
|
1174 | - */ |
|
1168 | + * Add info items to the topmenu template class to be displayed |
|
1169 | + * |
|
1170 | + * @param string $content Html of item |
|
1171 | + * @param string $id =null |
|
1172 | + * @access protected |
|
1173 | + * @return void |
|
1174 | + */ |
|
1175 | 1175 | abstract function _add_topmenu_info_item($content, $id=null); |
1176 | 1176 | |
1177 | 1177 | static $top_menu_extra = array(); |
1178 | 1178 | |
1179 | 1179 | /** |
1180 | - * Called by hooks to add an entry in the topmenu location. |
|
1181 | - * Extra entries will be added just before Logout. |
|
1182 | - * |
|
1183 | - * @param string $id unique element id |
|
1184 | - * @param string $url Address for the entry to link to |
|
1185 | - * @param string $title Text displayed for the entry |
|
1186 | - * @param string $target Optional, so the entry can open in a new page or popup |
|
1187 | - * @access public |
|
1188 | - * @return void |
|
1189 | - */ |
|
1180 | + * Called by hooks to add an entry in the topmenu location. |
|
1181 | + * Extra entries will be added just before Logout. |
|
1182 | + * |
|
1183 | + * @param string $id unique element id |
|
1184 | + * @param string $url Address for the entry to link to |
|
1185 | + * @param string $title Text displayed for the entry |
|
1186 | + * @param string $target Optional, so the entry can open in a new page or popup |
|
1187 | + * @access public |
|
1188 | + * @return void |
|
1189 | + */ |
|
1190 | 1190 | public static function add_topmenu_item($id,$url,$title,$target = '') |
1191 | 1191 | { |
1192 | 1192 | $entry['name'] = $id; |
@@ -1198,16 +1198,16 @@ discard block |
||
1198 | 1198 | } |
1199 | 1199 | |
1200 | 1200 | /** |
1201 | - * called by hooks to add an icon in the topmenu info location |
|
1202 | - * |
|
1203 | - * @param string $id unique element id |
|
1204 | - * @param string $icon_src src of the icon image. Make sure this nog height then 18pixels |
|
1205 | - * @param string $iconlink where the icon links to |
|
1206 | - * @param booleon $blink set true to make the icon blink |
|
1207 | - * @param mixed $tooltip string containing the tooltip html, or null of no tooltip |
|
1208 | - * @access public |
|
1209 | - * @return void |
|
1210 | - */ |
|
1201 | + * called by hooks to add an icon in the topmenu info location |
|
1202 | + * |
|
1203 | + * @param string $id unique element id |
|
1204 | + * @param string $icon_src src of the icon image. Make sure this nog height then 18pixels |
|
1205 | + * @param string $iconlink where the icon links to |
|
1206 | + * @param booleon $blink set true to make the icon blink |
|
1207 | + * @param mixed $tooltip string containing the tooltip html, or null of no tooltip |
|
1208 | + * @access public |
|
1209 | + * @return void |
|
1210 | + */ |
|
1211 | 1211 | abstract function topmenu_info_icon($id,$icon_src,$iconlink,$blink=false,$tooltip=null); |
1212 | 1212 | |
1213 | 1213 | /** |
@@ -1242,19 +1242,19 @@ discard block |
||
1242 | 1242 | protected static $js_include_mgr; |
1243 | 1243 | |
1244 | 1244 | /** |
1245 | - * Checks to make sure a valid package and file name is provided |
|
1246 | - * |
|
1247 | - * Example call syntax: |
|
1248 | - * a) Api\Framework::includeJS('jscalendar','calendar') |
|
1249 | - * --> /phpgwapi/js/jscalendar/calendar.js |
|
1250 | - * b) Api\Framework::includeJS('/phpgwapi/inc/calendar-setup.js',array('lang'=>'de')) |
|
1251 | - * --> /phpgwapi/inc/calendar-setup.js?lang=de |
|
1252 | - * |
|
1253 | - * @param string $package package or complete path (relative to EGW_SERVER_ROOT) to be included |
|
1254 | - * @param string|array $file =null file to be included - no ".js" on the end or array with get params |
|
1255 | - * @param string $app ='phpgwapi' application directory to search - default = phpgwapi |
|
1256 | - * @param boolean $append =true should the file be added |
|
1257 | - */ |
|
1245 | + * Checks to make sure a valid package and file name is provided |
|
1246 | + * |
|
1247 | + * Example call syntax: |
|
1248 | + * a) Api\Framework::includeJS('jscalendar','calendar') |
|
1249 | + * --> /phpgwapi/js/jscalendar/calendar.js |
|
1250 | + * b) Api\Framework::includeJS('/phpgwapi/inc/calendar-setup.js',array('lang'=>'de')) |
|
1251 | + * --> /phpgwapi/inc/calendar-setup.js?lang=de |
|
1252 | + * |
|
1253 | + * @param string $package package or complete path (relative to EGW_SERVER_ROOT) to be included |
|
1254 | + * @param string|array $file =null file to be included - no ".js" on the end or array with get params |
|
1255 | + * @param string $app ='phpgwapi' application directory to search - default = phpgwapi |
|
1256 | + * @param boolean $append =true should the file be added |
|
1257 | + */ |
|
1258 | 1258 | static function includeJS($package, $file=null, $app='phpgwapi') |
1259 | 1259 | { |
1260 | 1260 | self::$js_include_mgr->include_js_file($package, $file, $app); |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | */ |
355 | 355 | public function _get_footer() |
356 | 356 | { |
357 | - $var = Array( |
|
357 | + $var = array( |
|
358 | 358 | 'img_root' => $GLOBALS['egw_info']['server']['webserver_url'] . $this->template_dir.'/images', |
359 | 359 | 'version' => $GLOBALS['egw_info']['server']['versions']['phpgwapi'] |
360 | 360 | ); |
@@ -763,7 +763,7 @@ discard block |
||
763 | 763 | |
764 | 764 | $icon = isset($data['icon']) ? $data['icon'] : 'navbar'; |
765 | 765 | $icon_app = isset($data['icon_app']) ? $data['icon_app'] : $app; |
766 | - $apps[$app]['icon'] = $apps[$app]['icon_hover'] = Image::find($icon_app,Array($icon,'nonav'),'',$svg); |
|
766 | + $apps[$app]['icon'] = $apps[$app]['icon_hover'] = Image::find($icon_app,array($icon,'nonav'),'',$svg); |
|
767 | 767 | } |
768 | 768 | } |
769 | 769 | |
@@ -796,13 +796,13 @@ discard block |
||
796 | 796 | // We handle this here because its special |
797 | 797 | $apps['about']['title'] = 'EGroupware'; |
798 | 798 | $apps['about']['url'] = self::link('/about.php'); |
799 | - $apps['about']['icon'] = $apps['about']['icon_hover'] = Image::find('api',Array('about','nonav')); |
|
799 | + $apps['about']['icon'] = $apps['about']['icon_hover'] = Image::find('api',array('about','nonav')); |
|
800 | 800 | $apps['about']['name'] = 'about'; |
801 | 801 | |
802 | 802 | $apps['logout']['title'] = lang('Logout'); |
803 | 803 | $apps['logout']['name'] = 'logout'; |
804 | 804 | $apps['logout']['url'] = self::link('/logout.php'); |
805 | - $apps['logout']['icon'] = $apps['logout']['icon_hover'] = Image::find('api',Array('logout','nonav')); |
|
805 | + $apps['logout']['icon'] = $apps['logout']['icon_hover'] = Image::find('api',array('logout','nonav')); |
|
806 | 806 | |
807 | 807 | return $apps; |
808 | 808 | } |
@@ -78,6 +78,7 @@ discard block |
||
78 | 78 | * Constructor |
79 | 79 | * |
80 | 80 | * The constructor instanciates the class in $GLOBALS['egw']->framework, from where it should be used |
81 | + * @param string $template |
|
81 | 82 | */ |
82 | 83 | function __construct($template) |
83 | 84 | { |
@@ -564,7 +565,7 @@ discard block |
||
564 | 565 | /** |
565 | 566 | * Returns Html with user and time |
566 | 567 | * |
567 | - * @return void |
|
568 | + * @return string |
|
568 | 569 | */ |
569 | 570 | protected static function _user_time_info() |
570 | 571 | { |
@@ -993,7 +994,6 @@ discard block |
||
993 | 994 | * |
994 | 995 | * Themes are css file in the template directory |
995 | 996 | * |
996 | - * @param string $themes_dir ='css' |
|
997 | 997 | */ |
998 | 998 | function list_themes() |
999 | 999 | { |
@@ -1184,11 +1184,6 @@ discard block |
||
1184 | 1184 | /** |
1185 | 1185 | * Add menu items to the topmenu template class to be displayed |
1186 | 1186 | * |
1187 | - * @param array $app application data |
|
1188 | - * @param mixed $alt_label string with alternative menu item label default value = null |
|
1189 | - * @param string $urlextra string with alternate additional code inside <a>-tag |
|
1190 | - * @access protected |
|
1191 | - * @return void |
|
1192 | 1187 | */ |
1193 | 1188 | abstract function _add_topmenu_item(array $app_data,$alt_label=null); |
1194 | 1189 | |
@@ -1281,7 +1276,6 @@ discard block |
||
1281 | 1276 | * @param string $package package or complete path (relative to EGW_SERVER_ROOT) to be included |
1282 | 1277 | * @param string|array $file =null file to be included - no ".js" on the end or array with get params |
1283 | 1278 | * @param string $app ='phpgwapi' application directory to search - default = phpgwapi |
1284 | - * @param boolean $append =true should the file be added |
|
1285 | 1279 | */ |
1286 | 1280 | static function includeJS($package, $file=null, $app='phpgwapi') |
1287 | 1281 | { |
@@ -1442,7 +1436,7 @@ discard block |
||
1442 | 1436 | * @param string $action "add" or "delete" |
1443 | 1437 | * @param boolean|int|string $group ID of the group to create the favorite for, or 'all' for all users |
1444 | 1438 | * @param array $filters =array() key => value pairs for the filter |
1445 | - * @return boolean Success |
|
1439 | + * @return boolean|null Success |
|
1446 | 1440 | */ |
1447 | 1441 | public static function ajax_set_favorite($app, $name, $action, $group, $filters = array()) |
1448 | 1442 | { |
@@ -222,7 +222,10 @@ discard block |
||
222 | 222 | } |
223 | 223 | |
224 | 224 | // commit session (if existing), to fix timing problems sometimes preventing session creation ("Your session can not be verified") |
225 | - if (isset($GLOBALS['egw']->session)) $GLOBALS['egw']->session->commit_session(); |
|
225 | + if (isset($GLOBALS['egw']->session)) |
|
226 | + { |
|
227 | + $GLOBALS['egw']->session->commit_session(); |
|
228 | + } |
|
226 | 229 | |
227 | 230 | exit; |
228 | 231 | } |
@@ -252,8 +255,14 @@ discard block |
||
252 | 255 | */ |
253 | 256 | function render($content,$app_header=null,$navbar=null) |
254 | 257 | { |
255 | - if (!is_null($app_header)) $GLOBALS['egw_info']['flags']['app_header'] = $app_header; |
|
256 | - if (!is_null($navbar)) $GLOBALS['egw_info']['flags']['nonavbar'] = !$navbar; |
|
258 | + if (!is_null($app_header)) |
|
259 | + { |
|
260 | + $GLOBALS['egw_info']['flags']['app_header'] = $app_header; |
|
261 | + } |
|
262 | + if (!is_null($navbar)) |
|
263 | + { |
|
264 | + $GLOBALS['egw_info']['flags']['nonavbar'] = !$navbar; |
|
265 | + } |
|
257 | 266 | |
258 | 267 | echo $this->header(); |
259 | 268 | |
@@ -450,7 +459,10 @@ discard block |
||
450 | 459 | // send appheader to clientside |
451 | 460 | $extra['app-header'] = $app_header; |
452 | 461 | |
453 | - if($GLOBALS['egw_info']['flags']['currentapp'] != 'wiki') $robots ='<meta name="robots" content="none" />'; |
|
462 | + if($GLOBALS['egw_info']['flags']['currentapp'] != 'wiki') |
|
463 | + { |
|
464 | + $robots ='<meta name="robots" content="none" />'; |
|
465 | + } |
|
454 | 466 | |
455 | 467 | if (substr($GLOBALS['egw_info']['server']['favicon_file'],0,4) == 'http') |
456 | 468 | { |
@@ -692,13 +704,19 @@ discard block |
||
692 | 704 | $ind_b = isset($arr[$b['name']]) ? $arr[$b['name']] : null; |
693 | 705 | |
694 | 706 | if ($ind_a == $ind_b) |
695 | - return 0; |
|
707 | + { |
|
708 | + return 0; |
|
709 | + } |
|
696 | 710 | |
697 | 711 | if ($ind_a == null) |
698 | - return -1; |
|
712 | + { |
|
713 | + return -1; |
|
714 | + } |
|
699 | 715 | |
700 | 716 | if ($ind_b == null) |
701 | - return 1; |
|
717 | + { |
|
718 | + return 1; |
|
719 | + } |
|
702 | 720 | |
703 | 721 | return $ind_a > $ind_b ? 1 : -1; |
704 | 722 | } |
@@ -787,9 +805,12 @@ discard block |
||
787 | 805 | $app_title = $GLOBALS['egw_info']['apps'][$app]['title']; |
788 | 806 | } |
789 | 807 | |
790 | - if ($GLOBALS['egw_info']['user']['apps']['preferences']) // Preferences last |
|
808 | + if ($GLOBALS['egw_info']['user']['apps']['preferences']) |
|
809 | + { |
|
810 | + // Preferences last |
|
791 | 811 | { |
792 | 812 | $prefs = $apps['preferences']; |
813 | + } |
|
793 | 814 | unset($apps['preferences']); |
794 | 815 | $apps['preferences'] = $prefs; |
795 | 816 | } |
@@ -839,7 +860,10 @@ discard block |
||
839 | 860 | $themes_to_check[] = $this->template_dir.'/css/'.$this->template.'.css'; |
840 | 861 | foreach($themes_to_check as $theme_css) |
841 | 862 | { |
842 | - if (file_exists(EGW_SERVER_ROOT.$theme_css)) break; |
|
863 | + if (file_exists(EGW_SERVER_ROOT.$theme_css)) |
|
864 | + { |
|
865 | + break; |
|
866 | + } |
|
843 | 867 | } |
844 | 868 | $debug_minify = $GLOBALS['egw_info']['server']['debug_minify'] === 'True'; |
845 | 869 | if (!$debug_minify && file_exists(EGW_SERVER_ROOT.($theme_min_css = str_replace('.css', '.min.css', $theme_css)))) |
@@ -929,7 +953,9 @@ discard block |
||
929 | 953 | } |
930 | 954 | |
931 | 955 | $extra['url'] = $GLOBALS['egw_info']['server']['webserver_url']; |
932 | - $extra['include'] = array_map(function($str){return substr($str,1);}, self::get_script_links(true), array(1)); |
|
956 | + $extra['include'] = array_map(function($str) |
|
957 | + { |
|
958 | +return substr($str,1);}, self::get_script_links(true), array(1)); |
|
933 | 959 | $extra['app'] = $GLOBALS['egw_info']['flags']['currentapp']; |
934 | 960 | |
935 | 961 | // Load LABjs ONCE here |
@@ -941,7 +967,10 @@ discard block |
||
941 | 967 | // add values of extra parameter and class var as data attributes to script tag of egw.js |
942 | 968 | foreach($extra+self::$extra as $name => $value) |
943 | 969 | { |
944 | - if (is_array($value)) $value = json_encode($value); |
|
970 | + if (is_array($value)) |
|
971 | + { |
|
972 | + $value = json_encode($value); |
|
973 | + } |
|
945 | 974 | // we need to double encode (Html::htmlspecialchars( , TRUE)), as otherwise we get invalid json, eg. for quotes |
946 | 975 | $java_script .= ' data-'.$name."=\"". Html::htmlspecialchars($value, true)."\""; |
947 | 976 | } |
@@ -991,7 +1020,10 @@ discard block |
||
991 | 1020 | if (preg_match('/'."\.css$".'/i', $file)) |
992 | 1021 | { |
993 | 1022 | list($name) = explode('.',$file); |
994 | - if (!isset($list[$name])) $list[$name] = ucfirst ($name); |
|
1023 | + if (!isset($list[$name])) |
|
1024 | + { |
|
1025 | + $list[$name] = ucfirst ($name); |
|
1026 | + } |
|
995 | 1027 | } |
996 | 1028 | } |
997 | 1029 | closedir($dh); |
@@ -1070,7 +1102,8 @@ discard block |
||
1070 | 1102 | |
1071 | 1103 | Hooks::process('topmenu_info',array(),true); |
1072 | 1104 | // Add extra items added by hooks |
1073 | - foreach(self::$top_menu_extra as $extra_item) { |
|
1105 | + foreach(self::$top_menu_extra as $extra_item) |
|
1106 | + { |
|
1074 | 1107 | $this->_add_topmenu_item($extra_item); |
1075 | 1108 | } |
1076 | 1109 | |
@@ -1095,7 +1128,10 @@ discard block |
||
1095 | 1128 | protected function add_preferences_topmenu($type='prefs') |
1096 | 1129 | { |
1097 | 1130 | static $memberships=null; |
1098 | - if (!isset($memberships)) $memberships = $GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'], true); |
|
1131 | + if (!isset($memberships)) |
|
1132 | + { |
|
1133 | + $memberships = $GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'], true); |
|
1134 | + } |
|
1099 | 1135 | static $types = array( |
1100 | 1136 | 'prefs' => array( |
1101 | 1137 | 'title' => 'Preferences', |
@@ -1123,7 +1159,10 @@ discard block |
||
1123 | 1159 | // as all apps answer, we need to remove none-true responses |
1124 | 1160 | foreach($apps as $app => $val) |
1125 | 1161 | { |
1126 | - if (!$val) unset($apps[$app]); |
|
1162 | + if (!$val) |
|
1163 | + { |
|
1164 | + unset($apps[$app]); |
|
1165 | + } |
|
1127 | 1166 | } |
1128 | 1167 | } |
1129 | 1168 | else |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | $GLOBALS['egw_info']['server']['template_set'] = 'jdots'; |
117 | 117 | } |
118 | 118 | // eg. "default" is only used for login at the moment |
119 | - if (!class_exists($class=$GLOBALS['egw_info']['server']['template_set'].'_framework')) |
|
119 | + if (!class_exists($class = $GLOBALS['egw_info']['server']['template_set'].'_framework')) |
|
120 | 120 | { |
121 | 121 | $class = __CLASS__.'\\Minimal'; |
122 | 122 | } |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | Header\ContentSecurityPolicy::send(); |
135 | 135 | |
136 | 136 | // allow client-side to detect first load aka just logged in |
137 | - $reload_count =& Cache::getSession(__CLASS__, 'framework-reload'); |
|
137 | + $reload_count = & Cache::getSession(__CLASS__, 'framework-reload'); |
|
138 | 138 | self::$extra['framework-reload'] = (int)(bool)$reload_count++; |
139 | 139 | } |
140 | 140 | |
@@ -164,9 +164,9 @@ discard block |
||
164 | 164 | * @param string $link_app =null if appname or true, some templates generate a special link-handler url |
165 | 165 | * @return string The full url after processing |
166 | 166 | */ |
167 | - static function link($url, $extravars = '', $link_app=null) |
|
167 | + static function link($url, $extravars = '', $link_app = null) |
|
168 | 168 | { |
169 | - unset($link_app); // not used by required by function signature |
|
169 | + unset($link_app); // not used by required by function signature |
|
170 | 170 | return $GLOBALS['egw']->session->link($url, $extravars); |
171 | 171 | } |
172 | 172 | |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * @param string $url url to redirect to |
179 | 179 | * @param string $link_app =null appname to redirect for, default currentapp |
180 | 180 | */ |
181 | - static function redirect($url, $link_app=null) |
|
181 | + static function redirect($url, $link_app = null) |
|
182 | 182 | { |
183 | 183 | // Determines whether the current output buffer should be flushed |
184 | 184 | $do_flush = true; |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | else |
201 | 201 | { |
202 | 202 | $file = $line = null; |
203 | - if (headers_sent($file,$line)) |
|
203 | + if (headers_sent($file, $line)) |
|
204 | 204 | { |
205 | 205 | throw new Exception\AssertionFailed(__METHOD__."('".htmlspecialchars($url)."') can NOT redirect, output already started at $file line $line!"); |
206 | 206 | } |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | * @param string $link_app =null if appname or true, some templates generate a special link-handler url |
236 | 236 | * @return string The full url after processing |
237 | 237 | */ |
238 | - static function redirect_link($url, $extravars='', $link_app=null) |
|
238 | + static function redirect_link($url, $extravars = '', $link_app = null) |
|
239 | 239 | { |
240 | 240 | self::redirect(self::link($url, $extravars), $link_app); |
241 | 241 | } |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | * @param string $navbar =null show the navigation, default !$GLOBALS['egw_info']['flags']['nonavbar'], false gives a typical popu |
251 | 251 | * |
252 | 252 | */ |
253 | - function render($content,$app_header=null,$navbar=null) |
|
253 | + function render($content, $app_header = null, $navbar = null) |
|
254 | 254 | { |
255 | 255 | if (!is_null($app_header)) $GLOBALS['egw_info']['flags']['app_header'] = $app_header; |
256 | 256 | if (!is_null($navbar)) $GLOBALS['egw_info']['flags']['nonavbar'] = !$navbar; |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | * |
272 | 272 | * @return string with Html |
273 | 273 | */ |
274 | - abstract function header(array $extra=array()); |
|
274 | + abstract function header(array $extra = array()); |
|
275 | 275 | |
276 | 276 | /** |
277 | 277 | * Returns the Html from the body-tag til the main application area (incl. opening div tag) |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | * @return boolean $consider_navbar_not_yet_called_as_true=true |
292 | 292 | * @return boolean |
293 | 293 | */ |
294 | - abstract function isTop($consider_navbar_not_yet_called_as_true=true); |
|
294 | + abstract function isTop($consider_navbar_not_yet_called_as_true = true); |
|
295 | 295 | |
296 | 296 | /** |
297 | 297 | * Returns the content of one sidebox |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | * @param array $file |
302 | 302 | * @param string $type =null 'admin', 'preferences', 'favorites', ... |
303 | 303 | */ |
304 | - abstract function sidebox($appname,$menu_title,$file,$type=null); |
|
304 | + abstract function sidebox($appname, $menu_title, $file, $type = null); |
|
305 | 305 | |
306 | 306 | /** |
307 | 307 | * Returns the Html from the closing div of the main application area to the closing html-tag |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | * @param string $extra_vars for login url |
317 | 317 | * @param string $change_passwd =null string with message to render input fields for password change |
318 | 318 | */ |
319 | - function login_screen($extra_vars, $change_passwd=null) |
|
319 | + function login_screen($extra_vars, $change_passwd = null) |
|
320 | 320 | { |
321 | 321 | (new Framework\Login($this))->screen($extra_vars, $change_passwd); |
322 | 322 | } |
@@ -354,11 +354,11 @@ discard block |
||
354 | 354 | public function _get_footer() |
355 | 355 | { |
356 | 356 | $var = Array( |
357 | - 'img_root' => $GLOBALS['egw_info']['server']['webserver_url'] . $this->template_dir.'/images', |
|
357 | + 'img_root' => $GLOBALS['egw_info']['server']['webserver_url'].$this->template_dir.'/images', |
|
358 | 358 | 'version' => $GLOBALS['egw_info']['server']['versions']['phpgwapi'] |
359 | 359 | ); |
360 | 360 | $var['page_generation_time'] = ''; |
361 | - if($GLOBALS['egw_info']['user']['preferences']['common']['show_generation_time']) |
|
361 | + if ($GLOBALS['egw_info']['user']['preferences']['common']['show_generation_time']) |
|
362 | 362 | { |
363 | 363 | $times = self::get_page_generation_time(); |
364 | 364 | |
@@ -398,16 +398,16 @@ discard block |
||
398 | 398 | static public function _get_body_attribs() |
399 | 399 | { |
400 | 400 | $js = ''; |
401 | - foreach(self::$body_tags as $what => $data) |
|
401 | + foreach (self::$body_tags as $what => $data) |
|
402 | 402 | { |
403 | 403 | if (!empty($data)) |
404 | 404 | { |
405 | - if($what == 'onLoad') |
|
405 | + if ($what == 'onLoad') |
|
406 | 406 | { |
407 | - $js .= 'onLoad="egw_LAB.wait(function() {'. htmlspecialchars($data).'})"'; |
|
407 | + $js .= 'onLoad="egw_LAB.wait(function() {'.htmlspecialchars($data).'})"'; |
|
408 | 408 | continue; |
409 | 409 | } |
410 | - $js .= ' '.$what.'="' . htmlspecialchars($data) . '"'; |
|
410 | + $js .= ' '.$what.'="'.htmlspecialchars($data).'"'; |
|
411 | 411 | } |
412 | 412 | } |
413 | 413 | return $js; |
@@ -419,7 +419,7 @@ discard block |
||
419 | 419 | * @param array $extra =array() extra attributes passed as data-attribute to egw.js |
420 | 420 | * @return array |
421 | 421 | */ |
422 | - protected function _get_header(array $extra=array()) |
|
422 | + protected function _get_header(array $extra = array()) |
|
423 | 423 | { |
424 | 424 | // display password expires in N days message once per session |
425 | 425 | $message = null; |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | } |
431 | 431 | |
432 | 432 | // get used language code (with a little xss check, if someone tries to sneak something in) |
433 | - if (preg_match('/^[a-z]{2}(-[a-z]{2})?$/',$GLOBALS['egw_info']['user']['preferences']['common']['lang'])) |
|
433 | + if (preg_match('/^[a-z]{2}(-[a-z]{2})?$/', $GLOBALS['egw_info']['user']['preferences']['common']['lang'])) |
|
434 | 434 | { |
435 | 435 | $lang_code = $GLOBALS['egw_info']['user']['preferences']['common']['lang']; |
436 | 436 | } |
@@ -450,9 +450,9 @@ discard block |
||
450 | 450 | // send appheader to clientside |
451 | 451 | $extra['app-header'] = $app_header; |
452 | 452 | |
453 | - if($GLOBALS['egw_info']['flags']['currentapp'] != 'wiki') $robots ='<meta name="robots" content="none" />'; |
|
453 | + if ($GLOBALS['egw_info']['flags']['currentapp'] != 'wiki') $robots = '<meta name="robots" content="none" />'; |
|
454 | 454 | |
455 | - if (substr($GLOBALS['egw_info']['server']['favicon_file'],0,4) == 'http') |
|
455 | + if (substr($GLOBALS['egw_info']['server']['favicon_file'], 0, 4) == 'http') |
|
456 | 456 | { |
457 | 457 | $var['favicon_file'] = $GLOBALS['egw_info']['server']['favicon_file']; |
458 | 458 | } |
@@ -468,7 +468,7 @@ discard block |
||
468 | 468 | $include_wz_tooltip = '<script src="'.$GLOBALS['egw_info']['server']['webserver_url']. |
469 | 469 | $wz_tooltip.'?'.filemtime(EGW_SERVER_ROOT.$wz_tooltip).'" type="text/javascript"></script>'; |
470 | 470 | } |
471 | - return $this->_get_css()+array( |
|
471 | + return $this->_get_css() + array( |
|
472 | 472 | 'img_icon' => $var['favicon_file'], |
473 | 473 | 'img_shortcut' => $var['favicon_file'], |
474 | 474 | 'pngfix' => $pngfix, |
@@ -492,15 +492,15 @@ discard block |
||
492 | 492 | */ |
493 | 493 | protected function _get_navbar($apps) |
494 | 494 | { |
495 | - $var['img_root'] = $GLOBALS['egw_info']['server']['webserver_url'] . '/phpgwapi/templates/'.$this->template.'/images'; |
|
495 | + $var['img_root'] = $GLOBALS['egw_info']['server']['webserver_url'].'/phpgwapi/templates/'.$this->template.'/images'; |
|
496 | 496 | |
497 | - if(isset($GLOBALS['egw_info']['flags']['app_header'])) |
|
497 | + if (isset($GLOBALS['egw_info']['flags']['app_header'])) |
|
498 | 498 | { |
499 | 499 | $var['current_app_title'] = $GLOBALS['egw_info']['flags']['app_header']; |
500 | 500 | } |
501 | 501 | else |
502 | 502 | { |
503 | - $var['current_app_title']=$apps[$GLOBALS['egw_info']['flags']['currentapp']]['title']; |
|
503 | + $var['current_app_title'] = $apps[$GLOBALS['egw_info']['flags']['currentapp']]['title']; |
|
504 | 504 | } |
505 | 505 | $var['currentapp'] = $GLOBALS['egw_info']['flags']['currentapp']; |
506 | 506 | |
@@ -512,32 +512,32 @@ discard block |
||
512 | 512 | |
513 | 513 | $var['user_info'] = $this->_user_time_info(); |
514 | 514 | |
515 | - if($GLOBALS['egw_info']['user']['account_lastpwd_change'] == 0) |
|
515 | + if ($GLOBALS['egw_info']['user']['account_lastpwd_change'] == 0) |
|
516 | 516 | { |
517 | 517 | $api_messages = lang('You are required to change your password during your first login').'<br />'. |
518 | - lang('Click this image on the navbar: %1','<img src="'.Image::find('preferences','navbar.gif').'">'); |
|
518 | + lang('Click this image on the navbar: %1', '<img src="'.Image::find('preferences', 'navbar.gif').'">'); |
|
519 | 519 | } |
520 | - elseif($GLOBALS['egw_info']['server']['change_pwd_every_x_days'] && $GLOBALS['egw_info']['user']['account_lastpwd_change'] < time() - (86400*$GLOBALS['egw_info']['server']['change_pwd_every_x_days'])) |
|
520 | + elseif ($GLOBALS['egw_info']['server']['change_pwd_every_x_days'] && $GLOBALS['egw_info']['user']['account_lastpwd_change'] < time() - (86400 * $GLOBALS['egw_info']['server']['change_pwd_every_x_days'])) |
|
521 | 521 | { |
522 | - $api_messages = lang('it has been more then %1 days since you changed your password',$GLOBALS['egw_info']['server']['change_pwd_every_x_days']); |
|
522 | + $api_messages = lang('it has been more then %1 days since you changed your password', $GLOBALS['egw_info']['server']['change_pwd_every_x_days']); |
|
523 | 523 | } |
524 | 524 | |
525 | - if (substr($GLOBALS['egw_info']['server']['login_logo_file'],0,4) == 'http' || |
|
525 | + if (substr($GLOBALS['egw_info']['server']['login_logo_file'], 0, 4) == 'http' || |
|
526 | 526 | $GLOBALS['egw_info']['server']['login_logo_file'][0] == '/') |
527 | 527 | { |
528 | 528 | $var['logo_file'] = $GLOBALS['egw_info']['server']['login_logo_file']; |
529 | 529 | } |
530 | 530 | else |
531 | 531 | { |
532 | - $var['logo_file'] = Image::find('phpgwapi',$GLOBALS['egw_info']['server']['login_logo_file']?$GLOBALS['egw_info']['server']['login_logo_file']:'logo', '', null); // null=explicit allow svg |
|
532 | + $var['logo_file'] = Image::find('phpgwapi', $GLOBALS['egw_info']['server']['login_logo_file'] ? $GLOBALS['egw_info']['server']['login_logo_file'] : 'logo', '', null); // null=explicit allow svg |
|
533 | 533 | } |
534 | - $var['logo_url'] = $GLOBALS['egw_info']['server']['login_logo_url']?$GLOBALS['egw_info']['server']['login_logo_url']:'http://www.eGroupWare.org'; |
|
534 | + $var['logo_url'] = $GLOBALS['egw_info']['server']['login_logo_url'] ? $GLOBALS['egw_info']['server']['login_logo_url'] : 'http://www.eGroupWare.org'; |
|
535 | 535 | |
536 | - if (substr($var['logo_url'],0,4) != 'http') |
|
536 | + if (substr($var['logo_url'], 0, 4) != 'http') |
|
537 | 537 | { |
538 | 538 | $var['logo_url'] = 'http://'.$var['logo_url']; |
539 | 539 | } |
540 | - $var['logo_title'] = $GLOBALS['egw_info']['server']['login_logo_title']?$GLOBALS['egw_info']['server']['login_logo_title']:'www.eGroupWare.org'; |
|
540 | + $var['logo_title'] = $GLOBALS['egw_info']['server']['login_logo_title'] ? $GLOBALS['egw_info']['server']['login_logo_title'] : 'www.eGroupWare.org'; |
|
541 | 541 | |
542 | 542 | return $var; |
543 | 543 | } |
@@ -550,14 +550,14 @@ discard block |
||
550 | 550 | protected static function _user_time_info() |
551 | 551 | { |
552 | 552 | $now = new DateTime(); |
553 | - $user_info = '<b>'.Accounts::format_username() .'</b>'. ' - ' . lang($now->format('l')) . ' ' . $now->format(true); |
|
553 | + $user_info = '<b>'.Accounts::format_username().'</b>'.' - '.lang($now->format('l')).' '.$now->format(true); |
|
554 | 554 | |
555 | 555 | $user_tzs = DateTime::getUserTimezones(); |
556 | 556 | if (count($user_tzs) > 1) |
557 | 557 | { |
558 | 558 | $tz = $GLOBALS['egw_info']['user']['preferences']['common']['tz']; |
559 | - $user_info .= Html::form(Html::select('tz',$tz,$user_tzs,true),array(), |
|
560 | - '/index.php','','tz_selection',' style="display: inline;"','GET'); |
|
559 | + $user_info .= Html::form(Html::select('tz', $tz, $user_tzs, true), array(), |
|
560 | + '/index.php', '', 'tz_selection', ' style="display: inline;"', 'GET'); |
|
561 | 561 | } |
562 | 562 | return $user_info; |
563 | 563 | } |
@@ -569,10 +569,10 @@ discard block |
||
569 | 569 | */ |
570 | 570 | protected static function _current_users() |
571 | 571 | { |
572 | - if( $GLOBALS['egw_info']['user']['apps']['admin'] && $GLOBALS['egw_info']['user']['preferences']['common']['show_currentusers']) |
|
572 | + if ($GLOBALS['egw_info']['user']['apps']['admin'] && $GLOBALS['egw_info']['user']['preferences']['common']['show_currentusers']) |
|
573 | 573 | { |
574 | - $current_users = '<a href="' . self::link('/index.php','menuaction=admin.admin_accesslog.sessions') . '">' . |
|
575 | - lang('Current users') . ': <span id="currentusers">' . $GLOBALS['egw']->session->session_count() . '</span></a>'; |
|
574 | + $current_users = '<a href="'.self::link('/index.php', 'menuaction=admin.admin_accesslog.sessions').'">'. |
|
575 | + lang('Current users').': <span id="currentusers">'.$GLOBALS['egw']->session->session_count().'</span></a>'; |
|
576 | 576 | return $current_users; |
577 | 577 | } |
578 | 578 | } |
@@ -606,14 +606,14 @@ discard block |
||
606 | 606 | * @param array $opts =array() further params for http(s) context, eg. array('timeout' => 123) |
607 | 607 | * @return resource|null context to use with file_get_context/fopen or null if no proxy configured |
608 | 608 | */ |
609 | - public static function proxy_context($username=null, $password=null, array $opts = array()) |
|
609 | + public static function proxy_context($username = null, $password = null, array $opts = array()) |
|
610 | 610 | { |
611 | 611 | $opts += array( |
612 | 612 | 'method' => 'GET', |
613 | 613 | ); |
614 | 614 | if (!empty($GLOBALS['egw_info']['server']['httpproxy_server'])) |
615 | 615 | { |
616 | - $opts += array ( |
|
616 | + $opts += array( |
|
617 | 617 | 'proxy' => 'tcp://'.$GLOBALS['egw_info']['server']['httpproxy_server'].':'. |
618 | 618 | ($GLOBALS['egw_info']['server']['httpproxy_port'] ? $GLOBALS['egw_info']['server']['httpproxy_port'] : 8080), |
619 | 619 | 'request_fulluri' => true, |
@@ -642,7 +642,7 @@ discard block |
||
642 | 642 | * @param string &$changelog on return path to changelog |
643 | 643 | * @return string |
644 | 644 | */ |
645 | - public static function api_version(&$changelog=null) |
|
645 | + public static function api_version(&$changelog = null) |
|
646 | 646 | { |
647 | 647 | return Framework\Updates::api_version($changelog); |
648 | 648 | } |
@@ -655,7 +655,7 @@ discard block |
||
655 | 655 | */ |
656 | 656 | public static function index($app) |
657 | 657 | { |
658 | - $data =& $GLOBALS['egw_info']['user']['apps'][$app]; |
|
658 | + $data = & $GLOBALS['egw_info']['user']['apps'][$app]; |
|
659 | 659 | if (!isset($data)) |
660 | 660 | { |
661 | 661 | throw new Exception\WrongParameter("'$app' not a valid app for this user!"); |
@@ -672,7 +672,7 @@ discard block |
||
672 | 672 | $index = '/index.php?menuaction='.$data['index']; |
673 | 673 | } |
674 | 674 | } |
675 | - return self::link($index,$GLOBALS['egw_info']['flags']['params'][$app]); |
|
675 | + return self::link($index, $GLOBALS['egw_info']['flags']['params'][$app]); |
|
676 | 676 | } |
677 | 677 | |
678 | 678 | /** |
@@ -713,15 +713,15 @@ discard block |
||
713 | 713 | * true: always return svg, false: never return svg (current default), null: browser dependent, see svg_usable() |
714 | 714 | * @return array |
715 | 715 | */ |
716 | - protected static function _get_navbar_apps($svg=false) |
|
716 | + protected static function _get_navbar_apps($svg = false) |
|
717 | 717 | { |
718 | 718 | list($first) = each($GLOBALS['egw_info']['user']['apps']); |
719 | - if(is_array($GLOBALS['egw_info']['user']['apps']['admin']) && $first != 'admin') |
|
719 | + if (is_array($GLOBALS['egw_info']['user']['apps']['admin']) && $first != 'admin') |
|
720 | 720 | { |
721 | 721 | $newarray['admin'] = $GLOBALS['egw_info']['user']['apps']['admin']; |
722 | - foreach($GLOBALS['egw_info']['user']['apps'] as $index => $value) |
|
722 | + foreach ($GLOBALS['egw_info']['user']['apps'] as $index => $value) |
|
723 | 723 | { |
724 | - if($index != 'admin') |
|
724 | + if ($index != 'admin') |
|
725 | 725 | { |
726 | 726 | $newarray[$index] = $value; |
727 | 727 | } |
@@ -734,7 +734,7 @@ discard block |
||
734 | 734 | unset($newarray); |
735 | 735 | |
736 | 736 | $apps = array(); |
737 | - foreach($GLOBALS['egw_info']['user']['apps'] as $app => $data) |
|
737 | + foreach ($GLOBALS['egw_info']['user']['apps'] as $app => $data) |
|
738 | 738 | { |
739 | 739 | if (is_long($app)) |
740 | 740 | { |
@@ -751,21 +751,21 @@ discard block |
||
751 | 751 | if ($data['status'] == 4) |
752 | 752 | { |
753 | 753 | $apps[$app]['target'] = ' target="'.$app.'" onClick="'."if (this != '') { window.open(this+'". |
754 | - (strpos($apps[$app]['url'],'?') !== false ? '&' : '?'). |
|
754 | + (strpos($apps[$app]['url'], '?') !== false ? '&' : '?'). |
|
755 | 755 | "referer='+encodeURIComponent(location),this.target,'width=800,height=600,scrollbars=yes,resizable=yes'); return false; } else { return true; }".'"'; |
756 | 756 | } |
757 | - elseif(isset($GLOBALS['egw_info']['flags']['navbar_target']) && $GLOBALS['egw_info']['flags']['navbar_target']) |
|
757 | + elseif (isset($GLOBALS['egw_info']['flags']['navbar_target']) && $GLOBALS['egw_info']['flags']['navbar_target']) |
|
758 | 758 | { |
759 | - $apps[$app]['target'] = 'target="' . $GLOBALS['egw_info']['flags']['navbar_target'] . '"'; |
|
759 | + $apps[$app]['target'] = 'target="'.$GLOBALS['egw_info']['flags']['navbar_target'].'"'; |
|
760 | 760 | } |
761 | 761 | else |
762 | 762 | { |
763 | 763 | $apps[$app]['target'] = ''; |
764 | 764 | } |
765 | 765 | |
766 | - $icon = isset($data['icon']) ? $data['icon'] : 'navbar'; |
|
766 | + $icon = isset($data['icon']) ? $data['icon'] : 'navbar'; |
|
767 | 767 | $icon_app = isset($data['icon_app']) ? $data['icon_app'] : $app; |
768 | - $apps[$app]['icon'] = $apps[$app]['icon_hover'] = Image::find($icon_app,Array($icon,'nonav'),'',$svg); |
|
768 | + $apps[$app]['icon'] = $apps[$app]['icon_hover'] = Image::find($icon_app, Array($icon, 'nonav'), '', $svg); |
|
769 | 769 | } |
770 | 770 | } |
771 | 771 | |
@@ -798,13 +798,13 @@ discard block |
||
798 | 798 | // We handle this here because its special |
799 | 799 | $apps['about']['title'] = 'EGroupware'; |
800 | 800 | $apps['about']['url'] = self::link('/about.php'); |
801 | - $apps['about']['icon'] = $apps['about']['icon_hover'] = Image::find('api',Array('about','nonav')); |
|
801 | + $apps['about']['icon'] = $apps['about']['icon_hover'] = Image::find('api', Array('about', 'nonav')); |
|
802 | 802 | $apps['about']['name'] = 'about'; |
803 | 803 | |
804 | 804 | $apps['logout']['title'] = lang('Logout'); |
805 | 805 | $apps['logout']['name'] = 'logout'; |
806 | 806 | $apps['logout']['url'] = self::link('/logout.php'); |
807 | - $apps['logout']['icon'] = $apps['logout']['icon_hover'] = Image::find('api',Array('logout','nonav')); |
|
807 | + $apps['logout']['icon'] = $apps['logout']['icon_hover'] = Image::find('api', Array('logout', 'nonav')); |
|
808 | 808 | |
809 | 809 | return $apps; |
810 | 810 | } |
@@ -838,7 +838,7 @@ discard block |
||
838 | 838 | } |
839 | 839 | $themes_to_check[] = $this->template_dir.'/css/'.$GLOBALS['egw_info']['user']['preferences']['common']['theme'].'.css'; |
840 | 840 | $themes_to_check[] = $this->template_dir.'/css/'.$this->template.'.css'; |
841 | - foreach($themes_to_check as $theme_css) |
|
841 | + foreach ($themes_to_check as $theme_css) |
|
842 | 842 | { |
843 | 843 | if (file_exists(EGW_SERVER_ROOT.$theme_css)) break; |
844 | 844 | } |
@@ -872,7 +872,7 @@ discard block |
||
872 | 872 | |
873 | 873 | // sending print css last, so it can overwrite anything |
874 | 874 | $print_css = $this->template_dir.'/print.css'; |
875 | - if(!file_exists(EGW_SERVER_ROOT.$print_css)) |
|
875 | + if (!file_exists(EGW_SERVER_ROOT.$print_css)) |
|
876 | 876 | { |
877 | 877 | $print_css = '/api/templates/default/print.css'; |
878 | 878 | } |
@@ -898,7 +898,7 @@ discard block |
||
898 | 898 | * @param array $extra =array() extra data to pass to egw.js as data-parameter |
899 | 899 | * @return string the javascript to be included |
900 | 900 | */ |
901 | - public static function _get_js(array $extra=array()) |
|
901 | + public static function _get_js(array $extra = array()) |
|
902 | 902 | { |
903 | 903 | $java_script = ''; |
904 | 904 | |
@@ -906,7 +906,7 @@ discard block |
||
906 | 906 | Think of conf vars etc... ([email protected]) */ |
907 | 907 | if (isset($GLOBALS['egw_info']['flags']['java_script_thirst'])) |
908 | 908 | { |
909 | - $java_script .= $GLOBALS['egw_info']['flags']['java_script_thirst'] . "\n"; |
|
909 | + $java_script .= $GLOBALS['egw_info']['flags']['java_script_thirst']."\n"; |
|
910 | 910 | } |
911 | 911 | // add configuration, link-registry, images, user-data and -perferences for non-popup windows |
912 | 912 | // specifying etag in url to force reload, as we send expires header |
@@ -918,7 +918,7 @@ discard block |
||
918 | 918 | self::includeJS('/api/images.php', array( |
919 | 919 | 'template' => $GLOBALS['egw_info']['server']['template_set'], |
920 | 920 | 'etag' => md5(json_encode(Image::map($GLOBALS['egw_info']['server']['template_set']))), |
921 | - 'svg' => Header\UserAgent::mobile(), // always load non-svg image map, ATM we use svg icons only for mobile theme |
|
921 | + 'svg' => Header\UserAgent::mobile(), // always load non-svg image map, ATM we use svg icons only for mobile theme |
|
922 | 922 | )); |
923 | 923 | self::includeJS('/api/user.php', array( |
924 | 924 | 'user' => $GLOBALS['egw_info']['user']['account_lid'], |
@@ -930,7 +930,7 @@ discard block |
||
930 | 930 | } |
931 | 931 | |
932 | 932 | $extra['url'] = $GLOBALS['egw_info']['server']['webserver_url']; |
933 | - $extra['include'] = array_map(function($str){return substr($str,1);}, self::get_script_links(true), array(1)); |
|
933 | + $extra['include'] = array_map(function($str) {return substr($str, 1); }, self::get_script_links(true), array(1)); |
|
934 | 934 | $extra['app'] = $GLOBALS['egw_info']['flags']['currentapp']; |
935 | 935 | |
936 | 936 | // Load LABjs ONCE here |
@@ -940,18 +940,18 @@ discard block |
||
940 | 940 | '/api/js/jsapi/egw.js?'.filemtime(EGW_SERVER_ROOT.'/api/js/jsapi/egw.js').'" id="egw_script_id"'; |
941 | 941 | |
942 | 942 | // add values of extra parameter and class var as data attributes to script tag of egw.js |
943 | - foreach($extra+self::$extra as $name => $value) |
|
943 | + foreach ($extra + self::$extra as $name => $value) |
|
944 | 944 | { |
945 | 945 | if (is_array($value)) $value = json_encode($value); |
946 | 946 | // we need to double encode (Html::htmlspecialchars( , TRUE)), as otherwise we get invalid json, eg. for quotes |
947 | - $java_script .= ' data-'.$name."=\"". Html::htmlspecialchars($value, true)."\""; |
|
947 | + $java_script .= ' data-'.$name."=\"".Html::htmlspecialchars($value, true)."\""; |
|
948 | 948 | } |
949 | 949 | $java_script .= "></script>\n"; |
950 | 950 | |
951 | - if(@isset($_GET['menuaction'])) |
|
951 | + if (@isset($_GET['menuaction'])) |
|
952 | 952 | { |
953 | - list(, $class) = explode('.',$_GET['menuaction']); |
|
954 | - if(is_array($GLOBALS[$class]->public_functions) && |
|
953 | + list(, $class) = explode('.', $_GET['menuaction']); |
|
954 | + if (is_array($GLOBALS[$class]->public_functions) && |
|
955 | 955 | $GLOBALS[$class]->public_functions['java_script']) |
956 | 956 | { |
957 | 957 | $java_script .= $GLOBALS[$class]->java_script(); |
@@ -960,10 +960,10 @@ discard block |
||
960 | 960 | if (isset($GLOBALS['egw_info']['flags']['java_script'])) |
961 | 961 | { |
962 | 962 | // Strip out any script tags, this needs to be executed as anonymous function |
963 | - $GLOBALS['egw_info']['flags']['java_script'] = preg_replace(array('/(<script[^>]*>)([^<]*)/is','/<\/script>/'),array('$2',''),$GLOBALS['egw_info']['flags']['java_script']); |
|
964 | - if(trim($GLOBALS['egw_info']['flags']['java_script']) != '') |
|
963 | + $GLOBALS['egw_info']['flags']['java_script'] = preg_replace(array('/(<script[^>]*>)([^<]*)/is', '/<\/script>/'), array('$2', ''), $GLOBALS['egw_info']['flags']['java_script']); |
|
964 | + if (trim($GLOBALS['egw_info']['flags']['java_script']) != '') |
|
965 | 965 | { |
966 | - $java_script .= '<script type="text/javascript">window.egw_LAB.wait(function() {'.$GLOBALS['egw_info']['flags']['java_script'] . "});</script>\n"; |
|
966 | + $java_script .= '<script type="text/javascript">window.egw_LAB.wait(function() {'.$GLOBALS['egw_info']['flags']['java_script']."});</script>\n"; |
|
967 | 967 | } |
968 | 968 | } |
969 | 969 | |
@@ -980,7 +980,7 @@ discard block |
||
980 | 980 | function list_themes() |
981 | 981 | { |
982 | 982 | $list = array(); |
983 | - if (file_exists($file=EGW_SERVER_ROOT.$this->template_dir.'/setup/setup.inc.php') && |
|
983 | + if (file_exists($file = EGW_SERVER_ROOT.$this->template_dir.'/setup/setup.inc.php') && |
|
984 | 984 | (include $file) && isset($GLOBALS['egw_info']['template'][$this->template]['themes'])) |
985 | 985 | { |
986 | 986 | $list = $GLOBALS['egw_info']['template'][$this->template]['themes']; |
@@ -991,8 +991,8 @@ discard block |
||
991 | 991 | { |
992 | 992 | if (preg_match('/'."\.css$".'/i', $file)) |
993 | 993 | { |
994 | - list($name) = explode('.',$file); |
|
995 | - if (!isset($list[$name])) $list[$name] = ucfirst ($name); |
|
994 | + list($name) = explode('.', $file); |
|
995 | + if (!isset($list[$name])) $list[$name] = ucfirst($name); |
|
996 | 996 | } |
997 | 997 | } |
998 | 998 | closedir($dh); |
@@ -1006,21 +1006,20 @@ discard block |
||
1006 | 1006 | * @param boolean $full_data =false true: value is array with values for keys 'name', 'title', ... |
1007 | 1007 | * @returns array alphabetically sorted list of templates |
1008 | 1008 | */ |
1009 | - static function list_templates($full_data=false) |
|
1009 | + static function list_templates($full_data = false) |
|
1010 | 1010 | { |
1011 | 1011 | $list = array('pixelegg'=>null); |
1012 | 1012 | // templates packaged like apps in own directories (containing as setup/setup.inc.php file!) |
1013 | 1013 | $dr = dir(EGW_SERVER_ROOT); |
1014 | - while (($entry=$dr->read())) |
|
1014 | + while (($entry = $dr->read())) |
|
1015 | 1015 | { |
1016 | 1016 | if ($entry != '..' && !isset($GLOBALS['egw_info']['apps'][$entry]) && is_dir(EGW_SERVER_ROOT.'/'.$entry) && |
1017 | - file_exists($f = EGW_SERVER_ROOT . '/' . $entry .'/setup/setup.inc.php')) |
|
1017 | + file_exists($f = EGW_SERVER_ROOT.'/'.$entry.'/setup/setup.inc.php')) |
|
1018 | 1018 | { |
1019 | 1019 | include($f); |
1020 | 1020 | if (isset($GLOBALS['egw_info']['template'][$entry])) |
1021 | 1021 | { |
1022 | - $list[$entry] = $full_data ? $GLOBALS['egw_info']['template'][$entry] : |
|
1023 | - $GLOBALS['egw_info']['template'][$entry]['title']; |
|
1022 | + $list[$entry] = $full_data ? $GLOBALS['egw_info']['template'][$entry] : $GLOBALS['egw_info']['template'][$entry]['title']; |
|
1024 | 1023 | } |
1025 | 1024 | } |
1026 | 1025 | } |
@@ -1037,14 +1036,14 @@ discard block |
||
1037 | 1036 | * @param array $vars |
1038 | 1037 | * @param array $apps |
1039 | 1038 | */ |
1040 | - function topmenu(array $vars,array $apps) |
|
1039 | + function topmenu(array $vars, array $apps) |
|
1041 | 1040 | { |
1042 | - if($GLOBALS['egw_info']['user']['apps']['home'] && isset($apps['home'])) |
|
1041 | + if ($GLOBALS['egw_info']['user']['apps']['home'] && isset($apps['home'])) |
|
1043 | 1042 | { |
1044 | 1043 | $this->_add_topmenu_item($apps['home']); |
1045 | 1044 | } |
1046 | 1045 | |
1047 | - if($GLOBALS['egw_info']['user']['apps']['preferences']) |
|
1046 | + if ($GLOBALS['egw_info']['user']['apps']['preferences']) |
|
1048 | 1047 | { |
1049 | 1048 | $this->add_preferences_topmenu('prefs'); |
1050 | 1049 | $this->add_preferences_topmenu('acl'); |
@@ -1069,9 +1068,9 @@ discard block |
||
1069 | 1068 | $this->_add_topmenu_item(array_merge($apps['manual'],array('title' => lang('Help')))); |
1070 | 1069 | }*/ |
1071 | 1070 | |
1072 | - Hooks::process('topmenu_info',array(),true); |
|
1071 | + Hooks::process('topmenu_info', array(), true); |
|
1073 | 1072 | // Add extra items added by hooks |
1074 | - foreach(self::$top_menu_extra as $extra_item) { |
|
1073 | + foreach (self::$top_menu_extra as $extra_item) { |
|
1075 | 1074 | $this->_add_topmenu_item($extra_item); |
1076 | 1075 | } |
1077 | 1076 | |
@@ -1081,7 +1080,7 @@ discard block |
||
1081 | 1080 | { |
1082 | 1081 | $this->_add_topmenu_info_item($update, 'update'); |
1083 | 1082 | } |
1084 | - if($GLOBALS['egw_info']['user']['apps']['notifications']) |
|
1083 | + if ($GLOBALS['egw_info']['user']['apps']['notifications']) |
|
1085 | 1084 | { |
1086 | 1085 | $this->_add_topmenu_info_item(self::_get_notification_bell(), 'notifications'); |
1087 | 1086 | } |
@@ -1093,9 +1092,9 @@ discard block |
||
1093 | 1092 | /** |
1094 | 1093 | * Add Preferences link to topmenu using settings-hook to know if an app supports Preferences |
1095 | 1094 | */ |
1096 | - protected function add_preferences_topmenu($type='prefs') |
|
1095 | + protected function add_preferences_topmenu($type = 'prefs') |
|
1097 | 1096 | { |
1098 | - static $memberships=null; |
|
1097 | + static $memberships = null; |
|
1099 | 1098 | if (!isset($memberships)) $memberships = $GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'], true); |
1100 | 1099 | static $types = array( |
1101 | 1100 | 'prefs' => array( |
@@ -1109,20 +1108,20 @@ discard block |
||
1109 | 1108 | 'cats' => array( |
1110 | 1109 | 'title' => 'Categories', |
1111 | 1110 | 'hook' => 'categories', |
1112 | - 'run_hook' => true, // acturally run hook, not just look it's implemented |
|
1111 | + 'run_hook' => true, // acturally run hook, not just look it's implemented |
|
1113 | 1112 | ), |
1114 | 1113 | ); |
1115 | 1114 | if (!$GLOBALS['egw_info']['user']['apps']['preferences'] || $GLOBALS['egw_info']['server']['deny_'.$type] && |
1116 | 1115 | array_intersect($memberships, (array)$GLOBALS['egw_info']['server']['deny_'.$type]) && |
1117 | 1116 | !$GLOBALS['egw_info']['user']['apps']['admin']) |
1118 | 1117 | { |
1119 | - return; // user has no access to Preferences app |
|
1118 | + return; // user has no access to Preferences app |
|
1120 | 1119 | } |
1121 | 1120 | if (isset($types[$type]['run_hook'])) |
1122 | 1121 | { |
1123 | 1122 | $apps = Hooks::process($types[$type]['hook']); |
1124 | 1123 | // as all apps answer, we need to remove none-true responses |
1125 | - foreach($apps as $app => $val) |
|
1124 | + foreach ($apps as $app => $val) |
|
1126 | 1125 | { |
1127 | 1126 | if (!$val) unset($apps[$app]); |
1128 | 1127 | } |
@@ -1148,7 +1147,7 @@ discard block |
||
1148 | 1147 | * @access protected |
1149 | 1148 | * @return void |
1150 | 1149 | */ |
1151 | - abstract function _add_topmenu_item(array $app_data,$alt_label=null); |
|
1150 | + abstract function _add_topmenu_item(array $app_data, $alt_label = null); |
|
1152 | 1151 | |
1153 | 1152 | /** |
1154 | 1153 | * Add info items to the topmenu template class to be displayed |
@@ -1158,7 +1157,7 @@ discard block |
||
1158 | 1157 | * @access protected |
1159 | 1158 | * @return void |
1160 | 1159 | */ |
1161 | - abstract function _add_topmenu_info_item($content, $id=null); |
|
1160 | + abstract function _add_topmenu_info_item($content, $id = null); |
|
1162 | 1161 | |
1163 | 1162 | static $top_menu_extra = array(); |
1164 | 1163 | |
@@ -1173,7 +1172,7 @@ discard block |
||
1173 | 1172 | * @access public |
1174 | 1173 | * @return void |
1175 | 1174 | */ |
1176 | - public static function add_topmenu_item($id,$url,$title,$target = '') |
|
1175 | + public static function add_topmenu_item($id, $url, $title, $target = '') |
|
1177 | 1176 | { |
1178 | 1177 | $entry['name'] = $id; |
1179 | 1178 | $entry['url'] = $url; |
@@ -1194,7 +1193,7 @@ discard block |
||
1194 | 1193 | * @access public |
1195 | 1194 | * @return void |
1196 | 1195 | */ |
1197 | - abstract function topmenu_info_icon($id,$icon_src,$iconlink,$blink=false,$tooltip=null); |
|
1196 | + abstract function topmenu_info_icon($id, $icon_src, $iconlink, $blink = false, $tooltip = null); |
|
1198 | 1197 | |
1199 | 1198 | /** |
1200 | 1199 | * Call and return content of 'after_navbar' hook |
@@ -1204,7 +1203,7 @@ discard block |
||
1204 | 1203 | protected function _get_after_navbar() |
1205 | 1204 | { |
1206 | 1205 | ob_start(); |
1207 | - Hooks::process('after_navbar',null,true); |
|
1206 | + Hooks::process('after_navbar', null, true); |
|
1208 | 1207 | $content = ob_get_contents(); |
1209 | 1208 | ob_end_clean(); |
1210 | 1209 | |
@@ -1241,7 +1240,7 @@ discard block |
||
1241 | 1240 | * @param string $app ='phpgwapi' application directory to search - default = phpgwapi |
1242 | 1241 | * @param boolean $append =true should the file be added |
1243 | 1242 | */ |
1244 | - static function includeJS($package, $file=null, $app='phpgwapi') |
|
1243 | + static function includeJS($package, $file = null, $app = 'phpgwapi') |
|
1245 | 1244 | { |
1246 | 1245 | self::$js_include_mgr->include_js_file($package, $file, $app); |
1247 | 1246 | } |
@@ -1253,7 +1252,7 @@ discard block |
||
1253 | 1252 | * @param boolean $clear_files =false true clear files after returning them |
1254 | 1253 | * @return array with pathes relative to EGW_SERVER_ROOT |
1255 | 1254 | */ |
1256 | - static function js_files(array $files=null, $clear_files=false) |
|
1255 | + static function js_files(array $files = null, $clear_files = false) |
|
1257 | 1256 | { |
1258 | 1257 | if (isset($files) && is_array($files)) |
1259 | 1258 | { |
@@ -1272,7 +1271,7 @@ discard block |
||
1272 | 1271 | * @param boolean $clear_files =false true clear files after returning them |
1273 | 1272 | * @return string|array see $return_pathes parameter |
1274 | 1273 | */ |
1275 | - static public function get_script_links($return_pathes=false, $clear_files=false) |
|
1274 | + static public function get_script_links($return_pathes = false, $clear_files = false) |
|
1276 | 1275 | { |
1277 | 1276 | $to_include = Framework\Bundle::js_includes(self::$js_include_mgr->get_included_files($clear_files)); |
1278 | 1277 | |
@@ -1280,7 +1279,7 @@ discard block |
||
1280 | 1279 | { |
1281 | 1280 | return $to_include; |
1282 | 1281 | } |
1283 | - $start = '<script type="text/javascript" src="'. $GLOBALS['egw_info']['server']['webserver_url']; |
|
1282 | + $start = '<script type="text/javascript" src="'.$GLOBALS['egw_info']['server']['webserver_url']; |
|
1284 | 1283 | $end = '">'."</script>\n"; |
1285 | 1284 | return "\n".$start.implode($end.$start, $to_include).$end; |
1286 | 1285 | } |
@@ -1300,7 +1299,7 @@ discard block |
||
1300 | 1299 | * @param boolean $no_default_css =false true do NOT load any default css, only what app explicitly includes |
1301 | 1300 | * @return boolean false: css file not found, true: file found |
1302 | 1301 | */ |
1303 | - public static function includeCSS($app, $name=null, $append=true, $no_default_css=false) |
|
1302 | + public static function includeCSS($app, $name = null, $append = true, $no_default_css = false) |
|
1304 | 1303 | { |
1305 | 1304 | if ($no_default_css) |
1306 | 1305 | { |
@@ -1320,16 +1319,16 @@ discard block |
||
1320 | 1319 | |
1321 | 1320 | // try to add app specific css file |
1322 | 1321 | self::includeCSS($app, 'app-'.$GLOBALS['egw_info']['user']['preferences']['common']['theme']) || |
1323 | - self::includeCSS($app,'app'); |
|
1322 | + self::includeCSS($app, 'app'); |
|
1324 | 1323 | |
1325 | 1324 | // add all css files from Framework::includeCSS() |
1326 | 1325 | $query = null; |
1327 | 1326 | //error_log(__METHOD__."() Framework\CssIncludes::get()=".array2string(Framework\CssIncludes::get())); |
1328 | - foreach(Framework\CssIncludes::get() as $path) |
|
1327 | + foreach (Framework\CssIncludes::get() as $path) |
|
1329 | 1328 | { |
1330 | 1329 | unset($query); |
1331 | - list($path,$query) = explode('?',$path,2); |
|
1332 | - $path .= '?'. ($query ? $query : filemtime(EGW_SERVER_ROOT.$path)); |
|
1330 | + list($path, $query) = explode('?', $path, 2); |
|
1331 | + $path .= '?'.($query ? $query : filemtime(EGW_SERVER_ROOT.$path)); |
|
1333 | 1332 | $response->includeCSS($GLOBALS['egw_info']['server']['webserver_url'].$path); |
1334 | 1333 | } |
1335 | 1334 | |
@@ -1338,7 +1337,7 @@ discard block |
||
1338 | 1337 | |
1339 | 1338 | // add all js files from Framework::includeJS() |
1340 | 1339 | $files = Framework\Bundle::js_includes(self::$js_include_mgr->get_included_files()); |
1341 | - foreach($files as $path) |
|
1340 | + foreach ($files as $path) |
|
1342 | 1341 | { |
1343 | 1342 | $response->includeScript($GLOBALS['egw_info']['server']['webserver_url'].$path); |
1344 | 1343 | } |
@@ -1414,17 +1413,17 @@ discard block |
||
1414 | 1413 | */ |
1415 | 1414 | public static function ajax_user_list() |
1416 | 1415 | { |
1417 | - $list = array('accounts' => array(),'groups' => array(), 'owngroups' => array()); |
|
1418 | - if($GLOBALS['egw_info']['user']['preferences']['common']['account_selection'] == 'primary_group') |
|
1416 | + $list = array('accounts' => array(), 'groups' => array(), 'owngroups' => array()); |
|
1417 | + if ($GLOBALS['egw_info']['user']['preferences']['common']['account_selection'] == 'primary_group') |
|
1419 | 1418 | { |
1420 | 1419 | $list['accounts']['filter']['group'] = $GLOBALS['egw_info']['user']['account_primary_group']; |
1421 | 1420 | } |
1422 | - foreach($list as $type => &$accounts) |
|
1421 | + foreach ($list as $type => &$accounts) |
|
1423 | 1422 | { |
1424 | 1423 | $options = array('account_type' => $type) + $accounts; |
1425 | - $key_pair = Accounts::link_query('',$options); |
|
1424 | + $key_pair = Accounts::link_query('', $options); |
|
1426 | 1425 | $accounts = array(); |
1427 | - foreach($key_pair as $account_id => $name) |
|
1426 | + foreach ($key_pair as $account_id => $name) |
|
1428 | 1427 | { |
1429 | 1428 | $accounts[] = array('value' => $account_id, 'label' => $name); |
1430 | 1429 | } |
@@ -1442,16 +1441,16 @@ discard block |
||
1442 | 1441 | * @param boolean $_resolve_groups =false true: return attribute for all members, false return attribute for group itself |
1443 | 1442 | * @return array account_id => data pairs |
1444 | 1443 | */ |
1445 | - public static function ajax_account_data($_account_ids, $_field, $_resolve_groups=false) |
|
1444 | + public static function ajax_account_data($_account_ids, $_field, $_resolve_groups = false) |
|
1446 | 1445 | { |
1447 | 1446 | $list = array(); |
1448 | - foreach((array)$_account_ids as $account_id) |
|
1447 | + foreach ((array)$_account_ids as $account_id) |
|
1449 | 1448 | { |
1450 | - foreach($account_id < 0 && $_resolve_groups ? |
|
1449 | + foreach ($account_id < 0 && $_resolve_groups ? |
|
1451 | 1450 | $GLOBALS['egw']->accounts->members($account_id, true) : array($account_id) as $account_id) |
1452 | 1451 | { |
1453 | 1452 | // Make sure name is formatted according to preference |
1454 | - if($_field == 'account_fullname') |
|
1453 | + if ($_field == 'account_fullname') |
|
1455 | 1454 | { |
1456 | 1455 | $list[$account_id] = Accounts::format_username( |
1457 | 1456 | $GLOBALS['egw']->accounts->id2name($account_id, 'account_lid'), |
@@ -46,13 +46,13 @@ discard block |
||
46 | 46 | * @param Base $storage |
47 | 47 | * @param \Traversable $rs |
48 | 48 | */ |
49 | - public function __construct(Base $storage, \Traversable $rs=null) |
|
49 | + public function __construct(Base $storage, \Traversable $rs = null) |
|
50 | 50 | { |
51 | 51 | $this->storage = $storage; |
52 | 52 | |
53 | 53 | $this->total = $storage->total; |
54 | 54 | |
55 | - if (is_a($rs,'IteratorAggregate')) |
|
55 | + if (is_a($rs, 'IteratorAggregate')) |
|
56 | 56 | { |
57 | 57 | $this->rs = $rs->getIterator(); |
58 | 58 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function current() |
71 | 71 | { |
72 | - if (is_a($this->rs,'iterator')) |
|
72 | + if (is_a($this->rs, 'iterator')) |
|
73 | 73 | { |
74 | 74 | $data = $this->rs->current(); |
75 | 75 | |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | */ |
86 | 86 | public function key() |
87 | 87 | { |
88 | - if (is_a($this->rs,'iterator')) |
|
88 | + if (is_a($this->rs, 'iterator')) |
|
89 | 89 | { |
90 | 90 | return $this->rs->key(); |
91 | 91 | } |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | */ |
98 | 98 | public function next() |
99 | 99 | { |
100 | - if (is_a($this->rs,'iterator')) |
|
100 | + if (is_a($this->rs, 'iterator')) |
|
101 | 101 | { |
102 | 102 | return $this->rs->next(); |
103 | 103 | } |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | */ |
109 | 109 | public function rewind() |
110 | 110 | { |
111 | - if (is_a($this->rs,'iterator')) |
|
111 | + if (is_a($this->rs, 'iterator')) |
|
112 | 112 | { |
113 | 113 | return $this->rs->rewind(); |
114 | 114 | } |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | * |
120 | 120 | * @return boolean |
121 | 121 | */ |
122 | - public function valid () |
|
122 | + public function valid() |
|
123 | 123 | { |
124 | - if (is_a($this->rs,'iterator')) |
|
124 | + if (is_a($this->rs, 'iterator')) |
|
125 | 125 | { |
126 | 126 | return $this->rs->valid(); |
127 | 127 | } |
@@ -1367,14 +1367,14 @@ |
||
1367 | 1367 | } |
1368 | 1368 | |
1369 | 1369 | /** |
1370 | - * Get a default list of columns to search |
|
1371 | - * This is to be used as a fallback, for when the extending class does not define |
|
1372 | - * $this->columns_to_search. All the columns are considered, and any with $skip_columns_with in |
|
1373 | - * their name are discarded because these columns are expected to be foreign keys or other numeric |
|
1374 | - * values with no meaning to the user. |
|
1375 | - * |
|
1376 | - * @return array of column names |
|
1377 | - */ |
|
1370 | + * Get a default list of columns to search |
|
1371 | + * This is to be used as a fallback, for when the extending class does not define |
|
1372 | + * $this->columns_to_search. All the columns are considered, and any with $skip_columns_with in |
|
1373 | + * their name are discarded because these columns are expected to be foreign keys or other numeric |
|
1374 | + * values with no meaning to the user. |
|
1375 | + * |
|
1376 | + * @return array of column names |
|
1377 | + */ |
|
1378 | 1378 | protected function get_default_search_columns() |
1379 | 1379 | { |
1380 | 1380 | $skip_columns_with = array('_id', 'modified', 'modifier', 'status', 'cat_id', 'owner'); |
@@ -182,7 +182,10 @@ discard block |
||
182 | 182 | function __construct($app='',$table='',Api\Db $db=null,$column_prefix='',$no_clone=false,$timestamp_type=null) |
183 | 183 | { |
184 | 184 | // ease the transition to api |
185 | - if ($app == 'phpgwapi') $app = 'api'; |
|
185 | + if ($app == 'phpgwapi') |
|
186 | + { |
|
187 | + $app = 'api'; |
|
188 | + } |
|
186 | 189 | |
187 | 190 | if ($no_clone) |
188 | 191 | { |
@@ -198,9 +201,15 @@ discard block |
||
198 | 201 | { |
199 | 202 | $this->app = $app; |
200 | 203 | |
201 | - if (!$no_clone) $this->db->set_app($app); |
|
204 | + if (!$no_clone) |
|
205 | + { |
|
206 | + $this->db->set_app($app); |
|
207 | + } |
|
202 | 208 | |
203 | - if ($table) $this->setup_table($app,$table,$column_prefix); |
|
209 | + if ($table) |
|
210 | + { |
|
211 | + $this->setup_table($app,$table,$column_prefix); |
|
212 | + } |
|
204 | 213 | } |
205 | 214 | $this->init(); |
206 | 215 | |
@@ -221,7 +230,10 @@ discard block |
||
221 | 230 | */ |
222 | 231 | public function set_times($timestamp_type=false) |
223 | 232 | { |
224 | - if ($timestamp_type !== false) $this->timestamp_type = $timestamp_type; |
|
233 | + if ($timestamp_type !== false) |
|
234 | + { |
|
235 | + $this->timestamp_type = $timestamp_type; |
|
236 | + } |
|
225 | 237 | |
226 | 238 | // set current time |
227 | 239 | switch($this->timestamp_type) |
@@ -279,7 +291,10 @@ discard block |
||
279 | 291 | { |
280 | 292 | $this->autoinc_id = $col; |
281 | 293 | } |
282 | - if ($def['type'] == 'bool') $this->has_bools = true; |
|
294 | + if ($def['type'] == 'bool') |
|
295 | + { |
|
296 | + $this->has_bools = true; |
|
297 | + } |
|
283 | 298 | |
284 | 299 | foreach($this->table_def['uc'] as $k => $uni_index) |
285 | 300 | { |
@@ -318,7 +333,10 @@ discard block |
||
318 | 333 | */ |
319 | 334 | function data_merge($new) |
320 | 335 | { |
321 | - if ((int) $this->debug >= 4) echo "<p>so_sql::data_merge(".print_r($new,true).")</p>\n"; |
|
336 | + if ((int) $this->debug >= 4) |
|
337 | + { |
|
338 | + echo "<p>so_sql::data_merge(".print_r($new,true).")</p>\n"; |
|
339 | + } |
|
322 | 340 | |
323 | 341 | if (!is_array($new) || !count($new)) |
324 | 342 | { |
@@ -342,7 +360,10 @@ discard block |
||
342 | 360 | { |
343 | 361 | $this->data[self::USER_TIMEZONE_READ] = $new[self::USER_TIMEZONE_READ]; |
344 | 362 | } |
345 | - if ((int) $this->debug >= 4) _debug_array($this->data); |
|
363 | + if ((int) $this->debug >= 4) |
|
364 | + { |
|
365 | + _debug_array($this->data); |
|
366 | + } |
|
346 | 367 | } |
347 | 368 | |
348 | 369 | /** |
@@ -486,7 +507,10 @@ discard block |
||
486 | 507 | if (!is_array($keys)) |
487 | 508 | { |
488 | 509 | $pk = array_values($this->db_key_cols); |
489 | - if ($pk) $keys = array($pk[0] => $keys); |
|
510 | + if ($pk) |
|
511 | + { |
|
512 | + $keys = array($pk[0] => $keys); |
|
513 | + } |
|
490 | 514 | } |
491 | 515 | |
492 | 516 | $this->init($keys); |
@@ -500,13 +524,16 @@ discard block |
||
500 | 524 | $query[$db_col] = $this->data[$col]; |
501 | 525 | } |
502 | 526 | } |
503 | - if (!$query) // no primary key in keys, lets try the data_cols for a unique key |
|
527 | + if (!$query) |
|
528 | + { |
|
529 | + // no primary key in keys, lets try the data_cols for a unique key |
|
504 | 530 | { |
505 | 531 | foreach($this->db_uni_cols as $db_col => $col) |
506 | 532 | { |
507 | 533 | if (!is_array($col) && $this->data[$col] != '') |
508 | 534 | { |
509 | 535 | $query[$db_col] = $this->data[$col]; |
536 | + } |
|
510 | 537 | } |
511 | 538 | elseif(is_array($col)) |
512 | 539 | { |
@@ -520,31 +547,43 @@ discard block |
||
520 | 547 | } |
521 | 548 | $q[$db_c] = $this->data[$c]; |
522 | 549 | } |
523 | - if ($q) $query += $q; |
|
550 | + if ($q) |
|
551 | + { |
|
552 | + $query += $q; |
|
553 | + } |
|
524 | 554 | } |
525 | 555 | } |
526 | 556 | } |
527 | - if (!$query) // no unique key in keys, lets try everything else |
|
557 | + if (!$query) |
|
558 | + { |
|
559 | + // no unique key in keys, lets try everything else |
|
528 | 560 | { |
529 | 561 | foreach($this->db_data_cols as $db_col => $col) |
530 | 562 | { |
531 | 563 | if ($this->data[$col] != '') |
532 | 564 | { |
533 | 565 | $query[$db_col] = $this->data[$col]; |
566 | + } |
|
534 | 567 | } |
535 | 568 | } |
536 | 569 | } |
537 | - if (!$query) // keys has no cols |
|
570 | + if (!$query) |
|
571 | + { |
|
572 | + // keys has no cols |
|
538 | 573 | { |
539 | 574 | $this->db2data(); |
575 | + } |
|
540 | 576 | |
541 | 577 | return False; |
542 | 578 | } |
543 | - if ($join) // Prefix the columns with the table-name, as they might exist in the join |
|
579 | + if ($join) |
|
580 | + { |
|
581 | + // Prefix the columns with the table-name, as they might exist in the join |
|
544 | 582 | { |
545 | 583 | foreach($query as $col => $val) |
546 | 584 | { |
547 | 585 | if (is_int($col) || strpos($join,$col) === false) continue; |
586 | + } |
|
548 | 587 | $query[] = $this->db->expression($this->table_name,$this->table_name.'.',array($col=>$val)); |
549 | 588 | unset($query[$col]); |
550 | 589 | } |
@@ -553,11 +592,14 @@ discard block |
||
553 | 592 | $query,__LINE__,__FILE__,False,'',$this->app,0,$join) as $row) |
554 | 593 | { |
555 | 594 | $cols = $this->db_cols; |
556 | - if ($extra_cols) // extra columns to report |
|
595 | + if ($extra_cols) |
|
596 | + { |
|
597 | + // extra columns to report |
|
557 | 598 | { |
558 | 599 | foreach(is_array($extra_cols) ? $extra_cols : array($extra_cols) as $col) |
559 | 600 | { |
560 | 601 | if (FALSE!==stripos($col,' as ')) $col = preg_replace('/^.* as *([a-z0-9_]+) *$/i','\\1',$col); |
602 | + } |
|
561 | 603 | $cols[$col] = $col; |
562 | 604 | } |
563 | 605 | } |
@@ -580,7 +622,10 @@ discard block |
||
580 | 622 | { |
581 | 623 | unset($this->data[$this->db_key_cols[$this->autoinc_id]]); |
582 | 624 | } |
583 | - if ((int) $this->debug >= 4) echo "nothing found !!!</p>\n"; |
|
625 | + if ((int) $this->debug >= 4) |
|
626 | + { |
|
627 | + echo "nothing found !!!</p>\n"; |
|
628 | + } |
|
584 | 629 | |
585 | 630 | $this->db2data(); |
586 | 631 | |
@@ -596,7 +641,10 @@ discard block |
||
596 | 641 | */ |
597 | 642 | function save($keys=null,$extra_where=null) |
598 | 643 | { |
599 | - if (is_array($keys) && count($keys)) $this->data_merge($keys); |
|
644 | + if (is_array($keys) && count($keys)) |
|
645 | + { |
|
646 | + $this->data_merge($keys); |
|
647 | + } |
|
600 | 648 | |
601 | 649 | // check if data contains user timezone during read AND user changed timezone since then |
602 | 650 | // --> load old timezone for the rest of this request |
@@ -613,9 +661,13 @@ discard block |
||
613 | 661 | } |
614 | 662 | $this->data2db(); |
615 | 663 | |
616 | - if ((int) $this->debug >= 4) { echo "so_sql::save(".print_r($keys,true).") autoinc_id='$this->autoinc_id', data="; _debug_array($this->data); } |
|
664 | + if ((int) $this->debug >= 4) |
|
665 | + { |
|
666 | +echo "so_sql::save(".print_r($keys,true).") autoinc_id='$this->autoinc_id', data="; _debug_array($this->data); } |
|
617 | 667 | |
618 | - if ($this->autoinc_id && !$this->data[$this->db_key_cols[$this->autoinc_id]]) // insert with auto id |
|
668 | + if ($this->autoinc_id && !$this->data[$this->db_key_cols[$this->autoinc_id]]) |
|
669 | + { |
|
670 | + // insert with auto id |
|
619 | 671 | { |
620 | 672 | foreach($this->db_cols as $db_col => $col) |
621 | 673 | { |
@@ -625,7 +677,9 @@ discard block |
||
625 | 677 | (isset($this->table_def['fd'][$db_col]['default']) || // we have a default value |
626 | 678 | !isset($this->table_def['fd'][$db_col]['nullable']) || $this->table_def['fd'][$db_col]['nullable'])) // column is nullable |
627 | 679 | { |
628 | - continue; // no need to write that (unset) column |
|
680 | + continue; |
|
681 | + } |
|
682 | + // no need to write that (unset) column |
|
629 | 683 | } |
630 | 684 | if ($this->table_def['fd'][$db_col]['type'] == 'varchar' && |
631 | 685 | strlen($this->data[$col]) > $this->table_def['fd'][$db_col]['precision']) |
@@ -656,9 +710,13 @@ discard block |
||
656 | 710 | if (!array_key_exists($col,$this->data) && // handling of unset columns in $this->data |
657 | 711 | ($this->autoinc_id || // update of table with auto id or |
658 | 712 | isset($this->table_def['fd'][$db_col]['default']) || // we have a default value or |
659 | - !isset($this->table_def['fd'][$db_col]['nullable']) || $this->table_def['fd'][$db_col]['nullable'])) // column is nullable |
|
713 | + !isset($this->table_def['fd'][$db_col]['nullable']) || $this->table_def['fd'][$db_col]['nullable'])) |
|
660 | 714 | { |
661 | - continue; // no need to write that (unset) column |
|
715 | + // column is nullable |
|
716 | + { |
|
717 | + continue; |
|
718 | + } |
|
719 | + // no need to write that (unset) column |
|
662 | 720 | } |
663 | 721 | $data[$db_col] = !is_object($this->data[$col]) && (string) $this->data[$col] === '' && $this->empty_on_write == 'NULL' ? null : $this->data[$col]; |
664 | 722 | } |
@@ -675,9 +733,12 @@ discard block |
||
675 | 733 | { |
676 | 734 | $keys[$db_col] = $this->data[$col]; |
677 | 735 | } |
678 | - if (!$data && !$this->autoinc_id) // happens if all columns are in the primary key |
|
736 | + if (!$data && !$this->autoinc_id) |
|
737 | + { |
|
738 | + // happens if all columns are in the primary key |
|
679 | 739 | { |
680 | 740 | $data = $keys; |
741 | + } |
|
681 | 742 | $keys = False; |
682 | 743 | } |
683 | 744 | if ($this->autoinc_id) |
@@ -708,7 +769,10 @@ discard block |
||
708 | 769 | */ |
709 | 770 | function update($_fields,$merge=true) |
710 | 771 | { |
711 | - if ($merge) $this->data_merge($_fields); |
|
772 | + if ($merge) |
|
773 | + { |
|
774 | + $this->data_merge($_fields); |
|
775 | + } |
|
712 | 776 | |
713 | 777 | $fields = $this->data2db($_fields); |
714 | 778 | |
@@ -761,9 +825,12 @@ discard block |
||
761 | 825 | { |
762 | 826 | $keys = array($this->autoinc_id => $keys); |
763 | 827 | } |
764 | - if (!is_array($keys) || !count($keys)) // use internal data |
|
828 | + if (!is_array($keys) || !count($keys)) |
|
829 | + { |
|
830 | + // use internal data |
|
765 | 831 | { |
766 | 832 | $data = $this->data; |
833 | + } |
|
767 | 834 | $keys = $this->db_key_cols; |
768 | 835 | } |
769 | 836 | else // data and keys are supplied in $keys |
@@ -783,7 +850,10 @@ discard block |
||
783 | 850 | { |
784 | 851 | $query[$db_col] = $data[$col]; |
785 | 852 | } |
786 | - if ($only_return_query) return $query; |
|
853 | + if ($only_return_query) |
|
854 | + { |
|
855 | + return $query; |
|
856 | + } |
|
787 | 857 | |
788 | 858 | $this->db->delete($this->table_name,$query,__LINE__,__FILE__,$this->app); |
789 | 859 | |
@@ -816,7 +886,10 @@ discard block |
||
816 | 886 | function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false) |
817 | 887 | { |
818 | 888 | //error_log(__METHOD__.'('.array2string(array_combine(array_slice(array('criteria','only_keys','order_by','extra_cols','wildcard','empty','op','start','filter','join','need_full_no_count'), 0, count(func_get_args())), func_get_args())).')'); |
819 | - if ((int) $this->debug >= 4) echo "<p>so_sql::search(".print_r($criteria,true).",'$only_keys','$order_by',".print_r($extra_cols,true).",'$wildcard','$empty','$op','$start',".print_r($filter,true).",'$join')</p>\n"; |
|
889 | + if ((int) $this->debug >= 4) |
|
890 | + { |
|
891 | + echo "<p>so_sql::search(".print_r($criteria,true).",'$only_keys','$order_by',".print_r($extra_cols,true).",'$wildcard','$empty','$op','$start',".print_r($filter,true).",'$join')</p>\n"; |
|
892 | + } |
|
820 | 893 | |
821 | 894 | // if extending class or instanciator set columns to search, convert string criteria to array |
822 | 895 | if ($criteria && !is_array($criteria)) |
@@ -880,9 +953,12 @@ discard block |
||
880 | 953 | ($negate ? ') ' : ''); |
881 | 954 | } |
882 | 955 | } |
883 | - elseif (strpos($db_col,'.') !== false) // we have a table-name specified |
|
956 | + elseif (strpos($db_col,'.') !== false) |
|
957 | + { |
|
958 | + // we have a table-name specified |
|
884 | 959 | { |
885 | 960 | list($table,$only_col) = explode('.',$db_col); |
961 | + } |
|
886 | 962 | $type = $this->db->get_column_attribute($only_col, $table, true, 'type'); |
887 | 963 | if (empty($type)) |
888 | 964 | { |
@@ -907,13 +983,17 @@ discard block |
||
907 | 983 | } |
908 | 984 | } |
909 | 985 | } |
910 | - if (is_array($query) && $op != 'AND') $query = $this->db->column_data_implode(' '.$op.' ',$query); |
|
986 | + if (is_array($query) && $op != 'AND') |
|
987 | + { |
|
988 | + $query = $this->db->column_data_implode(' '.$op.' ',$query); |
|
989 | + } |
|
911 | 990 | } |
912 | 991 | if (is_array($filter)) |
913 | 992 | { |
914 | 993 | $db_filter = array(); |
915 | 994 | $data2db_filter = $this->data2db($filter); |
916 | - if (!is_array($data2db_filter)) { |
|
995 | + if (!is_array($data2db_filter)) |
|
996 | + { |
|
917 | 997 | echo function_backtrace()."<br/>\n"; |
918 | 998 | echo "filter=";_debug_array($filter); |
919 | 999 | echo "data2db(filter)=";_debug_array($data2db_filter); |
@@ -1009,7 +1089,10 @@ discard block |
||
1009 | 1089 | } |
1010 | 1090 | } |
1011 | 1091 | $num_rows = 0; // as spec. in max_matches in the user-prefs |
1012 | - if (is_array($start)) list($start,$num_rows) = $start; |
|
1092 | + if (is_array($start)) |
|
1093 | + { |
|
1094 | + list($start,$num_rows) = $start; |
|
1095 | + } |
|
1013 | 1096 | |
1014 | 1097 | // fix GROUP BY clause to contain all non-aggregate selected columns |
1015 | 1098 | if ($order_by && stripos($order_by,'GROUP BY') !== false) |
@@ -1037,18 +1120,24 @@ discard block |
||
1037 | 1120 | 'append' => $order_by, |
1038 | 1121 | 'join' => $join, |
1039 | 1122 | ); |
1040 | - if (!$union_cols) // union used the colum-names of the first query |
|
1123 | + if (!$union_cols) |
|
1124 | + { |
|
1125 | + // union used the colum-names of the first query |
|
1041 | 1126 | { |
1042 | 1127 | $union_cols = $this->_get_columns($only_keys,$extra_cols); |
1043 | 1128 | } |
1129 | + } |
|
1044 | 1130 | return true; // waiting for further calls, before running the union-query |
1045 | 1131 | } |
1046 | 1132 | // running the union query now |
1047 | - if ($start !== false) // need to get the total too, saved in $this->total |
|
1133 | + if ($start !== false) |
|
1134 | + { |
|
1135 | + // need to get the total too, saved in $this->total |
|
1048 | 1136 | { |
1049 | 1137 | if ($this->db->Type == 'mysql' && $this->db->ServerInfo['version'] >= 4.0) |
1050 | 1138 | { |
1051 | 1139 | $union[0]['cols'] = ($mysql_calc_rows = 'SQL_CALC_FOUND_ROWS ').$union[0]['cols']; |
1140 | + } |
|
1052 | 1141 | } |
1053 | 1142 | else // cant do a count, have to run the query without limit |
1054 | 1143 | { |
@@ -1056,18 +1145,24 @@ discard block |
||
1056 | 1145 | } |
1057 | 1146 | } |
1058 | 1147 | $rs = $this->db->union($union,__LINE__,__FILE__,$order_by,$start,$num_rows); |
1059 | - if ($this->debug) error_log(__METHOD__."() ".$this->db->Query_ID->sql); |
|
1148 | + if ($this->debug) |
|
1149 | + { |
|
1150 | + error_log(__METHOD__."() ".$this->db->Query_ID->sql); |
|
1151 | + } |
|
1060 | 1152 | |
1061 | 1153 | $cols = $union_cols; |
1062 | 1154 | $union = $union_cols = array(); |
1063 | 1155 | } |
1064 | 1156 | else // no UNION |
1065 | 1157 | { |
1066 | - if ($start !== false) // need to get the total too, saved in $this->total |
|
1158 | + if ($start !== false) |
|
1159 | + { |
|
1160 | + // need to get the total too, saved in $this->total |
|
1067 | 1161 | { |
1068 | 1162 | if ($this->db->Type == 'mysql' && $this->db->ServerInfo['version'] >= 4.0) |
1069 | 1163 | { |
1070 | 1164 | $mysql_calc_rows = 'SQL_CALC_FOUND_ROWS '; |
1165 | + } |
|
1071 | 1166 | } |
1072 | 1167 | elseif (!$need_full_no_count && (!$join || stripos($join,'LEFT JOIN')!==false)) |
1073 | 1168 | { |
@@ -1080,10 +1175,16 @@ discard block |
||
1080 | 1175 | } |
1081 | 1176 | $rs = $this->db->select($this->table_name,$mysql_calc_rows.$colums,$query,__LINE__,__FILE__, |
1082 | 1177 | $start,$order_by,$this->app,$num_rows,$join); |
1083 | - if ($this->debug) error_log(__METHOD__."() ".$this->db->Query_ID->sql); |
|
1178 | + if ($this->debug) |
|
1179 | + { |
|
1180 | + error_log(__METHOD__."() ".$this->db->Query_ID->sql); |
|
1181 | + } |
|
1084 | 1182 | $cols = $this->_get_columns($only_keys,$extra_cols); |
1085 | 1183 | } |
1086 | - if ((int) $this->debug >= 4) echo "<p>sql='{$this->db->Query_ID->sql}'</p>\n"; |
|
1184 | + if ((int) $this->debug >= 4) |
|
1185 | + { |
|
1186 | + echo "<p>sql='{$this->db->Query_ID->sql}'</p>\n"; |
|
1187 | + } |
|
1087 | 1188 | |
1088 | 1189 | if ($mysql_calc_rows) |
1089 | 1190 | { |
@@ -1096,9 +1197,12 @@ discard block |
||
1096 | 1197 | } |
1097 | 1198 | $arr = array(); |
1098 | 1199 | $n = 0; |
1099 | - if ($rs) foreach($rs as $row) |
|
1200 | + if ($rs) |
|
1201 | + { |
|
1202 | + foreach($rs as $row) |
|
1100 | 1203 | { |
1101 | 1204 | $data = array(); |
1205 | + } |
|
1102 | 1206 | foreach($cols as $db_col => $col) |
1103 | 1207 | { |
1104 | 1208 | $data[$col] = (isset($row[$db_col]) ? $row[$db_col] : $row[$col]); |
@@ -1166,9 +1270,15 @@ discard block |
||
1166 | 1270 | $col = substr($col, $pos+9); |
1167 | 1271 | } |
1168 | 1272 | $alias = $col; |
1169 | - if (stripos($col, ' AS ')) list($col, $alias) = preg_split('/ +AS +/i', $col); |
|
1273 | + if (stripos($col, ' AS ')) |
|
1274 | + { |
|
1275 | + list($col, $alias) = preg_split('/ +AS +/i', $col); |
|
1276 | + } |
|
1170 | 1277 | // do NOT group by constant expressions |
1171 | - if (preg_match('/^ *(-?[0-9]+|".*"|\'.*\'|NULL) *$/i', $col)) continue; |
|
1278 | + if (preg_match('/^ *(-?[0-9]+|".*"|\'.*\'|NULL) *$/i', $col)) |
|
1279 | + { |
|
1280 | + continue; |
|
1281 | + } |
|
1172 | 1282 | if (!in_array($col, $group_by_cols) && !in_array($alias, $group_by_cols)) |
1173 | 1283 | { |
1174 | 1284 | // instead of aliased primary key, we have to use original column incl. table-name as alias is ambigues |
@@ -1201,7 +1311,10 @@ discard block |
||
1201 | 1311 | { |
1202 | 1312 | $pattern = trim($_pattern); |
1203 | 1313 | // This function can get called multiple times. Make sure it doesn't re-process. |
1204 | - if (empty($pattern) || is_array($pattern)) return $pattern; |
|
1314 | + if (empty($pattern) || is_array($pattern)) |
|
1315 | + { |
|
1316 | + return $pattern; |
|
1317 | + } |
|
1205 | 1318 | if(strpos($pattern, 'CAST(COALESCE(') !== false) |
1206 | 1319 | { |
1207 | 1320 | return $pattern; |
@@ -1271,7 +1384,7 @@ discard block |
||
1271 | 1384 | { |
1272 | 1385 | $token = substr($token, 1,strlen($token)); |
1273 | 1386 | if(substr($token, -1) != '"') |
1274 | - { |
|
1387 | + { |
|
1275 | 1388 | $token .= ' '.strtok('"'); |
1276 | 1389 | } |
1277 | 1390 | else |
@@ -1387,7 +1500,8 @@ discard block |
||
1387 | 1500 | foreach($search_cols as $key => &$col) |
1388 | 1501 | { |
1389 | 1502 | // If the name as given isn't a real column name, and adding the prefix doesn't help, skip it |
1390 | - if(!$this->table_def['fd'][$col] && !($col = $this->prefix.array_search($col, $search_cols))) { |
|
1503 | + if(!$this->table_def['fd'][$col] && !($col = $this->prefix.array_search($col, $search_cols))) |
|
1504 | + { |
|
1391 | 1505 | // Can't search this column |
1392 | 1506 | unset($search_cols[$key]); |
1393 | 1507 | continue; |
@@ -1421,10 +1535,13 @@ discard block |
||
1421 | 1535 | function _get_columns($only_keys,$extra_cols) |
1422 | 1536 | { |
1423 | 1537 | //echo "_get_columns() only_keys="; _debug_array($only_keys); echo "extra_cols="; _debug_array($extra_cols); |
1424 | - if ($only_keys === true) // only primary key |
|
1538 | + if ($only_keys === true) |
|
1539 | + { |
|
1540 | + // only primary key |
|
1425 | 1541 | { |
1426 | 1542 | $cols = $this->db_key_cols; |
1427 | 1543 | } |
1544 | + } |
|
1428 | 1545 | else |
1429 | 1546 | { |
1430 | 1547 | $cols = array(); |
@@ -1433,18 +1550,27 @@ discard block |
||
1433 | 1550 | { |
1434 | 1551 | if (!$distinct_checked) |
1435 | 1552 | { |
1436 | - if (stripos($col, 'DISTINCT ') === 0) $col = substr($col, 9); |
|
1553 | + if (stripos($col, 'DISTINCT ') === 0) |
|
1554 | + { |
|
1555 | + $col = substr($col, 9); |
|
1556 | + } |
|
1437 | 1557 | $distinct_checked = true; |
1438 | 1558 | } |
1439 | - if (!$col || $col == '*' || $col == $this->table_name.'.*') // all columns |
|
1559 | + if (!$col || $col == '*' || $col == $this->table_name.'.*') |
|
1560 | + { |
|
1561 | + // all columns |
|
1440 | 1562 | { |
1441 | 1563 | $cols = array_merge($cols,$this->db_cols); |
1442 | 1564 | } |
1565 | + } |
|
1443 | 1566 | else // only the specified columns |
1444 | 1567 | { |
1445 | - if (stripos($col,'as')) // if there's already an explicit naming of the column, just use it |
|
1568 | + if (stripos($col,'as')) |
|
1569 | + { |
|
1570 | + // if there's already an explicit naming of the column, just use it |
|
1446 | 1571 | { |
1447 | 1572 | $col = preg_replace('/^.*as +([a-z0-9_]+) *$/i','\\1',$col); |
1573 | + } |
|
1448 | 1574 | $cols[$col] = $col; |
1449 | 1575 | continue; |
1450 | 1576 | } |
@@ -1459,11 +1585,14 @@ discard block |
||
1459 | 1585 | } |
1460 | 1586 | } |
1461 | 1587 | } |
1462 | - if ($extra_cols) // extra columns to report |
|
1588 | + if ($extra_cols) |
|
1589 | + { |
|
1590 | + // extra columns to report |
|
1463 | 1591 | { |
1464 | 1592 | foreach(is_array($extra_cols) ? $extra_cols : explode(',',$extra_cols) as $col) |
1465 | 1593 | { |
1466 | 1594 | if (stripos($col,'as ')!==false) $col = preg_replace('/^.*as +([a-z0-9_]+) *$/i','\\1',$col); |
1595 | + } |
|
1467 | 1596 | if (($db_col = array_search($col,$this->db_cols)) !== false) |
1468 | 1597 | { |
1469 | 1598 | $cols[$db_col] = $col; |
@@ -1508,7 +1637,11 @@ discard block |
||
1508 | 1637 | '',false,$op,$query['num_rows']?array((int)$query['start'],$query['num_rows']):(int)$query['start'], |
1509 | 1638 | $query['col_filter'],$join,$need_full_no_count); |
1510 | 1639 | |
1511 | - if (!$rows) $rows = array(); // otherwise false returned from search would be returned as array(false) |
|
1640 | + if (!$rows) |
|
1641 | + { |
|
1642 | + $rows = array(); |
|
1643 | + } |
|
1644 | + // otherwise false returned from search would be returned as array(false) |
|
1512 | 1645 | |
1513 | 1646 | return $this->total; |
1514 | 1647 | } |
@@ -1587,7 +1720,10 @@ discard block |
||
1587 | 1720 | { |
1588 | 1721 | return $cache[$cache_key]; |
1589 | 1722 | } |
1590 | - if (!is_array($value_col)) $value_col = array($value_col); |
|
1723 | + if (!is_array($value_col)) |
|
1724 | + { |
|
1725 | + $value_col = array($value_col); |
|
1726 | + } |
|
1591 | 1727 | |
1592 | 1728 | $cols = $ret = array(); |
1593 | 1729 | foreach($value_col as $key => $col) |
@@ -1595,7 +1731,10 @@ discard block |
||
1595 | 1731 | $matches = null; |
1596 | 1732 | $cols[$key] = preg_match('/AS ([a-z_0-9]+)$/i',$col,$matches) ? $matches[1] : $col; |
1597 | 1733 | } |
1598 | - if (!$order) $order = current($cols); |
|
1734 | + if (!$order) |
|
1735 | + { |
|
1736 | + $order = current($cols); |
|
1737 | + } |
|
1599 | 1738 | |
1600 | 1739 | if (($search =& $this->search(array(),($key_col ? $key_col.',' : 'DISTINCT ').implode(',',$value_col),$order,'','',false,'AND',false,$filter))) |
1601 | 1740 | { |
@@ -1621,7 +1760,10 @@ discard block |
||
1621 | 1760 | { |
1622 | 1761 | $data = $row[current($cols)]; |
1623 | 1762 | } |
1624 | - if ($data) $ret[$row[$key_col]] = $data; |
|
1763 | + if ($data) |
|
1764 | + { |
|
1765 | + $ret[$row[$key_col]] = $data; |
|
1766 | + } |
|
1625 | 1767 | } |
1626 | 1768 | } |
1627 | 1769 | return $cache[$cache_key] =& $ret; |
@@ -1194,7 +1194,7 @@ |
||
1194 | 1194 | * @param string &$wildcard ='' on return wildcard char to use, if pattern does not already contain wildcards! |
1195 | 1195 | * @param string &$op ='AND' on return boolean operation to use, if pattern does not start with ! we use OR else AND |
1196 | 1196 | * @param string $extra_col =null extra column to search |
1197 | - * @param array $search_cols =array() List of columns to search. If not provided, all columns in $this->db_cols will be considered |
|
1197 | + * @param string[] $search_cols =array() List of columns to search. If not provided, all columns in $this->db_cols will be considered |
|
1198 | 1198 | * @return array or column => value pairs |
1199 | 1199 | */ |
1200 | 1200 | public function search2criteria($_pattern,&$wildcard='',&$op='AND',$extra_col=null, $search_cols = array()) |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | * @param string $timestamp_type =null default null=leave them as is, 'ts'|'integer' use integer unix timestamps, |
180 | 180 | * 'object' use Api\DateTime objects or 'string' use DB timestamp (Y-m-d H:i:s) string |
181 | 181 | */ |
182 | - function __construct($app='',$table='',Api\Db $db=null,$column_prefix='',$no_clone=false,$timestamp_type=null) |
|
182 | + function __construct($app = '', $table = '', Api\Db $db = null, $column_prefix = '', $no_clone = false, $timestamp_type = null) |
|
183 | 183 | { |
184 | 184 | // ease the transition to api |
185 | 185 | if ($app == 'phpgwapi') $app = 'api'; |
@@ -200,11 +200,11 @@ discard block |
||
200 | 200 | |
201 | 201 | if (!$no_clone) $this->db->set_app($app); |
202 | 202 | |
203 | - if ($table) $this->setup_table($app,$table,$column_prefix); |
|
203 | + if ($table) $this->setup_table($app, $table, $column_prefix); |
|
204 | 204 | } |
205 | 205 | $this->init(); |
206 | 206 | |
207 | - if ((int) $this->debug >= 4) |
|
207 | + if ((int)$this->debug >= 4) |
|
208 | 208 | { |
209 | 209 | echo "<p>".__METHOD__."('$app','$table')</p>\n"; |
210 | 210 | _debug_array($this); |
@@ -219,21 +219,21 @@ discard block |
||
219 | 219 | * null=leave them as is, 'ts'|'integer' use integer unix timestamps, 'object' use Api\DateTime objects, |
220 | 220 | * 'string' use DB timestamp (Y-m-d H:i:s) string |
221 | 221 | */ |
222 | - public function set_times($timestamp_type=false) |
|
222 | + public function set_times($timestamp_type = false) |
|
223 | 223 | { |
224 | 224 | if ($timestamp_type !== false) $this->timestamp_type = $timestamp_type; |
225 | 225 | |
226 | 226 | // set current time |
227 | - switch($this->timestamp_type) |
|
227 | + switch ($this->timestamp_type) |
|
228 | 228 | { |
229 | 229 | case 'object': |
230 | 230 | $this->now = new Api\DateTime('now'); |
231 | 231 | break; |
232 | 232 | case 'string': |
233 | - $this->now = Api\DateTime::to('now',Api\DateTime::DATABASE); |
|
233 | + $this->now = Api\DateTime::to('now', Api\DateTime::DATABASE); |
|
234 | 234 | break; |
235 | 235 | default: |
236 | - $this->now = Api\DateTime::to('now','ts'); |
|
236 | + $this->now = Api\DateTime::to('now', 'ts'); |
|
237 | 237 | } |
238 | 238 | $this->tz_offset_s = Api\DateTime::tz_offset_s(); |
239 | 239 | } |
@@ -247,10 +247,10 @@ discard block |
||
247 | 247 | * @param string $table table-name |
248 | 248 | * @param string $colum_prefix ='' column prefix to automatic remove from the column-name, if the column name starts with it |
249 | 249 | */ |
250 | - function setup_table($app,$table,$colum_prefix='') |
|
250 | + function setup_table($app, $table, $colum_prefix = '') |
|
251 | 251 | { |
252 | 252 | $this->table_name = $table; |
253 | - $this->table_def = $this->db->get_table_definitions($app,$table); |
|
253 | + $this->table_def = $this->db->get_table_definitions($app, $table); |
|
254 | 254 | if (!$this->table_def || !is_array($this->table_def['fd'])) |
255 | 255 | { |
256 | 256 | throw new Api\Exception\WrongParameter(__METHOD__."('$app','$table'): No table definition for '$table' found !!!"); |
@@ -258,14 +258,14 @@ discard block |
||
258 | 258 | $this->db_key_cols = $this->db_data_cols = $this->db_cols = array(); |
259 | 259 | $this->autoinc_id = ''; |
260 | 260 | $len_prefix = strlen($colum_prefix); |
261 | - foreach($this->table_def['fd'] as $col => $def) |
|
261 | + foreach ($this->table_def['fd'] as $col => $def) |
|
262 | 262 | { |
263 | 263 | $name = $col; |
264 | - if ($len_prefix && substr($name,0,$len_prefix) == $colum_prefix) |
|
264 | + if ($len_prefix && substr($name, 0, $len_prefix) == $colum_prefix) |
|
265 | 265 | { |
266 | - $name = substr($col,$len_prefix); |
|
266 | + $name = substr($col, $len_prefix); |
|
267 | 267 | } |
268 | - if (in_array($col,$this->table_def['pk'])) |
|
268 | + if (in_array($col, $this->table_def['pk'])) |
|
269 | 269 | { |
270 | 270 | $this->db_key_cols[$col] = $name; |
271 | 271 | } |
@@ -281,13 +281,13 @@ discard block |
||
281 | 281 | } |
282 | 282 | if ($def['type'] == 'bool') $this->has_bools = true; |
283 | 283 | |
284 | - foreach($this->table_def['uc'] as $k => $uni_index) |
|
284 | + foreach ($this->table_def['uc'] as $k => $uni_index) |
|
285 | 285 | { |
286 | - if (is_array($uni_index) && in_array($name,$uni_index)) |
|
286 | + if (is_array($uni_index) && in_array($name, $uni_index)) |
|
287 | 287 | { |
288 | 288 | $this->db_uni_cols[$k][$col] = $name; |
289 | 289 | } |
290 | - elseif($name === $uni_index) |
|
290 | + elseif ($name === $uni_index) |
|
291 | 291 | { |
292 | 292 | $this->db_uni_cols[$col] = $name; |
293 | 293 | } |
@@ -302,9 +302,9 @@ discard block |
||
302 | 302 | function convert_all_timestamps() |
303 | 303 | { |
304 | 304 | $check_already_included = !empty($this->timestamps); |
305 | - foreach($this->table_def['fd'] as $name => $data) |
|
305 | + foreach ($this->table_def['fd'] as $name => $data) |
|
306 | 306 | { |
307 | - if ($data['type'] == 'timestamp' && (!$check_already_included || !in_array($name,$this->timestamps))) |
|
307 | + if ($data['type'] == 'timestamp' && (!$check_already_included || !in_array($name, $this->timestamps))) |
|
308 | 308 | { |
309 | 309 | $this->timestamps[] = $name; |
310 | 310 | } |
@@ -318,22 +318,22 @@ discard block |
||
318 | 318 | */ |
319 | 319 | function data_merge($new) |
320 | 320 | { |
321 | - if ((int) $this->debug >= 4) echo "<p>so_sql::data_merge(".print_r($new,true).")</p>\n"; |
|
321 | + if ((int)$this->debug >= 4) echo "<p>so_sql::data_merge(".print_r($new, true).")</p>\n"; |
|
322 | 322 | |
323 | 323 | if (!is_array($new) || !count($new)) |
324 | 324 | { |
325 | 325 | return; |
326 | 326 | } |
327 | - foreach($this->db_cols as $db_col => $col) |
|
327 | + foreach ($this->db_cols as $db_col => $col) |
|
328 | 328 | { |
329 | - if (array_key_exists($col,$new)) |
|
329 | + if (array_key_exists($col, $new)) |
|
330 | 330 | { |
331 | 331 | $this->data[$col] = $new[$col]; |
332 | 332 | } |
333 | 333 | } |
334 | - foreach($this->non_db_cols as $db_col => $col) |
|
334 | + foreach ($this->non_db_cols as $db_col => $col) |
|
335 | 335 | { |
336 | - if (array_key_exists($col,$new)) |
|
336 | + if (array_key_exists($col, $new)) |
|
337 | 337 | { |
338 | 338 | $this->data[$col] = $new[$col]; |
339 | 339 | } |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | { |
343 | 343 | $this->data[self::USER_TIMEZONE_READ] = $new[self::USER_TIMEZONE_READ]; |
344 | 344 | } |
345 | - if ((int) $this->debug >= 4) _debug_array($this->data); |
|
345 | + if ((int)$this->debug >= 4) _debug_array($this->data); |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | /** |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | * @param array $data =null if given works on that array and returns result, else works on internal data-array |
367 | 367 | * @return array |
368 | 368 | */ |
369 | - function db2data($data=null) |
|
369 | + function db2data($data = null) |
|
370 | 370 | { |
371 | 371 | if (!is_array($data)) |
372 | 372 | { |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | } |
375 | 375 | if ($this->timestamps) |
376 | 376 | { |
377 | - foreach($this->timestamps as $name) |
|
377 | + foreach ($this->timestamps as $name) |
|
378 | 378 | { |
379 | 379 | if (isset($data[$name]) && $data[$name]) |
380 | 380 | { |
@@ -384,7 +384,7 @@ discard block |
||
384 | 384 | } |
385 | 385 | else |
386 | 386 | { |
387 | - $data[$name] = Api\DateTime::server2user($data[$name],$this->timestamp_type); |
|
387 | + $data[$name] = Api\DateTime::server2user($data[$name], $this->timestamp_type); |
|
388 | 388 | } |
389 | 389 | } |
390 | 390 | } |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | throw new Api\Exception\WrongParameter(__METHOD__."(): No table definition for '$this->table' found !!!"); |
401 | 401 | } |
402 | 402 | } |
403 | - foreach($this->table_def['fd'] as $col => $def) |
|
403 | + foreach ($this->table_def['fd'] as $col => $def) |
|
404 | 404 | { |
405 | 405 | if ($def['type'] == 'bool' && isset($data[$col])) |
406 | 406 | { |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | * @param array $data =null if given works on that array and returns result, else works on internal data-array |
433 | 433 | * @return array |
434 | 434 | */ |
435 | - function data2db($data=null) |
|
435 | + function data2db($data = null) |
|
436 | 436 | { |
437 | 437 | if (!is_array($data)) |
438 | 438 | { |
@@ -440,11 +440,11 @@ discard block |
||
440 | 440 | } |
441 | 441 | if ($this->timestamps) |
442 | 442 | { |
443 | - foreach($this->timestamps as $name) |
|
443 | + foreach ($this->timestamps as $name) |
|
444 | 444 | { |
445 | 445 | if (isset($data[$name]) && $data[$name]) |
446 | 446 | { |
447 | - $data[$name] = Api\DateTime::user2server($data[$name],$this->timestamp_type); |
|
447 | + $data[$name] = Api\DateTime::user2server($data[$name], $this->timestamp_type); |
|
448 | 448 | } |
449 | 449 | } |
450 | 450 | } |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | * @param array $keys =array() array with keys in form internalName => value |
458 | 458 | * @return array internal data after init |
459 | 459 | */ |
460 | - function init($keys=array()) |
|
460 | + function init($keys = array()) |
|
461 | 461 | { |
462 | 462 | $this->data = array(); |
463 | 463 | |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | * @param string $join ='' sql to do a join, added as is after the table-name, eg. ", table2 WHERE x=y" or |
482 | 482 | * @return array|boolean data if row could be retrived else False |
483 | 483 | */ |
484 | - function read($keys,$extra_cols='',$join='') |
|
484 | + function read($keys, $extra_cols = '', $join = '') |
|
485 | 485 | { |
486 | 486 | if (!is_array($keys)) |
487 | 487 | { |
@@ -502,16 +502,16 @@ discard block |
||
502 | 502 | } |
503 | 503 | if (!$query) // no primary key in keys, lets try the data_cols for a unique key |
504 | 504 | { |
505 | - foreach($this->db_uni_cols as $db_col => $col) |
|
505 | + foreach ($this->db_uni_cols as $db_col => $col) |
|
506 | 506 | { |
507 | 507 | if (!is_array($col) && $this->data[$col] != '') |
508 | 508 | { |
509 | 509 | $query[$db_col] = $this->data[$col]; |
510 | 510 | } |
511 | - elseif(is_array($col)) |
|
511 | + elseif (is_array($col)) |
|
512 | 512 | { |
513 | 513 | $q = array(); |
514 | - foreach($col as $db_c => $c) |
|
514 | + foreach ($col as $db_c => $c) |
|
515 | 515 | { |
516 | 516 | if ($this->data[$col] == '') |
517 | 517 | { |
@@ -526,7 +526,7 @@ discard block |
||
526 | 526 | } |
527 | 527 | if (!$query) // no unique key in keys, lets try everything else |
528 | 528 | { |
529 | - foreach($this->db_data_cols as $db_col => $col) |
|
529 | + foreach ($this->db_data_cols as $db_col => $col) |
|
530 | 530 | { |
531 | 531 | if ($this->data[$col] != '') |
532 | 532 | { |
@@ -542,27 +542,27 @@ discard block |
||
542 | 542 | } |
543 | 543 | if ($join) // Prefix the columns with the table-name, as they might exist in the join |
544 | 544 | { |
545 | - foreach($query as $col => $val) |
|
545 | + foreach ($query as $col => $val) |
|
546 | 546 | { |
547 | - if (is_int($col) || strpos($join,$col) === false) continue; |
|
548 | - $query[] = $this->db->expression($this->table_name,$this->table_name.'.',array($col=>$val)); |
|
547 | + if (is_int($col) || strpos($join, $col) === false) continue; |
|
548 | + $query[] = $this->db->expression($this->table_name, $this->table_name.'.', array($col=>$val)); |
|
549 | 549 | unset($query[$col]); |
550 | 550 | } |
551 | 551 | } |
552 | 552 | // copy direct SQL parts from $keys |
553 | - for($i = 0; is_array($keys) && isset($keys[$i]); ++$i) |
|
553 | + for ($i = 0; is_array($keys) && isset($keys[$i]); ++$i) |
|
554 | 554 | { |
555 | 555 | $query[] = $keys[$i]; |
556 | 556 | } |
557 | - foreach($this->db->select($this->table_name,'*'.($extra_cols?','.(is_array($extra_cols)?implode(',',$extra_cols):$extra_cols):''), |
|
558 | - $query,__LINE__,__FILE__,False,'',$this->app,0,$join) as $row) |
|
557 | + foreach ($this->db->select($this->table_name, '*'.($extra_cols ? ','.(is_array($extra_cols) ?implode(',', $extra_cols) : $extra_cols) : ''), |
|
558 | + $query, __LINE__, __FILE__, False, '', $this->app, 0, $join) as $row) |
|
559 | 559 | { |
560 | 560 | $cols = $this->db_cols; |
561 | 561 | if ($extra_cols) // extra columns to report |
562 | 562 | { |
563 | - foreach(is_array($extra_cols) ? $extra_cols : array($extra_cols) as $col) |
|
563 | + foreach (is_array($extra_cols) ? $extra_cols : array($extra_cols) as $col) |
|
564 | 564 | { |
565 | - if (FALSE!==stripos($col,' as ')) $col = preg_replace('/^.* as *([a-z0-9_]+) *$/i','\\1',$col); |
|
565 | + if (FALSE !== stripos($col, ' as ')) $col = preg_replace('/^.* as *([a-z0-9_]+) *$/i', '\\1', $col); |
|
566 | 566 | $cols[$col] = $col; |
567 | 567 | } |
568 | 568 | } |
@@ -575,7 +575,7 @@ discard block |
||
575 | 575 | // store user timezone used for reading |
576 | 576 | $this->data[self::USER_TIMEZONE_READ] = Api\DateTime::$user_timezone->getName(); |
577 | 577 | |
578 | - if ((int) $this->debug >= 4) |
|
578 | + if ((int)$this->debug >= 4) |
|
579 | 579 | { |
580 | 580 | echo "data =\n"; _debug_array($this->data); |
581 | 581 | } |
@@ -585,7 +585,7 @@ discard block |
||
585 | 585 | { |
586 | 586 | unset($this->data[$this->db_key_cols[$this->autoinc_id]]); |
587 | 587 | } |
588 | - if ((int) $this->debug >= 4) echo "nothing found !!!</p>\n"; |
|
588 | + if ((int)$this->debug >= 4) echo "nothing found !!!</p>\n"; |
|
589 | 589 | |
590 | 590 | $this->db2data(); |
591 | 591 | |
@@ -599,7 +599,7 @@ discard block |
||
599 | 599 | * @param string|array $extra_where =null extra where clause, eg. to check an etag, returns true if no affected rows! |
600 | 600 | * @return int|boolean 0 on success, or errno != 0 on error, or true if $extra_where is given and no rows affected |
601 | 601 | */ |
602 | - function save($keys=null,$extra_where=null) |
|
602 | + function save($keys = null, $extra_where = null) |
|
603 | 603 | { |
604 | 604 | if (is_array($keys) && count($keys)) $this->data_merge($keys); |
605 | 605 | |
@@ -618,65 +618,65 @@ discard block |
||
618 | 618 | } |
619 | 619 | $this->data2db(); |
620 | 620 | |
621 | - if ((int) $this->debug >= 4) { echo "so_sql::save(".print_r($keys,true).") autoinc_id='$this->autoinc_id', data="; _debug_array($this->data); } |
|
621 | + if ((int)$this->debug >= 4) { echo "so_sql::save(".print_r($keys, true).") autoinc_id='$this->autoinc_id', data="; _debug_array($this->data); } |
|
622 | 622 | |
623 | 623 | if ($this->autoinc_id && !$this->data[$this->db_key_cols[$this->autoinc_id]]) // insert with auto id |
624 | 624 | { |
625 | - foreach($this->db_cols as $db_col => $col) |
|
625 | + foreach ($this->db_cols as $db_col => $col) |
|
626 | 626 | { |
627 | 627 | if (!$this->autoinc_id || $db_col != $this->autoinc_id) // not write auto-inc-id |
628 | 628 | { |
629 | - if (!array_key_exists($col,$this->data) && // handling of unset columns in $this->data |
|
630 | - (isset($this->table_def['fd'][$db_col]['default']) || // we have a default value |
|
629 | + if (!array_key_exists($col, $this->data) && // handling of unset columns in $this->data |
|
630 | + (isset($this->table_def['fd'][$db_col]['default']) || // we have a default value |
|
631 | 631 | !isset($this->table_def['fd'][$db_col]['nullable']) || $this->table_def['fd'][$db_col]['nullable'])) // column is nullable |
632 | 632 | { |
633 | - continue; // no need to write that (unset) column |
|
633 | + continue; // no need to write that (unset) column |
|
634 | 634 | } |
635 | 635 | if ($this->table_def['fd'][$db_col]['type'] == 'varchar' && |
636 | 636 | strlen($this->data[$col]) > $this->table_def['fd'][$db_col]['precision']) |
637 | 637 | { |
638 | 638 | // truncate the field to mamimum length, if upper layers didn't care |
639 | - $data[$db_col] = substr($this->data[$col],0,$this->table_def['fd'][$db_col]['precision']); |
|
639 | + $data[$db_col] = substr($this->data[$col], 0, $this->table_def['fd'][$db_col]['precision']); |
|
640 | 640 | } |
641 | 641 | else |
642 | 642 | { |
643 | - $data[$db_col] = (string) $this->data[$col] === '' && $this->empty_on_write == 'NULL' ? null : $this->data[$col]; |
|
643 | + $data[$db_col] = (string)$this->data[$col] === '' && $this->empty_on_write == 'NULL' ? null : $this->data[$col]; |
|
644 | 644 | } |
645 | 645 | } |
646 | 646 | } |
647 | - $this->db->insert($this->table_name,$data,false,__LINE__,__FILE__,$this->app); |
|
647 | + $this->db->insert($this->table_name, $data, false, __LINE__, __FILE__, $this->app); |
|
648 | 648 | |
649 | 649 | if ($this->autoinc_id) |
650 | 650 | { |
651 | - $this->data[$this->db_key_cols[$this->autoinc_id]] = $this->db->get_last_insert_id($this->table_name,$this->autoinc_id); |
|
651 | + $this->data[$this->db_key_cols[$this->autoinc_id]] = $this->db->get_last_insert_id($this->table_name, $this->autoinc_id); |
|
652 | 652 | } |
653 | 653 | } |
654 | 654 | else // insert in table without auto id or update of existing row, dont write colums unset in $this->data |
655 | 655 | { |
656 | - foreach($this->db_data_cols as $db_col => $col) |
|
656 | + foreach ($this->db_data_cols as $db_col => $col) |
|
657 | 657 | { |
658 | 658 | // we need to update columns set to null: after a $this->data[$col]=null: |
659 | 659 | // - array_key_exits($col,$this->data) === true |
660 | 660 | // - isset($this->data[$col]) === false |
661 | - if (!array_key_exists($col,$this->data) && // handling of unset columns in $this->data |
|
662 | - ($this->autoinc_id || // update of table with auto id or |
|
663 | - isset($this->table_def['fd'][$db_col]['default']) || // we have a default value or |
|
661 | + if (!array_key_exists($col, $this->data) && // handling of unset columns in $this->data |
|
662 | + ($this->autoinc_id || // update of table with auto id or |
|
663 | + isset($this->table_def['fd'][$db_col]['default']) || // we have a default value or |
|
664 | 664 | !isset($this->table_def['fd'][$db_col]['nullable']) || $this->table_def['fd'][$db_col]['nullable'])) // column is nullable |
665 | 665 | { |
666 | - continue; // no need to write that (unset) column |
|
666 | + continue; // no need to write that (unset) column |
|
667 | 667 | } |
668 | - $data[$db_col] = !is_object($this->data[$col]) && (string) $this->data[$col] === '' && $this->empty_on_write == 'NULL' ? null : $this->data[$col]; |
|
668 | + $data[$db_col] = !is_object($this->data[$col]) && (string)$this->data[$col] === '' && $this->empty_on_write == 'NULL' ? null : $this->data[$col]; |
|
669 | 669 | } |
670 | 670 | // allow to add direct sql updates, eg. "etag=etag+1" with int keys |
671 | 671 | if (is_array($keys) && isset($keys[0])) |
672 | 672 | { |
673 | - for($n=0; isset($keys[$n]); ++$n) |
|
673 | + for ($n = 0; isset($keys[$n]); ++$n) |
|
674 | 674 | { |
675 | 675 | $data[] = $keys[$n]; |
676 | 676 | } |
677 | 677 | } |
678 | 678 | $keys = $extra_where; |
679 | - foreach($this->db_key_cols as $db_col => $col) |
|
679 | + foreach ($this->db_key_cols as $db_col => $col) |
|
680 | 680 | { |
681 | 681 | $keys[$db_col] = $this->data[$col]; |
682 | 682 | } |
@@ -687,16 +687,16 @@ discard block |
||
687 | 687 | } |
688 | 688 | if ($this->autoinc_id) |
689 | 689 | { |
690 | - $this->db->update($this->table_name,$data,$keys,__LINE__,__FILE__,$this->app); |
|
690 | + $this->db->update($this->table_name, $data, $keys, __LINE__, __FILE__, $this->app); |
|
691 | 691 | if (($nothing_affected = !$this->db->Errno && !$this->db->affected_rows()) && $extra_where) |
692 | 692 | { |
693 | - return true; // extra_where not met, eg. etag wrong |
|
693 | + return true; // extra_where not met, eg. etag wrong |
|
694 | 694 | } |
695 | 695 | } |
696 | 696 | // always try an insert if we have no autoinc_id, as we dont know if the data exists |
697 | 697 | if (!$this->autoinc_id || $nothing_affected) |
698 | 698 | { |
699 | - $this->db->insert($this->table_name,$data,$keys,__LINE__,__FILE__,$this->app); |
|
699 | + $this->db->insert($this->table_name, $data, $keys, __LINE__, __FILE__, $this->app); |
|
700 | 700 | } |
701 | 701 | } |
702 | 702 | $this->db2data(); |
@@ -711,7 +711,7 @@ discard block |
||
711 | 711 | * @param boolean $merge =true if true $fields will be merged with $this->data (after update!), otherwise $this->data will be just $fields |
712 | 712 | * @return int|boolean 0 on success, or errno != 0 on error, or true if $extra_where is given and no rows affected |
713 | 713 | */ |
714 | - function update($_fields,$merge=true) |
|
714 | + function update($_fields, $merge = true) |
|
715 | 715 | { |
716 | 716 | if ($merge) $this->data_merge($_fields); |
717 | 717 | |
@@ -719,23 +719,23 @@ discard block |
||
719 | 719 | |
720 | 720 | // extract the keys from $fields or - if not set there - from $this->data |
721 | 721 | $keys = array(); |
722 | - foreach($this->db_key_cols as $col => $name) |
|
722 | + foreach ($this->db_key_cols as $col => $name) |
|
723 | 723 | { |
724 | 724 | $keys[$col] = isset($fields[$name]) ? $fields[$name] : $this->data[$name]; |
725 | 725 | unset($fields[$name]); |
726 | 726 | } |
727 | 727 | // extract the data from $fields |
728 | 728 | $data = array(); |
729 | - foreach($this->db_data_cols as $col => $name) |
|
729 | + foreach ($this->db_data_cols as $col => $name) |
|
730 | 730 | { |
731 | - if (array_key_exists($name,$fields)) |
|
731 | + if (array_key_exists($name, $fields)) |
|
732 | 732 | { |
733 | 733 | $data[$col] = $fields[$name]; |
734 | 734 | unset($fields[$name]); |
735 | 735 | } |
736 | 736 | } |
737 | 737 | // add direct sql like 'etag=etag+1' (it has integer keys) |
738 | - foreach($fields as $key => $value) |
|
738 | + foreach ($fields as $key => $value) |
|
739 | 739 | { |
740 | 740 | if (is_int($key)) |
741 | 741 | { |
@@ -744,9 +744,9 @@ discard block |
||
744 | 744 | } |
745 | 745 | if (!$data) |
746 | 746 | { |
747 | - return 0; // nothing to update |
|
747 | + return 0; // nothing to update |
|
748 | 748 | } |
749 | - if (!$this->db->update($this->table_name,$data,$keys,__LINE__,__FILE__,$this->app)) |
|
749 | + if (!$this->db->update($this->table_name, $data, $keys, __LINE__, __FILE__, $this->app)) |
|
750 | 750 | { |
751 | 751 | return $this->db->Errno; |
752 | 752 | } |
@@ -760,7 +760,7 @@ discard block |
||
760 | 760 | * @param boolean $only_return_query =false return $query of delete call to db object, but not run it (used by so_sql_cf!) |
761 | 761 | * @return int|array affected rows, should be 1 if ok, 0 if an error or array with id's if $only_return_ids |
762 | 762 | */ |
763 | - function delete($keys=null,$only_return_query=false) |
|
763 | + function delete($keys = null, $only_return_query = false) |
|
764 | 764 | { |
765 | 765 | if ($this->autoinc_id && $keys && !is_array($keys)) |
766 | 766 | { |
@@ -774,7 +774,7 @@ discard block |
||
774 | 774 | else // data and keys are supplied in $keys |
775 | 775 | { |
776 | 776 | $data = $keys; $keys = array(); |
777 | - foreach($this->db_cols as $db_col => $col) |
|
777 | + foreach ($this->db_cols as $db_col => $col) |
|
778 | 778 | { |
779 | 779 | if (isset($data[$col])) |
780 | 780 | { |
@@ -784,13 +784,13 @@ discard block |
||
784 | 784 | } |
785 | 785 | $data = $this->data2db($data); |
786 | 786 | |
787 | - foreach($keys as $db_col => $col) |
|
787 | + foreach ($keys as $db_col => $col) |
|
788 | 788 | { |
789 | 789 | $query[$db_col] = $data[$col]; |
790 | 790 | } |
791 | 791 | if ($only_return_query) return $query; |
792 | 792 | |
793 | - $this->db->delete($this->table_name,$query,__LINE__,__FILE__,$this->app); |
|
793 | + $this->db->delete($this->table_name, $query, __LINE__, __FILE__, $this->app); |
|
794 | 794 | |
795 | 795 | return $this->db->affected_rows(); |
796 | 796 | } |
@@ -818,15 +818,15 @@ discard block |
||
818 | 818 | * @todo return an interator instead of an array |
819 | 819 | * @return array|NULL array of matching rows (the row is an array of the cols) or NULL |
820 | 820 | */ |
821 | - function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false) |
|
821 | + function &search($criteria, $only_keys = True, $order_by = '', $extra_cols = '', $wildcard = '', $empty = False, $op = 'AND', $start = false, $filter = null, $join = '', $need_full_no_count = false) |
|
822 | 822 | { |
823 | 823 | //error_log(__METHOD__.'('.array2string(array_combine(array_slice(array('criteria','only_keys','order_by','extra_cols','wildcard','empty','op','start','filter','join','need_full_no_count'), 0, count(func_get_args())), func_get_args())).')'); |
824 | - if ((int) $this->debug >= 4) echo "<p>so_sql::search(".print_r($criteria,true).",'$only_keys','$order_by',".print_r($extra_cols,true).",'$wildcard','$empty','$op','$start',".print_r($filter,true).",'$join')</p>\n"; |
|
824 | + if ((int)$this->debug >= 4) echo "<p>so_sql::search(".print_r($criteria, true).",'$only_keys','$order_by',".print_r($extra_cols, true).",'$wildcard','$empty','$op','$start',".print_r($filter, true).",'$join')</p>\n"; |
|
825 | 825 | |
826 | 826 | // if extending class or instanciator set columns to search, convert string criteria to array |
827 | 827 | if ($criteria && !is_array($criteria)) |
828 | 828 | { |
829 | - $search = $this->search2criteria($criteria,$wildcard,$op); |
|
829 | + $search = $this->search2criteria($criteria, $wildcard, $op); |
|
830 | 830 | $criteria = array($search); |
831 | 831 | } |
832 | 832 | if (!is_array($criteria)) |
@@ -836,7 +836,7 @@ discard block |
||
836 | 836 | else |
837 | 837 | { |
838 | 838 | $criteria = $this->data2db($criteria); |
839 | - foreach($criteria as $col => $val) |
|
839 | + foreach ($criteria as $col => $val) |
|
840 | 840 | { |
841 | 841 | if (is_int($col)) |
842 | 842 | { |
@@ -844,7 +844,7 @@ discard block |
||
844 | 844 | } |
845 | 845 | elseif ($empty || $val != '') |
846 | 846 | { |
847 | - if (!($db_col = array_search($col,$this->db_cols))) |
|
847 | + if (!($db_col = array_search($col, $this->db_cols))) |
|
848 | 848 | { |
849 | 849 | $db_col = $col; |
850 | 850 | } |
@@ -855,7 +855,7 @@ discard block |
||
855 | 855 | $this->table_def['fd'][$db_col]['nullable'] !== false) |
856 | 856 | { |
857 | 857 | unset($criteria[$col]); |
858 | - $query[] = '(' . $db_col . ' IS NULL OR ' . $db_col . " = '')"; |
|
858 | + $query[] = '('.$db_col.' IS NULL OR '.$db_col." = '')"; |
|
859 | 859 | } |
860 | 860 | else |
861 | 861 | { |
@@ -863,10 +863,10 @@ discard block |
||
863 | 863 | } |
864 | 864 | } |
865 | 865 | elseif ($wildcard || $criteria[$col][0] == '!' || |
866 | - is_string($criteria[$col]) && (strpos($criteria[$col],'*')!==false || strpos($criteria[$col],'?')!==false)) |
|
866 | + is_string($criteria[$col]) && (strpos($criteria[$col], '*') !== false || strpos($criteria[$col], '?') !== false)) |
|
867 | 867 | { |
868 | 868 | // if search pattern alread contains a wildcard, do NOT add further ones automatic |
869 | - if (is_string($criteria[$col]) && (strpos($criteria[$col],'*')!==false || strpos($criteria[$col],'?')!==false)) |
|
869 | + if (is_string($criteria[$col]) && (strpos($criteria[$col], '*') !== false || strpos($criteria[$col], '?') !== false)) |
|
870 | 870 | { |
871 | 871 | $wildcard = ''; |
872 | 872 | } |
@@ -875,19 +875,19 @@ discard block |
||
875 | 875 | if ($criteria[$col][0] == '!') |
876 | 876 | { |
877 | 877 | $cmp_op = ' NOT'.$cmp_op; |
878 | - $criteria[$col] = substr($criteria[$col],1); |
|
878 | + $criteria[$col] = substr($criteria[$col], 1); |
|
879 | 879 | $negate = true; |
880 | 880 | } |
881 | - foreach(explode(' ',$criteria[$col]) as $crit) |
|
881 | + foreach (explode(' ', $criteria[$col]) as $crit) |
|
882 | 882 | { |
883 | 883 | $query[] = ($negate ? ' ('.$db_col.' IS NULL OR ' : '').$db_col.$cmp_op. |
884 | - $this->db->quote($wildcard.str_replace(array('%','_','*','?'),array('\\%','\\_','%','_'),$crit).$wildcard). |
|
884 | + $this->db->quote($wildcard.str_replace(array('%', '_', '*', '?'), array('\\%', '\\_', '%', '_'), $crit).$wildcard). |
|
885 | 885 | ($negate ? ') ' : ''); |
886 | 886 | } |
887 | 887 | } |
888 | - elseif (strpos($db_col,'.') !== false) // we have a table-name specified |
|
888 | + elseif (strpos($db_col, '.') !== false) // we have a table-name specified |
|
889 | 889 | { |
890 | - list($table,$only_col) = explode('.',$db_col); |
|
890 | + list($table, $only_col) = explode('.', $db_col); |
|
891 | 891 | $type = $this->db->get_column_attribute($only_col, $table, true, 'type'); |
892 | 892 | if (empty($type)) |
893 | 893 | { |
@@ -895,15 +895,15 @@ discard block |
||
895 | 895 | } |
896 | 896 | if (is_array($val) && count($val) > 1) |
897 | 897 | { |
898 | - foreach($val as &$v) |
|
898 | + foreach ($val as &$v) |
|
899 | 899 | { |
900 | 900 | $v = $this->db->quote($v, $type); |
901 | 901 | } |
902 | - $query[] = $sql = $db_col.' IN (' .implode(',',$val).')'; |
|
902 | + $query[] = $sql = $db_col.' IN ('.implode(',', $val).')'; |
|
903 | 903 | } |
904 | 904 | else |
905 | 905 | { |
906 | - $query[] = $db_col.'='.$this->db->quote(is_array($val)?array_shift($val):$val,$type); |
|
906 | + $query[] = $db_col.'='.$this->db->quote(is_array($val) ?array_shift($val) : $val, $type); |
|
907 | 907 | } |
908 | 908 | } |
909 | 909 | else |
@@ -912,7 +912,7 @@ discard block |
||
912 | 912 | } |
913 | 913 | } |
914 | 914 | } |
915 | - if (is_array($query) && $op != 'AND') $query = $this->db->column_data_implode(' '.$op.' ',$query); |
|
915 | + if (is_array($query) && $op != 'AND') $query = $this->db->column_data_implode(' '.$op.' ', $query); |
|
916 | 916 | } |
917 | 917 | if (is_array($filter)) |
918 | 918 | { |
@@ -920,19 +920,19 @@ discard block |
||
920 | 920 | $data2db_filter = $this->data2db($filter); |
921 | 921 | if (!is_array($data2db_filter)) { |
922 | 922 | echo function_backtrace()."<br/>\n"; |
923 | - echo "filter=";_debug_array($filter); |
|
924 | - echo "data2db(filter)=";_debug_array($data2db_filter); |
|
923 | + echo "filter="; _debug_array($filter); |
|
924 | + echo "data2db(filter)="; _debug_array($data2db_filter); |
|
925 | 925 | } |
926 | - foreach($data2db_filter as $col => $val) |
|
926 | + foreach ($data2db_filter as $col => $val) |
|
927 | 927 | { |
928 | 928 | if ($val !== '') |
929 | 929 | { |
930 | 930 | // check if a db-internal name conversation necessary |
931 | - if (!is_int($col) && ($c = array_search($col,$this->db_cols))) |
|
931 | + if (!is_int($col) && ($c = array_search($col, $this->db_cols))) |
|
932 | 932 | { |
933 | - $col = $this->table_name . '.' . $c; |
|
933 | + $col = $this->table_name.'.'.$c; |
|
934 | 934 | } |
935 | - if(is_int($col)) |
|
935 | + if (is_int($col)) |
|
936 | 936 | { |
937 | 937 | $db_filter[] = $val; |
938 | 938 | } |
@@ -950,35 +950,35 @@ discard block |
||
950 | 950 | { |
951 | 951 | if ($op != 'AND') |
952 | 952 | { |
953 | - $db_filter[] = '('.$this->db->column_data_implode(' '.$op.' ',$query).')'; |
|
953 | + $db_filter[] = '('.$this->db->column_data_implode(' '.$op.' ', $query).')'; |
|
954 | 954 | } |
955 | 955 | else |
956 | 956 | { |
957 | - $db_filter = array_merge($db_filter,$query); |
|
957 | + $db_filter = array_merge($db_filter, $query); |
|
958 | 958 | } |
959 | 959 | } |
960 | 960 | $query = $db_filter; |
961 | 961 | } |
962 | - if ((int) $this->debug >= 4) |
|
962 | + if ((int)$this->debug >= 4) |
|
963 | 963 | { |
964 | - echo "<p>so_sql::search(,only_keys=$only_keys,order_by='$order_by',wildcard='$wildcard',empty=$empty,$op,start='$start',".print_r($filter,true).") query=".print_r($query,true).", total='$this->total'</p>\n"; |
|
964 | + echo "<p>so_sql::search(,only_keys=$only_keys,order_by='$order_by',wildcard='$wildcard',empty=$empty,$op,start='$start',".print_r($filter, true).") query=".print_r($query, true).", total='$this->total'</p>\n"; |
|
965 | 965 | echo "<br>criteria = "; _debug_array($criteria); |
966 | 966 | } |
967 | 967 | if ($only_keys === true) |
968 | 968 | { |
969 | 969 | $colums = array_keys($this->db_key_cols); |
970 | - foreach($colums as &$column) |
|
970 | + foreach ($colums as &$column) |
|
971 | 971 | { |
972 | - $column = $this->table_name . '.' . $column; |
|
972 | + $column = $this->table_name.'.'.$column; |
|
973 | 973 | } |
974 | 974 | } |
975 | 975 | elseif (is_array($only_keys)) |
976 | 976 | { |
977 | 977 | $colums = array(); |
978 | - foreach($only_keys as $key => $col) |
|
978 | + foreach ($only_keys as $key => $col) |
|
979 | 979 | { |
980 | 980 | //Convert ambiguous columns to prefixed tablename.column name |
981 | - $colums[] = ($db_col = array_search($col,$this->db_cols)) ? $this->table_name .'.'.$db_col.' AS '.$col :$col; |
|
981 | + $colums[] = ($db_col = array_search($col, $this->db_cols)) ? $this->table_name.'.'.$db_col.' AS '.$col : $col; |
|
982 | 982 | } |
983 | 983 | } |
984 | 984 | elseif (!$only_keys) |
@@ -1008,20 +1008,20 @@ discard block |
||
1008 | 1008 | { |
1009 | 1009 | $colums[$key] = $this->table_name.'.'.$this->autoinc_id.' AS '.$this->autoinc_id; |
1010 | 1010 | } |
1011 | - elseif (!is_array($colums) && strpos($colums,$this->autoinc_id) !== false) |
|
1011 | + elseif (!is_array($colums) && strpos($colums, $this->autoinc_id) !== false) |
|
1012 | 1012 | { |
1013 | - $colums = preg_replace('/(?<! AS)([ ,]+)'.preg_quote($this->autoinc_id).'([ ,]+)/','\\1'.$this->table_name.'.'.$this->autoinc_id.' AS '.$this->autoinc_id.'\\2',$colums); |
|
1013 | + $colums = preg_replace('/(?<! AS)([ ,]+)'.preg_quote($this->autoinc_id).'([ ,]+)/', '\\1'.$this->table_name.'.'.$this->autoinc_id.' AS '.$this->autoinc_id.'\\2', $colums); |
|
1014 | 1014 | } |
1015 | 1015 | } |
1016 | - $num_rows = 0; // as spec. in max_matches in the user-prefs |
|
1017 | - if (is_array($start)) list($start,$num_rows) = $start; |
|
1016 | + $num_rows = 0; // as spec. in max_matches in the user-prefs |
|
1017 | + if (is_array($start)) list($start, $num_rows) = $start; |
|
1018 | 1018 | |
1019 | 1019 | // fix GROUP BY clause to contain all non-aggregate selected columns |
1020 | - if ($order_by && stripos($order_by,'GROUP BY') !== false) |
|
1020 | + if ($order_by && stripos($order_by, 'GROUP BY') !== false) |
|
1021 | 1021 | { |
1022 | 1022 | $order_by = $this->fix_group_by_columns($order_by, $colums, $this->table_name, $this->autoinc_id); |
1023 | 1023 | } |
1024 | - elseif ($order_by && stripos($order_by,'ORDER BY')===false && stripos($order_by,'GROUP BY')===false && stripos($order_by,'HAVING')===false) |
|
1024 | + elseif ($order_by && stripos($order_by, 'ORDER BY') === false && stripos($order_by, 'GROUP BY') === false && stripos($order_by, 'HAVING') === false) |
|
1025 | 1025 | { |
1026 | 1026 | $order_by = 'ORDER BY '.$order_by; |
1027 | 1027 | } |
@@ -1044,9 +1044,9 @@ discard block |
||
1044 | 1044 | ); |
1045 | 1045 | if (!$union_cols) // union used the colum-names of the first query |
1046 | 1046 | { |
1047 | - $union_cols = $this->_get_columns($only_keys,$extra_cols); |
|
1047 | + $union_cols = $this->_get_columns($only_keys, $extra_cols); |
|
1048 | 1048 | } |
1049 | - return true; // waiting for further calls, before running the union-query |
|
1049 | + return true; // waiting for further calls, before running the union-query |
|
1050 | 1050 | } |
1051 | 1051 | // running the union query now |
1052 | 1052 | if ($start !== false) // need to get the total too, saved in $this->total |
@@ -1057,10 +1057,10 @@ discard block |
||
1057 | 1057 | } |
1058 | 1058 | else // cant do a count, have to run the query without limit |
1059 | 1059 | { |
1060 | - $this->total = $this->db->union($union,__LINE__,__FILE__)->NumRows(); |
|
1060 | + $this->total = $this->db->union($union, __LINE__, __FILE__)->NumRows(); |
|
1061 | 1061 | } |
1062 | 1062 | } |
1063 | - $rs = $this->db->union($union,__LINE__,__FILE__,$order_by,$start,$num_rows); |
|
1063 | + $rs = $this->db->union($union, __LINE__, __FILE__, $order_by, $start, $num_rows); |
|
1064 | 1064 | if ($this->debug) error_log(__METHOD__."() ".$this->db->Query_ID->sql); |
1065 | 1065 | |
1066 | 1066 | $cols = $union_cols; |
@@ -1074,21 +1074,21 @@ discard block |
||
1074 | 1074 | { |
1075 | 1075 | $mysql_calc_rows = 'SQL_CALC_FOUND_ROWS '; |
1076 | 1076 | } |
1077 | - elseif (!$need_full_no_count && (!$join || stripos($join,'LEFT JOIN')!==false)) |
|
1077 | + elseif (!$need_full_no_count && (!$join || stripos($join, 'LEFT JOIN') !== false)) |
|
1078 | 1078 | { |
1079 | - $this->total = $this->db->select($this->table_name,'COUNT(*)',$query,__LINE__,__FILE__,false,'',$this->app,0,$join)->fetchColumn(); |
|
1079 | + $this->total = $this->db->select($this->table_name, 'COUNT(*)', $query, __LINE__, __FILE__, false, '', $this->app, 0, $join)->fetchColumn(); |
|
1080 | 1080 | } |
1081 | 1081 | else // cant do a count, have to run the query without limit |
1082 | 1082 | { |
1083 | - $this->total = $this->db->select($this->table_name,$colums,$query,__LINE__,__FILE__,false,$order_by,false,0,$join)->NumRows(); |
|
1083 | + $this->total = $this->db->select($this->table_name, $colums, $query, __LINE__, __FILE__, false, $order_by, false, 0, $join)->NumRows(); |
|
1084 | 1084 | } |
1085 | 1085 | } |
1086 | - $rs = $this->db->select($this->table_name,$mysql_calc_rows.$colums,$query,__LINE__,__FILE__, |
|
1087 | - $start,$order_by,$this->app,$num_rows,$join); |
|
1086 | + $rs = $this->db->select($this->table_name, $mysql_calc_rows.$colums, $query, __LINE__, __FILE__, |
|
1087 | + $start, $order_by, $this->app, $num_rows, $join); |
|
1088 | 1088 | if ($this->debug) error_log(__METHOD__."() ".$this->db->Query_ID->sql); |
1089 | - $cols = $this->_get_columns($only_keys,$extra_cols); |
|
1089 | + $cols = $this->_get_columns($only_keys, $extra_cols); |
|
1090 | 1090 | } |
1091 | - if ((int) $this->debug >= 4) echo "<p>sql='{$this->db->Query_ID->sql}'</p>\n"; |
|
1091 | + if ((int)$this->debug >= 4) echo "<p>sql='{$this->db->Query_ID->sql}'</p>\n"; |
|
1092 | 1092 | |
1093 | 1093 | if ($mysql_calc_rows) |
1094 | 1094 | { |
@@ -1097,14 +1097,14 @@ discard block |
||
1097 | 1097 | // ToDo: Implement that as an iterator, as $rs is also an interator and we could return one instead of an array |
1098 | 1098 | if ($this->search_return_iterator) |
1099 | 1099 | { |
1100 | - return new Db2DataIterator($this,$rs); |
|
1100 | + return new Db2DataIterator($this, $rs); |
|
1101 | 1101 | } |
1102 | 1102 | $arr = array(); |
1103 | 1103 | $n = 0; |
1104 | - if ($rs) foreach($rs as $row) |
|
1104 | + if ($rs) foreach ($rs as $row) |
|
1105 | 1105 | { |
1106 | 1106 | $data = array(); |
1107 | - foreach($cols as $db_col => $col) |
|
1107 | + foreach ($cols as $db_col => $col) |
|
1108 | 1108 | { |
1109 | 1109 | $data[$col] = (isset($row[$db_col]) ? $row[$db_col] : $row[$col]); |
1110 | 1110 | } |
@@ -1134,7 +1134,7 @@ discard block |
||
1134 | 1134 | $matches = null; |
1135 | 1135 | if (substr($GLOBALS['egw']->db->Type, 0, 5) == 'mysql' || !preg_match('/(GROUP BY .*)(HAVING.*|ORDER BY.*)?$/iU', $group_by, $matches)) |
1136 | 1136 | { |
1137 | - return $group_by; // nothing to do |
|
1137 | + return $group_by; // nothing to do |
|
1138 | 1138 | } |
1139 | 1139 | $changes = 0; |
1140 | 1140 | $group_by_cols = preg_split('/, */', trim(substr($matches[1], 9))); |
@@ -1144,9 +1144,9 @@ discard block |
||
1144 | 1144 | $columns = preg_split('/, */', $columns); |
1145 | 1145 | |
1146 | 1146 | // fix columns containing commas as part of function calls |
1147 | - for($n = 0; $n < count($columns); ++$n) |
|
1147 | + for ($n = 0; $n < count($columns); ++$n) |
|
1148 | 1148 | { |
1149 | - $col =& $columns[$n]; |
|
1149 | + $col = & $columns[$n]; |
|
1150 | 1150 | while (substr_count($col, '(') > substr_count($col, ')') && ++$n < count($columns)) |
1151 | 1151 | { |
1152 | 1152 | $col .= ','.$columns[$n]; |
@@ -1155,7 +1155,7 @@ discard block |
||
1155 | 1155 | } |
1156 | 1156 | unset($col); |
1157 | 1157 | } |
1158 | - foreach($columns as $n => $col) |
|
1158 | + foreach ($columns as $n => $col) |
|
1159 | 1159 | { |
1160 | 1160 | if ($col == '*') |
1161 | 1161 | { |
@@ -1168,7 +1168,7 @@ discard block |
||
1168 | 1168 | { |
1169 | 1169 | if (($pos = stripos($col, 'DISTINCT ')) !== false) |
1170 | 1170 | { |
1171 | - $col = substr($col, $pos+9); |
|
1171 | + $col = substr($col, $pos + 9); |
|
1172 | 1172 | } |
1173 | 1173 | $alias = $col; |
1174 | 1174 | if (stripos($col, ' AS ')) list($col, $alias) = preg_split('/ +AS +/i', $col); |
@@ -1186,7 +1186,7 @@ discard block |
||
1186 | 1186 | $ret = $group_by; |
1187 | 1187 | if ($changes) |
1188 | 1188 | { |
1189 | - $ret = str_replace($matches[1], 'GROUP BY '.implode(',', $group_by_cols).' ', $group_by); |
|
1189 | + $ret = str_replace($matches[1], 'GROUP BY '.implode(',', $group_by_cols).' ', $group_by); |
|
1190 | 1190 | //error_log(__METHOD__."('$group_by', ".array2string($columns).") group_by_cols=".array2string($group_by_cols)." changed to $ret"); |
1191 | 1191 | } |
1192 | 1192 | return $ret; |
@@ -1206,12 +1206,12 @@ discard block |
||
1206 | 1206 | * @param array $search_cols =array() List of columns to search. If not provided, all columns in $this->db_cols will be considered |
1207 | 1207 | * @return array or column => value pairs |
1208 | 1208 | */ |
1209 | - public function search2criteria($_pattern,&$wildcard='',&$op='AND',$extra_col=null, $search_cols = array()) |
|
1209 | + public function search2criteria($_pattern, &$wildcard = '', &$op = 'AND', $extra_col = null, $search_cols = array()) |
|
1210 | 1210 | { |
1211 | 1211 | $pattern = trim($_pattern); |
1212 | 1212 | // This function can get called multiple times. Make sure it doesn't re-process. |
1213 | 1213 | if (empty($pattern) || is_array($pattern)) return $pattern; |
1214 | - if(strpos($pattern, 'CAST(COALESCE(') !== false) |
|
1214 | + if (strpos($pattern, 'CAST(COALESCE(') !== false) |
|
1215 | 1215 | { |
1216 | 1216 | return $pattern; |
1217 | 1217 | } |
@@ -1228,24 +1228,24 @@ discard block |
||
1228 | 1228 | $numeric_columns = array(); |
1229 | 1229 | |
1230 | 1230 | // Special handling for an ID search, #<int> |
1231 | - if(strpos($_pattern, '#') === 0 && is_numeric(substr($_pattern, 1))) |
|
1231 | + if (strpos($_pattern, '#') === 0 && is_numeric(substr($_pattern, 1))) |
|
1232 | 1232 | { |
1233 | - return array('(' . $this->table_name.'.'. $this->autoinc_id . '=' . (int)substr($_pattern,1) . ')'); |
|
1233 | + return array('('.$this->table_name.'.'.$this->autoinc_id.'='.(int)substr($_pattern, 1).')'); |
|
1234 | 1234 | } |
1235 | - if(!$search_cols) |
|
1235 | + if (!$search_cols) |
|
1236 | 1236 | { |
1237 | 1237 | $search_cols = $this->get_default_search_columns(); |
1238 | 1238 | } |
1239 | 1239 | // Concat all fields to be searched together, so the conditions operate across the whole record |
1240 | - foreach($search_cols as $col) |
|
1240 | + foreach ($search_cols as $col) |
|
1241 | 1241 | { |
1242 | 1242 | $col_name = $col; |
1243 | 1243 | $table = $this->table_name; |
1244 | - if (strpos($col,'.') !== false) |
|
1244 | + if (strpos($col, '.') !== false) |
|
1245 | 1245 | { |
1246 | - list($table,$col_name) = explode('.',$col); |
|
1246 | + list($table, $col_name) = explode('.', $col); |
|
1247 | 1247 | } |
1248 | - $table_def = $table == $this->table_name ? $this->table_def : $this->db->get_table_definitions(true,$table); |
|
1248 | + $table_def = $table == $this->table_name ? $this->table_def : $this->db->get_table_definitions(true, $table); |
|
1249 | 1249 | if ($table_def['fd'][$col_name] && in_array($table_def['fd'][$col_name]['type'], $numeric_types)) |
1250 | 1250 | { |
1251 | 1251 | $numeric_columns[] = $col; |
@@ -1253,11 +1253,11 @@ discard block |
||
1253 | 1253 | } |
1254 | 1254 | if ($this->db->Type == 'mysql' && $table_def['fd'][$col_name]['type'] === 'ascii' && preg_match('/[\x80-\xFF]/', $_pattern)) |
1255 | 1255 | { |
1256 | - continue; // will only give sql error |
|
1256 | + continue; // will only give sql error |
|
1257 | 1257 | } |
1258 | - $columns[] = sprintf($this->db->capabilities[Api\Db::CAPABILITY_CAST_AS_VARCHAR],"COALESCE($col,'')"); |
|
1258 | + $columns[] = sprintf($this->db->capabilities[Api\Db::CAPABILITY_CAST_AS_VARCHAR], "COALESCE($col,'')"); |
|
1259 | 1259 | } |
1260 | - if(!$columns) |
|
1260 | + if (!$columns) |
|
1261 | 1261 | { |
1262 | 1262 | return array(); |
1263 | 1263 | } |
@@ -1266,9 +1266,9 @@ discard block |
||
1266 | 1266 | $break = ' '; |
1267 | 1267 | $token = strtok($pattern, $break); |
1268 | 1268 | |
1269 | - while($token) |
|
1269 | + while ($token) |
|
1270 | 1270 | { |
1271 | - if($token == strtoupper(lang('AND')) || $token == 'AND') |
|
1271 | + if ($token == strtoupper(lang('AND')) || $token == 'AND') |
|
1272 | 1272 | { |
1273 | 1273 | $token = '+'.strtok($break); |
1274 | 1274 | } |
@@ -1281,10 +1281,10 @@ discard block |
||
1281 | 1281 | { |
1282 | 1282 | $token = '-'.strtok($break); |
1283 | 1283 | } |
1284 | - if ($token[0]=='"') |
|
1284 | + if ($token[0] == '"') |
|
1285 | 1285 | { |
1286 | - $token = substr($token, 1,strlen($token)); |
|
1287 | - if(substr($token, -1) != '"') |
|
1286 | + $token = substr($token, 1, strlen($token)); |
|
1287 | + if (substr($token, -1) != '"') |
|
1288 | 1288 | { |
1289 | 1289 | $token .= ' '.strtok('"'); |
1290 | 1290 | } |
@@ -1295,16 +1295,16 @@ discard block |
||
1295 | 1295 | } |
1296 | 1296 | |
1297 | 1297 | // prepend and append extra wildcard %, if pattern does NOT already contain wildcards |
1298 | - if (strpos($token,'*') === false && strpos($token,'?') === false) |
|
1298 | + if (strpos($token, '*') === false && strpos($token, '?') === false) |
|
1299 | 1299 | { |
1300 | - $wildcard = '%'; // if pattern contains no wildcards, add them before AND after the pattern |
|
1300 | + $wildcard = '%'; // if pattern contains no wildcards, add them before AND after the pattern |
|
1301 | 1301 | } |
1302 | 1302 | else |
1303 | 1303 | { |
1304 | - $wildcard = ''; // no extra wildcard, if pattern already contains some |
|
1304 | + $wildcard = ''; // no extra wildcard, if pattern already contains some |
|
1305 | 1305 | } |
1306 | 1306 | |
1307 | - switch($token[0]) |
|
1307 | + switch ($token[0]) |
|
1308 | 1308 | { |
1309 | 1309 | case '+': |
1310 | 1310 | $op = 'AND'; |
@@ -1319,32 +1319,32 @@ discard block |
||
1319 | 1319 | $op = 'OR'; |
1320 | 1320 | break; |
1321 | 1321 | } |
1322 | - $token_filter = ' '.call_user_func_array(array($GLOBALS['egw']->db,'concat'),$columns).' '. |
|
1323 | - $this->db->capabilities['case_insensitive_like'] . ' ' . |
|
1324 | - $GLOBALS['egw']->db->quote($wildcard.str_replace(array('%','_','*','?'),array('\\%','\\_','%','_'),$token).$wildcard); |
|
1322 | + $token_filter = ' '.call_user_func_array(array($GLOBALS['egw']->db, 'concat'), $columns).' '. |
|
1323 | + $this->db->capabilities['case_insensitive_like'].' '. |
|
1324 | + $GLOBALS['egw']->db->quote($wildcard.str_replace(array('%', '_', '*', '?'), array('\\%', '\\_', '%', '_'), $token).$wildcard); |
|
1325 | 1325 | |
1326 | 1326 | // Compare numeric token as equality for numeric columns |
1327 | 1327 | // skip user-wildcards (*,?) in is_numeric test, but not SQL wildcards, which get escaped and give sql-error |
1328 | - if (is_numeric(str_replace(array('*','?'), '', $token))) |
|
1328 | + if (is_numeric(str_replace(array('*', '?'), '', $token))) |
|
1329 | 1329 | { |
1330 | 1330 | $numeric_filter = array(); |
1331 | - foreach($numeric_columns as $col) |
|
1331 | + foreach ($numeric_columns as $col) |
|
1332 | 1332 | { |
1333 | - if($wildcard == '') |
|
1333 | + if ($wildcard == '') |
|
1334 | 1334 | { |
1335 | 1335 | // Token has a wildcard from user, use LIKE |
1336 | - $numeric_filter[] = "($col IS NOT NULL AND CAST($col AS CHAR) " . |
|
1337 | - $this->db->capabilities['case_insensitive_like'] . ' ' . |
|
1338 | - $GLOBALS['egw']->db->quote(str_replace(array('*','?'), array('%','_'), $token)) . ')'; |
|
1336 | + $numeric_filter[] = "($col IS NOT NULL AND CAST($col AS CHAR) ". |
|
1337 | + $this->db->capabilities['case_insensitive_like'].' '. |
|
1338 | + $GLOBALS['egw']->db->quote(str_replace(array('*', '?'), array('%', '_'), $token)).')'; |
|
1339 | 1339 | } |
1340 | 1340 | else |
1341 | 1341 | { |
1342 | 1342 | $numeric_filter[] = "($col IS NOT NULL AND $col = $token)"; |
1343 | 1343 | } |
1344 | 1344 | } |
1345 | - if(count($numeric_filter) > 0) |
|
1345 | + if (count($numeric_filter) > 0) |
|
1346 | 1346 | { |
1347 | - $token_filter = '(' . $token_filter . ' OR ' . implode(' OR ', $numeric_filter) . ')'; |
|
1347 | + $token_filter = '('.$token_filter.' OR '.implode(' OR ', $numeric_filter).')'; |
|
1348 | 1348 | } |
1349 | 1349 | } |
1350 | 1350 | $criteria[$op][] = $token_filter; |
@@ -1352,32 +1352,32 @@ discard block |
||
1352 | 1352 | $token = strtok($break); |
1353 | 1353 | } |
1354 | 1354 | |
1355 | - if($criteria['NOT']) |
|
1355 | + if ($criteria['NOT']) |
|
1356 | 1356 | { |
1357 | - $filter[] = 'NOT (' . implode(' OR ', $criteria['NOT']) . ') '; |
|
1357 | + $filter[] = 'NOT ('.implode(' OR ', $criteria['NOT']).') '; |
|
1358 | 1358 | } |
1359 | - if($criteria['AND']) |
|
1359 | + if ($criteria['AND']) |
|
1360 | 1360 | { |
1361 | - $filter[] = implode(' AND ', $criteria['AND']) . ' '; |
|
1361 | + $filter[] = implode(' AND ', $criteria['AND']).' '; |
|
1362 | 1362 | } |
1363 | - if($criteria['OR']) |
|
1363 | + if ($criteria['OR']) |
|
1364 | 1364 | { |
1365 | - $filter[] = '(' . implode(' OR ', $criteria['OR']) . ') '; |
|
1365 | + $filter[] = '('.implode(' OR ', $criteria['OR']).') '; |
|
1366 | 1366 | } |
1367 | 1367 | |
1368 | - if(count($filter)) |
|
1368 | + if (count($filter)) |
|
1369 | 1369 | { |
1370 | - $result = '(' . implode(' AND ', $filter) . ')'; |
|
1370 | + $result = '('.implode(' AND ', $filter).')'; |
|
1371 | 1371 | } |
1372 | 1372 | |
1373 | 1373 | // OR extra column on the end so a null or blank won't block a hit in the main columns |
1374 | 1374 | if ($extra_col) |
1375 | 1375 | { |
1376 | - $result .= (strlen($result) ? ' OR ' : ' ') . "$extra_col = " . $GLOBALS['egw']->db->quote($pattern); |
|
1376 | + $result .= (strlen($result) ? ' OR ' : ' ')."$extra_col = ".$GLOBALS['egw']->db->quote($pattern); |
|
1377 | 1377 | } |
1378 | 1378 | |
1379 | 1379 | $op = 'OR'; |
1380 | - return array('(' . $result . ')'); |
|
1380 | + return array('('.$result.')'); |
|
1381 | 1381 | } |
1382 | 1382 | |
1383 | 1383 | /** |
@@ -1396,21 +1396,21 @@ discard block |
||
1396 | 1396 | $numeric_types = array('auto', 'int', 'float', 'double'); |
1397 | 1397 | |
1398 | 1398 | // Skip some numeric columns that don't make sense to search if we have to default to all columns |
1399 | - if(is_null($this->columns_to_search)) |
|
1399 | + if (is_null($this->columns_to_search)) |
|
1400 | 1400 | { |
1401 | - foreach($search_cols as $key => &$col) |
|
1401 | + foreach ($search_cols as $key => &$col) |
|
1402 | 1402 | { |
1403 | 1403 | // If the name as given isn't a real column name, and adding the prefix doesn't help, skip it |
1404 | - if(!$this->table_def['fd'][$col] && !($col = $this->prefix.array_search($col, $search_cols))) { |
|
1404 | + if (!$this->table_def['fd'][$col] && !($col = $this->prefix.array_search($col, $search_cols))) { |
|
1405 | 1405 | // Can't search this column |
1406 | 1406 | unset($search_cols[$key]); |
1407 | 1407 | continue; |
1408 | 1408 | } |
1409 | - if(in_array($this->table_def['fd'][$col]['type'], $numeric_types)) |
|
1409 | + if (in_array($this->table_def['fd'][$col]['type'], $numeric_types)) |
|
1410 | 1410 | { |
1411 | - foreach($skip_columns_with as $bad) |
|
1411 | + foreach ($skip_columns_with as $bad) |
|
1412 | 1412 | { |
1413 | - if(strpos($col, $bad) !== false) |
|
1413 | + if (strpos($col, $bad) !== false) |
|
1414 | 1414 | { |
1415 | 1415 | unset($search_cols[$key]); |
1416 | 1416 | continue 2; |
@@ -1432,7 +1432,7 @@ discard block |
||
1432 | 1432 | * @param string|array $extra_cols ='' string or array of strings to be added to the SELECT, eg. "count(*) as num" |
1433 | 1433 | * @return array with columns as db-name => internal-name pairs |
1434 | 1434 | */ |
1435 | - function _get_columns($only_keys,$extra_cols) |
|
1435 | + function _get_columns($only_keys, $extra_cols) |
|
1436 | 1436 | { |
1437 | 1437 | //echo "_get_columns() only_keys="; _debug_array($only_keys); echo "extra_cols="; _debug_array($extra_cols); |
1438 | 1438 | if ($only_keys === true) // only primary key |
@@ -1443,7 +1443,7 @@ discard block |
||
1443 | 1443 | { |
1444 | 1444 | $cols = array(); |
1445 | 1445 | $distinct_checked = false; |
1446 | - foreach(is_array($only_keys) ? $only_keys : explode(',', $only_keys) as $col) |
|
1446 | + foreach (is_array($only_keys) ? $only_keys : explode(',', $only_keys) as $col) |
|
1447 | 1447 | { |
1448 | 1448 | if (!$distinct_checked) |
1449 | 1449 | { |
@@ -1452,17 +1452,17 @@ discard block |
||
1452 | 1452 | } |
1453 | 1453 | if (!$col || $col == '*' || $col == $this->table_name.'.*') // all columns |
1454 | 1454 | { |
1455 | - $cols = array_merge($cols,$this->db_cols); |
|
1455 | + $cols = array_merge($cols, $this->db_cols); |
|
1456 | 1456 | } |
1457 | 1457 | else // only the specified columns |
1458 | 1458 | { |
1459 | - if (stripos($col,'as')) // if there's already an explicit naming of the column, just use it |
|
1459 | + if (stripos($col, 'as')) // if there's already an explicit naming of the column, just use it |
|
1460 | 1460 | { |
1461 | - $col = preg_replace('/^.*as +([a-z0-9_]+) *$/i','\\1',$col); |
|
1461 | + $col = preg_replace('/^.*as +([a-z0-9_]+) *$/i', '\\1', $col); |
|
1462 | 1462 | $cols[$col] = $col; |
1463 | 1463 | continue; |
1464 | 1464 | } |
1465 | - if (($db_col = array_search($col,$this->db_cols)) !== false) |
|
1465 | + if (($db_col = array_search($col, $this->db_cols)) !== false) |
|
1466 | 1466 | { |
1467 | 1467 | $cols[$db_col] = $col; |
1468 | 1468 | } |
@@ -1475,10 +1475,10 @@ discard block |
||
1475 | 1475 | } |
1476 | 1476 | if ($extra_cols) // extra columns to report |
1477 | 1477 | { |
1478 | - foreach(is_array($extra_cols) ? $extra_cols : explode(',',$extra_cols) as $col) |
|
1478 | + foreach (is_array($extra_cols) ? $extra_cols : explode(',', $extra_cols) as $col) |
|
1479 | 1479 | { |
1480 | - if (stripos($col,'as ')!==false) $col = preg_replace('/^.*as +([a-z0-9_]+) *$/i','\\1',$col); |
|
1481 | - if (($db_col = array_search($col,$this->db_cols)) !== false) |
|
1480 | + if (stripos($col, 'as ') !== false) $col = preg_replace('/^.*as +([a-z0-9_]+) *$/i', '\\1', $col); |
|
1481 | + if (($db_col = array_search($col, $this->db_cols)) !== false) |
|
1482 | 1482 | { |
1483 | 1483 | $cols[$db_col] = $col; |
1484 | 1484 | } |
@@ -1505,12 +1505,12 @@ discard block |
||
1505 | 1505 | * @param string|array $extra_cols =array() |
1506 | 1506 | * @return int total number of rows |
1507 | 1507 | */ |
1508 | - function get_rows($query,&$rows,&$readonlys,$join='',$need_full_no_count=false,$only_keys=false,$extra_cols=array()) |
|
1508 | + function get_rows($query, &$rows, &$readonlys, $join = '', $need_full_no_count = false, $only_keys = false, $extra_cols = array()) |
|
1509 | 1509 | { |
1510 | - unset($readonlys); // required by function signature, but not used in this default implementation |
|
1511 | - if ((int) $this->debug >= 4) |
|
1510 | + unset($readonlys); // required by function signature, but not used in this default implementation |
|
1511 | + if ((int)$this->debug >= 4) |
|
1512 | 1512 | { |
1513 | - echo "<p>so_sql::get_rows(".print_r($query,true).",,)</p>\n"; |
|
1513 | + echo "<p>so_sql::get_rows(".print_r($query, true).",,)</p>\n"; |
|
1514 | 1514 | } |
1515 | 1515 | $criteria = array(); |
1516 | 1516 | $op = 'AND'; |
@@ -1518,11 +1518,11 @@ discard block |
||
1518 | 1518 | { |
1519 | 1519 | $criteria = $query['search']; |
1520 | 1520 | } |
1521 | - $rows = $this->search($criteria,$only_keys,$query['order']?$query['order'].' '.$query['sort']:'',$extra_cols, |
|
1522 | - '',false,$op,$query['num_rows']?array((int)$query['start'],$query['num_rows']):(int)$query['start'], |
|
1523 | - $query['col_filter'],$join,$need_full_no_count); |
|
1521 | + $rows = $this->search($criteria, $only_keys, $query['order'] ? $query['order'].' '.$query['sort'] : '', $extra_cols, |
|
1522 | + '', false, $op, $query['num_rows'] ? array((int)$query['start'], $query['num_rows']) : (int)$query['start'], |
|
1523 | + $query['col_filter'], $join, $need_full_no_count); |
|
1524 | 1524 | |
1525 | - if (!$rows) $rows = array(); // otherwise false returned from search would be returned as array(false) |
|
1525 | + if (!$rows) $rows = array(); // otherwise false returned from search would be returned as array(false) |
|
1526 | 1526 | |
1527 | 1527 | return $this->total; |
1528 | 1528 | } |
@@ -1533,7 +1533,7 @@ discard block |
||
1533 | 1533 | * @param array $data =null data-set to check, defaults to $this->data |
1534 | 1534 | * @return int 0: all keys are unique, 1: first key not unique, 2: ... |
1535 | 1535 | */ |
1536 | - function not_unique($data=null) |
|
1536 | + function not_unique($data = null) |
|
1537 | 1537 | { |
1538 | 1538 | if (!is_array($data)) |
1539 | 1539 | { |
@@ -1546,12 +1546,12 @@ discard block |
||
1546 | 1546 | { |
1547 | 1547 | $uni_keys[] = $this->db_key_cols; |
1548 | 1548 | } |
1549 | - foreach($uni_keys as $db_col => $col) |
|
1549 | + foreach ($uni_keys as $db_col => $col) |
|
1550 | 1550 | { |
1551 | 1551 | if (is_array($col)) |
1552 | 1552 | { |
1553 | 1553 | $query = array(); |
1554 | - foreach($col as $db_c => $c) |
|
1554 | + foreach ($col as $db_c => $c) |
|
1555 | 1555 | { |
1556 | 1556 | $query[$db_c] = $data[$c]; |
1557 | 1557 | } |
@@ -1560,17 +1560,17 @@ discard block |
||
1560 | 1560 | { |
1561 | 1561 | $query = array($db_col => $data[$col]); |
1562 | 1562 | } |
1563 | - foreach($this->db->select($this->table_name,$this->db_key_cols,$query,__LINE__,__FILE__,false,'',$this->app) as $other) |
|
1563 | + foreach ($this->db->select($this->table_name, $this->db_key_cols, $query, __LINE__, __FILE__, false, '', $this->app) as $other) |
|
1564 | 1564 | { |
1565 | - foreach($this->db_key_cols as $key_col) |
|
1565 | + foreach ($this->db_key_cols as $key_col) |
|
1566 | 1566 | { |
1567 | 1567 | if ($data[$key_col] != $other[$key_col]) |
1568 | 1568 | { |
1569 | - if ((int) $this->debug >= 4) |
|
1569 | + if ((int)$this->debug >= 4) |
|
1570 | 1570 | { |
1571 | 1571 | echo "<p>not_unique in ".array2string($col)." as for '$key_col': '${data[$key_col]}' != '${other[$key_col]}'</p>\n"; |
1572 | 1572 | } |
1573 | - return $n; // different entry => $n not unique |
|
1573 | + return $n; // different entry => $n not unique |
|
1574 | 1574 | } |
1575 | 1575 | } |
1576 | 1576 | } |
@@ -1591,7 +1591,7 @@ discard block |
||
1591 | 1591 | * @param string $order ='' order, default '' = same as (first) $value_col |
1592 | 1592 | * @return array with key_col => value_col pairs or array if more then one value_col given (keys as in value_col) |
1593 | 1593 | */ |
1594 | - function query_list($value_col,$key_col='',$filter=array(),$order='') |
|
1594 | + function query_list($value_col, $key_col = '', $filter = array(), $order = '') |
|
1595 | 1595 | { |
1596 | 1596 | static $cache = array(); |
1597 | 1597 | |
@@ -1604,16 +1604,16 @@ discard block |
||
1604 | 1604 | if (!is_array($value_col)) $value_col = array($value_col); |
1605 | 1605 | |
1606 | 1606 | $cols = $ret = array(); |
1607 | - foreach($value_col as $key => $col) |
|
1607 | + foreach ($value_col as $key => $col) |
|
1608 | 1608 | { |
1609 | 1609 | $matches = null; |
1610 | - $cols[$key] = preg_match('/AS ([a-z_0-9]+)$/i',$col,$matches) ? $matches[1] : $col; |
|
1610 | + $cols[$key] = preg_match('/AS ([a-z_0-9]+)$/i', $col, $matches) ? $matches[1] : $col; |
|
1611 | 1611 | } |
1612 | 1612 | if (!$order) $order = current($cols); |
1613 | 1613 | |
1614 | - if (($search =& $this->search(array(),($key_col ? $key_col.',' : 'DISTINCT ').implode(',',$value_col),$order,'','',false,'AND',false,$filter))) |
|
1614 | + if (($search = & $this->search(array(), ($key_col ? $key_col.',' : 'DISTINCT ').implode(',', $value_col), $order, '', '', false, 'AND', false, $filter))) |
|
1615 | 1615 | { |
1616 | - if (preg_match('/AS ([a-z_0-9]+)$/i',$key_col,$matches)) |
|
1616 | + if (preg_match('/AS ([a-z_0-9]+)$/i', $key_col, $matches)) |
|
1617 | 1617 | { |
1618 | 1618 | $key_col = $matches[1]; |
1619 | 1619 | } |
@@ -1621,12 +1621,12 @@ discard block |
||
1621 | 1621 | { |
1622 | 1622 | $key_col = current($cols); |
1623 | 1623 | } |
1624 | - foreach($search as $row) |
|
1624 | + foreach ($search as $row) |
|
1625 | 1625 | { |
1626 | 1626 | if (count($cols) > 1) |
1627 | 1627 | { |
1628 | 1628 | $data = array(); |
1629 | - foreach($cols as $key => $col) |
|
1629 | + foreach ($cols as $key => $col) |
|
1630 | 1630 | { |
1631 | 1631 | $data[$key] = $row[$col]; |
1632 | 1632 | } |
@@ -1638,7 +1638,7 @@ discard block |
||
1638 | 1638 | if ($data) $ret[$row[$key_col]] = $data; |
1639 | 1639 | } |
1640 | 1640 | } |
1641 | - return $cache[$cache_key] =& $ret; |
|
1641 | + return $cache[$cache_key] = & $ret; |
|
1642 | 1642 | } |
1643 | 1643 | |
1644 | 1644 | /** |
@@ -1647,13 +1647,13 @@ discard block |
||
1647 | 1647 | * @param string $column =null name of column or null for all (default) |
1648 | 1648 | * @return array|string array with internal-name => comment pairs, or string with comment, if $column given |
1649 | 1649 | */ |
1650 | - public function get_comments($column=null) |
|
1650 | + public function get_comments($column = null) |
|
1651 | 1651 | { |
1652 | - static $comments=null; |
|
1652 | + static $comments = null; |
|
1653 | 1653 | |
1654 | 1654 | if (is_null($comments)) |
1655 | 1655 | { |
1656 | - foreach($this->db_cols as $db_col => $col) |
|
1656 | + foreach ($this->db_cols as $db_col => $col) |
|
1657 | 1657 | { |
1658 | 1658 | $comments[$col] = $this->table_def['fd'][$db_col]['comment']; |
1659 | 1659 | } |
@@ -53,9 +53,9 @@ discard block |
||
53 | 53 | * |
54 | 54 | * @return so_sql2 |
55 | 55 | */ |
56 | - function __construct($app='',$table='',Api\Db $db=null,$column_prefix='',$no_clone=false) |
|
56 | + function __construct($app = '', $table = '', Api\Db $db = null, $column_prefix = '', $no_clone = false) |
|
57 | 57 | { |
58 | - parent::__construct($app,$table,$db,$column_prefix,$no_clone); |
|
58 | + parent::__construct($app, $table, $db, $column_prefix, $no_clone); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -68,13 +68,13 @@ discard block |
||
68 | 68 | */ |
69 | 69 | function __get($property) |
70 | 70 | { |
71 | - switch($property) |
|
71 | + switch ($property) |
|
72 | 72 | { |
73 | 73 | case 'id': |
74 | 74 | $property = $this->autoinc_id; |
75 | 75 | break; |
76 | 76 | } |
77 | - if (in_array($property,$this->db_cols) || in_array($property,$this->non_db_cols)) |
|
77 | + if (in_array($property, $this->db_cols) || in_array($property, $this->non_db_cols)) |
|
78 | 78 | { |
79 | 79 | return $this->data[$property]; |
80 | 80 | } |
@@ -88,15 +88,15 @@ discard block |
||
88 | 88 | * @param string $property |
89 | 89 | * @param mixed $value |
90 | 90 | */ |
91 | - function __set($property,$value) |
|
91 | + function __set($property, $value) |
|
92 | 92 | { |
93 | - switch($property) |
|
93 | + switch ($property) |
|
94 | 94 | { |
95 | 95 | case 'id': |
96 | 96 | $property = $this->autoinc_id; |
97 | 97 | break; |
98 | 98 | } |
99 | - if (in_array($property,$this->db_cols) || in_array($property,$this->non_db_cols)) |
|
99 | + if (in_array($property, $this->db_cols) || in_array($property, $this->non_db_cols)) |
|
100 | 100 | { |
101 | 101 | $this->data[$property] = $value; |
102 | 102 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | */ |
22 | 22 | class App extends Exception\NoPermission |
23 | 23 | { |
24 | - function __construct($msg=null,$code=101) |
|
24 | + function __construct($msg = null, $code = 101) |
|
25 | 25 | { |
26 | 26 | if (isset($GLOBALS['egw_info']['apps'][$msg])) |
27 | 27 | { |
@@ -39,6 +39,6 @@ discard block |
||
39 | 39 | '"'.$app.'"'); |
40 | 40 | } |
41 | 41 | } |
42 | - parent::__construct($msg,$code); |
|
42 | + parent::__construct($msg, $code); |
|
43 | 43 | } |
44 | 44 | } |
@@ -26,10 +26,10 @@ |
||
26 | 26 | * @param string $msg =null message, default "Entry not found!" |
27 | 27 | * @param int $code =99 numerical code, default 2 |
28 | 28 | */ |
29 | - function __construct($msg=null,$code=2) |
|
29 | + function __construct($msg = null, $code = 2) |
|
30 | 30 | { |
31 | 31 | if (is_null($msg)) $msg = lang('Entry not found!'); |
32 | 32 | |
33 | - parent::__construct($msg,$code); |
|
33 | + parent::__construct($msg, $code); |
|
34 | 34 | } |
35 | 35 | } |
@@ -28,7 +28,10 @@ |
||
28 | 28 | */ |
29 | 29 | function __construct($msg=null,$code=2) |
30 | 30 | { |
31 | - if (is_null($msg)) $msg = lang('Entry not found!'); |
|
31 | + if (is_null($msg)) |
|
32 | + { |
|
33 | + $msg = lang('Entry not found!'); |
|
34 | + } |
|
32 | 35 | |
33 | 36 | parent::__construct($msg,$code); |
34 | 37 | } |
@@ -33,7 +33,7 @@ |
||
33 | 33 | * @param string $msg |
34 | 34 | * @param int $code |
35 | 35 | */ |
36 | - function __construct($url,$app=null,$msg=null,$code=301) |
|
36 | + function __construct($url, $app = null, $msg = null, $code = 301) |
|
37 | 37 | { |
38 | 38 | $this->url = $url; |
39 | 39 | $this->app = $app; |
@@ -27,10 +27,10 @@ |
||
27 | 27 | * @param string $msg =null message, default "Permission denied!" |
28 | 28 | * @param int $code =100 numerical code, default 100 |
29 | 29 | */ |
30 | - function __construct($msg=null,$code=100) |
|
30 | + function __construct($msg = null, $code = 100) |
|
31 | 31 | { |
32 | 32 | if (is_null($msg)) $msg = lang('Permisson denied!'); |
33 | 33 | |
34 | - parent::__construct($msg,$code); |
|
34 | + parent::__construct($msg, $code); |
|
35 | 35 | } |
36 | 36 | } |
@@ -29,7 +29,10 @@ |
||
29 | 29 | */ |
30 | 30 | function __construct($msg=null,$code=100) |
31 | 31 | { |
32 | - if (is_null($msg)) $msg = lang('Permisson denied!'); |
|
32 | + if (is_null($msg)) |
|
33 | + { |
|
34 | + $msg = lang('Permisson denied!'); |
|
35 | + } |
|
33 | 36 | |
34 | 37 | parent::__construct($msg,$code); |
35 | 38 | } |
@@ -27,10 +27,10 @@ |
||
27 | 27 | * @param string $msg =null message, default "Database error!" |
28 | 28 | * @param int $code =100 |
29 | 29 | */ |
30 | - function __construct($msg=null,$code=100) |
|
30 | + function __construct($msg = null, $code = 100) |
|
31 | 31 | { |
32 | 32 | if (is_null($msg)) $msg = lang('Database error!'); |
33 | 33 | |
34 | - parent::__construct($msg,$code); |
|
34 | + parent::__construct($msg, $code); |
|
35 | 35 | } |
36 | 36 | } |
@@ -29,7 +29,10 @@ |
||
29 | 29 | */ |
30 | 30 | function __construct($msg=null,$code=100) |
31 | 31 | { |
32 | - if (is_null($msg)) $msg = lang('Database error!'); |
|
32 | + if (is_null($msg)) |
|
33 | + { |
|
34 | + $msg = lang('Database error!'); |
|
35 | + } |
|
33 | 36 | |
34 | 37 | parent::__construct($msg,$code); |
35 | 38 | } |